cp_hospital.c

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2002-2010 UFO: Alien Invasion.
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019 See the GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         /* if the character has less that 100 hitpoints, he will be disadvantaged by using the percentage
00052          * method of allocating hitpoints.  So just give the character "healing" as Hitpoints, otherwise
00053          * allocate "healing" as a percentage of the characters total hitpoints. */
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             /* only those employees, that are in the current base */
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     /* nothing to save here */
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 }

Generated by  doxygen 1.6.2