UFO: Alien Invasion
Doxygen documentation generating
cp_mission_buildbase.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_geoscape.h"
31 #include "../cp_ufo.h"
32 #include "../cp_missions.h"
33 #include "../cp_time.h"
34 #include "../cp_xvi.h"
35 #include "../cp_alien_interest.h"
36 #include "cp_mission_buildbase.h"
37 #include "cp_mission_recon.h"
38 
39 #define HAPPINESS_SUBVERSION_LOSS -0.15
40 
47 {
49 }
50 
56 {
58  /* This is a subverting government mission */
60  } else {
61  /* An alien base has been built */
62  const alienBase_t* base = mission->data.alienBase;
63  assert(base);
64  CP_SpreadXVIAtPos(base->pos);
65 
66  if (CP_IsXVIStarted())
70  }
71 
72  CP_MissionRemove(mission);
73 }
74 
80 {
81  /* Restore some alien interest for build base that has been removed when mission has been created */
84 
85  CP_MissionRemove(mission);
86 }
87 
92 {
94 }
95 
101 {
102  /* An alien base has been built */
103  alienBase_t* base = mission->data.alienBase;
104  assert(base);
105 
108 
109  AB_DestroyBase(base);
110  mission->data.alienBase = nullptr;
111  CP_MissionRemove(mission);
112 }
113 
118 static void CP_BuildBaseMissionLeave (mission_t* mission)
119 {
120  assert(mission->ufo);
121  /* there must be an alien base set */
122  assert(mission->data.alienBase);
123 
124  mission->stage = STAGE_RETURN_TO_ORBIT;
125 
127  UFO_SetRandomDest(mission->ufo);
128  /* Display UFO on geoscape if it is detected */
129  mission->ufo->landed = false;
130 }
131 
137 static void CP_BuildBaseSetUpBase (mission_t* mission)
138 {
139  alienBase_t* base;
140  const DateTime minBuildingTime(5, 0);
141  const DateTime maxBuildingTime(10, 0);
143  assert(mission->ufo);
144 
145  mission->stage = STAGE_BUILD_BASE;
146 
147  mission->finalDate = ccs.date + Date_Random(minBuildingTime, maxBuildingTime);
148 
149  base = AB_BuildBase(mission->pos);
150  if (!base) {
151  cgi->Com_DPrintf(DEBUG_CLIENT, "CP_BuildBaseSetUpBase: could not create alien base\n");
152  CP_MissionRemove(mission);
153  return;
154  }
155  mission->data.alienBase = base;
156 
157  /* ufo becomes invisible on geoscape */
158  CP_UFORemoveFromGeoscape(mission, false);
159 }
160 
166 static void CP_BuildBaseGoToBase (mission_t* mission)
167 {
168  assert(mission->ufo);
169 
170  mission->stage = STAGE_MISSION_GOTO;
171 
172  AB_SetAlienBasePosition(mission->pos);
173 
174  UFO_SendToDestination(mission->ufo, mission->pos);
175 }
176 
181 static void CP_BuildBaseGovernmentLeave (const campaign_t* campaign, mission_t* mission)
182 {
183  nation_t* nation;
184 
185  assert(mission);
186  assert(mission->ufo);
187 
188  mission->stage = STAGE_RETURN_TO_ORBIT;
189 
190  /* Mission is a success: government is subverted => lower happiness */
191  nation = GEO_GetNation(mission->pos);
194  if (nation) {
195  const nationInfo_t* stats = NAT_GetCurrentMonthInfo(nation);
197  }
198 
200  UFO_SetRandomDest(mission->ufo);
201  /* Display UFO on geoscape if it is detected */
202  mission->ufo->landed = false;
203 }
204 
210 {
211  const DateTime minMissionDelay(3, 0);
212  const DateTime maxMissionDelay(5, 0);
213 
214  assert(mission->ufo);
215 
216  mission->stage = STAGE_SUBVERT_GOV;
217 
218  /* mission appear on geoscape, player can go there */
219  CP_MissionAddToGeoscape(mission, false);
220 
221  mission->finalDate = ccs.date + Date_Random(minMissionDelay, maxMissionDelay);
222  /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
223  CP_UFORemoveFromGeoscape(mission, false);
224 }
225 
230 static void CP_BuildBaseChooseMission (mission_t* mission)
231 {
233  CP_ReconMissionGroundGo(mission);
234  else
235  CP_BuildBaseGoToBase(mission);
236 }
237 
243 void CP_BuildBaseMissionNextStage (const campaign_t* campaign, mission_t* mission)
244 {
245  switch (mission->stage) {
246  case STAGE_NOT_ACTIVE:
247  /* Create mission */
248  CP_MissionBegin(mission);
249  break;
251  /* Choose type of mission */
252  CP_BuildBaseChooseMission(mission);
253  break;
254  case STAGE_MISSION_GOTO:
256  /* subverting mission */
258  else
259  /* just arrived on base location: build base */
260  CP_BuildBaseSetUpBase(mission);
261  break;
262  case STAGE_BUILD_BASE:
263  /* Leave earth */
264  CP_BuildBaseMissionLeave(mission);
265  break;
266  case STAGE_SUBVERT_GOV:
267  /* Leave earth */
268  CP_BuildBaseGovernmentLeave(campaign, mission);
269  break;
271  /* mission is over, remove mission */
273  break;
274  default:
275  cgi->Com_Printf("CP_BuildBaseMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
276  CP_MissionRemove(mission);
277  break;
278  }
279 }
Class describing a point of time.
Definition: DateTime.h:30
const nationInfo_t * NAT_GetCurrentMonthInfo(const nation_t *const nation)
Get the current month nation stats.
Definition: cp_nation.cpp:133
void CP_BuildBaseMissionOnSpawn(void)
Run when the mission is spawned.
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
float happiness
Definition: cp_nation.h:39
void CP_BuildBaseMissionIsFailure(mission_t *mission)
Build Base mission is over and is a failure (from an alien point of view): change interest values...
static void CP_BuildBaseSetUpBase(mission_t *mission)
UFO arrived on new base destination: build base.
void CP_ReconMissionGroundGo(mission_t *mission)
Set ground mission, and go to ground mission pos.
void AB_SetAlienBasePosition(vec2_t pos)
Set new base position.
int alienBaseInterest
Definition: cp_campaign.h:209
void INT_ChangeIndividualInterest(float interestFactor, interestCategory_t category)
Change individual interest value.
Nation definition.
Definition: cp_nation.h:46
static void CP_BuildBaseSubvertGovernment(mission_t *mission)
Start Subverting Mission.
void CP_BuildBaseMissionNextStage(const campaign_t *campaign, mission_t *mission)
Determine what action should be performed when a Build Base mission stage ends.
void CP_SpreadXVIAtPos(const vec2_t pos)
Spread XVI at a given position.
Definition: cp_xvi.cpp:56
union mission_t::missionData_t data
#define DEBUG_CLIENT
Definition: defines.h:59
Detailed information about the nation relationship (currently per month, but could be used elsewhere)...
Definition: cp_nation.h:35
void NAT_SetHappiness(const float minhappiness, nation_t *nation, const float happiness)
Updates the nation happiness.
Definition: cp_nation.cpp:189
float minhappiness
Definition: cp_campaign.h:187
Campaign mission header.
const cgame_import_t * cgi
bool CP_MissionBegin(mission_t *mission)
mission begins: UFO arrive on 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.
bool CP_BasemissionIsSubvertingGovernmentMission(const mission_t *mission)
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
Campaign mission headers.
campaign_t * curCampaign
Definition: cp_campaign.h:378
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
static void CP_BuildBaseGovernmentLeave(const campaign_t *campaign, mission_t *mission)
Subverting Mission ends: UFO leave earth.
class DateTime date
Definition: cp_campaign.h:246
static void CP_BuildBaseMissionLeave(mission_t *mission)
Build Base mission ends: UFO leave earth.
alienBase_t * AB_BuildBase(const vec2_t pos)
Build a new alien base.
void CP_UFORemoveFromGeoscape(mission_t *mission, bool destroyed)
Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions...
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
Definition: cp_ufo.cpp:562
void CP_BuildBaseMissionBaseDestroyed(mission_t *mission)
Alien base has been destroyed: change interest values.
#define HAPPINESS_SUBVERSION_LOSS
Alien Base.
Definition: cp_alienbase.h:28
aircraft_t * ufo
Definition: cp_missions.h:106
int initialOverallInterest
Definition: cp_missions.h:100
void AB_DestroyBase(alienBase_t *base)
Destroy an alien base.
static void CP_BuildBaseChooseMission(mission_t *mission)
Choose if the mission should be an alien infiltration or a build base mission.
static void CP_BuildBaseGoToBase(mission_t *mission)
Go to new base position.
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
#define CP_IsXVIStarted()
Definition: cp_xvi.h:37
nation_t * GEO_GetNation(const vec2_t pos)
Translate nation map color to nation.
void CP_BuildBaseMissionIsSuccess(mission_t *mission)
Build Base mission is over and is a success (from an alien point of view): change interest values...