1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

* changes in campaign handling

This commit is contained in:
mateuszb
2013-02-06 19:48:09 +00:00
parent 56ffd05648
commit 169cf3558d
4 changed files with 45 additions and 12 deletions

View File

@@ -1092,12 +1092,12 @@ void CGameState::init(StartInfo * si)
/*************************replace hero placeholders*****************************/ /*************************replace hero placeholders*****************************/
tlog4 << "\tReplacing hero placeholders"; tlog4 << "\tReplacing hero placeholders";
std::vector<std::tuple<CGHeroInstance*, int> > campHeroReplacements; //instance, id in vector std::vector<std::pair<CGHeroInstance*, int> > campHeroReplacements; //instance, id in vector
if (scenarioOps->campState) if (scenarioOps->campState)
{ {
auto replaceHero = [&](int objId, CGHeroInstance * ghi) auto replaceHero = [&](int objId, CGHeroInstance * ghi)
{ {
campHeroReplacements.push_back(std::make_tuple(ghi, objId)); campHeroReplacements.push_back(std::make_pair(ghi, objId));
// ghi->tempOwner = getHumanPlayerInfo()[0]->color; // ghi->tempOwner = getHumanPlayerInfo()[0]->color;
// ghi->id = objId; // ghi->id = objId;
// gs->map->objects[objId] = ghi; // gs->map->objects[objId] = ghi;
@@ -1109,7 +1109,7 @@ void CGameState::init(StartInfo * si)
if(bonus.is_initialized()) if(bonus.is_initialized())
{ {
std::vector<CGHeroInstance *> Xheroes; std::vector<CGHeroInstance*> Xheroes;
if (bonus->type == CScenarioTravel::STravelBonus::PLAYER_PREV_SCENARIO) if (bonus->type == CScenarioTravel::STravelBonus::PLAYER_PREV_SCENARIO)
{ {
Xheroes = campaign->camp->scenarios[bonus->info2].crossoverHeroes; Xheroes = campaign->camp->scenarios[bonus->info2].crossoverHeroes;
@@ -1128,7 +1128,7 @@ void CGameState::init(StartInfo * si)
if(hp->subID != 0xFF) //select by type if(hp->subID != 0xFF) //select by type
{ {
bool found = false; bool found = false;
BOOST_FOREACH(CGHeroInstance * ghi, Xheroes) BOOST_FOREACH(auto ghi, Xheroes)
{ {
if (ghi->subID == hp->subID) if (ghi->subID == hp->subID)
{ {
@@ -1153,6 +1153,7 @@ void CGameState::init(StartInfo * si)
{ {
return a->getHeroStrength() > b->getHeroStrength(); return a->getHeroStrength() > b->getHeroStrength();
}); //sort, descending strength }); //sort, descending strength
for(int g=0; g<map->objects.size(); ++g) for(int g=0; g<map->objects.size(); ++g)
{ {
CGObjectInstance * obj = map->objects[g]; CGObjectInstance * obj = map->objects[g];
@@ -1257,10 +1258,10 @@ void CGameState::init(StartInfo * si)
BOOST_FOREACH(auto obj, campHeroReplacements) BOOST_FOREACH(auto obj, campHeroReplacements)
{ {
CGHeroInstance * hero = new CGHeroInstance(), CGHeroInstance * hero = new CGHeroInstance();
* oldHero = std::get<0>(obj); CGHeroInstance * oldHero = obj.first;
hero->initHero(oldHero->subID); hero->initHero(oldHero->subID);
hero->id = std::get<1>(obj); hero->id = obj.second;
map->objects[hero->id] = hero; map->objects[hero->id] = hero;
map->heroes.push_back(hero); map->heroes.push_back(hero);
const auto & travelOptions = scenarioOps->campState->getCurrentScenario().travelOptions; const auto & travelOptions = scenarioOps->campState->getCurrentScenario().travelOptions;
@@ -1278,7 +1279,7 @@ void CGameState::init(StartInfo * si)
hero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && hero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) &&
Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val
= oldHero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && = oldHero->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) &&
Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val; Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val;
} }
} }
if (travelOptions.whatHeroKeeps & 4) if (travelOptions.whatHeroKeeps & 4)

View File

@@ -738,6 +738,19 @@ public:
VariantVisitorSaver<Serializer> visitor(*this->This()); VariantVisitorSaver<Serializer> visitor(*this->This());
boost::apply_visitor(visitor, data); boost::apply_visitor(visitor, data);
} }
template <typename T>
void saveSerializable(const boost::optional<T> &data)
{
if(data)
{
*this << (ui8)1;
*this << *data;
}
else
{
*this << (ui8)0;
}
}
template <typename E> template <typename E>
void saveEnum(const E &data) void saveEnum(const E &data)
{ {
@@ -1102,6 +1115,22 @@ public:
assert(0); assert(0);
//TODO write more if needed, general solution would be much longer //TODO write more if needed, general solution would be much longer
} }
template <typename T>
void loadSerializable(boost::optional<T> & data)
{
ui8 present;
*this >> present;
if(present)
{
T t;
*this >> t;
data = t;
}
else
{
data = boost::optional<T>();
}
}
void loadSerializable(CStackInstance *&s) void loadSerializable(CStackInstance *&s)
{ {
if(sendStackInstanceByIds) if(sendStackInstanceByIds)

View File

@@ -323,7 +323,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
{ {
crossoverHeroes = heroes; crossoverHeroes = heroes;
if (!(travelOptions.whatHeroKeeps & 1)) if (!(travelOptions.whatHeroKeeps & 1))
{ {
//trimming experience //trimming experience
@@ -341,7 +341,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
{ {
cgh->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) && cgh->getBonusLocalFirst(Selector::type(Bonus::PRIMARY_SKILL) &&
Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val Selector::subtype(g) && Selector::sourceType(Bonus::HERO_BASE_SKILL) )->val
= cgh->type->heroClass->primarySkillInitial[g]; = cgh->type->heroClass->primarySkillInitial[g];
} }
} }
} }
@@ -372,7 +372,7 @@ void CCampaignScenario::prepareCrossoverHeroes( std::vector<CGHeroInstance *> he
const ArtSlotInfo *info = hero->getSlot(i); const ArtSlotInfo *info = hero->getSlot(i);
if (!info) if (!info)
continue; continue;
const CArtifactInstance *art = info->artifact; const CArtifactInstance *art = info->artifact;
if (!art)//FIXME: check spellbook and catapult behaviour if (!art)//FIXME: check spellbook and catapult behaviour
continue; continue;

View File

@@ -1,5 +1,8 @@
#pragma once #pragma once
#include "../../Global.h"
#include "../../lib/GameConstants.h"
/* /*
* CCampaignHandler.h, part of VCMI engine * CCampaignHandler.h, part of VCMI engine
* *
@@ -106,7 +109,7 @@ public:
CScenarioTravel travelOptions; CScenarioTravel travelOptions;
std::vector<CGHeroInstance*> crossoverHeroes; std::vector<CGHeroInstance *> crossoverHeroes;
void loadPreconditionRegions(ui32 regions); void loadPreconditionRegions(ui32 regions);
void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes); void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);