UFO: Alien Invasion
cp_event_callbacks.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2022 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #include "../../cl_shared.h"
26 #include "../../ui/ui_dataids.h" /* TEXT_STANDARD */
27 #include "cp_campaign.h"
28 #include "cp_geoscape.h"
29 #include "cp_event_callbacks.h"
30 #include "cp_missions.h"
31 
37 static void CP_AddTechAsResearchable_f (void)
38 {
39  if (cgi->Cmd_Argc() < 2) {
40  cgi->Com_Printf("Usage: %s <tech>\n", cgi->Cmd_Argv(0));
41  return;
42  }
43 
44  const char* techID = cgi->Cmd_Argv(1);
45  technology_t* tech = RS_GetTechByID(techID);
47 }
48 
56 static void CP_AddItemAsCollected_f (void)
57 {
58  int baseID;
59  const char* id;
60  base_t* base;
61  const objDef_t* item;
62 
63  if (cgi->Cmd_Argc() < 2) {
64  cgi->Com_Printf("Usage: %s <item>\n", cgi->Cmd_Argv(0));
65  return;
66  }
67 
68  id = cgi->Cmd_Argv(1);
69  baseID = atoi(cgi->Cmd_Argv(2));
70  base = B_GetBaseByIDX(baseID);
71  if (base == nullptr)
72  return;
73 
74  /* i = item index */
75  item = INVSH_GetItemByIDSilent(id);
76  if (item) {
77  technology_t* tech = RS_GetTechForItem(item);
78  base->storage.numItems[item->idx]++;
79  cgi->Com_DPrintf(DEBUG_CLIENT, "add item: '%s'\n", item->id);
80  RS_MarkCollected(tech);
81  }
82 }
83 
88 static void CP_ChangeNationHappiness_f (void)
89 {
90  float change;
91  nation_t* nation;
92  const nationInfo_t* stats;
93  const mission_t* mission = GEO_GetSelectedMission();
94 
95  if (cgi->Cmd_Argc() < 2) {
96  cgi->Com_Printf("Usage: %s <absolute change value>\n", cgi->Cmd_Argv(0));
97  return;
98  }
99  change = atof(cgi->Cmd_Argv(1));
100 
101  if (!mission) {
102  cgi->Com_Printf("No mission selected - could not determine nation to use\n");
103  return;
104  }
105 
106  nation = GEO_GetNation(mission->pos);
107  assert(nation);
108 
109  stats = NAT_GetCurrentMonthInfo(nation);
110  NAT_SetHappiness(ccs.curCampaign->minhappiness, nation, stats->happiness + change);
111 }
112 
118 static void CP_EndGame_f (void)
119 {
120  cgi->UI_RegisterText(TEXT_STANDARD, _("Congratulations! You have reached the end of the UFO:AI campaign.\n"
121  "However, this is not the end of the road. The game remains in development.\n"
122  "The campaign will be expanded with new missions, new enemies, "
123  "new UFOs, new player controllable craft and more research.\n\n"
124  "And YOU can help make it happen! Visit our forums or IRC channel to find\n"
125  "out what you can do to help finish this game. Alternatively, you can just\n"
126  "come by and talk about the game, or find other players for a multiplayer game.\n\n"
127  "Thank you for playing, and we hope to see you around.\n\n"
128  " - The UFO:AI development team"));
129  CP_EndCampaign(true);
130 }
131 
133 static const cmdList_t cp_commands[] = {
134  {"cp_add_researchable", CP_AddTechAsResearchable_f, "Add a tech as researchable"},
135  {"cp_add_item", CP_AddItemAsCollected_f, "Add an item as collected"},
136  {"cp_changehappiness", CP_ChangeNationHappiness_f, "Function to raise or lower nation happiness."},
137  {"cp_endgame", CP_EndGame_f, "This command will end the current campaign"},
138 
139  {nullptr, nullptr, nullptr}
140 };
141 
148 {
149  const cmdList_t* commands;
150 
151  for (commands = cp_commands; commands->name; commands++)
152  if (add)
153  cgi->Cmd_AddCommand(commands->name, commands->function, commands->description);
154  else
155  cgi->Cmd_RemoveCommand(commands->name);
156 }
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn&#39;t found.
Definition: inv_shared.cpp:249
const nationInfo_t * NAT_GetCurrentMonthInfo(const nation_t *const nation)
Get the current month nation stats.
Definition: cp_nation.cpp:133
mission definition
Definition: cp_missions.h:86
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
void RS_MarkOneResearchable(technology_t *tech)
Marks one tech as researchable.
A base with all it&#39;s data.
Definition: cp_base.h:84
#define _(String)
Definition: cl_shared.h:44
static const cmdList_t cp_commands[]
mission trigger functions
void CP_EndCampaign(bool won)
Function to handle the campaign end.
Definition: cp_campaign.cpp:89
Detailed information about the nation relationship (currently per month, but could be used elsewhere)...
Definition: cp_nation.h:35
const char * description
Definition: cmd.h:89
const char *IMPORT * Cmd_Argv(int n)
xcommand_t function
Definition: cmd.h:88
QGL_EXTERN GLuint * id
Definition: r_gl.h:86
Nation definition.
Definition: cp_nation.h:46
const char * id
Definition: inv_shared.h:268
void CP_CampaignTriggerFunctions(bool add)
Add/Remove temporary mission trigger functions.
float happiness
Definition: cp_nation.h:39
#define DEBUG_CLIENT
Definition: defines.h:59
void NAT_SetHappiness(const float minhappiness, nation_t *nation, const float happiness)
Updates the nation happiness.
Definition: cp_nation.cpp:189
float minhappiness
Definition: cp_campaign.h:187
Campaign missions headers.
const char * name
Definition: cmd.h:87
void RS_MarkCollected(technology_t *tech)
Marks a give technology as collected.
static void CP_AddItemAsCollected_f(void)
For things like craft_ufo_scout that are no real items this function will increase the collected coun...
const cgame_import_t * cgi
ccs_t ccs
Definition: cp_campaign.cpp:63
base_t * B_GetBaseByIDX(int baseIdx)
Array bound check for the base index. Will also return unfounded bases as long as the index is in the...
Definition: cp_base.cpp:313
vec2_t pos
Definition: cp_missions.h:105
Header for Geoscape management.
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
campaign_t * curCampaign
Definition: cp_campaign.h:378
static void CP_AddTechAsResearchable_f(void)
This is the technology parsed from research.ufo.
Definition: cp_research.h:139
Definition: cmd.h:86
#define GEO_GetSelectedMission()
Definition: cp_geoscape.h:59
Header file for single player campaign control.
static void CP_EndGame_f(void)
static void CP_ChangeNationHappiness_f(void)
Changes nation happiness by given value.
technology_t * RS_GetTechForItem(const objDef_t *item)
Returns technology entry for an item.
nation_t * GEO_GetNation(const vec2_t pos)
Translate nation map color to nation.