コード例 #1
0
ファイル: AirCAI.cpp プロジェクト: 9heart/spring
void CAirCAI::ExecuteAreaAttack(Command& c)
{
    assert(owner->unitDef->canAttack);

    // FIXME: check owner->UsingScriptMoveType() and skip rest if true?
    AAirMoveType* myPlane = GetStrafeAirMoveType(owner);

    if (targetDied) {
        targetDied = false;
        inCommand = false;
    }

    const float3& pos = c.GetPos(0);
    const float radius = c.params[3];

    if (inCommand) {
        if (myPlane->aircraftState == AAirMoveType::AIRCRAFT_LANDED)
            inCommand = false;

        if (orderTarget && orderTarget->pos.SqDistance2D(pos) > Square(radius)) {
            inCommand = false;

            // target wandered out of the attack-area
            SetOrderTarget(NULL);
            SelectNewAreaAttackTargetOrPos(c);
        }
    } else {
        if (myPlane->aircraftState != AAirMoveType::AIRCRAFT_LANDED) {
            inCommand = true;

            SelectNewAreaAttackTargetOrPos(c);
        }
    }
}
コード例 #2
0
void CCommandAI::WeaponFired(CWeapon* weapon, const bool searchForNewTarget)
{
	if (!inCommand)
		return;

	const Command& c = commandQue.front();

	const bool haveGroundAttackCmd = (c.GetID() == CMD_ATTACK && c.GetParamsCount() >= 3);
	const bool haveAreaAttackCmd = (c.GetID() == CMD_AREA_ATTACK);

	bool orderFinished = false;

	if (searchForNewTarget) {
		// manual fire or attack commands with meta will only fire a single salvo
		// noAutoTarget weapons finish an attack commands after a
		// salvo if they have more orders queued
		if (weapon->weaponDef->manualfire && !(c.options & META_KEY))
			orderFinished = true;

		if (weapon->noAutoTarget && !(c.options & META_KEY) && haveGroundAttackCmd && HasMoreMoveCommands())
			orderFinished = true;

		// if we have an area-attack command and this was the
		// last salvo of our main weapon, assume we completed an attack
		// (run) on one position and move to the next
		//
		// if we have >= 2 consecutive CMD_ATTACK's, then
		//   SelectNAATP --> FinishCommand (inCommand=false) -->
		//   SlowUpdate --> ExecuteAttack (inCommand=true) -->
		//   queue has advanced
		//
		// @SelectNewAreaAttackTargetOrPos
		// return argument says if a new area attack target was chosen, else finish current command
		if (haveAreaAttackCmd) {
			orderFinished = !SelectNewAreaAttackTargetOrPos(c);
		}
	}

	// when this fails, we need to take a copy at top instead of a reference
	assert(&c == &commandQue.front());

	eoh->WeaponFired(*owner, *(weapon->weaponDef));
	if (orderFinished) {
		FinishCommand();
	}
}
コード例 #3
0
ファイル: CommandAI.cpp プロジェクト: AlexDiede/spring
void CCommandAI::WeaponFired(CWeapon* weapon, bool mainWeapon, bool lastSalvo)
{
	const Command& c = commandQue.empty()? Command(CMD_STOP): commandQue.front();

	const bool haveGroundAttackCmd = (c.GetID() == CMD_ATTACK && c.GetParamsCount() >= 3);
	const bool haveAreaAttackCmd = (c.GetID() == CMD_AREA_ATTACK);
	if (mainWeapon && lastSalvo && (haveAreaAttackCmd || (haveGroundAttackCmd && HasMoreMoveCommands()))) {
		// if we have an area-attack command (or a regular attack command
		// followed by anything that requires movement) and this was the
		// last salvo of our main weapon, assume we completed an attack
		// (run) on one position and move to the next
		SelectNewAreaAttackTargetOrPos(c);
	}

	if (!inCommand) { return; }
	if (!weapon->weaponDef->manualfire || (c.options & META_KEY)) { return; }

	if (c.GetID() == CMD_ATTACK || c.GetID() == CMD_MANUALFIRE) {
		owner->AttackUnit(NULL, (c.options & INTERNAL_ORDER) == 0, true);
		eoh->WeaponFired(*owner, *(weapon->weaponDef));
		FinishCommand();
	}
}