1 /**
2  * @file
3  * @brief Header for installation management 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 #define MAX_INSTALLATIONS_PER_BASE 3
28 #define MAX_INSTALLATION_TEMPLATES	6
29 
30 #define MAX_INSTALLATION_DAMAGE	100
31 #define MAX_INSTALLATION_BATTERIES	5
32 
33 /**
34  * @brief Possible installation states
35  * @note: Don't change the order or you have to change the installationmenu scriptfiles, too
36  */
37 typedef enum {
38 	INSTALLATION_NOT_USED,				/**< installation is not set yet */
39 	INSTALLATION_UNDER_CONSTRUCTION,	/**< installation is under construction */
40 	INSTALLATION_WORKING				/**< nothing special, it's working */
41 } installationStatus_t;
42 
43 typedef enum {
44 	INSTALLATION_RADAR,
45 	INSTALLATION_DEFENCE,
46 	INSTALLATION_UFOYARD,
47 	INSTALLATION_ORBIT,
48 
49 	INSTALLATION_TYPE_MAX
50 } installationType_t;
51 
52 typedef struct installationTemplate_s {
53 	char* id;							/**< id of the installation. */
54 	char* name;							/**< Name of the installation (as you see it ingame). */
55 	char* description;					/**< Short description in build dialog */
56 	installationType_t type;			/**< the type of the installation */
57 
58 	int cost;							/**< Price of the installation. */
59 	int radarRange;						/**< The range of the installation's radar.  Units is the angle of the two points from center of earth. */
60 	int trackingRange;					/**< The tracking range of the installation's radar. Units are degrees. */
61 	int maxBatteries;					/**< The maximum number of battery slots that can be used in an installation. */
62 	int maxUFOsStored;					/**< The maximum number of ufos that can be stored in an installation. */
63 	int maxDamage;						/**< The maximum amount of damage an installation can sustain before it is destroyed. */
64 	int buildTime;						/**< Time to build the installation, in days. */
65 	char* model;						/**< Model used on 3D geoscape */
66 	char* image;						/**< Image used on 2D geoscape */
67 	struct technology_s* tech;			/**< Link to the installation-technology. */
68 	bool once;
69 } installationTemplate_t;
70 
71 
72 /** @brief A installation with all it's data */
73 typedef struct installation_s {
74 	int idx;						/**< Self link. Index in the global installation-list. */
75 	char name[MAX_VAR];				/**< Name of the installation */
76 
77 	const installationTemplate_t* installationTemplate; /** The template used for the installation. */
78 
79 	vec3_t pos;						/**< pos on geoscape */
80 
81 	installationStatus_t installationStatus; /**< the current installation status */
82 
83 	float alienInterest;			/**< How much aliens know this installation (and may attack it) */
84 
85 	struct radar_s radar;			/**< Radar of the installation (for radar towers) */
86 
87 	baseWeapon_t batteries[MAX_INSTALLATION_BATTERIES];	/**< Missile/Laser batteries assigned to this installation. For Sam Sites only. */
88 	int numBatteries;				/**< how many batteries are installed? */
89 
90 	capacities_t ufoCapacity;		/**< Capacity of UFO Yard. */
91 
92 	int installationDamage;			/**< Hit points of installation */
93 	int buildStart;					/**< Date when the installation building started */
94 	bool selected;					/**< current selected installation? */
95 } installation_t;
96 
97 /** Currently displayed/accessed base. */
98 extern installation_t* installationCurrent;
99 
100 /** Coordinates to place the new installation at (long, lat) */
101 extern vec2_t newInstallationPos;
102 
103 /* get installation */
104 #define INS_Foreach(var) LIST_Foreach(ccs.installations, installation_t, var)
105 #define INS_ForeachOfType(var, installationType) \
106 	INS_Foreach(var) \
107 		if ((var)->installationTemplate->type != (installationType)) continue; else
108 
109 #define INS_GetInstallationIDX(installation) ((installation)->idx)
110 installation_t* INS_GetByIDX(int idx);
111 installation_t* INS_GetFirstUFOYard(bool free);
112 int INS_GetCount(void);
113 
114 /* Installation template */
115 void INS_ParseInstallations(const char* name, const char** text);
116 const installationTemplate_t* INS_GetInstallationTemplateByID(const char* id);
117 const installationTemplate_t* INS_GetInstallationTemplateByType(installationType_t type);
118 void INS_LinkTechnologies(void);
119 
120 bool INS_HasAny(installationStatus_t status = INSTALLATION_WORKING);
121 bool INS_HasType(installationType_t type, installationStatus_t status = INSTALLATION_WORKING);
122 installationType_t INS_GetType(const char* type);
123 
124 /* Lifecycle: build/update/destroy */
125 installation_t* INS_Build(const installationTemplate_t* installationTemplate, const vec2_t pos, const char* name);
126 void INS_UpdateInstallationData(void);
127 void INS_DestroyInstallation(installation_t* installation);
128 
129 /* selection */
130 installation_t* INS_GetCurrentSelectedInstallation(void);
131 void INS_SetCurrentSelectedInstallation(const installation_t* installation);
132 void INS_SelectInstallation(installation_t* installation);
133 
134 void INS_InitStartup(void);
135 void INS_Shutdown(void);
136