00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "../cl_shared.h"
00026 #include "../cl_team.h"
00027 #include "../ui/ui_main.h"
00028 #include "../ui/ui_data.h"
00029 #include "../ui/ui_draw.h"
00030 #include "cp_campaign.h"
00031 #include "cp_employee_callbacks.h"
00032 #include "cp_employee.h"
00033
00034
00036 static employee_t *selectedEmployee = NULL;
00037
00038 static int employeeCategory = 0;
00039
00040 static const int maxEmployeesPerPage = 15;
00041
00042 static int employeeScrollPos = 0;
00043
00044
00045 linkedList_t *employeeList;
00047
00048 int employeesInCurrentList;
00049
00053 static void E_UpdateGUICount_f (void)
00054 {
00055 int max;
00056 base_t *base = B_GetCurrentSelectedBase();
00057
00058 if (!base)
00059 return;
00060
00061 max = base->capacities[CAP_EMPLOYEES].max;
00062 Cvar_SetValue("mn_hiresoldiers", E_CountHired(base, EMPL_SOLDIER));
00063 Cvar_SetValue("mn_hireworkers", E_CountHired(base, EMPL_WORKER));
00064 Cvar_SetValue("mn_hirescientists", E_CountHired(base, EMPL_SCIENTIST));
00065 Cvar_SetValue("mn_hirepilots", E_CountHired(base, EMPL_PILOT));
00066 Cvar_Set("mn_hirepeople", va("%d/%d", E_CountAllHired(base), max));
00067 }
00068
00069 static void E_EmployeeSelect (employee_t *employee)
00070 {
00071 const base_t *base = B_GetCurrentSelectedBase();
00072 if (!base)
00073 return;
00074
00075 selectedEmployee = employee;
00076 if (selectedEmployee) {
00077 const character_t *chr = &selectedEmployee->chr;
00078
00079 Cvar_SetValue("mn_employee_hired", E_IsHired(selectedEmployee) ? 1 : 0);
00080 Cvar_SetValue("mn_ucn", chr->ucn);
00081
00082
00083 CL_UpdateCharacterValues(chr, "mn_");
00084 }
00085 }
00086
00091 static void E_EmployeeListScroll_f (void)
00092 {
00093 int j, cnt = 0;
00094 employee_t* employee;
00095 base_t *base = B_GetCurrentSelectedBase();
00096
00097 if (!base)
00098 return;
00099
00100 if (Cmd_Argc() < 2)
00101 return;
00102
00103 employeeScrollPos = atoi(Cmd_Argv(1));
00104 j = employeeScrollPos;
00105
00106 employee = NULL;
00107 while ((employee = E_GetNext(employeeCategory, employee))) {
00108
00109 if (E_IsHired(employee) && !E_IsInBase(employee, base))
00110 continue;
00111
00112
00113 if (j) {
00114 j--;
00115 continue;
00116 }
00117
00118 if (E_IsHired(employee))
00119 UI_ExecuteConfunc("employeeadd %i", cnt);
00120 else
00121 UI_ExecuteConfunc("employeedel %i", cnt);
00122
00123 cnt++;
00124
00125
00126 if (cnt >= maxEmployeesPerPage)
00127 break;
00128 }
00129
00130 for (;cnt < maxEmployeesPerPage; cnt++) {
00131 Cvar_Set(va("mn_name%i", cnt), "");
00132 UI_ExecuteConfunc("employeedisable %i", cnt);
00133 }
00134
00135 UI_ExecuteConfunc("hire_fix_scroll %i", employeeScrollPos);
00136 }
00137
00142 static void E_EmployeeList_f (void)
00143 {
00144 employee_t* employee;
00145 int hiredEmployeeIdx;
00146 linkedList_t *employeeListName;
00147 base_t *base = B_GetCurrentSelectedBase();
00148
00149 if (!base)
00150 return;
00151
00152 if (Cmd_Argc() < 2) {
00153 Com_Printf("Usage: %s <category> <employeeid>\n", Cmd_Argv(0));
00154 return;
00155 }
00156
00157 employeeCategory = atoi(Cmd_Argv(1));
00158 if (employeeCategory >= MAX_EMPL || employeeCategory < 0)
00159 employeeCategory = EMPL_SOLDIER;
00160
00161 if (Cmd_Argc() == 3)
00162 hiredEmployeeIdx = atoi(Cmd_Argv(2));
00163 else
00164 hiredEmployeeIdx = -1;
00165
00166
00167 employeesInCurrentList = 0;
00168
00169 LIST_Delete(&employeeList);
00170
00171 UI_ResetData(TEXT_LIST);
00172 employeeListName = NULL;
00173
00174 employee = NULL;
00175 while ((employee = E_GetNext(employeeCategory, employee))) {
00176
00177 if (E_IsHired(employee) && !E_IsInBase(employee, base))
00178 continue;
00179 LIST_AddPointer(&employeeListName, employee->chr.name);
00180 LIST_AddPointer(&employeeList, employee);
00181 employeesInCurrentList++;
00182 }
00183 UI_RegisterLinkedListText(TEXT_LIST, employeeListName);
00184
00185
00192 if (employeesInCurrentList == 0) {
00193 Cvar_Set("mn_show_employee", "0");
00194 } else {
00195 if (employeeCategory == EMPL_PILOT || employeeCategory == EMPL_SCIENTIST || employeeCategory == EMPL_WORKER)
00196 Cvar_Set("mn_show_employee", "2");
00197 else
00198 Cvar_Set("mn_show_employee", "1");
00199 }
00200
00201
00202 if (hiredEmployeeIdx < 0 || selectedEmployee == NULL)
00203 employee = E_GetEmployeeByMenuIndex(0);
00204 else
00205 employee = selectedEmployee;
00206
00207 E_EmployeeSelect(employee);
00208
00209
00210 UI_ExecuteConfunc("hire_update_number %i", employeesInCurrentList);
00211 UI_ExecuteConfunc("employee_scroll 0");
00212 }
00213
00214
00219 static void E_ChangeName_f (void)
00220 {
00221 employee_t *employee = E_GetEmployeeFromChrUCN(Cvar_GetInteger("mn_ucn"));
00222 if (employee)
00223 Q_strncpyz(employee->chr.name, Cvar_GetString("mn_name"), sizeof(employee->chr.name));
00224 }
00225
00231 int E_GenerateHiredEmployeesList (const base_t *base)
00232 {
00233 assert(base);
00234 employeesInCurrentList = E_GetHiredEmployees(base, EMPL_SOLDIER, &employeeList);
00235 return employeesInCurrentList;
00236 }
00237
00238
00243 employee_t* E_GetEmployeeByMenuIndex (int num)
00244 {
00245 return (employee_t*)LIST_GetByIdx(employeeList, num);
00246 }
00247
00248
00253 static void E_EmployeeDelete_f (void)
00254 {
00255
00256 int num;
00257 employee_t* employee;
00258
00259
00260 if (Cmd_Argc() < 2) {
00261 Com_Printf("Usage: %s <num>\n", Cmd_Argv(0));
00262 return;
00263 }
00264
00265 num = employeeScrollPos + atoi(Cmd_Argv(1));
00266
00267 employee = E_GetEmployeeByMenuIndex(num);
00268
00269 if (!employee)
00270 return;
00271
00272 if (E_IsHired(employee)) {
00273 if (!E_UnhireEmployee(employee)) {
00274 UI_DisplayNotice(_("Could not fire employee"), 2000, "employees");
00275 Com_DPrintf(DEBUG_CLIENT, "Couldn't fire employee\n");
00276 return;
00277 }
00278 }
00279 E_DeleteEmployee(employee, employee->type);
00280 Cbuf_AddText(va("employee_init %i\n", employeeCategory));
00281 }
00282
00288 static void E_EmployeeHire_f (void)
00289 {
00290
00291 int num, button;
00292 const char *arg;
00293 employee_t* employee;
00294 base_t *base = B_GetCurrentSelectedBase();
00295
00296 if (!base)
00297 return;
00298
00299
00300 if (Cmd_Argc() < 2) {
00301 Com_Printf("Usage: %s <+num>\n", Cmd_Argv(0));
00302 return;
00303 }
00304
00305 arg = Cmd_Argv(1);
00306
00307
00308
00309
00310 if (arg[0] == '+') {
00311 num = atoi(arg + 1);
00312 button = num - employeeScrollPos;
00313
00314
00315 } else {
00316 button = atoi(Cmd_Argv(1));
00317 num = button + employeeScrollPos;
00318 }
00319
00320 employee = E_GetEmployeeByMenuIndex(num);
00321
00322 if (!employee)
00323 return;
00324
00325 if (E_IsHired(employee)) {
00326 if (!E_UnhireEmployee(employee)) {
00327 Com_DPrintf(DEBUG_CLIENT, "Couldn't fire employee\n");
00328 UI_DisplayNotice(_("Could not fire employee"), 2000, "employees");
00329 } else
00330 UI_ExecuteConfunc("employeedel %i", button);
00331 } else {
00332 if (!E_HireEmployee(base, employee)) {
00333 Com_DPrintf(DEBUG_CLIENT, "Couldn't hire employee\n");
00334 UI_DisplayNotice(_("Could not hire employee"), 2000, "employees");
00335 UI_ExecuteConfunc("employeedel %i", button);
00336 } else
00337 UI_ExecuteConfunc("employeeadd %i", button);
00338 }
00339 E_EmployeeSelect(employee);
00340
00341 E_UpdateGUICount_f();
00342 }
00343
00347 static void E_EmployeeSelect_f (void)
00348 {
00349 int num;
00350
00351
00352 if (Cmd_Argc() < 2) {
00353 Com_Printf("Usage: %s <num>\n", Cmd_Argv(0));
00354 return;
00355 }
00356
00357 num = atoi(Cmd_Argv(1));
00358 if (num < 0 || num >= employeesInCurrentList)
00359 return;
00360
00361 E_EmployeeSelect(E_GetEmployeeByMenuIndex(num));
00362 }
00363
00364 void E_InitCallbacks (void)
00365 {
00366 Cmd_AddCommand("employee_update_count", E_UpdateGUICount_f, "Callback to update the employee count of the current GUI");
00367
00368
00369 Cmd_AddCommand("employee_init", E_EmployeeList_f, "Init function for employee hire menu");
00370 Cmd_AddCommand("employee_delete", E_EmployeeDelete_f, "Removed an employee from the global employee list");
00371 Cmd_AddCommand("employee_hire", E_EmployeeHire_f, NULL);
00372 Cmd_AddCommand("employee_select", E_EmployeeSelect_f, NULL);
00373 Cmd_AddCommand("employee_changename", E_ChangeName_f, "Change the name of an employee");
00374 Cmd_AddCommand("employee_scroll", E_EmployeeListScroll_f, "Scroll callback for employee list");
00375 }
00376
00377 void E_ShutdownCallbacks (void)
00378 {
00379 Cmd_RemoveCommand("employee_update_count");
00380 Cmd_RemoveCommand("employee_init");
00381 Cmd_RemoveCommand("employee_delete");
00382 Cmd_RemoveCommand("employee_hire");
00383 Cmd_RemoveCommand("employee_select");
00384 Cmd_RemoveCommand("employee_changename");
00385 Cmd_RemoveCommand("employee_scroll");
00386 }