UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_capacity.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, 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
75void CAP_SetMax (base_t* base, baseCapacities_t capacity, int value)
76{
77 base->capacities[capacity].max = std::max(0, value);
78}
79
86void 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
97void CAP_SetCurrent (base_t* base, baseCapacities_t capacity, int value)
98{
99 base->capacities[capacity].cur = std::max(0, value);
100}
101
108void 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
119int 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
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;
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);
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}
Share stuff between the different cgame implementations.
#define _(String)
Definition cl_shared.h:44
Header file for aircraft stuff.
base_t * B_GetNext(base_t *lastBase)
Iterates through founded bases.
Definition cp_base.cpp:286
bool B_ItemIsStoredInBaseStorage(const objDef_t *obj)
Check if an item is stored in storage.
Definition cp_base.cpp:2560
int B_AddAntimatter(base_t *base, int amount)
Manages antimatter (adding, removing) through Antimatter Storage Facility.
Definition cp_base.cpp:2635
buildingType_t B_GetBuildingTypeByCapacity(baseCapacities_t cap)
Get building type by base capacity.
Definition cp_base.cpp:447
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:2133
@ BASE_DESTROYED
Definition cp_base.h:65
const building_t * B_GetBuildingTemplateByType(buildingType_t type)
Returns the building template in the global building-types list for a buildingType.
buildingType_t
All different building types.
Definition cp_building.h:51
Header file for single player campaign control.
const cgame_import_t * cgi
void CAP_AddMax(base_t *base, baseCapacities_t capacity, int value)
Changes the maximal capacity on a base.
void CAP_UpdateStorageCap(base_t *base)
Update Storage Capacity.
void CAP_AddCurrent(base_t *base, baseCapacities_t capacity, int value)
Changes the current (used) capacity on a base.
void CAP_CheckOverflow(void)
Checks capacity overflows on bases.
void CAP_RemoveAntimatterExceedingCapacity(base_t *base)
Remove exceeding antimatter if an antimatter tank has been destroyed.
int CAP_GetFreeCapacity(const base_t *base, baseCapacities_t capacityType)
Returns the free capacity of a type.
void CAP_SetMax(base_t *base, baseCapacities_t capacity, int value)
Sets the maximal capacity on a base.
void CAP_SetCurrent(base_t *base, baseCapacities_t capacity, int value)
Sets the current (used) capacity on a base.
#define CAP_GetCurrent(base, capacity)
Definition cp_capacity.h:52
baseCapacities_t
All possible capacities in base.
Definition cp_capacity.h:27
@ CAP_ANTIMATTER
Definition cp_capacity.h:35
@ CAP_WORKSPACE
Definition cp_capacity.h:34
@ CAP_ITEMS
Definition cp_capacity.h:32
@ MAX_CAP
Definition cp_capacity.h:37
@ CAP_LABSPACE
Definition cp_capacity.h:33
@ CAP_AIRCRAFT_BIG
Definition cp_capacity.h:30
@ CAP_EMPLOYEES
Definition cp_capacity.h:31
@ CAP_AIRCRAFT_SMALL
Definition cp_capacity.h:29
@ CAP_ALIENS
Definition cp_capacity.h:28
#define CAP_GetMax(base, capacity)
Definition cp_capacity.h:51
#define CAP_Get(base, capacity)
Capacity macros.
Definition cp_capacity.h:50
int E_CountHired(const base_t *const base, employeeType_t type)
Counts hired employees of a given type in a given base.
@ EMPL_ROBOT
Definition cp_employee.h:35
Header for Geoscape management.
Campaign missions headers.
void PR_UpdateProductionCap(base_t *base, int workerChange)
Update the current capacity of Workshop.
#define UGV_SIZE
Definition cp_produce.h:33
void RS_RemoveScientistsExceedingCapacity(base_t *base)
Remove all exceeding scientist.
void CP_GameTimeStop(void)
Stop game time speed.
Definition cp_time.cpp:126
Campaign geoscape time header.
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
QGL_EXTERN GLint i
Definition r_gl.h:113
A base with all it's data.
Definition cp_base.h:84
baseStatus_t baseStatus
Definition cp_base.h:102
int idx
Definition cp_base.h:85
char name[MAX_VAR]
Definition cp_base.h:86
capacities_t capacities[MAX_CAP]
Definition cp_base.h:110
A building with all it's data.
Definition cp_building.h:73
char * name
Definition cp_building.h:79
Store capacities in base.
Definition cp_capacity.h:41
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264