/** * @brief This removes an employee from the global list so that * he/she is no longer hireable. */ static void E_EmployeeDelete_f (void) { /* Check syntax. */ if (cgi->Cmd_Argc() < 2) { Com_Printf("Usage: %s <num>\n", cgi->Cmd_Argv(0)); return; } /* num - menu index (line in text) */ int num = employeeScrollPos + atoi(cgi->Cmd_Argv(1)); Employee* employee = E_GetEmployeeByMenuIndex(num); /* empty slot selected */ if (!employee) return; if (employee->isHired()) { if (!employee->unhire()) { cgi->UI_DisplayNotice(_("Could not fire employee"), 2000, "employees"); Com_DPrintf(DEBUG_CLIENT, "Couldn't fire employee\n"); return; } } E_DeleteEmployee(employee); cgi->Cbuf_AddText("employee_init %i\n", employeeCategory); num = std::max(0, num - 1); cgi->Cbuf_AddText("employee_select %i\n", num); cgi->Cbuf_AddText("hire_select %i\n", num); cgi->Cbuf_AddText("employee_update_count\n"); }
/** * @brief Callback for employee_hire command * @note a + as parameter indicates, that more than @c maxEmployeesPerPage are possible * @sa CL_AssignSoldier_f */ static void E_EmployeeHire_f (void) { /* num - menu index (line in text), button - number of button */ int num, button; const char *arg; Employee* employee; base_t *base = B_GetCurrentSelectedBase(); if (!base) return; /* Check syntax. */ if (cgi->Cmd_Argc() < 2) { Com_Printf("Usage: %s <+num>\n", cgi->Cmd_Argv(0)); return; } arg = cgi->Cmd_Argv(1); /* check whether this is called with the text node click function * with values from 0 - #available employees (bigger values than * maxEmployeesPerPage) possible ... */ if (arg[0] == '+') { num = atoi(arg + 1); button = num - employeeScrollPos; /* ... or with the hire pictures that are using only values from * 0 - maxEmployeesPerPage */ } else { button = atoi(cgi->Cmd_Argv(1)); num = button + employeeScrollPos; } employee = E_GetEmployeeByMenuIndex(num); /* empty slot selected */ if (!employee) return; if (employee->isHired()) { if (!employee->unhire()) { Com_DPrintf(DEBUG_CLIENT, "Couldn't fire employee\n"); cgi->UI_DisplayNotice(_("Could not fire employee"), 2000, "employees"); } else { cgi->UI_ExecuteConfunc("employeehire %i", button); } } else { if (!E_HireEmployee(base, employee)) { Com_DPrintf(DEBUG_CLIENT, "Couldn't hire employee\n"); cgi->UI_DisplayNotice(_("Could not hire employee"), 2000, "employees"); cgi->UI_ExecuteConfunc("employeehire %i", button); } else { cgi->UI_ExecuteConfunc("employeefire %i", button); } } E_EmployeeSelect(employee); E_UpdateGUICount_f(); }