goal_hitswitch.cpp

来自「C人工智能游戏开发的一些实例源代码 C Game development in 」· C++ 代码 · 共 44 行

CPP
44
字号


Goal_HitSwitch::Goal_HitSwitch(AI* pAI, const PathNode *switchNode_) : Goal( pAI ), GoalQueue()
 switchNode(switchNode_), timer(0.0f), active(false)
{
	Assert(switchNode->flags & CPathNode::flagNodeSwitch);
	const CEntity *pEntity = switchNode->GetEntity();
	pSwitch = pEntity->Switch();
	Assert(pSwitch);
}

bool Goal_HitSwitch::ReplanSubgoals(){
	ResetSubgoals();
	NewSubgoal(new Goal_GotoNode(mpAI, switchNode)); //goto the switch
	NewSubgoal(new Goal_TurnToEntity(mpAI, pSwitch)); //turn towards the switch
	return true;
}

Goal_HitSwitch::~Goal_HitSwitch()
{
}

// Update the goal
void Goal_HitSwitch::Update( float secs_elapsed )
{	
	if (!active){
		ReplanSubgoals();
		active = true;
	}

	typeGoalStatus status = UpdateSubgoals( secs_elapsed );
	if (status==statusFailed) {
		mGoalStatus = statusFailed;	
		return; 
	}

	if (!NoSubgoals())
		return;

	mpAI->Nudge(pSwitch->ID()); //send an activation message to the switch

	mGoalStatus = statusSucceeded;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?