UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_basedefence_callbacks.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24 
25 #include "../../cl_shared.h"
26 #include "../../ui/ui_dataids.h"
27 #include "cp_campaign.h"
30 #include "cp_mapfightequip.h"
31 #include "cp_ufo.h"
32 #include "cp_missions.h"
33 
39 {
40  assert(type);
41  if (Q_streq(type, "missile"))
42  return AC_ITEM_BASE_MISSILE;
43  else if (Q_streq(type, "laser"))
44  return AC_ITEM_BASE_LASER;
45 
46  return MAX_ACITEMS;
47 }
53 {
54  switch (type) {
56  return "missile";
57  case AC_ITEM_BASE_LASER:
58  return "laser";
59  default:
60  return "unknown";
61  }
62 }
63 
69 {
70  linkedList_t* itemList = nullptr;
71  technology_t** list;
72 
73  assert(slot);
74 
75  /* Add all items corresponding to airequipID to list */
76  list = AII_GetCraftitemTechsByType(slot->type);
77 
78  /* Copy only those which are researched to buffer */
79  while (*list) {
80  if (AIM_SelectableCraftItem(slot, *list))
81  cgi->LIST_AddString(&itemList, _((*list)->name));
82  list++;
83  }
84 
85  /* copy buffer to mn.menuText to display it on screen */
86  cgi->UI_RegisterLinkedListText(TEXT_LIST, itemList);
87 }
88 
93 static void BDEF_SelectItem_f (void)
94 {
95  aircraftSlot_t* slot;
98  aircraftItemType_t bdefType;
99  int slotIDX;
100  int itemIDX;
101 
102  if (cgi->Cmd_Argc() < 4) {
103  cgi->Com_Printf("Usage: %s <type> <slotIDX> <itemIDX>\n", cgi->Cmd_Argv(0));
104  return;
105  }
106 
107  bdefType = BDEF_GetItemTypeFromID(cgi->Cmd_Argv(1));
108  slotIDX = atoi(cgi->Cmd_Argv(2));
109  itemIDX = atoi(cgi->Cmd_Argv(3));
110 
111  if (bdefType == MAX_ACITEMS) {
112  cgi->Com_Printf("BDEF_AddItem_f: Invalid defence type.\n");
113  return;
114  }
115 
116  if (slotIDX >= 0) {
117  const objDef_t* item;
118  slot = (installation) ? BDEF_GetInstallationSlotByIDX(installation, bdefType, slotIDX) : BDEF_GetBaseSlotByIDX(base, bdefType, slotIDX);
119  item = (slot) ? ( (slot->nextItem) ? slot->nextItem : slot->item ) : nullptr;
121  } else if (itemIDX >= 0) {
122  technology_t** list;
123  technology_t* itemTech = nullptr;
124  int i = 0;
125 
126  slot = (installation) ? BDEF_GetInstallationSlotByIDX(installation, bdefType, 0) : BDEF_GetBaseSlotByIDX(base, bdefType, 0);
127  list = AII_GetCraftitemTechsByType(bdefType);
128  while (*list && i <= itemIDX) {
129  if (AIM_SelectableCraftItem(slot, *list)) {
130  itemTech = *list;
131  i++;
132  break;
133  }
134  list++;
135  }
136  UP_AircraftItemDescription((itemTech) ? INVSH_GetItemByIDSilent(itemTech->provides) : nullptr);
137  } else {
138  cgi->Com_Printf("BDEF_AddItem_f: Invalid item-space.\n");
139  }
140 }
141 
142 static void BDEF_AddSlotToSlotList (const aircraftSlot_t* slot, linkedList_t** slotList)
143 {
144  char defBuffer[512];
145  const int size = cgi->LIST_Count(*slotList) + 1;
146  if (!slot->item) {
147  Com_sprintf(defBuffer, lengthof(defBuffer), _("%i: empty"), size);
148  cgi->LIST_AddString(slotList, defBuffer);
149  } else {
150  const technology_t* tech;
151  const char* status;
152  if (!slot->installationTime)
153  status = _("Working");
154  else if (slot->installationTime > 0)
155  status = _("Installing");
156  else if (slot->nextItem)
157  status = _("Replacing");
158  else
159  status = _("Removing");
160 
161  if (slot->nextItem != nullptr)
162  tech = RS_GetTechForItem(slot->nextItem);
163  else
164  tech = RS_GetTechForItem(slot->item);
165 
166  Com_sprintf(defBuffer, lengthof(defBuffer), "%i: %s (%s)", size, _(tech->name), status);
167  cgi->LIST_AddString(slotList, defBuffer);
168  }
169 }
170 
171 static void BDEF_FillSlotList (const baseWeapon_t* batteries, int maxBatteries, linkedList_t** slotList)
172 {
173  BDEF_UpdateAircraftItemList(&batteries->slot);
174 
175  for (int i = 0; i < maxBatteries; i++, batteries++) {
176  const aircraftSlot_t* slot = &batteries->slot;
177  BDEF_AddSlotToSlotList(slot, slotList);
178  }
179 }
180 
186 {
187  char type[MAX_VAR];
190  aircraftItemType_t bdefType;
191  linkedList_t* slotList = nullptr;
192  const bool missileResearched = RS_IsResearched_ptr(RS_GetTechByID("rs_building_missile"));
193  const bool laserResearched = RS_IsResearched_ptr(RS_GetTechByID("rs_building_laser"));
194 
195  if (cgi->Cmd_Argc() != 2)
196  type[0] = '\0';
197  else
198  Q_strncpyz(type, cgi->Cmd_Argv(1), sizeof(type));
199 
200  /* don't let old links appear on this menu */
201  cgi->UI_ResetData(TEXT_BASEDEFENCE_LIST);
202  cgi->UI_ResetData(TEXT_LIST);
203  cgi->UI_ResetData(TEXT_ITEMDESCRIPTION);
204 
205  /* base or installation should not be nullptr because we are in the menu of this base or installation */
206  if (!base && !installation)
207  return;
208 
209  /* base and installation should not both be set. This function requires one or the other set. */
210  if (base && installation) {
211  Sys_Error("BDEF_BaseDefenceMenuUpdate_f: Both the base and installation are set");
212  return;
213  }
214 
215  cgi->Cvar_Set("mn_target", _("None"));
216  cgi->UI_ExecuteConfunc("setautofire disable");
217  if (installation) {
218  /* Every slot aims the same target */
219  if (installation->numBatteries) {
220  cgi->UI_ExecuteConfunc("setautofire %i", installation->batteries[0].autofire);
221 
222  if (installation->batteries[0].target)
223  cgi->Cvar_Set("mn_target", "%s", UFO_GetName(installation->batteries[0].target));
224  }
225  } else if (base) {
226  bool autofire = false;
227  /* Every slot aims the same target */
228  if (base->numBatteries) {
229  autofire |= base->batteries[0].autofire;
230  if (base->batteries[0].target)
231  cgi->Cvar_Set("mn_target", "%s", UFO_GetName(base->batteries[0].target));
232  }
233  if (base->numLasers) {
234  autofire |= base->lasers[0].autofire;
235  if (base->lasers[0].target && !base->batteries[0].target)
236  cgi->Cvar_Set("mn_target", "%s", UFO_GetName(base->lasers[0].target));
237  }
238  if (base->numBatteries || base->numLasers)
239  cgi->UI_ExecuteConfunc("setautofire %i", autofire);
240  }
241 
242  /* Check if we can change to laser or missile */
243  if (base) {
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",
249  (!missileResearched) ? "na" : (installation && installation->installationStatus == INSTALLATION_WORKING
250  && installation->numBatteries > 0) ? "enable" : "disable", "na");
251  }
252 
253  if (Q_streq(type, "missile"))
254  bdefType = AC_ITEM_BASE_MISSILE;
255  else if (Q_streq(type, "laser"))
256  bdefType = AC_ITEM_BASE_LASER;
257  else /* info page */
258  return;
259 
260  /* Check that the base or installation has at least 1 battery */
261  if (base) {
262  if (base->numBatteries + base->numLasers < 1) {
263  cgi->Com_Printf("BDEF_BaseDefenceMenuUpdate_f: there is no defence battery in this base: you shouldn't be in this function.\n");
264  return;
265  }
266  } else if (installation) {
267  if (installation->installationStatus != INSTALLATION_WORKING) {
268  cgi->Com_Printf("BDEF_BaseDefenceMenuUpdate_f: installation isn't working: you shouldn't be in this function.\n");
269  return;
270  } else if (installation->installationTemplate->maxBatteries < 1) {
271  cgi->Com_Printf("BDEF_BaseDefenceMenuUpdate_f: there is no defence battery in this installation: you shouldn't be in this function.\n");
272  return;
273  }
274  }
275 
276  if (installation) {
277  /* we are in the installation defence menu */
278  if (installation->installationTemplate->maxBatteries == 0) {
279  cgi->LIST_AddString(&slotList, _("No defence of this type in this installation"));
280  } else {
281  BDEF_FillSlotList(installation->batteries, installation->installationTemplate->maxBatteries, &slotList);
282  }
283  } else if (bdefType == AC_ITEM_BASE_MISSILE) {
284  /* we are in the base defence menu for missile */
285  if (base->numBatteries == 0) {
286  cgi->LIST_AddString(&slotList, _("No defence of this type in this base"));
287  } else {
288  BDEF_FillSlotList(base->batteries, base->numActiveBatteries, &slotList);
289  }
290  } else if (bdefType == AC_ITEM_BASE_LASER) {
291  /* we are in the base defence menu for laser */
292  if (base->numLasers == 0) {
293  cgi->LIST_AddString(&slotList, _("No defence of this type in this base"));
294  } else {
295  BDEF_FillSlotList(base->lasers, base->numActiveLasers, &slotList);
296  }
297  } else {
298  cgi->Com_Printf("BDEF_BaseDefenceMenuUpdate_f: unknown bdefType.\n");
299  return;
300  }
301  cgi->UI_RegisterLinkedListText(TEXT_BASEDEFENCE_LIST, slotList);
302 }
303 
307 static void BDEF_AddItem_f (void)
308 {
309  aircraftSlot_t* slot;
312  technology_t** list;
313  technology_t* itemTech = nullptr;
314  aircraftItemType_t bdefType;
315  int slotIDX;
316 
317  if ((!base && !installation) || (base && installation)) {
318  cgi->Com_Printf("Exiting early base and installation both true or both false\n");
319  return;
320  }
321 
322  if (cgi->Cmd_Argc() < 3) {
323  cgi->Com_Printf("Usage: %s <type> <slotIDX>\n", cgi->Cmd_Argv(0));
324  return;
325  }
326 
327  bdefType = BDEF_GetItemTypeFromID(cgi->Cmd_Argv(1));
328  slotIDX = atoi(cgi->Cmd_Argv(2));
329 
330  if (bdefType == MAX_ACITEMS) {
331  cgi->Com_Printf("BDEF_AddItem_f: Invalid defence type.\n");
332  return;
333  }
334 
335  if (slotIDX < 0) {
336  return;
337  } else {
338  int maxWeapon;
339  if (base)
340  maxWeapon = (bdefType == AC_ITEM_BASE_MISSILE) ? base->numActiveBatteries : base->numActiveLasers;
341  else
342  maxWeapon = installation->numBatteries;
343  if (slotIDX >= maxWeapon)
344  return;
345  }
346 
347  slot = (installation) ? BDEF_GetInstallationSlotByIDX(installation, bdefType, slotIDX) : BDEF_GetBaseSlotByIDX(base, bdefType, slotIDX);
348 
349  if (!slot) {
350  cgi->Com_Printf("BDEF_AddItem_f: Invalid slot.\n");
351  return;
352  }
353 
354  list = AII_GetCraftitemTechsByType(bdefType);
355  while (*list) {
356  if (AIM_SelectableCraftItem(slot, *list)) {
357  itemTech = *list;
358  break;
359  }
360  list++;
361  }
362 
363  if (!itemTech)
364  return;
365 
366  if (!slot->nextItem) {
367  /* we add the weapon, shield, item, or base defence if slot is free or the installation of
368  * current item just began */
369  if (!slot->item || (slot->item && slot->installationTime == slot->item->craftitem.installationTime)) {
370  AII_RemoveItemFromSlot(base, slot, false);
371  AII_AddItemToSlot(base, itemTech, slot, false); /* Aircraft stats are updated below */
372  AII_AutoAddAmmo(slot);
373  } else if (slot->item == INVSH_GetItemByID(itemTech->provides)) {
374  /* the added item is the same than the one in current slot */
375  if (slot->installationTime == -slot->item->craftitem.installationTime) {
376  /* player changed his mind: he just want to re-add the item he just removed */
377  slot->installationTime = 0;
378  } else if (!slot->installationTime) {
379  /* player try to add a weapon he already have: just skip */
380  }
381  } else {
382  /* We start removing current item in slot, and the selected item will be installed afterwards */
384  AII_AddItemToSlot(base, itemTech, slot, true);
385  AII_AutoAddAmmo(slot);
386  }
387  } else {
388  /* remove weapon and ammo of next item */
389  AII_RemoveItemFromSlot(base, slot, false);
390  AII_AddItemToSlot(base, itemTech, slot, true);
391  AII_AutoAddAmmo(slot);
392  }
393 
394  /* Reinit menu */
395  cgi->Cmd_ExecuteString("basedef_updatemenu %s", BDEF_GetIDFromItemType(slot->type));
396 }
397 
401 static void BDEF_RemoveItem_f (void)
402 {
403  aircraftSlot_t* slot;
406  aircraftItemType_t bdefType;
407  int slotIDX;
408 
409  if ((!base && !installation) || (base && installation)) {
410  cgi->Com_Printf("Exiting early base and install both true or both false\n");
411  return;
412  }
413 
414  if (cgi->Cmd_Argc() < 3) {
415  cgi->Com_Printf("Usage: %s <type> <slotIDX>\n", cgi->Cmd_Argv(0));
416  return;
417  }
418 
419  bdefType = BDEF_GetItemTypeFromID(cgi->Cmd_Argv(1));
420  slotIDX = atoi(cgi->Cmd_Argv(2));
421 
422  if (bdefType == MAX_ACITEMS) {
423  cgi->Com_Printf("BDEF_AddItem_f: Invalid defence type.\n");
424  return;
425  }
426 
427  if (slotIDX < 0) {
428  return;
429  } else {
430  int maxWeapon;
431  if (base)
432  maxWeapon = (bdefType == AC_ITEM_BASE_MISSILE) ? base->numActiveBatteries : base->numActiveLasers;
433  else
434  maxWeapon = installation->numBatteries;
435  if (slotIDX >= maxWeapon)
436  return;
437  }
438 
439  slot = (installation) ? BDEF_GetInstallationSlotByIDX(installation, bdefType, slotIDX) : BDEF_GetBaseSlotByIDX(base, bdefType, slotIDX);
440 
441  if (!slot) {
442  cgi->Com_Printf("BDEF_AddItem_f: Invalid slot.\n");
443  return;
444  }
445 
446  if (!slot->item)
447  return;
448 
449  if (!slot->nextItem) {
450  /* we change the weapon, shield, item, or base defence that is already in the slot */
451  /* if the item has been installed since less than 1 hour, you don't need time to remove it */
452  if (slot->installationTime < slot->item->craftitem.installationTime) {
454  AII_RemoveItemFromSlot(base, slot, true); /* we remove only ammo, not item */
455  } else {
456  AII_RemoveItemFromSlot(base, slot, false); /* we remove weapon and ammo */
457  }
458  } else {
459  /* we change the weapon, shield, item, or base defence that will be installed AFTER the removal
460  * of the one in the slot atm */
461  AII_RemoveItemFromSlot(base, slot, false); /* we remove weapon and ammo */
462  /* if you canceled next item for less than 1 hour, previous item is still functional */
463  if (slot->installationTime == -slot->item->craftitem.installationTime) {
464  slot->installationTime = 0;
465  }
466  }
467  cgi->Cmd_ExecuteString("basedef_updatemenu %s", BDEF_GetIDFromItemType(slot->type));
468 }
469 
477 static void BDEF_RemoveBattery_f (void)
478 {
479  basedefenceType_t basedefType;
480  int baseIdx;
481  base_t* base;
482 
483  if (cgi->Cmd_Argc() < 3) {
484  cgi->Com_Printf("Usage: %s <basedefType> <baseIdx>", cgi->Cmd_Argv(0));
485  return;
486  } else {
487  char type[MAX_VAR];
488 
489  Q_strncpyz(type, cgi->Cmd_Argv(1), sizeof(type));
490  if (Q_streq(type, "missile"))
491  basedefType = BASEDEF_MISSILE;
492  else if (Q_streq(type, "laser"))
493  basedefType = BASEDEF_LASER;
494  else if (Q_streq(type, "random"))
495  basedefType = BASEDEF_RANDOM;
496  else
497  return;
498  baseIdx = atoi(cgi->Cmd_Argv(2));
499  }
500 
501  /* Check that the baseIdx exists */
502  if (baseIdx < 0 || baseIdx >= B_GetCount()) {
503  cgi->Com_Printf("BDEF_RemoveBattery_f: baseIdx %i doesn't exist: there is only %i bases in game.\n",
504  baseIdx, B_GetCount());
505  return;
506  }
507 
508  base = B_GetFoundedBaseByIDX(baseIdx);
509  if (!base) {
510  cgi->Com_Printf("BDEF_RemoveBattery_f: baseIdx %i is not founded.\n", baseIdx);
511  return;
512  }
513 
514  if (basedefType == BASEDEF_RANDOM) {
515  /* Type of base defence to destroy is randomly selected */
516  if (base->numBatteries <= 0 && base->numLasers <= 0) {
517  cgi->Com_Printf("No base defence to destroy\n");
518  return;
519  } else if (base->numBatteries <= 0) {
520  /* only laser battery is possible */
521  basedefType = BASEDEF_LASER;
522  } else if (base->numLasers <= 0) {
523  /* only missile battery is possible */
524  basedefType = BASEDEF_MISSILE;
525  } else {
526  /* both type are possible, choose one randomly */
527  basedefType = (basedefenceType_t)(rand() % 2 + BASEDEF_MISSILE);
528  }
529  } else {
530  /* Check if the removed building was under construction */
532  int workingNum, max;
533  building_t* building;
534 
535  switch (basedefType) {
536  case BASEDEF_MISSILE:
537  type = B_DEFENCE_MISSILE;
538  max = base->numBatteries;
539  break;
540  case BASEDEF_LASER:
541  type = B_DEFENCE_LASER;
542  max = base->numLasers;
543  break;
544  default:
545  cgi->Com_Printf("BDEF_RemoveBattery_f: base defence type %i doesn't exist.\n", basedefType);
546  return;
547  }
548 
549  building = nullptr;
550  workingNum = 0;
551  while ((building = B_GetNextBuildingByType(base, building, type)))
552  if (building->buildingStatus == B_STATUS_WORKING)
553  workingNum++;
554 
555  if (workingNum == max) {
556  /* Removed building was under construction, do nothing */
557  return;
558  } else if (workingNum != max - 1) {
559  /* Should never happen, we only remove building one by one */
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);
562  return;
563  }
564 
565  /* If we reached this point, that means we are removing a working building: continue */
566  }
567 
568  BDEF_RemoveBattery(base, basedefType, -1);
569 }
570 
574 static void BDEF_AddBattery_f (void)
575 {
576  basedefenceType_t basedefType;
577  base_t* base;
578  const char* type;
579 
580  if (cgi->Cmd_Argc() < 3) {
581  cgi->Com_Printf("Usage: %s <basedefType> <baseIdx>", cgi->Cmd_Argv(0));
582  return;
583  }
584 
585  type = cgi->Cmd_Argv(1);
586  if (Q_streq(type, "missile"))
587  basedefType = BASEDEF_MISSILE;
588  else if (Q_streq(type, "laser"))
589  basedefType = BASEDEF_LASER;
590  else if (Q_streq(type, "random"))
591  basedefType = BASEDEF_RANDOM;
592  else {
593  cgi->Com_Printf("BDEF_AddBattery_f: base defence type %s doesn't exist.\n", type);
594  return;
595  }
596 
597  base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(2)));
598  if (base == nullptr) {
599  cgi->Com_Printf("BDEF_AddBattery_f: Invalid base index given\n");
600  return;
601  }
602 
603  BDEF_AddBattery(basedefType, base);
604 }
605 
612 static void BDEF_SetAutoFire (baseWeapon_t* weapon, bool state)
613 {
614  assert(weapon);
615  weapon->autofire = state;
616  if (!weapon->autofire) {
617  weapon->target = nullptr;
618  cgi->Cvar_Set("mn_target", _("None"));
619  }
620 }
621 
625 static void BDEF_UpdateActiveBattery_f (void)
626 {
627  base_t* base;
628  const char* type;
629  int count;
630 
631  if (cgi->Cmd_Argc() < 3) {
632  cgi->Com_Printf("Usage: %s <basedefType> <baseIdx>", cgi->Cmd_Argv(0));
633  return;
634  }
635 
636  base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(2)));
637  if (base == nullptr) {
638  cgi->Com_Printf("BDEF_UpdateActiveBattery_f: Invalid base index given\n");
639  return;
640  }
641 
642  type = cgi->Cmd_Argv(1);
643  if (Q_streq(type, "missile")) {
645  base->numActiveBatteries = std::min(count, base->numBatteries);
646  } else if (Q_streq(type, "laser")) {
648  base->numActiveLasers = std::min(count, base->numLasers);
649  } else {
650  cgi->Com_Printf("BDEF_UpdateActiveBattery_f: base defence type %s doesn't exist.\n", type);
651  return;
652  }
653 }
654 
659 static void BDEF_ChangeAutoFire (void)
660 {
663  int i;
664 
665  if (!base && !installation)
666  return;
667  if (base && installation)
668  return;
669  if (cgi->Cmd_Argc() < 2)
670  return;
671 
672  if (base) {
673  for (i = 0; i < base->numBatteries; i++)
674  BDEF_SetAutoFire(&base->batteries[i], atoi(cgi->Cmd_Argv(1)));
675  for (i = 0; i < base->numLasers; i++)
676  BDEF_SetAutoFire(&base->lasers[i], atoi(cgi->Cmd_Argv(1)));
677  } else if (installation) {
678  for (i = 0; i < installation->numBatteries; i++)
679  BDEF_SetAutoFire(&installation->batteries[i], atoi(cgi->Cmd_Argv(1)));
680  }
681 }
682 
683 static const cmdList_t baseDefenseCmds[] = {
684  {"add_battery", BDEF_AddBattery_f, "Add a new battery to base"},
685  {"remove_battery", BDEF_RemoveBattery_f, "Remove a battery from base"},
686  {"basedef_updatemenu", BDEF_BaseDefenceMenuUpdate_f, "Inits base defence menu"},
687  {"basedef_selectitem", BDEF_SelectItem_f, nullptr},
688  {"basedef_additem", BDEF_AddItem_f, "Add item to slot"},
689  {"basedef_removeitem", BDEF_RemoveItem_f, "Remove item from slot"},
690  {"basedef_autofire", BDEF_ChangeAutoFire, "Change autofire option for selected defence system"},
691  {"basedef_updatebatteries", BDEF_UpdateActiveBattery_f, "Updates the active defence systems counters"},
692  {nullptr, nullptr, nullptr}
693 };
695 {
696  cgi->Cmd_TableAddList(baseDefenseCmds);
697 }
698 
700 {
701  cgi->Cmd_TableRemoveList(baseDefenseCmds);
702 }
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
Definition: cp_aircraft.h:91
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
Definition: inv_shared.cpp:249
aircraftSlot_t slot
Definition: cp_base.h:78
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
A building with all it's data.
Definition: cp_building.h:73
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.
Definition: inv_shared.cpp:282
A installation with all it's data.
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
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...
#define _(String)
Definition: cl_shared.h:43
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
Definition: shared.cpp:494
char name[MAX_VAR]
Definition: cp_base.h:86
base_t * B_GetCurrentSelectedBase(void)
returns the currently selected base
Definition: cp_base.cpp:1578
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.
Definition: cp_ufo.cpp:243
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.
Definition: cp_building.h:51
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
A base with all it's data.
Definition: cp_base.h:84
base_t * B_GetFoundedBaseByIDX(int baseIdx)
Array bound check for the base index.
Definition: cp_base.cpp:325
char * provides
Definition: cp_research.h:154
bool autofire
Definition: cp_base.h:80
int numActiveLasers
Definition: cp_base.h:121
int B_GetCount(void)
Returns the count of founded bases.
Definition: cp_base.cpp:276
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
Definition: shared.cpp:457
aircraftItemType_t type
Definition: cp_aircraft.h:82
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.
GLsizei size
Definition: r_gl.h:152
#define MAX_VAR
Definition: shared.h:36
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
int numLasers
Definition: cp_base.h:120
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.
Definition: cp_research.h:137
Definition: cmd.h:86
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...
Definition: cp_base.cpp:312
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.
slot of aircraft
Definition: cp_aircraft.h:77
bool AII_AddItemToSlot(base_t *base, const technology_t *tech, aircraftSlot_t *slot, bool nextItem)
Add an item to an aircraft slot.
int numActiveBatteries
Definition: cp_base.h:118
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.
Definition: cp_base.cpp:389
QGL_EXTERN GLuint count
Definition: r_gl.h:99
baseWeapon_t batteries[MAX_BASE_SLOT]
Definition: cp_base.h:116
QGL_EXTERN GLint i
Definition: r_gl.h:113
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.
Definition: inv_shared.h:197
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.
Definition: cp_base.cpp:366
Header file for single player campaign control.
static void BDEF_AddSlotToSlotList(const aircraftSlot_t *slot, linkedList_t **slotList)
int installationTime
Definition: inv_shared.h:252
static const char * BDEF_GetIDFromItemType(aircraftItemType_t type)
returns the string identifier from an itemtype index
baseWeapon_t lasers[MAX_BASE_SLOT]
Definition: cp_base.h:119
static void BDEF_UpdateActiveBattery_f(void)
Updates the active defences counter.
#define lengthof(x)
Definition: shared.h:105
technology_t ** AII_GetCraftitemTechsByType(aircraftItemType_t type)
Returns a list of craftitem technologies for the given type.
#define Q_streq(a, b)
Definition: shared.h:136
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
Definition: cp_building.h:94
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.
craftItem craftitem
Definition: inv_shared.h:331
aircraft_t * target
Definition: cp_base.h:79
static aircraftItemType_t BDEF_GetItemTypeFromID(const char *type)
returns the itemtype index from a string identifier
const char *IMPORT * Cmd_Argv(int n)
const objDef_t * item
Definition: cp_aircraft.h:84
baseWeapon_t batteries[MAX_INSTALLATION_BATTERIES]
int numBatteries
Definition: cp_base.h:117
int installationTime
Definition: cp_aircraft.h:89