UFO: Alien Invasion
cp_aircraft.h
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2022 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 "../../DateTime.h"
28 #include "cp_capacity.h"
29 #include "cp_radar.h"
30 
31 #define MAX_AIRCRAFT 64
32 #define LINE_MAXSEG 64
33 #define LINE_MAXPTS (LINE_MAXSEG + 2)
34 
36 #define AIRCRAFT_REFUEL_FACTOR 16
37 
39 typedef struct mapline_s {
40  int numPoints;
41  float distance;
44 } mapline_t;
45 
48 typedef enum {
52 } itemWeight_t;
53 
55 typedef enum {
64 
66 } itemPos_t;
67 
69 typedef enum {
71 
74 
75 #define MAX_AIRCRAFTSLOT 8
76 
78 typedef struct aircraftSlot_s {
79  int idx;
80  struct base_s* base;
81  struct installation_s* installation;
82  struct aircraft_s* aircraft;
85  const objDef_t* item;
86  const objDef_t* ammo;
88  int ammoLeft;
92  const objDef_t* nextItem;
94  const objDef_t* nextAmmo;
97 
99 typedef enum aircraftStatus_s {
113 
115 typedef struct aircraft_s {
116  int idx;
119  struct aircraft_s* tpl;
120  char* id;
121  char name[MAX_VAR];
122  char* defaultName;
123  char* image;
124  char* model;
128  int price;
130  int fuel;
131  int damage;
136  int point;
137  int time;
142  class Employee* pilot;
150  struct base_s* homebase;
151  const char* building;
153  struct mission_s* mission;
155  char* missionID;
157  struct aircraft_s* aircraftTarget;
158  bool leader;
159  struct radar_s radar;
160  int stats[AIR_STATS_MAX] ;
163  struct technology_s* tech;
165  bool notifySent[MAX_AIR_NOTIFICATIONS]; /* stores if a notification was already sent */
166 
167  bool detected;
169  bool landed;
175  class DateTime lastSpotted;
180  inline ufoType_t getUfoType() const {
181  return ufotype;
182  }
183  inline void setUfoType(ufoType_t ufoT) {
184  ufotype = ufoT;
185  }
186 } aircraft_t;
187 
188 
193 #define AIR_Foreach(var) LIST_Foreach(ccs.aircraft, aircraft_t, var)
194 
195 #define AIR_IsAircraftOfBase(aircraft, base) ((aircraft)->homebase == (base) && (aircraft)->status != AIR_CRASHED)
196 
202 #define AIR_ForeachFromBase(var, base) \
203  AIR_Foreach(var) \
204  if (!AIR_IsAircraftOfBase(var, (base))) continue; else
205 
206 #define AIR_IsUFO(aircraft) ((aircraft)->getUfoType() != UFO_NONE)
207 
208 
209 aircraft_t* AIR_NewAircraft(struct base_s* base, const aircraft_t* aircraftTemplate);
210 aircraft_t* AIR_Add(struct base_s* base, const aircraft_t* aircraftTemplate);
211 bool AIR_Delete(struct base_s* base, aircraft_t* aircraft);
212 void AIR_DeleteAircraft(aircraft_t* aircraft);
213 void AIR_DestroyAircraft(aircraft_t* aircraft, bool killPilot = true);
214 
215 const aircraft_t* AIR_GetAircraftSilent(const char* name);
216 const aircraft_t* AIR_GetAircraft(const char* name);
217 
218 aircraft_t* AIR_GetFirstFromBase(const struct base_s* base);
219 bool AIR_BaseHasAircraft(const struct base_s* base);
220 int AIR_BaseCountAircraft(const struct base_s* base);
221 aircraft_t* AIR_GetAircraftFromBaseByIDXSafe(const struct base_s* base, int index);
222 
224 
225 const char* AIR_AircraftStatusToName(const aircraft_t* aircraft);
226 bool AIR_IsAircraftInBase(const aircraft_t* aircraft);
227 bool AIR_IsAircraftOnGeoscape(const aircraft_t* aircraft);
228 
229 void AIR_ResetAircraftTeam(aircraft_t* aircraft);
230 bool AIR_AddToAircraftTeam(aircraft_t* aircraft, class Employee* employee);
231 bool AIR_IsInAircraftTeam(const aircraft_t* aircraft, const class Employee* employee);
232 int AIR_GetTeamSize(const aircraft_t* aircraft);
233 
234 void AIR_CampaignRun(const struct campaign_s* campaign, int dt, bool updateRadarOverlay);
235 bool AIR_AircraftMakeMove(int dt, aircraft_t* aircraft);
236 
237 void AIR_ParseAircraft(const char* name, const char** text, bool assignAircraftItems);
238 
239 bool AIR_AircraftHasEnoughFuel(const aircraft_t* aircraft, const vec2_t destination);
240 bool AIR_AircraftHasEnoughFuelOneWay(const aircraft_t* aircraft, const vec2_t destination);
241 
242 void AIR_AircraftReturnToBase(aircraft_t* aircraft);
243 bool AIR_SendAircraftToMission(aircraft_t* aircraft, struct mission_s* mission);
244 
245 void AIR_AircraftsNotifyMissionRemoved(const struct mission_s* mission);
246 void AIR_AircraftsNotifyUFORemoved(const aircraft_t* const ufo, bool destroyed);
247 
248 void AIR_GetDestinationWhilePursuing(const aircraft_t* shooter, const aircraft_t* target, vec2_t dest);
250 void AIR_AircraftsUFODisappear(const aircraft_t* const ufo);
251 bool AIR_ScriptSanityCheck(void);
252 int AIR_AircraftMenuStatsValues(const int value, const int stat);
253 int AIR_CountInBaseByTemplate(const struct base_s* base, const aircraft_t* aircraftTemplate);
254 
255 int AIR_GetAircraftWeaponRanges(const aircraftSlot_t* slot, int maxSlot, float* weaponRanges);
257 
258 const char* AIR_CheckMoveIntoNewHomebase(const aircraft_t* aircraft, const struct base_s* base);
259 void AIR_MoveAircraftIntoNewHomebase(aircraft_t* aircraft, struct base_s* base);
260 
261 void AII_CollectItem(aircraft_t* aircraft, const objDef_t* item, int amount);
262 void AII_CollectingItems(aircraft_t* aircraft, int won);
263 
264 bool AIR_SetPilot(aircraft_t* aircraft, class Employee* pilot);
265 Employee* AIR_GetPilot(const aircraft_t* aircraft);
266 
267 bool AIR_PilotSurvivedCrash(const aircraft_t* aircraft);
268 
269 bool AIR_AddEmployee(Employee* employee, aircraft_t* aircraft);
270 void AIR_RemoveEmployees(aircraft_t& aircraft);
271 bool AIR_RemoveEmployee(Employee* employee, aircraft_t* aircraft);
272 
273 const aircraft_t* AIR_IsEmployeeInAircraft(const class Employee* employee, const aircraft_t* aircraft);
274 
275 void AIR_AutoAddPilotToAircraft(const struct base_s* base, class Employee* pilot);
276 void AIR_RemovePilotFromAssignedAircraft(const struct base_s* base, const class Employee* pilot);
277 
278 void AIR_MoveEmployeeInventoryIntoStorage(const aircraft_t& aircraft, equipDef_t& equip);
279 
280 void AIR_AssignInitial(aircraft_t* aircraft);
281 
282 bool AIR_CanIntercept(const aircraft_t* aircraft);
283 
284 int AIR_GetOperationRange(const aircraft_t* aircraft);
285 int AIR_GetRemainingRange(const aircraft_t* aircraft);
286 
287 void AIR_InitStartup(void);
288 void AIR_Shutdown(void);
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.
struct base_s * homebase
Definition: cp_aircraft.h:150
aircraftStatus_t status
Definition: cp_aircraft.h:126
#define LINE_MAXPTS
Definition: cp_aircraft.h:33
itemPos_t pos
Definition: cp_aircraft.h:95
aircraft_t * AIR_Add(struct base_s *base, const aircraft_t *aircraftTemplate)
baseCapacities_t AIR_GetHangarCapacityType(const aircraft_t *aircraft)
Returns capacity type needed for an aircraft.
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
const char * building
Definition: cp_aircraft.h:151
int detectionIdx
Definition: cp_aircraft.h:174
int maxWeapons
Definition: cp_aircraft.h:145
A path on the map described by 2D points.
Definition: cp_aircraft.h:39
char * id
Definition: cp_aircraft.h:120
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...
short ufoType_t
Definition: scripts.h:145
char * image
Definition: cp_aircraft.h:123
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.
Class describing a point of time.
Definition: DateTime.h:30
char * model
Definition: cp_aircraft.h:124
const objDef_t * ammo
Definition: cp_aircraft.h:86
float distance
Definition: cp_aircraft.h:41
bool AIR_RemoveEmployee(Employee *employee, aircraft_t *aircraft)
Removes a soldier from an aircraft.
ufoType_t ufotype
Definition: cp_aircraft.h:125
bool notOnGeoscape
Definition: cp_aircraft.h:171
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)
int installationTime
Definition: cp_aircraft.h:90
int AIR_GetRemainingRange(const aircraft_t *aircraft)
Calculates the remaining range the aircraft can fly.
void AIR_AutoAddPilotToAircraft(const struct base_s *base, class Employee *pilot)
struct installation_s * installation
Definition: cp_aircraft.h:81
vec3_t projectedPos
Definition: cp_aircraft.h:134
int maxElectronics
Definition: cp_aircraft.h:148
void AIR_AircraftsNotifyMissionRemoved(const struct mission_s *mission)
bool AIR_AddEmployee(Employee *employee, aircraft_t *aircraft)
Assigns a soldier to an aircraft.
struct base_s * base
Definition: cp_aircraft.h:80
char * defaultName
Definition: cp_aircraft.h:122
void AIR_DeleteAircraft(aircraft_t *aircraft)
Removes an aircraft from its base and the game.
mapline_t route
Definition: cp_aircraft.h:135
int ufoInterestOnGeoscape
Definition: cp_aircraft.h:172
void AIR_AssignInitial(aircraft_t *aircraft)
Assigns initial team of soldiers to aircraft.
void AIR_InitStartup(void)
Init actions for aircraft-subsystem.
#define MAX_VAR
Definition: shared.h:36
Item cargo class.
Definition: itemcargo.h:41
const objDef_t * nextAmmo
Definition: cp_aircraft.h:94
void AII_CollectItem(aircraft_t *aircraft, const objDef_t *item, int amount)
Add an item to aircraft inventory.
struct aircraft_s * aircraft
Definition: cp_aircraft.h:82
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.
itemWeight_t size
Definition: cp_aircraft.h:87
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 * tpl
Definition: cp_aircraft.h:119
class AlienCargo * alienCargo
Definition: cp_aircraft.h:177
vec3_t pos
Definition: cp_aircraft.h:132
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)
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.
linkedList_t * acTeam
Definition: cp_aircraft.h:140
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 setUfoType(ufoType_t ufoT)
Definition: cp_aircraft.h:183
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)
ufoType_t getUfoType() const
Definition: cp_aircraft.h:180
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)
QGL_EXTERN GLuint index
Definition: r_gl.h:110
void AIR_MoveAircraftIntoNewHomebase(aircraft_t *aircraft, struct base_s *base)
baseCapacities_t
All possible capacities in base.
Definition: cp_capacity.h:27
class Employee * pilot
Definition: cp_aircraft.h:142
An aircraft with all it's data.
Definition: cp_aircraft.h:115
struct technology_s * tech
Definition: cp_aircraft.h:163
void AIR_ResetAircraftTeam(aircraft_t *aircraft)
Resets team in given aircraft.
struct mission_s * mission
Definition: cp_aircraft.h:153
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.
static hudRadar_t radar
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:75
aircraftSlot_t shield
Definition: cp_aircraft.h:146
bool AIR_Delete(struct base_s *base, aircraft_t *aircraft)
bool AIR_IsAircraftInBase(const aircraft_t *aircraft)
Checks whether given aircraft is in its homebase.
bool AIR_SendAircraftToMission(aircraft_t *aircraft, struct mission_s *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
vec3_t direction
Definition: cp_aircraft.h:133
int maxTeamSize
Definition: cp_aircraft.h:139
bool AIR_SetPilot(aircraft_t *aircraft, class Employee *pilot)
Assign a pilot to an aircraft.
vec_t vec3_t[3]
Definition: ufotypes.h:39
char * missionID
Definition: cp_aircraft.h:155
vec_t vec2_t[2]
Definition: ufotypes.h:38
linkedList_t * missionTypes
Definition: cp_aircraft.h:173
slot of aircraft
Definition: cp_aircraft.h:78
const char * AIR_AircraftStatusToName(const aircraft_t *aircraft)
Translates the aircraft status id to a translatable string.
bool AIR_AddToAircraftTeam(aircraft_t *aircraft, class Employee *employee)
Adds given employee to given aircraft.
const aircraft_t * AIR_GetAircraftSilent(const char *name)
Searches the global array of aircraft types for a given aircraft.
int numPoints
Definition: cp_aircraft.h:40
struct aircraft_s * aircraftTarget
Definition: cp_aircraft.h:157
void AIR_ParseAircraft(const char *name, const char **text, bool assignAircraftItems)
Parses all aircraft that are defined in our UFO-scripts.
const objDef_t * item
Definition: cp_aircraft.h:85
itemPos_t
different positions for aircraft items
Definition: cp_aircraft.h:55
int AIR_CountInBaseByTemplate(const struct base_s *base, const aircraft_t *aircraftTemplate)
aircraftStatus_t
Definition: cp_aircraft.h:99
void AIR_CampaignRun(const struct campaign_s *campaign, int dt, bool updateRadarOverlay)
const aircraft_t * AIR_IsEmployeeInAircraft(const class Employee *employee, const aircraft_t *aircraft)
int productionCost
Definition: cp_aircraft.h:129
bool AIR_BaseHasAircraft(const struct base_s *base)
class ItemCargo * itemCargo
Definition: cp_aircraft.h:178
aircraftItemType_t type
Definition: cp_aircraft.h:83
const objDef_t * nextItem
Definition: cp_aircraft.h:92
itemWeight_t
different weight for aircraft items
Definition: cp_aircraft.h:48
aircraft_notifications_t
notification signals for aircraft events
Definition: cp_aircraft.h:69
bool detected
Definition: cp_aircraft.h:167