[+] Support for player color changing

This commit is contained in:
cybermind 2015-02-22 23:27:27 +05:00
parent 59430f91a2
commit a25d28c04d
12 changed files with 52 additions and 23 deletions

View file

@ -462,7 +462,7 @@ void AiInit(CPlayer &player)
if (!ait->Race.empty() && ait->Race != PlayerRaces.Name[player.Race]) {
continue;
}
if (!player.AiName.empty() && ait->Class != player.AiName) {
if (!player.AiName.empty() && ait->Name != player.AiName) {
continue;
}
break;

View file

@ -501,7 +501,7 @@ static void DrawPlayers()
i == Editor.CursorPlayer && Map.Info.PlayerType[i] != PlayerNobody ? ColorWhite : ColorGray,
x + i % 8 * 20, y, 19, 19);
if (Map.Info.PlayerType[i] != PlayerNobody) {
Video.FillRectangle(Players[i].Color, x + 1 + i % 8 * 20, y + 1, 17, 17);
Video.FillRectangle(PlayerColors[GameSettings.Presets[i].PlayerColor][0], x + 1 + i % 8 * 20, y + 1, 17, 17);
}
if (i == Editor.SelectedPlayer) {
Video.DrawRectangle(ColorGreen, x + 1 + i % 8 * 20, y + 1, 17, 17);

View file

@ -111,6 +111,7 @@ void SaveGameSettings(CFile &file)
{
file.printf("\nGameSettings.NetGameType = %d\n", GameSettings.NetGameType);
for (int i = 0; i < PlayerMax - 1; ++i) {
file.printf("GameSettings.Presets[%d].PlayerColor = %d\n", i, GameSettings.Presets[i].PlayerColor);
file.printf("GameSettings.Presets[%d].Race = %d\n", i, GameSettings.Presets[i].Race);
file.printf("GameSettings.Presets[%d].Team = %d\n", i, GameSettings.Presets[i].Team);
file.printf("GameSettings.Presets[%d].Type = %d\n", i, GameSettings.Presets[i].Type);
@ -1020,6 +1021,7 @@ void CreateGame(const std::string &filename, CMap *map)
void InitSettings()
{
for (int i = 0; i < PlayerMax; ++i) {
GameSettings.Presets[i].PlayerColor = i;
GameSettings.Presets[i].Race = SettingsPresetMapDefault;
GameSettings.Presets[i].Team = SettingsPresetMapDefault;
GameSettings.Presets[i].Type = SettingsPresetMapDefault;

View file

@ -98,9 +98,10 @@ public:
class MPPlayer
{
public:
MPPlayer() : Race(0), Team(0), Type(0) {}
MPPlayer() : PlayerColor(0), Race(0), Team(0), Type(0) {}
std::string Name;
int PlayerColor;
int Race;
int Team;
int Type;
@ -196,6 +197,7 @@ static FullReplay *StartReplay()
for (int i = 0; i < PlayerMax; ++i) {
replay->Players[i].Name = Players[i].Name;
replay->Players[i].PlayerColor = GameSettings.Presets[i].PlayerColor;
replay->Players[i].Race = GameSettings.Presets[i].Race;
replay->Players[i].Team = GameSettings.Presets[i].Team;
replay->Players[i].Type = GameSettings.Presets[i].Type;
@ -245,6 +247,7 @@ static void ApplyReplaySettings()
}
for (int i = 0; i < PlayerMax; ++i) {
GameSettings.Presets[i].PlayerColor = CurrentReplay->Players[i].PlayerColor;
GameSettings.Presets[i].Race = CurrentReplay->Players[i].Race;
GameSettings.Presets[i].Team = CurrentReplay->Players[i].Team;
GameSettings.Presets[i].Type = CurrentReplay->Players[i].Type;
@ -342,6 +345,7 @@ static void SaveFullLog(CFile &file)
} else {
file.printf("\t{");
}
file.printf(" PlayerColor = %d,", CurrentReplay->Players[i].PlayerColor);
file.printf(" Race = %d,", CurrentReplay->Players[i].Race);
file.printf(" Team = %d,", CurrentReplay->Players[i].Team);
file.printf(" Type = %d }%s", CurrentReplay->Players[i].Type,
@ -623,6 +627,8 @@ static int CclReplayLog(lua_State *l)
value = LuaToString(l, -2);
if (!strcmp(value, "Name")) {
replay->Players[j].Name = LuaToString(l, -1);
} else if (!strcmp(value, "PlayerColor")) {
replay->Players[j].PlayerColor = LuaToNumber(l, -1);
} else if (!strcmp(value, "Race")) {
replay->Players[j].Race = LuaToNumber(l, -1);
} else if (!strcmp(value, "Team")) {

View file

@ -47,9 +47,10 @@ class CMap;
----------------------------------------------------------------------------*/
struct SettingsPresets {
int Race; /// Race of the player
int Team; /// Team of player -- NOT SELECTABLE YET
int Type; /// Type of player (for network games)
int PlayerColor; /// Color of a player
int Race; /// Race of the player
int Team; /// Team of player -- NOT SELECTABLE YET
int Type; /// Type of player (for network games)
};
/**

View file

@ -42,6 +42,7 @@
#include "editor.h"
#include "map.h"
#include "player.h"
#include "settings.h"
#include "unit.h"
#include "unit_manager.h"
#include "ui.h"
@ -458,7 +459,7 @@ static void DrawUnitOn(CUnit &unit, int red_phase)
color = ColorGreen;
}
} else {
color = unit.Player->Color;
color = PlayerColors[GameSettings.Presets[unit.Player->Index].PlayerColor][0];
}
int mx = 1 + UI.Minimap.XOffset + Map2MinimapX[unit.tilePos.x];

View file

@ -44,6 +44,7 @@ extern unsigned long GameCycle;
$#include "settings.h"
struct SettingsPresets {
int PlayerColor;
int Race;
int Team;
int Type;

View file

@ -47,6 +47,7 @@
#include "interface.h"
#include "map.h"
#include "player.h"
#include "settings.h"
#include "sound.h"
#include "spells.h"
#include "translate.h"
@ -796,7 +797,7 @@ void CButtonPanel::Draw()
}
buttons[i].Icon.Icon->DrawUnitIcon(*UI.ButtonPanel.Buttons[i].Style,
GetButtonStatus(buttons[i], ButtonUnderCursor),
pos, buf, player);
pos, buf, GameSettings.Presets[player].PlayerColor);
}
}
//

View file

@ -47,6 +47,7 @@
#include "menus.h"
#include "network.h"
#include "player.h"
#include "settings.h"
#include "sound.h"
#include "spells.h"
#include "translate.h"
@ -366,7 +367,9 @@ static void DrawUnitInfo_Training(const CUnit &unit)
const unsigned int flags = (ButtonAreaUnderCursor == ButtonAreaTraining && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.SingleTrainingButton->X, UI.SingleTrainingButton->Y);
icon.DrawUnitIcon(*UI.SingleTrainingButton->Style, flags, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
icon.DrawUnitIcon(*UI.SingleTrainingButton->Style, flags, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
}
} else {
if (!UI.TrainingText.empty()) {
@ -383,7 +386,9 @@ static void DrawUnitInfo_Training(const CUnit &unit)
&& static_cast<size_t>(ButtonUnderCursor) == i) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.TrainingButtons[i].X, UI.TrainingButtons[i].Y);
icon.DrawUnitIcon(*UI.TrainingButtons[i].Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
icon.DrawUnitIcon(*UI.TrainingButtons[i].Style, flag, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
}
}
}
@ -416,7 +421,9 @@ static void DrawUnitInfo_portrait(const CUnit &unit)
const int flag = (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
type.Icon.Icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
type.Icon.Icon->DrawUnitIcon(*UI.SingleSelectedButton->Style, flag, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
}
}
@ -435,7 +442,9 @@ static bool DrawUnitInfo_single_selection(const CUnit &unit)
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.UpgradingButton->X, UI.UpgradingButton->Y);
icon.DrawUnitIcon(*UI.UpgradingButton->Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
icon.DrawUnitIcon(*UI.UpgradingButton->Style, flag, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
}
return true;
}
@ -447,7 +456,9 @@ static bool DrawUnitInfo_single_selection(const CUnit &unit)
&& ButtonUnderCursor == 0) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
PixelPos pos(UI.ResearchingButton->X, UI.ResearchingButton->Y);
icon.DrawUnitIcon(*UI.ResearchingButton->Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : unit.Player->Index);
icon.DrawUnitIcon(*UI.ResearchingButton->Style, flag, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
}
return true;
}
@ -469,7 +480,9 @@ static void DrawUnitInfo_transporter(CUnit &unit)
int flag = (ButtonAreaUnderCursor == ButtonAreaTransporting && static_cast<size_t>(ButtonUnderCursor) == j) ?
(IconActive | (MouseButtons & LeftButton)) : 0;
const PixelPos pos(UI.TransportingButtons[j].X, UI.TransportingButtons[j].Y);
icon.DrawUnitIcon(*UI.TransportingButtons[j].Style, flag, pos, "", unit.RescuedFrom ? unit.RescuedFrom->Index : uins->Player->Index);
icon.DrawUnitIcon(*UI.TransportingButtons[j].Style, flag, pos, "", unit.RescuedFrom
? GameSettings.Presets[unit.RescuedFrom->Index].PlayerColor
: GameSettings.Presets[unit.Player->Index].PlayerColor);
UiDrawLifeBar(*uins, pos.x, pos.y);
if (uins->Type->CanCastSpell && uins->Variable[MANA_INDEX].Max) {
UiDrawManaBar(*uins, pos.x, pos.y);
@ -1048,7 +1061,7 @@ static void InfoPanel_draw_no_selection()
label.Draw(x + 15, y, i);
Video.DrawRectangleClip(ColorWhite, x, y, 12, 12);
Video.FillRectangleClip(Players[i].Color, x + 1, y + 1, 10, 10);
Video.FillRectangleClip(PlayerColors[GameSettings.Presets[i].PlayerColor][0], x + 1, y + 1, 10, 10);
label.Draw(x + 27, y, Players[i].Name);
label.Draw(x + 117, y, Players[i].Score);
@ -1098,7 +1111,9 @@ static void InfoPanel_draw_multiple_selection()
icon.DrawUnitIcon(*UI.SelectedButtons[i].Style,
(ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == (int)i) ?
(IconActive | (MouseButtons & LeftButton)) : 0,
pos, "", Selected[i]->RescuedFrom ? Selected[i]->RescuedFrom->Index : Selected[i]->Player->Index);
pos, "", Selected[i]->RescuedFrom
? GameSettings.Presets[Selected[i]->RescuedFrom->Index].PlayerColor
: GameSettings.Presets[Selected[i]->Player->Index].PlayerColor);
UiDrawLifeBar(*Selected[i], UI.SelectedButtons[i].X, UI.SelectedButtons[i].Y);
if (ButtonAreaUnderCursor == ButtonAreaSelected && ButtonUnderCursor == (int) i) {

View file

@ -2166,7 +2166,7 @@ void DrawPieMenu()
if (gray) {
buttons[i].Icon.Icon->DrawGrayscaleIcon(pos);
} else {
buttons[i].Icon.Icon->DrawIcon(pos);
buttons[i].Icon.Icon->DrawIcon(pos, ThisPlayer->Index);
}
// Tutorial show command key in icons

View file

@ -49,6 +49,7 @@
#include "map.h"
#include "player.h"
#include "script.h"
#include "settings.h"
#include "sound.h"
#include "translate.h"
#include "unit.h"
@ -142,11 +143,11 @@ void DrawUnitSelection(const CViewport &vp, const CUnit &unit)
} else if (ThisPlayer->IsEnemy(unit)) {
color = ColorRed;
} else {
color = unit.Player->Color;
color = PlayerColors[GameSettings.Presets[unit.Player->Index].PlayerColor][0];
for (int i = 0; i < PlayerMax; ++i) {
if (unit.TeamSelected & (1 << i)) {
color = Players[i].Color;
color = PlayerColors[GameSettings.Presets[i].PlayerColor][0];
}
}
}
@ -885,15 +886,15 @@ void CUnit::Draw(const CViewport &vp) const
if (state == 1) {
if (constructed && cframe) {
const PixelPos pos(screenPos + (type->GetPixelSize()) / 2);
DrawConstruction(player, cframe, *type, frame, pos);
DrawConstruction(GameSettings.Presets[player].PlayerColor, cframe, *type, frame, pos);
} else {
DrawUnitType(*type, sprite, player, frame, screenPos);
DrawUnitType(*type, sprite, GameSettings.Presets[player].PlayerColor, frame, screenPos);
}
//
// Draw the future unit type, if upgrading to it.
//
} else {
DrawUnitType(*type, sprite, player, frame, screenPos);
DrawUnitType(*type, sprite, GameSettings.Presets[player].PlayerColor, frame, screenPos);
}
// Unit's extras not fully supported.. need to be decorations themselves.

View file

@ -42,6 +42,7 @@
#include "editor.h"
#include "interface.h"
#include "map.h"
#include "settings.h"
#include "tileset.h"
#include "translate.h"
#include "ui.h"
@ -182,7 +183,7 @@ static void DrawBuildingCursor()
PushClipping();
vp.SetClipping();
DrawShadow(*CursorBuilding, CursorBuilding->StillFrame, screenPos);
DrawUnitType(*CursorBuilding, CursorBuilding->Sprite, ThisPlayer->Index,
DrawUnitType(*CursorBuilding, CursorBuilding->Sprite, GameSettings.Presets[ThisPlayer->Index].PlayerColor,
CursorBuilding->StillFrame, screenPos);
if (CursorBuilding->CanAttack && CursorBuilding->Stats->Variables[ATTACKRANGE_INDEX].Value > 0) {
const PixelPos center(screenPos + CursorBuilding->GetPixelSize() / 2);