Debian Codegraph @

Descent3/soar_helpers.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/soar_helpers.cpp $
21 * $Revision: 7 $
22 * $Date: 4/16/99 12:33a $
23 * $Author: Matt $
24 *
25 * Functions called by the Soar DLL
26 *
27 * $Log: /DescentIII/main/soar_helpers.cpp $
28 *
29 * 7 4/16/99 12:33a Matt
30 * Disable Soar on non-Windows systems.
31 *
32 */
33
34 #include "soar.h"cxx . . $ `<file>/Descent3/soar.h`/
35
36 #ifdef SOAR_ENABLED
37
38 #include "soar_helpers.h"
39
40 #include "object.h"
41 #include "vecmat.h"
42 #include "controls.h"
43 #include "weapon.h"
44 #include "room.h"
45 #include "terrain.h"
46 #include "player.h"
47 #include "gameloop.h"
48 #include "doorway.h"
49
50 bool DSGetHighestObjIndex(int &n) {
51 n = Highest_object_index;
52 return true;
53 }
54
55 bool DSGetObjSize(int n, float *size) {
56 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
57 return false;
58
59 *size = Objects[n].size;
60 return true;
61 }
62
63 bool DSGetObjMass(int n, float *mass) {
64 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
65 return false;
66
67 *mass = Objects[n].mtype.phys_info.mass;
68 return true;
69 }
70
71 bool DSGetObjShields(int n, float *shields) {
72 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
73 return false;
74
75 *shields = Objects[n].shields;
76 return true;
77 }
78
79 bool DSGetObjOrient(int n, matrix *m) {
80 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
81 return false;
82
83 *m = Objects[n].orient;
84 return true;
85 }
86
87 bool DSGetObjVelocity(int n, vector *vel) {
88 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
89 return false;
90
91 *vel = Objects[n].mtype.phys_info.velocity;
92 return true;
93 }
94
95 bool DSGetObjPos(int n, vector *pos) {
96 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
97 return false;
98
99 *pos = Objects[n].pos;
100 return true;
101 }
102
103 bool DSGetObjRoomNum(int n, int *roomnum) {
104 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
105 return false;
106
107 *roomnum = Objects[n].roomnum;
108 return true;
109 }
110
111 bool DSGetObjRotVelocity(int n, vector *rotvel) {
112 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
113 return false;
114
115 *rotvel = Objects[n].mtype.phys_info.rotvel;
116 return true;
117 }
118
119 bool DSGetObjType(int n, int *type) {
120 if (n < 0 || n > Highest_object_index)
121 return false;
122
123 *type = Objects[n].type;
124 return true;
125 }
126
127 bool DSGetObjId(int n, int *id) {
128 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
129 return false;
130
131 *id = Objects[n].id;
132 return true;
133 }
134
135 bool DSGetNextObjIndex(int n, int *next) {
136 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
137 return false;
138
139 *next = Objects[n].next;
140 return true;
141 }
142
143 bool DSGetPrevObjIndex(int n, int *prev) {
144 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
145 return false;
146
147 *prev = Objects[n].next;
148 return true;
149 }
150
151 bool DSSetControllerInfo(int n, game_controls *controls) {
152 object *objp;
153
154 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE || Objects[n].control_type != CT_SOAR)
155 return false;
156
157 objp = &Objects[n];
158
159 // Update object's physics
160 if (objp->movement_type == MT_PHYSICS) {
161 objp->mtype.phys_info.rotthrust.x = controls->pitch_thrust * objp->mtype.phys_info.full_rotthrust;
162 objp->mtype.phys_info.rotthrust.z = controls->bank_thrust * objp->mtype.phys_info.full_rotthrust;
163 objp->mtype.phys_info.rotthrust.y = controls->heading_thrust * objp->mtype.phys_info.full_rotthrust;
164 objp->mtype.phys_info.thrust = (objp->orient.fvec * controls->forward_thrust * objp->mtype.phys_info.full_thrust) +
165 (objp->orient.uvec * controls->vertical_thrust * objp->mtype.phys_info.full_thrust) +
166 (objp->orient.rvec * controls->sideways_thrust * objp->mtype.phys_info.full_thrust);
167 }
168
169 // Process weapon firing
170 FireWeaponFromPlayer(objp, PW_PRIMARY, controls->fire_primary_down_count, controls->fire_primary_down_state,
171 controls->fire_primary_down_time);
172 FireWeaponFromPlayer(objp, PW_SECONDARY, controls->fire_secondary_down_count, controls->fire_secondary_down_state,
173 controls->fire_secondary_down_time);
174
175 // Deal with the flare
176 for (int i = 0; i < controls->fire_flare_down_count; i++)
177 FireFlareFromPlayer(objp);
178
179 return true;
180 }
181
182 bool DSGetFirstRoomObject(int n, int *first) {
183 if (!ROOMNUM_OUTSIDE(n)) {
184 if (n < 0 || n > Highest_room_index || Rooms[n].used == 0)
185 return false;
186
187 *first = Rooms[n].objects;
188 } else {
189 int cell;
190
191 cell = CELLNUM(n);
192 if (cell < 0 && cell >= TERRAIN_WIDTH * TERRAIN_DEPTH)
193 return false;
194
195 *first = Terrain_seg[n].objects;
196 }
197
198 return true;
199 }
200
201 bool DSPauseGame(void) {
202 PauseGame();
203
204 return true;
205 }
206
207 bool DSResumeGame(void) {
208 ResumeGame();
209
210 return true;
211 }
212
213 bool DSGetObjAABB(int n, vector *min_xyz, vector *max_xyz) {
214 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
215 return false;
216
217 *min_xyz = Objects[n].min_xyz;
218 *max_xyz = Objects[n].max_xyz;
219
220 return true;
221 }
222
223 // CHRISHACK -- THIS WEAPON STUFF SUCKS. The current weapon slots are from 0 to 9.
224 // slots 0 - 4 are primaries (mapped twice for a total of 10 primaries (weapons 0 - 9))
225 // Note: Weapon 0 and 5 use slot 0, weapon 1 and 6 use slot 1, etc.
226 // slots 5 - 9 are secondaries (mapped twice for a total of 10 secondaries (weapons 10 - 19))
227 // if you currently are using the lower mapping, and you call the function with that slot
228 // number, you use the higher mapping. If available at that slot, it selects that one
229 bool DSSelectCurrentWeapon(int n) {
230 if (n < 0 || n > 9)
231 return false;
232
233 SelectWeapon(n);
234 return true;
235 }
236
237 // These are from 0 to 9
238 bool DSGetCurrentPrimary(int *n) {
239 *n = Players[Player_num].weapon[PW_PRIMARY].index;
240 return true;
241 }
242
243 // These are from 10 to 19
244 bool DSGetCurrentSecondary(int *n) {
245 *n = Players[Player_num].weapon[PW_SECONDARY].index;
246 return true;
247 }
248
249 // Bit field using the first 20 bits. If set, that weapon is available
250 bool DSGetAvailableWeapons(int *flags) {
251 *flags = Players[Player_num].weapon_flags;
252
253 return true;
254 }
255
256 bool DSGetNumRoomPortals(int n, int *num_portals) {
257 if (n < 0 || n > Highest_room_index || Rooms[n].used == 0)
258 return false;
259
260 *num_portals = Rooms[n].num_portals;
261
262 return true;
263 }
264
265 bool DSGetRoomPortalConnectRoom(int n, int p, int *connect_room) {
266 if (n < 0 || n > Highest_room_index || Rooms[n].used == 0)
267 return false;
268 if (p < 0 || p >= Rooms[n].num_portals)
269 return false;
270
271 *connect_room = Rooms[n].portals[p].croom;
272
273 return true;
274 }
275
276 bool DSIsObjDestroyable(int n, bool *f_is_destroyable) {
277 if (n < 0 || n > Highest_object_index || Objects[n].type == OBJ_NONE)
278 return false;
279
280 *f_is_destroyable = (Objects[n].flags & OF_DESTROYABLE) != 0;
281
282 return true;
283 }
284
285 bool DSIsDoorOpenable(int n, int *is_openable) {
286 if (n < 0 || n > Highest_object_index || Objects[n].type != OBJ_DOOR)
287 return false;
288 *is_openable = !DoorwayLocked(Objects[n].handle);
289 return true;
290 }
291
292 // doorway state
293 // #define DOORWAY_CLOSED 0 // door is closed
294 // #define DOORWAY_OPENING 1 // door is opening
295 // #define DOORWAY_WAITING 2 // door is waiting to be closed
296 // #define DOORWAY_CLOSING 3 // door is closing
297 // #define DOORWAY_OPEN 4 // door is open, that's it.
298
299 bool DSGetDoorStatus(int n, int *status) {
300 if (n < 0 || n > Highest_object_index || Objects[n].type != OBJ_DOOR)
301 return false;
302 *status = DoorwayState(Objects[n].handle);
303 return true;
304 }
305
306 void DSSoarInit() {
307 void *dsfunc[27];
308
309 dsfunc[0] = (void *)DSGetHighestObjIndex;
310 dsfunc[1] = (void *)DSGetObjSize;
311 dsfunc[2] = (void *)DSGetObjMass;
312 dsfunc[3] = (void *)DSGetObjShields;
313 dsfunc[4] = (void *)DSGetObjPos;
314 dsfunc[5] = (void *)DSGetObjOrient;
315 dsfunc[6] = (void *)DSGetObjVelocity;
316 dsfunc[7] = (void *)DSGetObjRotVelocity;
317 dsfunc[8] = (void *)DSGetObjRoomNum;
318 dsfunc[9] = (void *)DSGetObjType;
319 dsfunc[10] = (void *)DSGetObjId;
320 dsfunc[11] = (void *)DSGetNextObjIndex;
321 dsfunc[12] = (void *)DSGetPrevObjIndex;
322 dsfunc[13] = (void *)DSSetControllerInfo;
323 dsfunc[14] = (void *)DSGetFirstRoomObject;
324 dsfunc[15] = (void *)DSPauseGame;
325 dsfunc[16] = (void *)DSResumeGame;
326 dsfunc[17] = (void *)DSGetObjAABB;
327 dsfunc[18] = (void *)DSSelectCurrentWeapon;
328 dsfunc[19] = (void *)DSGetCurrentPrimary;
329 dsfunc[20] = (void *)DSGetCurrentSecondary;
330 dsfunc[21] = (void *)DSGetAvailableWeapons;
331 dsfunc[22] = (void *)DSGetNumRoomPortals;
332 dsfunc[23] = (void *)DSGetRoomPortalConnectRoom;
333 dsfunc[24] = (void *)DSIsObjDestroyable;
334 dsfunc[25] = (void *)DSIsDoorOpenable;
335 dsfunc[26] = (void *)DSGetDoorStatus;
336
337 SoarInit((void *)Terrain_seg, sizeof(Terrain_seg[0]), (void *)Rooms, sizeof(Rooms[0]), (void *)Objects,
338 sizeof(Objects[0]), (void *)dsfunc);
339
340 Soar_active = true;
341 }
342
343 void DSSoarEnd() {
344 SoarEnd();
345 Soar_active = false;
346 }
347
348 #endif // ifdef SOAR_ENABLED