UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_mission_harvest.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"
33#include "../cp_xvi.h"
35#include "cp_mission_harvest.h"
36#include "cp_mission_recon.h"
37
52
65
70static void CP_HarvestMissionStart (mission_t* mission)
71{
72 const DateTime minMissionDelay(2, 0);
73 const DateTime maxMissionDelay(3, 0);
74
75 mission->stage = STAGE_HARVEST;
76
77 if (mission->ufo) {
78 mission->finalDate = ccs.date + Date_Random(minMissionDelay, maxMissionDelay);
79 /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
80 CP_UFORemoveFromGeoscape(mission, false);
81 } else {
82 /* Go to next stage on next frame */
83 mission->finalDate = ccs.date;
84 }
85
86 /* mission appear on geoscape, player can go there */
87 CP_MissionAddToGeoscape(mission, false);
88}
89
97static bool CP_ChooseNation (const mission_t* mission, linkedList_t** nationList)
98{
99 int randomNumber, max = 0;
100 /* Increase this factor to make probability to select non-infected nation higher
101 * Used to make sure that non-infected nation can still be attacked */
102 const int OFFSET = 1;
103
104 if (mission->ufo)
105 return false;
106
107 /* favour mission with higher XVI level */
108 NAT_Foreach(nation) {
109 const nationInfo_t* stats = NAT_GetCurrentMonthInfo(nation);
110 max += OFFSET + stats->xviInfection;
111 }
112
113 randomNumber = (int) (frand() * (float) max);
114
115 /* Select the corresponding nation */
116 NAT_Foreach(nation) {
117 const nationInfo_t* stats = NAT_GetCurrentMonthInfo(nation);
118 randomNumber -= OFFSET + stats->xviInfection;
119 if (randomNumber < 0) {
120 cgi->LIST_AddString(nationList, nation->id);
121 return true;
122 }
123 }
124
125 return false;
126}
127
136{
137 mission->stage = STAGE_MISSION_GOTO;
138
139 /* Choose a map */
140 if (CP_ChooseMap(mission, nullptr)) {
141 int counter;
142 linkedList_t* nationList = nullptr;
143 const bool nationTest = CP_ChooseNation(mission, &nationList);
144 for (counter = 0; counter < MAX_POS_LOOP; counter++) {
145 if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, nationTest ? nationList : nullptr))
146 continue;
147 if (GEO_PositionCloseToBase(mission->pos))
148 continue;
149 mission->posAssigned = true;
150 break;
151 }
152 if (counter >= MAX_POS_LOOP) {
153 cgi->Com_Printf("CP_HarvestMissionGo: Error, could not set position.\n");
154 CP_MissionRemove(mission);
155 return;
156 }
157 cgi->LIST_Delete(&nationList);
158 } else {
159 cgi->Com_Printf("CP_HarvestMissionGo: No map found, remove mission.\n");
160 CP_MissionRemove(mission);
161 return;
162 }
163
164 if (mission->ufo) {
166 UFO_SendToDestination(mission->ufo, mission->pos);
167 } else {
168 /* Go to next stage on next frame */
169 mission->finalDate = ccs.date;
170 }
171}
172
178{
179 switch (mission->stage) {
180 case STAGE_NOT_ACTIVE:
181 /* Create Harvesting mission */
182 CP_MissionBegin(mission);
183 break;
185 /* Go to mission */
186 CP_HarvestMissionGo(mission);
187 break;
189 /* just arrived on a new Harvesting mission: start it */
190 CP_HarvestMissionStart(mission);
191 break;
192 case STAGE_HARVEST:
193 /* Leave earth */
194 CP_ReconMissionLeave(mission);
195 break;
197 /* mission is over, remove mission */
199 break;
200 default:
201 cgi->Com_Printf("CP_HarvestMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
202 CP_MissionRemove(mission);
203 break;
204 }
205}
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_RECON
@ INTERESTCATEGORY_XVI
@ INTERESTCATEGORY_TERROR_ATTACK
@ INTERESTCATEGORY_INTERCEPT
@ INTERESTCATEGORY_HARVEST
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.
static bool CP_ChooseNation(const mission_t *mission, linkedList_t **nationList)
Choose nation if needed for given mission.
static void CP_HarvestMissionStart(mission_t *mission)
Start Harvesting mission.
void CP_HarvestMissionNextStage(mission_t *mission)
Determine what action should be performed when a Harvesting mission stage ends.
static void CP_HarvestMissionIsSuccess(mission_t *mission)
Harvesting mission is over and is a success: change interest values.
void CP_HarvestMissionIsFailure(mission_t *mission)
Harvesting mission is over and is a failure: change interest values.
void CP_HarvestMissionGo(mission_t *mission)
Set Harvest mission, and go to mission pos.
Campaign mission headers.
void CP_ReconMissionLeave(mission_t *mission)
Recon mission ends: UFO leave earth.
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.
@ STAGE_RETURN_TO_ORBIT
Definition cp_missions.h:51
@ STAGE_HARVEST
Definition cp_missions.h:49
@ 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
const nationInfo_t * NAT_GetCurrentMonthInfo(const nation_t *const nation)
Get the current month nation stats.
#define NAT_Foreach(var)
iterates trough nations
Definition cp_nation.h:80
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
Campaign XVI header.
#define CP_IsXVIStarted()
Definition cp_xvi.h:37
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
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
Detailed information about the nation relationship (currently per month, but could be used elsewhere)...
Definition cp_nation.h:35
int xviInfection
Definition cp_nation.h:40