Example #1
0
bool CCommandAI::SkipParalyzeTarget(const CUnit* target)
{
	// check to see if we are about to paralyze a unit that is already paralyzed
	if ((target == NULL) || (owner->weapons.size() <= 0)) {
		return false;
	}
	const CWeapon* w = owner->weapons.front();
	if (!w->weaponDef->paralyzer) {
		return false;
	}
	// visible and stunned?
	if ((target->losStatus[owner->allyteam] & LOS_INLOS) && target->IsStunned() && HasMoreMoveCommands()) {
		return true;
	}
	return false;
}
Example #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();
	}
}
Example #3
0
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();
	}
}