25 #include "../../cl_shared.h"
26 #include "../../ui/ui_dataids.h"
43 else if (
Q_streq(type,
"laser"))
81 cgi->LIST_AddString(&itemList,
_((*list)->name));
102 if (
cgi->Cmd_Argc() < 4) {
103 cgi->Com_Printf(
"Usage: %s <type> <slotIDX> <itemIDX>\n",
cgi->
Cmd_Argv(0));
112 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid defence type.\n");
121 }
else if (itemIDX >= 0) {
128 while (*list && i <= itemIDX) {
138 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid item-space.\n");
145 const int size =
cgi->LIST_Count(*slotList) + 1;
148 cgi->LIST_AddString(slotList, defBuffer);
153 status =
_(
"Working");
155 status =
_(
"Installing");
157 status =
_(
"Replacing");
159 status =
_(
"Removing");
167 cgi->LIST_AddString(slotList, defBuffer);
175 for (
int i = 0;
i < maxBatteries;
i++, batteries++) {
195 if (
cgi->Cmd_Argc() != 2)
206 if (!base && !installation)
210 if (base && installation) {
211 Sys_Error(
"BDEF_BaseDefenceMenuUpdate_f: Both the base and installation are set");
216 cgi->UI_ExecuteConfunc(
"setautofire disable");
226 bool autofire =
false;
239 cgi->UI_ExecuteConfunc(
"setautofire %i", autofire);
244 cgi->UI_ExecuteConfunc(
"set_defencetypes %s %s",
245 (!missileResearched) ?
"na" : (base && base->
numBatteries > 0) ?
"enable" :
"disable",
246 (!laserResearched) ?
"na" : (base && base->
numLasers > 0) ?
"enable" :
"disable");
247 }
else if (installation) {
248 cgi->UI_ExecuteConfunc(
"set_defencetypes %s %s",
250 && installation->
numBatteries > 0) ?
"enable" :
"disable",
"na");
255 else if (
Q_streq(type,
"laser"))
263 cgi->Com_Printf(
"BDEF_BaseDefenceMenuUpdate_f: there is no defence battery in this base: you shouldn't be in this function.\n");
266 }
else if (installation) {
268 cgi->Com_Printf(
"BDEF_BaseDefenceMenuUpdate_f: installation isn't working: you shouldn't be in this function.\n");
271 cgi->Com_Printf(
"BDEF_BaseDefenceMenuUpdate_f: there is no defence battery in this installation: you shouldn't be in this function.\n");
279 cgi->LIST_AddString(&slotList,
_(
"No defence of this type in this installation"));
286 cgi->LIST_AddString(&slotList,
_(
"No defence of this type in this base"));
293 cgi->LIST_AddString(&slotList,
_(
"No defence of this type in this base"));
298 cgi->Com_Printf(
"BDEF_BaseDefenceMenuUpdate_f: unknown bdefType.\n");
317 if ((!base && !installation) || (base && installation)) {
318 cgi->Com_Printf(
"Exiting early base and installation both true or both false\n");
322 if (
cgi->Cmd_Argc() < 3) {
323 cgi->Com_Printf(
"Usage: %s <type> <slotIDX>\n",
cgi->
Cmd_Argv(0));
331 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid defence type.\n");
343 if (slotIDX >= maxWeapon)
350 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid slot.\n");
409 if ((!base && !installation) || (base && installation)) {
410 cgi->Com_Printf(
"Exiting early base and install both true or both false\n");
414 if (
cgi->Cmd_Argc() < 3) {
415 cgi->Com_Printf(
"Usage: %s <type> <slotIDX>\n",
cgi->
Cmd_Argv(0));
423 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid defence type.\n");
435 if (slotIDX >= maxWeapon)
442 cgi->Com_Printf(
"BDEF_AddItem_f: Invalid slot.\n");
483 if (
cgi->Cmd_Argc() < 3) {
484 cgi->Com_Printf(
"Usage: %s <basedefType> <baseIdx>",
cgi->
Cmd_Argv(0));
492 else if (
Q_streq(type,
"laser"))
494 else if (
Q_streq(type,
"random"))
503 cgi->Com_Printf(
"BDEF_RemoveBattery_f: baseIdx %i doesn't exist: there is only %i bases in game.\n",
510 cgi->Com_Printf(
"BDEF_RemoveBattery_f: baseIdx %i is not founded.\n", baseIdx);
517 cgi->Com_Printf(
"No base defence to destroy\n");
535 switch (basedefType) {
545 cgi->Com_Printf(
"BDEF_RemoveBattery_f: base defence type %i doesn't exist.\n", basedefType);
555 if (workingNum == max) {
558 }
else if (workingNum != max - 1) {
560 cgi->Com_Printf(
"BDEF_RemoveBattery_f: Error while checking number of batteries (%i instead of %i) in base '%s'.\n",
561 workingNum, max, base->
name);
580 if (
cgi->Cmd_Argc() < 3) {
581 cgi->Com_Printf(
"Usage: %s <basedefType> <baseIdx>",
cgi->
Cmd_Argv(0));
588 else if (
Q_streq(type,
"laser"))
590 else if (
Q_streq(type,
"random"))
593 cgi->Com_Printf(
"BDEF_AddBattery_f: base defence type %s doesn't exist.\n", type);
598 if (base ==
nullptr) {
599 cgi->Com_Printf(
"BDEF_AddBattery_f: Invalid base index given\n");
631 if (
cgi->Cmd_Argc() < 3) {
632 cgi->Com_Printf(
"Usage: %s <basedefType> <baseIdx>",
cgi->
Cmd_Argv(0));
637 if (base ==
nullptr) {
638 cgi->Com_Printf(
"BDEF_UpdateActiveBattery_f: Invalid base index given\n");
643 if (
Q_streq(type,
"missile")) {
646 }
else if (
Q_streq(type,
"laser")) {
650 cgi->Com_Printf(
"BDEF_UpdateActiveBattery_f: base defence type %s doesn't exist.\n", type);
665 if (!base && !installation)
667 if (base && installation)
669 if (
cgi->Cmd_Argc() < 2)
677 }
else if (installation) {
690 {
"basedef_autofire",
BDEF_ChangeAutoFire,
"Change autofire option for selected defence system"},
692 {
nullptr,
nullptr,
nullptr}
696 cgi->Cmd_TableAddList(baseDefenseCmds);
701 cgi->Cmd_TableRemoveList(baseDefenseCmds);
static void BDEF_SetAutoFire(baseWeapon_t *weapon, bool state)
Function to turn on/off autofire of a base weapon.
static void BDEF_AddItem_f(void)
add item to a base defence slot (installation too)
const objDef_t * nextItem
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
void Sys_Error(const char *error,...)
A building with all it's data.
installationStatus_t installationStatus
aircraftSlot_t * BDEF_GetInstallationSlotByIDX(installation_t *installation, aircraftItemType_t type, int idx)
returns the aircraftSlot of an installaion at an index or the first free slot
bool RS_IsResearched_ptr(const technology_t *tech)
Checks whether an item is already researched.
const objDef_t * INVSH_GetItemByID(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
A installation with all it's data.
QGL_EXTERN GLint GLenum type
static const cmdList_t baseDefenseCmds[]
static void BDEF_BaseDefenceMenuUpdate_f(void)
Fills the battery list, descriptions, and weapons in slots of the basedefence equip menu...
static void BDEF_RemoveBattery_f(void)
Remove a defence system from base.
static void BDEF_ChangeAutoFire(void)
Menu callback for changing autofire state Command: basedef_autofire <0|1>
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
base_t * B_GetCurrentSelectedBase(void)
returns the currently selected base
void BDEF_RemoveBattery(base_t *base, basedefenceType_t basedefType, int idx)
Remove a base defence sytem from base.
const char * UFO_GetName(const aircraft_t *ufocraft)
Returns name of the UFO if UFO has been researched.
static void BDEF_RemoveItem_f(void)
add item to a base defence slot (installation too)
void BDEF_ShutdownCallbacks(void)
buildingType_t
All different building types.
Defines all attributes of objects used in the inventory.
A base with all it's data.
base_t * B_GetFoundedBaseByIDX(int baseIdx)
Array bound check for the base index.
int B_GetCount(void)
Returns the count of founded bases.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
cvar_t *IMPORT * Cvar_Set(const char *varName, const char *value,...) __attribute__((format(__printf__
Header file for menu callback functions used for base and aircraft equip menu.
Header file for menu callback functions used for basedefence menu.
aircraftSlot_t * BDEF_GetBaseSlotByIDX(base_t *base, aircraftItemType_t type, int idx)
returns the aircraftSlot of a base at an index or the first free slot
Campaign missions headers.
const cgame_import_t * cgi
void UP_AircraftItemDescription(const objDef_t *item)
Prints the (UFOpaedia and other) description for aircraft items.
This is the technology parsed from research.ufo.
void BDEF_InitCallbacks(void)
base_t * B_GetBaseByIDX(int baseIdx)
Array bound check for the base index. Will also return unfounded bases as long as the index is in the...
const installationTemplate_t * installationTemplate
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
void BDEF_AddBattery(basedefenceType_t basedefType, base_t *base)
Adds a defence system to base.
static void BDEF_AddBattery_f(void)
Adds a defence system to base.
bool AII_AddItemToSlot(base_t *base, const technology_t *tech, aircraftSlot_t *slot, bool nextItem)
Add an item to an aircraft slot.
bool B_CheckBuildingTypeStatus(const base_t *const base, buildingType_t type, buildingStatus_t status, int *cnt)
Searches the base for a given building type with the given status.
baseWeapon_t batteries[MAX_BASE_SLOT]
static void BDEF_FillSlotList(const baseWeapon_t *batteries, int maxBatteries, linkedList_t **slotList)
Header for slot management related stuff.
bool AIM_SelectableCraftItem(const aircraftSlot_t *slot, const technology_t *tech)
Check if an aircraft item should or should not be displayed in airequip menu.
aircraftItemType_t
All different types of craft items.
void AII_AutoAddAmmo(aircraftSlot_t *slot)
Auto add ammo corresponding to weapon, if there is enough in storage.
basedefenceType_t
The different possible types of base defence systems.
installation_t * INS_GetCurrentSelectedInstallation(void)
Returns the current selected installation.
building_t * B_GetNextBuildingByType(const base_t *base, building_t *lastBuilding, buildingType_t buildingType)
Iterates throught buildings of a type in a base.
Header file for single player campaign control.
static void BDEF_AddSlotToSlotList(const aircraftSlot_t *slot, linkedList_t **slotList)
static const char * BDEF_GetIDFromItemType(aircraftItemType_t type)
returns the string identifier from an itemtype index
baseWeapon_t lasers[MAX_BASE_SLOT]
static void BDEF_UpdateActiveBattery_f(void)
Updates the active defences counter.
technology_t ** AII_GetCraftitemTechsByType(aircraftItemType_t type)
Returns a list of craftitem technologies for the given type.
technology_t * RS_GetTechForItem(const objDef_t *item)
Returns technology entry for an item.
static void BDEF_SelectItem_f(void)
Show item description in bdef menu.
static void BDEF_UpdateAircraftItemList(const aircraftSlot_t *slot)
Update the list of item you can choose.
buildingStatus_t buildingStatus
void AII_RemoveItemFromSlot(base_t *base, aircraftSlot_t *slot, bool ammo)
Remove the item from the slot (or optionally its ammo only) and put it the base storage.
static aircraftItemType_t BDEF_GetItemTypeFromID(const char *type)
returns the itemtype index from a string identifier
const char *IMPORT * Cmd_Argv(int n)
baseWeapon_t batteries[MAX_INSTALLATION_BATTERIES]