Ejemplo n.º 1
0
	bool operator()(const CUnit *const unit) const {
		if (unit->Type->CanAttack == false) {
			return *enemy == NULL;
		}
		if (FIND_TYPE == AIATTACK_RANGE) {
			*enemy = AttackUnitsInReactRange(*unit);
		} else if (FIND_TYPE == AIATTACK_ALLMAP) {
			*enemy = AttackUnitsInDistance(*unit, MaxMapWidth);
		} else if (FIND_TYPE == AIATTACK_BUILDING) {
			*enemy = AttackUnitsInDistance(*unit, MaxMapWidth, true);
			Assert(!*enemy || (*enemy)->Type->Building);
			if (*enemy == NULL) {
				*enemy = AttackUnitsInDistance(*unit, MaxMapWidth);
			}
		}
		return *enemy == NULL;
	}
Ejemplo n.º 2
0
/**
**  Attack units in attack range.
**
**  @param unit  Find unit in attack range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInRange(const CUnit &unit, CUnitFilter pred)
{
	//Wyrmgus start
//	Assert(unit.Type->CanAttack);
	Assert(unit.CanAttack());
//	return AttackUnitsInDistance(unit, unit.Stats->Variables[ATTACKRANGE_INDEX].Max, pred);
	return AttackUnitsInDistance(unit, unit.GetModifiedVariable(ATTACKRANGE_INDEX), pred);
	//Wyrmgus end
}
Ejemplo n.º 3
0
/**
**  Attack units in reaction range.
**
**  @param unit  Find unit in reaction range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInReactRange(const CUnit &unit, CUnitFilter pred)
{
	//Wyrmgus start
//	Assert(unit.Type->CanAttack);
	Assert(unit.CanAttack());
//	const int range = unit.Player->Type == PlayerPerson ? unit.Type->ReactRangePerson : unit.Type->ReactRangeComputer;
	const int range = unit.GetReactionRange();
	//Wyrmgus end
	return AttackUnitsInDistance(unit, range, pred);
}
Ejemplo n.º 4
0
/**
**  Attack units in reaction range.
**
**  @param unit  Find unit in reaction range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInReactRange(const CUnit *unit)
{
	int range;

	Assert(unit->Type->CanAttack);

	if (unit->Player->Type == PlayerPerson) {
		range = unit->Type->ReactRangePerson;
	} else {
		range = unit->Type->ReactRangeComputer;
	}

	return AttackUnitsInDistance(unit, range);
}
Ejemplo n.º 5
0
/**
**	Attack opponent with force.
**
**	@param force	Force number to attack with.
*/
global void AiAttackWithForce(int force)
{
    const AiUnit* aiunit;
    const Unit* enemy;
    int x;
    int y;

    AiCleanForce(force);

    AiPlayer->Force[force].Attacking=0;
    if( (aiunit=AiPlayer->Force[force].Units) ) {
	AiPlayer->Force[force].Attacking=1;

	enemy=NoUnitP;
	while( aiunit && !enemy ) {	// Use an unit that can attack
	    if( aiunit->Unit->Type->CanAttack ) {
		enemy = AttackUnitsInDistance(aiunit->Unit, MaxMapWidth);
	    }
	    aiunit=aiunit->Next;
	}

	if (!enemy) {
	    DebugLevel0Fn("Need to plan an attack with transporter\n");
	    if( !AiPlayer->Force[force].State 
		    && !AiPlanAttack(&AiPlayer->Force[force]) ) {
		DebugLevel0Fn("Can't transport, look for walls\n");
		if( !AiFindWall(&AiPlayer->Force[force]) ) {
		    AiPlayer->Force[force].Attacking=0;
		}
	    }
	    return;
	}
	AiPlayer->Force[force].State=0;
	x = enemy->X;
	y = enemy->Y;

	//
	//	Send all units in the force to enemy.
	//
	aiunit=AiPlayer->Force[force].Units;
	while( aiunit ) {
	    if( aiunit->Unit->Type->CanAttack ) {
		CommandAttack(aiunit->Unit, x, y, NULL,FlushCommands);
	    } else {
		CommandMove(aiunit->Unit, x, y, FlushCommands);
	    }
	    aiunit=aiunit->Next;
	}
    }
}
Ejemplo n.º 6
0
/**
**  Attack units in attack range.
**
**  @param unit  Find unit in attack range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInRange(const CUnit *unit)
{
	Assert(unit->Type->CanAttack);
	return AttackUnitsInDistance(unit, unit->Stats->Variables[ATTACKRANGE_INDEX].Max);
}
Ejemplo n.º 7
0
/**
**  Attack units in reaction range.
**
**  @param unit  Find unit in reaction range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInReactRange(const CUnit &unit, CUnitFilter pred)
{
	Assert(unit.Type->CanAttack);
	const int range = unit.Player->Type == PlayerPerson ? unit.Type->ReactRangePerson : unit.Type->ReactRangeComputer;
	return AttackUnitsInDistance(unit, range, pred);
}
Ejemplo n.º 8
0
/**
**  Attack units in attack range.
**
**  @param unit  Find unit in attack range for this unit.
**
**  @return      Pointer to unit which should be attacked.
*/
CUnit *AttackUnitsInRange(const CUnit &unit, CUnitFilter pred)
{
	Assert(unit.Type->CanAttack);
	return AttackUnitsInDistance(unit, unit.Stats->Variables[ATTACKRANGE_INDEX].Max, pred);
}
Ejemplo n.º 9
0
CUnit *AttackUnitsInDistance(const CUnit &unit, int range)
{
	return AttackUnitsInDistance(unit, range, NoFilter());
}