cp_hospital.c
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "../cl_shared.h"
00028 #include "../cl_team.h"
00029 #include "../ui/ui_main.h"
00030 #include "cp_campaign.h"
00031 #include "cp_hospital.h"
00032
00033 #define GET_HP_HEALING( ab ) (1 + (ab) * 15/MAX_SKILL)
00034
00042 qboolean HOS_HealCharacter (character_t* chr, qboolean hospital)
00043 {
00044 float healing = 1.0f;
00045
00046 if (hospital)
00047 healing = GET_HP_HEALING(chr->score.skills[ABILITY_POWER]);
00048
00049 assert(chr);
00050 if (chr->HP < chr->maxHP) {
00051
00052
00053
00054 if (chr->maxHP < MAX_HP)
00055 chr->HP = min(chr->HP + healing, chr->maxHP);
00056 else
00057 chr->HP = min(chr->HP + ((healing / 100.0f) * chr->maxHP), chr->maxHP);
00058
00059 if (chr->HP == chr->maxHP)
00060 return qfalse;
00061 return qtrue;
00062 } else
00063 return qfalse;
00064 }
00065
00071 void HOS_HospitalRun (void)
00072 {
00073 int type;
00074
00075 for (type = 0; type < MAX_EMPL; type++) {
00076 employee_t *employee = NULL;
00077 while ((employee = E_GetNextHired(type, employee))) {
00078 if (B_GetBuildingStatus(employee->baseHired, B_HOSPITAL))
00079 HOS_HealCharacter(&(employee->chr), qtrue);
00080 else
00081 HOS_HealCharacter(&(employee->chr), qfalse);
00082 }
00083 }
00084 }
00085
00092 qboolean HOS_HealEmployee (employee_t* employee)
00093 {
00094 assert(employee);
00095 return HOS_HealCharacter(&employee->chr, qtrue);
00096 }
00097
00103 void HOS_HealAll (const base_t* const base)
00104 {
00105 int type;
00106
00107 assert(base);
00108
00109 for (type = 0; type < MAX_EMPL; type++) {
00110 employee_t *employee = NULL;
00111 while ((employee = E_GetNextFromBase(type, employee, base))) {
00112 HOS_HealEmployee(employee);
00113 }
00114 }
00115 }
00116
00117
00118 #ifdef DEBUG
00119
00122 static void HOS_HealAll_f (void)
00123 {
00124 int type;
00125 base_t *base = B_GetCurrentSelectedBase();
00126
00127 if (!base)
00128 return;
00129
00130 for (type = 0; type < MAX_EMPL; type++) {
00131 employee_t *employee = NULL;
00132 while ((employee = E_GetNextFromBase(type, employee, base))) {
00133 employee->chr.HP = employee->chr.maxHP;
00134 }
00135 }
00136 }
00137
00141 static void HOS_HurtAll_f (void)
00142 {
00143 int type, amount;
00144 base_t *base = B_GetCurrentSelectedBase();
00145
00146 if (!base)
00147 return;
00148
00149 if (Cmd_Argc() == 2)
00150 amount = atoi(Cmd_Argv(1));
00151 else
00152 amount = 1;
00153
00154 for (type = 0; type < MAX_EMPL; type++) {
00155 employee_t *employee = NULL;
00156 while ((employee = E_GetNext(type, employee))) {
00157
00158 if (!E_IsInBase(employee, base))
00159 continue;
00160 employee->chr.HP = max(0, employee->chr.HP - amount);
00161 }
00162 }
00163 }
00164 #endif
00165
00166
00172 void HOS_InitStartup (void)
00173 {
00174 #ifdef DEBUG
00175 Cmd_AddCommand("debug_hosp_hurt_all", HOS_HurtAll_f, "Debug function to hurt all employees in the current base by one");
00176 Cmd_AddCommand("debug_hosp_heal_all", HOS_HealAll_f, "Debug function to heal all employees in the current base completely");
00177 #endif
00178 }
00179
00185 qboolean HOS_SaveXML (mxml_node_t *p)
00186 {
00187
00188 return qtrue;
00189 }
00190
00196 qboolean HOS_LoadXML (mxml_node_t *p)
00197 {
00198 return qtrue;
00199 }
00200
00205 qboolean HOS_HospitalAllowed (const base_t* base)
00206 {
00207 if (base->baseStatus != BASE_UNDER_ATTACK
00208 && B_GetBuildingStatus(base, B_HOSPITAL)) {
00209 return qtrue;
00210 } else {
00211 return qfalse;
00212 }
00213 }