⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goal_gothroughdoor.cpp

📁 很好游戏代码
💻 CPP
字号:

#include "GoThroughDoor.h"
#include "Goal_GotoNode.h"
#include "Goal_FollowLink.h"
#include "NodeMapPrims.h"
#include "Goal_HitDoorSwitch.h"
#include "Door.h"

Goal_GoThroughDoor::Goal_GoThroughDoor(AI* pAI, const PathLink *pathlink)
										: Goal( pAI ), GoalQueue(), link(pathlink), active(false)
{
	LAssert(link->flags & PathLink::flagLinkDoor); //make sure the link was labeled with a door
	door = link->GetDoor();
	LAssert(door);
}

Goal_GoThroughDoor::~Goal_GoThroughDoor()
{
}

bool Goal_GoThroughDoor::ReplanSubgoals(){

	Door::DoorStatus doorStatus = door->GetDoorStatus();

	const PathNode *bestswitchnode = NULL;
	const Switch *bestswitch = NULL;
	//Now find the switch that is in the same noDoor region as the door entrance node
	for (int i=0; i < door->NumControllers(); i++){
		const CPathNode *sn = g_NodeMap.GetSwitchLocation(door->GetController(i));
		if (sn && sn->NoDoorsBetween(link->Start())){
			bestswitchnode = sn;
			bestswitch = door->GetController(i);
		}
	}
	if (bestswitchnode){ //otherwise, we're going to assume the door is nudgeable
		NewSubgoal(new Goal_HitDoorSwitch(mpAI, bestswitchnode, door)); //nudge the switch
	}
	NewSubgoal(new Goal_GotoNode(mpAI, link->Start()));
	NewSubgoal(new Goal_FollowLink(mpAI, link));
	
	return true;
}

// Update the goal
void Goal_GoThroughDoor::Update( float secs_elapsed )
{
	//if we haven't been activated yet, then we need to plan (replan) our subgoals
	if (!active){
		ReplanSubgoals();
		active = true;
		return;
	}
	
   mGoalStatus = UpdateSubgoals( secs_elapsed ); //update subgoals and set our status
}

⌨️ 快捷键说明

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