Пример #1
0
/**
**  Check what computer units can do with magic.
**  In fact, turn on autocast for AI.
*/
void AiCheckMagic()
{
	CPlayer &player = *AiPlayer->Player;
	const int n = player.GetUnitCount();

	for (int i = 0; i < n; ++i) {
		CUnit &unit = player.GetUnit(i);

		if (unit.Type->Spells.size() > 0) {
			// Check only idle magic units
			for (size_t i = 0; i != unit.Orders.size(); ++i) {
				if (unit.Orders[i]->Action == UnitActionSpellCast) {
					return;
				}
			}
			for (unsigned int j = 0; j < unit.Type->Spells.size(); ++j) {
				CSpell *spell = unit.Type->Spells[j];
				// Check if we can cast this spell. SpellIsAvailable checks for upgrades.
				if (spell->IsAvailableForUnit(unit)
					&& spell->AICast) {
					if (AutoCastSpell(unit, *spell)) {
						break;
					}
				}
			}
		}
	}
}
Пример #2
0
/**
**  Check what computer units can do with magic.
**  In fact, turn on autocast for AI.
*/
void AiCheckMagic()
{
	CPlayer &player = *AiPlayer->Player;
	const int n = player.GetUnitCount();

	for (int i = 0; i < n; ++i) {
		CUnit &unit = player.GetUnit(i);

		if (unit.Type->CanCastSpell) {
			// Check only idle magic units
			for (size_t i = 0; i != unit.Orders.size(); ++i) {
				if (unit.Orders[i]->Action == UnitActionSpellCast) {
					return;
				}
			}
			for (unsigned int j = 0; j < SpellTypeTable.size(); ++j) {
				// Check if we can cast this spell. SpellIsAvailable checks for upgrades.
				if (unit.Type->CanCastSpell[j] && SpellIsAvailable(player, j)
					&& SpellTypeTable[j]->AICast) {
					if (AutoCastSpell(unit, *SpellTypeTable[j])) {
						break;
					}
				}
			}
		}
	}
}
Пример #3
0
/**
**  Auto cast a spell if possible
**
**  @return  true if a spell was auto cast, false otherwise
*/
static bool AutoCast(CUnit *unit)
{
	if (unit->AutoCastSpell) {
		for (int i = 0; i < (int)SpellTypeTable.size(); ++i) {
			if (unit->AutoCastSpell[i] && AutoCastSpell(unit, SpellTypeTable[i])) {
				return true;
			}
		}
	}
	return false;
}
Пример #4
0
bool COrder_Still::AutoCastStand(CUnit &unit)
{
	if (!unit.Removed) { // Removed units can't cast any spells, from bunker)
		for (unsigned int i = 0; i < SpellTypeTable.size(); ++i) {
			if (unit.AutoCastSpell[i]
				&& (SpellTypeTable[i]->AutoCast || SpellTypeTable[i]->AICast)
				&& AutoCastSpell(unit, *SpellTypeTable[i])) {
				return true;
			}
		}
	}
	return false;
}
Пример #5
0
/**
**	@brief	Auto cast a spell if possible
**
**	@return	True if a spell was auto cast, false otherwise
*/
bool AutoCast(CUnit &unit)
{
	if (unit.AutoCastSpell && !unit.Removed) { // Removed units can't cast any spells, from bunker)
		for (unsigned int i = 0; i < CSpell::Spells.size(); ++i) {
			if (unit.AutoCastSpell[i]
				&& (CSpell::Spells[i]->AutoCast || CSpell::Spells[i]->AICast)
				&& AutoCastSpell(unit, *CSpell::Spells[i])) {
				return true;
			}
		}
	}
	return false;
}
Пример #6
0
/**
**  Check what computer units can do with magic.
**  In fact, turn on autocast for AI.
*/
void AiCheckMagic(void)
{
	const int n = AiPlayer->Player->TotalNumUnits;
	CUnit **units = AiPlayer->Player->Units;
	const CPlayer *player = AiPlayer->Player; /*units[0]->Player */

	for (int i = 0; i < n; ++i) {
		CUnit &unit = *units[i];

		// Check only magic units
		if (unit.Type->CanCastSpell) {
			for (unsigned int j = 0; j < SpellTypeTable.size(); ++j) {
				// Check if we can cast this spell. SpellIsAvailable checks for upgrades.
				if (unit.Type->CanCastSpell[j] && SpellIsAvailable(player, j) &&
					(SpellTypeTable[j]->AutoCast || SpellTypeTable[j]->AICast)) {
						AutoCastSpell(unit, SpellTypeTable[j]);
				}
			}
		}
	}
}
Пример #7
0
/**
**  Auto cast a spell
**
**  @param unit  The unit to cast a spell
*/
static void AiAutoCastSpell(CUnit *unit)
{
	if (!unit->Type->CanCastSpell)
	{
		return;
	}

	for (size_t i = 0; i < SpellTypeTable.size(); ++i)
	{
		// Check if we can cast this spell.
		if (unit->Type->CanCastSpell[i] &&
			(SpellTypeTable[i]->AutoCast || SpellTypeTable[i]->AICast))
		{
			if (AutoCastSpell(unit, SpellTypeTable[i]))
			{
				// Spell was cast
				return;
			}
		}
	}
}