UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_aircraft.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_radar.h"
29 
30 #define MAX_AIRCRAFT 64
31 #define LINE_MAXSEG 64
32 #define LINE_MAXPTS (LINE_MAXSEG + 2)
33 
35 #define AIRCRAFT_REFUEL_FACTOR 16
36 
38 typedef struct mapline_s {
39  int numPoints;
40  float distance;
43 } mapline_t;
44 
47 typedef enum {
51 } itemWeight_t;
52 
54 typedef enum {
63 
65 } itemPos_t;
66 
68 typedef enum {
70 
73 
74 #define MAX_AIRCRAFTSLOT 8
75 
77 typedef struct aircraftSlot_s {
78  int idx;
79  struct base_s* base;
81  struct aircraft_s* aircraft;
84  const objDef_t* item;
85  const objDef_t* ammo;
87  int ammoLeft;
91  const objDef_t* nextItem;
93  const objDef_t* nextAmmo;
96 
98 typedef enum aircraftStatus_s {
112 
114 typedef struct aircraft_s {
115  int idx;
118  struct aircraft_s* tpl;
119  char* id;
120  char name[MAX_VAR];
121  char* defaultName;
122  char* image;
123  char* model;
127  int price;
129  int fuel;
130  int damage;
135  int point;
136  int time;
141  class Employee* pilot;
149  struct base_s* homebase;
150  const char* building;
152  struct mission_s* mission;
154  char* missionID;
157  bool leader;
158  struct radar_s radar;
162  struct technology_s* tech;
164  bool notifySent[MAX_AIR_NOTIFICATIONS]; /* stores if a notification was already sent */
165 
166  bool detected;
168  bool landed;
179  inline ufoType_t getUfoType() const {
180  return ufotype;
181  }
182  inline void setUfoType(ufoType_t ufoT) {
183  ufotype = ufoT;
184  }
185 } aircraft_t;
186 
187 
192 #define AIR_Foreach(var) LIST_Foreach(ccs.aircraft, aircraft_t, var)
193 
194 #define AIR_IsAircraftOfBase(aircraft, base) ((aircraft)->homebase == (base) && (aircraft)->status != AIR_CRASHED)
195 
201 #define AIR_ForeachFromBase(var, base) \
202  AIR_Foreach(var) \
203  if (!AIR_IsAircraftOfBase(var, (base))) continue; else
204 
205 #define AIR_IsUFO(aircraft) ((aircraft)->getUfoType() != UFO_NONE)
206 
207 
208 aircraft_t* AIR_NewAircraft(struct base_s* base, const aircraft_t* aircraftTemplate);
209 aircraft_t* AIR_Add(struct base_s* base, const aircraft_t* aircraftTemplate);
210 bool AIR_Delete(struct base_s* base, aircraft_t* aircraft);
211 void AIR_DeleteAircraft(aircraft_t* aircraft);
212 void AIR_DestroyAircraft(aircraft_t* aircraft, bool killPilot = true);
213 
214 const aircraft_t* AIR_GetAircraftSilent(const char* name);
215 const aircraft_t* AIR_GetAircraft(const char* name);
216 
217 aircraft_t* AIR_GetFirstFromBase(const struct base_s* base);
218 bool AIR_BaseHasAircraft(const struct base_s* base);
219 int AIR_BaseCountAircraft(const struct base_s* base);
220 aircraft_t* AIR_GetAircraftFromBaseByIDXSafe(const struct base_s* base, int index);
221 
223 
224 const char* AIR_AircraftStatusToName(const aircraft_t* aircraft);
225 bool AIR_IsAircraftInBase(const aircraft_t* aircraft);
226 bool AIR_IsAircraftOnGeoscape(const aircraft_t* aircraft);
227 
228 void AIR_ResetAircraftTeam(aircraft_t* aircraft);
229 bool AIR_AddToAircraftTeam(aircraft_t* aircraft, class Employee* employee);
230 bool AIR_IsInAircraftTeam(const aircraft_t* aircraft, const class Employee* employee);
231 int AIR_GetTeamSize(const aircraft_t* aircraft);
232 
233 void AIR_CampaignRun(const struct campaign_s* campaign, int dt, bool updateRadarOverlay);
234 bool AIR_AircraftMakeMove(int dt, aircraft_t* aircraft);
235 
236 void AIR_ParseAircraft(const char* name, const char** text, bool assignAircraftItems);
237 
238 bool AIR_AircraftHasEnoughFuel(const aircraft_t* aircraft, const vec2_t destination);
239 bool AIR_AircraftHasEnoughFuelOneWay(const aircraft_t* aircraft, const vec2_t destination);
240 
241 void AIR_AircraftReturnToBase(aircraft_t* aircraft);
242 bool AIR_SendAircraftToMission(aircraft_t* aircraft, struct mission_s* mission);
243 
244 void AIR_AircraftsNotifyMissionRemoved(const struct mission_s* mission);
245 void AIR_AircraftsNotifyUFORemoved(const aircraft_t* const ufo, bool destroyed);
246 
247 void AIR_GetDestinationWhilePursuing(const aircraft_t* shooter, const aircraft_t* target, vec2_t dest);
249 void AIR_AircraftsUFODisappear(const aircraft_t* const ufo);
250 bool AIR_ScriptSanityCheck(void);
251 int AIR_AircraftMenuStatsValues(const int value, const int stat);
252 int AIR_CountInBaseByTemplate(const struct base_s* base, const aircraft_t* aircraftTemplate);
253 
254 int AIR_GetAircraftWeaponRanges(const aircraftSlot_t* slot, int maxSlot, float* weaponRanges);
256 
257 const char* AIR_CheckMoveIntoNewHomebase(const aircraft_t* aircraft, const struct base_s* base);
258 void AIR_MoveAircraftIntoNewHomebase(aircraft_t* aircraft, struct base_s* base);
259 
260 void AII_CollectItem(aircraft_t* aircraft, const objDef_t* item, int amount);
261 void AII_CollectingItems(aircraft_t* aircraft, int won);
262 
263 bool AIR_SetPilot(aircraft_t* aircraft, class Employee* pilot);
264 Employee* AIR_GetPilot(const aircraft_t* aircraft);
265 
266 bool AIR_PilotSurvivedCrash(const aircraft_t* aircraft);
267 
268 bool AIR_AddEmployee(Employee* employee, aircraft_t* aircraft);
269 void AIR_RemoveEmployees(aircraft_t& aircraft);
270 bool AIR_RemoveEmployee(Employee* employee, aircraft_t* aircraft);
271 
272 const aircraft_t* AIR_IsEmployeeInAircraft(const class Employee* employee, const aircraft_t* aircraft);
273 
274 void AIR_AutoAddPilotToAircraft(const struct base_s* base, class Employee* pilot);
275 void AIR_RemovePilotFromAssignedAircraft(const struct base_s* base, const class Employee* pilot);
276 
277 void AIR_MoveEmployeeInventoryIntoStorage(const aircraft_t& aircraft, equipDef_t& equip);
278 
279 void AIR_AssignInitial(aircraft_t* aircraft);
280 
281 bool AIR_CanIntercept(const aircraft_t* aircraft);
282 
283 int AIR_GetOperationRange(const aircraft_t* aircraft);
284 int AIR_GetRemainingRange(const aircraft_t* aircraft);
285 
286 void AIR_InitStartup(void);
287 void AIR_Shutdown(void);
const objDef_t * nextItem
Definition: cp_aircraft.h:91
float distance
Definition: cp_aircraft.h:40
bool AIR_AircraftHasEnoughFuelOneWay(const aircraft_t *aircraft, const vec2_t destination)
check if aircraft has enough fuel to go to destination
int AIR_GetOperationRange(const aircraft_t *aircraft)
Calculates the range an aircraft can fly on the geoscape.
bool notifySent[MAX_AIR_NOTIFICATIONS]
Definition: cp_aircraft.h:164
bool notOnGeoscape
Definition: cp_aircraft.h:170
struct installation_s * installation
Definition: cp_aircraft.h:80
#define LINE_MAXPTS
Definition: cp_aircraft.h:32
A installation with all it's data.
aircraft_t * AIR_Add(struct base_s *base, const aircraft_t *aircraftTemplate)
Adds a new aircraft from a given aircraft template to the base and sets the homebase for the new airc...
baseCapacities_t AIR_GetHangarCapacityType(const aircraft_t *aircraft)
Returns capacity type needed for an aircraft.
char * id
Definition: cp_aircraft.h:119
int detectionIdx
Definition: cp_aircraft.h:173
const char * building
Definition: cp_aircraft.h:150
void AIR_AircraftsUFODisappear(const aircraft_t *const ufo)
Notify that a UFO disappear from radars.
void AIR_MoveEmployeeInventoryIntoStorage(const aircraft_t &aircraft, equipDef_t &equip)
Move all the equipment carried by the team on the aircraft into the given equipment.
bool AIR_AircraftHasEnoughFuel(const aircraft_t *aircraft, const vec2_t destination)
check if aircraft has enough fuel to go to destination, and then come back home
int AIR_AircraftMenuStatsValues(const int value, const int stat)
Some of the aircraft values needs special calculations when they are shown in the menus...
int maxTeamSize
Definition: cp_aircraft.h:138
short ufoType_t
Definition: scripts.h:146
ufoType_t getUfoType() const
Definition: cp_aircraft.h:179
aircraft_t * AIR_GetFirstFromBase(const struct base_s *base)
bool AIR_IsAircraftOnGeoscape(const aircraft_t *aircraft)
Checks whether given aircraft is on geoscape.
Employee * AIR_GetPilot(const aircraft_t *aircraft)
Get pilot of an aircraft.
char * image
Definition: cp_aircraft.h:122
bool AIR_RemoveEmployee(Employee *employee, aircraft_t *aircraft)
Removes a soldier from an aircraft.
char name[MAX_VAR]
Definition: cp_aircraft.h:120
aircraft_t * AIR_AircraftGetFromIDX(int idx)
Returns aircraft for a given global index.
void AIR_Shutdown(void)
Closing actions for aircraft-subsystem.
aircraft_t * AIR_GetAircraftFromBaseByIDXSafe(const struct base_s *base, int index)
mission definition
Definition: cp_missions.h:85
linkedList_t * acTeam
Definition: cp_aircraft.h:139
int AIR_GetRemainingRange(const aircraft_t *aircraft)
Calculates the remaining range the aircraft can fly.
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
mapline_t route
Definition: cp_aircraft.h:134
ufoType_t ufotype
Definition: cp_aircraft.h:124
struct mission_s * mission
Definition: cp_aircraft.h:152
struct aircraft_s * tpl
Definition: cp_aircraft.h:118
void AIR_AutoAddPilotToAircraft(const struct base_s *base, class Employee *pilot)
int maxElectronics
Definition: cp_aircraft.h:147
A base with all it's data.
Definition: cp_base.h:84
class ItemCargo * itemCargo
Definition: cp_aircraft.h:177
void AIR_AircraftsNotifyMissionRemoved(const struct mission_s *mission)
bool AIR_AddEmployee(Employee *employee, aircraft_t *aircraft)
Assigns a soldier to an aircraft.
linkedList_t * missionTypes
Definition: cp_aircraft.h:172
struct radar_s radar
Definition: cp_aircraft.h:158
void AIR_DeleteAircraft(aircraft_t *aircraft)
Removes an aircraft from its base and the game.
struct technology_s * tech
Definition: cp_aircraft.h:162
void setUfoType(ufoType_t ufoT)
Definition: cp_aircraft.h:182
aircraftItemType_t type
Definition: cp_aircraft.h:82
void AIR_AssignInitial(aircraft_t *aircraft)
Assigns initial team of soldiers to aircraft.
int productionCost
Definition: cp_aircraft.h:128
void AIR_InitStartup(void)
Init actions for aircraft-subsystem.
struct base_s * base
Definition: cp_aircraft.h:79
vec3_t pos
Definition: cp_aircraft.h:131
#define MAX_VAR
Definition: shared.h:36
Item cargo class.
Definition: itemcargo.h:41
void AII_CollectItem(aircraft_t *aircraft, const objDef_t *item, int amount)
Add an item to aircraft inventory.
const objDef_t * ammo
Definition: cp_aircraft.h:85
const aircraft_t * AIR_GetAircraft(const char *name)
Searches the global array of aircraft types for a given aircraft.
void AII_CollectingItems(aircraft_t *aircraft, int won)
Collect items from the battlefield.
int AIR_GetTeamSize(const aircraft_t *aircraft)
Counts the number of soldiers in given aircraft.
void AIR_AircraftsNotifyUFORemoved(const aircraft_t *const ufo, bool destroyed)
Notify that a UFO has been removed.
const char * AIR_CheckMoveIntoNewHomebase(const aircraft_t *aircraft, const struct base_s *base)
void AIR_RemoveEmployees(aircraft_t &aircraft)
Removes all soldiers from an aircraft.
struct aircraft_s * aircraftTarget
Definition: cp_aircraft.h:156
This is the technology parsed from research.ufo.
Definition: cp_research.h:137
int ufoInterestOnGeoscape
Definition: cp_aircraft.h:171
void AIR_GetDestinationWhilePursuing(const aircraft_t *shooter, const aircraft_t *target, vec2_t dest)
Calculates the point where aircraft should go to intecept a moving target.
int AIR_BaseCountAircraft(const struct base_s *base)
Engine-side time information in the game.
Definition: common.h:290
bool AIR_SendAircraftPursuingUFO(aircraft_t *aircraft, aircraft_t *ufo)
Make the specified aircraft purchasing a UFO.
bool AIR_AircraftMakeMove(int dt, aircraft_t *aircraft)
Moves given aircraft.
itemWeight_t size
Definition: cp_aircraft.h:86
aircraftSlot_t weapons[MAX_AIRCRAFTSLOT]
Definition: cp_aircraft.h:143
aircraftStatus_s
Definition: cp_aircraft.h:98
bool AIR_IsInAircraftTeam(const aircraft_t *aircraft, const class Employee *employee)
bool AIR_ScriptSanityCheck(void)
Checks the parsed aircraft for errors.
Alien cargo class.
Definition: aliencargo.h:41
QGL_EXTERN GLenum GLuint * dest
Definition: r_gl.h:101
void AIR_AircraftReturnToBase(aircraft_t *aircraft)
Calculates the way back to homebase for given aircraft and returns it.
aircraft_t * AIR_NewAircraft(struct base_s *base, const aircraft_t *aircraftTemplate)
Places a new aircraft in the given base.
slot of aircraft
Definition: cp_aircraft.h:77
int AIR_GetAircraftWeaponRanges(const aircraftSlot_t *slot, int maxSlot, float *weaponRanges)
Get the all the unique weapon ranges of this aircraft.
bool AIR_CanIntercept(const aircraft_t *aircraft)
enum aircraftStatus_s aircraftStatus_t
struct aircraft_s aircraft_t
An aircraft with all it's data.
QGL_EXTERN GLuint index
Definition: r_gl.h:110
void AIR_MoveAircraftIntoNewHomebase(aircraft_t *aircraft, struct base_s *base)
Moves a given aircraft to a new base (also the employees and inventory)
const objDef_t * nextAmmo
Definition: cp_aircraft.h:93
char * defaultName
Definition: cp_aircraft.h:121
int numPoints
Definition: cp_aircraft.h:39
struct base_s * homebase
Definition: cp_aircraft.h:149
baseCapacities_t
All possible capacities in base.
Definition: cp_capacity.h:27
vec2_t point[LINE_MAXPTS]
Definition: cp_aircraft.h:42
vec3_t projectedPos
Definition: cp_aircraft.h:133
int maxWeapons
Definition: cp_aircraft.h:144
void AIR_ResetAircraftTeam(aircraft_t *aircraft)
Resets team in given aircraft.
void AIR_RemovePilotFromAssignedAircraft(const struct base_s *base, const class Employee *pilot)
void AIR_DestroyAircraft(aircraft_t *aircraft, bool killPilot=true)
Removes an aircraft from its base and the game.
bool AIR_PilotSurvivedCrash(const aircraft_t *aircraft)
Determine if an aircraft's pilot survived a crash, based on his piloting skill (and a bit of randomne...
#define MAX_AIRCRAFTSLOT
Definition: cp_aircraft.h:74
struct mapline_s mapline_t
A path on the map described by 2D points.
bool AIR_Delete(struct base_s *base, aircraft_t *aircraft)
Will remove the given aircraft from the base.
bool AIR_IsAircraftInBase(const aircraft_t *aircraft)
Checks whether given aircraft is in its homebase.
bool detected
Definition: cp_aircraft.h:166
bool AIR_SendAircraftToMission(aircraft_t *aircraft, struct mission_s *mission)
Sends the specified aircraft to specified mission.
aircraftItemType_t
All different types of craft items.
Definition: inv_shared.h:197
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
aircraftSlot_t shield
Definition: cp_aircraft.h:145
aircraftStatus_t status
Definition: cp_aircraft.h:125
bool AIR_SetPilot(aircraft_t *aircraft, class Employee *pilot)
Assign a pilot to an aircraft.
itemPos_t pos
Definition: cp_aircraft.h:94
vec_t vec3_t[3]
Definition: ufotypes.h:39
vec_t vec2_t[2]
Definition: ufotypes.h:38
char * missionID
Definition: cp_aircraft.h:154
const char * AIR_AircraftStatusToName(const aircraft_t *aircraft)
Translates the aircraft status id to a translatable string.
vec3_t direction
Definition: cp_aircraft.h:132
bool AIR_AddToAircraftTeam(aircraft_t *aircraft, class Employee *employee)
Adds given employee to given aircraft.
int stats[AIR_STATS_MAX]
Definition: cp_aircraft.h:159
const aircraft_t * AIR_GetAircraftSilent(const char *name)
Searches the global array of aircraft types for a given aircraft.
An aircraft with all it's data.
Definition: cp_aircraft.h:114
class AlienCargo * alienCargo
Definition: cp_aircraft.h:176
void AIR_ParseAircraft(const char *name, const char **text, bool assignAircraftItems)
Parses all aircraft that are defined in our UFO-scripts.
itemPos_t
different positions for aircraft items
Definition: cp_aircraft.h:54
int AIR_CountInBaseByTemplate(const struct base_s *base, const aircraft_t *aircraftTemplate)
struct aircraft_s * aircraft
Definition: cp_aircraft.h:81
void AIR_CampaignRun(const struct campaign_s *campaign, int dt, bool updateRadarOverlay)
date_t lastSpotted
Definition: cp_aircraft.h:174
char * model
Definition: cp_aircraft.h:123
class Employee * pilot
Definition: cp_aircraft.h:141
A path on the map described by 2D points.
Definition: cp_aircraft.h:38
const aircraft_t * AIR_IsEmployeeInAircraft(const class Employee *employee, const aircraft_t *aircraft)
aircraftSlot_t electronics[MAX_AIRCRAFTSLOT]
Definition: cp_aircraft.h:146
const objDef_t * item
Definition: cp_aircraft.h:84
bool AIR_BaseHasAircraft(const struct base_s *base)
int installationTime
Definition: cp_aircraft.h:89
struct aircraftSlot_s aircraftSlot_t
slot of aircraft
itemWeight_t
different weight for aircraft items
Definition: cp_aircraft.h:47
aircraft_notifications_t
notification signals for aircraft events
Definition: cp_aircraft.h:68