bool TrainAction::Execute() { LogActivity(Execute); EntityClassType traineeType = (EntityClassType)_params[PARAM_EntityClassId]; GameEntity *pGameTrainer; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool executed = false; // Adapt trainer m_trainerId = pAdapter->AdaptBuildingForTraining(traineeType); if (m_trainerId != INVALID_TID) { // Issue train order pGameTrainer = g_Game->Self()->GetEntity(m_trainerId); _ASSERTE(pGameTrainer); executed = pGameTrainer->Train(traineeType); if (executed) { pGameTrainer->Lock(this); } } return executed; }
//---------------------------------------------------------------------------------------------- int BuildActionEx::ExecuteAux(unsigned long p_cycles) { EntityClassType builderType; EntityClassType buildingType; GameEntity *pGameBuilder; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); int ret; builderType = g_Game->Self()->GetWorkerType(); buildingType = (EntityClassType)_params[PARAM_BuildingClassId]; // Initialize build state _buildStarted = false; // Adapt build position assert(pAdapter); _buildPosition = pAdapter->AdaptPositionForBuilding(buildingType); // Adapt builder _builderId = pAdapter->AdaptWorkerForBuild(); // Issue build order pGameBuilder = g_Game->Self()->GetEntity(_builderId); assert(pGameBuilder); pGameBuilder->Lock(); ret = pGameBuilder->Build(buildingType, _buildPosition.X, _buildPosition.Y); return ret; }
bool ResearchAction::Execute(RtsGame& game, const WorldClock& p_clock) { // FIXME: because we don't have a goal for Research for now, we can use the action as a goal // at the same time, by not issuing the research action if it is already done if (game.Self()->TechTree()->ResearchDone((ResearchType)_params[PARAM_ResearchId])) return true; ResearchType researchType = (ResearchType)_params[PARAM_ResearchId]; GameEntity *pGameResearcher; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool executed = false; // Adapt researcher m_researcherId = pAdapter->AdaptBuildingForResearch(researchType); if (m_researcherId != INVALID_TID) { // Issue research order pGameResearcher = game.Self()->GetEntity(m_researcherId); _ASSERTE(pGameResearcher); executed = pGameResearcher->Research(researchType); if (executed) { pGameResearcher->Lock(this); } } return executed; }
//---------------------------------------------------------------------------------------------- bool AttackEntityAction::Execute(RtsGame& game, const WorldClock& p_clock) { EntityClassType attackerType = (EntityClassType)_params[PARAM_EntityClassId]; EntityClassType targetType = (EntityClassType)_params[PARAM_TargetEntityClassId]; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool executed = false; // Adapt attacker m_attackerId = pAdapter->GetEntityObjectId(attackerType,AdapterEx::AttackerStatesRank); if (m_attackerId != INVALID_TID) { m_targetId = pAdapter->AdaptTargetEntity(targetType, Parameters()); if (m_targetId != INVALID_TID) { GameEntity* pAttacker = game.Self()->GetEntity(m_attackerId); _ASSERTE(pAttacker); pAttacker->Lock(this); executed = pAttacker->AttackEntity(m_targetId); } } return executed; }
bool BuildActionEx::Execute(RtsGame& game, const WorldClock& p_clock) { EntityClassType buildingType = (EntityClassType)_params[PARAM_EntityClassId]; GameEntity *pGameBuilder; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool bOk = false; //// Adapt builder //_builderId = pAdapter->AdaptBuilder(buildingType, true); //// Adapt build position //_buildArea = pAdapter->AdaptPositionForBuilding(buildingType); // Adapt builder // Adapt build position auto adaptedParams = pAdapter->AdaptBuilderAndPosition(buildingType, true); _builderId = adaptedParams.first; _buildArea = adaptedParams.second; if (_builderId != INVALID_TID) { // Initialize build state _buildStarted = false; // Issue build order pGameBuilder = game.Self()->GetEntity(_builderId); LogInfo("Builder=%s was selected to execute build", pGameBuilder->ToString().c_str()); pGameBuilder->Lock(this); // Special buildings (for example addons) are not associated with build positions so no need to assert in that case. if (!game.GetEntityType(buildingType)->P(TP_IsSpecialBuilding)) { _ASSERTE(!_buildArea.IsNull()); _buildArea.Lock(this); } _ASSERTE(!_requiredResources.IsNull()); _requiredResources.Lock(this); bOk = pGameBuilder->Build(buildingType, _buildArea.Pos()); if (bOk) _buildIssued = true; } return bOk; }
//---------------------------------------------------------------------------------------------- bool MoveAction::ExecuteAux(RtsGame& game, const WorldClock& p_clock) { AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); EntityClassType entityType = (EntityClassType)_params[PARAM_EntityClassId]; //Adapt Entity _entityId = pAdapter->GetEntityObjectId(entityType, AdapterEx::EntityToMoveStatesRank); bool executed = false; if(_entityId != INVALID_TID) { //Adapt position _position = pAdapter->AdaptPosition(Parameters()); _pEntity = game.Self()->GetEntity(_entityId); _pEntity->Lock(this); _ASSERTE(_pEntity); executed = _pEntity->Move(_position); } return executed; }
bool BuildActionEx::ExecuteAux(RtsGame& game, const WorldClock& p_clock) { EntityClassType buildingType; GameEntity *pGameBuilder; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool bOk = false; // Adapt builder _builderId = pAdapter->GetEntityObjectId(game.Self()->GetWorkerType(),AdapterEx::WorkerStatesRankVector); if (_builderId != INVALID_TID) { buildingType = (EntityClassType)_params[PARAM_EntityClassId]; // Initialize build state _buildStarted = false; // Adapt build position assert(pAdapter); _buildArea = pAdapter->AdaptPositionForBuilding(buildingType); // Issue build order pGameBuilder = game.Self()->GetEntity(_builderId); assert(pGameBuilder); bOk = pGameBuilder->Build(buildingType, _buildArea.Pos()); if (bOk) { _buildIssued = true; pGameBuilder->Lock(this); assert(!_buildArea.IsNull()); _buildArea.Lock(this); assert(!_requiredResources.IsNull()); _requiredResources.Lock(this); } } return bOk; }
//---------------------------------------------------------------------------------------------- bool AttackGroundAction::Execute(RtsGame& game, const WorldClock& p_clock) { EntityClassType attackerType = (EntityClassType)_params[PARAM_EntityClassId]; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool executed = false; // Adapt attacker _attackerId = pAdapter->GetEntityObjectId(attackerType,AdapterEx::AttackerStatesRank); if (_attackerId != INVALID_TID) { GameEntity* pGameAttacker = game.Self()->GetEntity(_attackerId); _ASSERTE(pGameAttacker); pGameAttacker->Lock(this); // Adapt attack position _position = pAdapter->AdaptEnemyBorder(); executed = pGameAttacker->AttackGround(_position); } return executed; }
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); } } } }
bool IStrategizer::GatherResourceAction::ExecuteAux(RtsGame* pRtsGame, const WorldClock& p_clock ) { EntityClassType gathererType = (EntityClassType)_params[PARAM_EntityClassId]; ResourceType resourceType; AbstractAdapter* pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool bOK = false; // Adapt gatherer _gathererId = pAdapter->GetEntityObjectId(gathererType, AdapterEx::WorkerStatesRankVector); if(_gathererId != INVALID_TID) { resourceType = (ResourceType)_params[PARAM_ResourceId]; // Initialize gather state _gatherStarted = false; // Adapt resource id 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); bOK = pGameGatherer->GatherResourceEntity(_resourceId); if (bOK) { _gatherIssued = true; pGameGatherer->Lock(this); } } } return bOK; }
//---------------------------------------------------------------------------------------------- bool TrainAction::ExecuteAux(RtsGame& game, const WorldClock& clock) { LogActivity(ExecuteAux); EntityClassType traineeType = (EntityClassType)_params[PARAM_EntityClassId]; GameEntity *pGameTrainer; AbstractAdapter *pAdapter = g_OnlineCaseBasedPlanner->Reasoner()->Adapter(); bool executed = false; // Adapt trainer m_trainerId = pAdapter->AdaptBuildingForTraining(traineeType); if (m_trainerId != INVALID_TID) { // Issue train order pGameTrainer = game.Self()->GetEntity(m_trainerId); _ASSERTE(pGameTrainer); _ASSERTE(!m_requiredResources.IsNull()); m_requiredResources.Lock(this); executed = pGameTrainer->Train(traineeType); } return executed; }