cp_base.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #ifndef CLIENT_CL_BASEMANGEMENT_H
00027 #define CLIENT_CL_BASEMANGEMENT_H
00028 
00029 #include "cp_aliencont.h"
00030 
00031 #define MAX_BASES 8
00032 
00033 #define MAX_BUILDINGS       32
00034 #define MAX_BASETEMPLATES   5
00035 
00036 #define MAX_BATTERY_DAMAGE  50
00037 #define MAX_BASE_DAMAGE     100
00038 #define MAX_BASE_SLOT       4
00039 
00041 #define BASEMAP_SIZE_X      778.0
00042 #define BASEMAP_SIZE_Y      672.0
00043 
00044 /* see MAX_TILESTRINGS */
00045 #define BASE_SIZE       5
00046 #define MAX_BASEBUILDINGS   BASE_SIZE * BASE_SIZE
00047 
00048 #define MAX_EMPLOYEES_IN_BUILDING 64
00049 
00050 #define MAX_BLOCKEDFIELDS   4
00051 #define MIN_BLOCKEDFIELDS   1
00052 
00057 #define BASE_TILE_SIZE 512
00058 #define BASE_TILE_UNITS (BASE_TILE_SIZE / UNIT_SIZE)
00059 #define BASE_MAX_WORLDLEVEL 6
00060 
00061 #define B_GetBaseIDX(base) ((ptrdiff_t)((base) - ccs.bases))
00062 #define B_GetBuildingIDX(base, building) ((ptrdiff_t)((building) - ccs.buildings[base->idx]))
00063 
00069 #define B_BuildingSetUsed(usedArray, buildingIDX) { (usedArray)[buildingIDX] = qtrue; }
00070 
00075 #define B_BuildingGetUsed(usedArray, buildingIDX) ((usedArray)[buildingIDX])
00076 
00081 typedef enum {
00082     BASE_NOT_USED,
00083     BASE_UNDER_ATTACK,  
00084     BASE_WORKING,       
00085     BASE_DESTROYED      
00086 } baseStatus_t;
00087 
00089 typedef enum {
00090     BA_NONE,
00091     BA_NEWBUILDING,     
00093     BA_MAX
00094 } baseAction_t;
00095 
00097 typedef enum {
00098     B_STATUS_NOT_SET,           
00099     B_STATUS_UNDER_CONSTRUCTION,    
00100     B_STATUS_CONSTRUCTION_FINISHED, 
00101     /* and building needs workers */
00102     B_STATUS_WORKING,           
00103     B_STATUS_DOWN               
00104 } buildingStatus_t;
00105 
00108 typedef enum {
00109     B_MISC,         
00110     B_LAB,          
00111     B_QUARTERS,     
00112     B_STORAGE,      
00113     B_WORKSHOP,     
00114     B_HOSPITAL,     
00115     B_HANGAR,       
00116     B_ALIEN_CONTAINMENT,    
00117     B_SMALL_HANGAR,     
00118     B_POWER,        
00119     B_COMMAND,      
00120     B_ANTIMATTER,       
00121     B_ENTRANCE,     
00122     B_DEFENCE_MISSILE,      
00123     B_DEFENCE_LASER,        
00124     B_RADAR,            
00126     MAX_BUILDING_TYPE
00127 } buildingType_t;
00128 
00130 typedef enum {
00131     CAP_ALIENS,     
00132     CAP_AIRCRAFT_SMALL, 
00133     CAP_AIRCRAFT_BIG,   
00134     CAP_EMPLOYEES,      
00135     CAP_ITEMS,      
00136     CAP_LABSPACE,       
00137     CAP_WORKSPACE,      
00138     CAP_ANTIMATTER,     
00140     MAX_CAP
00141 } baseCapacities_t;
00142 
00144 typedef struct cap_maxcur_s {
00145     int max;        
00146     int cur;        
00147 } capacities_t;
00148 
00150 typedef struct building_s {
00151     int idx;                
00152     struct building_s *tpl; 
00153     struct base_s *base;    
00155     char *id;
00156     char *name;         
00157     char *image, *mapPart, *pedia;
00158 
00159     char *needs;        
00160     int fixCosts, varCosts;
00161 
00166     float level;
00167 
00168     int timeStart, buildTime;
00169 
00170     buildingStatus_t buildingStatus;    
00172     qboolean visible;   
00175     char onConstruct[MAX_VAR];
00176     char onAttack[MAX_VAR];
00177     char onDestroy[MAX_VAR];
00178 
00179     int maxCount;       
00181     vec2_t pos;         
00182     qboolean mandatory;
00183 
00185     int maxEmployees;
00186 
00187     buildingType_t buildingType;    
00188     technology_t *tech;             
00189     struct building_s *dependsBuilding; 
00191     int capacity;       
00192 } building_t;
00193 
00194 typedef struct baseBuildingTile_s {
00195     building_t *building;   
00196     qboolean    blocked;    
00197     /* These are only used for baseTemplates: */
00198     int posX;   
00199     int posY;   
00200 } baseBuildingTile_t;
00201 
00202 typedef struct baseWeapon_s {
00203     /* int idx; */
00204     aircraftSlot_t slot;    
00205     aircraft_t *target;     
00206     qboolean autofire;      
00207 } baseWeapon_t;
00208 
00210 typedef struct base_s {
00211     int idx;                    
00212     char name[MAX_VAR];         
00213     baseBuildingTile_t map[BASE_SIZE][BASE_SIZE];   
00216     qboolean founded;   
00217     vec3_t pos;     
00224     qboolean hasBuilding[MAX_BUILDING_TYPE];
00225 
00228     linkedList_t *aircraft;
00229     aircraft_t *aircraftCurrent;        
00231     baseStatus_t baseStatus; 
00233     float alienInterest;    
00235     struct radar_s radar;
00236 
00237     aliensCont_t alienscont[MAX_ALIENCONT_CAP]; 
00239     capacities_t capacities[MAX_CAP];       
00241     equipDef_t storage; 
00243     inventory_t bEquipment; 
00246     baseWeapon_t batteries[MAX_BASE_SLOT];  
00247     int numBatteries;
00248     baseWeapon_t lasers[MAX_BASE_SLOT];     
00249     int numLasers;
00250 
00251     qboolean selected;      
00252     building_t *buildingCurrent; 
00253 } base_t;
00254 
00256 typedef struct baseTemplate_s {
00257     char* id;           
00258     baseBuildingTile_t buildings[MAX_BASEBUILDINGS]; 
00259     int numBuildings;       
00260 } baseTemplate_t;
00261 
00262 void B_UpdateBaseData(void);
00263 int B_CheckBuildingConstruction(building_t *b, base_t* base);
00264 float B_GetMaxBuildingLevel(const base_t* base, const buildingType_t type);
00265 void B_ParseBuildings(const char *name, const char **text, qboolean link);
00266 void B_ParseBaseTemplate(const char *name, const char **text);
00267 void B_BaseResetStatus(base_t* const base);
00268 building_t *B_GetBuildingInBaseByType(const base_t* base, buildingType_t type, qboolean onlyWorking);
00269 building_t *B_GetBuildingTemplate(const char *buildingName);
00270 const baseTemplate_t *B_GetBaseTemplate(const char *baseTemplateName);
00271 buildingType_t B_GetBuildingTypeByBuildingID(const char *buildingID);
00272 
00274 extern vec2_t newBasePos;
00275 
00276 void B_InitStartup(void);
00277 
00278 /* base functions */
00279 void B_NewBases(void);
00280 void B_SetUpBase(base_t* base, vec2_t pos);
00281 base_t* B_GetBaseByIDX(int baseIdx);
00282 base_t* B_GetFoundedBaseByIDX(int baseIdx);
00283 void B_SelectBase(const base_t *base);
00284 void B_UpdateBaseCount(void);
00285 int B_GetFoundedBaseCount(void);
00286 void B_Destroy(base_t *base);
00287 
00288 base_t *B_GetFirstUnfoundedBase(void);
00289 base_t *B_GetCurrentSelectedBase(void);
00290 void B_SetCurrentSelectedBase(const base_t *base);
00291 
00292 qboolean B_AssembleMap(const base_t *base);
00293 
00294 /* building functions */
00295 buildingType_t B_GetBuildingTypeByCapacity(baseCapacities_t cap);
00296 
00297 building_t* B_GetNextBuilding(const base_t *base, building_t *lastBuilding);
00298 building_t* B_GetNextBuildingByType(const base_t *base, building_t *lastBuilding, buildingType_t buildingType);
00299 void B_BuildingStatus(const base_t* base, const building_t* building);
00300 qboolean B_CheckBuildingTypeStatus(const base_t* const base, buildingType_t type, buildingStatus_t status, int *cnt);
00301 qboolean B_GetBuildingStatus(const base_t* const base, const buildingType_t type);
00302 void B_SetBuildingStatus(base_t* const base, const buildingType_t type, qboolean newStatus);
00303 qboolean B_CheckBuildingDependencesStatus(const base_t* const base, const building_t* building);
00304 
00305 building_t* B_SetBuildingByClick(base_t *base, const building_t const *buildingTemplate, int row, int col);
00306 void B_MarkBuildingDestroy(base_t* base, building_t* building);
00307 qboolean B_BuildingDestroy(base_t* base, building_t* building);
00308 
00309 building_t *B_GetFreeBuildingType(buildingType_t type);
00310 int B_GetNumberOfBuildingsInBaseByTemplate(const base_t *base, const building_t *type);
00311 int B_GetNumberOfBuildingsInBaseByBuildingType(const base_t *base, const buildingType_t type);
00312 
00313 void B_BuildingOpenAfterClick(const base_t *base, const building_t *building);
00314 void B_ResetBuildingCurrent(base_t* base);
00315 
00316 /* storage functions */
00317 qboolean B_ItemIsStoredInBaseStorage(const objDef_t *obj);
00318 qboolean B_BaseHasItem(const base_t *base, const objDef_t *item);
00319 int B_ItemInBase(const objDef_t *item, const base_t *base);
00320 
00321 int B_AddToStorage(base_t* base, const objDef_t *obj, int amount);
00322 
00323 /* aircraft functions */
00324 void B_AircraftReturnedToHomeBase(aircraft_t* aircraft);
00325 void B_DumpAircraftToHomeBase(aircraft_t *aircraft);
00326 
00327 /* capacity functions */
00328 void B_UpdateBaseCapacities(baseCapacities_t cap, base_t *base);
00329 qboolean B_UpdateStorageAndCapacity(base_t* base, const objDef_t *obj, int amount, qboolean reset, qboolean ignorecap);
00330 baseCapacities_t B_GetCapacityFromBuildingType(buildingType_t type);
00331 void B_ResetAllStatusAndCapacities(base_t *base, qboolean firstEnable);
00332 void B_UpdateStorageCap(base_t *base);
00333 
00334 void B_RemoveAircraftExceedingCapacity(base_t* base, buildingType_t buildingType);
00335 void B_RemoveItemsExceedingCapacity(base_t *base);
00336 void B_RemoveAntimatterExceedingCapacity(base_t *base);
00337 
00338 int B_FreeCapacity(const base_t *base, baseCapacities_t cap);
00339 
00340 /* menu functions */
00341 void B_BaseMenuInit(const base_t *base);
00342 void B_DrawBuilding(base_t* base, building_t* building);
00343 
00344 /* antimatter */
00345 int B_AntimatterInBase(const base_t *base);
00346 void B_ManageAntimatter(base_t *base, int amount, qboolean add);
00347 
00348 /* savesystem */
00349 void B_SaveBaseSlotsXML(const baseWeapon_t *weapons, const int numWeapons, mxml_node_t *p);
00350 int B_LoadBaseSlotsXML(baseWeapon_t* weapons, int numWeapons, mxml_node_t *p);
00351 qboolean B_SaveStorageXML(mxml_node_t *parent, const equipDef_t equip);
00352 qboolean B_LoadStorageXML(mxml_node_t *parent, equipDef_t *equip);
00353 
00354 /* other */
00355 qboolean B_ScriptSanityCheck(void);
00356 int B_GetInstallationLimit(void);
00357 
00358 /* functions that checks whether the buttons in the base menu are useable */
00359 qboolean BS_BuySellAllowed(const base_t* base);
00360 qboolean AIR_AircraftAllowed(const base_t* base);
00361 qboolean RS_ResearchAllowed(const base_t* base);
00362 qboolean PR_ProductionAllowed(const base_t* base);
00363 qboolean E_HireAllowed(const base_t* base);
00364 qboolean AC_ContainmentAllowed(const base_t* base);
00365 qboolean HOS_HospitalAllowed(const base_t* base);
00366 
00367 #endif /* CLIENT_CP_BASE_H */

Generated by  doxygen 1.6.2