UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_supply.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_ufo.h"
31#include "../cp_missions.h"
32#include "../cp_time.h"
33#include "../cp_xvi.h"
35#include "cp_mission_supply.h"
36
42{
43 alienBase_t* base;
45
46 /* Spread XVI */
47 base = mission->data.alienBase;
48 assert(base);
50
51 CP_MissionRemove(mission);
52}
53
66
71static void CP_SupplyMissionLeave (mission_t* mission)
72{
73 assert(mission->ufo);
74 /* there must be an alien base set */
75 assert(mission->data.alienBase);
76
78
80 UFO_SetRandomDest(mission->ufo);
81 /* Display UFO on geoscape if it is detected */
82 mission->ufo->landed = false;
83}
84
90static void CP_SupplySetStayAtBase (mission_t* mission)
91{
92 const DateTime minSupplyTime(3, 0);
93 const DateTime maxSupplyTime(10, 0);
94
95 assert(mission->ufo);
96 /* there must be an alien base set */
97 assert(mission->data.alienBase);
98
99 mission->stage = STAGE_SUPPLY;
100
101 /* Maybe base has been destroyed since mission creation ? */
103 cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
104 CP_MissionRemove(mission);
105 return;
106 }
107
108 mission->finalDate = ccs.date + Date_Random(minSupplyTime, maxSupplyTime);
109
110 AB_SupplyBase(mission->data.alienBase, mission->ufo->detected);
111
112 /* ufo becomes invisible on geoscape */
113 CP_UFORemoveFromGeoscape(mission, false);
114}
115
121static void CP_SupplyGoToBase (mission_t* mission)
122{
123 alienBase_t* alienBase;
124
125 assert(mission->ufo);
126
127 mission->stage = STAGE_MISSION_GOTO;
128
129 /* Maybe base has been destroyed since mission creation ? */
131 cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
132 CP_MissionRemove(mission);
133 return;
134 }
135
136 alienBase = AB_ChooseBaseToSupply();
137 assert(alienBase);
138 mission->data.alienBase = alienBase;
139 Vector2Copy(alienBase->pos, mission->pos);
140
141 UFO_SendToDestination(mission->ufo, mission->pos);
142}
143
148static void CP_SupplyMissionCreate (mission_t* mission)
149{
150 ufoType_t ufoType;
151
152 mission->stage = STAGE_COME_FROM_ORBIT;
153
154 /* Maybe base has been destroyed since mission creation ? */
156 cgi->Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
157 CP_MissionRemove(mission);
158 return;
159 }
160
161 ufoType = CP_MissionChooseUFO(mission);
162 if (ufoType == UFO_NONE) {
163 cgi->Com_DPrintf(DEBUG_CLIENT, "Supply mission can't be spawned without UFO: removing supply mission.\n");
164 CP_MissionRemove(mission);
165 } else {
167 mission->ufo = UFO_AddToGeoscape(ufoType, nullptr, mission);
168 if (!mission->ufo) {
169 cgi->Com_Printf("CP_SupplyMissionCreate: Could not add UFO '%s', remove mission\n", cgi->Com_UFOTypeToShortName(ufoType));
170 CP_MissionRemove(mission);
171 }
172 }
173}
174
180{
181 switch (mission->stage) {
182 case STAGE_NOT_ACTIVE:
183 /* Create mission */
184 CP_SupplyMissionCreate(mission);
185 break;
187 /* Go to base position */
188 CP_SupplyGoToBase(mission);
189 break;
191 /* just arrived on base location: Supply base */
192 CP_SupplySetStayAtBase(mission);
193 break;
194 case STAGE_SUPPLY:
195 /* Leave earth */
196 CP_SupplyMissionLeave(mission);
197 break;
199 /* mission is over, remove mission */
201 break;
202 default:
203 cgi->Com_Printf("CP_SupplyMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
204 CP_MissionRemove(mission);
205 break;
206 }
207}
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_SUPPLY
@ INTERESTCATEGORY_INTERCEPT
bool AB_CheckSupplyMissionPossible(void)
Check if a supply mission is possible.
void AB_SupplyBase(alienBase_t *base, bool decreaseStealth)
Supply a base.
alienBase_t * AB_ChooseBaseToSupply(void)
Choose Alien Base that should be supplied.
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
static void CP_SupplySetStayAtBase(mission_t *mission)
UFO arrived on new base destination: Supply base.
static void CP_SupplyGoToBase(mission_t *mission)
Go to base position.
static void CP_SupplyMissionCreate(mission_t *mission)
Supply mission begins: UFO arrive on earth.
void CP_SupplyMissionIsFailure(mission_t *mission)
Supply mission is over and is a failure (from an alien point of view): change interest values.
void CP_SupplyMissionNextStage(mission_t *mission)
Determine what action should be performed when a Supply mission stage ends.
void CP_SupplyMissionIsSuccess(mission_t *mission)
Supply mission is over and is a success (from an alien point of view): change interest values.
static void CP_SupplyMissionLeave(mission_t *mission)
Supply mission ends: UFO leave earth.
Campaign mission headers.
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.
ufoType_t CP_MissionChooseUFO(const mission_t *mission)
Choose UFO type for a given mission category.
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_SUPPLY
Definition cp_missions.h:45
@ STAGE_NOT_ACTIVE
Definition cp_missions.h:35
@ STAGE_COME_FROM_ORBIT
Definition cp_missions.h:36
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
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 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 DEBUG_CLIENT
Definition defines.h:59
#define UFO_NONE
Definition scripts.h:148
short ufoType_t
Definition scripts.h:145
Alien Base.
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
class DateTime finalDate
alienBase_t * alienBase
Definition cp_missions.h:95
#define Vector2Copy(src, dest)
Definition vector.h:52