void GamePlayer::OnEntityDestroy(Message* p_pMessage) { EntityDestroyMessage *pDestroyMsg = nullptr; GameEntity *pEntity = nullptr; TID entityId; pDestroyMsg = (EntityDestroyMessage*)p_pMessage; if (pDestroyMsg->Data()->OwnerId == m_id) { entityId = pDestroyMsg->Data()->EntityId; assert(m_entities.Contains(entityId)); pEntity = GetEntity(entityId); pDestroyMsg->Data()->EntityType = pEntity->Type(); assert(pEntity); m_entities.erase(entityId); g_IMSysMgr.UnregisterGameObj(entityId); LogInfo("[%s] Unit '%s':%d destroyed", Enums[m_id], Enums[pEntity->Type()], pEntity->Id()); Toolbox::MemoryClean(pEntity); } }
void ArmyController::NotifyMessegeSent(_In_ Message* pMsg) { if (pMsg->TypeId() == MSG_EntityDestroy) { EntityDestroyMessage* pDestroyMsg = static_cast<EntityDestroyMessage*>(pMsg); _ASSERTE(pDestroyMsg && pDestroyMsg->Data()); if (pDestroyMsg->Data()->OwnerId == PLAYER_Self) { OnEntityLost(pDestroyMsg->Data()->EntityId); } } else if (pMsg->TypeId() == MSG_EntityRenegade) { EntityDestroyMessage* pDestroyMsg = static_cast<EntityDestroyMessage*>(pMsg); _ASSERTE(pDestroyMsg && pDestroyMsg->Data()); // One of my units changed control to another player if (pDestroyMsg->Data()->OwnerId != PLAYER_Self && m_entities.count(pDestroyMsg->Data()->EntityId) > 0) { OnEntityLost(pDestroyMsg->Data()->EntityId); } } }
void IStrategizer::GatherResourceAction::HandleMessage( RtsGame* pRtsGame, Message* p_msg, bool& p_consumed ) { if(PlanStepEx::State() == ESTATE_Executing && p_msg->MessageTypeID() == MSG_EntityDestroy) { EntityDestroyMessage* pMsg = static_cast<EntityDestroyMessage*>(p_msg); TID resourceId; if (pMsg->Data()->OwnerId != PLAYER_Neutral) return; assert(pMsg && pMsg->Data()); resourceId = pMsg->Data()->EntityId; if (resourceId != _resourceId) return; // Resource being gathered is destroyed, so adapt a new resource and gather it AbstractAdapter* pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); ResourceType resourceType = (ResourceType)_params[PARAM_ResourceId]; assert(pAdapter); _resourceId = pAdapter->AdaptResourceForGathering(resourceType, Parameters()); if(_resourceId != INVALID_TID) { GameEntity* pGameGatherer = g_Game->Self()->GetEntity(_gathererId); GameEntity* pGameResource = g_Game->GetPlayer(PLAYER_Neutral)->GetEntity(_resourceId); assert(pGameGatherer); assert(pGameResource); if (pGameGatherer->GatherResourceEntity(_resourceId)) { _gatherIssued = true; pGameGatherer->Lock(this); } } } }