UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_event_callbacks.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
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
56static 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
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
118static 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
133static 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}
Share stuff between the different cgame implementations.
#define _(String)
Definition cl_shared.h:44
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
void CP_EndCampaign(bool won)
Function to handle the campaign end.
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
static void CP_ChangeNationHappiness_f(void)
Changes nation happiness by given value.
static void CP_EndGame_f(void)
static void CP_AddItemAsCollected_f(void)
For things like craft_ufo_scout that are no real items this function will increase the collected coun...
static void CP_AddTechAsResearchable_f(void)
static const cmdList_t cp_commands[]
mission trigger functions
void CP_CampaignTriggerFunctions(bool add)
Add/Remove temporary mission trigger functions.
nation_t * GEO_GetNation(const vec2_t pos)
Translate nation map color to nation.
Header for Geoscape management.
#define GEO_GetSelectedMission()
Definition cp_geoscape.h:59
Campaign missions headers.
void NAT_SetHappiness(const float minhappiness, nation_t *nation, const float happiness)
Updates the nation happiness.
const nationInfo_t * NAT_GetCurrentMonthInfo(const nation_t *const nation)
Get the current month nation stats.
void RS_MarkOneResearchable(technology_t *tech)
Marks one tech as researchable.
void RS_MarkCollected(technology_t *tech)
Marks a give technology as collected.
technology_t * RS_GetTechForItem(const objDef_t *item)
Returns technology entry for an item.
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
#define DEBUG_CLIENT
Definition defines.h:59
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
QGL_EXTERN GLuint * id
Definition r_gl.h:86
A base with all it's data.
Definition cp_base.h:84
equipDef_t storage
Definition cp_base.h:112
const char * description
Definition cmd.h:89
const char * name
Definition cmd.h:87
xcommand_t function
Definition cmd.h:88
int numItems[MAX_OBJDEFS]
Definition inv_shared.h:608
mission definition
Definition cp_missions.h:86
vec2_t pos
Nation definition.
Definition cp_nation.h:46
Detailed information about the nation relationship (currently per month, but could be used elsewhere)...
Definition cp_nation.h:35
float happiness
Definition cp_nation.h:39
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
const char * id
Definition inv_shared.h:268
This is the technology parsed from research.ufo.
@ TEXT_STANDARD
Definition ui_dataids.h:30