Debian Codegraph @

Descent3/weapon.h

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/weapon.h $
21 * $Revision: 87 $
22 * $Date: 4/12/99 12:49p $
23 * $Author: Jeff $
24 *
25 * Header for weapon.cpp & weaponfire.cpp
26 *
27 * $Log: /DescentIII/main/weapon.h $
28 *
29 * 87 4/12/99 12:49p Jeff
30 * added recoil_force to weapon's page
31 *
32 * 86 4/05/99 4:39p Jason
33 * added groovy new smoke trails
34 *
35 * 85 3/31/99 10:27a Samir
36 * code to reset auto select states when ship is initializiaed and code to
37 * save and load these states from disk.
38 *
39 * 84 3/05/99 12:19p Matt
40 * Delete now-unused function AddWeaponAmmoToPlayer()
41 *
42 * 83 3/03/99 5:09p Samir
43 * AddWeaponAmmoToPlayer added.
44 *
45 * 82 3/02/99 7:22p Chris
46 * Add the 'fire at target' check box for weapon batteries
47 *
48 * 81 2/22/99 2:05p Jason
49 * added different damages for players and generics
50 *
51 * 80 2/08/99 5:29p Jason
52 * added more weapon options
53 *
54 * 79 1/25/99 7:43a Chris
55 * Added the GUID (Goal Unique Id) and added the ability for weapon
56 * batteries to always fire exactly forward.
57 *
58 * 78 1/11/99 2:14p Chris
59 * Massive work on OSIRIS and AI
60 *
61 * 77 11/13/98 12:30p Jason
62 * changes for weapons
63 *
64 * 76 10/22/98 2:41p Samir
65 * fixed autoselection for good.
66 *
67 * 75 10/21/98 11:52p Samir
68 * print different message if autoselecting a recently acquired weapon.
69 *
70 * 74 10/15/98 6:46p Chris
71 * Added custom size for weapons
72 *
73 * 73 10/07/98 9:36p Samir
74 * added a function to switch a player's weapon to another in the given
75 * weapon class.
76 *
77 * 72 10/01/98 6:56p Jason
78 * turned off energy weapon hit effects if the object getting hit is the
79 * viewer - this helps cut down on the general clutter in heavy combat
80 *
81 * 71 9/30/98 4:31p Samir
82 * added functions to handle weapon select list.
83 *
84 * 70 9/28/98 10:43a Chris
85 * Fixed a bug with HAS_FLAG
86 *
87 * 69 9/10/98 5:56p Chris
88 * Added more shit to the matcen code :)
89 *
90 * 68 9/08/98 5:35p Jason
91 * added WF_NO_ROTATE flag to weapons
92 *
93 * 67 9/01/98 4:41p Matt
94 * Removed obsolete fields in the weapon structure
95 *
96 * 66 8/31/98 1:35p Keneta
97 * Made some use count unsigned shorts
98 *
99 * 65 8/31/98 11:15a Keneta
100 * Upp'ed max weapons
101 *
102 * 64 8/19/98 2:48p Jason
103 * fixed some weapon firing and weapon exploding bugs
104 *
105 * 63 8/06/98 1:00p Chris
106 * Added new homing flags
107 *
108 * 62 8/03/98 1:09p Jason
109 * added some more weapons flags
110 *
111 * 61 7/31/98 5:23p Jason
112 * added ship armor scalars
113 *
114 * 60 7/30/98 6:03p Jason
115 * (Jeff) checked in so we can compile...missing 2 WF_* flags
116 *
117 * 59 7/30/98 11:09a Jason
118 * added weapons that freeze and deform terrain
119 *
120 * 58 7/06/98 11:52a Jason
121 * added countermeasure prototype
122 *
123 * 57 7/01/98 12:12p Jason
124 * added countermeasures
125 *
126 * 56 6/22/98 6:26p Jason
127 * added gravity field effect for weapons
128 *
129 * 55 6/19/98 12:04p Jason
130 *
131 * 54 6/16/98 10:54a Jeff
132 *
133 * 53 5/26/98 5:06p Samir
134 * changed name of weapon indices and added function to get weapon's icon
135 * image.
136 *
137 * 52 5/25/98 8:36p Matt
138 * Added code to set different sizes for different weapon scorch marks.
139 * Also, don't leave scorch marks on lights.
140 *
141 * 51 5/25/98 8:17p Matt
142 * Moved MAX_PLAYER_WEAPONS fromw weapon.h to player.h, so that the latter
143 * doesn't need to include the former, drastically speeding build times
144 * when weapon.h is changed.
145 *
146 * 50 5/25/98 6:39p Jason
147 * got icons working for weapons
148 *
149 * 49 5/22/98 12:34p Matt
150 * Added scorch mark/bullet hole system.
151 *
152 * 48 5/19/98 4:42a Chris
153 * Added shockwave's -- enjoy. :)
154 *
155 * 47 5/07/98 2:40p Chris
156 * Added death_dot and bounce sound for weapons
157 *
158 * 46 4/24/98 8:02a Samir
159 * added a int16_t weapon name array.
160 *
161 * 45 4/19/98 5:00p Jason
162 * added cool napalm effect, plus made object effects dynamically
163 * allocated
164 *
165 * 44 4/17/98 1:59p Jason
166 * added cool object effects
167 *
168 * 43 4/15/98 12:22p Jason
169 * lots of miscellaneous stuff pertaining to lighting and vis effects
170 *
171 * 42 4/10/98 2:16p Jason
172 * fixed guided missile problems
173 *
174 * 41 4/10/98 12:39p Jason
175 * added expanding explosion bitmaps
176 *
177 * 40 4/09/98 12:05p Chris
178 * Added parenting for all object types. :)
179 *
180 * 39 4/07/98 3:31p Jason
181 * got particle effects working with weapons
182 *
183 * 38 4/06/98 4:53p Jason
184 * got pageable polymodels working correctly with editor
185 *
186 * 37 2/17/98 11:32p Matt
187 * Fixed player wepon fire problem when down_count != 0 && down_time == 0
188 * Add function to clear out player firing activity for when die or switch
189 * weapons
190 *
191 */
192
193 #ifndef WEAPON_H
194 #define WEAPON_H
195
196 #include "pstypes.h"
197 #include "manage.h"
198 #include "object.h"
199 #include "objinfo.h"
200 #include "weapon_external.h"
201
202 #define MAX_PRIMARY_WEAPONS 10
203 #define MAX_SECONDARY_WEAPONS 10
204
205 #define MAX_WEAPON_NOT_HIT_PARENT_TIME 3.0f
206
207 // This can be changed safely
208 #define MAX_WEAPONS 200
209
210 // THIS CONSTANT SHOULD EQUAL THE NUMBER OF WEAPONS SELECTABLE!!!
211 #define MAX_STATIC_WEAPONS 21
212
213 #define DEFAULT_WEAPON_SIZE 1.0 // Default size of a weapon -- used for bitmap weapons
214
215 #define HAS_FLAG(a) (1 << (a))
216
217 // Weapon flags
218 #define WF_HUD_ANIMATED (1 << 0)
219 #define WF_IMAGE_BITMAP (1 << 1) // whether or not the firing image is a bitmap or model
220 #define WF_SMOKE (1 << 2) // Weapon drops smoke as it moves
221 #define WF_MATTER_WEAPON (1 << 3) // This a matter weapon, as opposed to an energy weapon
222 #define WF_ELECTRICAL (1 << 4) // This weapons fires as an electrical storm
223 #define WF_IMAGE_VCLIP (1 << 5) // This weapon fire image is a vclip
224 #define WF_SPRAY (1 << 6) // This weapon is a spray, like a flamethrower
225 #define WF_STREAMER (1 << 7) // This weapon has a streamer effect attached
226 #define WF_INVISIBLE (1 << 8) // This weapon is invisible
227 #define WF_RING (1 << 9) // This weapon is drawn ring style
228 #define WF_SATURATE (1 << 10) // Saturate this bitmap weapon
229 #define WF_BLAST_RING (1 << 11) // Creates a blast ring upon explosion
230 #define WF_PLANAR_BLAST (1 << 12) // Blast bitmap takes on the walls plane
231 #define WF_PLANAR (1 << 13) // This weapon doesn't always face you
232 #define WF_ENABLE_CAMERA (1 << 14) // This weapon can be used for missile camera
233 #define WF_SPAWNS_IMPACT (1 << 15) // This weapon spawns others on impact
234 #define WF_SPAWNS_TIMEOUT (1 << 16) // This weapon spawns others when it times out
235 #define WF_EXPAND (1 << 17) // This weapon expands when exploding
236 #define WF_MUZZLE (1 << 18) // This weapon produces a muzzle flash when fired
237 #define WF_MICROWAVE (1 << 19) // This weapon makes a microwave effect on the victim
238 #define WF_NAPALM (1 << 20) // This weapon does a napalm effect to objects it touches
239 #define WF_REVERSE_SMOKE (1 << 21) // The smoke trail gets smaller as it ages
240 #define WF_GRAVITY_FIELD (1 << 22) // This weapon has a gravity field
241 #define WF_COUNTERMEASURE (1 << 23) // This weapon is a countermeasure
242 #define WF_SPAWNS_ROBOT (1 << 24) // This weapon spawns a robot upon death
243 #define WF_FREEZE (1 << 25) // This weapon slows a ship/object down
244 #define WF_TIMEOUT_WALL (1 << 26) // This weapon times out like a wall hit
245 #define WF_PLANAR_SMOKE (1 << 27) // This weapon has a planar smoke trail instead of a blob
246 #define WF_SILENT_HOMING (1 << 28) // This weapon does not give a homing lock sound
247 #define WF_HOMING_SPLIT (1 << 29) // This weapon homes when it splits
248 #define WF_NO_ROTATE (1 << 30) // This weapon does not rotate as a bitmap
249 #define WF_CUSTOM_SIZE (1 << 31) // This weapon uses a custom size
250
251 #define MAX_LASER_LEVEL 4
252 #define MAX_SUPER_LASER_LEVEL 6
253
254 #define PRIMARY_INDEX 0
255 #define SECONDARY_INDEX 10
256
257 // These defines must correspond to the Static_weapons_names array
258
259 #define MAX_WEAPON_SOUNDS 7
260 #define WSI_FIRE \
261 0 // chrishack -- removed! Change const when we add a new slot
262 // grep for occurances of WSI_FIRE and fix (or remove) old code
263 #define WSI_IMPACT_WALL 1
264 #define WSI_FLYING 2
265 #define WSI_IMPACT_ROBOT 3
266 #define WSI_BOUNCE 4
267
268 struct weapon {
269 char name[PAGENAME_LEN];
270 float player_damage; // how much damage a full impact causes a player
271 float generic_damage; // how much damage a full impact causes a robot
272 float alpha; // What alpha to draw this weapon with
273 int16_t sounds[MAX_WEAPON_SOUNDS]; // sounds for various things
274 int16_t hud_image_handle; // a handle to a bitmap or vclip for the hud display
275 int16_t fire_image_handle; // model or bitmap. Shown when you fire this weapon
276 int16_t explode_image_handle; // exploding vclip
277 int16_t smoke_handle; // smoke trail handle to texture
278 int16_t spawn_handle; // weapon handle that gets spawned
279 int16_t alternate_spawn_handle; // weapon handle that gets spawned (sometimes)
280 int16_t robot_spawn_handle; // robot that gets spawned as a countermeasure
281 int16_t particle_handle; // particle handle to texture
282 int16_t icon_handle;
283 int16_t scorch_handle; // handle for scorch bitmap, or -1 for none
284 uint8_t spawn_count; // how many of spawn handle gets created
285 uint8_t alternate_chance; // how often the alternate spawn weapon gets chosen (0 to 100)
286
287 uint16_t used;
288
289 uint8_t particle_count;
290 uint8_t terrain_damage_depth;
291
292 float terrain_damage_size;
293
294 float scorch_size; // how big the scorch mark is
295
296 int flags; // see above
297
298 float size;
299 float life_time;
300 float thrust_time;
301 float impact_size;
302 float impact_time;
303 float impact_player_damage, impact_generic_damage;
304 float impact_force;
305 float explode_size;
306 float explode_time;
307 float particle_size;
308 float particle_life;
309 float gravity_size;
310 float gravity_time;
311 float custom_size;
312 float homing_fov;
313 float recoil_force;
314
315 light_info lighting_info;
316 physics_info phys_info;
317
318 };
319
320 struct fusion_effect {
321 float total_time;
322
323 };
324
325 extern float Primary_ramp_time, Secondary_ramp_time;
326
327 extern int Num_weapons;
328 extern weapon Weapons[MAX_WEAPONS];
329 extern const char *Static_weapon_names[];
330 extern int Static_weapon_names_msg[];
331 extern int Static_weapon_ckpt_names[][2];
332
333 // Sets all weapons to unused
334 void InitWeapons();
335
336 // Allocs a weapon for use, returns -1 if error, else index on success
337 int AllocWeapon();
338
339 // Frees weapon index n
340 void FreeWeapon(int n);
341
342 // Gets next weapon from n that has actually been alloced
343 int GetNextWeapon(int n);
344
345 // Gets previous weapon from n that has actually been alloced
346 int GetPrevWeapon(int n);
347
348 // Searches thru all weapons for a specific name, returns -1 if not found
349 // or index of weapon with name
350 int FindWeaponName(const char *name);
351
352 // Given a filename, loads either the model or vclip found in that file. If type
353 // is not NULL, sets it to 1 if file is model, otherwise sets it to zero
354 int LoadWeaponHudImage(char *filename, int *type);
355
356 // Given a weapon handle, returns that weapons image for framenum
357 int GetWeaponHudImage(int handle, int framenum);
358
359 // Given a filename, loads either the model or vclip found in that file. If type
360 // is not NULL, sets it to 1 if file is model, otherwise sets it to zero
361 int LoadWeaponFireImage(char *filename, int *type, int *anim, int pageable = 1);
362
363 // Given a weapon handle, returns that weapons firing bitmap/model
364 int GetWeaponFireImage(int handle, int frame);
365
366 // Given a weapon name, assigns that weapon to a specific index into
367 // the Weapons array. Returns -1 if the named weapon is not found, 0 if the weapon
368 // is already in its place, or 1 if successfully moved
369 int MatchWeaponToIndex(char *name, int dest_index);
370
371 // Moves a weapon from a given index into a new one (above MAX_STATIC_POWERUPS)
372 // returns new index
373 int MoveWeaponFromIndex(int index);
374
375 // This is a very confusing function. It takes all the weapons that we have loaded
376 // and remaps then into their proper places (if they are static).
377 void RemapWeapons();
378
379 // goes thru every entity that could possible have a weapon index (ie objects, weapons, etc)
380 // and changes the old index to the new index
381 void RemapAllWeaponObjects(int old_index, int new_index);
382
383 // Creates a weapon
384 // Returns the objnum of the weapon object
385 int CreateWeaponObject(int weapon_num, int segnum, vector *position, int flags);
386
387 // Creates an weapon and sends it speeding on its way
388 // returns the objnum of the weapon
389 int CreateAndFireWeapon(vector *pos, vector *dir, object *parent, int weapon_num);
390
391 // Given an object and a weapon, fires a shot from that object
392 // returns the object number of the weapon
393 int FireWeaponFromObject(object *obj, int weapon_num, int gun_num = -1, bool f_force_forward = false,
394 bool f_force_target = false);
395
396 // Draws a weapon
397 void DrawWeaponObject(object *obj);
398
399 // unconditionally adds a weapon and ammo to a player.
400 int AddWeaponToPlayer(int slot, int weap_index, int ammo);
401
402 // Called when a player dies or switches weapons to clear out any active weapon stuff
403 void ClearPlayerFiring(object *objp, int weapon_type);
404
405 // Fires a weapon from our player. Won't fire if ammo/energy requirements aren't met.
406 // Parameters: weapon_type - either PW_PRIMARY or PW_SECONDARY
407 void FireWeaponFromPlayer(object *objp, int weapon_type, int down_count, bool down_state, float down_time);
408
409 // Fires a flare from our player.
410 // It might make sense to combine this with FireWeaponFromPlayer(), or maybe not
411 void FireFlareFromPlayer(object *objp);
412
413 // Does per frame weapon code
414 void WeaponDoFrame(object *obj);
415
416 // Returns the position and the normal of a gun point
417 bool WeaponCalcGun(vector *gun_point, vector *gun_normal, object *obj, int gun_num);
418
419 // Checks for relation between weapons and other objects
420 extern bool ObjectsAreRelated(int o1, int o2);
421
422 // A quick way to see where a weapon hits. Weapons make debris.
423 void CreateWeaponDebris(object *obj);
424
425 // Selects a weapon
426 void SelectWeapon(int slot);
427
428 // automatically switches primary weapon to this value. and type.
429 int SwitchPlayerWeapon(int weapon_type);
430
431 // Auto selects a weapon, usually the next best weapon.
432 // weapon_type is either PW_PRIMARY or PW_SECONDARY
433 // if new_wpn != -1, then we will see if the current weapon is inferior, to new weapon. If
434 // it isn't, then the new weapon is selected.
435 // returns true if selecting new weapon, otherwise false.
436 bool AutoSelectWeapon(int weapon_type, int new_wpn = -1);
437
438 // is a weapon secondary or primary?
439 bool IsWeaponSecondary(int index);
440
441 // used for sequencing
442 // resets memory for what slots have high priority weapons (laser->super_laser, for instance) when user selects
443 void ResetWeaponSelectStates(uint16_t new_state = 0);
444
445 // save and load weapon state information
446 void SaveWeaponSelectStates(CFILE *fp);
447 void LoadWeaponSelectStates(CFILE *fp);
448
449 // Draws an alpha blended polygon over the entire 3d rendering scene
450 // The r,g,b floats specify the color
451 void DrawAlphaBlendedScreen(float r, float g, float b, float alpha);
452
453 // Does the weapon spray effect for an object
454 void DoSprayEffect(object *obj, otype_wb_info *static_wb, uint8_t wb_index);
455
456 // Plays the animation that accompanies a weapon death
457 void DoWeaponExploded(object *, vector *norm = NULL, vector *collision_point = NULL, object *hit_object = NULL);
458
459 void TimeoutWeapon(object *);
460
461 // Creates chidren from a dying weapon
462 void CreateImpactSpawnFromWeapon(object *obj, vector *norm);
463
464 // Releases the guided missile of a passed in player
465 void ReleaseGuidedMissile(int slot);
466
467 // Releases the user timeout of a passed in player
468 void ReleaseUserTimeoutMissile(int slot);
469
470 // Retreives the weapon in the weapon array based off of an 'index' from 0-19 (non-mapped
471 // primary and secondaries) (we need a ship too.)
472 weapon *GetWeaponFromIndex(int player, int index);
473
474 // Creates a robot as a countermeasure
475 void CreateRobotSpawnFromWeapon(object *obj);
476
477 // Given a parent object and a weapon id, creates that countermeasure
478 void CreateCountermeasureFromObject(object *parent, int weapon_id);
479
480 //////////////////////////////////////////////////////////////////////////////
481 const uint16_t WPNSEL_SKIP = 0x8000, WPNSEL_INVALID = 0xffff;
482
483 const uint16_t DefaultPrimarySelectList[MAX_PRIMARY_WEAPONS] = {
484 LASER_INDEX, VAUSS_INDEX, MICROWAVE_INDEX, PLASMA_INDEX, FUSION_INDEX,
485 SUPER_LASER_INDEX, MASSDRIVER_INDEX, NAPALM_INDEX, EMD_INDEX, OMEGA_INDEX};
486
487 const uint16_t DefaultSecondarySelectList[MAX_SECONDARY_WEAPONS] = {
488 CONCUSSION_INDEX, HOMING_INDEX, IMPACTMORTAR_INDEX, SMART_INDEX, MEGA_INDEX, FRAG_INDEX,
489 GUIDED_INDEX + WPNSEL_SKIP, NAPALMROCKET_INDEX, CYCLONE_INDEX, BLACKSHARK_INDEX};
490
491 // weapon auto selection info.
492 uint16_t GetAutoSelectPrimaryWpnIdx(int slot);
493 uint16_t GetAutoSelectSecondaryWpnIdx(int slot);
494 void SetAutoSelectPrimaryWpnIdx(int slot, uint16_t idx);
495 void SetAutoSelectSecondaryWpnIdx(int slot, uint16_t idx);
496
497 #endif