diff --git a/AI/VCAI/Goals/Win.cpp b/AI/VCAI/Goals/Win.cpp index f54ed6dc7..d2ab613e3 100644 --- a/AI/VCAI/Goals/Win.cpp +++ b/AI/VCAI/Goals/Win.cpp @@ -54,15 +54,15 @@ TSubgoal Win::whatToDoToAchieve() return sptr(GetArtOfType(goal.objectType.as())); 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->getOwner() == ai->playerID) //we can't capture our own object return sptr(Conquer()); - return sptr(VisitObj(goal.object->id.getNum())); + return sptr(VisitObj(goal.objectID.getNum())); } else { @@ -124,13 +124,13 @@ TSubgoal Win::whatToDoToAchieve() } 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 { diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 2da8b4603..75158bdab 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -1411,9 +1411,9 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio } case EventCondition::HAVE_BUILDING: { - if (condition.object) // specific town + if (condition.objectID != ObjectInstanceID::NONE) // specific town { - const auto * t = dynamic_cast(condition.object); + const auto * t = getTown(condition.objectID); return (t->tempOwner == player && t->hasBuilt(condition.objectType.as())); } else // any town @@ -1428,12 +1428,12 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio } 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(condition.object)) + if(const auto * hero = getHero(condition.objectID)) return boost::range::find(gs->map->heroesOnMap, hero) == gs->map->heroesOnMap.end(); else - return getObj(condition.object->id) == nullptr; + return getObj(condition.objectID) == nullptr; } else { @@ -1451,9 +1451,9 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio // NOTE: cgameinfocallback specified explicitly in order to get const version 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 { @@ -1468,7 +1468,7 @@ bool CGameState::checkForVictory(const PlayerColor & player, const EventConditio } case EventCondition::TRANSPORT: { - const auto * t = dynamic_cast(condition.object); + const auto * t = getTown(condition.objectID); return (t->visitingHero && t->visitingHero->hasArt(condition.objectType.as())) || (t->garrisonHero && t->garrisonHero->hasArt(condition.objectType.as())); } diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index ad7771840..0ea8bb52d 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -1793,11 +1793,8 @@ bool CGHeroInstance::isMissionCritical() const auto const & testFunctor = [&](const EventCondition & condition) { - if ((condition.condition == EventCondition::CONTROL) && condition.object) - { - const auto * hero = dynamic_cast(condition.object); - return (hero != this); - } + if ((condition.condition == EventCondition::CONTROL) && condition.objectID != ObjectInstanceID::NONE) + return (id != condition.objectID); if(condition.condition == EventCondition::IS_HUMAN) return true; diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index 005ebb5b2..f7f19c658 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -448,19 +448,19 @@ void CMap::checkForObjectives() case EventCondition::HAVE_BUILDING: if (isInTheMap(cond.position)) - cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN); + cond.objectID = getObjectiveObjectFrom(cond.position, Obj::TOWN)->id; break; case EventCondition::CONTROL: if (isInTheMap(cond.position)) - cond.object = getObjectiveObjectFrom(cond.position, cond.objectType.as()); + cond.objectID = getObjectiveObjectFrom(cond.position, cond.objectType.as())->id; - if (cond.object) + if (cond.objectID != ObjectInstanceID::NONE) { - const auto * town = dynamic_cast(cond.object); + const auto * town = dynamic_cast(objects[cond.objectID].get()); if (town) event.onFulfill.replaceRawString(town->getNameTranslated()); - const auto * hero = dynamic_cast(cond.object); + const auto * hero = dynamic_cast(objects[cond.objectID].get()); if (hero) event.onFulfill.replaceRawString(hero->getNameTranslated()); } @@ -468,17 +468,17 @@ void CMap::checkForObjectives() case EventCondition::DESTROY: if (isInTheMap(cond.position)) - cond.object = getObjectiveObjectFrom(cond.position, cond.objectType.as()); + cond.objectID = getObjectiveObjectFrom(cond.position, cond.objectType.as())->id; - if (cond.object) + if (cond.objectID != ObjectInstanceID::NONE) { - const auto * hero = dynamic_cast(cond.object); + const auto * hero = dynamic_cast(objects[cond.objectID].get()); if (hero) event.onFulfill.replaceRawString(hero->getNameTranslated()); } break; case EventCondition::TRANSPORT: - cond.object = getObjectiveObjectFrom(cond.position, Obj::TOWN); + cond.objectID = getObjectiveObjectFrom(cond.position, Obj::TOWN)->id; break; //break; case EventCondition::DAYS_PASSED: //break; case EventCondition::IS_HUMAN: diff --git a/lib/mapping/CMapHeader.cpp b/lib/mapping/CMapHeader.cpp index bdc3a808e..cacfc4c24 100644 --- a/lib/mapping/CMapHeader.cpp +++ b/lib/mapping/CMapHeader.cpp @@ -68,7 +68,6 @@ bool PlayerInfo::hasCustomMainHero() const } EventCondition::EventCondition(EWinLoseType condition): - object(nullptr), value(-1), position(-1, -1, -1), condition(condition) @@ -76,7 +75,6 @@ EventCondition::EventCondition(EWinLoseType condition): } EventCondition::EventCondition(EWinLoseType condition, si32 value, TargetTypeID objectType, const int3 & position): - object(nullptr), value(value), objectType(objectType), position(position), diff --git a/lib/mapping/CMapHeader.h b/lib/mapping/CMapHeader.h index e5b34892c..4ba9d9a0a 100644 --- a/lib/mapping/CMapHeader.h +++ b/lib/mapping/CMapHeader.h @@ -120,7 +120,7 @@ struct DLL_LINKAGE EventCondition EventCondition(EWinLoseType condition = STANDARD_WIN); 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; TargetTypeID objectType; std::string objectInstanceName; @@ -130,7 +130,7 @@ struct DLL_LINKAGE EventCondition template void serialize(Handler & h, const int version) { - h & object; + h & objectID; h & value; h & objectType; h & position; diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index e50ce9412..1dd78cabc 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -1215,7 +1215,7 @@ void RemoveObject::applyGs(CGameState *gs) { auto patcher = [&](EventCondition cond) -> EventExpression::Variant { - if (cond.object == obj) + if (cond.objectID == obj->id) { if (cond.condition == EventCondition::DESTROY) {