UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_hospital.cpp
Go to the documentation of this file.
1
6
7/*
8Copyright (C) 2002-2025 UFO: Alien Invasion.
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25*/
26
27#include "../../cl_shared.h"
28#include "cp_campaign.h"
29#include "cp_hospital.h"
30
31#define GET_HP_HEALING( ab ) (1 + (ab) * 15/MAX_SKILL)
32
33static void HOS_HealWounds (character_t* chr, int healing)
34{
35 woundInfo_t& wounds = chr->wounds;
36
37 for (int bodyPart = 0; bodyPart < chr->teamDef->bodyTemplate->numBodyParts(); ++bodyPart) {
38 if (wounds.treatmentLevel[bodyPart] <= 0)
39 continue;
40 wounds.treatmentLevel[bodyPart] = std::max(0, wounds.treatmentLevel[bodyPart] - healing);
41 }
42}
43
51bool HOS_HealCharacter (character_t* chr, bool hospital)
52{
53 assert(chr);
54 float healing = ccs.curCampaign->healingRate;
55
56 if (hospital) {
57 healing *= GET_HP_HEALING(chr->score.skills[ABILITY_POWER]);
58 HOS_HealWounds(chr, healing);
59 }
60
61 if (chr->HP < chr->maxHP) {
62 /* if the character has less that 100 hitpoints, he will be disadvantaged by using the percentage
63 * method of allocating hitpoints. So just give the character "healing" as Hitpoints, otherwise
64 * allocate "healing" as a percentage of the characters total hitpoints. */
65 if (chr->maxHP < INITIAL_HP)
66 chr->HP = std::min(chr->HP + static_cast<int>(healing), chr->maxHP);
67 else
68 chr->HP = std::min(chr->HP + static_cast<int>(((healing / 100.0f) * chr->maxHP)), chr->maxHP);
69
70 if (chr->HP == chr->maxHP)
71 return false;
72 return true;
73 }
74 return false;
75}
76
82void HOS_HospitalRun (void)
83{
84 for (int i = 0; i < MAX_EMPL; i++) {
86 E_Foreach(type, employee) {
87 if (!employee->isHired())
88 continue;
89 const bool hospital = B_GetBuildingStatus(employee->baseHired, B_HOSPITAL);
90 HOS_HealCharacter(&(employee->chr), hospital);
91 CHRSH_UpdateImplants(employee->chr);
92 }
93 }
94}
95
97{
98 float injuryLevel = 0.0f;
99
100 const BodyData* const bt = chr.teamDef->bodyTemplate;
101 for (int i = 0; i < bt->numBodyParts(); ++i) {
102 const float woundLevel = chr.wounds.treatmentLevel[i];
103 if (woundLevel * 0.5f >= bt->woundThreshold(i) * chr.maxHP)
104 injuryLevel += woundLevel / chr.maxHP;
105 }
106
107 return injuryLevel;
108}
109
111{
112 return HOS_GetInjuryLevel(chr) > 0.0001f || chr.HP < chr.maxHP;
113}
114
115#ifdef DEBUG
119static void HOS_HealAll_f (void)
120{
121 if (cgi->Cmd_Argc() < 2) {
122 cgi->Com_Printf("Usage: %s <baseIDX>\n", cgi->Cmd_Argv(0));
123 return;
124 }
125 base_t* base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(1)));
126 if (!base) {
127 cgi->Com_Printf("Invalid base idx\n");
128 return;
129 }
130
131 for (int type = 0; type < MAX_EMPL; type++) {
132 E_Foreach(type, employee) {
133 if (!employee->isHiredInBase(base))
134 continue;
135 employee->chr.HP = employee->chr.maxHP;
136 }
137 }
138}
139
143static void HOS_HurtAll_f (void)
144{
145 if (cgi->Cmd_Argc() < 2) {
146 cgi->Com_Printf("Usage: %s <baseIDX> [amount]\n", cgi->Cmd_Argv(0));
147 return;
148 }
149 base_t* base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(1)));
150 if (!base) {
151 cgi->Com_Printf("Invalid base idx\n");
152 return;
153 }
154
155 int amount;
156 if (cgi->Cmd_Argc() >= 3)
157 amount = atoi(cgi->Cmd_Argv(1));
158 else
159 amount = 1;
160
161 for (int type = 0; type < MAX_EMPL; type++) {
162 E_Foreach(type, employee) {
163 /* only those employees, that are in the current base */
164 if (!employee->isHiredInBase(base))
165 continue;
166 employee->chr.HP = std::max(0, employee->chr.HP - amount);
167 }
168 }
169}
170#endif
171
178{
179#ifdef DEBUG
180 cgi->Cmd_AddCommand("debug_hosp_hurt_all", HOS_HurtAll_f, "Debug function to hurt all employees in the current base by one");
181 cgi->Cmd_AddCommand("debug_hosp_heal_all", HOS_HealAll_f, "Debug function to heal all employees in the current base completely");
182#endif
183}
184
191{
192 /* nothing to save here */
193 return true;
194}
195
202{
203 return true;
204}
205
210bool HOS_HospitalAllowed (const base_t* base)
211{
212 return !B_IsUnderAttack(base) && B_GetBuildingStatus(base, B_HOSPITAL);
213}
void CHRSH_UpdateImplants(character_t &chr)
Updates the characters permanent implants. Called every day.
@ ABILITY_POWER
Definition chr_shared.h:37
Share stuff between the different cgame implementations.
float woundThreshold(const short bodyPart) const
short numBodyParts(void) const
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
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t buildingType)
Get the status associated to a building.
Definition cp_base.cpp:478
#define B_IsUnderAttack(base)
Definition cp_base.h:53
@ B_HOSPITAL
Definition cp_building.h:57
ccs_t ccs
Header file for single player campaign control.
const cgame_import_t * cgi
employeeType_t
The types of employees.
Definition cp_employee.h:30
@ MAX_EMPL
Definition cp_employee.h:36
#define E_Foreach(employeeType, var)
bool HOS_SaveXML(xmlNode_t *p)
Saving function for hospital related data.
void HOS_HospitalRun(void)
Checks health status of all employees in all bases.
bool HOS_HealCharacter(character_t *chr, bool hospital)
Heals character.
static void HOS_HealWounds(character_t *chr, int healing)
void HOS_InitStartup(void)
Initial stuff for hospitals Bind some of the functions in this file to console-commands that you can ...
bool HOS_HospitalAllowed(const base_t *base)
Returns true if you can enter in the hospital.
bool HOS_LoadXML(xmlNode_t *p)
Saving function for hospital related data.
#define GET_HP_HEALING(ab)
float HOS_GetInjuryLevel(const character_t &chr)
bool HOS_NeedsHealing(const character_t &chr)
Header file for hospital related stuff.
#define INITIAL_HP
Definition defines.h:102
QGL_EXTERN GLint i
Definition r_gl.h:113
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
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
int skills[SKILL_NUM_TYPES]
Definition chr_shared.h:122
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
#define xmlNode_t
Definition xml.h:24