UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_base.h
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
67
68typedef struct baseBuildingTile_s {
70 bool blocked;
71 /* These are only used for baseTemplates: */
72 int posX;
73 int posY;
75
76typedef struct baseWeapon_s {
77 /* int idx; */
80 bool autofire;
82
128
135
137float B_GetMaxBuildingLevel(const base_t* base, const buildingType_t type);
138void B_ParseBaseTemplate(const char* name, const char** text);
139void B_BaseResetStatus(base_t* const base);
140const building_t* B_GetBuildingInBaseByType(const base_t* base, buildingType_t type, bool onlyWorking);
141const baseTemplate_t* B_GetBaseTemplate(const char* baseTemplateName);
142
143void B_InitStartup(void);
144
145/* base functions */
146base_t* B_Build(const struct campaign_s* campaign, const vec2_t pos, const char* name, bool fillBase = false);
147void B_SetUpFirstBase(const struct campaign_s* campaign, base_t* base);
148base_t* B_GetNext(base_t* lastBase);
149base_t* B_GetBaseByIDX(int baseIdx);
150base_t* B_GetFoundedBaseByIDX(int baseIdx);
151int B_GetCount(void);
152void B_SelectBase(const base_t* base);
153void B_Destroy(base_t* base);
154void B_Delete(base_t* base);
155void B_SetName(base_t* base, const char* name);
156
159void B_SetCurrentSelectedBase(const base_t* base);
160
161bool 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
167building_t* B_GetNextBuilding(const base_t* base, building_t* lastBuilding);
168building_t* B_GetNextBuildingByType(const base_t* base, building_t* lastBuilding, buildingType_t buildingType);
169bool B_CheckBuildingTypeStatus(const base_t* const base, buildingType_t type, buildingStatus_t status, int* cnt);
170bool B_GetBuildingStatus(const base_t* const base, const buildingType_t type);
171void B_SetBuildingStatus(base_t* const base, const buildingType_t type, bool newStatus);
172
173bool B_MapIsCellFree(const base_t* base, int col, int row);
174building_t* B_BuildBuilding(base_t* base, const building_t* buildingTemplate, int col, int row);
175bool B_IsBuildingDestroyable(const building_t* building);
176bool B_BuildingDestroy(building_t* building);
177
181
182/* storage functions */
184bool B_BaseHasItem(const base_t* base, const objDef_t* item);
185int B_ItemInBase(const objDef_t* item, const base_t* base);
186
187int B_AddToStorage(base_t* base, const objDef_t* obj, int amount);
188
189/* aircraft functions */
192
193/* capacity functions */
197void B_ResetAllStatusAndCapacities(base_t* base, bool firstEnable);
198
199/* antimatter */
200int B_AntimatterInBase(const base_t* base);
201int B_AddAntimatter(base_t* base, int amount);
202
203/* savesystem */
204void B_SaveBaseSlotsXML(const baseWeapon_t* weapons, const int numWeapons, xmlNode_t* p);
205int B_LoadBaseSlotsXML(baseWeapon_t* weapons, int numWeapons, xmlNode_t* p);
206bool B_SaveStorageXML(xmlNode_t* parent, const equipDef_t& equip);
207bool B_LoadStorageXML(xmlNode_t* parent, equipDef_t* equip);
208
209/* other */
210int B_GetInstallationLimit(void);
211
212/* functions that checks whether the buttons in the base menu are useable */
213bool BS_BuySellAllowed(const base_t* base);
214bool AIR_AircraftAllowed(const base_t* base);
215bool RS_ResearchAllowed(const base_t* base);
216bool PR_ProductionAllowed(const base_t* base);
217bool E_HireAllowed(const base_t* base);
218bool AC_ContainmentAllowed(const base_t* base);
219bool HOS_HospitalAllowed(const base_t* base);
Alien containment class.
inventory definition with all its containers
Definition inv_shared.h:525
Header file for Alien Containment stuff.
void B_ParseBaseTemplate(const char *name, const char **text)
Reads a base layout template.
Definition cp_base.cpp:1435
void B_DumpAircraftToHomeBase(aircraft_t *aircraft)
Will unload all cargo to the homebase.
Definition cp_base.cpp:2084
building_t * B_GetFreeBuildingType(buildingType_t type)
void B_BaseResetStatus(base_t *const base)
Sets the baseStatus to BASE_NOT_USED.
Definition cp_base.cpp:1789
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t type)
Get the status associated to a building.
Definition cp_base.cpp:478
bool B_BuildingDestroy(building_t *building)
Removes a building from the given base.
Definition cp_base.cpp:771
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
void B_SetUpFirstBase(const struct campaign_s *campaign, base_t *base)
bool AC_ContainmentAllowed(const base_t *base)
Returns true if the current base is able to handle captured aliens.
baseCapacities_t B_GetCapacityFromBuildingType(buildingType_t type)
Get the capacity associated to a building type.
Definition cp_base.cpp:416
bool PR_ProductionAllowed(const base_t *base)
Returns true if the current base is able to produce items.
#define BASE_SIZE
Definition cp_base.h:38
base_t * B_GetFoundedBaseByIDX(int baseIdx)
Array bound check for the base index.
Definition cp_base.cpp:326
base_t * B_Build(const struct campaign_s *campaign, const vec2_t pos, const char *name, bool fillBase=false)
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:563
bool B_LoadStorageXML(xmlNode_t *parent, equipDef_t *equip)
Loads base storage.
Definition cp_base.cpp:2387
void B_SelectBase(const base_t *base)
Select and opens a base.
Definition cp_base.cpp:1592
baseStatus_t
Possible base states.
Definition cp_base.h:61
@ BASE_UNDER_ATTACK
Definition cp_base.h:63
@ BASE_WORKING
Definition cp_base.h:64
@ BASE_NOT_USED
Definition cp_base.h:62
@ BASE_DESTROYED
Definition cp_base.h:65
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
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:367
bool AIR_AircraftAllowed(const base_t *base)
Returns true if the current base is able to handle aircraft.
base_t * B_GetNext(base_t *lastBase)
Iterates through founded bases.
Definition cp_base.cpp:286
void B_SetCurrentSelectedBase(const base_t *base)
Sets the selected base.
Definition cp_base.cpp:1553
bool E_HireAllowed(const base_t *base)
Returns true if the current base is able to handle employees.
void B_AircraftReturnedToHomeBase(aircraft_t *aircraft)
Do anything when dropship returns to base.
Definition cp_base.cpp:2102
void B_ResetAllStatusAndCapacities(base_t *base, bool firstEnable)
Recalculate status and capacities of one base.
Definition cp_base.cpp:706
bool B_BaseHasItem(const base_t *base, const objDef_t *item)
Check if an item is available on a base.
Definition cp_base.cpp:2119
int B_GetCount(void)
Returns the count of founded bases.
Definition cp_base.cpp:277
bool B_ItemIsStoredInBaseStorage(const objDef_t *obj)
Check if an item is stored in storage.
Definition cp_base.cpp:2560
int B_GetInstallationLimit(void)
Counts the actual installation count limit.
Definition cp_base.cpp:1153
int B_AddAntimatter(base_t *base, int amount)
Manages antimatter (adding, removing) through Antimatter Storage Facility.
Definition cp_base.cpp:2635
base_t * B_GetCurrentSelectedBase(void)
returns the currently selected base
Definition cp_base.cpp:1578
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:313
bool B_IsBuildingDestroyable(const building_t *building)
Returns if a base building is destroyable.
Definition cp_base.cpp:224
void B_SetName(base_t *base, const char *name)
Set the base name.
Definition cp_base.cpp:1173
void B_Destroy(base_t *base)
Destroy a base.
Definition cp_base.cpp:914
void B_UpdateBaseCapacities(baseCapacities_t cap, base_t *base)
Updates base capacities.
Definition cp_base.cpp:2160
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:390
bool RS_ResearchAllowed(const base_t *base)
Returns true if the current base is able to handle research.
#define MAX_BASEBUILDINGS
Definition cp_base.h:39
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
void B_SetBuildingStatus(base_t *const base, const buildingType_t type, bool newStatus)
Set status associated to a building.
Definition cp_base.cpp:499
void B_Delete(base_t *base)
Resets a base structure.
Definition cp_base.cpp:898
int B_AntimatterInBase(const base_t *base)
returns the amount of antimatter stored in a base
Definition cp_base.cpp:2613
bool HOS_HospitalAllowed(const base_t *base)
Returns true if you can enter in the hospital.
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
int B_AddToStorage(base_t *base, const objDef_t *obj, int amount)
Add/remove items to/from the storage.
Definition cp_base.cpp:2576
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
#define MAX_BASE_SLOT
Definition cp_base.h:35
void B_UpdateBuildingConstructions(void)
Updates base data.
Definition cp_base.cpp:2009
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:2228
bool B_SaveStorageXML(xmlNode_t *parent, const equipDef_t &equip)
Saves base storage.
Definition cp_base.cpp:2244
base_t * B_GetFirstUnfoundedBase(void)
Get the first unfounded base.
Definition cp_base.cpp:1537
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:519
void B_InitStartup(void)
Resets console commands.
Definition cp_base.cpp:1970
building_t * B_GetNextBuilding(const base_t *base, building_t *lastBuilding)
Iterates through buildings in a base.
Definition cp_base.cpp:339
bool B_MapIsCellFree(const base_t *base, int col, int row)
Check a base cell.
Definition cp_base.cpp:1263
bool BS_BuySellAllowed(const base_t *base)
Returns true if you can buy or sell equipment.
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:2347
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
Header for base building related stuff.
buildingType_t
All different building types.
Definition cp_building.h:51
@ MAX_BUILDING_TYPE
Definition cp_building.h:69
buildingStatus_t
All possible building status.
Definition cp_building.h:31
baseCapacities_t
All possible capacities in base.
Definition cp_capacity.h:27
@ MAX_CAP
Definition cp_capacity.h:37
Header for production related stuff.
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
#define MAX_VAR
Definition shared.h:36
An aircraft with all it's data.
slot of aircraft
Definition cp_aircraft.h:78
A base with all it's data.
Definition cp_base.h:84
production_queue_t productions
Definition cp_base.h:124
int numLasers
Definition cp_base.h:120
aircraft_t * aircraftCurrent
Definition cp_base.h:100
struct radar_s radar
Definition cp_base.h:106
class AlienContainment * alienContainment
Definition cp_base.h:108
baseWeapon_t batteries[MAX_BASE_SLOT]
Definition cp_base.h:116
baseWeapon_t lasers[MAX_BASE_SLOT]
Definition cp_base.h:119
bool founded
Definition cp_base.h:90
float alienInterest
Definition cp_base.h:104
baseBuildingTile_t map[BASE_SIZE][BASE_SIZE]
Definition cp_base.h:87
int numActiveLasers
Definition cp_base.h:121
baseStatus_t baseStatus
Definition cp_base.h:102
Inventory bEquipment
Definition cp_base.h:114
int idx
Definition cp_base.h:85
char name[MAX_VAR]
Definition cp_base.h:86
bool hasBuilding[MAX_BUILDING_TYPE]
Definition cp_base.h:98
vec3_t pos
Definition cp_base.h:91
int numBatteries
Definition cp_base.h:117
bool selected
Definition cp_base.h:126
int numActiveBatteries
Definition cp_base.h:118
equipDef_t storage
Definition cp_base.h:112
capacities_t capacities[MAX_CAP]
Definition cp_base.h:110
building_t * building
Definition cp_base.h:69
template for creating a base
Definition cp_base.h:130
baseBuildingTile_t buildings[MAX_BASEBUILDINGS]
Definition cp_base.h:132
aircraftSlot_t slot
Definition cp_base.h:78
aircraft_t * target
Definition cp_base.h:79
bool autofire
Definition cp_base.h:80
A building with all it's data.
Definition cp_building.h:73
Store capacities in base.
Definition cp_capacity.h:41
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
A production queue. Lists all items to be produced.
Definition cp_produce.h:91
vec_t vec3_t[3]
Definition ufotypes.h:39
vec_t vec2_t[2]
Definition ufotypes.h:38
#define xmlNode_t
Definition xml.h:24