UFO: Alien Invasion
Doxygen documentation generating
cp_mission_recon.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_recon.h"
37 
42 static void CP_ReconMissionIsSuccess (mission_t* mission)
43 {
48  if (CP_IsXVIStarted())
50 
51  CP_MissionRemove(mission);
52 }
53 
59 {
63 
64  CP_MissionRemove(mission);
65 }
66 
72 {
73  mission->stage = STAGE_RETURN_TO_ORBIT;
74 
75  if (mission->ufo) {
77  UFO_SetRandomDest(mission->ufo);
78  /* Display UFO on geoscape if it is detected */
79  mission->ufo->landed = false;
80  } else {
81  /* Go to next stage on next frame */
82  mission->finalDate = ccs.date;
83  }
85 }
86 
93 static bool CP_ReconMissionChoose (mission_t* mission)
94 {
95  /* mission without UFO is always a ground mission */
96  if (!mission->ufo)
97  return false;
98 
99  return (frand() > 0.5f);
100 }
101 
108 {
109  const DateTime minReconDelay(1, 0);
110  const DateTime maxReconDelay(2, 0); /* How long the UFO will fly on earth */
111 
112  assert(mission->ufo);
113 
114  mission->stage = STAGE_RECON_AIR;
115 
116  mission->finalDate = ccs.date + Date_Random(minReconDelay, maxReconDelay);
117 }
118 
126 {
127 
128  mission->stage = STAGE_MISSION_GOTO;
129 
130  /* maybe the UFO just finished a ground mission and starts a new one? */
131  if (mission->ufo) {
133  mission->ufo->landed = false;
134  }
135 
136  /* Choose a map */
137  if (CP_ChooseMap(mission, nullptr)) {
138  int counter;
139  for (counter = 0; counter < MAX_POS_LOOP; counter++) {
140  if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, nullptr))
141  continue;
142  if (GEO_PositionCloseToBase(mission->pos))
143  continue;
144  mission->posAssigned = true;
145  break;
146  }
147  if (counter >= MAX_POS_LOOP) {
148  cgi->Com_Printf("CP_ReconMissionGroundGo: Error, could not set position.\n");
149  CP_MissionRemove(mission);
150  return;
151  }
152  } else {
153  cgi->Com_Printf("CP_ReconMissionGroundGo: No map found, remove mission.\n");
154  CP_MissionRemove(mission);
155  return;
156  }
157 
158  if (mission->ufo) {
160  UFO_SendToDestination(mission->ufo, mission->pos);
161  } else {
162  /* Go to next stage on next frame */
163  mission->finalDate = ccs.date;
164  }
165 }
166 
171 static void CP_ReconMissionGround (mission_t* mission)
172 {
173  mission->stage = STAGE_RECON_GROUND;
174  mission->posAssigned = true;
175 
176  const DateTime minMissionDelay(2, 0);
177  const DateTime maxMissionDelay(3, 0);
178  mission->finalDate = ccs.date + Date_Random(minMissionDelay, maxMissionDelay);
179  /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
180  if (mission->ufo)
181  CP_UFORemoveFromGeoscape(mission, false);
182  /* mission appear on geoscape, player can go there */
183  CP_MissionAddToGeoscape(mission, false);
184 }
185 
193 {
194  return (frand() > 0.7f);
195 }
196 
201 static void CP_ReconMissionSelect (mission_t* mission)
202 {
203  if (mission->stage == STAGE_COME_FROM_ORBIT) {
204  /* this is the begining of the mission: choose between aerial or ground mission */
205  if (CP_ReconMissionChoose(mission))
206  /* This is a aerial mission */
207  CP_ReconMissionAerial(mission);
208  else
209  /* This is a ground mission */
210  CP_ReconMissionGroundGo(mission);
211  } else if (mission->stage == STAGE_RECON_GROUND) {
212  /* Ground mission may occur several times */
213  if (CP_ReconMissionNewGroundMission(mission))
214  CP_ReconMissionGroundGo(mission);
215  else
216  CP_ReconMissionLeave(mission);
217  }
218 }
219 
225 {
226  switch (mission->stage) {
227  case STAGE_NOT_ACTIVE:
228  /* Create Recon mission */
229  CP_MissionBegin(mission);
230  break;
232  case STAGE_RECON_GROUND:
233  /* Choose if a new ground mission should be started */
234  CP_ReconMissionSelect(mission);
235  break;
236  case STAGE_MISSION_GOTO:
237  /* just arrived on a new ground mission: start it */
238  CP_ReconMissionGround(mission);
239  break;
240  case STAGE_RECON_AIR:
241  /* Leave earth */
242  CP_ReconMissionLeave(mission);
243  break;
245  /* mission is over, remove mission */
246  CP_ReconMissionIsSuccess(mission);
247  break;
248  default:
249  cgi->Com_Printf("CP_ReconMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
250  CP_MissionRemove(mission);
251  break;
252  }
253 }
static void CP_ReconMissionIsSuccess(mission_t *mission)
Recon mission is over and is a success: change interest values.
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
static void CP_ReconMissionSelect(mission_t *mission)
Set recon mission type (aerial or ground).
mission definition
Definition: cp_missions.h:86
bool CP_ChooseMap(mission_t *mission, const vec2_t pos)
Choose a map for given mission.
linkedList_t * terrains
Definition: q_shared.h:486
void CP_ReconMissionGroundGo(mission_t *mission)
Set ground mission, and go to ground mission pos.
void INT_ChangeIndividualInterest(float interestFactor, interestCategory_t category)
Change individual interest value.
void CP_ReconMissionIsFailure(mission_t *mission)
Recon mission is over and is a failure: change interest values.
void CP_ReconMissionLeave(mission_t *mission)
Recon mission ends: UFO leave earth.
int AB_GetAlienBaseNumber(void)
Check number of alien bases.
const int MAX_POS_LOOP
Definition: cp_missions.cpp:62
base_t * GEO_PositionCloseToBase(const vec2_t pos)
Check if given pos is close to an existing base.
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.
ccs_t ccs
Definition: cp_campaign.cpp:63
class DateTime finalDate
Definition: cp_missions.h:103
vec2_t pos
Definition: cp_missions.h:105
static void CP_ReconMissionGround(mission_t *mission)
Start ground mission.
bool CP_GetRandomPosOnGeoscapeWithParameters(vec2_t pos, const linkedList_t *terrainTypes, const linkedList_t *cultureTypes, const linkedList_t *populationTypes, const linkedList_t *nations)
Determines a random position on geoscape that fulfills certain criteria given via parameters...
static bool CP_ReconMissionChoose(mission_t *mission)
Choose between aerial and ground mission.
void CP_ReconMissionNextStage(mission_t *mission)
Determine what action should be performed when a Recon mission stage ends.
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
Campaign mission headers.
static bool CP_ReconMissionNewGroundMission(mission_t *mission)
Choose if a new ground mission should be started.
float frand(void)
Return random values between 0 and 1.
Definition: mathlib.cpp:506
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
linkedList_t * populations
Definition: q_shared.h:487
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...
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
Definition: cp_ufo.cpp:562
bool posAssigned
Definition: cp_missions.h:112
void CP_ReconMissionAerial(mission_t *mission)
Set aerial mission.
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.
#define CP_IsXVIStarted()
Definition: cp_xvi.h:37
mapDef_t * mapDef
Definition: cp_missions.h:89
linkedList_t * cultures
Definition: q_shared.h:488