Skip to content

Commit

Permalink
Fix to issues with generated hero saving, improvements to hero admini…
Browse files Browse the repository at this point in the history
…strative efficiency modifier
  • Loading branch information
Andrettin committed Nov 17, 2015
1 parent 1030ab2 commit d871c82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/include/grand_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class CGrandStrategyHero
{
}

void Initialize();
void Create();
void Die();
int GetAdministrativeEfficiencyModifier();
Expand Down
17 changes: 13 additions & 4 deletions src/stratagus/grand_strategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3644,6 +3644,13 @@ std::string CGrandStrategyFaction::GetRulerTitle()
return "";
}

void CGrandStrategyHero::Initialize()
{
this->Type = const_cast<CUnitType *>(&(*this->DefaultType));
int province_of_origin_id = GetProvinceId(this->ProvinceOfOriginName);
this->ProvinceOfOrigin = const_cast<CProvince *>(&(*GrandStrategyGame.Provinces[province_of_origin_id]));
}

void CGrandStrategyHero::Create()
{
//show message that the hero has appeared
Expand Down Expand Up @@ -3729,7 +3736,11 @@ int CGrandStrategyHero::GetAdministrativeEfficiencyModifier()
int modifier = 0;

if (this->Type != NULL) {
modifier += (this->Type->DefaultStat.Variables[INTELLIGENCE_INDEX].Value - 10) * 25 / 10; //+2.5% administrative efficiency for every intelligence point above 10, and -2.5% for every point below 10
int intelligence = this->Type->DefaultStat.Variables[INTELLIGENCE_INDEX].Value;
if (intelligence == 10) {
intelligence += 1; //grant +1 intelligence to heroes with 10 intelligence, to prevent them from having no bonus
}
modifier += (intelligence - 10) * 5; //+2.5% administrative efficiency for every intelligence point above 10, and -2.5% for every point below 10; changed that to 5 for now since heroes don't get intelligence scores which are particularly high
}

return modifier;
Expand Down Expand Up @@ -5514,9 +5525,7 @@ void InitializeGrandStrategyGame()

//set hero unit types to their default type
for (size_t i = 0; i < GrandStrategyGame.Heroes.size(); ++i) {
GrandStrategyGame.Heroes[i]->Type = const_cast<CUnitType *>(&(*GrandStrategyGame.Heroes[i]->DefaultType));
int province_of_origin_id = GetProvinceId(GrandStrategyGame.Heroes[i]->ProvinceOfOriginName);
GrandStrategyGame.Heroes[i]->ProvinceOfOrigin = const_cast<CProvince *>(&(*GrandStrategyGame.Provinces[province_of_origin_id]));
GrandStrategyGame.Heroes[i]->Initialize();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stratagus/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ void SaveGrandStrategyGame(const std::string &filename)
if (GrandStrategyGame.Heroes[i]->Mother != NULL) {
fprintf(fd, "\tMother = \"%s\",\n", GrandStrategyGame.Heroes[i]->Mother->GetFullName().c_str());
}
fprintf(fd, "\tGenerated = \"true\"\n");
fprintf(fd, "\tGenerated = true\n");
fprintf(fd, "})\n");
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/unit/script_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,10 @@ static int CclDefineGrandStrategyHero(lua_State *l)
}
}

if (hero->Generated) { //if the hero was generated, initialize it (since this is loaded during a save game, after the other heroes have already been initialized)
hero->Initialize();
}

return 0;
}
//Wyrmgus end
Expand Down

0 comments on commit d871c82

Please sign in to comment.