Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 5e5574c77a0dbd6a6f3c0a410de7c606ed515689 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Tam=C3=A1s=20Feh=C3=A9rv=C3=A1ri?= <geever@users.sourceforge.net>
- Date: Sun, 7 Nov 2010 03:26:24 +0100
- Subject: [PATCH] * optimize the aircraft loops (with AIR_Foreach)
- ---
- src/client/campaign/cp_aircraft.c | 247 +++++++++++++--------------
- src/client/campaign/cp_aircraft.h | 3 +
- src/client/campaign/cp_aircraft_callbacks.c | 8 +-
- src/client/campaign/cp_base.c | 8 +-
- src/client/campaign/cp_employee.c | 7 +-
- src/client/campaign/cp_map.c | 59 +++----
- src/client/campaign/cp_mapfightequip.c | 32 ++--
- src/client/campaign/cp_market_callbacks.c | 10 +-
- src/client/campaign/cp_nation.c | 12 +-
- src/client/campaign/cp_popup.c | 109 ++++++-------
- src/client/campaign/cp_radar.c | 59 +++----
- src/client/campaign/cp_research.c | 13 +-
- src/client/campaign/cp_statistics.c | 11 +-
- src/client/campaign/cp_team_callbacks.c | 11 +-
- src/client/campaign/cp_transfer_callbacks.c | 12 +-
- src/client/campaign/cp_ufo.c | 76 ++++-----
- 16 files changed, 319 insertions(+), 358 deletions(-)
- diff --git a/src/client/campaign/cp_aircraft.c b/src/client/campaign/cp_aircraft.c
- index 9d61831..604324d 100644
- --- a/src/client/campaign/cp_aircraft.c
- +++ b/src/client/campaign/cp_aircraft.c
- @@ -85,11 +85,13 @@ qboolean AIR_BaseHasAircraft (const base_t *base)
- */
- int AIR_BaseCountAircraft (const base_t *base)
- {
- - aircraft_t *aircraft = NULL;
- + aircraft_t *aircraft;
- int count = 0;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - count++;
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base))
- + count++;
- + }
- return count;
- }
- @@ -162,9 +164,10 @@ void AIR_UpdateHangarCapForAll (base_t *base)
- base->capacities[CAP_AIRCRAFT_BIG].cur = 0;
- base->capacities[CAP_AIRCRAFT_SMALL].cur = 0;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - AIR_UpdateHangarCapForOne(aircraft->tpl, base);
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base))
- + AIR_UpdateHangarCapForOne(aircraft->tpl, base);
- + }
- }
- #ifdef DEBUG
- @@ -183,8 +186,7 @@ void AIR_ListAircraft_f (void)
- base = B_GetFoundedBaseByIDX(baseIdx);
- }
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNext(aircraft)) != NULL) {
- + AIR_Foreach(aircraft) {
- int k;
- linkedList_t *l;
- @@ -541,11 +543,10 @@ int AIR_CountTypeInBase (const base_t *base, aircraftType_t aircraftType)
- int count = 0;
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (aircraft->type == aircraftType)
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && aircraft->type == aircraftType)
- count++;
- -
- + }
- return count;
- }
- @@ -559,11 +560,10 @@ int AIR_CountInBaseByTemplate (const base_t *base, const aircraft_t *aircraftTem
- int count = 0;
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (aircraft->tpl == aircraftTemplate)
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && aircraft->tpl == aircraftTemplate)
- count++;
- -
- + }
- return count;
- }
- @@ -691,6 +691,7 @@ void AIR_AircraftReturnToBase (aircraft_t *aircraft)
- * @brief Returns the index of the aircraft in the base->aircraft array.
- * @param[in] aircraft The aircraft to get the index for.
- * @return The array index or AIRCRAFT_INBASE_INVALID on error.
- + * @todo Remove this! Aircraft no longer have local index per base
- */
- int AIR_GetAircraftIDXInBase (const aircraft_t* aircraft)
- {
- @@ -719,6 +720,7 @@ int AIR_GetAircraftIDXInBase (const aircraft_t* aircraft)
- * @param base The base to get the aircraft from
- * @param index The index of the aircraft in the given base
- * @return @c NULL if there is no such aircraft in the given base, or the aircraft pointer that belongs to the given index.
- + * @todo Remove this! Aircraft no longer have local index per base
- */
- aircraft_t *AIR_GetAircraftFromBaseByIDXSafe (base_t* base, int index)
- {
- @@ -1276,49 +1278,48 @@ void CL_CampaignRunAircraft (campaign_t* campaign, int dt, qboolean updateRadarO
- assert(dt >= 0);
- if (dt > 0) {
- - base_t *base = NULL;
- -
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- - /* Run each aircraft */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - int k;
- - assert(aircraft->homebase);
- - if (aircraft->status == AIR_IDLE) {
- - /* Aircraft idle out of base */
- - aircraft->fuel -= dt;
- - } else if (AIR_IsAircraftOnGeoscape(aircraft)) {
- - AIR_Move(aircraft, dt);
- - /* radar overlay should be updated */
- - radarOverlayReset = qtrue;
- - } else if (aircraft->status == AIR_REFUEL) {
- - AIR_Refuel(aircraft, dt);
- - }
- + aircraft_t *aircraft;
- - /* Check aircraft low fuel (only if aircraft is not already returning to base or in base) */
- - if (aircraft->status != AIR_RETURNING && AIR_IsAircraftOnGeoscape(aircraft) &&
- - !AIR_AircraftHasEnoughFuel(aircraft, aircraft->pos)) {
- - /** @todo check if aircraft can go to a closer base with free space */
- - MS_AddNewMessage(_("Notice"), va(_("Craft %s is low on fuel and must return to base."), aircraft->name), qfalse, MSG_STANDARD, NULL);
- - AIR_AircraftReturnToBase(aircraft);
- - }
- + /* Run each aircraft */
- + AIR_Foreach(aircraft) {
- + int k;
- - /* Aircraft purchasing ufo */
- - if (aircraft->status == AIR_UFO) {
- - /* Solve the fight */
- - AIRFIGHT_ExecuteActions(campaign, aircraft, aircraft->aircraftTarget);
- - }
- + if (aircraft->status == AIR_CRASHED)
- + continue;
- - for (k = 0; k < aircraft->maxWeapons; k++) {
- - /* Update delay to launch next projectile */
- - if (AIR_IsAircraftOnGeoscape(aircraft) && (aircraft->weapons[k].delayNextShot > 0))
- - aircraft->weapons[k].delayNextShot -= dt;
- - /* Reload if needed */
- - if (aircraft->weapons[k].ammoLeft <= 0)
- - AII_ReloadWeapon(&aircraft->weapons[k]);
- - }
- + assert(aircraft->homebase);
- + if (aircraft->status == AIR_IDLE) {
- + /* Aircraft idle out of base */
- + aircraft->fuel -= dt;
- + } else if (AIR_IsAircraftOnGeoscape(aircraft)) {
- + AIR_Move(aircraft, dt);
- + /* radar overlay should be updated */
- + radarOverlayReset = qtrue;
- + } else if (aircraft->status == AIR_REFUEL) {
- + AIR_Refuel(aircraft, dt);
- + }
- +
- + /* Check aircraft low fuel (only if aircraft is not already returning to base or in base) */
- + if (aircraft->status != AIR_RETURNING && AIR_IsAircraftOnGeoscape(aircraft) &&
- + !AIR_AircraftHasEnoughFuel(aircraft, aircraft->pos)) {
- + /** @todo check if aircraft can go to a closer base with free space */
- + MS_AddNewMessage(_("Notice"), va(_("Craft %s is low on fuel and must return to base."), aircraft->name), qfalse, MSG_STANDARD, NULL);
- + AIR_AircraftReturnToBase(aircraft);
- + }
- +
- + /* Aircraft purchasing ufo */
- + if (aircraft->status == AIR_UFO) {
- + /* Solve the fight */
- + AIRFIGHT_ExecuteActions(campaign, aircraft, aircraft->aircraftTarget);
- + }
- +
- + for (k = 0; k < aircraft->maxWeapons; k++) {
- + /* Update delay to launch next projectile */
- + if (AIR_IsAircraftOnGeoscape(aircraft) && (aircraft->weapons[k].delayNextShot > 0))
- + aircraft->weapons[k].delayNextShot -= dt;
- + /* Reload if needed */
- + if (aircraft->weapons[k].ammoLeft <= 0)
- + AII_ReloadWeapon(&aircraft->weapons[k]);
- }
- }
- }
- @@ -1336,8 +1337,9 @@ void CL_CampaignRunAircraft (campaign_t* campaign, int dt, qboolean updateRadarO
- */
- aircraft_t* AIR_AircraftGetFromIDX (int aircraftIdx)
- {
- - aircraft_t* aircraft = NULL;
- - while ((aircraft = AIR_GetNext(aircraft)) != NULL) {
- + aircraft_t* aircraft;
- +
- + AIR_Foreach(aircraft) {
- if (aircraft->idx == aircraftIdx) {
- Com_DPrintf(DEBUG_CLIENT, "AIR_AircraftGetFromIDX: aircraft idx: %i\n", aircraft->idx);
- return aircraft;
- @@ -1779,8 +1781,7 @@ void AIR_ListCraftIndexes_f (void)
- aircraft_t *aircraft;
- Com_Printf("globalIDX\t(Craftname)\n");
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNext(aircraft)) != NULL) {
- + AIR_Foreach(aircraft) {
- Com_Printf("%i\t(%s)\n", aircraft->idx, aircraft->name);
- }
- }
- @@ -1818,19 +1819,17 @@ Aircraft functions related to UFOs or missions.
- ===============================================*/
- /**
- - * @brief Notify that a mission has been removed.
- - * @note Aircraft currently moving to the mission will be redirect to base
- + * @brief Notify aircraft that a mission has been removed.
- * @param[in] mission Pointer to the mission that has been removed.
- + * @note Aircraft currently moving to the mission will be redirect to base
- */
- void AIR_AircraftsNotifyMissionRemoved (const mission_t *const mission)
- {
- - base_t *base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t* aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (aircraft->status == AIR_MISSION && aircraft->mission == mission)
- - AIR_AircraftReturnToBase(aircraft);
- - }
- + aircraft_t* aircraft;
- +
- + AIR_Foreach(aircraft) {
- + if (aircraft->status == AIR_MISSION && aircraft->mission == mission)
- + AIR_AircraftReturnToBase(aircraft);
- }
- }
- @@ -1842,12 +1841,24 @@ void AIR_AircraftsNotifyMissionRemoved (const mission_t *const mission)
- void AIR_AircraftsNotifyUFORemoved (const aircraft_t *const ufo, qboolean destroyed)
- {
- base_t *base;
- + aircraft_t* aircraft;
- assert(ufo);
- + /* Aircraft currently purchasing the specified ufo will be redirect to base */
- + AIR_Foreach(aircraft) {
- + if (aircraft->status == AIR_UFO) {
- + if (ufo == aircraft->aircraftTarget) {
- + AIR_AircraftReturnToBase(aircraft);
- + } else if (destroyed && (ufo < aircraft->aircraftTarget)) {
- + aircraft->aircraftTarget--;
- + }
- + }
- + }
- +
- + /** @todo this should be in a BDEF_NotifyUFORemoved callback */
- base = NULL;
- while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t* aircraft;
- int i;
- /* Base currently targeting the specified ufo loose their target */
- for (i = 0; i < base->numBatteries; i++) {
- @@ -1864,34 +1875,21 @@ void AIR_AircraftsNotifyUFORemoved (const aircraft_t *const ufo, qboolean destro
- else if (destroyed && (baseWeapon->target > ufo))
- baseWeapon->target--;
- }
- - /* Aircraft currently purchasing the specified ufo will be redirect to base */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (aircraft->status == AIR_UFO) {
- - if (ufo == aircraft->aircraftTarget)
- - AIR_AircraftReturnToBase(aircraft);
- - else if (destroyed && (ufo < aircraft->aircraftTarget)) {
- - aircraft->aircraftTarget--;
- - }
- - }
- }
- }
- /**
- * @brief Notify that a UFO disappear from radars.
- - * @note Aircraft currently pursuing the specified UFO will be redirected to base
- * @param[in] ufo Pointer to a UFO that has disappeared.
- + * @note Aircraft currently pursuing the specified UFO will be redirected to base
- */
- void AIR_AircraftsUFODisappear (const aircraft_t *const ufo)
- {
- - base_t *base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (aircraft->status == AIR_UFO)
- - if (ufo == aircraft->aircraftTarget)
- - AIR_AircraftReturnToBase(aircraft);
- - }
- + aircraft_t *aircraft;
- +
- + AIR_Foreach(aircraft) {
- + if (aircraft->status == AIR_UFO && ufo == aircraft->aircraftTarget)
- + AIR_AircraftReturnToBase(aircraft);
- }
- }
- @@ -2295,9 +2293,8 @@ void AIR_AutoAddPilotToAircraft (const base_t* base, employee_t* pilot)
- {
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_SetPilot(aircraft, pilot))
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && AIR_SetPilot(aircraft, pilot))
- break;
- }
- }
- @@ -2312,9 +2309,8 @@ void AIR_RemovePilotFromAssignedAircraft (const base_t* base, const employee_t*
- {
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_GetPilot(aircraft) == pilot) {
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && AIR_GetPilot(aircraft) == pilot) {
- AIR_SetPilot(aircraft, NULL);
- break;
- }
- @@ -2549,9 +2545,9 @@ qboolean AIR_SaveXML (mxml_node_t *parent)
- /* save phalanx aircraft */
- snode = mxml_AddNode(parent, SAVE_AIRCRAFT_PHALANX);
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNext(aircraft)) != NULL)
- + AIR_Foreach(aircraft) {
- AIR_SaveAircraftXML(snode, aircraft, qfalse);
- + }
- /* save the ufos on geoscape */
- snode = mxml_AddNode(parent, SAVE_AIRCRAFT_UFOS);
- @@ -2870,24 +2866,21 @@ qboolean AIR_LoadXML (mxml_node_t *parent)
- static qboolean AIR_PostLoadInitMissions (void)
- {
- qboolean success = qtrue;
- + aircraft_t *aircraft;
- aircraft_t *ufo;
- - base_t *base = NULL;
- /* PHALANX aircraft */
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft))) {
- - if (!aircraft->missionID || aircraft->missionID[0] == '\0')
- - continue;
- - aircraft->mission = CP_GetMissionByID(aircraft->missionID);
- - if (!aircraft->mission) {
- - Com_Printf("Aircraft %s (idx: %i) is linked to an invalid mission: %s\n", aircraft->name, aircraft->idx, aircraft->missionID);
- - if (aircraft->status == AIR_MISSION)
- - AIR_AircraftReturnToBase(aircraft);
- - }
- - Mem_Free(aircraft->missionID);
- - aircraft->missionID = NULL;
- + AIR_Foreach(aircraft) {
- + if (!aircraft->missionID || aircraft->missionID[0] == '\0')
- + continue;
- + aircraft->mission = CP_GetMissionByID(aircraft->missionID);
- + if (!aircraft->mission) {
- + Com_Printf("Aircraft %s (idx: %i) is linked to an invalid mission: %s\n", aircraft->name, aircraft->idx, aircraft->missionID);
- + if (aircraft->status == AIR_MISSION)
- + AIR_AircraftReturnToBase(aircraft);
- }
- + Mem_Free(aircraft->missionID);
- + aircraft->missionID = NULL;
- }
- /* UFOs */
- @@ -3009,9 +3002,9 @@ int AIR_CalculateHangarStorage (const aircraft_t *aircraftTemplate, const base_t
- assert(aircraftTemplate);
- assert(aircraftTemplate == aircraftTemplate->tpl); /* Make sure it's an aircraft template. */
- - if (!base->founded)
- + if (!base->founded) {
- return -1;
- - else {
- + } else {
- const int aircraftCapacity = AIR_GetCapacityByAircraftWeight(aircraftTemplate);
- /* If this is a small aircraft, we will check space in small hangar.
- * If this is a large aircraft, we will check space in big hangar. */
- @@ -3035,17 +3028,12 @@ qboolean AIR_RemoveEmployee (employee_t *employee, aircraft_t *aircraft)
- /* If no aircraft is given we search if he is in _any_ aircraft and set
- * the aircraft pointer to it. */
- if (!aircraft) {
- - base_t *base = NULL;
- - while ((base = B_GetNext(base)) != NULL) {
- - aircraft_t *acTemp = NULL;
- - while ((acTemp = AIR_GetNextFromBase(base, acTemp))) {
- - if (AIR_IsEmployeeInAircraft(employee, acTemp)) {
- - aircraft = acTemp;
- - break;
- - }
- - }
- - if (aircraft)
- + aircraft_t *acTemp;
- + AIR_Foreach(acTemp) {
- + if (AIR_IsEmployeeInAircraft(employee, acTemp)) {
- + aircraft = acTemp;
- break;
- + }
- }
- if (!aircraft)
- return qfalse;
- @@ -3075,13 +3063,10 @@ const aircraft_t *AIR_IsEmployeeInAircraft (const employee_t *employee, const ai
- /* If no aircraft is given we search if he is in _any_ aircraft and return true if that's the case. */
- if (!aircraft) {
- - base_t *base = NULL;
- - while ((base = B_GetNext(base)) != NULL) {
- - aircraft_t *aircraftByIDX = NULL;
- - while ((aircraftByIDX = AIR_GetNextFromBase(base, aircraftByIDX))) {
- - if (AIR_IsEmployeeInAircraft(employee, aircraftByIDX))
- - return aircraftByIDX;
- - }
- + aircraft_t *anyAircraft;
- + AIR_Foreach(anyAircraft) {
- + if (AIR_IsEmployeeInAircraft(employee, anyAircraft))
- + return anyAircraft;
- }
- return NULL;
- }
- @@ -3281,7 +3266,7 @@ void AIR_Shutdown (void)
- craft = NULL;
- while ((craft = AIR_GetNext(craft)))
- - LIST_Delete(&craft->acTeam);
- + AIR_ResetAircraftTeam(craft);
- LIST_Delete(&ccs.aircraft);
- AIR_ShutdownCallbacks();
- diff --git a/src/client/campaign/cp_aircraft.h b/src/client/campaign/cp_aircraft.h
- index f928ddb..2143d81 100644
- --- a/src/client/campaign/cp_aircraft.h
- +++ b/src/client/campaign/cp_aircraft.h
- @@ -240,6 +240,9 @@ void AIR_ListAircraftSamples_f(void);
- void AIR_ListCraftIndexes_f(void);
- #endif
- +#define AIR_IsAircraftOfBase(aircraft, base) ((aircraft)->homebase == (base) && (aircraft)->status != AIR_CRASHED)
- +#define AIR_Foreach(var) LIST_Foreach(ccs.aircraft, aircraft_t, var)
- +
- aircraft_t *AIR_Add(struct base_s *base, const aircraft_t *aircraftTemplate);
- qboolean AIR_Delete(struct base_s *base, const aircraft_t *aircraft);
- diff --git a/src/client/campaign/cp_aircraft_callbacks.c b/src/client/campaign/cp_aircraft_callbacks.c
- index 67497c5..d901ac1 100644
- --- a/src/client/campaign/cp_aircraft_callbacks.c
- +++ b/src/client/campaign/cp_aircraft_callbacks.c
- @@ -223,6 +223,7 @@ void AIR_AircraftSelect (aircraft_t* aircraft)
- UI_RegisterText(TEXT_AIRCRAFT_INFO, aircraftInfo);
- + /** @todo This shouldn't exists. UI should use the global idx as reference */
- /* compute the ID and... */
- aircraftInBase = NULL;
- id = 0;
- @@ -248,9 +249,10 @@ static void AIR_AircraftUpdateList_f (void)
- base_t *base = B_GetCurrentSelectedBase();
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - LIST_AddString(&list, aircraft->name);
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base))
- + LIST_AddString(&list, aircraft->name);
- + }
- UI_RegisterLinkedListText(TEXT_AIRCRAFT_LIST, list);
- }
- diff --git a/src/client/campaign/cp_base.c b/src/client/campaign/cp_base.c
- index 5dec3b9..fe217a0 100644
- --- a/src/client/campaign/cp_base.c
- +++ b/src/client/campaign/cp_base.c
- @@ -702,15 +702,19 @@ void B_RemoveAircraftExceedingCapacity (base_t* base, buildingType_t buildingTyp
- linkedList_t *awayAircraft = NULL;
- int numAwayAircraft;
- int randomNum;
- - aircraft_t *aircraft = NULL;
- + aircraft_t *aircraft;
- /* destroy aircraft only if there's not enough hangar (hangar is already destroyed) */
- if (B_FreeCapacity(base, capacity) >= 0)
- return;
- /* destroy one aircraft (must not be sold: may be destroyed by aliens) */
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- + AIR_Foreach(aircraft) {
- const int aircraftSize = aircraft->size;
- +
- + if (!AIR_IsAircraftOfBase(aircraft, base))
- + continue;
- +
- switch (aircraftSize) {
- case AIRCRAFT_SMALL:
- if (buildingType != B_SMALL_HANGAR)
- diff --git a/src/client/campaign/cp_employee.c b/src/client/campaign/cp_employee.c
- index 4a3f8d8..94dac96 100644
- --- a/src/client/campaign/cp_employee.c
- +++ b/src/client/campaign/cp_employee.c
- @@ -87,11 +87,10 @@ qboolean E_IsAwayFromBase (const employee_t *employee)
- base = employee->baseHired;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (!AIR_IsAircraftInBase(aircraft) && AIR_IsInAircraftTeam(aircraft, employee))
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && !AIR_IsAircraftInBase(aircraft) && AIR_IsInAircraftTeam(aircraft, employee))
- return qtrue;
- -
- + }
- return qfalse;
- }
- diff --git a/src/client/campaign/cp_map.c b/src/client/campaign/cp_map.c
- index 9ac2073..513e342 100644
- --- a/src/client/campaign/cp_map.c
- +++ b/src/client/campaign/cp_map.c
- @@ -270,7 +270,9 @@ static void MAP_MultiSelectExecuteAction_f (void)
- */
- void MAP_MapClick (uiNode_t* node, int x, int y)
- {
- + aircraft_t *aircraft;
- aircraft_t *ufo;
- + base_t *base;
- int i;
- vec2_t pos;
- const linkedList_t *list;
- @@ -331,22 +333,17 @@ void MAP_MapClick (uiNode_t* node, int x, int y)
- CP_MissionToTypeString(tempMission), _(tempMission->location));
- }
- - /* Get selected bases */
- - for (i = 0; i < MAX_BASES && multiSelect.nbSelect < MULTISELECT_MAXSELECT; i++) {
- - const base_t *base = B_GetFoundedBaseByIDX(i);
- - aircraft_t *aircraft;
- -
- - if (!base)
- - continue;
- + /* Get selected aircraft which belong */
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOnGeoscape(aircraft) && aircraft->fuel > 0 && MAP_IsMapPositionSelected(node, aircraft->pos, x, y))
- + MAP_MultiSelectListAddItem(MULTISELECT_TYPE_AIRCRAFT, aircraft->idx, _("Aircraft"), aircraft->name);
- + }
- + /* Get selected bases */
- + base = NULL;
- + while ((base = B_GetNext(base)) != NULL && multiSelect.nbSelect < MULTISELECT_MAXSELECT) {
- if (MAP_IsMapPositionSelected(node, base->pos, x, y))
- - MAP_MultiSelectListAddItem(MULTISELECT_TYPE_BASE, i, _("Base"), base->name);
- -
- - /* Get selected aircraft which belong to the base */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (AIR_IsAircraftOnGeoscape(aircraft) && aircraft->fuel > 0 && MAP_IsMapPositionSelected(node, aircraft->pos, x, y))
- - MAP_MultiSelectListAddItem(MULTISELECT_TYPE_AIRCRAFT, aircraft->idx, _("Aircraft"), aircraft->name);
- + MAP_MultiSelectListAddItem(MULTISELECT_TYPE_BASE, base->idx, _("Base"), base->name);
- }
- /* Get selected installations */
- @@ -1115,6 +1112,7 @@ static void MAP_GetGeoscapeAngle (float *vector)
- int counter = 0;
- int maxEventIdx;
- const int numMissions = CP_CountMissionOnGeoscape();
- + aircraft_t *aircraft;
- aircraft_t *ufo;
- base_t *base;
- int numBases = B_GetCount();
- @@ -1193,18 +1191,14 @@ static void MAP_GetGeoscapeAngle (float *vector)
- counter += ccs.numInstallations;
- /* Cycle through aircraft (only those present on geoscape) */
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_IsAircraftOnGeoscape(aircraft)) {
- - if (centerOnEventIdx == counter) {
- - MAP_ConvertObjectPositionToGeoscapePosition(vector, aircraft->pos);
- - MAP_SelectAircraft(aircraft);
- - return;
- - }
- - counter++;
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOnGeoscape(aircraft)) {
- + if (centerOnEventIdx == counter) {
- + MAP_ConvertObjectPositionToGeoscapePosition(vector, aircraft->pos);
- + MAP_SelectAircraft(aircraft);
- + return;
- }
- + counter++;
- }
- }
- @@ -1757,6 +1751,7 @@ static void MAP_DrawMapMarkers (const uiNode_t* node)
- int x, y, i, installationIdx, idx;
- const char* font;
- aircraft_t *ufo;
- + aircraft_t *aircraft;
- base_t *base;
- const vec4_t white = {1.f, 1.f, 1.f, 0.7f};
- @@ -1794,17 +1789,13 @@ static void MAP_DrawMapMarkers (const uiNode_t* node)
- /* draw bases */
- base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- + while ((base = B_GetNextFounded(base)) != NULL)
- MAP_DrawMapOneBase(node, base, oneUFOVisible, font);
- - /* draw all aircraft of base */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_IsAircraftOnGeoscape(aircraft))
- - MAP_DrawMapOnePhalanxAircraft(node, aircraft, oneUFOVisible);
- - }
- + /* draw all aircraft */
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOnGeoscape(aircraft))
- + MAP_DrawMapOnePhalanxAircraft(node, aircraft, oneUFOVisible);
- }
- /* draws ufos */
- diff --git a/src/client/campaign/cp_mapfightequip.c b/src/client/campaign/cp_mapfightequip.c
- index afd4290..f660e3c 100644
- --- a/src/client/campaign/cp_mapfightequip.c
- +++ b/src/client/campaign/cp_mapfightequip.c
- @@ -168,9 +168,8 @@ qboolean AIM_PilotAssignedAircraft (const base_t* base, const employee_t* pilot)
- qboolean found = qfalse;
- aircraft_t *aircraft;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_GetPilot(aircraft) == pilot) {
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && AIR_GetPilot(aircraft) == pilot) {
- found = qtrue;
- break;
- }
- @@ -403,6 +402,7 @@ static void AII_UpdateOneInstallationDelay (base_t* base, installation_t* instal
- void AII_UpdateInstallationDelay (void)
- {
- int j, k;
- + aircraft_t *aircraft;
- base_t *base;
- for (j = 0; j < MAX_INSTALLATIONS; j++) {
- @@ -417,29 +417,25 @@ void AII_UpdateInstallationDelay (void)
- base = NULL;
- while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- /* Update base */
- for (k = 0; k < base->numBatteries; k++)
- AII_UpdateOneInstallationDelay(base, NULL, NULL, &base->batteries[k].slot);
- for (k = 0; k < base->numLasers; k++)
- AII_UpdateOneInstallationDelay(base, NULL, NULL, &base->lasers[k].slot);
- + }
- - /* Update each aircraft */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_IsAircraftInBase(aircraft)) {
- - /* Update electronics delay */
- - for (k = 0; k < aircraft->maxElectronics; k++)
- - AII_UpdateOneInstallationDelay(base, NULL, aircraft, aircraft->electronics + k);
- -
- + /* Update each aircraft */
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftInBase(aircraft)) {
- + /* Update electronics delay */
- + for (k = 0; k < aircraft->maxElectronics; k++)
- + AII_UpdateOneInstallationDelay(aircraft->homebase, NULL, aircraft, aircraft->electronics + k);
- /* Update weapons delay */
- - for (k = 0; k < aircraft->maxWeapons; k++)
- - AII_UpdateOneInstallationDelay(base, NULL, aircraft, aircraft->weapons + k);
- + for (k = 0; k < aircraft->maxWeapons; k++)
- + AII_UpdateOneInstallationDelay(aircraft->homebase, NULL, aircraft, aircraft->weapons + k);
- - /* Update shield delay */
- - AII_UpdateOneInstallationDelay(base, NULL, aircraft, &aircraft->shield);
- - }
- + /* Update shield delay */
- + AII_UpdateOneInstallationDelay(aircraft->homebase, NULL, aircraft, &aircraft->shield);
- }
- }
- }
- diff --git a/src/client/campaign/cp_market_callbacks.c b/src/client/campaign/cp_market_callbacks.c
- index cd41ff7..ff1b2a7 100644
- --- a/src/client/campaign/cp_market_callbacks.c
- +++ b/src/client/campaign/cp_market_callbacks.c
- @@ -127,9 +127,8 @@ static int BS_GetStorageAmountInBase (const base_t* base, const char *aircraftID
- assert(base);
- /* Get storage amount in the base. */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (!strcmp(aircraft->id, aircraftID))
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && !strcmp(aircraft->id, aircraftID))
- storage++;
- }
- return storage;
- @@ -659,8 +658,9 @@ static void BS_SellAircraft_f (void)
- if (!aircraftTemplate)
- return;
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- + AIR_Foreach(aircraft) {
- + if (!AIR_IsAircraftOfBase(aircraft, base))
- + continue;
- if (!strcmp(aircraft->id, aircraftTemplate->id)) {
- if (AIR_GetTeamSize(aircraft) > 0) {
- teamNote = qtrue;
- diff --git a/src/client/campaign/cp_nation.c b/src/client/campaign/cp_nation.c
- index 62c40ad..6cea693 100644
- --- a/src/client/campaign/cp_nation.c
- +++ b/src/client/campaign/cp_nation.c
- @@ -845,6 +845,7 @@ static void NAT_NationList_f (void)
- * @note Called from CL_CampaignRun
- * @sa CL_CampaignRun
- * @sa B_CreateEmployee
- + * @todo This is very redundant with CL_StatsUpdate_f. Ivestigate and clean up.
- */
- void NAT_HandleBudget (const campaign_t *campaign)
- {
- @@ -856,6 +857,7 @@ void NAT_HandleBudget (const campaign_t *campaign)
- int initialCredits = ccs.credits;
- base_t *base;
- const salary_t *salary = &campaign->salaries;
- + aircraft_t *aircraft;
- /* Refreshes the pilot global list. Pilots who are already hired are unchanged, but all other
- * pilots are replaced. The new pilots is evenly distributed between the nations that are happy (happiness > 0). */
- @@ -913,12 +915,10 @@ void NAT_HandleBudget (const campaign_t *campaign)
- }
- cost = 0;
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - const salary_t *salary = &campaign->salaries;
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - cost += aircraft->price * salary->aircraftFactor / salary->aircraftDivisor;
- + AIR_Foreach(aircraft) {
- + if (aircraft->status == AIR_CRASHED)
- + continue;
- + cost += aircraft->price * salary->aircraftFactor / salary->aircraftDivisor;
- }
- totalExpenditure += cost;
- diff --git a/src/client/campaign/cp_popup.c b/src/client/campaign/cp_popup.c
- index dc0b182..5ac1f1a 100644
- --- a/src/client/campaign/cp_popup.c
- +++ b/src/client/campaign/cp_popup.c
- @@ -311,7 +311,7 @@ POPUP_INTERCEPT
- void CL_DisplayPopupInterceptMission (mission_t* mission)
- {
- linkedList_t *aircraftList = NULL;
- - base_t *base;
- + aircraft_t *aircraft;
- if (!mission)
- return;
- @@ -322,31 +322,26 @@ void CL_DisplayPopupInterceptMission (mission_t* mission)
- /* Create the list of aircraft, and write the text to display in popup */
- popupIntercept.numAircraft = 0;
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - /* Check aircraft in base */
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - const int teamSize = AIR_GetTeamSize(aircraft);
- - /* if aircraft is empty we can't send it on a ground mission */
- - if (teamSize > 0 && AIR_CanIntercept(aircraft)) {
- - char aircraftListText[256] = "";
- - const float distance = GetDistanceOnGlobe(aircraft->pos, mission->pos);
- - const char *statusName = AIR_AircraftStatusToName(aircraft);
- - const char *time = CL_SecondConvert((float)SECONDS_PER_HOUR * distance / aircraft->stats[AIR_STATS_SPEED]);
- - Com_sprintf(aircraftListText, sizeof(aircraftListText), _("%s (%i/%i)\t%s\t%s\t%s"), aircraft->name,
- - teamSize, aircraft->maxTeamSize, statusName, base->name, time);
- - LIST_AddString(&aircraftList, aircraftListText);
- - popupIntercept.aircraft[popupIntercept.numAircraft] = aircraft;
- - popupIntercept.numAircraft++;
- - if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- - break;
- - }
- + AIR_Foreach(aircraft) {
- + const int teamSize = AIR_GetTeamSize(aircraft);
- +
- + if (aircraft->status == AIR_CRASHED)
- + continue;
- + /* if aircraft is empty we can't send it on a ground mission */
- + if (teamSize > 0 && AIR_CanIntercept(aircraft)) {
- + char aircraftListText[256] = "";
- + const float distance = GetDistanceOnGlobe(aircraft->pos, mission->pos);
- + const char *statusName = AIR_AircraftStatusToName(aircraft);
- + const char *time = CL_SecondConvert((float)SECONDS_PER_HOUR * distance / aircraft->stats[AIR_STATS_SPEED]);
- + Com_sprintf(aircraftListText, sizeof(aircraftListText), _("%s (%i/%i)\t%s\t%s\t%s"), aircraft->name,
- + teamSize, aircraft->maxTeamSize, statusName, aircraft->homebase->name, time);
- + LIST_AddString(&aircraftList, aircraftListText);
- + popupIntercept.aircraft[popupIntercept.numAircraft] = aircraft;
- + popupIntercept.numAircraft++;
- + if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- + break;
- }
- - /* also leave the outer loop */
- - if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- - break;
- - } /* bases */
- + }
- if (popupIntercept.numAircraft)
- UI_RegisterLinkedListText(TEXT_AIRCRAFT_LIST, aircraftList);
- @@ -369,6 +364,7 @@ void CL_DisplayPopupInterceptUFO (aircraft_t* ufo)
- {
- linkedList_t *aircraftList = NULL;
- linkedList_t *baseList = NULL;
- + aircraft_t *aircraft;
- base_t *base;
- int installationIdx;
- @@ -381,47 +377,40 @@ void CL_DisplayPopupInterceptUFO (aircraft_t* ufo)
- /* Create the list of aircraft, and write the text to display in popup */
- popupIntercept.numAircraft = 0;
- + AIR_Foreach(aircraft) {
- + if (AIR_CanIntercept(aircraft)) {
- + char aircraftListText[256] = "";
- + /* don't show aircraft with no weapons or no ammo, or crafts that
- + * can't even reach the target */
- + const char *enoughFuelMarker = "^B";
- +
- + /* Does the aircraft has weapons and ammo ? */
- + if (AIRFIGHT_ChooseWeapon(aircraft->weapons, aircraft->maxWeapons, aircraft->pos, aircraft->pos) == AIRFIGHT_WEAPON_CAN_NEVER_SHOOT) {
- + Com_DPrintf(DEBUG_CLIENT, "CL_DisplayPopupIntercept: No useable weapon found in craft '%s' (%i)\n", aircraft->id, aircraft->maxWeapons);
- + continue;
- + }
- + /* now check the aircraft range */
- + if (!AIR_AircraftHasEnoughFuel(aircraft, ufo->pos)) {
- + Com_DPrintf(DEBUG_CLIENT, "CL_DisplayPopupIntercept: Target out of reach for craft '%s'\n", aircraft->id);
- + enoughFuelMarker = "";
- + }
- +
- + Com_sprintf(aircraftListText, sizeof(aircraftListText), _("%s%s (%i/%i)\t%s\t%s"), enoughFuelMarker, aircraft->name,
- + AIR_GetTeamSize(aircraft), aircraft->maxTeamSize, AIR_AircraftStatusToName(aircraft), aircraft->homebase->name);
- + LIST_AddString(&aircraftList, aircraftListText);
- + popupIntercept.aircraft[popupIntercept.numAircraft] = aircraft;
- + popupIntercept.numAircraft++;
- + if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- + break;
- + }
- + }
- +
- base = NULL;
- while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- /* Check if the base should be displayed in base list
- * don't check range because maybe UFO will get closer */
- if (AII_BaseCanShoot(base))
- LIST_AddString(&baseList, va("^B%s", base->name));
- -
- - /* Check aircraft in base */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_CanIntercept(aircraft)) {
- - char aircraftListText[256] = "";
- - /* don't show aircraft with no weapons or no ammo, or crafts that
- - * can't even reach the target */
- - const char *enoughFuelMarker = "^B";
- -
- - /* Does the aircraft has weapons and ammo ? */
- - if (AIRFIGHT_ChooseWeapon(aircraft->weapons, aircraft->maxWeapons, aircraft->pos, aircraft->pos) == AIRFIGHT_WEAPON_CAN_NEVER_SHOOT) {
- - Com_DPrintf(DEBUG_CLIENT, "CL_DisplayPopupIntercept: No useable weapon found in craft '%s' (%i)\n", aircraft->id, aircraft->maxWeapons);
- - continue;
- - }
- - /* now check the aircraft range */
- - if (!AIR_AircraftHasEnoughFuel(aircraft, ufo->pos)) {
- - Com_DPrintf(DEBUG_CLIENT, "CL_DisplayPopupIntercept: Target out of reach for craft '%s'\n", aircraft->id);
- - enoughFuelMarker = "";
- - }
- -
- - Com_sprintf(aircraftListText, sizeof(aircraftListText), _("%s%s (%i/%i)\t%s\t%s"), enoughFuelMarker, aircraft->name,
- - AIR_GetTeamSize(aircraft), aircraft->maxTeamSize, AIR_AircraftStatusToName(aircraft), base->name);
- - LIST_AddString(&aircraftList, aircraftListText);
- - popupIntercept.aircraft[popupIntercept.numAircraft] = aircraft;
- - popupIntercept.numAircraft++;
- - if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- - break;
- - }
- - }
- - /* also leave the outer loop */
- - if (popupIntercept.numAircraft >= POPUP_INTERCEPT_MAX_AIRCRAFT)
- - break;
- } /* bases */
- if (popupIntercept.numAircraft)
- diff --git a/src/client/campaign/cp_radar.c b/src/client/campaign/cp_radar.c
- index 298c93d..0eadbdb 100644
- --- a/src/client/campaign/cp_radar.c
- +++ b/src/client/campaign/cp_radar.c
- @@ -97,19 +97,15 @@ static inline void RADAR_DrawCoverage (const radar_t* radar, const vec2_t pos)
- */
- void RADAR_UpdateWholeRadarOverlay (void)
- {
- - base_t *base;
- + aircraft_t *aircraft;
- /* Copy Base and installation radar overlay*/
- CP_InitializeRadarOverlay(qfalse);
- /* Add aircraft radar coverage */
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (AIR_IsAircraftOnGeoscape(aircraft))
- - RADAR_DrawCoverage(&aircraft->radar, aircraft->pos);
- - }
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOnGeoscape(aircraft))
- + RADAR_DrawCoverage(&aircraft->radar, aircraft->pos);
- }
- CP_UploadRadarCoverage();
- @@ -180,22 +176,22 @@ void RADAR_DeactivateRadarOverlay (void)
- {
- int idx;
- base_t *base;
- + aircraft_t *aircraft;
- /* never deactivate radar if player wants it to be always turned on */
- if (radarOverlayWasSet)
- return;
- + AIR_Foreach(aircraft) {
- + /** @todo Is aircraft->radar cleared for crashed aircraft? */
- + if (aircraft->radar.numUFOs)
- + return;
- + }
- +
- base = NULL;
- while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- if (base->radar.numUFOs)
- return;
- -
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- - if (aircraft->radar.numUFOs)
- - return;
- }
- for (idx = 0; idx < MAX_INSTALLATIONS; idx++) {
- @@ -426,27 +422,27 @@ void RADAR_AddDetectedUFOToEveryRadar (const aircraft_t const *ufo)
- {
- int idx;
- base_t *base = NULL;
- + aircraft_t *aircraft;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- + AIR_Foreach(aircraft) {
- + if (!AIR_IsAircraftOnGeoscape(aircraft))
- + continue;
- +
- + if (!RADAR_IsUFOSensored(&aircraft->radar, ufo)) {
- + /* Distance from radar to UFO */
- + const float dist = GetDistanceOnGlobe(ufo->pos, aircraft->pos);
- + if (dist <= aircraft->radar.trackingRange)
- + RADAR_AddUFO(&aircraft->radar, ufo);
- + }
- + }
- + while ((base = B_GetNextFounded(base)) != NULL) {
- if (!RADAR_IsUFOSensored(&base->radar, ufo)) {
- - const float dist = GetDistanceOnGlobe(ufo->pos, base->pos); /* Distance from radar to UFO */
- + /* Distance from radar to UFO */
- + const float dist = GetDistanceOnGlobe(ufo->pos, base->pos);
- if (dist <= base->radar.trackingRange)
- RADAR_AddUFO(&base->radar, ufo);
- }
- -
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (!AIR_IsAircraftOnGeoscape(aircraft))
- - continue;
- -
- - if (!RADAR_IsUFOSensored(&aircraft->radar, ufo)) {
- - const float dist = GetDistanceOnGlobe(ufo->pos, aircraft->pos); /* Distance from radar to UFO */
- - if (dist <= aircraft->radar.trackingRange)
- - RADAR_AddUFO(&aircraft->radar, ufo);
- - }
- - }
- }
- for (idx = 0; idx < MAX_INSTALLATIONS; idx++) {
- @@ -460,7 +456,8 @@ void RADAR_AddDetectedUFOToEveryRadar (const aircraft_t const *ufo)
- continue;
- if (!RADAR_IsUFOSensored(&installation->radar, ufo)) {
- - const float dist = GetDistanceOnGlobe(ufo->pos, installation->pos); /* Distance from radar to UFO */
- + /* Distance from radar to UFO */
- + const float dist = GetDistanceOnGlobe(ufo->pos, installation->pos);
- if (dist <= ufo->radar.trackingRange)
- RADAR_AddUFO(&installation->radar, ufo);
- }
- diff --git a/src/client/campaign/cp_research.c b/src/client/campaign/cp_research.c
- index 815c287..ccab8a6 100644
- --- a/src/client/campaign/cp_research.c
- +++ b/src/client/campaign/cp_research.c
- @@ -625,14 +625,11 @@ void RS_InitTree (const campaign_t *campaign, qboolean load)
- if (load) {
- /* when you load a savegame right after starting UFO, the aircraft in bases
- * and installations don't have any tech assigned */
- - base_t *base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - /* if you already played before loading the game, tech are already defined for templates */
- - if (!aircraft->tech)
- - aircraft->tech = RS_GetTechByProvided(aircraft->id);
- - }
- + aircraft_t *aircraft;
- + AIR_Foreach(aircraft) {
- + /* if you already played before loading the game, tech are already defined for templates */
- + if (!aircraft->tech)
- + aircraft->tech = RS_GetTechByProvided(aircraft->id);
- }
- }
- diff --git a/src/client/campaign/cp_statistics.c b/src/client/campaign/cp_statistics.c
- index f5a94f1..3af09bc 100644
- --- a/src/client/campaign/cp_statistics.c
- +++ b/src/client/campaign/cp_statistics.c
- @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- #define MAX_STATS_BUFFER 2048
- /**
- * @brief Shows the current stats from stats_t stats
- + * @todo This is very redundant with NAT_HandleBudget Ivestigate and clean up.
- */
- void CL_StatsUpdate_f (void)
- {
- @@ -42,6 +43,7 @@ void CL_StatsUpdate_f (void)
- base_t *base;
- const campaign_t *campaign = ccs.curCampaign;
- const salary_t *salary = &campaign->salaries;
- + aircraft_t *aircraft;
- /* delete buffer */
- memset(statsBuffer, 0, sizeof(statsBuffer));
- @@ -102,12 +104,9 @@ void CL_StatsUpdate_f (void)
- sum += costs;
- costs = 0;
- -
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - const salary_t *salary = &campaign->salaries;
- - aircraft_t *aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL)
- + AIR_Foreach(aircraft) {
- + if (aircraft->status == AIR_CRASHED)
- + continue;
- costs += aircraft->price * salary->aircraftFactor / salary->aircraftDivisor;
- }
- Q_strcat(pos, va(_("Aircraft:\t%i c\n"), costs), (ptrdiff_t)(&statsBuffer[MAX_STATS_BUFFER] - pos));
- diff --git a/src/client/campaign/cp_team_callbacks.c b/src/client/campaign/cp_team_callbacks.c
- index f8b5fab..ddab095 100644
- --- a/src/client/campaign/cp_team_callbacks.c
- +++ b/src/client/campaign/cp_team_callbacks.c
- @@ -195,7 +195,8 @@ static void CL_UpdateEquipmentMenuParameters_f (void)
- {
- equipDef_t unused;
- int p;
- - aircraft_t *aircraft, *aircraftInBase;
- + aircraft_t *aircraft;
- + aircraft_t *aircraftInBase;
- base_t *base = B_GetCurrentSelectedBase();
- size_t size;
- @@ -231,9 +232,11 @@ static void CL_UpdateEquipmentMenuParameters_f (void)
- /* clean up aircraft crew for upcoming mission */
- CL_CleanTempInventory(aircraft->homebase);
- - aircraftInBase = NULL;
- - while ((aircraftInBase = AIR_GetNextFromBase(aircraft->homebase, aircraftInBase)) != NULL)
- - CL_CleanupAircraftCrew(aircraftInBase, &unused);
- + AIR_Foreach(aircraftInBase) {
- + /** @todo should we run this for crashed aircraft too? */
- + if (AIR_IsAircraftOfBase(aircraft, base))
- + CL_CleanupAircraftCrew(aircraftInBase, &unused);
- + }
- UI_ContainerNodeUpdateEquipment(&aircraft->homebase->bEquipment, &unused);
- }
- diff --git a/src/client/campaign/cp_transfer_callbacks.c b/src/client/campaign/cp_transfer_callbacks.c
- index 2dbf384..feccee6 100644
- --- a/src/client/campaign/cp_transfer_callbacks.c
- +++ b/src/client/campaign/cp_transfer_callbacks.c
- @@ -682,10 +682,10 @@ static int TR_FillAircraft (const base_t *srcbase, const base_t *destbase, linke
- {
- int cnt = 0;
- if (AIR_AircraftAllowed(destbase)) {
- - aircraft_t *aircraft = NULL;
- + aircraft_t *aircraft;
- - while ((aircraft = AIR_GetNextFromBase(srcbase, aircraft))) {
- - if (TR_AircraftListSelect(aircraft)) {
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, srcbase) && TR_AircraftListSelect(aircraft)) {
- char str[128];
- Com_sprintf(str, sizeof(str), _("Aircraft %s"), aircraft->name);
- TR_AddListEntry(names, str, amounts, 1, transfers, -1);
- @@ -1007,10 +1007,10 @@ static void TR_AddAircraftToTransferList (base_t *base, transferData_t *transfer
- int cnt = 0;
- if (AIR_AircraftAllowed(transferBase)) {
- - aircraft_t *aircraft = NULL;
- + aircraft_t *aircraft;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft))) {
- - if (TR_AircraftListSelect(aircraft)) {
- + AIR_Foreach(aircraft) {
- + if (AIR_IsAircraftOfBase(aircraft, base) && TR_AircraftListSelect(aircraft)) {
- if (cnt == num) {
- if (TR_CheckAircraft(aircraft, transferBase)) {
- LIST_AddPointer(&transferData->aircraft, (void*)aircraft);
- diff --git a/src/client/campaign/cp_ufo.c b/src/client/campaign/cp_ufo.c
- index 5a9108f..8587569 100644
- --- a/src/client/campaign/cp_ufo.c
- +++ b/src/client/campaign/cp_ufo.c
- @@ -390,8 +390,7 @@ void UFO_UpdateAlienInterestForAllBasesAndInstallations (void)
- */
- static void UFO_SearchAircraftTarget (const campaign_t* campaign, aircraft_t *ufo)
- {
- - base_t *base;
- - aircraft_t* phalanxAircraft;
- + aircraft_t *phalanxAircraft;
- float distance = 999999.;
- /* UFO never try to attack a PHALANX aircraft except if they came on earth in that aim */
- @@ -413,27 +412,22 @@ static void UFO_SearchAircraftTarget (const campaign_t* campaign, aircraft_t *uf
- }
- ufo->status = AIR_TRANSIT;
- - base = NULL;
- - while ((base = B_GetNextFounded(base)) != NULL) {
- - /* check if the ufo can attack an aircraft */
- - phalanxAircraft = NULL;
- - while ((phalanxAircraft = AIR_GetNextFromBase(base, phalanxAircraft)) != NULL) {
- - /* check that aircraft is flying */
- - if (AIR_IsAircraftOnGeoscape(phalanxAircraft)) {
- - /* get the distance from ufo to aircraft */
- - const float dist = GetDistanceOnGlobe(ufo->pos, phalanxAircraft->pos);
- - /* check out of reach */
- - if (dist > MAX_DETECTING_RANGE)
- - continue;
- - /* choose the nearest target */
- - if (dist < distance) {
- - distance = dist;
- - if (UFO_SendPursuingAircraft(ufo, phalanxAircraft) && UFO_IsUFOSeenOnGeoscape(ufo)) {
- - /* stop time and notify */
- - MSO_CheckAddNewMessage(NT_UFO_ATTACKING, _("Notice"), va(_("A UFO is flying toward %s"), phalanxAircraft->name), qfalse,
- - MSG_STANDARD, NULL);
- - /** @todo present a popup with possible orders like: return to base, attack the ufo, try to flee the rockets */
- - }
- + AIR_Foreach(phalanxAircraft) {
- + /* check that aircraft is flying */
- + if (AIR_IsAircraftOnGeoscape(phalanxAircraft)) {
- + /* get the distance from ufo to aircraft */
- + const float dist = GetDistanceOnGlobe(ufo->pos, phalanxAircraft->pos);
- + /* check out of reach */
- + if (dist > MAX_DETECTING_RANGE)
- + continue;
- + /* choose the nearest target */
- + if (dist < distance) {
- + distance = dist;
- + if (UFO_SendPursuingAircraft(ufo, phalanxAircraft) && UFO_IsUFOSeenOnGeoscape(ufo)) {
- + /* stop time and notify */
- + MSO_CheckAddNewMessage(NT_UFO_ATTACKING, _("Notice"), va(_("A UFO is flying toward %s"), phalanxAircraft->name), qfalse,
- + MSG_STANDARD, NULL);
- + /** @todo present a popup with possible orders like: return to base, attack the ufo, try to flee the rockets */
- }
- }
- }
- @@ -749,6 +743,7 @@ qboolean UFO_CampaignCheckEvents (void)
- /* detected tells us whether or not a UFO is detected NOW, whereas ufo->detected tells
- * us whether or not the UFO was detected PREVIOUSLY. */
- qboolean detected = qfalse;
- + aircraft_t *aircraft;
- base_t *base;
- /* don't update UFO status id UFO is landed or crashed */
- @@ -758,10 +753,25 @@ qboolean UFO_CampaignCheckEvents (void)
- /* note: We can't exit these loops as soon as we found the UFO detected
- * RADAR_CheckUFOSensored registers the UFO in every radars' detection list
- * which detect it */
- +
- + /* Check if UFO is detected by an aircraft */
- + AIR_Foreach(aircraft) {
- + if (!AIR_IsAircraftOnGeoscape(aircraft))
- + continue;
- + /* maybe the ufo is already detected, don't reset it */
- + if (RADAR_CheckUFOSensored(&aircraft->radar, aircraft->pos, ufo, detected | ufo->detected)) {
- + const int distance = GetDistanceOnGlobe(aircraft->pos, ufo->pos);
- + detected = qtrue;
- + if (minDistance < 0 || minDistance > distance) {
- + minDistance = distance;
- + Q_strncpyz(detectedBy, aircraft->name, sizeof(detectedBy));
- + }
- + }
- + }
- +
- + /* Check if UFO is detected by a base */
- base = NULL;
- while ((base = B_GetNextFounded(base)) != NULL) {
- - aircraft_t *aircraft;
- -
- if (!B_GetBuildingStatus(base, B_POWER))
- continue;
- @@ -775,23 +785,9 @@ qboolean UFO_CampaignCheckEvents (void)
- }
- }
- - /* Check if UFO is detected by an aircraft */
- - aircraft = NULL;
- - while ((aircraft = AIR_GetNextFromBase(base, aircraft)) != NULL) {
- - if (!AIR_IsAircraftOnGeoscape(aircraft))
- - continue;
- - /* maybe the ufo is already detected, don't reset it */
- - if (RADAR_CheckUFOSensored(&aircraft->radar, aircraft->pos, ufo, detected | ufo->detected)) {
- - const int distance = GetDistanceOnGlobe(aircraft->pos, ufo->pos);
- - detected = qtrue;
- - if (minDistance < 0 || minDistance > distance) {
- - minDistance = distance;
- - Q_strncpyz(detectedBy, aircraft->name, sizeof(detectedBy));
- - }
- - }
- - }
- }
- + /* Check if UFO is detected by a radartower */
- for (installationIdx = 0; installationIdx < ccs.numInstallations; installationIdx++) {
- installation_t *installation = INS_GetFoundedInstallationByIDX(installationIdx);
- if (!installation)
- --
- 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement