1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

* minor changes - hero crossover in campaigns

This commit is contained in:
mateuszb 2010-08-30 14:52:18 +00:00
parent 9e8d0651f6
commit 34b4e09927

View File

@ -1203,6 +1203,22 @@ CGameState::~CGameState()
capitols.clear(); capitols.clear();
} }
namespace HHLP
{
class HeroRemoverHelper
{
public:
si32 allowedplayer;
HeroRemoverHelper(si32 player) : allowedplayer(player)
{
}
bool operator()(const CGHeroInstance * cgh)
{
return cgh->tempOwner != allowedplayer;
}
};
}
void CGameState::init( StartInfo * si, ui32 checksum, int Seed ) void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
{ {
VLC->creh->globalEffects = &globalEffects; VLC->creh->globalEffects = &globalEffects;
@ -1276,6 +1292,18 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
return ret; return ret;
} }
static void replaceHero( CGameState * gs, int objId, CGHeroInstance * ghi )
{
ghi->id = objId;
gs->map->objects[objId] = ghi;
gs->map->heroes.push_back(ghi);
}
//sort in descending order by power
static bool heroPowerSorter(const CGHeroInstance * a, const CGHeroInstance * b)
{
return a->getHeroStrength() > b->getHeroStrength();
}
}; };
switch(si->mode) switch(si->mode)
@ -1449,6 +1477,53 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
} }
} }
/*************************replace hero placeholders*****************************/
if (campaign)
{
CScenarioTravel::STravelBonus bonus =
campaign->camp->scenarios[si->whichMapInCampaign].travelOptions.bonusesToChoose[si->choosenCampaignBonus];
for(int g=0; g<map->objects.size(); ++g)
{
CGObjectInstance * obj = map->objects[g];
if (obj->ID != 214) //not a placeholder
{
continue;
}
CGHeroPlaceholder * hp = static_cast<CGHeroPlaceholder*>(obj);
CGHeroInstance * substitution = NULL;
std::vector<CGHeroInstance *> Xheroes;
if (bonus.type == 8) //hero crossover
{
Xheroes = campaign->camp->scenarios[bonus.info2].crossoverHeroes;
std::remove_if(Xheroes.begin(), Xheroes.end(), HHLP::HeroRemoverHelper(bonus.info1));
}
else if (bonus.type == 9) //starting hero
{
}
if (hp->subID == 0xFF) //select by power
{
std::sort(Xheroes.begin(), Xheroes.end(), HLP::heroPowerSorter);
HLP::replaceHero(this, g, Xheroes[hp->power - 1]);
}
else //select by type
{
BOOST_FOREACH(CGHeroInstance * ghi, Xheroes)
{
if (ghi->subID == hp->subID)
{
HLP::replaceHero(this, g, ghi);
break;
}
}
}
}
}
/******************RESOURCES****************************************************/ /******************RESOURCES****************************************************/
std::vector<int> startresAI, startresHuman; std::vector<int> startresAI, startresHuman;
std::ifstream tis(DATA_DIR "/config/startres.txt"); std::ifstream tis(DATA_DIR "/config/startres.txt");