Пример #1
0
/**
* 我发现队员的大脑已经变成了接受队伍消息的地方了,然后根据队伍消息来调整自己的目标 
*/
bool GoalCharacterThink::handleMessage( Telegram& msg )
{
    // 首先交给子目标处理
    if (forwardMessageToFrontMostSubgoal(msg)) return true;

    switch (msg.type)
    {
    case TELEGRAM_ENUM_TEAM_COLLECTIVE_FORWARD:                 // 队伍通知手下跟随队伍前进
        {
            m_pOwner->getSteeringBehaviros()->keepFormationOn();
            return true;
        }

    case TELEGRAM_ENUM_TEAM_CANCEL_COLLECTIVE_FORWARD:          // 队伍通知手下不用跟随队伍了
        {
            m_pOwner->getSteeringBehaviros()->keepFormationOff();
            return true;
        }

    case TELEGRAM_ENUM_TEAM_ATTACK_SPECIFIED_TARGET:            // 队伍命令手下攻击指定目标
        {
            // 删除所有的当前任务,然后设定新的任务
            removeAllSubgoals();
            int tmpTargetId =   (int)msg.extraInfo;
            addSubgoal(new GoalAttackSpecifiedTarget(m_pOwner, tmpTargetId));
            return true;
        }

    default:
        break;
    }

    return false;
}
Пример #2
0
//------------------------------- Activate ------------------------------------
//-----------------------------------------------------------------------------
void GoalAttackTarget::activate()
{
	_status = ACTIVE;

	//if this goal is reactivated then there may be some existing subgoals that
	//must be removed
	removeAllSubgoals();

	//it is possible for a bot's target to die whilst this goal is active so we
	//must test to make sure the bot always has an active target
	if (!_owner->getTargetSys()->isTargetPresent())
	{
		_status = COMPLETED;

		return;
	}

	//if the bot is able to shoot the target (there is LOS between bot and target),
	//then select a tactic to follow while shooting
	if (_owner->getTargetSys()->isTargetAttackable())
	{
		addSubgoal(new GoalMainAttack(_owner));
	}

	//if the target is not visible, go hunt it.
	else
	{
		if (_owner->getType() != BaseGameEntity::TOWER_CHARACTER)
			addSubgoal(new GoalHuntTarget(_owner));
		//addSubgoal(new GoalHuntTarget(_owner));
	}
}
Пример #3
0
void GoalThink::addGoal_HoldPosition(const cocos2d::Vec2& destination)
{
	if (notPresent(GOAL_HOLD_POSITION))
	{
		removeAllSubgoals();
		addSubgoal(new GoalHoldPosition(_owner, destination));
	}
}
Пример #4
0
void GoalThink::addGoal_AttackTarget()
{
	if (notPresent(GOAL_ATTACK_TARGET))
	{
		removeAllSubgoals();
		addSubgoal(new GoalAttackTarget(_owner));
	}
}
Пример #5
0
void GoalThink::addGoal_Explore()
{
	if (notPresent(GOAL_EXPLORE))
	{
		removeAllSubgoals();
		addSubgoal(new GoalExplore(_owner));
	}
}
	void Goal_MoveToPosition::activate()
	{
		setStatus(Status::ACTIVE);

		removeAllSubgoals();

		std::list<sf::Vector2f> path;
		if (mOwner.getPathPlanner().createPathToPosition(mPosition, path))
		{
			addSubgoal<Goal_FollowPath>(mOwner, std::move(path));
		}
	}
Пример #7
0
void GoalThink::addGoal_PersistanceAttack()
{
	if (_owner->getTargetSys()->isTargetPresent())
	{
		if (notPresent(GOAL_PERSISTANCE_ATTACK))
		{
			removeAllSubgoals();
			addSubgoal(new GoalPersistanceAttack(_owner));
		}
	}
	else
	{
		CCLOG("no target!");
	}
}