UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_mission_supply.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_ufo.h"
30 #include "../cp_missions.h"
31 #include "../cp_time.h"
32 #include "../cp_xvi.h"
33 #include "../cp_alien_interest.h"
34 #include "cp_mission_supply.h"
35 
41 {
42  alienBase_t* base;
44 
45  /* Spread XVI */
46  base = mission->data.alienBase;
47  assert(base);
48  CP_SpreadXVIAtPos(base->pos);
49 
50  CP_MissionRemove(mission);
51 }
52 
58 {
62 
63  CP_MissionRemove(mission);
64 }
65 
70 static void CP_SupplyMissionLeave (mission_t* mission)
71 {
72  assert(mission->ufo);
73  /* there must be an alien base set */
74  assert(mission->data.alienBase);
75 
76  mission->stage = STAGE_RETURN_TO_ORBIT;
77 
79  UFO_SetRandomDest(mission->ufo);
80  /* Display UFO on geoscape if it is detected */
81  mission->ufo->landed = false;
82 }
83 
89 static void CP_SupplySetStayAtBase (mission_t* mission)
90 {
91  const date_t minSupplyTime = {3, 0};
92  const date_t supplyTime = {10, 0};
94  assert(mission->ufo);
95  /* there must be an alien base set */
96  assert(mission->data.alienBase);
97 
98  mission->stage = STAGE_SUPPLY;
99 
100  /* Maybe base has been destroyed since mission creation ? */
102  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
103  CP_MissionRemove(mission);
104  return;
105  }
106 
107  mission->finalDate = Date_Add(ccs.date, Date_Random(minSupplyTime, supplyTime));
108 
109  AB_SupplyBase(mission->data.alienBase, mission->ufo->detected);
110 
111  /* ufo becomes invisible on geoscape */
112  CP_UFORemoveFromGeoscape(mission, false);
113 }
114 
120 static void CP_SupplyGoToBase (mission_t* mission)
121 {
122  alienBase_t* alienBase;
123 
124  assert(mission->ufo);
125 
126  mission->stage = STAGE_MISSION_GOTO;
127 
128  /* Maybe base has been destroyed since mission creation ? */
130  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
131  CP_MissionRemove(mission);
132  return;
133  }
134 
135  alienBase = AB_ChooseBaseToSupply();
136  assert(alienBase);
137  mission->data.alienBase = alienBase;
138  Vector2Copy(alienBase->pos, mission->pos);
139 
140  UFO_SendToDestination(mission->ufo, mission->pos);
141 }
142 
147 static void CP_SupplyMissionCreate (mission_t* mission)
148 {
149  ufoType_t ufoType;
150 
151  mission->stage = STAGE_COME_FROM_ORBIT;
152 
153  /* Maybe base has been destroyed since mission creation ? */
155  cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
156  CP_MissionRemove(mission);
157  return;
158  }
159 
160  ufoType = CP_MissionChooseUFO(mission);
161  if (ufoType == UFO_NONE) {
162  cgi->Com_DPrintf(DEBUG_CLIENT, "Supply mission can't be spawned without UFO: removing supply mission.\n");
163  CP_MissionRemove(mission);
164  } else {
166  mission->ufo = UFO_AddToGeoscape(ufoType, nullptr, mission);
167  if (!mission->ufo) {
168  cgi->Com_Printf("CP_SupplyMissionCreate: Could not add UFO '%s', remove mission\n", cgi->Com_UFOTypeToShortName(ufoType));
169  CP_MissionRemove(mission);
170  }
171  }
172 }
173 
179 {
180  switch (mission->stage) {
181  case STAGE_NOT_ACTIVE:
182  /* Create mission */
183  CP_SupplyMissionCreate(mission);
184  break;
186  /* Go to base position */
187  CP_SupplyGoToBase(mission);
188  break;
189  case STAGE_MISSION_GOTO:
190  /* just arrived on base location: Supply base */
191  CP_SupplySetStayAtBase(mission);
192  break;
193  case STAGE_SUPPLY:
194  /* Leave earth */
195  CP_SupplyMissionLeave(mission);
196  break;
198  /* mission is over, remove mission */
199  CP_SupplyMissionIsSuccess(mission);
200  break;
201  default:
202  cgi->Com_Printf("CP_SupplyMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
203  CP_MissionRemove(mission);
204  break;
205  }
206 }
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
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:146
date_t date
Definition: cp_campaign.h:245
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...
mission definition
Definition: cp_missions.h:85
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.
#define DEBUG_CLIENT
Definition: defines.h:59
date_t finalDate
Definition: cp_missions.h:102
Campaign mission headers.
aircraft_t * ufo
Definition: cp_missions.h:105
ufoType_t CP_MissionChooseUFO(const mission_t *mission)
Choose UFO type for a given mission category.
const cgame_import_t * cgi
const char *IMPORT * Com_UFOTypeToShortName(ufoType_t type)
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:62
Engine-side time information in the game.
Definition: common.h:290
alienBase_t * alienBase
Definition: cp_missions.h:94
date_t Date_Add(date_t a, const date_t &b)
Add two dates and return the result.
Definition: cp_time.cpp:272
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
union mission_s::missionData_t data
static void CP_SupplyMissionLeave(mission_t *mission)
Supply mission ends: UFO leave earth.
bool detected
Definition: cp_aircraft.h:166
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
Alien Base.
Definition: cp_alienbase.h:28
void AB_SupplyBase(alienBase_t *base, bool decreaseStealth)
Supply a base.
vec2_t pos
Definition: cp_alienbase.h:30
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
static void CP_SupplyGoToBase(mission_t *mission)
Go to base position.
static void CP_SupplySetStayAtBase(mission_t *mission)
UFO arrived on new base destination: Supply base.
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
vec2_t pos
Definition: cp_missions.h:104
#define UFO_NONE
Definition: scripts.h:149
missionStage_t stage
Definition: cp_missions.h:98