UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_mission_ufocarrier.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #include "../../../cl_shared.h"
27 #include "../../../ui/ui_dataids.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"
34 #include "../cp_alien_interest.h"
35 #include "cp_mission_ufocarrier.h"
36 
38 {
39  MIS_Foreach(mission) {
40  if (mission->category == INTERESTCATEGORY_UFOCARRIER)
41  return mission;
42  }
43 
44  return nullptr;
45 }
46 
50 static void CP_UFOCarrierMissionStart (mission_t* mission)
51 {
52  mission->idx = ++ccs.campaignStats.missions;
53  mission->finalDate = ccs.date;
54  mission->stage = STAGE_RECON_AIR;
55 }
56 
57 static void CP_UFOCarrierMissionUpdate (mission_t* mission)
58 {
59  /* delay the next update for some time */
60  const date_t delay = {2, 0};
61  mission->finalDate = Date_Add(ccs.date, delay);
62 
64  cgi->UI_PopupButton(_("UFO-Carrier"), _("The Carrier UFO is in range. Should we launch the payload?"),
65  "ui_pop;", _("Wait"), _("Don't attack the UFO-Carrier yet"),
66  "cp_attack_ufocarrier;ui_pop;", _("Launch"), _("Attack the UFO-Carrier now"),
67  nullptr, nullptr, nullptr);
68  }
69 }
70 
76 {
77  switch (mission->stage) {
78  case STAGE_NOT_ACTIVE:
80  break;
81  default:
83  break;
84  }
85 }
86 
91 {
92  /* only one carrier missions is allowed */
93  if (CP_GetCarrierMission() != nullptr)
94  return;
95 
97  if (!installationTemplate)
98  return;
99 
100  if (cgi->Cmd_Argc() == 3) {
101  const vec2_t pos = Vector2FromInt(atof(cgi->Cmd_Argv(1)), atof(cgi->Cmd_Argv(2)));
102  if (!MapIsWater(GEO_GetColor(pos, MAPTYPE_TERRAIN, nullptr))) {
103  INS_Build(installationTemplate, pos, _(installationTemplate->name));
104  GEO_CenterPosition(pos);
105  CL_EventAddMail("ufocarrier");
106  }
107  }
108 
110 }
111 
117 {
118  mission_t* mission = CP_GetCarrierMission();
119  if (mission == nullptr)
120  return;
121 
123  return;
124 
125 #if 1
126 
127  cgi->UI_RegisterText(TEXT_STANDARD, "*msgid:campaignwin");
128  CP_EndCampaign(true);
129 #else
130  /* check max amount - we can't win if we can't add the ufo */
132  return;
133 
134  const aircraft_t* ufoTemplate = UFO_GetTemplate(UFO_CARRIER);
135  aircraft_t* ufo = UFO_CreateFromTemplate(ufoTemplate);
136  if (ufo == nullptr) {
137  cgi->Com_Error(ERR_DROP, "Could not add UFO-Carrier to geoscape");
138  return;
139  }
140  ufo->mission = mission;
141  mission->ufo = ufo;
142  CP_GetRandomPosOnGeoscape(ufo->pos, true);
144  if (mission->mapDef != nullptr) {
145  cgi->Com_Printf("spawned mapdef: %s\n", mission->mapDef->id);
146  }
147 #endif
148 }
#define MAX_UFOONGEOSCAPE
Definition: cp_radar.h:27
const installationTemplate_t * INS_GetInstallationTemplateByType(installationType_t type)
Returns the installation Template for a given installation type.
char * id
Definition: q_shared.h:463
#define MIS_Foreach(var)
iterates through missions
Definition: cp_missions.h:118
void CL_EventAddMail(const char *eventMailId)
Adds the event mail to the message stack. This message is going to be added to the savegame...
Definition: cp_event.cpp:508
bool INS_HasType(installationType_t type, installationStatus_t status)
Checks whether the given installation type is available.
#define _(String)
Definition: cl_shared.h:43
void CP_EndCampaign(bool won)
Function to handle the campaign end.
Definition: cp_campaign.cpp:88
date_t date
Definition: cp_campaign.h:245
void GEO_CenterPosition(const vec2_t pos)
Start to rotate or shift the globe to the given position.
const byte * GEO_GetColor(const vec2_t pos, mapType_t type, bool *coast)
Returns the color value from geoscape of a certain mask (terrain, culture or population) at a given p...
void CP_SpawnCrashSiteMission(aircraft_t *ufo)
Spawn a new crash site after a UFO has been destroyed.
mission definition
Definition: cp_missions.h:85
struct mission_s * mission
Definition: cp_aircraft.h:152
Campaign mission headers.
void CP_AttackUFOCarrier_f(void)
Decide whether you hit and destroyed the carrier and spawns a new carrier crash site mission...
#define ERR_DROP
Definition: common.h:211
date_t finalDate
Definition: cp_missions.h:102
const aircraft_t * UFO_GetTemplate(ufoType_t ufoType)
Get the template data for the given ufo type.
Definition: cp_ufo.cpp:695
static void CP_UFOCarrierMissionStart(mission_t *mission)
Start UFO-Carrier mission.
vec3_t pos
Definition: cp_aircraft.h:131
aircraft_t * ufo
Definition: cp_missions.h:105
const cgame_import_t * cgi
static void CP_UFOCarrierMissionUpdate(mission_t *mission)
ccs_t ccs
Definition: cp_campaign.cpp:62
stats_t campaignStats
Definition: cp_campaign.h:378
aircraft_t * UFO_CreateFromTemplate(const aircraft_t *ufoTemplate)
Creates a new ufo on the geoscape from the given aircraft template.
Definition: cp_ufo.cpp:741
Engine-side time information in the game.
Definition: common.h:290
void CP_UFOCarrierNextStage(mission_t *mission)
Determine what action should be performed when a UFOCarriering mission stage ends.
date_t Date_Add(date_t a, const date_t &b)
Add two dates and return the result.
Definition: cp_time.cpp:272
installation_t * INS_Build(const installationTemplate_t *installationTemplate, const vec2_t pos, const char *name)
Build a new installation.
static mission_t * CP_GetCarrierMission(void)
#define Vector2FromInt(x, y)
Definition: vector.h:40
void CP_GetRandomPosOnGeoscape(vec2_t pos, bool noWater)
Determines a random position on geoscape.
int missions
Definition: cp_statistics.h:29
int numUFOs
Definition: cp_campaign.h:355
#define MapIsWater(color)
Definition: cp_geoscape.h:32
vec_t vec2_t[2]
Definition: ufotypes.h:38
void CP_SpawnUFOCarrier_f(void)
Spawns a UFO-Carrier mission.
An aircraft with all it's data.
Definition: cp_aircraft.h:114
mapDef_t * mapDef
Definition: cp_missions.h:88
const char *IMPORT * Cmd_Argv(int n)
mission_t * CP_CreateNewMission(interestCategory_t category, bool beginNow)
Create a new mission of given category.
missionStage_t stage
Definition: cp_missions.h:98