UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_hospital_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 "../../cl_team.h" /* CL_ActorGetSkillString */
27#include "../../ui/ui_dataids.h"
28#include "cp_campaign.h"
30#include "cp_hospital.h"
31#include "cp_team.h"
32
33static void HOS_EntryWoundData (const character_t& chr)
34{
35 const BodyData* bodyData = chr.teamDef->bodyTemplate;
36 const woundInfo_t& wounds = chr.wounds;
37
38 for (int bodyPart = 0; bodyPart < bodyData->numBodyParts(); ++bodyPart) {
39 if (wounds.treatmentLevel[bodyPart] == 0)
40 continue;
41 const float severity = static_cast<float>(wounds.treatmentLevel[bodyPart]) / chr.maxHP;
42 char text[MAX_VAR];
43 Com_sprintf(text, lengthof(text), CHRSH_IsTeamDefRobot(chr.teamDef) ? _("Damaged %s (damage: %i)") :
44 _("Wounded %s (damage: %i)"), _(bodyData->name(bodyPart)), wounds.treatmentLevel[bodyPart]);
45 cgi->UI_ExecuteConfunc("hospital_wounds %i %s %f \"%s\"", chr.ucn, bodyData->id(bodyPart), severity, text);
46 }
47}
48
49static const char* HOS_GetRank (const Employee& employee)
50{
51 /* Print rank for soldiers or type for other employees. */
52 if (employee.isSoldier()) {
53 const rank_t* rankPtr = CL_GetRankByIdx(employee.chr.score.rank);
54 return _(rankPtr->name);
55 }
56 return E_GetEmployeeString(employee.getType(), 1);
57}
58
59static const char* HOS_GetInjuryLevelString (const Employee& employee, float injuryLevel)
60{
61 /* If the employee is seriously wounded (HP <= 50% maxHP), make him red. */
62 if (employee.chr.HP <= (int) (employee.chr.maxHP * 0.5) || injuryLevel > 0.5f)
63 return "serious";
64
65 /* If the employee is semi-seriously wounded (HP <= 85% maxHP), make him yellow. */
66 else if (employee.chr.HP <= (int) (employee.chr.maxHP * 0.85) || injuryLevel > 0.15f)
67 return "medium";
68
69 /* no wounds and full hp */
70 else if (employee.chr.HP >= employee.chr.maxHP && injuryLevel < 0.0001f)
71 return "healthy";
72
73 return "light";
74}
75
76static inline void HOS_Entry (const Employee& employee)
77{
78 const character_t& chr = employee.chr;
79 const float injuryLevel = HOS_GetInjuryLevel(chr);
80 if (!employee.isSoldier() && chr.HP >= chr.maxHP && injuryLevel <= 0.0f)
81 return;
82
83 const char* rank = HOS_GetRank(employee);
84 const char* level = HOS_GetInjuryLevelString(employee, injuryLevel);
85 const aircraft_t* craft = AIR_IsEmployeeInAircraft(&employee, nullptr);
86
87 cgi->UI_ExecuteConfunc("hospitaladd %i \"%s\" %i %i \"%s\" \"%s\" \"%s\"",
88 chr.ucn, level, chr.HP, chr.maxHP, chr.name, rank, craft ? craft->name : "");
90}
91
92static void HOS_ImplantDetails_f (void)
93{
94 const int odIdx = atoi(cgi->Cmd_Argv(1));
95 const objDef_t* od = INVSH_GetItemByIDX(odIdx);
96 if (od == nullptr)
97 return;
99 if (def == nullptr)
100 return;
101 cgi->Com_Printf("implant: %s\n", def->id);
102}
103
108static void HOS_Init_f (void)
109{
110 if (cgi->Cmd_Argc() < 2) {
111 cgi->Com_Printf("Usage: %s <baseIDX>\n", cgi->Cmd_Argv(0));
112 return;
113 }
114 base_t* base = B_GetFoundedBaseByIDX(atoi(cgi->Cmd_Argv(1)));
115 if (base == nullptr) {
116 cgi->Com_Printf("%s: Invalid base IDX: %s\n", cgi->Cmd_Argv(0), cgi->Cmd_Argv(1));
117 return;
118 }
119
120 if (!B_GetBuildingStatus(base, B_HOSPITAL)) {
121 cgi->UI_PopWindow(false);
122 return;
123 }
124
125 bool containerSet = false;
126 for (int type = 0; type < MAX_EMPL; type++) {
127 E_Foreach(type, employee) {
128 /* Don't show soldiers who are not in this base or gone in mission */
129 if (!employee->isHiredInBase(base) || employee->isAwayFromBase())
130 continue;
131 HOS_Entry(*employee);
132 if (containerSet)
133 continue;
134 CP_SetEquipContainer(&employee->chr);
135 containerSet = true;
136 }
137 }
138}
139
140static const cmdList_t hospitalCmds[] = {
141 {"hosp_init", HOS_Init_f, "Init function for hospital menu"},
142 {"hosp_implant_details", HOS_ImplantDetails_f, "Print details for an implant"},
143 {nullptr, nullptr, nullptr}
144};
145
147{
148 cgi->Cmd_TableAddList(hospitalCmds);
149}
150
152{
153 cgi->Cmd_TableRemoveList(hospitalCmds);
154}
bool CHRSH_IsTeamDefRobot(const teamDef_t *const td)
Check if a team definition is a robot.
Share stuff between the different cgame implementations.
#define _(String)
Definition cl_shared.h:44
const char * name(const short bodyPart) const
short numBodyParts(void) const
const char * id(void) const
character_t chr
employeeType_t getType() const
Definition cp_employee.h:99
bool isSoldier() const
Definition cp_employee.h:82
const aircraft_t * AIR_IsEmployeeInAircraft(const Employee *employee, const aircraft_t *aircraft)
Tells you if an employee is assigned to an aircraft.
base_t * B_GetFoundedBaseByIDX(int baseIdx)
Array bound check for the base index.
Definition cp_base.cpp:326
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t buildingType)
Get the status associated to a building.
Definition cp_base.cpp:478
@ B_HOSPITAL
Definition cp_building.h:57
Header file for single player campaign control.
const cgame_import_t * cgi
const char * E_GetEmployeeString(employeeType_t type, int n)
Convert employeeType_t to translated string.
@ MAX_EMPL
Definition cp_employee.h:36
#define E_Foreach(employeeType, var)
float HOS_GetInjuryLevel(const character_t &chr)
Header file for hospital related stuff.
static void HOS_EntryWoundData(const character_t &chr)
static const cmdList_t hospitalCmds[]
static void HOS_Init_f(void)
Script command to initialize the hospital menu.
static void HOS_ImplantDetails_f(void)
static const char * HOS_GetInjuryLevelString(const Employee &employee, float injuryLevel)
void HOS_InitCallbacks(void)
void HOS_ShutdownCallbacks(void)
static void HOS_Entry(const Employee &employee)
static const char * HOS_GetRank(const Employee &employee)
Header file for menu related console command callbacks.
rank_t * CL_GetRankByIdx(const int index)
Returns a rank at an index.
Definition cp_rank.cpp:50
void CP_SetEquipContainer(character_t *chr)
Set up equip (floor) container for soldiers.
Definition cp_team.cpp:137
Team management for the campaign gametype headers.
level_locals_t level
Definition g_main.cpp:38
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
const implantDef_t * INVSH_GetImplantForObjDef(const objDef_t *od)
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
#define MAX_VAR
Definition shared.h:36
#define lengthof(x)
Definition shared.h:105
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
An aircraft with all it's data.
char name[MAX_VAR]
A base with all it's data.
Definition cp_base.h:84
Describes a character with all its attributes.
Definition chr_shared.h:388
const teamDef_t * teamDef
Definition chr_shared.h:413
chrScoreGlobal_t score
Definition chr_shared.h:406
woundInfo_t wounds
Definition chr_shared.h:402
char name[MAX_VAR]
Definition chr_shared.h:390
const char * id
Definition inv_shared.h:102
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
Describes a rank that a recruit can gain.
Definition cp_rank.h:29
const char * name
Definition cp_rank.h:31
const BodyData * bodyTemplate
Definition chr_shared.h:350
Info on a wound.
Definition chr_shared.h:361
int treatmentLevel[BODYPART_MAXTYPE]
Definition chr_shared.h:363