Esempio n. 1
0
/**
**  Handle AI of all players each game cycle.
*/
void PlayersEachCycle()
{
	for (int player = 0; player < NumPlayers; ++player) {
		CPlayer *p = &Players[player];
		if (p->AutoAttackTargets.size() > 0) {
			CUnitCache &autoatacktargets = p->AutoAttackTargets;
			/* both loops can not be connected !!!! */
			for (unsigned int i = 0; i < autoatacktargets.size();) {
				CUnit *aatarget = autoatacktargets[i];
				if (!aatarget->IsAliveOnMap() ||
					Map.Field(aatarget->Offset)->Guard[player] == 0) {
					autoatacktargets.Units.erase(autoatacktargets.Units.begin() + i);
					aatarget->RefsDecrease();
					continue;
				}
				++i;
			}
			if (autoatacktargets.size() > 0) {
				for (int j = 0; j < p->TotalNumUnits; ++j) {
					CUnit &guard = *p->Units[j];
					bool stand_ground = guard.CurrentAction() == UnitActionStandGround;
					if (guard.Type->CanAttack &&
								(stand_ground || guard.IsIdle()) &&
								 !guard.IsUnusable()) {
						AutoAttack(guard, autoatacktargets, stand_ground);
					}
				}
			}
		}
		if (p->AiEnabled) {
			AiEachCycle(p);
		}
	}
}
Esempio n. 2
0
/**
**  Handle AI of all players each game cycle.
*/
void PlayersEachCycle()
{
	for (int player = 0; player < NumPlayers; ++player) {
		CPlayer &p = Players[player];

		if (p.AiEnabled) {
			AiEachCycle(p);
		}
	}
}
Esempio n. 3
0
/**
**	Handle AI of all players each game cycle.
*/
global void PlayersEachCycle(void)
{
    int player;

    for( player=0; player<NumPlayers; ++player ) {
	if( Players[player].AiEnabled ) {
	    AiEachCycle(&Players[player]);
	}
    }
}
Esempio n. 4
0
/**
**  Handle AI of all players each game cycle.
*/
void PlayersEachCycle(void)
{
    if (!EnableAI)
        return;	// StratagusAI MOD

    for (int player = 0; player < NumPlayers; ++player) {
        if (Players[player].AiEnabled) {
            AiEachCycle(&Players[player]);
        }
    }
}
Esempio n. 5
0
/**
**  Handle AI of all players each game cycle.
*/
void PlayersEachCycle(void)
{
	for (int player = 0; player < NumPlayers; ++player) {
		CPlayer *p = &Players[player];

		// Update rate based economy
		for (int res = 0; res < MaxCosts; ++res) {
			int rate = p->ProductionRate[res] - p->ActualUtilizationRate[res];
			if (rate > 0) {
				if (p->StoredResources[res] < p->StorageCapacity[res]) {
					p->StoredResources[res] += rate;
					if (p->StoredResources[res] > p->StorageCapacity[res]) {
						p->StoredResources[res] = p->StorageCapacity[res];
					}
				}
			} else if (rate < 0) {
				rate = -rate;
//				Assert(p->StoredResources[res] >= rate);
				p->StoredResources[res] -= rate;
				if (p->StoredResources[res] < 0) {
					p->StoredResources[res] = 0;
				}
			}
			p->TotalResources[res] += p->ProductionRate[res];
		}

		// Recalculate costs
		std::map<CUnit *, int *>::iterator it;
		for (it = p->UnitsConsumingResourcesActual.begin(); it != p->UnitsConsumingResourcesActual.end(); ++it) {
			int costs[MaxCosts];
			CalculateCosts((*it).first, costs);
			p->UpdateUnitsConsumingResources((*it).first, costs);
		}

		// Ai
		if (p->AiEnabled) {
			AiEachCycle(p);
		}
	}
}