UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_base.h
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 #pragma once
26 
27 #include "cp_capacity.h"
28 #include "cp_aliencont.h"
29 #include "cp_produce.h"
30 #include "cp_building.h"
31 
32 #define MAX_BASES 8
33 #define MAX_BASETEMPLATES 5
34 #define MAX_BUILDINGS 32
35 #define MAX_BASE_SLOT 4
36 
37 /* see MAX_TILESTRINGS */
38 #define BASE_SIZE 5
39 #define MAX_BASEBUILDINGS BASE_SIZE * BASE_SIZE
40 
41 #define MAX_BLOCKEDFIELDS 4
42 #define MIN_BLOCKEDFIELDS 1
43 
48 #define BASE_TILE_SIZE 512
49 #define BASE_TILE_UNITS (BASE_TILE_SIZE / UNIT_SIZE)
50 
51 #define BASE_INITIALINTEREST 1.0
52 
53 #define B_IsUnderAttack(base) ((base)->baseStatus == BASE_UNDER_ATTACK)
54 
55 #define B_AtLeastOneExists() (B_GetNext(nullptr) != nullptr)
56 
61 typedef enum {
66 } baseStatus_t;
67 
68 typedef struct baseBuildingTile_s {
70  bool blocked;
71  /* These are only used for baseTemplates: */
72  int posX;
73  int posY;
75 
76 typedef struct baseWeapon_s {
77  /* int idx; */
80  bool autofire;
81 } baseWeapon_t;
82 
84 typedef struct base_s {
85  int idx;
86  char name[MAX_VAR];
90  bool founded;
99 
106  struct radar_s radar;
107 
122 
123  /* we will allow only one active production at the same time for each base */
125 
126  bool selected;
127 } base_t;
128 
130 typedef struct baseTemplate_s {
131  char* id;
135 
137 float B_GetMaxBuildingLevel(const base_t* base, const buildingType_t type);
138 void B_ParseBaseTemplate(const char* name, const char** text);
139 void B_BaseResetStatus(base_t* const base);
140 const building_t* B_GetBuildingInBaseByType(const base_t* base, buildingType_t type, bool onlyWorking);
141 const baseTemplate_t* B_GetBaseTemplate(const char* baseTemplateName);
142 
143 void B_InitStartup(void);
144 
145 /* base functions */
146 base_t* B_Build(const struct campaign_s* campaign, const vec2_t pos, const char* name, bool fillBase = false);
147 void B_SetUpFirstBase(const struct campaign_s* campaign, base_t* base);
148 base_t* B_GetNext(base_t* lastBase);
149 base_t* B_GetBaseByIDX(int baseIdx);
150 base_t* B_GetFoundedBaseByIDX(int baseIdx);
151 int B_GetCount(void);
152 void B_SelectBase(const base_t* base);
153 void B_Destroy(base_t* base);
154 void B_Delete(base_t* base);
155 void B_SetName(base_t* base, const char* name);
156 
159 void B_SetCurrentSelectedBase(const base_t* base);
160 
161 bool B_AssembleMap(char* maps, size_t mapsLength, char* coords, size_t coordsLength, const base_t* base);
162 
163 /* building functions */
164 #define B_IsTileBlocked(base, x, y) (base)->map[(int)(y)][(int)(x)].blocked
165 #define B_GetBuildingAt(base, x, y) (base)->map[(int)(y)][(int)(x)].building
166 
167 building_t* B_GetNextBuilding(const base_t* base, building_t* lastBuilding);
168 building_t* B_GetNextBuildingByType(const base_t* base, building_t* lastBuilding, buildingType_t buildingType);
169 bool B_CheckBuildingTypeStatus(const base_t* const base, buildingType_t type, buildingStatus_t status, int* cnt);
170 bool B_GetBuildingStatus(const base_t* const base, const buildingType_t type);
171 void B_SetBuildingStatus(base_t* const base, const buildingType_t type, bool newStatus);
172 
173 bool B_MapIsCellFree(const base_t* base, int col, int row);
174 building_t* B_BuildBuilding(base_t* base, const building_t* buildingTemplate, int col, int row);
175 bool B_IsBuildingDestroyable(const building_t* building);
176 bool B_BuildingDestroy(building_t* building);
177 
181 
182 /* storage functions */
183 bool B_ItemIsStoredInBaseStorage(const objDef_t* obj);
184 bool B_BaseHasItem(const base_t* base, const objDef_t* item);
185 int B_ItemInBase(const objDef_t* item, const base_t* base);
186 
187 int B_AddToStorage(base_t* base, const objDef_t* obj, int amount);
188 
189 /* aircraft functions */
191 void B_DumpAircraftToHomeBase(aircraft_t* aircraft);
192 
193 /* capacity functions */
197 void B_ResetAllStatusAndCapacities(base_t* base, bool firstEnable);
198 
199 /* antimatter */
200 int B_AntimatterInBase(const base_t* base);
201 int B_AddAntimatter(base_t* base, int amount);
202 
203 /* savesystem */
204 void B_SaveBaseSlotsXML(const baseWeapon_t* weapons, const int numWeapons, xmlNode_t* p);
205 int B_LoadBaseSlotsXML(baseWeapon_t* weapons, int numWeapons, xmlNode_t* p);
206 bool B_SaveStorageXML(xmlNode_t* parent, const equipDef_t& equip);
207 bool B_LoadStorageXML(xmlNode_t* parent, equipDef_t* equip);
208 
209 /* other */
210 int B_GetInstallationLimit(void);
211 
212 /* functions that checks whether the buttons in the base menu are useable */
213 bool BS_BuySellAllowed(const base_t* base);
214 bool AIR_AircraftAllowed(const base_t* base);
215 bool RS_ResearchAllowed(const base_t* base);
216 bool PR_ProductionAllowed(const base_t* base);
217 bool E_HireAllowed(const base_t* base);
218 bool AC_ContainmentAllowed(const base_t* base);
219 bool HOS_HospitalAllowed(const base_t* base);
building_t * B_GetNextBuilding(const base_t *base, building_t *lastBuilding)
Iterates through buildings in a base.
Definition: cp_base.cpp:338
bool AC_ContainmentAllowed(const base_t *base)
Returns true if the current base is able to handle captured aliens.
Header file for Alien Containment stuff.
#define MAX_BASEBUILDINGS
Definition: cp_base.h:39
base_t * B_GetNext(base_t *lastBase)
Iterates through founded bases.
Definition: cp_base.cpp:285
struct baseBuildingTile_s baseBuildingTile_t
baseStatus_t
Possible base states.
Definition: cp_base.h:61
void B_UpdateBaseCapacities(baseCapacities_t cap, base_t *base)
Updates base capacities.
Definition: cp_base.cpp:2161
aircraftSlot_t slot
Definition: cp_base.h:78
A building with all it's data.
Definition: cp_building.h:73
struct base_s base_t
A base with all it's data.
production_queue_t productions
Definition: cp_base.h:124
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
bool B_BuildingDestroy(building_t *building)
Removes a building from the given base.
Definition: cp_base.cpp:770
int B_AddToStorage(base_t *base, const objDef_t *obj, int amount)
Add/remove items to/from the storage.
Definition: cp_base.cpp:2574
base_t * B_GetFoundedBaseByIDX(int baseIdx)
Array bound check for the base index.
Definition: cp_base.cpp:325
base_t * B_GetFirstUnfoundedBase(void)
Get the first unfounded base.
Definition: cp_base.cpp:1537
base_t * B_Build(const struct campaign_s *campaign, const vec2_t pos, const char *name, bool fillBase=false)
char name[MAX_VAR]
Definition: cp_base.h:86
bool founded
Definition: cp_base.h:90
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
bool AIR_AircraftAllowed(const base_t *base)
Returns true if the current base is able to handle aircraft.
int B_GetNumberOfBuildingsInBaseByTemplate(const base_t *base, const building_t *type)
Counts the number of buildings of a particular type in a base.
Definition: cp_base.cpp:1353
baseStatus_t baseStatus
Definition: cp_base.h:102
#define BASE_SIZE
Definition: cp_base.h:38
struct baseWeapon_s baseWeapon_t
class AlienContainment * alienContainment
Definition: cp_base.h:108
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
#define MAX_BASE_SLOT
Definition: cp_base.h:35
building_t * B_GetFreeBuildingType(buildingType_t type)
capacities_t capacities[MAX_CAP]
Definition: cp_base.h:110
void B_InitStartup(void)
Resets console commands.
Definition: cp_base.cpp:1971
const baseTemplate_t * B_GetBaseTemplate(const char *baseTemplateName)
Returns the baseTemplate in the global baseTemplate list that has the unique name baseTemplateID...
Definition: cp_base.cpp:1246
buildingType_t
All different building types.
Definition: cp_building.h:51
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
template for creating a base
Definition: cp_base.h:130
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
Alien containment class.
bool B_ItemIsStoredInBaseStorage(const objDef_t *obj)
Check if an item is stored in storage.
Definition: cp_base.cpp:2558
bool B_BaseHasItem(const base_t *base, const objDef_t *item)
Check if an item is available on a base.
Definition: cp_base.cpp:2120
equipDef_t storage
Definition: cp_base.h:112
bool B_SaveStorageXML(xmlNode_t *parent, const equipDef_t &equip)
Saves base storage.
Definition: cp_base.cpp:2245
void B_SaveBaseSlotsXML(const baseWeapon_t *weapons, const int numWeapons, xmlNode_t *p)
Saves the missile and laser slots of a base or sam site.
Definition: cp_base.cpp:2229
bool HOS_HospitalAllowed(const base_t *base)
Returns true if you can enter in the hospital.
A base with all it's data.
Definition: cp_base.h:84
A production queue. Lists all items to be produced.
Definition: cp_produce.h:90
bool autofire
Definition: cp_base.h:80
int numActiveLasers
Definition: cp_base.h:121
void B_ResetAllStatusAndCapacities(base_t *base, bool firstEnable)
Recalculate status and capacities of one base.
Definition: cp_base.cpp:705
#define xmlNode_t
Definition: xml.h:24
void B_SetName(base_t *base, const char *name)
Set the base name.
Definition: cp_base.cpp:1173
inventory definition with all its containers
Definition: inv_shared.h:525
aircraft_t * aircraftCurrent
Definition: cp_base.h:100
bool B_MapIsCellFree(const base_t *base, int col, int row)
Check a base cell.
Definition: cp_base.cpp:1263
void B_SetBuildingStatus(base_t *const base, const buildingType_t type, bool newStatus)
Set status associated to a building.
Definition: cp_base.cpp:498
building_t * building
Definition: cp_base.h:69
char * id
Definition: cp_base.h:131
#define MAX_VAR
Definition: shared.h:36
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t type)
Get the status associated to a building.
Definition: cp_base.cpp:477
int numLasers
Definition: cp_base.h:120
struct radar_s radar
Definition: cp_base.h:106
void B_UpdateBuildingConstructions(void)
Updates base data.
Definition: cp_base.cpp:2010
int idx
Definition: cp_base.h:85
bool selected
Definition: cp_base.h:126
bool B_AssembleMap(char *maps, size_t mapsLength, char *coords, size_t coordsLength, const base_t *base)
Perform the base assembling in case of an alien attack.
Definition: cp_base.cpp:562
Header for production related stuff.
baseBuildingTile_t map[BASE_SIZE][BASE_SIZE]
Definition: cp_base.h:87
Header for base building related stuff.
bool RS_ResearchAllowed(const base_t *base)
Returns true if the current base is able to handle research.
slot of aircraft
Definition: cp_aircraft.h:77
int B_GetNumberOfBuildingsInBaseByBuildingType(const base_t *base, const buildingType_t type)
Counts the number of buildings of a particular building type in a base.
Definition: cp_base.cpp:1386
int numActiveBatteries
Definition: cp_base.h:118
void B_ParseBaseTemplate(const char *name, const char **text)
Reads a base layout template.
Definition: cp_base.cpp:1435
base_t * B_GetCurrentSelectedBase(void)
returns the currently selected base
Definition: cp_base.cpp:1578
int B_GetInstallationLimit(void)
Counts the actual installation count limit.
Definition: cp_base.cpp:1153
bool PR_ProductionAllowed(const base_t *base)
Returns true if the current base is able to produce items.
Definition: cp_produce.cpp:595
baseCapacities_t
All possible capacities in base.
Definition: cp_capacity.h:27
void B_SetCurrentSelectedBase(const base_t *base)
Sets the selected base.
Definition: cp_base.cpp:1553
baseWeapon_t batteries[MAX_BASE_SLOT]
Definition: cp_base.h:116
int numBuildings
Definition: cp_base.h:133
bool BS_BuySellAllowed(const base_t *base)
Returns true if you can buy or sell equipment.
Definition: cp_market.cpp:655
bool B_IsBuildingDestroyable(const building_t *building)
Returns if a base building is destroyable.
Definition: cp_base.cpp:223
bool B_LoadStorageXML(xmlNode_t *parent, equipDef_t *equip)
Loads base storage.
Definition: cp_base.cpp:2388
void B_SelectBase(const base_t *base)
Select and opens a base.
Definition: cp_base.cpp:1592
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
buildingType_t B_GetBuildingTypeByCapacity(baseCapacities_t cap)
Get building type by base capacity.
Definition: cp_base.cpp:446
baseCapacities_t B_GetCapacityFromBuildingType(buildingType_t type)
Get the capacity associated to a building type.
Definition: cp_base.cpp:415
float alienInterest
Definition: cp_base.h:104
void B_Delete(base_t *base)
Resets a base structure.
Definition: cp_base.cpp:897
vec_t vec3_t[3]
Definition: ufotypes.h:39
vec_t vec2_t[2]
Definition: ufotypes.h:38
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
void B_BaseResetStatus(base_t *const base)
Sets the baseStatus to BASE_NOT_USED.
Definition: cp_base.cpp:1789
baseWeapon_t lasers[MAX_BASE_SLOT]
Definition: cp_base.h:119
const building_t * B_GetBuildingInBaseByType(const base_t *base, buildingType_t type, bool onlyWorking)
Gets a building of a given type in the given base.
Definition: cp_base.cpp:1414
void B_Destroy(base_t *base)
Destroy a base.
Definition: cp_base.cpp:913
baseBuildingTile_t buildings[MAX_BASEBUILDINGS]
Definition: cp_base.h:132
bool E_HireAllowed(const base_t *base)
Returns true if the current base is able to handle employees.
Inventory bEquipment
Definition: cp_base.h:114
float B_GetMaxBuildingLevel(const base_t *base, const buildingType_t type)
Get the maximum level of a building type in a base.
Definition: cp_base.cpp:518
void B_SetUpFirstBase(const struct campaign_s *campaign, base_t *base)
void B_AircraftReturnedToHomeBase(aircraft_t *aircraft)
Do anything when dropship returns to base.
Definition: cp_base.cpp:2103
vec3_t pos
Definition: cp_base.h:91
Store capacities in base.
Definition: cp_capacity.h:41
int B_LoadBaseSlotsXML(baseWeapon_t *weapons, int numWeapons, xmlNode_t *p)
Loads the missile and laser slots of a base or sam site.
Definition: cp_base.cpp:2348
building_t * B_BuildBuilding(base_t *base, const building_t *buildingTemplate, int col, int row)
Build a new building to the base.
Definition: cp_base.cpp:1279
An aircraft with all it's data.
Definition: cp_aircraft.h:114
int B_GetCount(void)
Returns the count of founded bases.
Definition: cp_base.cpp:276
int B_AntimatterInBase(const base_t *base)
returns the amount of antimatter stored in a base
Definition: cp_base.cpp:2611
bool hasBuilding[MAX_BUILDING_TYPE]
Definition: cp_base.h:98
aircraft_t * target
Definition: cp_base.h:79
struct baseTemplate_s baseTemplate_t
template for creating a base
int B_AddAntimatter(base_t *base, int amount)
Manages antimatter (adding, removing) through Antimatter Storage Facility.
Definition: cp_base.cpp:2633
void B_DumpAircraftToHomeBase(aircraft_t *aircraft)
Will unload all cargo to the homebase.
Definition: cp_base.cpp:2085
int numBatteries
Definition: cp_base.h:117
buildingStatus_t
All possible building status.
Definition: cp_building.h:31