//---------------------------------------------------------------------------------------------- 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 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; }
//---------------------------------------------------------------------------------------------- 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 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; }
//---------------------------------------------------------------------------------------------- void TrainAction::HandleMessage(RtsGame& game, Message* pMsg, bool& consumed) { if (PlanStepEx::State() == ESTATE_Executing && pMsg->MessageTypeID() == MSG_EntityCreate) { EntityCreateMessage* pEntityMsg = static_cast<EntityCreateMessage*>(pMsg); _ASSERTE(pEntityMsg && pEntityMsg->Data()); if (pEntityMsg->Data()->OwnerId != PLAYER_Self) return; TID entityId = pEntityMsg->Data()->EntityId; GameEntity *pEntity = game.Self()->GetEntity(entityId); _ASSERTE(pEntity); // We are interested only in free trainees that have not been locked before if (!m_trainStarted && m_traineeId == INVALID_TID && pEntity->Type() == _params[PARAM_EntityClassId] && !pEntity->IsLocked()) { // Check if the trainer is training that entity GameEntity* pTrainer = game.Self()->GetEntity(m_trainerId); _ASSERTE(pTrainer); if (pTrainer->IsTraining(entityId)) { m_trainStarted = true; m_traineeId = entityId; m_pTrainee = pEntity; // Lock that trainee and bound it to this action because if we don't // other ready actions in the same update cycle will receive the same message // and they may bind to the same trainee pEntity->Lock(this); consumed = true; LogInfo("Action %s has bound trainee=%d to trainer=%d", ToString().c_str(), m_traineeId, m_trainerId); } } } }
//---------------------------------------------------------------------------------------------- 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; }