[*] Research all upgrades which were already researched on the map beginning

This commit is contained in:
cybermind 2015-02-15 12:10:04 +05:00
parent 28c49d7370
commit 951f59e4c5
3 changed files with 38 additions and 5 deletions

View file

@ -841,6 +841,7 @@ void CreateGame(const std::string &filename, CMap *map)
//
InitUnitTypes(1);
LoadMap(filename, *map);
ApplyUpgrades();
}
CclCommand("if (MapLoaded ~= nil) then MapLoaded() end");

View file

@ -74,12 +74,10 @@ extern int UpgradeIdByIdent(const std::string &sid);
/// Upgrade will be acquired
extern void UpgradeAcquire(CPlayer &player, const CUpgrade *upgrade);
/// for now it will be empty?
/// perhaps acquired upgrade can be lost if (for example) a building is lost
/// (lumber mill? stronghold?)
/// this function will apply all modifiers in reverse way
/// Upgrade will be lost
extern void UpgradeLost(CPlayer &player, int id);
/// Apply researched upgrades when map is loading
extern void ApplyUpgrades();
/*----------------------------------------------------------------------------
-- Allow(s)

View file

@ -777,6 +777,13 @@ void UpgradeAcquire(CPlayer &player, const CUpgrade *upgrade)
}
}
/**
** Upgrade will be lost
**
** @param player Player researching the upgrade.
** @param id Upgrade to be lost.
**
*/
void UpgradeLost(CPlayer &player, int id)
{
player.UpgradeTimers.Upgrades[id] = 0;
@ -795,6 +802,33 @@ void UpgradeLost(CPlayer &player, int id)
}
}
/**
** Apply researched upgrades when map is loading
**
** @return: void
*/
void ApplyUpgrades()
{
for (std::vector<CUpgrade *>::size_type j = 0; j < AllUpgrades.size(); ++j) {
CUpgrade *upgrade = AllUpgrades[j];
if (upgrade) {
for (int p = 0; p < PlayerMax; ++p) {
if (Players[p].Allow.Upgrades[j] == 'R') {
int id = upgrade->ID;
Players[p].UpgradeTimers.Upgrades[id] = upgrade->Costs[TimeCost];
AllowUpgradeId(Players[p], id, 'R'); // research done
for (int z = 0; z < NumUpgradeModifiers; ++z) {
if (UpgradeModifiers[z]->UpgradeId == id) {
ApplyUpgradeModifier(Players[p], UpgradeModifiers[z]);
}
}
}
}
}
}
}
/*----------------------------------------------------------------------------
-- Allow(s)
----------------------------------------------------------------------------*/