UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_buildbase.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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"
37#include "cp_mission_recon.h"
38
39#define HAPPINESS_SUBVERSION_LOSS -0.15
40
47{
48 return mission->initialOverallInterest < ccs.curCampaign->alienBaseInterest;
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);
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
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
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
137static void CP_BuildBaseSetUpBase (mission_t* mission)
138{
139 alienBase_t* base;
140 const DateTime minBuildingTime(5, 0);
141 const DateTime maxBuildingTime(10, 0);
142
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
166static void CP_BuildBaseGoToBase (mission_t* mission)
167{
168 assert(mission->ufo);
169
170 mission->stage = STAGE_MISSION_GOTO;
171
173
174 UFO_SendToDestination(mission->ufo, mission->pos);
175}
176
181static 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
231{
234 else
235 CP_BuildBaseGoToBase(mission);
236}
237
243void 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 */
253 break;
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 */
265 break;
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}
DateTime class definition.
Share stuff between the different cgame implementations.
Class describing a point of time.
Definition DateTime.h:31
void INT_ChangeIndividualInterest(float interestFactor, interestCategory_t category)
Change individual interest value.
Alien interest header.
@ INTERESTCATEGORY_BASE_ATTACK
@ INTERESTCATEGORY_BUILDING
@ INTERESTCATEGORY_SUPPLY
@ INTERESTCATEGORY_XVI
@ INTERESTCATEGORY_TERROR_ATTACK
@ INTERESTCATEGORY_INTERCEPT
@ INTERESTCATEGORY_HARVEST
void AB_SetAlienBasePosition(vec2_t pos)
Set new base position.
void AB_DestroyBase(alienBase_t *base)
Destroy an alien base.
alienBase_t * AB_BuildBase(const vec2_t pos)
Build a new alien base.
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
nation_t * GEO_GetNation(const vec2_t pos)
Translate nation map color to nation.
Header for Geoscape management.
static void CP_BuildBaseMissionLeave(mission_t *mission)
Build Base mission ends: UFO leave earth.
void CP_BuildBaseMissionBaseDestroyed(mission_t *mission)
Alien base has been destroyed: change interest values.
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.
static void CP_BuildBaseGovernmentLeave(const campaign_t *campaign, mission_t *mission)
Subverting Mission ends: UFO leave earth.
void CP_BuildBaseMissionOnSpawn(void)
Run when the mission is spawned.
#define HAPPINESS_SUBVERSION_LOSS
void CP_BuildBaseMissionIsSuccess(mission_t *mission)
Build Base mission is over and is a success (from an alien point of view): change interest values.
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_BuildBaseChooseMission(mission_t *mission)
Choose if the mission should be an alien infiltration or a build base mission.
bool CP_BasemissionIsSubvertingGovernmentMission(const mission_t *mission)
static void CP_BuildBaseGoToBase(mission_t *mission)
Go to new base position.
static void CP_BuildBaseSetUpBase(mission_t *mission)
UFO arrived on new base destination: build base.
Campaign mission header.
void CP_ReconMissionGroundGo(mission_t *mission)
Set ground mission, and go to ground mission pos.
Campaign mission headers.
bool CP_MissionBegin(mission_t *mission)
mission begins: UFO arrive on earth.
void CP_UFORemoveFromGeoscape(mission_t *mission, bool destroyed)
Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions.
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.
void CP_MissionDisableTimeLimit(mission_t *mission)
Disable time limit for given mission.
Campaign missions headers.
@ STAGE_RETURN_TO_ORBIT
Definition cp_missions.h:51
@ STAGE_MISSION_GOTO
Definition cp_missions.h:39
@ STAGE_BUILD_BASE
Definition cp_missions.h:42
@ STAGE_NOT_ACTIVE
Definition cp_missions.h:35
@ STAGE_COME_FROM_ORBIT
Definition cp_missions.h:36
@ STAGE_SUBVERT_GOV
Definition cp_missions.h:44
void NAT_SetHappiness(const float minhappiness, nation_t *nation, const float happiness)
Updates the nation happiness.
const nationInfo_t * NAT_GetCurrentMonthInfo(const nation_t *const nation)
Get the current month nation stats.
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
Campaign geoscape time header.
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
Definition cp_ufo.cpp:562
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_SpreadXVIAtPos(const vec2_t pos)
Spread XVI at a given position.
Definition cp_xvi.cpp:56
Campaign XVI header.
#define CP_IsXVIStarted()
Definition cp_xvi.h:37
#define DEBUG_CLIENT
Definition defines.h:59
Alien Base.
float minhappiness
mission definition
Definition cp_missions.h:86
aircraft_t * ufo
int initialOverallInterest
missionStage_t stage
Definition cp_missions.h:99
vec2_t pos
union mission_t::missionData_t data
class DateTime finalDate
Nation definition.
Definition cp_nation.h:46
Detailed information about the nation relationship (currently per month, but could be used elsewhere)...
Definition cp_nation.h:35
float happiness
Definition cp_nation.h:39
alienBase_t * alienBase
Definition cp_missions.h:95