UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_rescue.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
37static 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
66void 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
95static void CP_LeaveRescueMission (mission_t* mission)
96{
97 CP_EndRescueMission(mission, nullptr, false);
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) {
121 CP_BeginRescueMission(mission);
122 break;
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}
DateTime class definition.
Share stuff between the different cgame implementations.
Class describing a point of time.
Definition DateTime.h:31
#define ERR_DROP
Definition common.h:211
bool AIR_RemoveEmployee(Employee *employee, aircraft_t *aircraft)
Removes a soldier from an aircraft.
void AIR_DestroyAircraft(aircraft_t *aircraft, bool killPilot)
Removes an aircraft from its base and the game.
void B_DumpAircraftToHomeBase(aircraft_t *aircraft)
Will unload all cargo to the homebase.
Definition cp_base.cpp:2084
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
void CP_RescueNextStage(mission_t *mission)
Determine what action should be performed when a Rescue mission stage ends.
static void CP_LeaveRescueMission(mission_t *mission)
Rescue mission expired, UFO leave earth.
void CP_EndRescueMission(mission_t *mission, aircraft_t *aircraft, bool won)
Actions to be done when rescue mission finished/expired.
static void CP_BeginRescueMission(mission_t *mission)
Actions to be done when UFO arrived at rescue mission location.
Campaign mission headers.
bool CP_CheckMissionLimitedInTime(const mission_t *mission)
Check if mission should end because of limited time.
void CP_MissionRemove(mission_t *mission)
Removes a mission from mission global array.
void CP_MissionRemoveFromGeoscape(mission_t *mission)
Removes a mission from geoscape: make it non visible and call notify functions.
void CP_MissionAddToGeoscape(mission_t *mission, bool force)
Add a mission to geoscape: make it visible and stop time.
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
Campaign missions headers.
@ STAGE_RECON_GROUND
Definition cp_missions.h:40
@ STAGE_RETURN_TO_ORBIT
Definition cp_missions.h:51
@ STAGE_MISSION_GOTO
Definition cp_missions.h:39
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
Campaign geoscape time header.
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
#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
An aircraft with all it's data.
linkedList_t * acTeam
class Employee * pilot
mission definition
Definition cp_missions.h:86
aircraft_t * ufo
mapDef_t * mapDef
Definition cp_missions.h:89
missionStage_t stage
Definition cp_missions.h:99
union mission_t::missionData_t data
bool posAssigned
class DateTime finalDate