mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Remove pointer to CGObjectInstance from map header
This commit is contained in:
parent
f53a53051b
commit
9f906ff1d2
@ -54,15 +54,15 @@ TSubgoal Win::whatToDoToAchieve()
|
|||||||
return sptr(GetArtOfType(goal.objectType.as<ArtifactID>()));
|
return sptr(GetArtOfType(goal.objectType.as<ArtifactID>()));
|
||||||
case EventCondition::DESTROY:
|
case EventCondition::DESTROY:
|
||||||
{
|
{
|
||||||
if(goal.object)
|
if(goal.objectID != ObjectInstanceID::NONE)
|
||||||
{
|
{
|
||||||
auto obj = cb->getObj(goal.object->id);
|
auto obj = cb->getObj(goal.objectID);
|
||||||
if(obj)
|
if(obj)
|
||||||
if(obj->getOwner() == ai->playerID) //we can't capture our own object
|
if(obj->getOwner() == ai->playerID) //we can't capture our own object
|
||||||
return sptr(Conquer());
|
return sptr(Conquer());
|
||||||
|
|
||||||
|
|
||||||
return sptr(VisitObj(goal.object->id.getNum()));
|
return sptr(VisitObj(goal.objectID.getNum()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -124,13 +124,13 @@ TSubgoal Win::whatToDoToAchieve()
|
|||||||
}
|
}
|
||||||
case EventCondition::CONTROL:
|
case EventCondition::CONTROL:
|
||||||
{
|
{
|
||||||
if(goal.object)
|
if(goal.objectID != ObjectInstanceID::NONE)
|
||||||
{
|
{
|
||||||
auto objRelations = cb->getPlayerRelations(ai->playerID, goal.object->tempOwner);
|
auto obj = cb->getObj(goal.objectID);
|
||||||
|
|
||||||
if(objRelations == PlayerRelations::ENEMIES)
|
if(obj && cb->getPlayerRelations(ai->playerID, obj->tempOwner) == PlayerRelations::ENEMIES)
|
||||||
{
|
{
|
||||||
return sptr(VisitObj(goal.object->id.getNum()));
|
return sptr(VisitObj(goal.objectID.getNum()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1411,9 +1411,9 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
|
|||||||
}
|
}
|
||||||
case EventCondition::HAVE_BUILDING:
|
case EventCondition::HAVE_BUILDING:
|
||||||
{
|
{
|
||||||
if (condition.object) // specific town
|
if (condition.objectID != ObjectInstanceID::NONE) // specific town
|
||||||
{
|
{
|
||||||
const auto * t = dynamic_cast<const CGTownInstance *>(condition.object);
|
const auto * t = getTown(condition.objectID);
|
||||||
return (t->tempOwner == player && t->hasBuilt(condition.objectType.as<BuildingID>()));
|
return (t->tempOwner == player && t->hasBuilt(condition.objectType.as<BuildingID>()));
|
||||||
}
|
}
|
||||||
else // any town
|
else // any town
|
||||||
@ -1428,12 +1428,12 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
|
|||||||
}
|
}
|
||||||
case EventCondition::DESTROY:
|
case EventCondition::DESTROY:
|
||||||
{
|
{
|
||||||
if (condition.object) // mode A - destroy specific object of this type
|
if (condition.objectID != ObjectInstanceID::NONE) // mode A - destroy specific object of this type
|
||||||
{
|
{
|
||||||
if(const auto * hero = dynamic_cast<const CGHeroInstance *>(condition.object))
|
if(const auto * hero = getHero(condition.objectID))
|
||||||
return boost::range::find(gs->map->heroesOnMap, hero) == gs->map->heroesOnMap.end();
|
return boost::range::find(gs->map->heroesOnMap, hero) == gs->map->heroesOnMap.end();
|
||||||
else
|
else
|
||||||
return getObj(condition.object->id) == nullptr;
|
return getObj(condition.objectID) == nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1451,9 +1451,9 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
|
|||||||
// NOTE: cgameinfocallback specified explicitly in order to get const version
|
// NOTE: cgameinfocallback specified explicitly in order to get const version
|
||||||
const auto & team = CGameInfoCallback::getPlayerTeam(player)->players;
|
const auto & team = CGameInfoCallback::getPlayerTeam(player)->players;
|
||||||
|
|
||||||
if (condition.object) // mode A - flag one specific object, like town
|
if (condition.objectID != ObjectInstanceID::NONE) // mode A - flag one specific object, like town
|
||||||
{
|
{
|
||||||
return team.count(condition.object->tempOwner) != 0;
|
return team.count(getObjInstance(condition.objectID)->tempOwner) != 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1468,7 +1468,7 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio
|
|||||||
}
|
}
|
||||||
case EventCondition::TRANSPORT:
|
case EventCondition::TRANSPORT:
|
||||||
{
|
{
|
||||||
const auto * t = dynamic_cast<const CGTownInstance *>(condition.object);
|
const auto * t = getTown(condition.objectID);
|
||||||
return (t->visitingHero && t->visitingHero->hasArt(condition.objectType.as<ArtifactID>())) ||
|
return (t->visitingHero && t->visitingHero->hasArt(condition.objectType.as<ArtifactID>())) ||
|
||||||
(t->garrisonHero && t->garrisonHero->hasArt(condition.objectType.as<ArtifactID>()));
|
(t->garrisonHero && t->garrisonHero->hasArt(condition.objectType.as<ArtifactID>()));
|
||||||
}
|
}
|
||||||
|
@ -1793,11 +1793,8 @@ bool CGHeroInstance::isMissionCritical() const
|
|||||||
|
|
||||||
auto const & testFunctor = [&](const EventCondition & condition)
|
auto const & testFunctor = [&](const EventCondition & condition)
|
||||||
{
|
{
|
||||||
if ((condition.condition == EventCondition::CONTROL) && condition.object)
|
if ((condition.condition == EventCondition::CONTROL) && condition.objectID != ObjectInstanceID::NONE)
|
||||||
{
|
return (id != condition.objectID);
|
||||||
const auto * hero = dynamic_cast<const CGHeroInstance *>(condition.object);
|
|
||||||
return (hero != this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(condition.condition == EventCondition::IS_HUMAN)
|
if(condition.condition == EventCondition::IS_HUMAN)
|
||||||
return true;
|
return true;
|
||||||
|
@ -448,19 +448,19 @@ void CMap::checkForObjectives()
|
|||||||
|
|
||||||
case EventCondition::HAVE_BUILDING:
|
case EventCondition::HAVE_BUILDING:
|
||||||
if (isInTheMap(cond.position))
|
if (isInTheMap(cond.position))
|
||||||
cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN);
|
cond.objectID = getObjectiveObjectFrom(cond.position, Obj::TOWN)->id;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EventCondition::CONTROL:
|
case EventCondition::CONTROL:
|
||||||
if (isInTheMap(cond.position))
|
if (isInTheMap(cond.position))
|
||||||
cond.object = getObjectiveObjectFrom(cond.position, cond.objectType.as<MapObjectID>());
|
cond.objectID = getObjectiveObjectFrom(cond.position, cond.objectType.as<MapObjectID>())->id;
|
||||||
|
|
||||||
if (cond.object)
|
if (cond.objectID != ObjectInstanceID::NONE)
|
||||||
{
|
{
|
||||||
const auto * town = dynamic_cast<const CGTownInstance *>(cond.object);
|
const auto * town = dynamic_cast<const CGTownInstance *>(objects[cond.objectID].get());
|
||||||
if (town)
|
if (town)
|
||||||
event.onFulfill.replaceRawString(town->getNameTranslated());
|
event.onFulfill.replaceRawString(town->getNameTranslated());
|
||||||
const auto * hero = dynamic_cast<const CGHeroInstance *>(cond.object);
|
const auto * hero = dynamic_cast<const CGHeroInstance *>(objects[cond.objectID].get());
|
||||||
if (hero)
|
if (hero)
|
||||||
event.onFulfill.replaceRawString(hero->getNameTranslated());
|
event.onFulfill.replaceRawString(hero->getNameTranslated());
|
||||||
}
|
}
|
||||||
@ -468,17 +468,17 @@ void CMap::checkForObjectives()
|
|||||||
|
|
||||||
case EventCondition::DESTROY:
|
case EventCondition::DESTROY:
|
||||||
if (isInTheMap(cond.position))
|
if (isInTheMap(cond.position))
|
||||||
cond.object = getObjectiveObjectFrom(cond.position, cond.objectType.as<MapObjectID>());
|
cond.objectID = getObjectiveObjectFrom(cond.position, cond.objectType.as<MapObjectID>())->id;
|
||||||
|
|
||||||
if (cond.object)
|
if (cond.objectID != ObjectInstanceID::NONE)
|
||||||
{
|
{
|
||||||
const auto * hero = dynamic_cast<const CGHeroInstance *>(cond.object);
|
const auto * hero = dynamic_cast<const CGHeroInstance *>(objects[cond.objectID].get());
|
||||||
if (hero)
|
if (hero)
|
||||||
event.onFulfill.replaceRawString(hero->getNameTranslated());
|
event.onFulfill.replaceRawString(hero->getNameTranslated());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EventCondition::TRANSPORT:
|
case EventCondition::TRANSPORT:
|
||||||
cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN);
|
cond.objectID = getObjectiveObjectFrom(cond.position, Obj::TOWN)->id;
|
||||||
break;
|
break;
|
||||||
//break; case EventCondition::DAYS_PASSED:
|
//break; case EventCondition::DAYS_PASSED:
|
||||||
//break; case EventCondition::IS_HUMAN:
|
//break; case EventCondition::IS_HUMAN:
|
||||||
|
@ -68,7 +68,6 @@ bool PlayerInfo::hasCustomMainHero() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
EventCondition::EventCondition(EWinLoseType condition):
|
EventCondition::EventCondition(EWinLoseType condition):
|
||||||
object(nullptr),
|
|
||||||
value(-1),
|
value(-1),
|
||||||
position(-1, -1, -1),
|
position(-1, -1, -1),
|
||||||
condition(condition)
|
condition(condition)
|
||||||
@ -76,7 +75,6 @@ EventCondition::EventCondition(EWinLoseType condition):
|
|||||||
}
|
}
|
||||||
|
|
||||||
EventCondition::EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position):
|
EventCondition::EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position):
|
||||||
object(nullptr),
|
|
||||||
value(value),
|
value(value),
|
||||||
objectType(objectType),
|
objectType(objectType),
|
||||||
position(position),
|
position(position),
|
||||||
|
@ -120,7 +120,7 @@ struct DLL_LINKAGE EventCondition
|
|||||||
EventCondition(EWinLoseType condition = STANDARD_WIN);
|
EventCondition(EWinLoseType condition = STANDARD_WIN);
|
||||||
EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position = int3(-1, -1, -1));
|
EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position = int3(-1, -1, -1));
|
||||||
|
|
||||||
const CGObjectInstance * object; // object that was at specified position or with instance name on start
|
ObjectInstanceID objectID; // object that was at specified position or with instance name on start
|
||||||
si32 value;
|
si32 value;
|
||||||
TargetTypeID objectType;
|
TargetTypeID objectType;
|
||||||
std::string objectInstanceName;
|
std::string objectInstanceName;
|
||||||
@ -130,7 +130,7 @@ struct DLL_LINKAGE EventCondition
|
|||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & object;
|
h & objectID;
|
||||||
h & value;
|
h & value;
|
||||||
h & objectType;
|
h & objectType;
|
||||||
h & position;
|
h & position;
|
||||||
|
@ -1215,7 +1215,7 @@ void RemoveObject::applyGs(CGameState *gs)
|
|||||||
{
|
{
|
||||||
auto patcher = [&](EventCondition cond) -> EventExpression::Variant
|
auto patcher = [&](EventCondition cond) -> EventExpression::Variant
|
||||||
{
|
{
|
||||||
if (cond.object == obj)
|
if (cond.objectID == obj->id)
|
||||||
{
|
{
|
||||||
if (cond.condition == EventCondition::DESTROY)
|
if (cond.condition == EventCondition::DESTROY)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user