Debian Codegraph @

Descent3/ship.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/ship.cpp $
21 * $Revision: 19 $
22 * $Date: 5/13/99 3:42p $
23 * $Author: Ardussi $
24 *
25 * $Log: /DescentIII/Main/ship.cpp $
26 *
27 * 19 5/13/99 3:42p Ardussi
28 * changes for compiling on the Mac
29 *
30 * 18 5/12/99 1:57p Jason
31 * fixed yet more buggy/ugly code
32 *
33 * 17 4/11/99 4:46p Matt
34 * Small fixes
35 *
36 * 16 4/11/99 3:04p Matt
37 * Reduced the max number of player ships from 30 to 5.
38 * Re-wrote the static ship name code to be more space efficient.
39 * Took default ship name (the one used to find the ship) out of string
40 * table.
41 *
42 * 15 2/17/99 10:32a Matt
43 * Init physics hit_die_dot for new items
44 *
45 * 14 10/08/98 10:28p Jason
46 * more demo changes for ship
47 *
48 * 13 10/02/98 1:47p Jason
49 * added lod player ships
50 *
51 * 12 8/07/98 2:43p Jeff
52 * flags gets cleared and initialized correctly
53 *
54 * 11 7/31/98 5:23p Jason
55 * added ship armor scalars
56 *
57 * 10 6/15/98 4:00p Jason
58 * replaced monochromatic polymodel lighting with rgb lighting
59 *
60 * 9 4/30/98 11:32a Chris
61 * ClearWB to WBClear
62 *
63 * 8 4/02/98 3:54p Jason
64 * first pass in getting polymodel paging to work
65 *
66 * 7 2/17/98 8:12p Matt
67 * Added looping & release sounds for player weapons
68 *
69 * 6 11/04/97 6:18p Chris
70 * Added support so that the player ship uses the robot's firing dialog.
71 *
72 * 5 10/21/97 11:57a Jason
73 * added ability to set dying model for player ship
74 *
75 * 4 10/20/97 4:46p Jason
76 * changes for explosions
77 *
78 * 3 9/09/97 7:02p Jason
79 * don't reload the models during the remap phase
80 *
81 * 2 8/06/97 12:40p Jason
82 * fixed some potentially serious memory problems
83 *
84 * 6 4/07/97 3:17p Chris
85 * Incremental improvement
86 *
87 * 5 4/07/97 3:13p Chris
88 *
89 * 4 4/02/97 5:21p Jason
90 * added the ability for pages to free the models that they point to
91 *
92 * 3 4/02/97 4:04p Jason
93 * made ships remap properly
94 *
95 * 2 3/31/97 4:34p Jason
96 * added player ship page
97 *
98 * 1 3/31/97 12:21p Jason
99 *
100 * $NoKeywords: $
101 */
102
103 #include "ship.h"cxx . . $ `<file>/Descent3/ship.h`/
104 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
105 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
106 #include "object.h"cxx . . $ `<file>/Descent3/object.h`/
107 #include "3d.h"cxx . . $ `<file>/lib/3d.h`/
108 #include <stdlib.h>
109 #include <stdio.h>
110 #include <stdarg.h>
111 #include <string.h>
112 #include "polymodel.h"cxx . . $ `<file>/model/polymodel.h`/
113 #include "player.h"cxx . . $ `<file>/Descent3/player.h`/
114 #include "robotfire.h"cxx . . $ `<file>/Descent3/robotfire.h`/
115
116 #define DEFAULT_SHIP_SIZEcxx . . $ `Descent3/ship.cpp:116:9`! 4.0
117
118 shipcxx . . $ ship# Shipscxx . . $ Ships.[MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!];
119 int Num_shipscxx . . $ Num_ships. = 0;
120
121 // There are no static ships
122 char *Static_ship_namescxx . . $ Static_ship_names.[1];
123 #define NUM_STATIC_SHIPScxx . . $ `Descent3/ship.cpp:123:9`! 0
124
125 #define SHIP_PYRO_IDcxx . . $ `Descent3/ship.cpp:125:9`! 0
126 #define SHIP_PHOENIX_IDcxx . . $ `Descent3/ship.cpp:126:9`! 1
127 #define SHIP_MAGNUM_IDcxx . . $ `Descent3/ship.cpp:127:9`! 2
128
129 const char *AllowedShipscxx . . $ AllowedShips.[MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!] = {"Pyro-GL", "Phoenix", "Magnum-AHT"};
130
131 // Sets all ships to unused
132 void InitShipscxx . . $ InitShips(49f6e7a06ebc5aa8).() {
133 for (int i = 0; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++) {
134 memset(&Shipscxx . . $ Ships.[i], 0, sizeof(shipcxx . . $ ship#));
135 }
136 Num_shipscxx . . $ Num_ships. = 0;
137 }
138
139 // Allocs a ship for use, returns -1 if error, else index on success
140 int AllocShipcxx . . $ AllocShip(b126dc7c1de90089).() {
141 for (int i = 0; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++) {
142 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used. == 0) {
143 memset(&Shipscxx . . $ Ships.[i], 0, sizeof(shipcxx . . $ ship#));
144 Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used. = 1;
145 Shipscxx . . $ Ships.[i].sizecxx . . $ ship#size. = DEFAULT_SHIP_SIZEcxx . . $ `Descent3/ship.cpp:116:9`!;
146 Shipscxx . . $ Ships.[i].dying_model_handlecxx . . $ ship#dying_model_handle. = -1;
147 Shipscxx . . $ Ships.[i].med_render_handlecxx . . $ ship#med_render_handle. = -1;
148 Shipscxx . . $ Ships.[i].lo_render_handlecxx . . $ ship#lo_render_handle. = -1;
149 Shipscxx . . $ Ships.[i].med_lod_distancecxx . . $ ship#med_lod_distance. = DEFAULT_MED_LOD_DISTANCEcxx . . $ `Descent3/objinfo.h:349:9`!;
150 Shipscxx . . $ Ships.[i].lo_lod_distancecxx . . $ ship#lo_lod_distance. = DEFAULT_LO_LOD_DISTANCEcxx . . $ `Descent3/objinfo.h:350:9`!;
151 Shipscxx . . $ Ships.[i].model_handlecxx . . $ ship#model_handle. = -1;
152 Shipscxx . . $ Ships.[i].armor_scalarcxx . . $ ship#armor_scalar. = 1.0;
153 Shipscxx . . $ Ships.[i].flagscxx . . $ ship#flags. = 0;
154
155 Shipscxx . . $ Ships.[i].phys_infocxx . . $ ship#phys_info..hit_die_dotcxx . . $ physics_info#$anonymous_type_5#hit_die_dot. = -1; //-1 mean doesn't apply
156
157 // Make sure the weapon battery info is cleared for a new object
158 WBClearInfocxx . . $ WBClearInfo(35337aada7327cb).(Shipscxx . . $ Ships.[i].static_wbcxx . . $ ship#static_wb.);
159
160 for (int w = 0; w < MAX_PLAYER_WEAPONScxx . . $ `Descent3/player_external_struct.h:91:9`!; w++) {
161 Shipscxx . . $ Ships.[i].firing_soundcxx . . $ ship#firing_sound.[w] = -1;
162 // Ships[i].release_sound[w] = -1;
163 }
164
165 Num_shipscxx . . $ Num_ships.++;
166 return i;
167 }
168 }
169
170 Int3cxx . . $ `misc/pserror.h:247:9`!(); // No ships free!
171 return -1;
172 }
173
174 // Frees ship index n
175 void FreeShipcxx . . $ FreeShip(d4f767463ce0a6b3).(int n) {
176 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Ships[n].used > 0);
177
178 Shipscxx . . $ Ships.[n].usedcxx . . $ ship#used. = 0;
179 Shipscxx . . $ Ships.[n].namecxx . . $ ship#name.[0] = 0;
180 Num_shipscxx . . $ Num_ships.--;
181 }
182
183 // Gets next ship from n that has actually been alloced
184 int GetNextShipcxx . . $ GetNextShip(7864480464b09eea).(int n) {
185 int i;
186
187 if (Num_shipscxx . . $ Num_ships. == 0)
188 return -1;
189
190 if ((n < 0) || (n >= MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!))
191 n = -1;
192
193 for (i = n + 1; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++)
194 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.)
195 return i;
196 for (i = 0; i < n; i++)
197 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.)
198 return i;
199
200 // this is the only one
201
202 return n;
203 }
204
205 // Gets previous ship from n that has actually been alloced
206 int GetPrevShipcxx . . $ GetPrevShip(7864480464b09eea).(int n) {
207 int i;
208
209 if (Num_shipscxx . . $ Num_ships. == 0)
210 return -1;
211
212 if ((n < 0) || (n >= MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!))
213 n = MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!;
214
215 for (i = n - 1; i >= 0; i--) {
216 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.)
217 return i;
218 }
219 for (i = MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`! - 1; i > n; i--) {
220 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.)
221 return i;
222 }
223
224 // this is the only one
225 return n;
226 }
227 // Searches thru all ships for a specific name, returns -1 if not found
228 // or index of ship with name
229 int FindShipNamecxx . . $ FindShipName(5c4306d8553b3696).(const char *name) {
230 int i;
231
232 ASSERTcxx . . $ `misc/pserror.h:246:9`!(name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
233
234 for (i = 0; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++)
235 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(name, Ships[i].name))
236 return i;
237
238 return -1;
239 }
240
241 int LoadShipImagecxx . . $ LoadShipImage(5c4306d8553b3696).(const char *filename) {
242 int img_handle;
243
244 img_handle = LoadPolyModelcxx . . $ LoadPolyModel(220e687f58daa9be).(filenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., 1);
245
246 return img_handle;
247 }
248
249 // Given a ship handle, returns an index to that ships model
250 int GetShipImagecxx . . $ GetShipImage(7864480464b09eea).(int handle) {
251 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Ships[handle].used > 0);
252
253 return (Shipscxx . . $ Ships.[handle].model_handlecxx . . $ ship#model_handle.);
254 }
255
256 // This is a very confusing function. It takes all the ships that we have loaded
257 // and remaps then into their proper places (if they are static).
258 void RemapShipscxx . . $ RemapShips(49f6e7a06ebc5aa8).() {
259 int i;
260
261 // Loop through the static ships and move them to the correct slots
262 for (i = 0; i < NUM_STATIC_SHIPScxx . . $ `Descent3/ship.cpp:123:9`!; i++) {
263
264 int cur_index = FindShipNamecxx . . $ FindShipName(5c4306d8553b3696).(Static_ship_namescxx . . $ Static_ship_names.[i]);
265
266 if (cur_index == -1) {
267 Int3cxx . . $ `misc/pserror.h:247:9`!(); // couldn't find statically-mapped ship
268 continue;
269 }
270
271 if (cur_index != i) { // not in right slot
272
273 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.) { // someone else in this slot, so swap
274 shipcxx . . $ ship# tship = Shipscxx . . $ Ships.[i];
275 Shipscxx . . $ Ships.[i] =cxx . . $ ship#`operator=`(5a0bc11e4f873f56). Shipscxx . . $ Ships.[cur_index];
276 Shipscxx . . $ Ships.[cur_index] =cxx . . $ ship#`operator=`(5a0bc11e4f873f56). tship;
277 RemapAllShipObjectscxx . . $ RemapAllShipObjects(3e454b8ccf442868).(i, MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!);
278 RemapAllShipObjectscxx . . $ RemapAllShipObjects(3e454b8ccf442868).(cur_index, i);
279 RemapAllShipObjectscxx . . $ RemapAllShipObjects(3e454b8ccf442868).(MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!, cur_index);
280 } else { // slot is unused, so just take it
281 Shipscxx . . $ Ships.[i] =cxx . . $ ship#`operator=`(5a0bc11e4f873f56). Shipscxx . . $ Ships.[cur_index];
282 Shipscxx . . $ Ships.[cur_index].usedcxx . . $ ship#used. = 0;
283 RemapAllShipObjectscxx . . $ RemapAllShipObjects(3e454b8ccf442868).(cur_index, i);
284 }
285 }
286 }
287
288 // Now, if any ships are polygon models and those models don't have correct
289 // textures, attempt to reload the model texture list
290 for (i = 0; i < MAX_SHIPScxx . . $ `Descent3/ship.h:122:9`!; i++) {
291 if (Shipscxx . . $ Ships.[i].usedcxx . . $ ship#used.) {
292 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Ships[i].model_handle != -1);
293 // LoadPolyModel (Poly_models[Ships[i].model_handle].name);
294 }
295 }
296 }
297
298 // goes thru every entity that could possible have a ship index
299 // and changes the old index to the new index
300 void RemapAllShipObjectscxx . . $ RemapAllShipObjects(3e454b8ccf442868).(int old_index, int new_index) {
301 for (int i = 0; i < MAX_OBJECTScxx . . $ `lib/object_external_struct.h:107:9`!; i++) {
302 if (Objectscxx . . $ Objects.[i].typecxx . . $ object#type. == OBJ_PLAYERcxx . . $ `Descent3/object_external.h:164:9`!) {
303 if (Playerscxx . . $ Players.[Objectscxx . . $ Objects.[i].idcxx . . $ object#id.].ship_indexcxx . . $ player#ship_index. == old_index)
304 Playerscxx . . $ Players.[Objectscxx . . $ Objects.[i].idcxx . . $ object#id.].ship_indexcxx . . $ player#ship_index. = new_index;
305 }
306 }
307 }