UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_recon.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"
36#include "cp_mission_recon.h"
37
53
66
72{
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
93static 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
171static 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
201static 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 */
211 } else if (mission->stage == STAGE_RECON_GROUND) {
212 /* Ground mission may occur several times */
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;
233 /* Choose if a new ground mission should be started */
234 CP_ReconMissionSelect(mission);
235 break;
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 */
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}
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_SUPPLY
@ INTERESTCATEGORY_RECON
@ INTERESTCATEGORY_XVI
@ INTERESTCATEGORY_TERROR_ATTACK
@ INTERESTCATEGORY_INTERCEPT
@ INTERESTCATEGORY_HARVEST
int AB_GetAlienBaseNumber(void)
Check number of alien bases.
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
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.
base_t * GEO_PositionCloseToBase(const vec2_t pos)
Check if given pos is close to an existing base.
Header for Geoscape management.
void CP_ReconMissionLeave(mission_t *mission)
Recon mission ends: UFO leave earth.
void CP_ReconMissionAerial(mission_t *mission)
Set aerial mission.
static void CP_ReconMissionSelect(mission_t *mission)
Set recon mission type (aerial or ground).
static void CP_ReconMissionIsSuccess(mission_t *mission)
Recon mission is over and is a success: change interest values.
void CP_ReconMissionNextStage(mission_t *mission)
Determine what action should be performed when a Recon mission stage ends.
void CP_ReconMissionIsFailure(mission_t *mission)
Recon mission is over and is a failure: change interest values.
static void CP_ReconMissionGround(mission_t *mission)
Start ground mission.
void CP_ReconMissionGroundGo(mission_t *mission)
Set ground mission, and go to ground mission pos.
static bool CP_ReconMissionNewGroundMission(mission_t *mission)
Choose if a new ground mission should be started.
static bool CP_ReconMissionChoose(mission_t *mission)
Choose between aerial and ground mission.
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.
const int MAX_POS_LOOP
bool CP_ChooseMap(mission_t *mission, const vec2_t pos)
Choose a map for given mission.
void CP_MissionRemoveFromGeoscape(mission_t *mission)
Removes a mission from geoscape: make it non visible and call notify functions.
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_RECON_GROUND
Definition cp_missions.h:40
@ STAGE_RETURN_TO_ORBIT
Definition cp_missions.h:51
@ STAGE_MISSION_GOTO
Definition cp_missions.h:39
@ STAGE_NOT_ACTIVE
Definition cp_missions.h:35
@ STAGE_COME_FROM_ORBIT
Definition cp_missions.h:36
@ STAGE_RECON_AIR
Definition cp_missions.h:38
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
Campaign XVI header.
#define CP_IsXVIStarted()
Definition cp_xvi.h:37
float frand(void)
Return random values between 0 and 1.
Definition mathlib.cpp:506
linkedList_t * terrains
Definition q_shared.h:486
linkedList_t * cultures
Definition q_shared.h:488
linkedList_t * populations
Definition q_shared.h:487
mission definition
Definition cp_missions.h:86
aircraft_t * ufo
mapDef_t * mapDef
Definition cp_missions.h:89
missionStage_t stage
Definition cp_missions.h:99
vec2_t pos
bool posAssigned
class DateTime finalDate