Exemplo n.º 1
0
/**
 * @brief Make the UFOs run
 * @param[in] campaign The campaign data structure
 * @param[in] deltaTime The time passed since last call
 */
void UFO_CampaignRunUFOs (const campaign_t* campaign, int deltaTime)
{
	int ufoIdx, k;

	/* now the ufos are flying around, too - cycle backward - ufo might be destroyed */
	for (ufoIdx = ccs.numUFOs - 1; ufoIdx >= 0; ufoIdx--) {
		aircraft_t *ufo = UFO_GetByIDX(ufoIdx);
		/* don't run a landed ufo */
		if (ufo->landed)
			continue;

		/* Every UFO on geoscape should have a mission assigned */
		assert(ufo->mission);

		/* reached target and not following a phalanx aircraft? then we need a new destination */
		if (AIR_AircraftMakeMove(deltaTime, ufo) && ufo->status != AIR_UFO) {
			float *end;
			end = ufo->route.point[ufo->route.numPoints - 1];
			Vector2Copy(end, ufo->pos);
			MAP_CheckPositionBoundaries(ufo->pos);
			if (ufo->mission->stage == STAGE_INTERCEPT && ufo->mission->data.aircraft) {
				/* Attacking an installation: fly over this installation */
				UFO_SetRandomDestAround(ufo, ufo->mission->pos);
			} else
				UFO_SetRandomDest(ufo);
			if (CP_CheckNextStageDestination(campaign, ufo))
				/* UFO has been removed from game */
				continue;
			/* UFO was destroyed (maybe because the mission was removed) */
			if (ufoIdx == ccs.numUFOs)
				continue;
		}

		/* is there a PHALANX aircraft to shoot at ? */
		UFO_SearchAircraftTarget(campaign, ufo);

		/* antimatter tanks */
		if (ufo->fuel <= 0)
			ufo->fuel = ufo->stats[AIR_STATS_FUELSIZE];

		/* Update delay to launch next projectile */
		for (k = 0; k < ufo->maxWeapons; k++) {
			aircraftSlot_t *slot = &ufo->weapons[k];
			if (slot->delayNextShot > 0)
				slot->delayNextShot -= deltaTime;
		}
	}
}
Exemplo n.º 2
0
/**
 * @brief UFO starts to attack the installation.
 * @note Intercept mission -- Stage 2
 */
static void CP_InterceptAttackInstallation (mission_t* mission)
{
	const date_t minAttackDelay = {0, 3600};
	const date_t attackDelay = {0, 21600};		/* How long the UFO should stay on earth */
	installation_t* installation;
	vec3_t missionPos;

	mission->stage = STAGE_INTERCEPT;

	installation = mission->data.installation;
	Vector2Copy(mission->pos, missionPos);
	if (!VectorCompareEps(missionPos, installation->pos, UFO_EPSILON)) {
		mission->finalDate = ccs.date;
		return;
	}

	/* Make round around the position of the mission */
	UFO_SetRandomDestAround(mission->ufo, mission->pos);
	mission->finalDate = Date_Add(ccs.date, Date_Random(minAttackDelay, attackDelay));
}