本文整理汇总了C++中RtsGame类的典型用法代码示例。如果您正苦于以下问题:C++ RtsGame类的具体用法?C++ RtsGame怎么用?C++ RtsGame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RtsGame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FreeResources
void BuildActionEx::FreeResources(RtsGame &game)
{
if (_builderId != INVALID_TID)
{
if (!_buildArea.IsNull() && _buildArea.IsLocked())
{
// Special buildings (for example addons) are not associated with build positions so no need to assert in that case.
_ASSERTE(game.GetEntityType((EntityClassType)_params[PARAM_EntityClassId])->P(TP_IsSpecialBuilding) || !_buildArea.IsNull());
_buildArea.Unlock(this);
}
if (!_requiredResources.IsNull() && _requiredResources.IsLocked())
{
_requiredResources.Unlock(this);
}
if (_builderId != INVALID_TID)
{
GameEntity *pEntity = game.Self()->GetEntity(_builderId);
if (pEntity && pEntity->IsLocked())
{
pEntity->Unlock(this);
}
_builderId = INVALID_TID;
}
}
}
示例2: Execute
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;
}
示例3: AliveConditionsSatisfied
//----------------------------------------------------------------------------------------------
bool TrainAction::AliveConditionsSatisfied(RtsGame& game)
{
bool trainerExist = false;
bool traineeExist = false;
bool trainerBusy = false;
bool traineeBeingTrained = false;
bool success = false;
// 1. Trainer building exist
trainerExist = g_Assist.DoesEntityObjectExist(m_trainerId);
if (trainerExist)
{
if (m_trainStarted)
{
// 2. Trainer building is busy or in the training state
GameEntity* pTrainer = game.Self()->GetEntity(m_trainerId);
_ASSERTE(pTrainer);
ObjectStateType trainerState = (ObjectStateType)pTrainer->Attr(EOATTR_State);
trainerBusy = trainerState == OBJSTATE_Training;
// 3. The trainee unit object exist, i.e not cancel
traineeExist = g_Assist.DoesEntityObjectExist(m_traineeId);
if (traineeExist && !trainerBusy)
{
success = true;
}
else if (trainerBusy)
{
if (traineeExist)
{
// 4. Trainee is still being trained
GameEntity* pTrainee = game.Self()->GetEntity(m_traineeId);
_ASSERTE(pTrainee);
ObjectStateType traineeState = (ObjectStateType)pTrainee->Attr(EOATTR_State);
traineeBeingTrained = traineeState == OBJSTATE_BeingConstructed;
if (traineeBeingTrained || traineeState == OBJSTATE_Idle)
success = true;
}
}
}
else
{
success = true;
}
}
else
{
ConditionEx* failedCondition = new EntityClassExist(PLAYER_Self, m_trainerType, 1);
m_history.Add(ESTATE_Failed, failedCondition);
}
return success;
}
示例4: OnFailure
//----------------------------------------------------------------------------------------------
void AttackEntityAction::OnFailure(RtsGame& game, const WorldClock& p_clock)
{
GameEntity* pAttacker = game.Self()->GetEntity(m_attackerId);
if (pAttacker && pAttacker->IsLocked() && pAttacker->Owner() == this)
pAttacker->Unlock(this);
}
示例5: SuccessConditionsSatisfied
//----------------------------------------------------------------------------------------------
bool TrainAction::SuccessConditionsSatisfied(RtsGame& game)
{
bool success = false;
bool traineeBeingTrained = false;
if (m_trainStarted)
{
// 1. Trainee unit object exist
bool traineeExist = g_Assist.DoesEntityObjectExist(m_traineeId);
if (traineeExist)
{
// 2. Trainee is ready and no more being constructed
GameEntity* pTrainee = game.Self()->GetEntity(m_traineeId);
_ASSERTE(pTrainee);
ObjectStateType traineeState = (ObjectStateType)pTrainee->Attr(EOATTR_State);
traineeBeingTrained = traineeState == OBJSTATE_BeingConstructed;
if (!traineeBeingTrained)
{
LogInfo("Action %s succeeded to train trainee=%d from trainer=%d", ToString().c_str(), m_traineeId, m_trainerId);
success = true;
}
}
}
return success;
}
示例6: Execute
//----------------------------------------------------------------------------------------------
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;
}
示例7: HandleMessage
void BuildActionEx::HandleMessage(RtsGame& game, Message* p_msg, bool& p_consumed)
{
if(PlanStepEx::State() == ESTATE_Executing && p_msg->MessageTypeID() == MSG_EntityCreate)
{
EntityCreateMessage* pMsg = static_cast<EntityCreateMessage*>(p_msg);
TID buildingId;
GameEntity *pGameBuilding;
Vector2 msgBuildPosition;
if (pMsg->Data()->OwnerId != PLAYER_Self)
return;
assert(pMsg && pMsg->Data());
buildingId = pMsg->Data()->EntityId;
pGameBuilding = game.Self()->GetEntity(buildingId);
assert(pGameBuilding);
msgBuildPosition.X = pMsg->Data()->X;
msgBuildPosition.Y = pMsg->Data()->Y;
if (msgBuildPosition.X == _buildArea.Pos().X &&
msgBuildPosition.Y == _buildArea.Pos().Y &&
pGameBuilding->Type() == _params[PARAM_EntityClassId])
{
_buildingId = pGameBuilding->Id();
_buildStarted = true;
assert(!_requiredResources.IsNull());
_requiredResources.Unlock(this);
}
}
}
示例8: Execute
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;
}
示例9: Evaluate
bool ResearchDone::Evaluate(RtsGame& game)
{
_isSatisfied = game.GetPlayer((PlayerType)m_params[PARAM_PlayerId])->TechTree()->ResearchDone((ResearchType)m_params[PARAM_ResearchId]);
_isEvaluated = true;
return _isEvaluated && _isSatisfied;
}
示例10: SuccessConditionsSatisfied
//----------------------------------------------------------------------------------------------
bool WinGameGoal::SuccessConditionsSatisfied(RtsGame& game)
{
EntityList enemyEntities;
game.Enemy()->Entities(enemyEntities);
// All enemy units are destroyed, win game!
return enemyEntities.empty();
}
示例11: SuccessConditionsSatisfied
//----------------------------------------------------------------------------------------------
bool AttackGroundAction::SuccessConditionsSatisfied(RtsGame& game)
{
_ASSERTE(PlanStepEx::GetState() == ESTATE_Executing);
GameEntity* pGameAttacker = game.Self()->GetEntity(_attackerId);
_ASSERTE(pGameAttacker);
ObjectStateType attackerState = (ObjectStateType)pGameAttacker->P(OP_State);
return (attackerState == OBJSTATE_Attacking) || (attackerState == OBJSTATE_UnderAttack);
}
示例12: CellFeature
//---------------------------------------------------------------------------
bool EntityClassNearArea::Evaluate(RtsGame& pRtsGame)
{
vector<TID> entityIds;
pRtsGame.Self()->Entities((EntityClassType)_conditionParameters[PARAM_EntityClassId], entityIds);
Vector2 position = Vector2::Null();
ConditionEx::Evaluate(pRtsGame);
for (size_t i = 0; i < entityIds.size(); ++i)
{
position = pRtsGame.Map()->GetNearestCell(new CellFeature(_conditionParameters));
if (!position.IsNull())
{
_isSatisfied = true;
break;
}
}
return _isEvaluated && _isSatisfied;
}
示例13: HandleMessage
//----------------------------------------------------------------------------------------------
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);
}
}
}
}
示例14: ExecuteAux
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;
}
示例15: FreeResources
void ResearchAction::FreeResources(RtsGame& game)
{
if (m_researcherId != INVALID_TID)
{
GameEntity* pResearcher = game.Self()->GetEntity(m_researcherId);
if (pResearcher && pResearcher->IsLocked())
pResearcher->Unlock(this);
m_researcherId = INVALID_TID;
}
}