1 /** 2 * @file 3 * @brief Header for base building related stuff. 4 */ 5 6 /* 7 Copyright (C) 2002-2013 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 "../../../shared/shared.h" 28 #include "../../../shared/mathlib.h" 29 #include "../../../common/common.h" 30 31 struct technology_s; 32 33 /** @brief All possible building status. */ 34 typedef enum { 35 B_STATUS_NOT_SET, /**< not build yet */ 36 B_STATUS_UNDER_CONSTRUCTION, /**< right now under construction */ 37 B_STATUS_CONSTRUCTION_FINISHED, /**< construction finished - no workers assigned */ 38 /* and building needs workers */ 39 B_STATUS_WORKING, /**< working normal (or workers assigned when needed) */ 40 B_STATUS_DOWN /**< totally damaged */ 41 } buildingStatus_t; 42 43 /** @brief Building events */ 44 typedef enum { 45 B_ONCONSTRUCT, /**< building was placed on the base map */ 46 B_ONENABLE, /**< building get operational (built up and all dependencies met) */ 47 B_ONDISABLE, /**< building got disabled (ex: a dependency was destroyed) */ 48 B_ONDESTROY, /**< building was destroyed */ 49 B_MAXEVENT 50 } buildingEvent_t; 51 52 /** @brief All different building types. 53 * @note if you change the order, you'll load values of hasBuilding in wrong indice */ 54 typedef enum { 55 B_MISC, /**< this building is nothing with a special function (used when a building appears twice in .ufo file) */ 56 B_LAB, /**< this building is a lab */ 57 B_QUARTERS, /**< this building is a quarter */ 58 B_STORAGE, /**< this building is a storage */ 59 B_WORKSHOP, /**< this building is a workshop */ 60 B_HOSPITAL, /**< this building is a hospital */ 61 B_HANGAR, /**< this building is a hangar */ 62 B_ALIEN_CONTAINMENT, /**< this building is an alien containment */ 63 B_SMALL_HANGAR, /**< this building is a small hangar */ 64 B_POWER, /**< this building is power plant */ 65 B_COMMAND, /**< this building is command centre */ 66 B_ANTIMATTER, /**< this building is antimatter storage */ 67 B_ENTRANCE, /**< this building is an entrance */ 68 B_DEFENCE_MISSILE, /**< this building is a missile rack */ 69 B_DEFENCE_LASER, /**< this building is a laser battery */ 70 B_RADAR, /**< this building is a radar */ 71 72 MAX_BUILDING_TYPE 73 } buildingType_t; 74 75 /** @brief A building with all it's data. */ 76 typedef struct building_s { 77 int idx; /**< Index in in the base buildings list. */ 78 struct building_s* tpl; /**< Self link in "buildingTemplates" list. */ 79 struct base_s* base; /**< The base this building is located in. */ 80 81 const char* id; 82 char* name; /**< translatable name of the building */ 83 const char* image, *mapPart, *pedia; 84 85 vec2_t size; 86 int fixCosts, varCosts; 87 88 /** 89 * level of the building. 90 * @note This value depends on the implementation of the affected building 91 * might e.g. be a factor */ 92 float level; 93 94 date_t timeStart; 95 int buildTime; 96 97 buildingStatus_t buildingStatus; 98 99 /** Event handler functions */ 100 char* onConstruct; 101 char* onDestroy; 102 char* onEnable; 103 char* onDisable; 104 105 int maxCount; /**< How many building of the same type allowed? */ 106 107 vec2_t pos; /**< location in the base. */ 108 bool mandatory; 109 110 /** How many employees to hire on construction in the first base */ 111 int maxEmployees; 112 113 buildingType_t buildingType; /**< This way we can rename the buildings without loosing the control. @note Not to be confused with "tpl".*/ 114 struct technology_s* tech; /**< Link to the building-technology. */ 115 const struct building_s* dependsBuilding; /**< If the building needs another one to work (= to be buildable). @sa "buildingTemplates" list*/ 116 117 int capacity; /**< Capacity of this building (used in calculate base capacities). */ 118 } building_t; 119 120 /** 121 * @brief Macro sets a building used 122 * @param[in] usedArray must be a bool array of the size MAX_BUILDINGS 123 * @param[in] buildingIDX Index of building to set used 124 */ 125 #define B_BuildingSetUsed(usedArray, buildingIDX) { (usedArray)[buildingIDX] = true; } 126 /** 127 * @brief Macro returns if a building is used 128 * @param[in] usedArray must be a bool array of the size MAX_BUILDINGS 129 * @param[in] buildingIDX Index of building to check 130 */ 131 #define B_BuildingGetUsed(usedArray, buildingIDX) ((usedArray)[buildingIDX]) 132 133 void B_ParseBuildings(const char* name, const char** text, bool link); 134 bool B_BuildingScriptSanityCheck(void); 135 136 building_t* B_GetBuildingTemplate(const char* buildingName); 137 building_t* B_GetBuildingTemplateSilent(const char* buildingName); 138 const building_t* B_GetBuildingTemplateByType(buildingType_t type); 139 140 buildingType_t B_GetBuildingTypeByBuildingID(const char* buildingID); 141 bool B_CheckBuildingDependencesStatus(const building_t* building); 142 bool B_IsBuildingBuiltUp(const building_t* building); 143 float B_GetConstructionTimeRemain(const building_t* building); 144 145 bool B_FireEvent(const building_t* buildingTemplate, const struct base_s* base, buildingEvent_t eventType); 146