UFO: Alien Invasion
Doxygen documentation generating
cp_mission_supply.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 
26 #include "../../../DateTime.h"
27 #include "../../../cl_shared.h"
28 #include "../cp_campaign.h"
29 #include "../cp_alienbase.h"
30 #include "../cp_ufo.h"
31 #include "../cp_missions.h"
32 #include "../cp_time.h"
33 #include "../cp_xvi.h"
34 #include "../cp_alien_interest.h"
35 #include "cp_mission_supply.h"
36 
42 {
43  alienBase_t* base;
45 
46  /* Spread XVI */
47  base = mission->data.alienBase;
48  assert(base);
49  CP_SpreadXVIAtPos(base->pos);
50 
51  CP_MissionRemove(mission);
52 }
53 
59 {
63 
64  CP_MissionRemove(mission);
65 }
66 
71 static void CP_SupplyMissionLeave (mission_t* mission)
72 {
73  assert(mission->ufo);
74  /* there must be an alien base set */
75  assert(mission->data.alienBase);
76 
77  mission->stage = STAGE_RETURN_TO_ORBIT;
78 
80  UFO_SetRandomDest(mission->ufo);
81  /* Display UFO on geoscape if it is detected */
82  mission->ufo->landed = false;
83 }
84 
90 static void CP_SupplySetStayAtBase (mission_t* mission)
91 {
92  const DateTime minSupplyTime(3, 0);
93  const DateTime maxSupplyTime(10, 0);
95  assert(mission->ufo);
96  /* there must be an alien base set */
97  assert(mission->data.alienBase);
98 
99  mission->stage = STAGE_SUPPLY;
100 
101  /* Maybe base has been destroyed since mission creation ? */
103  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
104  CP_MissionRemove(mission);
105  return;
106  }
107 
108  mission->finalDate = ccs.date + Date_Random(minSupplyTime, maxSupplyTime);
109 
110  AB_SupplyBase(mission->data.alienBase, mission->ufo->detected);
111 
112  /* ufo becomes invisible on geoscape */
113  CP_UFORemoveFromGeoscape(mission, false);
114 }
115 
121 static void CP_SupplyGoToBase (mission_t* mission)
122 {
123  alienBase_t* alienBase;
124 
125  assert(mission->ufo);
126 
127  mission->stage = STAGE_MISSION_GOTO;
128 
129  /* Maybe base has been destroyed since mission creation ? */
131  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
132  CP_MissionRemove(mission);
133  return;
134  }
135 
136  alienBase = AB_ChooseBaseToSupply();
137  assert(alienBase);
138  mission->data.alienBase = alienBase;
139  Vector2Copy(alienBase->pos, mission->pos);
140 
141  UFO_SendToDestination(mission->ufo, mission->pos);
142 }
143 
148 static void CP_SupplyMissionCreate (mission_t* mission)
149 {
150  ufoType_t ufoType;
151 
152  mission->stage = STAGE_COME_FROM_ORBIT;
153 
154  /* Maybe base has been destroyed since mission creation ? */
156  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
157  CP_MissionRemove(mission);
158  return;
159  }
160 
161  ufoType = CP_MissionChooseUFO(mission);
162  if (ufoType == UFO_NONE) {
163  cgi->Com_DPrintf(DEBUG_CLIENT, "Supply mission can't be spawned without UFO: removing supply mission.\n");
164  CP_MissionRemove(mission);
165  } else {
167  mission->ufo = UFO_AddToGeoscape(ufoType, nullptr, mission);
168  if (!mission->ufo) {
169  cgi->Com_Printf("CP_SupplyMissionCreate: Could not add UFO '%s', remove mission\n", cgi->Com_UFOTypeToShortName(ufoType));
170  CP_MissionRemove(mission);
171  }
172  }
173 }
174 
180 {
181  switch (mission->stage) {
182  case STAGE_NOT_ACTIVE:
183  /* Create mission */
184  CP_SupplyMissionCreate(mission);
185  break;
187  /* Go to base position */
188  CP_SupplyGoToBase(mission);
189  break;
190  case STAGE_MISSION_GOTO:
191  /* just arrived on base location: Supply base */
192  CP_SupplySetStayAtBase(mission);
193  break;
194  case STAGE_SUPPLY:
195  /* Leave earth */
196  CP_SupplyMissionLeave(mission);
197  break;
199  /* mission is over, remove mission */
200  CP_SupplyMissionIsSuccess(mission);
201  break;
202  default:
203  cgi->Com_Printf("CP_SupplyMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
204  CP_MissionRemove(mission);
205  break;
206  }
207 }
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
void CP_SupplyMissionNextStage(mission_t *mission)
Determine what action should be performed when a Supply mission stage ends.
static void CP_SupplyMissionCreate(mission_t *mission)
Supply mission begins: UFO arrive on earth.
short ufoType_t
Definition: scripts.h:145
void INT_ChangeIndividualInterest(float interestFactor, interestCategory_t category)
Change individual interest value.
aircraft_t * UFO_AddToGeoscape(ufoType_t ufoType, const vec2_t destination, mission_t *mission)
Add a UFO to geoscape.
Definition: cp_ufo.cpp:773
void CP_SupplyMissionIsSuccess(mission_t *mission)
Supply mission is over and is a success (from an alien point of view): change interest values...
void CP_SpreadXVIAtPos(const vec2_t pos)
Spread XVI at a given position.
Definition: cp_xvi.cpp:56
bool AB_CheckSupplyMissionPossible(void)
Check if a supply mission is possible.
alienBase_t * AB_ChooseBaseToSupply(void)
Choose Alien Base that should be supplied.
union mission_t::missionData_t data
#define DEBUG_CLIENT
Definition: defines.h:59
Campaign mission headers.
ufoType_t CP_MissionChooseUFO(const mission_t *mission)
Choose UFO type for a given mission category.
const cgame_import_t * cgi
void CP_MissionRemove(mission_t *mission)
Removes a mission from mission global array.
void CP_SupplyMissionIsFailure(mission_t *mission)
Supply mission is over and is a failure (from an alien point of view): change interest values...
ccs_t ccs
Definition: cp_campaign.cpp:63
class DateTime finalDate
Definition: cp_missions.h:103
vec2_t pos
Definition: cp_missions.h:105
vec2_t pos
Definition: cp_alienbase.h:30
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
alienBase_t * alienBase
Definition: cp_missions.h:95
static void CP_SupplyMissionLeave(mission_t *mission)
Supply mission ends: UFO leave earth.
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
void CP_UFORemoveFromGeoscape(mission_t *mission, bool destroyed)
Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions...
#define Vector2Copy(src, dest)
Definition: vector.h:52
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
Definition: cp_ufo.cpp:562
void AB_SupplyBase(alienBase_t *base, bool decreaseStealth)
Supply a base.
Alien Base.
Definition: cp_alienbase.h:28
static void CP_SupplyGoToBase(mission_t *mission)
Go to base position.
aircraft_t * ufo
Definition: cp_missions.h:106
static void CP_SupplySetStayAtBase(mission_t *mission)
UFO arrived on new base destination: Supply base.
const char *IMPORT * Com_UFOTypeToShortName(ufoType_t type)
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
#define UFO_NONE
Definition: scripts.h:148
bool detected
Definition: cp_aircraft.h:167