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:
@@ -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;
|
||||||
@@ -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;
|
||||||
|
@@ -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)
|
||||||
|
@@ -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
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user