1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Workaround for serializer allowing sending CStackInstance* pointing to commander. (and only CStackInstance*)

This commit is contained in:
Michał W. Urbańczyk 2012-05-21 23:39:35 +00:00
parent d34cf90bf7
commit 401d6816d1
2 changed files with 32 additions and 4 deletions

View File

@ -1030,7 +1030,15 @@ bool CArtifactInstance::canBePutAt(const CArtifactSet *artSet, int slot, bool as
return true; return true;
} }
if(!vstd::contains(artType->possibleSlots[artSet->bearerType()], slot)) auto possibleSlots = artType->possibleSlots.find(artSet->bearerType());
if(possibleSlots == artType->possibleSlots.end())
{
tlog3 << "Warning: arrtifact " << artType->Name() << " doesn't have defined allowed slots for bearer of type "
<< artSet->bearerType() << std::endl;
return false;
}
if(!vstd::contains(possibleSlots->second, slot))
return false; return false;
return artSet->isPositionFree(slot, assumeDestRemoved); return artSet->isPositionFree(slot, assumeDestRemoved);

View File

@ -24,6 +24,8 @@
#include "CObjectHandler.h" //fo CArmedInstance #include "CObjectHandler.h" //fo CArmedInstance
const ui32 version = 732; const ui32 version = 732;
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
class CConnection; class CConnection;
class CGObjectInstance; class CGObjectInstance;
class CStackInstance; class CStackInstance;
@ -378,7 +380,14 @@ struct SaveIfStackInstance<Ser, CStackInstance *>
static bool invoke(Ser &s, const CStackInstance* const &data) static bool invoke(Ser &s, const CStackInstance* const &data)
{ {
assert(data->armyObj); assert(data->armyObj);
TSlot slot = data->armyObj->findStack(data); TSlot slot = -1;
if(data->getNodeType() == Bonus::COMMANDER)
slot = COMMANDER_SLOT_PLACEHOLDER;
else
slot = data->armyObj->findStack(data);
assert(slot != -1);
s << data->armyObj << slot; s << data->armyObj << slot;
return true; return true;
} }
@ -391,6 +400,7 @@ struct LoadIfStackInstance
return false; return false;
} }
}; };
template<typename Ser> template<typename Ser>
struct LoadIfStackInstance<Ser, CStackInstance *> struct LoadIfStackInstance<Ser, CStackInstance *>
{ {
@ -399,8 +409,18 @@ struct LoadIfStackInstance<Ser, CStackInstance *>
CArmedInstance *armedObj; CArmedInstance *armedObj;
TSlot slot; TSlot slot;
s >> armedObj >> slot; s >> armedObj >> slot;
assert(armedObj->hasStackAtSlot(slot)); if(slot != COMMANDER_SLOT_PLACEHOLDER)
data = armedObj->stacks[slot]; {
assert(armedObj->hasStackAtSlot(slot));
data = armedObj->stacks[slot];
}
else
{
auto hero = dynamic_cast<CGHeroInstance *>(armedObj);
assert(hero);
assert(hero->commander);
data = hero->commander;
}
return true; return true;
} }
}; };