From 58e63e89989dc90dd749ae9635f550b639738fde Mon Sep 17 00:00:00 2001 From: Andrettin Date: Fri, 13 Nov 2015 22:04:52 +0100 Subject: [PATCH] Fixed bug if game tried to set a non-existent faction --- src/stratagus/player.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp index 0cb223a20..04f9ac11c 100644 --- a/src/stratagus/player.cpp +++ b/src/stratagus/player.cpp @@ -1110,23 +1110,23 @@ void CPlayer::SetFaction(const std::string faction_name) this->SetName(faction_name); } this->Faction = faction; - int PrimaryColor = PlayerRaces.Factions[this->Race][faction]->Color; - int SecondaryColor = PlayerRaces.Factions[this->Race][faction]->SecondaryColor; - bool color_used = false; - for (int i = 0; i < PlayerMax; ++i) { - if (this->Index != i && Players[i].Faction != -1 && Players[i].Type != PlayerNobody && Players[i].Color == PlayerColors[PrimaryColor][0]) { - color_used = true; - } - } - if (!color_used) { - this->Color = PlayerColors[PrimaryColor][0]; - this->UnitColors.Colors = PlayerColorsRGB[PrimaryColor]; - } else { - this->Color = PlayerColors[SecondaryColor][0]; - this->UnitColors.Colors = PlayerColorsRGB[SecondaryColor]; - } - if (this->Faction != -1) { + int PrimaryColor = PlayerRaces.Factions[this->Race][faction]->Color; + int SecondaryColor = PlayerRaces.Factions[this->Race][faction]->SecondaryColor; + bool color_used = false; + for (int i = 0; i < PlayerMax; ++i) { + if (this->Index != i && Players[i].Faction != -1 && Players[i].Type != PlayerNobody && Players[i].Color == PlayerColors[PrimaryColor][0]) { + color_used = true; + } + } + if (!color_used) { + this->Color = PlayerColors[PrimaryColor][0]; + this->UnitColors.Colors = PlayerColorsRGB[PrimaryColor]; + } else { + this->Color = PlayerColors[SecondaryColor][0]; + this->UnitColors.Colors = PlayerColorsRGB[SecondaryColor]; + } + if (!PlayerRaces.Factions[this->Race][this->Faction]->FactionUpgrade.empty()) { UpgradeAcquire(*this, CUpgrade::Get(PlayerRaces.Factions[this->Race][this->Faction]->FactionUpgrade)); }