UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_capacity.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23 
24 #include "../../cl_shared.h"
25 #include "cp_campaign.h"
26 #include "cp_capacity.h"
27 #include "cp_aircraft.h"
28 #include "cp_missions.h"
29 #include "cp_geoscape.h"
30 #include "cp_popup.h"
31 #include "cp_time.h"
32 #include "cp_ufo.h"
33 
39 {
40  const int amount = CAP_GetMax(base, CAP_ANTIMATTER) - CAP_GetCurrent(base, CAP_ANTIMATTER);
41  if (amount >= 0)
42  return;
43 
44  B_AddAntimatter(base, amount);
45 }
46 
53 {
54  CAP_SetCurrent(base, CAP_ITEMS, 0);
55 
56  for (int i = 0; i < cgi->csi->numODs; i++) {
57  const objDef_t* obj = INVSH_GetItemByIDX(i);
58 
60  continue;
61 
62  CAP_AddCurrent(base, CAP_ITEMS, B_ItemInBase(obj, base) * obj->size);
63  }
64 
65  /* UGV takes room in storage capacity */
67 }
68 
75 void CAP_SetMax (base_t* base, baseCapacities_t capacity, int value)
76 {
77  base->capacities[capacity].max = std::max(0, value);
78 }
79 
86 void CAP_AddMax (base_t* base, baseCapacities_t capacity, int value)
87 {
88  base->capacities[capacity].max = std::max(0, base->capacities[capacity].max + value);
89 }
90 
97 void CAP_SetCurrent (base_t* base, baseCapacities_t capacity, int value)
98 {
99  base->capacities[capacity].cur = std::max(0, value);
100 }
101 
108 void CAP_AddCurrent (base_t* base, baseCapacities_t capacity, int value)
109 {
110  base->capacities[capacity].cur = std::max(0, base->capacities[capacity].cur + value);
111 }
112 
119 int CAP_GetFreeCapacity (const base_t* base, baseCapacities_t capacityType)
120 {
121  const capacities_t* cap = CAP_Get(base, capacityType);
122  return cap->max - cap->cur;
123 }
124 
129 void CAP_CheckOverflow (void)
130 {
131  base_t* base = nullptr;
132 
133  while ((base = B_GetNext(base)) != nullptr) {
134  for (int i = CAP_ALIENS; i < MAX_CAP; i++) {
135  baseCapacities_t capacityType = (baseCapacities_t)i;
136  capacities_t* cap = CAP_Get(base, capacityType);
137 
138  if (cap->cur <= cap->max)
139  continue;
140 
141  switch (capacityType) {
142  case CAP_ANTIMATTER:
144  break;
145  case CAP_WORKSPACE:
147  break;
148  case CAP_LABSPACE:
150  break;
151  case CAP_AIRCRAFT_SMALL:
152  case CAP_AIRCRAFT_BIG:
153  case CAP_ALIENS:
154  case CAP_EMPLOYEES:
155  case CAP_ITEMS:
156  if (base->baseStatus != BASE_DESTROYED) {
158  const building_t* bldg = B_GetBuildingTemplateByType(bldgType);
159  CP_GameTimeStop();
160  cgi->Cmd_ExecuteString("ui_push popup_cap_overload %d \"%s\" \"%s\" %d %d",
161  base->idx, base->name, _(bldg->name), cap->max - cap->cur, cap->max);
162  }
163  break;
164  default:
165  /* nothing to do */
166  break;
167  }
168  }
169  }
170 }
int B_ItemInBase(const objDef_t *item, const base_t *base)
Check if the item has been collected (i.e it is in the storage) in the given base.
Definition: cp_base.cpp:2134
A building with all it's data.
Definition: cp_building.h:73
void CAP_AddCurrent(base_t *base, baseCapacities_t capacity, int value)
Changes the current (used) capacity on a base.
#define _(String)
Definition: cl_shared.h:43
const building_t * B_GetBuildingTemplateByType(buildingType_t type)
Returns the building template in the global building-types list for a buildingType.
char name[MAX_VAR]
Definition: cp_base.h:86
#define CAP_Get(base, capacity)
Capacity macros.
Definition: cp_capacity.h:50
csi_t * csi
Definition: cgame.h:100
baseStatus_t baseStatus
Definition: cp_base.h:102
capacities_t capacities[MAX_CAP]
Definition: cp_base.h:110
int numODs
Definition: q_shared.h:518
buildingType_t
All different building types.
Definition: cp_building.h:51
void RS_RemoveScientistsExceedingCapacity(base_t *base)
Remove all exceeding scientist.
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
void CP_GameTimeStop(void)
Stop game time speed.
Definition: cp_time.cpp:126
#define CAP_GetCurrent(base, capacity)
Definition: cp_capacity.h:52
int E_CountHired(const base_t *const base, employeeType_t type)
Counts hired employees of a given type in a given base.
A base with all it's data.
Definition: cp_base.h:84
int CAP_GetFreeCapacity(const base_t *base, baseCapacities_t capacityType)
Returns the free capacity of a type.
void CAP_AddMax(base_t *base, baseCapacities_t capacity, int value)
Changes the maximal capacity on a base.
Definition: cp_capacity.cpp:86
void CAP_RemoveAntimatterExceedingCapacity(base_t *base)
Remove exceeding antimatter if an antimatter tank has been destroyed.
Definition: cp_capacity.cpp:38
Campaign missions headers.
base_t * B_GetNext(base_t *lastBase)
Iterates through founded bases.
Definition: cp_base.cpp:285
const cgame_import_t * cgi
int idx
Definition: cp_base.h:85
Campaign geoscape time header.
void CAP_CheckOverflow(void)
Checks capacity overflows on bases.
Header for Geoscape management.
char * name
Definition: cp_building.h:79
#define CAP_GetMax(base, capacity)
Definition: cp_capacity.h:51
baseCapacities_t
All possible capacities in base.
Definition: cp_capacity.h:27
void CAP_UpdateStorageCap(base_t *base)
Update Storage Capacity.
Definition: cp_capacity.cpp:52
Header file for aircraft stuff.
QGL_EXTERN GLint i
Definition: r_gl.h:113
void CAP_SetCurrent(base_t *base, baseCapacities_t capacity, int value)
Sets the current (used) capacity on a base.
Definition: cp_capacity.cpp:97
int size
Definition: inv_shared.h:334
int B_AddAntimatter(base_t *base, int amount)
Manages antimatter (adding, removing) through Antimatter Storage Facility.
Definition: cp_base.cpp:2633
Header file for single player campaign control.
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
Definition: inv_shared.cpp:266
#define UGV_SIZE
Definition: cp_produce.h:33
Store capacities in base.
Definition: cp_capacity.h:41
void CAP_SetMax(base_t *base, baseCapacities_t capacity, int value)
Sets the maximal capacity on a base.
Definition: cp_capacity.cpp:75
void PR_UpdateProductionCap(base_t *base, int workerChange)
Update the current capacity of Workshop.
Definition: cp_produce.cpp:606
buildingType_t B_GetBuildingTypeByCapacity(baseCapacities_t cap)
Get building type by base capacity.
Definition: cp_base.cpp:446
bool B_ItemIsStoredInBaseStorage(const objDef_t *obj)
Check if an item is stored in storage.
Definition: cp_base.cpp:2558