1 /**
2  * @file
3  * @brief Header file for Transfer 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 
26 #pragma once
27 
28 struct transferData_s;
29 
30 typedef enum {
31 	CARGO_TYPE_INVALID = 0,
32 	CARGO_TYPE_ITEM,
33 	CARGO_TYPE_EMPLOYEE,
34 	CARGO_TYPE_ALIEN_DEAD,
35 	CARGO_TYPE_ALIEN_ALIVE,
36 	CARGO_TYPE_AIRCRAFT
37 } transferCargoType_t;
38 
39 enum {
40 	TRANS_ALIEN_ALIVE,
41 	TRANS_ALIEN_DEAD,
42 
43 	TRANS_ALIEN_MAX
44 };
45 
46 /** @brief Transfer informations (they are being stored in ccs.transfers). */
47 typedef struct transfer_s {
48 	base_t* destBase;				/**< Pointer to destination base. May not be nullptr if active is true. */
49 	base_t* srcBase;				/**< Pointer to source base. May be nullptr if transfer comes from a mission (alien body recovery). */
50 	date_t event;					/**< When the transfer finish process should start. */
51 
52 	int itemAmount[MAX_OBJDEFS];			/**< Amount of given item. */
53 	class AlienCargo* alienCargo;			/**< Alien cargo */
54 	linkedList_t* employees[MAX_EMPL];
55 	linkedList_t* aircraft;
56 
57 	bool hasItems;				/**< Transfer of items. */
58 	bool hasEmployees;			/**< Transfer of employees. */
59 	bool hasAircraft;			/**< Transfer of aircraft. */
60 } transfer_t;
61 
62 /**
63  * @brief transfer types
64  */
65 typedef enum {
66 	TRANS_TYPE_INVALID = -1,
67 	TRANS_TYPE_ITEM,
68 	TRANS_TYPE_EMPLOYEE,
69 	TRANS_TYPE_ALIEN,
70 	TRANS_TYPE_AIRCRAFT,
71 
72 	TRANS_TYPE_MAX
73 } transferType_t;
74 
75 /** @brief Array of current cargo onboard. */
76 typedef struct transferCargo_s {
77 	union transferItem_t {
78 		const objDef_t* item;
79 		const aircraft_t* aircraft;
80 		const Employee* employee;
81 		const teamDef_t* alienTeam;
82 		const void* pointer;		/**< if you just wanna check whether a valid pointer was set */
83 	} data;
84 	transferCargoType_t type;			/**< Type of cargo (1 - items, 2 - employees, 3 - alien bodies, 4 - live aliens). */
85 } transferCargo_t;
86 
87 typedef struct transferData_s {
88 	/** @brief Current selected aircraft for transfer (if transfer started from mission). */
89 	aircraft_t* transferStartAircraft;
90 
91 	/** @brief Current selected base for transfer. */
92 	base_t* transferBase;
93 
94 	/** @brief Current transfer type (item, employee, alien, aircraft). */
95 	transferType_t currentTransferType;
96 
97 	/** @brief Current cargo onboard. */
98 	transferCargo_t cargo[MAX_CARGO];
99 
100 	/** @brief Current item cargo. Amount of items for each object definition index. */
101 	int trItemsTmp[MAX_OBJDEFS];
102 
103 	/** @brief Current alien cargo. */
104 	class AlienCargo* alienCargo;
105 
106 	/** @brief Current personnel cargo. */
107 	linkedList_t* trEmployeesTmp[MAX_EMPL];
108 
109 	/** @brief Current aircraft for transfer. */
110 	linkedList_t* aircraft;
111 
112 	/** @brief Current cargo type count (updated in TR_CargoList) */
113 	int trCargoCountTmp;
114 } transferData_t;
115 
116 #define TR_SetData(dataPtr, typeVal, ptr)  do { (dataPtr)->data.pointer = (ptr); (dataPtr)->type = (typeVal); } while (0);
117 #define TR_Foreach(var) LIST_Foreach(ccs.transfers, transfer_t, var)
118 #define TR_ForeachEmployee(var, transfer, employeeType) LIST_Foreach(transfer->employees[employeeType], Employee, var)
119 #define TR_ForeachAircraft(var, transfer) LIST_Foreach(transfer->aircraft, aircraft_t, var)
120 
121 bool TR_AddData(transferData_t* transferData, transferCargoType_t type, const void* data);
122 void TR_TransferRun(void);
123 void TR_NotifyAircraftRemoved(const aircraft_t* aircraft);
124 
125 transfer_t* TR_TransferStart(base_t* srcBase, transferData_t &transData);
126 
127 void TR_InitStartup(void);
128 void TR_Shutdown(void);
129