UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_mission_recon.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 
26 #include "../../../cl_shared.h"
27 #include "../cp_campaign.h"
28 #include "../cp_alienbase.h"
29 #include "../cp_geoscape.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_recon.h"
36 
41 static void CP_ReconMissionIsSuccess (mission_t* mission)
42 {
47  if (CP_IsXVIStarted())
49 
50  CP_MissionRemove(mission);
51 }
52 
58 {
62 
63  CP_MissionRemove(mission);
64 }
65 
71 {
72  mission->stage = STAGE_RETURN_TO_ORBIT;
73 
74  if (mission->ufo) {
76  UFO_SetRandomDest(mission->ufo);
77  /* Display UFO on geoscape if it is detected */
78  mission->ufo->landed = false;
79  } else {
80  /* Go to next stage on next frame */
81  mission->finalDate = ccs.date;
82  }
84 }
85 
92 static bool CP_ReconMissionChoose (mission_t* mission)
93 {
94  /* mission without UFO is always a ground mission */
95  if (!mission->ufo)
96  return false;
97 
98  return (frand() > 0.5f);
99 }
100 
107 {
108  const date_t minReconDelay = {1, 0};
109  const date_t reconDelay = {2, 0}; /* How long the UFO will fly on earth */
110 
111  assert(mission->ufo);
112 
113  mission->stage = STAGE_RECON_AIR;
114 
115  mission->finalDate = Date_Add(ccs.date, Date_Random(minReconDelay, reconDelay));
116 }
117 
125 {
126 
127  mission->stage = STAGE_MISSION_GOTO;
128 
129  /* maybe the UFO just finished a ground mission and starts a new one? */
130  if (mission->ufo) {
132  mission->ufo->landed = false;
133  }
134 
135  /* Choose a map */
136  if (CP_ChooseMap(mission, nullptr)) {
137  int counter;
138  for (counter = 0; counter < MAX_POS_LOOP; counter++) {
139  if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, nullptr))
140  continue;
141  if (GEO_PositionCloseToBase(mission->pos))
142  continue;
143  mission->posAssigned = true;
144  break;
145  }
146  if (counter >= MAX_POS_LOOP) {
147  cgi->Com_Printf("CP_ReconMissionGroundGo: Error, could not set position.\n");
148  CP_MissionRemove(mission);
149  return;
150  }
151  } else {
152  cgi->Com_Printf("CP_ReconMissionGroundGo: No map found, remove mission.\n");
153  CP_MissionRemove(mission);
154  return;
155  }
156 
157  if (mission->ufo) {
159  UFO_SendToDestination(mission->ufo, mission->pos);
160  } else {
161  /* Go to next stage on next frame */
162  mission->finalDate = ccs.date;
163  }
164 }
165 
170 static void CP_ReconMissionGround (mission_t* mission)
171 {
172  const date_t minMissionDelay = {2, 0};
173  const date_t missionDelay = {3, 0};
174 
175  mission->stage = STAGE_RECON_GROUND;
176  mission->posAssigned = true;
177 
178  mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
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.
linkedList_t * terrains
Definition: q_shared.h:486
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
static void CP_ReconMissionSelect(mission_t *mission)
Set recon mission type (aerial or ground).
bool CP_ChooseMap(mission_t *mission, const vec2_t pos)
Choose a map for given mission.
void CP_ReconMissionGroundGo(mission_t *mission)
Set ground mission, and go to ground mission pos.
linkedList_t * populations
Definition: q_shared.h:487
bool posAssigned
Definition: cp_missions.h:111
date_t date
Definition: cp_campaign.h:245
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.
mission definition
Definition: cp_missions.h:85
const int MAX_POS_LOOP
Definition: cp_missions.cpp:61
date_t finalDate
Definition: cp_missions.h:102
aircraft_t * ufo
Definition: cp_missions.h:105
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:62
Engine-side time information in the game.
Definition: common.h:290
static void CP_ReconMissionGround(mission_t *mission)
Start ground mission.
date_t Date_Add(date_t a, const date_t &b)
Add two dates and return the result.
Definition: cp_time.cpp:272
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
void CP_UFORemoveFromGeoscape(mission_t *mission, bool destroyed)
Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions...
linkedList_t * cultures
Definition: q_shared.h:488
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
Definition: cp_ufo.cpp:562
void CP_ReconMissionAerial(mission_t *mission)
Set aerial mission.
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
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.
#define CP_IsXVIStarted()
Definition: cp_xvi.h:37
vec2_t pos
Definition: cp_missions.h:104
missionStage_t stage
Definition: cp_missions.h:98