Example #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);
		}
	}
}
Example #2
0
void MissileHandlePierce(Missile &missile, const Vec2i &pos)
{
	CUnit *unit = UnitOnMapTile(pos, -1);
	if (unit && unit->IsAliveOnMap()
		&& (missile.Type->FriendlyFire || unit->IsEnemy(*missile.SourceUnit->Player))) {
		missile.MissileHit(unit);
	}
}
Example #3
0
/**
**  Set teleport deastination for teleporter unit
**
**  @param l  Lua state.
*/
static int CclSetTeleportDestination(lua_State *l)
{
	LuaCheckArgs(l, 2);

	lua_pushvalue(l, 1);
	CUnit *unit = CclGetUnit(l);
	lua_pop(l, 1);
	if (unit->Type->Teleporter == false) {
		LuaError(l, "Unit not a teleporter");
	}
	lua_pushvalue(l, 2);
	CUnit *dest = CclGetUnit(l);
	lua_pop(l, 1);
	if (dest->IsAliveOnMap()) {
		unit->Goal = dest;
	}

	return 0;
}