UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_terror.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_geoscape.h"
30#include "../cp_ufo.h"
31#include "../cp_missions.h"
32#include "../cp_time.h"
34#include "cp_mission_recon.h"
35#include "cp_mission_terror.h"
36
48
62
63
68{
69 /* Prevent multiple terror missions per cycle by resetting interest. */
71}
72
73
79{
80 const DateTime minMissionDelay(2, 0);
81 const DateTime maxMissionDelay(3, 0);
82
83 mission->stage = STAGE_TERROR_MISSION;
84
85 mission->finalDate = ccs.date + Date_Random(minMissionDelay, maxMissionDelay);
86 /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
87 if (mission->ufo)
88 CP_UFORemoveFromGeoscape(mission, false);
89 /* mission appear on geoscape, player can go there */
90 CP_MissionAddToGeoscape(mission, false);
91}
92
97static city_t* CP_ChooseCity (void)
98{
99 if (ccs.numCities > 0) {
100 const int randnumber = rand() % ccs.numCities;
101
102 return (city_t*) cgi->LIST_GetByIdx(ccs.cities, randnumber);
103 }
104
105 return nullptr;
106}
107
108static const mission_t* CP_TerrorInCity (const city_t* city)
109{
110 if (!city)
111 return nullptr;
112
113 MIS_Foreach(mission) {
114 if (mission->category == INTERESTCATEGORY_TERROR_ATTACK
115 && mission->stage <= STAGE_TERROR_MISSION
116 && Vector2Equal(mission->pos, city->pos))
117 return mission;
118 }
119 return nullptr;
120}
121
127static void CP_TerrorMissionGo (mission_t* mission)
128{
129 int counter;
130
131 mission->stage = STAGE_MISSION_GOTO;
132
133 /* Choose a map */
134 for (counter = 0; counter < MAX_POS_LOOP; counter++) {
135 city_t* city = CP_ChooseCity();
136
137 if (!city)
138 continue;
139
140 if (GEO_PositionCloseToBase(city->pos))
141 continue;
142
143 if (!CP_ChooseMap(mission, city->pos))
144 continue;
145
146 if (CP_TerrorInCity(city))
147 continue;
148
149 Vector2Copy(city->pos, mission->pos);
150 mission->data.city = city;
151 mission->posAssigned = true;
152 break;
153 }
154 if (counter >= MAX_POS_LOOP) {
155 cgi->Com_DPrintf(DEBUG_CLIENT, "CP_TerrorMissionGo: Could not set position.\n");
156 CP_MissionRemove(mission);
157 return;
158 }
159
160 if (mission->ufo) {
162 UFO_SendToDestination(mission->ufo, mission->pos);
163 } else {
164 /* Go to next stage on next frame */
165 mission->finalDate = ccs.date;
166 }
167}
168
174{
175 switch (mission->stage) {
176 case STAGE_NOT_ACTIVE:
177 /* Create Terror attack mission */
178 CP_MissionBegin(mission);
179 break;
181 /* Go to mission */
182 CP_TerrorMissionGo(mission);
183 break;
185 /* just arrived on a new Terror attack mission: start it */
186 CP_TerrorMissionStart(mission);
187 break;
189 /* Leave earth */
190 CP_ReconMissionLeave(mission);
191 break;
193 /* mission is over, remove mission */
195 break;
196 default:
197 cgi->Com_Printf("CP_TerrorMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
198 CP_MissionRemove(mission);
199 break;
200 }
201}
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_TERROR_ATTACK
@ INTERESTCATEGORY_INTERCEPT
@ INTERESTCATEGORY_HARVEST
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
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.
Campaign mission headers.
void CP_TerrorMissionIsFailure(mission_t *mission)
Terror attack mission is over and is a failure: change interest values.
static const mission_t * CP_TerrorInCity(const city_t *city)
void CP_TerrorMissionStart(mission_t *mission)
Start Terror attack mission.
static void CP_TerrorMissionGo(mission_t *mission)
Set Terror attack mission, and go to Terror attack mission pos.
static city_t * CP_ChooseCity(void)
Choose a city for terror mission.
void CP_TerrorMissionIsSuccess(mission_t *mission)
Terror attack mission is over and is a success: change interest values.
void CP_TerrorMissionOnSpawn(void)
Run when the mission is spawned.
void CP_TerrorMissionNextStage(mission_t *mission)
Determine what action should be performed when a Terror attack mission stage ends.
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_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.
#define MIS_Foreach(var)
iterates through missions
@ 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_TERROR_MISSION
Definition cp_missions.h:41
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
#define DEBUG_CLIENT
Definition defines.h:59
City definition.
Definition cp_nation.h:70
vec2_t pos
Definition cp_nation.h:73
mission definition
Definition cp_missions.h:86
aircraft_t * ufo
missionStage_t stage
Definition cp_missions.h:99
vec2_t pos
union mission_t::missionData_t data
bool posAssigned
class DateTime finalDate
#define Vector2Equal(a, b)
Definition vector.h:67
#define Vector2Copy(src, dest)
Definition vector.h:52