UFO: Alien Invasion
Doxygen documentation generating
cp_mission_rescue.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2023 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 
25 #include "../../../DateTime.h"
26 #include "../../../cl_shared.h"
27 #include "../cp_campaign.h"
28 #include "../cp_missions.h"
29 #include "../cp_time.h"
30 #include "../cp_ufo.h"
31 #include "cp_mission_rescue.h"
32 
37 static void CP_BeginRescueMission (mission_t* mission)
38 {
39  /* How long the rescue mission will stay before aliens leave / die */
40  const DateTime minCrashDelay(7, 0);
41  const DateTime maxCrashDelay(14, 0);
42 
43  assert(mission->ufo);
44  mission->posAssigned = true;
45 
46  mission->mapDef = cgi->Com_GetMapDefinitionByID("rescue");
47  if (!mission->mapDef) {
48  CP_MissionRemove(mission);
49  cgi->Com_Error(ERR_DROP, "Could not find mapdef rescue");
50  return;
51  }
52 
53  mission->ufo->landed = true;
54  mission->stage = STAGE_RECON_GROUND;
55  mission->finalDate = ccs.date + Date_Random(minCrashDelay, maxCrashDelay);
56  /* mission appear on geoscape, player can go there */
57  CP_MissionAddToGeoscape(mission, false);
58 }
59 
66 void CP_EndRescueMission (mission_t* mission, aircraft_t* aircraft, bool won)
67 {
68  aircraft_t* crashedAircraft = mission->data.aircraft;
69 
70  assert(crashedAircraft);
71  if (won) {
72  assert(aircraft);
73  /* Save the pilot */
74  if (crashedAircraft->pilot)
75  AIR_RemoveEmployee(crashedAircraft->pilot, crashedAircraft);
76  /* Save the soldiers */
77  LIST_Foreach(crashedAircraft->acTeam, Employee, employee) {
78  AIR_RemoveEmployee(employee, crashedAircraft);
79  }
80 
81  /* return to collect goods and aliens from the crashed aircraft */
84  B_DumpAircraftToHomeBase(crashedAircraft);
85  }
86 
87  if (won || (CP_CheckMissionLimitedInTime(mission) && ccs.date > mission->finalDate))
88  AIR_DestroyAircraft(crashedAircraft);
89 }
90 
95 static void CP_LeaveRescueMission (mission_t* mission)
96 {
97  CP_EndRescueMission(mission, nullptr, false);
98  mission->stage = STAGE_RETURN_TO_ORBIT;
99 
100  if (mission->ufo) {
102  UFO_SetRandomDest(mission->ufo);
103  /* Display UFO on geoscape if it is detected */
104  mission->ufo->landed = false;
105  } else {
106  /* Go to next stage on next frame */
107  mission->finalDate = ccs.date;
108  }
110 }
111 
117 {
118  assert(mission);
119  switch (mission->stage) {
120  case STAGE_MISSION_GOTO:
121  CP_BeginRescueMission(mission);
122  break;
123  case STAGE_RECON_GROUND:
124  CP_LeaveRescueMission(mission);
125  break;
127  CP_MissionRemove(mission);
128  break;
129  default:
130  cgi->Com_Printf("CP_RescueNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
131  CP_MissionRemove(mission);
132  break;
133  }
134 }
Class describing a point of time.
Definition: DateTime.h:30
void UFO_SetRandomDest(aircraft_t *ufocraft)
Give a random destination to the given UFO, and make him to move there.
Definition: cp_ufo.cpp:259
missionStage_t stage
Definition: cp_missions.h:99
mission definition
Definition: cp_missions.h:86
bool CP_CheckMissionLimitedInTime(const mission_t *mission)
Check if mission should end because of limited time.
bool AIR_RemoveEmployee(Employee *employee, aircraft_t *aircraft)
Removes a soldier from an aircraft.
void CP_RescueNextStage(mission_t *mission)
Determine what action should be performed when a Rescue mission stage ends.
void CP_EndRescueMission(mission_t *mission, aircraft_t *aircraft, bool won)
Actions to be done when rescue mission finished/expired.
union mission_t::missionData_t data
#define ERR_DROP
Definition: common.h:211
void B_DumpAircraftToHomeBase(aircraft_t *aircraft)
Will unload all cargo to the homebase.
Definition: cp_base.cpp:2084
const cgame_import_t * cgi
static void CP_LeaveRescueMission(mission_t *mission)
Rescue mission expired, UFO leave earth.
void CP_MissionRemove(mission_t *mission)
Removes a mission from mission global array.
void CP_MissionAddToGeoscape(mission_t *mission, bool force)
Add a mission to geoscape: make it visible and stop time.
ccs_t ccs
Definition: cp_campaign.cpp:63
class DateTime finalDate
Definition: cp_missions.h:103
linkedList_t * acTeam
Definition: cp_aircraft.h:140
Campaign mission headers.
class Employee * pilot
Definition: cp_aircraft.h:142
static void CP_BeginRescueMission(mission_t *mission)
Actions to be done when UFO arrived at rescue mission location.
An aircraft with all it's data.
Definition: cp_aircraft.h:115
void AIR_DestroyAircraft(aircraft_t *aircraft, bool killPilot)
Removes an aircraft from its base and the game.
DateTime Date_Random(const DateTime &minFrame, const DateTime &maxFrame)
Return a random relative date which lies between a lower and upper limit.
Definition: cp_time.cpp:239
class DateTime date
Definition: cp_campaign.h:246
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
Definition: list.h:41
bool posAssigned
Definition: cp_missions.h:112
mapDef_t *IMPORT * Com_GetMapDefinitionByID(const char *mapDefID)
aircraft_t * ufo
Definition: cp_missions.h:106
void CP_MissionRemoveFromGeoscape(mission_t *mission)
Removes a mission from geoscape: make it non visible and call notify functions.
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
mapDef_t * mapDef
Definition: cp_missions.h:89