cp_hospital_callbacks.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "../cl_shared.h"
00026 #include "../cl_team.h"
00027 #include "../ui/ui_main.h"
00028 #include "../ui/ui_popup.h"
00029 #include "cp_campaign.h"
00030 #include "cp_hospital.h"
00031 #include "cp_hospital_callbacks.h"
00032 
00034 static employee_t* currentEmployeeInHospital = NULL;
00035 
00037 static int hospitalFirstEntry;
00038 
00040 static int hospitalNumEntries;
00041 
00043 #define HOS_MENU_MAX_ENTRIES 21
00044 
00046 #define HOS_MENU_LINE_ENTRIES 3
00047 
00052 static void HOS_UpdateMenu (void)
00053 {
00054     char name[128];
00055     char rank[128];
00056     int j, type;
00057     int entry;
00058     base_t *base = B_GetCurrentSelectedBase();
00059 
00060     if (!base)
00061         return;
00062 
00063     /* Reset list. */
00064     UI_ExecuteConfunc("hospital_clear");
00065 
00066     for (type = 0, j = 0, entry = 0; type < MAX_EMPL; type++) {
00067         employee_t *employee = NULL;
00068         while ((employee = E_GetNextFromBase(type, employee, base))) {
00069             /* Don't show soldiers who are gone in mission */
00070             if (E_IsAwayFromBase(employee))
00071                 continue;
00072             /* Don't show healthy employees */
00073             if (employee->chr.HP >= employee->chr.maxHP)
00074                 continue;
00075 
00076             if (j >= hospitalFirstEntry && entry < HOS_MENU_MAX_ENTRIES) {
00077                 /* Print name. */
00078                 Q_strncpyz(name, employee->chr.name, sizeof(name));
00079                 /* Print rank for soldiers or type for other personel. */
00080                 if (type == EMPL_SOLDIER) {
00081                     const rank_t *rankPtr = CL_GetRankByIdx(employee->chr.score.rank);
00082                     Q_strncpyz(rank, _(rankPtr->name), sizeof(rank));
00083                 } else
00084                     Q_strncpyz(rank, E_GetEmployeeString(employee->type), sizeof(rank));
00085                 Com_DPrintf(DEBUG_CLIENT, "%s idx: %i entry: %i\n", name, employee->idx, entry);
00086                 /* If the employee is seriously wounded (HP <= 50% maxHP), make him red. */
00087                 if (employee->chr.HP <= (int) (employee->chr.maxHP * 0.5))
00088                     UI_ExecuteConfunc("hospitalserious %i", entry);
00089                 /* If the employee is semi-seriously wounded (HP <= 85% maxHP), make him yellow. */
00090                 else if (employee->chr.HP <= (int) (employee->chr.maxHP * 0.85))
00091                     UI_ExecuteConfunc("hospitalmedium %i", entry);
00092                 else
00093                     UI_ExecuteConfunc("hospitallight %i", entry);
00094 
00095                 /* Display name in the correct list-entry. */
00096                 Cvar_Set(va("mn_hos_item%i", entry), name);
00097                 /* Display rank in the correct list-entry. */
00098                 Cvar_Set(va("mn_hos_rank%i", entry), rank);
00099                 /* Prepare the health bar */
00100                 Cvar_Set(va("mn_hos_hp%i", entry), va("%i", employee->chr.HP));
00101                 Cvar_Set(va("mn_hos_hpmax%i", entry), va("%i", employee->chr.maxHP));
00102                 /* Increase the counter of list entries. */
00103                 entry++;
00104             }
00105             j++;
00106         }
00107     }
00108     hospitalNumEntries = j;
00109 
00110     /* Set rest of the list-entries to have no text at all. */
00111     for (; entry < HOS_MENU_MAX_ENTRIES; entry++) {
00112         Cvar_Set(va("mn_hos_item%i", entry), "");
00113         Cvar_Set(va("mn_hos_rank%i", entry), "");
00114         Cvar_Set(va("mn_hos_hp%i", entry), "0");
00115         Cvar_Set(va("mn_hos_hpmax%i", entry), "1");
00116         UI_ExecuteConfunc("hospitalunused %i", entry);
00117     }
00118 }
00119 
00124 static void HOS_Init_f (void)
00125 {
00126     base_t *base = B_GetCurrentSelectedBase();
00127 
00128     if (!base)
00129         return;
00130 
00131     if (!B_GetBuildingStatus(base, B_HOSPITAL)) {
00132         UI_PopWindow(qfalse);
00133         return;
00134     }
00135 
00136     hospitalFirstEntry = 0;
00137 
00138     HOS_UpdateMenu();
00139 
00140 }
00141 
00145 static void HOS_ListUp_f (void)
00146 {
00147     if (hospitalFirstEntry >= HOS_MENU_LINE_ENTRIES)
00148         hospitalFirstEntry -= HOS_MENU_LINE_ENTRIES;
00149 
00150     HOS_UpdateMenu();
00151 }
00152 
00156 static void HOS_ListDown_f (void)
00157 {
00158     if (hospitalFirstEntry + HOS_MENU_MAX_ENTRIES < hospitalNumEntries)
00159         hospitalFirstEntry += HOS_MENU_LINE_ENTRIES;
00160 
00161     HOS_UpdateMenu();
00162 }
00163 
00167 static void HOS_ListClick_f (void)
00168 {
00169     int num, type;
00170     base_t *base = B_GetCurrentSelectedBase();
00171 
00172     if (!base) {
00173         currentEmployeeInHospital = NULL;
00174         return;
00175     }
00176 
00177     if (Cmd_Argc() < 2) {
00178         Com_Printf("Usage: %s <arg>\n", Cmd_Argv(0));
00179         return;
00180     }
00181 
00182     /* which employee? */
00183     num = atoi(Cmd_Argv(1)) + hospitalFirstEntry;
00184 
00185     for (type = 0; type < MAX_EMPL; type++) {
00186         employee_t *employee = NULL;
00187         while ((employee = E_GetNextFromBase(type, employee, base))) {
00188             /* only those that need healing */
00189             if (employee->chr.HP >= employee->chr.maxHP)
00190                 continue;
00191             /* Don't select soldiers that are gone to a mission */
00192             if (E_IsAwayFromBase(employee))
00193                 continue;
00194             if (!num) {
00195                 currentEmployeeInHospital = employee;
00196                 /* end outer loop, too */
00197                 type = MAX_EMPL + 1;
00198                 /* end inner loop */
00199                 break;
00200             }
00201             num--;
00202         }
00203     }
00204 
00205     /* open the hospital menu for this employee */
00206     if (type != MAX_EMPL)
00207         UI_PushWindow("hospital_employee", NULL);
00208 }
00209 
00213 static void HOS_EmployeeInit_f (void)
00214 {
00215     character_t* c;
00216 
00217     if (!currentEmployeeInHospital) {
00218         Com_Printf("HOS_EmployeeInit_f: no employee selected.\n");
00219         return;
00220     }
00221 
00222     UI_ResetData(TEXT_STANDARD);
00223 
00224     c = &currentEmployeeInHospital->chr;
00225     CL_UpdateCharacterValues(c, "mn_");
00226 
00227     Cvar_SetValue("mn_hp", c->HP);
00228     Cvar_SetValue("mn_hpmax", c->maxHP);
00229 }
00230 
00231 
00232 void HOS_InitCallbacks(void)
00233 {
00234     Cmd_AddCommand("hosp_empl_init", HOS_EmployeeInit_f, "Init function for hospital employee menu");
00235     Cmd_AddCommand("hosp_init", HOS_Init_f, "Init function for hospital menu");
00236     Cmd_AddCommand("hosp_list_click", HOS_ListClick_f, "Click function for hospital employee list");
00237     Cmd_AddCommand("hosp_list_up", HOS_ListUp_f, "Scroll up function for hospital employee list");
00238     Cmd_AddCommand("hosp_list_down", HOS_ListDown_f, "Scroll down function for hospital employee list");
00239 }
00240 
00241 void HOS_ShutdownCallbacks(void)
00242 {
00243     Cmd_RemoveCommand("hosp_empl_init");
00244     Cmd_RemoveCommand("hosp_init");
00245     Cmd_RemoveCommand("hosp_list_click");
00246     Cmd_RemoveCommand("hosp_list_up");
00247     Cmd_RemoveCommand("hosp_list_down");
00248 }

Generated by  doxygen 1.6.2