UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_mission_rescue.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 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 "../../../cl_shared.h"
26 #include "../cp_campaign.h"
27 #include "../cp_missions.h"
28 #include "../cp_time.h"
29 #include "../cp_ufo.h"
30 #include "cp_mission_rescue.h"
31 
36 static void CP_BeginRescueMission (mission_t* mission)
37 {
38  /* How long the rescue mission will stay before aliens leave / die */
39  const date_t minCrashDelay = {7, 0};
40  const date_t crashDelay = {14, 0};
41 
42  assert(mission->ufo);
43  mission->posAssigned = true;
44 
45  mission->mapDef = cgi->Com_GetMapDefinitionByID("rescue");
46  if (!mission->mapDef) {
47  CP_MissionRemove(mission);
48  cgi->Com_Error(ERR_DROP, "Could not find mapdef rescue");
49  return;
50  }
51 
52  mission->ufo->landed = true;
53  mission->stage = STAGE_RECON_GROUND;
54  mission->finalDate = Date_Add(ccs.date, Date_Random(minCrashDelay, crashDelay));
55  /* mission appear on geoscape, player can go there */
56  CP_MissionAddToGeoscape(mission, false);
57 }
58 
65 void CP_EndRescueMission (mission_t* mission, aircraft_t* aircraft, bool won)
66 {
67  aircraft_t* crashedAircraft = mission->data.aircraft;
68 
69  assert(crashedAircraft);
70  if (won) {
71  assert(aircraft);
72  /* Save the pilot */
73  if (crashedAircraft->pilot)
74  AIR_RemoveEmployee(crashedAircraft->pilot, crashedAircraft);
75  /* Save the soldiers */
76  LIST_Foreach(crashedAircraft->acTeam, Employee, employee) {
77  AIR_RemoveEmployee(employee, crashedAircraft);
78  }
79 
80  /* return to collect goods and aliens from the crashed aircraft */
83  B_DumpAircraftToHomeBase(crashedAircraft);
84  }
85 
86  if (won || (CP_CheckMissionLimitedInTime(mission) && Date_LaterThan(&ccs.date, &mission->finalDate)))
87  AIR_DestroyAircraft(crashedAircraft);
88 }
89 
94 static void CP_LeaveRescueMission (mission_t* mission)
95 {
96  CP_EndRescueMission(mission, nullptr, false);
97  mission->stage = STAGE_RETURN_TO_ORBIT;
98 
99  if (mission->ufo) {
101  UFO_SetRandomDest(mission->ufo);
102  /* Display UFO on geoscape if it is detected */
103  mission->ufo->landed = false;
104  } else {
105  /* Go to next stage on next frame */
106  mission->finalDate = ccs.date;
107  }
109 }
110 
116 {
117  assert(mission);
118  switch (mission->stage) {
119  case STAGE_MISSION_GOTO:
120  CP_BeginRescueMission(mission);
121  break;
122  case STAGE_RECON_GROUND:
123  CP_LeaveRescueMission(mission);
124  break;
126  CP_MissionRemove(mission);
127  break;
128  default:
129  cgi->Com_Printf("CP_RescueNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
130  CP_MissionRemove(mission);
131  break;
132  }
133 }
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
bool CP_CheckMissionLimitedInTime(const mission_t *mission)
Check if mission should end because of limited time.
bool posAssigned
Definition: cp_missions.h:111
bool AIR_RemoveEmployee(Employee *employee, aircraft_t *aircraft)
Removes a soldier from an aircraft.
date_t date
Definition: cp_campaign.h:245
void CP_RescueNextStage(mission_t *mission)
Determine what action should be performed when a Rescue mission stage ends.
mission definition
Definition: cp_missions.h:85
linkedList_t * acTeam
Definition: cp_aircraft.h:139
void CP_EndRescueMission(mission_t *mission, aircraft_t *aircraft, bool won)
Actions to be done when rescue mission finished/expired.
bool Date_LaterThan(const date_t *now, const date_t *compare)
Check whether the given date and time is later than current date.
Definition: cp_time.cpp:239
#define ERR_DROP
Definition: common.h:211
void B_DumpAircraftToHomeBase(aircraft_t *aircraft)
Will unload all cargo to the homebase.
Definition: cp_base.cpp:2085
date_t finalDate
Definition: cp_missions.h:102
aircraft_t * ufo
Definition: cp_missions.h:105
mapDef_t *IMPORT * Com_GetMapDefinitionByID(const char *mapDefID)
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:62
Engine-side time information in the game.
Definition: common.h:290
date_t Date_Add(date_t a, const date_t &b)
Add two dates and return the result.
Definition: cp_time.cpp:272
Campaign mission headers.
union mission_s::missionData_t data
static void CP_BeginRescueMission(mission_t *mission)
Actions to be done when UFO arrived at rescue mission location.
void AIR_DestroyAircraft(aircraft_t *aircraft, bool killPilot)
Removes an aircraft from its base and the game.
#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
date_t Date_Random(date_t minFrame, date_t maxFrame)
Return a random relative date which lies between a lower and upper limit.
Definition: cp_time.cpp:302
An aircraft with all it's data.
Definition: cp_aircraft.h:114
mapDef_t * mapDef
Definition: cp_missions.h:88
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.
class Employee * pilot
Definition: cp_aircraft.h:141
missionStage_t stage
Definition: cp_missions.h:98