1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Rework campaign bonuses storage in type-safe form

Replaced campaign bonuses from using 3 integers to store anything with
type-safe version that uses std::variant that ensures that all bonuses
are in correct state.

Also removed "interesting" solutions like storing primary skills using
bit shifts.

Prerequirement for HotA campaign support
This commit is contained in:
Ivan Savenko
2025-05-28 18:03:17 +03:00
parent 713dbfb1f7
commit 2cd29c1893
16 changed files with 1028 additions and 707 deletions

View File

@@ -832,12 +832,16 @@ void CVCMIServer::setCampaignBonus(int bonusId)
campaignBonus = bonusId;
const CampaignScenario & scenario = si->campState->scenario(campaignMap);
const std::vector<CampaignBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
if(bonDescs[bonusId].type == CampaignBonusType::HERO || bonDescs[bonusId].type == CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO)
const CampaignBonus & bonus = scenario.travelOptions.bonusesToChoose.at(bonusId);
if(bonus.getType() == CampaignBonusType::HERO || bonus.getType() == CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO)
{
PlayerColor startingPlayer = bonus.getType() == CampaignBonusType::HERO ?
bonus.getValue<CampaignBonusStartingHero>().startingPlayer :
bonus.getValue<CampaignBonusHeroesFromScenario>().startingPlayer;
for(auto & elem : si->playerInfos)
{
if(elem.first == PlayerColor(bonDescs[bonusId].info1))
if(elem.first == startingPlayer)
setPlayerConnectedId(elem.second, 1);
else
setPlayerConnectedId(elem.second, PlayerSettings::PLAYER_AI);