2 * $Logfile: /Freespace2/code/Weapon/Weapons.cpp $
7 * Code to handle the weapon systems
10 * Revision 1.3 2002/05/28 08:52:03 relnev
11 * implemented two assembly stubs.
13 * cleaned up a few warnings.
15 * added a little demo hackery to make it progress a little farther.
17 * Revision 1.2 2002/05/07 03:16:53 theoddone33
18 * The Great Newline Fix
20 * Revision 1.1.1.1 2002/05/03 03:28:11 root
24 * 69 9/14/99 3:26a Dave
25 * Fixed laser fogging problem in nebula (D3D)> Fixed multiplayer
26 * respawn-too-early problem. Made a few crash points safe.
28 * 68 9/14/99 1:32a Andsager
29 * Better LOD for weapon explosions when behind. Move point ahead to get
30 * vertex and then find size.
32 * 67 9/07/99 1:10p Mikek
33 * Fix code I busted due to adding lifeleft to missiles.
35 * 66 9/07/99 12:20a Andsager
36 * LOD less agressive at lower hardware detail level
38 * 65 9/06/99 7:21p Dave
39 * Commented out bad lifeleft scaling code in weapon_set_tracking_info()
41 * 64 9/06/99 3:23p Andsager
42 * Make fireball and weapon expl ani LOD choice look at resolution of the
45 * 63 9/06/99 12:46a Andsager
46 * Add weapon_explosion_ani LOD
48 * 62 9/05/99 11:24p Mikek
49 * Fixed problems caused by earlier checkin (that was rolled back).
50 * Problem was wp->target_pos was not set for swarmers.
52 * More tweaking of missile behavior. Also add 20% to lifetime of a
55 * [Rolled back -- MK] 63 9/05/99 2:23p Mikek
56 * Make aspect seekers a little less likely to miss their target.
57 * Mysterious why they do it so often. Maybe fix for FS3...
59 * [Rolled back -- MK] 62 9/04/99 12:09p Mikek
60 * Limit number of spawned weapons that can home on player based on skill
61 * level. Works same as for non-spawned weapons. Only do in single
64 * 61 8/27/99 1:34a Andsager
65 * Modify damage by shockwaves for BIG|HUGE ships. Modify shockwave damge
66 * when weapon blows up.
68 * 60 8/24/99 10:47a Jefff
69 * tech room weapon anims. added tech anim field to weapons.tbl
71 * 59 8/16/99 11:58p Andsager
72 * Disable collision on proximity for ships with SIF_DONT_COLLIDE_INVIS
75 * 58 8/10/99 5:30p Jefff
76 * Added tech_title string to weapon_info. Changed parser accordingly.
78 * 57 8/05/99 2:06a Dave
81 * 56 8/02/99 5:16p Dave
82 * Bumped up weapon title string length from 32 to 48
84 * 55 7/29/99 5:41p Jefff
85 * Sound hooks for cmeasure success
87 * 54 7/24/99 1:54p Dave
88 * Hud text flash gauge. Reworked dead popup to use 4 buttons in red-alert
91 * 53 7/19/99 7:20p Dave
92 * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
95 * 52 7/18/99 12:32p Dave
96 * Randomly oriented shockwaves.
98 * 51 7/16/99 1:50p Dave
99 * 8 bit aabitmaps. yay.
101 * 50 7/15/99 9:20a Andsager
102 * FS2_DEMO initial checkin
104 * 49 7/08/99 10:53a Dave
105 * New multiplayer interpolation scheme. Not 100% done yet, but still
106 * better than the old way.
108 * 48 7/02/99 4:31p Dave
109 * Much more sophisticated lightning support.
111 * 47 7/01/99 5:57p Johnson
112 * Oops. Fixed big ship damage.
114 * 46 7/01/99 4:23p Dave
115 * Full support for multiple linked ambient engine sounds. Added "big
118 * 45 6/30/99 5:53p Dave
119 * Put in new anti-camper code.
121 * 44 6/22/99 3:24p Danw
122 * Fixed incorrect weapon hit sound culling.
124 * 43 6/21/99 7:25p Dave
125 * netplayer pain packet. Added type E unmoving beams.
127 * 42 6/14/99 10:45a Dave
128 * Made beam weapons specify accuracy by skill level in the weapons.tbl
130 * 41 6/11/99 11:13a Dave
131 * last minute changes before press tour build.
133 * 40 6/04/99 2:16p Dave
134 * Put in shrink effect for beam weapons.
136 * 39 6/01/99 8:35p Dave
137 * Finished lockarm weapons. Added proper supercap weapons/damage. Added
138 * awacs-set-radius sexpression.
140 * 38 6/01/99 3:52p Dave
141 * View footage screen. Fixed xstrings to not display the & symbol. Popup,
142 * dead popup, pxo find player popup, pxo private room popup.
144 * 37 5/27/99 6:17p Dave
145 * Added in laser glows.
147 * 36 5/20/99 7:00p Dave
148 * Added alternate type names for ships. Changed swarm missile table
151 * 35 5/08/99 8:25p Dave
152 * Upped object pairs. First run of nebula lightning.
154 * 34 4/28/99 11:13p Dave
155 * Temporary checkin of artillery code.
157 * 33 4/28/99 3:11p Andsager
158 * Stagger turret weapon fire times. Make turrets smarter when target is
159 * protected or beam protected. Add weaopn range to weapon info struct.
161 * 32 4/22/99 11:06p Dave
162 * Final pass at beam weapons. Solidified a lot of stuff. All that remains
163 * now is to tweak and fix bugs as they come up. No new beam weapon
166 * 31 4/19/99 11:01p Dave
167 * More sophisticated targeting laser support. Temporary checkin.
169 * 30 4/16/99 5:54p Dave
170 * Support for on/off style "stream" weapons. Real early support for
171 * target-painting lasers.
173 * 29 4/07/99 6:22p Dave
174 * Fred and Freespace support for multiple background bitmaps and suns.
175 * Fixed link errors on all subprojects. Moved encrypt_init() to
176 * cfile_init() and lcl_init(), since its safe to call twice.
178 * 28 4/02/99 1:35p Dave
179 * Removed weapon hit packet. No good for causing pain.
181 * 27 4/02/99 9:55a Dave
182 * Added a few more options in the weapons.tbl for beam weapons. Attempt
183 * at putting "pain" packets into multiplayer.
185 * 26 3/31/99 9:26p Dave
186 * Don't load beam textures when in Fred.
188 * 25 3/31/99 8:24p Dave
189 * Beefed up all kinds of stuff, incluging beam weapons, nebula effects
190 * and background nebulae. Added per-ship non-dimming pixel colors.
192 * 24 3/23/99 2:29p Andsager
193 * Fix shockwaves for kamikazi and Fred defined. Collect together
194 * shockwave_create_info struct.
196 * 23 3/23/99 11:03a Dave
197 * Added a few new fields and fixed parsing code for new weapon stuff.
199 * 22 3/19/99 9:52a Dave
200 * Checkin to repair massive source safe crash. Also added support for
201 * pof-style nebulae, and some new weapons code.
203 * 24 3/15/99 6:45p Daveb
204 * Put in rough nebula bitmap support.
206 * 23 3/12/99 3:19p Enricco
207 * Remove spurious Int3()
209 * 22 3/11/99 5:53p Dave
210 * More network optimization. Spliced in Dell OEM planet bitmap crap.
212 * 21 3/10/99 6:51p Dave
213 * Changed the way we buffer packets for all clients. Optimized turret
214 * fired packets. Did some weapon firing optimizations.
216 * 20 2/24/99 4:02p Dave
217 * Fixed weapon locking and homing problems for multiplayer dogfight mode.
219 * 19 2/05/99 12:52p Dave
220 * Fixed Glide nondarkening textures.
222 * 18 1/29/99 12:47a Dave
223 * Put in sounds for beam weapon. A bunch of interface screens (tech
226 * 17 1/27/99 9:56a Dave
227 * Temporary checkin of beam weapons for Dan to make cool sounds.
229 * 16 1/25/99 5:03a Dave
230 * First run of stealth, AWACS and TAG missile support. New mission type
233 * 15 1/24/99 11:37p Dave
234 * First full rev of beam weapons. Very customizable. Removed some bogus
235 * Int3()'s in low level net code.
237 * 14 1/21/99 10:45a Dave
238 * More beam weapon stuff. Put in warmdown time.
240 * 13 1/12/99 5:45p Dave
241 * Moved weapon pipeline in multiplayer to almost exclusively client side.
242 * Very good results. Bandwidth goes down, playability goes up for crappy
243 * connections. Fixed object update problem for ship subsystems.
245 * 12 1/08/99 2:08p Dave
246 * Fixed software rendering for pofview. Super early support for AWACS and
249 * 11 1/06/99 2:24p Dave
250 * Stubs and release build fixes.
252 * 10 12/01/98 6:12p Johnson
253 * Make sure to page in weapon impact animations as xparent textures.
255 * 9 11/20/98 4:08p Dave
256 * Fixed flak effect in multiplayer.
258 * 8 11/14/98 5:33p Dave
259 * Lots of nebula work. Put in ship contrails.
261 * 7 11/05/98 4:18p Dave
262 * First run nebula support. Beefed up localization a bit. Removed all
263 * conditional compiles for foreign versions. Modified mission file
266 * 6 10/26/98 9:42a Dave
267 * Early flak gun support.
269 * 5 10/23/98 3:51p Dave
270 * Full support for tstrings.tbl and foreign languages. All that remains
271 * is to make it active in Fred.
273 * 4 10/07/98 6:27p Dave
274 * Globalized mission and campaign file extensions. Removed Silent Threat
275 * special code. Moved \cache \players and \multidata into the \data
278 * 3 10/07/98 4:49p Andsager
279 * don't do weapon swap (was needed for mission disk)
281 * 2 10/07/98 10:54a Dave
284 * 1 10/07/98 10:51a Dave
286 * 314 9/21/98 11:19p Dave
289 * 313 9/19/98 4:33p Adam
290 * Changed default values for particle spew (used on Leech Cannon)
292 * 312 9/13/98 10:51p Dave
293 * Put in newfangled icons for mission simulator room. New mdisk.vp
294 * checksum and file length.
296 * 311 9/13/98 4:29p Andsager
297 * Maintain Weapon_info compataiblity with mission disk
299 * 310 9/13/98 4:26p Andsager
301 * 309 9/01/98 4:25p Dave
302 * Put in total (I think) backwards compatibility between mission disk
303 * freespace and non mission disk freespace, including pilot files and
304 * campaign savefiles.
306 * 308 8/28/98 3:29p Dave
307 * EMP effect done. AI effects may need some tweaking as required.
309 * 307 8/25/98 1:49p Dave
310 * First rev of EMP effect. Player side stuff basically done. Next comes
313 * 306 8/18/98 10:15a Dave
314 * Touchups on the corkscrew missiles. Added particle spewing weapons.
316 * 305 8/17/98 5:07p Dave
317 * First rev of corkscrewing missiles.
319 * 304 6/30/98 2:23p Dave
320 * Revised object update system. Removed updates for all weapons. Put
321 * button info back into control info packet.
323 * 303 6/22/98 8:36a Allender
324 * revamping of homing weapon system. don't send as object updates
327 * 302 5/24/98 2:25p Allender
328 * be sure that homing missiles die on client when lifeleft gets too
329 * negative (lost packets)
331 * 301 5/20/98 5:47p Sandeep
333 * 300 5/18/98 1:58a Mike
334 * Make Phoenix not be fired at fighters (but yes bombers).
335 * Improve positioning of ships in guard mode.
336 * Make turrets on player ship not fire near end of support ship docking.
344 #include "systemvars.h"
353 #include "floating.h"
355 #include "lighting.h"
359 #include "fireballs.h"
361 #include "hudtarget.h"
362 #include "freespace.h"
367 #include "multimsgs.h"
368 #include "linklist.h"
371 #include "cmeasure.h"
372 #include "shockwave.h"
374 #include "staticrand.h"
376 #include "multiutil.h"
380 #include "objcollide.h"
382 #include "particle.h"
383 #include "asteroid.h"
385 #include "multi_obj.h"
386 #include "corkscrew.h"
388 #include "localize.h"
390 #include "muzzleflash.h"
393 int Weapon_flyby_sound_enabled = 1;
394 DCF_BOOL( weapon_flyby, Weapon_flyby_sound_enabled )
397 static int Weapon_flyby_sound_timer;
399 weapon Weapons[MAX_WEAPONS];
400 weapon_info Weapon_info[MAX_WEAPON_TYPES];
402 #define MISSILE_OBJ_USED (1<<0) // flag used in missile_obj struct
403 #define MAX_MISSILE_OBJS MAX_WEAPONS // max number of missiles tracked in missile list
404 missile_obj Missile_objs[MAX_MISSILE_OBJS]; // array used to store missile object indexes
405 missile_obj Missile_obj_list; // head of linked list of missile_obj structs
408 // WEAPON EXPLOSION INFO
409 #define MAX_weapon_expl_lod 4
410 #define MAX_Weapon_expl_info 3
412 typedef struct weapon_expl_lod {
413 char filename[MAX_FILENAME_LEN];
419 typedef struct weapon_expl_info {
421 weapon_expl_lod lod[MAX_weapon_expl_lod];
424 weapon_expl_info Weapon_expl_info[MAX_Weapon_expl_info];
426 int Num_weapon_expl = 0;
428 int Num_weapon_types = 0;
431 int Weapons_inited = 0;
433 int laser_model_inner = -1;
434 int laser_model_outer = -1;
436 int missile_model = -1;
438 char *Weapon_names[MAX_WEAPON_TYPES];
440 int First_secondary_index = -1;
442 #define MAX_SPAWN_WEAPONS 10 // Up to 10 weapons can spawn weapons.
445 char Spawn_names[MAX_SPAWN_WEAPONS][NAME_LENGTH];
447 int Num_player_weapon_precedence; // Number of weapon types in Player_weapon_precedence
448 int Player_weapon_precedence[MAX_WEAPON_TYPES]; // Array of weapon types, precedence list for player weapon selection
450 // Used to avoid playing too many impact sounds in too short a time interval.
451 // This will elimate the odd "stereo" effect that occurs when two weapons impact at
452 // nearly the same time, like from a double laser (also saves sound channels!)
453 #define IMPACT_SOUND_DELTA 50 // in milliseconds
454 int Weapon_impact_timer; // timer, initalized at start of each mission
456 // energy suck defines
457 #define ESUCK_DEFAULT_WEAPON_REDUCE (10.0f)
458 #define ESUCK_DEFAULT_AFTERBURNER_REDUCE (10.0f)
460 // scale factor for supercaps taking damage from weapons which are not "supercap" weapons
461 #define SUPERCAP_DAMAGE_SCALE 0.25f
463 // scale factor for big ships getting hit by flak
464 #define FLAK_DAMAGE_SCALE 0.05f
466 extern int Max_allowed_player_homers[];
467 extern int compute_num_homing_objects(object *target_objp);
470 void parse_weapon_expl_tbl()
473 char base_filename[256] = "";
478 if ((rval = setjmp(parse_abort)) != 0) {
479 Error(LOCATION, "Unable to parse weapon_expl.tbl! Code = %i.\n", rval);
482 read_file_text(NOX("weapon_expl.tbl"));
487 required_string("#Start");
488 while (required_string_either("#End","$Name:")) {
489 Assert( Num_weapon_expl < MAX_Weapon_expl_info);
492 required_string("$Name:");
493 stuff_string(base_filename, F_NAME, NULL);
495 // # of lod levels - make sure old fireball.tbl is compatible
496 Weapon_expl_info[Num_weapon_expl].lod_count = 1;
497 if(optional_string("$LOD:")){
498 stuff_int(&Weapon_expl_info[Num_weapon_expl].lod_count);
501 // stuff default filename
502 strcpy(Weapon_expl_info[Num_weapon_expl].lod[0].filename, base_filename);
504 // stuff LOD level filenames
505 for(idx=1; idx<Weapon_expl_info[Num_weapon_expl].lod_count; idx++){
506 if(idx >= MAX_weapon_expl_lod){
510 sprintf(Weapon_expl_info[Num_weapon_expl].lod[idx].filename, "%s_%d", base_filename, idx);
515 required_string("#End");
517 // close localization
521 int get_weapon_expl_info_index(char *filename)
523 for (int i=0; i<MAX_Weapon_expl_info; i++) {
524 if ( stricmp(Weapon_expl_info[i].lod[0].filename, filename) == 0) {
531 // ----------------------------------------------------------------------
532 // missile_obj_list_init()
534 // Clear out the Missile_obj_list
536 void missile_obj_list_init()
540 list_init(&Missile_obj_list);
541 for ( i = 0; i < MAX_MISSILE_OBJS; i++ ) {
542 Missile_objs[i].flags = 0;
546 // ---------------------------------------------------
547 // missile_obj_list_add()
549 // Function to add a node from the Missile_obj_list. Only
550 // called from weapon_create()
551 int missile_obj_list_add(int objnum)
555 for ( i = 0; i < MAX_MISSILE_OBJS; i++ ) {
556 if ( !(Missile_objs[i].flags & MISSILE_OBJ_USED) )
559 if ( i == MAX_MISSILE_OBJS ) {
560 Error(LOCATION, "Fatal Error: Ran out of missile object nodes\n");
564 Missile_objs[i].flags = 0;
565 Missile_objs[i].objnum = objnum;
566 list_append(&Missile_obj_list, &Missile_objs[i]);
567 Missile_objs[i].flags |= MISSILE_OBJ_USED;
572 // ---------------------------------------------------
573 // missle_obj_list_remove()
575 // Function to remove a node from the Missile_obj_list. Only
576 // called from weapon_delete()
577 void missle_obj_list_remove(int index)
579 Assert(index >= 0 && index < MAX_MISSILE_OBJS);
580 list_remove(&Missile_obj_list, &Missile_objs[index]);
581 Missile_objs[index].flags = 0;
584 // ---------------------------------------------------
585 // missile_obj_list_rebuild()
587 // Called by the save/restore code to rebuild Missile_obj_list
589 void missile_obj_list_rebuild()
593 missile_obj_list_init();
595 for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
596 if ( objp->type == OBJ_WEAPON && Weapon_info[Weapons[objp->instance].weapon_info_index].subtype == WP_MISSILE ) {
597 Weapons[objp->instance].missile_list_index = missile_obj_list_add(OBJ_INDEX(objp));
602 // If this is a player countermeasure, let the player know he evaded a missile
603 void weapon_maybe_alert_cmeasure_success(object *objp)
605 if ( objp->type == OBJ_CMEASURE ) {
607 cmp = &Cmeasures[objp->instance];
608 if ( cmp->source_objnum == OBJ_INDEX(Player_obj) ) {
609 hud_start_text_flash(XSTR("Evaded", 1430), 800);
610 snd_play(&Snds[SND_MISSILE_EVADED_POPUP]);
611 } else if ( Objects[cmp->source_objnum].flags & OF_PLAYER_SHIP ) {
612 send_countermeasure_success_packet( cmp->source_objnum );
617 // ---------------------------------------------------
618 // missile_obj_return_address()
620 // Called externally to generate an address from an index into
621 // the Missile_objs[] array
623 missile_obj *missile_obj_return_address(int index)
625 Assert(index >= 0 && index < MAX_MISSILE_OBJS);
626 return &Missile_objs[index];
629 // Return the index of Weapon_info[].name that is *name.
630 int weapon_info_lookup(char *name)
634 for (i=0; i<Num_weapon_types; i++)
635 if (!stricmp(name, Weapon_info[i].name))
641 #define DEFAULT_WEAPON_SPAWN_COUNT 10
643 // Parse the weapon flags.
644 void parse_wi_flags(weapon_info *weaponp)
646 char weapon_strings[MAX_WEAPON_FLAGS][NAME_LENGTH];
649 required_string("$Flags:");
651 num_strings = stuff_string_list(weapon_strings, MAX_WEAPON_FLAGS);
653 for (int i=0; i<num_strings; i++) {
654 if (!stricmp(NOX("Electronics"), weapon_strings[i]))
655 weaponp->wi_flags |= WIF_ELECTRONICS;
656 else if (!strnicmp(NOX("Spawn"), weapon_strings[i], 5)) {
657 if (weaponp->spawn_type == -1) {
658 int skip_length, name_length;
661 temp_string = weapon_strings[i];
663 weaponp->wi_flags |= WIF_SPAWN;
664 weaponp->spawn_type = (short)Num_spawn_types;
665 skip_length = strlen(NOX("Spawn")) + strspn(&temp_string[strlen(NOX("Spawn"))], NOX(" \t"));
666 char *num_start = strchr(&temp_string[skip_length], ',');
667 if (num_start == NULL) {
668 weaponp->spawn_count = DEFAULT_WEAPON_SPAWN_COUNT;
671 weaponp->spawn_count = (short)atoi(num_start+1);
672 name_length = num_start - temp_string - skip_length;
675 strncpy(Spawn_names[Num_spawn_types++], &(weapon_strings[i][skip_length]), name_length);
676 Assert(Num_spawn_types < MAX_SPAWN_WEAPONS);
678 Warning(LOCATION, "Illegal to have two spawn types for one weapon.\n"
679 "Ignoring weapon %s", weapon_strings[i]);
680 } else if (!stricmp(NOX("Remote Detonate"), weapon_strings[i]))
681 weaponp->wi_flags |= WIF_REMOTE;
682 else if (!stricmp(NOX("Puncture"), weapon_strings[i]))
683 weaponp->wi_flags |= WIF_PUNCTURE;
684 else if (!stricmp(NOX("Big Ship"), weapon_strings[i]))
685 weaponp->wi_flags |= WIF_BIG_ONLY;
686 else if (!stricmp(NOX("Huge"), weapon_strings[i]))
687 weaponp->wi_flags |= WIF_HUGE;
688 else if (!stricmp(NOX("Bomber+"), weapon_strings[i]))
689 weaponp->wi_flags |= WIF_BOMBER_PLUS;
690 else if (!stricmp(NOX("child"), weapon_strings[i]))
691 weaponp->wi_flags |= WIF_CHILD;
692 else if (!stricmp(NOX("Bomb"), weapon_strings[i]))
693 weaponp->wi_flags |= WIF_BOMB;
694 else if (!stricmp(NOX("No Dumbfire"), weapon_strings[i]))
695 weaponp->wi_flags |= WIF_NO_DUMBFIRE;
696 else if (!stricmp(NOX("In tech database"), weapon_strings[i]))
697 weaponp->wi_flags |= WIF_IN_TECH_DATABASE;
698 else if (!stricmp(NOX("Player allowed"), weapon_strings[i]))
699 weaponp->wi_flags |= WIF_PLAYER_ALLOWED;
700 else if (!stricmp(NOX("Particle Spew"), weapon_strings[i]))
701 weaponp->wi_flags |= WIF_PARTICLE_SPEW;
702 else if (!stricmp(NOX("EMP"), weapon_strings[i]))
703 weaponp->wi_flags |= WIF_EMP;
704 else if (!stricmp(NOX("Esuck"), weapon_strings[i]))
705 weaponp->wi_flags |= WIF_ENERGY_SUCK;
706 else if (!stricmp(NOX("Flak"), weapon_strings[i]))
707 weaponp->wi_flags |= WIF_FLAK;
708 else if (!stricmp(NOX("Corkscrew"), weapon_strings[i]))
709 weaponp->wi_flags |= WIF_CORKSCREW;
710 else if (!stricmp(NOX("Shudder"), weapon_strings[i]))
711 weaponp->wi_flags |= WIF_SHUDDER;
712 else if (!stricmp(NOX("lockarm"), weapon_strings[i]))
713 weaponp->wi_flags |= WIF_LOCKARM;
714 else if (!stricmp(NOX("beam"), weapon_strings[i]))
715 weaponp->wi_flags |= WIF_BEAM;
716 else if (!stricmp(NOX("stream"), weapon_strings[i]))
717 weaponp->wi_flags |= WIF_STREAM;
718 else if (!stricmp(NOX("supercap"), weapon_strings[i]))
719 weaponp->wi_flags |= WIF_SUPERCAP;
721 Warning(LOCATION, "Bogus string in weapon flags: %s\n", weapon_strings[i]);
724 // SWARM, CORKSCREW and FLAK should be mutually exclusive
725 if(weaponp->wi_flags & WIF_FLAK){
726 Assert(!(weaponp->wi_flags & WIF_CORKSCREW) && !(weaponp->wi_flags & WIF_SWARM));
728 if(weaponp->wi_flags & WIF_CORKSCREW){
729 Assert(!(weaponp->wi_flags & WIF_FLAK) && !(weaponp->wi_flags & WIF_SWARM));
731 if(weaponp->wi_flags & WIF_SWARM){
732 Assert(!(weaponp->wi_flags & WIF_CORKSCREW) && !(weaponp->wi_flags & WIF_FLAK));
735 // make sure flak guns are only placed on turrets
736 if(weaponp->wi_flags & WIF_FLAK){
737 Assert(weaponp->wi_flags & WIF_BIG_ONLY);
741 // function to parse the information for a specific weapon type.
742 // return 0 if successful, otherwise return -1
743 #define WEAPONS_MULTITEXT_LENGTH 2048
747 char buf[WEAPONS_MULTITEXT_LENGTH];
749 char fname[255] = "";
752 wip = &Weapon_info[Num_weapon_types];
756 required_string("$Name:");
757 stuff_string(wip->name, F_NAME, NULL);
758 diag_printf ("Weapon name -- %s\n", wip->name);
760 // AL 28-3-98: If this is a demo build, we only want to parse weapons that are preceded with
762 #ifdef DEMO // not needed FS2_DEMO (separate table file)
763 if ( wip->name[0] != '@' ) {
764 // advance to next weapon, and return -1
766 if ( skip_to_start_of_strings("$Name:", "#End") != 1 ) {
773 if ( wip->name[0] == '@' ) {
774 char old_name[NAME_LENGTH];
775 strcpy(old_name, wip->name);
776 strcpy(wip->name, old_name+1);
780 if (optional_string("+Title:")) {
781 stuff_string(wip->title, F_NAME, NULL, WEAPON_TITLE_LEN);
785 if (optional_string("+Description:")) {
786 stuff_string(buf, F_MULTITEXT, NULL);
787 wip->desc = strdup(buf);
790 wip->tech_title[0] = 0;
791 if (optional_string("+Tech Title:")) {
792 stuff_string(wip->tech_title, F_NAME, NULL, NAME_LENGTH);
795 wip->tech_anim_filename[0] = 0;
796 if (optional_string("+Tech Anim:")) {
797 stuff_string(wip->tech_anim_filename, F_NAME, NULL, NAME_LENGTH);
800 wip->tech_desc = NULL;
801 if (optional_string("+Tech Description:")) {
802 stuff_string(buf, F_MULTITEXT, NULL, WEAPONS_MULTITEXT_LENGTH);
803 wip->tech_desc = strdup(buf);
806 // Read the model file. It can be a POF file or none.
807 // If there is no model file (Model file: = "none") then we use our special
808 // laser renderer which requires inner, middle and outer information.
809 required_string("$Model file:");
810 stuff_string(wip->pofbitmap_name, F_NAME, NULL);
811 diag_printf ("Model pof file -- %s\n", wip->pofbitmap_name );
812 if ( stricmp(wip->pofbitmap_name, NOX("none")) ) {
814 wip->render_type = WRT_POF;
815 wip->laser_bitmap = -1;
817 // No POF or AVI file specified, render as special laser type.
820 wip->render_type = WRT_LASER;
823 // laser bitmap itself
824 required_string("@Laser Bitmap:");
825 stuff_string(wip->pofbitmap_name, F_NAME, NULL);
826 wip->laser_bitmap = -1;
828 wip->laser_bitmap = bm_load( wip->pofbitmap_name );
831 // optional laser glow
832 wip->laser_glow_bitmap = -1;
833 if(optional_string("@Laser Glow:")){
834 stuff_string(fname, F_NAME, NULL);
836 wip->laser_glow_bitmap = bm_load( fname );
838 // might as well lock it down as an aabitmap now
839 if(wip->laser_glow_bitmap >= 0){
840 bm_lock(wip->laser_glow_bitmap, 8, BMP_AABITMAP);
841 bm_unlock(wip->laser_glow_bitmap);
846 required_string("@Laser Color:");
847 stuff_byte(&r); stuff_byte(&g); stuff_byte(&b);
848 gr_init_color( &wip->laser_color_1, r, g, b );
850 // optional string for cycling laser colors
851 gr_init_color(&wip->laser_color_2, 0, 0, 0);
852 if(optional_string("@Laser Color2:")){
853 stuff_byte(&r); stuff_byte(&g); stuff_byte(&b);
854 gr_init_color( &wip->laser_color_2, r, g, b );
857 required_string("@Laser Length:");
858 stuff_float(&wip->laser_length);
860 required_string("@Laser Head Radius:");
861 stuff_float(&wip->laser_head_radius);
863 required_string("@Laser Tail Radius:");
864 stuff_float(&wip->laser_tail_radius );
867 required_string("$Mass:");
868 stuff_float( &(wip->mass) );
869 diag_printf ("Weapon mass -- %7.3f\n", wip->mass);
871 required_string("$Velocity:");
872 stuff_float( &(wip->max_speed) );
873 diag_printf ("Weapon mass -- %7.3f\n", wip->max_speed);
875 required_string("$Fire Wait:");
876 stuff_float( &(wip->fire_wait) );
877 diag_printf ("Weapon fire wait -- %7.3f\n", wip->fire_wait);
879 required_string("$Damage:");
880 stuff_float(&wip->damage);
882 // secondary weapons require these values
883 if (First_secondary_index != -1) {
884 required_string("$Blast Force:");
885 stuff_float( &(wip->blast_force) );
886 diag_printf ("Weapon blast force -- %7.3f\n", wip->blast_force);
888 required_string("$Inner Radius:");
889 stuff_float( &(wip->inner_radius) );
890 if ( wip->inner_radius != 0 ) {
891 wip->wi_flags |= WIF_AREA_EFFECT;
893 diag_printf ("Weapon inner blast radius -- %7.3f\n", wip->inner_radius);
895 required_string("$Outer Radius:");
896 stuff_float( &(wip->outer_radius) );
897 if ( wip->outer_radius != 0 ) {
898 wip->wi_flags |= WIF_AREA_EFFECT;
900 diag_printf ("Weapon outer blast radius -- %7.3f\n", wip->outer_radius);
902 required_string("$Shockwave Speed:");
903 stuff_float( &(wip->shockwave_speed) );
904 if ( wip->shockwave_speed != 0 ) {
905 wip->wi_flags |= WIF_SHOCKWAVE;
907 diag_printf ("Shockwave speed -- %7.3f\n", wip->shockwave_speed);
909 // for primary weapons they're optional
911 if(optional_string("$Blast Force:")){
912 stuff_float( &(wip->blast_force) );
913 diag_printf ("Weapon blast force -- %7.3f\n", wip->blast_force);
916 if(optional_string("$Inner Radius:")){
917 stuff_float( &(wip->inner_radius) );
918 if ( wip->inner_radius != 0 ) {
919 wip->wi_flags |= WIF_AREA_EFFECT;
921 diag_printf ("Weapon inner blast radius -- %7.3f\n", wip->inner_radius);
924 if(optional_string("$Outer Radius:")){
925 stuff_float( &(wip->outer_radius) );
926 if ( wip->outer_radius != 0 ) {
927 wip->wi_flags |= WIF_AREA_EFFECT;
929 diag_printf ("Weapon outer blast radius -- %7.3f\n", wip->outer_radius);
932 if(optional_string("$Shockwave Speed:")){
933 stuff_float( &(wip->shockwave_speed) );
934 if ( wip->shockwave_speed != 0 ) {
935 wip->wi_flags |= WIF_SHOCKWAVE;
937 diag_printf ("Shockwave speed -- %7.3f\n", wip->shockwave_speed);
941 required_string("$Armor Factor:");
942 stuff_float(&wip->armor_factor);
944 required_string("$Shield Factor:");
945 stuff_float(&wip->shield_factor);
947 required_string("$Subsystem Factor:");
948 stuff_float(&wip->subsystem_factor);
950 required_string("$Lifetime:");
951 stuff_float(&wip->lifetime);
953 required_string("$Energy Consumed:");
954 stuff_float(&wip->energy_consumed);
956 required_string("$Cargo Size:");
957 stuff_float(&wip->cargo_size);
960 required_string("$Homing:");
961 stuff_boolean(&is_homing);
963 if (is_homing == 1) {
966 // the following five items only need to be recorded if the weapon is a homing weapon
967 required_string("+Type:");
968 stuff_string(temp_type, F_NAME, NULL);
970 if (!stricmp(temp_type, NOX("HEAT"))) {
971 float view_cone_angle;
973 wip->wi_flags |= WIF_HOMING_HEAT | WIF_TURNS;
975 required_string("+Turn Time:");
976 stuff_float(&wip->turn_time);
978 required_string("+View Cone:");
979 stuff_float(&view_cone_angle);
981 wip->fov = (float)cos((float)(ANG_TO_RAD(view_cone_angle/2.0f)));
983 } else if (!stricmp(temp_type, NOX("ASPECT"))) {
984 wip->wi_flags |= WIF_HOMING_ASPECT | WIF_TURNS;
986 required_string("+Turn Time:");
987 stuff_float(&wip->turn_time);
989 required_string("+Min Lock Time:"); // minimum time (in seconds) to achieve lock
990 stuff_float(&wip->min_lock_time);
992 required_string("+Lock Pixels/Sec:"); // pixels/sec moved while locking
993 stuff_int(&wip->lock_pixels_per_sec);
995 required_string("+Catch-up Pixels/Sec:"); // pixels/sec moved while catching-up for a lock
996 stuff_int(&wip->catchup_pixels_per_sec);
998 required_string("+Catch-up Penalty:"); // number of extra pixels to move while locking as a penalty for catching up for a lock
999 stuff_int(&wip->catchup_pixel_penalty);
1001 Error(LOCATION, "Illegal homing type = %s.\nMust be HEAT or ASPECT.\n", temp_type);
1007 wip->swarm_count = -1;
1008 if(optional_string("$Swarm:")){
1009 wip->swarm_count = SWARM_DEFAULT_NUM_MISSILES_FIRED;
1010 stuff_int(&s_count);
1011 wip->swarm_count = (short)s_count;
1013 // flag as being a swarm weapon
1014 wip->wi_flags |= WIF_SWARM;
1017 required_string("$LaunchSnd:");
1018 stuff_int(&wip->launch_snd);
1020 required_string("$ImpactSnd:");
1021 stuff_int(&wip->impact_snd);
1023 if (First_secondary_index != -1) {
1024 required_string("$FlyBySnd:");
1025 stuff_int(&wip->flyby_snd);
1028 // Secondary weapons are required to have a rearm rate.
1029 if (First_secondary_index != -1) {
1030 required_string( "$Rearm Rate:");
1031 stuff_float( &wip->rearm_rate );
1032 if (wip->rearm_rate > 0.1f)
1033 wip->rearm_rate = 1.0f/wip->rearm_rate;
1035 wip->rearm_rate = 1.0f;
1038 wip->weapon_range = 999999999.9f;
1039 if (optional_string("+Weapon Range:")) {
1040 stuff_float(&wip->weapon_range);
1043 wip->spawn_type = -1;
1044 parse_wi_flags(wip);
1046 char trail_name[MAX_FILENAME_LEN] = "";
1047 trail_info *ti = &wip->tr_info;
1048 memset(ti, 0, sizeof(trail_info));
1049 if(optional_string("$Trail:")){
1050 wip->wi_flags |= WIF_TRAIL; // missile leaves a trail
1052 required_string("+Start Width:");
1053 stuff_float(&ti->w_start);
1055 required_string("+End Width:");
1056 stuff_float(&ti->w_end);
1058 required_string("+Start Alpha:");
1059 stuff_float(&ti->a_start);
1061 required_string("+End Alpha:");
1062 stuff_float(&ti->a_end);
1064 required_string("+Max Life:");
1065 stuff_float(&ti->max_life);
1067 ti->stamp = fl2i(1000.0f*ti->max_life)/(NUM_TRAIL_SECTIONS+1);
1069 required_string("+Bitmap:");
1070 stuff_string(trail_name, F_NAME, NULL);
1071 ti->bitmap = bm_load(trail_name);
1072 // wip->delta_time = fl2i(1000.0f*wip->max_life)/(NUM_TRAIL_SECTIONS+1); // time between sections. max_life / num_sections basically.
1075 // read in filename for icon that is used in weapons selection
1076 wip->icon_filename[0] = 0;
1077 if ( optional_string("$Icon:") ) {
1078 stuff_string(wip->icon_filename, F_NAME, NULL);
1081 // read in filename for animation that is used in weapons selection
1082 wip->anim_filename[0] = 0;
1083 if ( optional_string("$Anim:") ) {
1084 stuff_string(wip->anim_filename, F_NAME, NULL);
1087 wip->impact_weapon_expl_index = -1;
1088 if ( optional_string("$Impact Explosion:") ) {
1089 char impact_ani_file[FILESPEC_LENGTH];
1090 stuff_string(impact_ani_file, F_NAME, NULL);
1091 if ( stricmp(impact_ani_file,NOX("none"))) {
1092 wip->impact_weapon_expl_index = get_weapon_expl_info_index(impact_ani_file);
1093 //int num_frames, fps;
1094 //wip->impact_explosion_ani = bm_load_animation( impact_ani_file, &num_frames, &fps, 1 );
1096 required_string("$Impact Explosion Radius:");
1097 stuff_float(&wip->impact_explosion_radius);
1102 char mflash_string[255] = "";
1103 wip->muzzle_flash = -1;
1104 if( optional_string("$Muzzleflash:") ){
1105 stuff_string(mflash_string, F_NAME, NULL);
1108 wip->muzzle_flash = mflash_lookup(mflash_string);
1110 if(wip->muzzle_flash >= 0){
1111 wip->wi_flags |= WIF_MFLASH;
1115 // EMP optional stuff (if WIF_EMP is not set, none of this matters, anyway)
1116 if( optional_string("$EMP Intensity:") ){
1117 stuff_float(&wip->emp_intensity);
1119 wip->emp_intensity = EMP_DEFAULT_INTENSITY;
1121 if( optional_string("$EMP Time:") ){
1122 stuff_float(&wip->emp_time);
1124 wip->emp_intensity = EMP_DEFAULT_TIME;
1127 // Energy suck optional stuff (if WIF_ENERGY_SUCK is not set, none of this matters anyway)
1128 if( optional_string("$Leech Weapon:") ){
1129 stuff_float(&wip->weapon_reduce);
1131 wip->weapon_reduce = ESUCK_DEFAULT_WEAPON_REDUCE;
1133 if( optional_string("$Leech Afterburner:") ){
1134 stuff_float(&wip->afterburner_reduce);
1136 wip->afterburner_reduce = ESUCK_DEFAULT_AFTERBURNER_REDUCE;
1139 // beam weapon optional stuff
1140 wip->b_info.beam_type = -1;
1141 wip->b_info.beam_life = -1.0f;
1142 wip->b_info.beam_warmup = -1;
1143 wip->b_info.beam_warmdown = -1;
1144 wip->b_info.beam_muzzle_radius = 0.0f;
1145 wip->b_info.beam_particle_count = -1;
1146 wip->b_info.beam_particle_radius = 0.0f;
1147 wip->b_info.beam_particle_angle = 0.0f;
1148 wip->b_info.beam_particle_ani = -1;
1149 wip->b_info.beam_loop_sound = -1;
1150 wip->b_info.beam_warmup_sound = -1;
1151 wip->b_info.beam_warmdown_sound = -1;
1152 wip->b_info.beam_num_sections = 0;
1153 wip->b_info.beam_glow_bitmap = -1;
1154 wip->b_info.beam_shots = 0;
1155 wip->b_info.beam_shrink_factor = 0.0f;
1156 wip->b_info.beam_shrink_pct = 0.0f;
1157 if( optional_string("$BeamInfo:")){
1159 required_string("+Type:");
1160 stuff_int(&wip->b_info.beam_type);
1162 // how long it lasts
1163 required_string("+Life:");
1164 stuff_float(&wip->b_info.beam_life);
1167 required_string("+Warmup:");
1168 stuff_int(&wip->b_info.beam_warmup);
1171 required_string("+Warmdown:");
1172 stuff_int(&wip->b_info.beam_warmdown);
1174 // muzzle glow radius
1175 required_string("+Radius:");
1176 stuff_float(&wip->b_info.beam_muzzle_radius);
1178 // particle spew count
1179 required_string("+PCount:");
1180 stuff_int(&wip->b_info.beam_particle_count);
1183 required_string("+PRadius:");
1184 stuff_float(&wip->b_info.beam_particle_radius);
1186 // angle off turret normal
1187 required_string("+PAngle:");
1188 stuff_float(&wip->b_info.beam_particle_angle);
1190 // particle bitmap/ani
1191 required_string("+PAni:");
1192 stuff_string(fname, F_NAME, NULL);
1194 int num_frames, fps;
1195 wip->b_info.beam_particle_ani = bm_load_animation(fname, &num_frames, &fps, 1);
1199 required_string("+Miss Factor:");
1200 for(idx=0; idx<NUM_SKILL_LEVELS; idx++){
1201 wip->b_info.beam_miss_factor[idx] = 0.00001f;
1202 stuff_float(&wip->b_info.beam_miss_factor[idx]);
1206 required_string("+BeamSound:");
1207 stuff_int(&wip->b_info.beam_loop_sound);
1210 required_string("+WarmupSound:");
1211 stuff_int(&wip->b_info.beam_warmup_sound);
1214 required_string("+WarmdownSound:");
1215 stuff_int(&wip->b_info.beam_warmdown_sound);
1218 required_string("+Muzzleglow:");
1219 stuff_string(fname, F_NAME, NULL);
1221 wip->b_info.beam_glow_bitmap = bm_load(fname);
1224 // # of shots (only used for type D beams)
1225 required_string("+Shots:");
1226 stuff_int(&wip->b_info.beam_shots);
1229 required_string("+ShrinkFactor:");
1230 stuff_float(&wip->b_info.beam_shrink_factor);
1231 required_string("+ShrinkPct:");
1232 stuff_float(&wip->b_info.beam_shrink_pct);
1235 while( optional_string("$Section:") ){
1236 beam_weapon_section_info i;
1237 char tex_name[255] = "";
1240 required_string("+Width:");
1241 stuff_float(&i.width);
1244 required_string("+Texture:");
1245 stuff_string(tex_name, F_NAME, NULL);
1248 i.texture = bm_load(tex_name);
1250 bm_lock(i.texture, 16, BMP_TEX_OTHER);
1251 bm_unlock(i.texture);
1256 required_string("+RGBA Inner:");
1257 stuff_byte(&i.rgba_inner[0]);
1258 stuff_byte(&i.rgba_inner[1]);
1259 stuff_byte(&i.rgba_inner[2]);
1260 stuff_byte(&i.rgba_inner[3]);
1263 required_string("+RGBA Outer:");
1264 stuff_byte(&i.rgba_outer[0]);
1265 stuff_byte(&i.rgba_outer[1]);
1266 stuff_byte(&i.rgba_outer[2]);
1267 stuff_byte(&i.rgba_outer[3]);
1270 required_string("+Flicker:");
1271 stuff_float(&i.flicker);
1274 required_string("+Zadd:");
1275 stuff_float(&i.z_add);
1278 if(wip->b_info.beam_num_sections < MAX_BEAM_SECTIONS - 1){
1279 wip->b_info.sections[wip->b_info.beam_num_sections++] = i;
1284 // tag weapon optional stuff
1285 wip->tag_level = -1;
1286 wip->tag_time = -1.0f;
1287 if( optional_string("$Tag:")){
1288 stuff_int(&wip->tag_level);
1289 stuff_float(&wip->tag_time);
1290 wip->wi_flags |= WIF_TAG;
1296 // function to parse the information for a specific ship type.
1297 void parse_cmeasure()
1299 cmeasure_info *cmeasurep;
1301 cmeasurep = &Cmeasure_info[Num_cmeasure_types];
1303 required_string("$Name:");
1304 stuff_string(cmeasurep->cmeasure_name, F_NAME, NULL);
1307 $Velocity: 20.0 ;; speed relative to ship, rear-fired until POF info added, MK, 5/22/97
1309 $Lifetime Min: 1.0 ;; Minimum lifetime
1310 $Lifetime Max: 2.0 ;; Maximum lifetime. Actual lifetime is rand(min..max).
1311 $LaunchSnd: counter_1.wav, .8, 10, 300 ;; countermeasure 1 fired (sound is 3d)
1314 required_string("$Velocity:");
1315 stuff_float( &(cmeasurep->max_speed) );
1317 required_string("$Fire Wait:");
1318 stuff_float( &(cmeasurep->fire_wait) );
1320 required_string("$Lifetime Min:");
1321 stuff_float(&cmeasurep->life_min);
1323 required_string("$Lifetime Max:");
1324 stuff_float(&cmeasurep->life_max);
1326 required_string("$LaunchSnd:");
1327 stuff_int(&cmeasurep->launch_sound);
1329 required_string("$Model:");
1330 stuff_string(cmeasurep->pof_name, F_NAME, NULL);
1331 cmeasurep->model_num = -1;
1335 // For all weapons that spawn weapons, given an index at weaponp->spawn_type,
1336 // convert the strings in Spawn_names to indices in the Weapon_types array.
1337 void translate_spawn_types()
1341 for (i=0; i<Num_weapon_types; i++)
1342 if (Weapon_info[i].spawn_type != -1) {
1343 int spawn_type = Weapon_info[i].spawn_type;
1345 for (j=0; j<Num_weapon_types; j++)
1346 if (!stricmp(Spawn_names[spawn_type], Weapon_info[j].name)) {
1347 Weapon_info[i].spawn_type = (short)j;
1349 Warning(LOCATION, "Weapon %s spawns itself. Infinite recursion?\n", Weapon_info[i].name);
1355 void parse_weaponstbl()
1357 // open localization
1360 read_file_text("weapons.tbl");
1363 Num_weapon_types = 0;
1364 First_secondary_index = -1;
1365 Num_spawn_types = 0;
1367 required_string("#Primary Weapons");
1368 while (required_string_either("#End", "$Name:")) {
1369 Assert( Num_weapon_types < MAX_WEAPON_TYPES );
1370 // AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
1371 if ( parse_weapon() ) {
1374 Weapon_info[Num_weapon_types].subtype = WP_LASER;
1377 required_string("#End");
1379 required_string("#Secondary Weapons");
1380 First_secondary_index = Num_weapon_types;
1381 while (required_string_either("#End", "$Name:")) {
1382 Assert( Num_weapon_types < MAX_WEAPON_TYPES );
1383 // AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
1384 if ( parse_weapon() ) {
1387 Weapon_info[Num_weapon_types].subtype = WP_MISSILE;
1390 required_string("#End");
1392 required_string("#Beam Weapons");
1393 while (required_string_either("#End", "$Name:")) {
1394 Assert( Num_weapon_types < MAX_WEAPON_TYPES );
1395 // AL 28-3-98: If parse_weapon() fails, try next .tbl weapon
1396 if ( parse_weapon() ) {
1399 Weapon_info[Num_weapon_types].subtype = WP_BEAM;
1402 required_string("#End");
1404 required_string("#Countermeasures");
1405 while (required_string_either("#End", "$Name:")) {
1406 Assert( Num_cmeasure_types < MAX_CMEASURE_TYPES );
1408 Num_cmeasure_types++;
1411 required_string("#End");
1413 // Read in a list of weapon_info indicies that are an ordering of the player weapon precedence.
1414 // This list is used to select an alternate weapon when a particular weapon is not available
1415 // during weapon selection.
1416 required_string("$Player Weapon Precedence:");
1417 Num_player_weapon_precedence = stuff_int_list(Player_weapon_precedence, MAX_WEAPON_TYPES, WEAPON_LIST_TYPE);
1419 translate_spawn_types();
1421 // close localization
1425 void create_weapon_names()
1429 for (i=0; i<Num_weapon_types; i++)
1430 Weapon_names[i] = Weapon_info[i].name;
1433 // This will get called once at game startup
1438 if ( !Weapons_inited ) {
1441 #warning FS2_DEMO HACK! commented out a function call
1442 // parse weapon_exp.tbl
1443 parse_weapon_expl_tbl();
1445 // parse weapons.tbl
1446 if ((rval = setjmp(parse_abort)) != 0) {
1447 Error(LOCATION, "Error parsing 'weapons.tbl'\r\nError code = %i.\r\n", rval);
1450 create_weapon_names();
1455 weapon_level_init();
1459 // This will get called at the start of each level.
1460 void weapon_level_init()
1464 // Reset everything between levels
1466 for (i=0; i<MAX_WEAPONS; i++) {
1467 Weapons[i].objnum = -1;
1468 Weapons[i].weapon_info_index = -1;
1471 trail_level_init(); // reset all missile trails
1474 missile_obj_list_init();
1476 cscrew_level_init();
1481 Weapon_flyby_sound_timer = timestamp(0);
1482 Weapon_impact_timer = 1; // inited each level, used to reduce impact sounds
1485 MONITOR( NumWeaponsRend );
1487 float weapon_glow_scale_f = 2.3f;
1488 float weapon_glow_scale_r = 2.3f;
1489 float weapon_glow_scale_l = 1.5f;
1490 float weapon_glow_alpha_d3d = 0.85f;
1491 float weapon_glow_alpha_glide = 0.99f;
1492 void weapon_render(object *obj)
1499 MONITOR_INC(NumWeaponsRend, 1);
1501 Assert(obj->type == OBJ_WEAPON);
1503 num = obj->instance;
1505 wip = &Weapon_info[Weapons[num].weapon_info_index];
1507 switch (wip->render_type) {
1509 // turn off fogging for good measure
1510 gr_fog_set(GR_FOGMODE_NONE, 0, 0, 0);
1512 if (wip->laser_bitmap >= 0) {
1513 gr_set_color_fast(&wip->laser_color_1);
1514 gr_set_bitmap(wip->laser_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.99999f);
1517 vm_vec_scale_add(&headp, &obj->pos, &obj->orient.fvec, wip->laser_length);
1518 wp->weapon_flags &= ~WF_CONSIDER_FOR_FLYBY_SOUND;
1519 if ( g3_draw_laser(&headp, wip->laser_head_radius, &obj->pos, wip->laser_tail_radius) ) {
1520 wp->weapon_flags |= WF_CONSIDER_FOR_FLYBY_SOUND;
1524 // maybe draw laser glow bitmap
1525 if(wip->laser_glow_bitmap >= 0){
1526 // get the laser color
1527 weapon_get_laser_color(&c, obj);
1530 vm_vec_scale_add(&headp2, &obj->pos, &obj->orient.fvec, wip->laser_length * weapon_glow_scale_l);
1531 gr_set_bitmap(wip->laser_glow_bitmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, gr_screen.mode == GR_DIRECT3D ? weapon_glow_alpha_d3d : weapon_glow_alpha_glide);
1532 g3_draw_laser_rgb(&headp2, wip->laser_head_radius * weapon_glow_scale_f, &obj->pos, wip->laser_tail_radius * weapon_glow_scale_r, c.red, c.green, c.blue);
1538 uint render_flags = MR_NORMAL|MR_IS_MISSILE|MR_NO_LIGHTING;
1540 model_clear_instance(wip->model_num);
1542 if ( (wip->wi_flags & WIF_THRUSTER) && (wp->thruster_bitmap > -1) ) {
1545 // Add noise to thruster geometry.
1546 //ft = obj->phys_info.forward_thrust;
1547 ft = 1.0f; // Always use 1.0f for missiles
1548 ft *= (1.0f + frand()/5.0f - 1.0f/10.0f);
1552 model_set_thrust( wip->model_num, ft, wp->thruster_bitmap, wp->thruster_glow_bitmap, wp->thruster_glow_noise);
1553 render_flags |= MR_SHOW_THRUSTERS;
1556 model_render(wip->model_num, &obj->orient, &obj->pos, render_flags);
1558 // render a missile plume as well
1560 static int plume = -1;
1561 extern float Interp_thrust_twist;
1562 extern float Interp_thrust_twist2;
1564 plume = model_load("plume01.pof", -1, NULL);
1567 Interp_thrust_twist = tw;
1568 Interp_thrust_twist2 = tw2;
1569 model_set_alpha(plume_alpha);
1570 model_render(plume, &obj->orient, &obj->pos, MR_ALL_XPARENT);
1571 Interp_thrust_twist = -1.0f;
1572 Interp_thrust_twist2 = -1.0f;
1579 Warning(LOCATION, "Unknown weapon rendering type = %i\n", wip->render_type);
1583 void weapon_delete(object *obj)
1588 num = obj->instance;
1590 Assert( Weapons[num].objnum == OBJ_INDEX(obj));
1593 Assert(wp->weapon_info_index >= 0);
1594 wp->weapon_info_index = -1;
1595 if (wp->swarm_index >= 0) {
1596 swarm_delete(wp->swarm_index);
1597 wp->swarm_index = -1;
1600 if(wp->cscrew_index >= 0) {
1601 cscrew_delete(wp->cscrew_index);
1602 wp->cscrew_index = -1;
1605 if (wp->missile_list_index >= 0) {
1606 missle_obj_list_remove(wp->missile_list_index);
1607 wp->missile_list_index = -1;
1610 if (wp->flak_index >= 0){
1611 flak_delete(wp->flak_index);
1612 wp->flak_index = -1;
1615 if (wp->trail_num > -1) {
1616 trail_object_died(wp->trail_num);
1621 Assert(Num_weapons >= 0);
1624 // Check if missile is newly locked onto the Player, maybe play a launch warning
1625 void weapon_maybe_play_warning(weapon *wp)
1627 if ( wp->homing_object == Player_obj ) {
1628 if ( !(wp->weapon_flags & WF_LOCK_WARNING_PLAYED) ) {
1629 wp->weapon_flags |= WF_LOCK_WARNING_PLAYED;
1630 if ( Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_HEAT ) {
1631 snd_play(&Snds[SND_HEATLOCK_WARN]);
1633 Assert(Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_ASPECT);
1634 snd_play(&Snds[SND_ASPECTLOCK_WARN]);
1640 #define CMEASURE_DETONATE_DISTANCE 40.0f
1642 // Detonate all missiles near this countermeasure.
1643 void detonate_nearby_missiles(cmeasure *cmp)
1646 vector cmeasure_pos;
1648 cmeasure_pos = Objects[cmp->objnum].pos;
1650 mop = GET_FIRST(&Missile_obj_list);
1651 while(mop != END_OF_LIST(&Missile_obj_list)) {
1655 objp = &Objects[mop->objnum];
1656 wp = &Weapons[objp->instance];
1658 if (wp->team != cmp->team) {
1659 if ( Missiontime - wp->creation_time > F1_0/2) {
1660 if (vm_vec_dist_quick(&cmeasure_pos, &objp->pos) < CMEASURE_DETONATE_DISTANCE) {
1661 if (wp->lifeleft > 0.2f) {
1662 //nprintf(("Jim", "Frame %i: Cmeasure #%i detonating weapon #%i\n", Framecount, cmp-Cmeasures, wp-Weapons));
1663 wp->lifeleft = 0.2f;
1664 // nprintf(("AI", "Frame %i: Flagging weapon %i for detonation.\n", Framecount, wp-Weapons));
1674 // Find an object for weapon #num (object *weapon_objp) to home on due to heat.
1675 void find_homing_object(object *weapon_objp, int num)
1677 object *objp, *old_homing_objp;
1684 wip = &Weapon_info[Weapons[num].weapon_info_index];
1686 best_dist = 99999.9f;
1688 // save the old homing object so that multiplayer servers can give the right information
1689 // to clients if the object changes
1690 old_homing_objp = wp->homing_object;
1692 wp->homing_object = &obj_used_list;
1694 // Scan all objects, find a weapon to home on.
1695 for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
1696 if ((objp->type == OBJ_SHIP) || (objp->type == OBJ_CMEASURE)) {
1697 if (objp->type == OBJ_CMEASURE)
1698 if (Cmeasures[objp->instance].flags & CMF_DUD_HEAT)
1701 int homing_object_team = obj_team(objp);
1702 if ( (homing_object_team != wp->team) || (homing_object_team == TEAM_TRAITOR) ) {
1705 vector vec_to_object;
1707 // AL 2-17-98: If ship is immune to sensors, can't home on it (Sandeep says so)!
1708 if ( objp->type == OBJ_SHIP ) {
1709 if ( Ships[objp->instance].flags & SF_HIDDEN_FROM_SENSORS ) {
1714 // If this is a player object, make sure there aren't already too many homers.
1715 // Only in single player. In multiplayer, we don't want to restrict it in dogfight on team vs. team.
1716 // For co-op, it's probably also OK.
1717 if (!( Game_mode & GM_MULTIPLAYER )) {
1718 int num_homers = compute_num_homing_objects(objp);
1719 if (Max_allowed_player_homers[Game_skill_level] < num_homers)
1724 dist = vm_vec_normalized_dir(&vec_to_object, &objp->pos, &weapon_objp->pos);
1726 if (objp->type == OBJ_CMEASURE)
1729 dot = vm_vec_dot(&vec_to_object, &weapon_objp->orient.fvec);
1731 if (dot > wip->fov) {
1732 if (dist < best_dist) {
1734 wp->homing_object = objp;
1735 wp->target_sig = objp->signature;
1737 weapon_maybe_alert_cmeasure_success(objp);
1744 // if (wp->homing_object->type == OBJ_CMEASURE)
1745 // nprintf(("AI", "Frame %i: Weapon #%i homing on cmeasure #%i\n", Framecount, num, objp-Objects));
1747 if (wp->homing_object == Player_obj)
1748 weapon_maybe_play_warning(wp);
1750 // if the old homing object is different that the new one, send a packet to clients
1751 if ( MULTIPLAYER_MASTER && (old_homing_objp != wp->homing_object) ) {
1752 send_homing_weapon_info( num );
1756 // Scan all countermeasures. Maybe make weapon_objp home on it.
1757 void find_homing_object_cmeasures_1(object *weapon_objp)
1762 float best_dot, dist, dot;
1764 wp = &Weapons[weapon_objp->instance];
1765 wip = &Weapon_info[wp->weapon_info_index];
1767 best_dot = wip->fov; // Note, setting to this avoids comparison below.
1769 for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
1770 if (objp->type == OBJ_CMEASURE) {
1771 vector vec_to_object;
1772 dist = vm_vec_normalized_dir(&vec_to_object, &objp->pos, &weapon_objp->pos);
1774 if (dist < MAX_CMEASURE_TRACK_DIST) {
1776 if (wip->wi_flags & WIF_HOMING_ASPECT) {
1777 chance = 1.0f/2.0f; // aspect seeker this likely to chase a countermeasure
1779 chance = 1.0f/1.5f; // heat seeker this likely to chase a countermeasure
1781 if ((objp->signature != wp->cmeasure_ignore_objnum) && (objp->signature != wp->cmeasure_chase_objnum)) {
1782 if (frand() < chance) {
1783 wp->cmeasure_ignore_objnum = objp->signature; // Don't process this countermeasure again.
1784 //nprintf(("Jim", "Frame %i: Weapon #%i ignoring cmeasure #%i\n", Framecount, OBJ_INDEX(weapon_objp), objp->signature));
1786 wp->cmeasure_chase_objnum = objp->signature; // Don't process this countermeasure again.
1787 //nprintf(("Jim", "Frame %i: Weapon #%i CHASING cmeasure #%i\n", Framecount, OBJ_INDEX(weapon_objp), objp->signature));
1791 if (objp->signature != wp->cmeasure_ignore_objnum) {
1793 dot = vm_vec_dot(&vec_to_object, &weapon_objp->orient.fvec);
1795 if (dot > best_dot) {
1796 //nprintf(("Jim", "Frame %i: Weapon #%i homing on cmeasure #%i\n", Framecount, weapon_objp-Objects, objp->signature));
1798 wp->homing_object = objp;
1799 weapon_maybe_alert_cmeasure_success(objp);
1808 // Someone launched countermeasures.
1809 // For all heat-seeking homing objects, see if should favor tracking a countermeasure instead.
1810 void find_homing_object_cmeasures()
1812 object *weapon_objp;
1814 // nprintf(("AI", "Scanning for countermeasures in frame %i\n", Framecount));
1816 if (Cmeasures_homing_check == 0)
1819 if (Cmeasures_homing_check <= 0)
1820 Cmeasures_homing_check = 1;
1822 Cmeasures_homing_check--;
1824 for (weapon_objp = GET_FIRST(&obj_used_list); weapon_objp != END_OF_LIST(&obj_used_list); weapon_objp = GET_NEXT(weapon_objp) ) {
1825 if (weapon_objp->type == OBJ_WEAPON) {
1826 weapon_info *wip = &Weapon_info[Weapons[weapon_objp->instance].weapon_info_index];
1828 if (wip->wi_flags & WIF_HOMING)
1829 find_homing_object_cmeasures_1(weapon_objp);
1835 // Find object with signature "sig" and make weapon home on it.
1836 void find_homing_object_by_sig(object *weapon_objp, int sig)
1840 object *old_homing_objp;
1842 wp = &Weapons[weapon_objp->instance];
1844 // save the old object so that multiplayer masters know whether to send a homing update packet
1845 old_homing_objp = wp->homing_object;
1847 sop = GET_FIRST(&Ship_obj_list);
1848 while(sop != END_OF_LIST(&Ship_obj_list)) {
1851 objp = &Objects[sop->objnum];
1852 if (objp->signature == sig) {
1853 wp->homing_object = objp;
1854 wp->target_sig = objp->signature;
1861 // if the old homing object is different that the new one, send a packet to clients
1862 if ( MULTIPLAYER_MASTER && (old_homing_objp != wp->homing_object) ) {
1863 send_homing_weapon_info( weapon_objp->instance );
1868 // Make weapon num home. It's also object *obj.
1869 void weapon_home(object *obj, int num, float frame_time)
1875 Assert(obj->type == OBJ_WEAPON);
1876 Assert(obj->instance == num);
1878 wip = &Weapon_info[wp->weapon_info_index];
1879 hobjp = Weapons[num].homing_object;
1881 // If not 1/2 second gone by, don't home yet.
1882 if ((hobjp == &obj_used_list) || ( f2fl(Missiontime - wp->creation_time) < 0.25f )) {
1883 // If this is a heat seeking homing missile and 1/2 second has elapsed since firing
1884 // and we don't have a target (else we wouldn't be inside the IF), find a new target.
1885 if (wip->wi_flags & WIF_HOMING_HEAT)
1886 if ( f2fl(Missiontime - wp->creation_time) > 0.5f )
1887 find_homing_object(obj, num);
1889 if (obj->phys_info.speed > wip->max_speed) {
1890 obj->phys_info.speed -= frame_time * 4;
1891 vm_vec_copy_scale( &obj->phys_info.desired_vel, &obj->orient.fvec, obj->phys_info.speed);
1892 } else if ((obj->phys_info.speed < wip->max_speed/4) && (wip->wi_flags & WIF_HOMING_HEAT)) {
1893 obj->phys_info.speed = wip->max_speed/4;
1894 vm_vec_copy_scale( &obj->phys_info.desired_vel, &obj->orient.fvec, obj->phys_info.speed);
1897 /* Removed code that makes bombs drop for a bit. They looked odd and it was confusing. People wondered where their weapons went.
1898 // Make bombs drop down for first second of life.
1899 if (wip->wi_flags & WIF_BOMB) {
1900 if (wip->lifetime - wp->lifeleft < 0.5f) {
1901 float time_scale = wip->lifetime - wp->lifeleft;
1902 vm_vec_scale_add2(&obj->phys_info.desired_vel, &obj->orient.uvec, (time_scale - 0.5f) * max(10.0f, obj->phys_info.speed/2.0f));
1909 // AL 4-8-98: If orgiginal target for aspect lock missile is lost, stop homing
1910 if (wip->wi_flags & WIF_HOMING_ASPECT) {
1911 if ( wp->target_sig > 0 ) {
1912 if ( wp->homing_object->signature != wp->target_sig ) {
1913 wp->homing_object = &obj_used_list;
1919 // AL 4-13-98: Stop homing on a subsystem if parent ship has changed
1920 if (wip->wi_flags & WIF_HOMING_HEAT) {
1921 if ( wp->target_sig > 0 ) {
1922 if ( wp->homing_object->signature != wp->target_sig ) {
1923 wp->homing_subsys = NULL;
1929 if (hobjp->type == OBJ_NONE) {
1930 find_homing_object(obj, num);
1935 switch (hobjp->type) {
1937 if (wip->wi_flags & WIF_HOMING_ASPECT)
1938 find_homing_object_by_sig(obj, wp->target_sig);
1940 find_homing_object(obj, num);
1944 if (hobjp->signature != wp->target_sig) {
1945 if (wip->wi_flags & WIF_HOMING_ASPECT)
1946 find_homing_object_by_sig(obj, wp->target_sig);
1948 find_homing_object(obj, num);
1953 // only allowed to home on bombs
1954 Assert(Weapon_info[Weapons[hobjp->instance].weapon_info_index].wi_flags & WIF_BOMB);
1955 if (wip->wi_flags & WIF_HOMING_ASPECT)
1956 find_homing_object_by_sig(obj, wp->target_sig);
1958 find_homing_object(obj, num);
1966 // See if this weapon is the nearest homing object to the object it is homing on.
1967 // If so, update some fields in the target object's ai_info.
1968 if (hobjp != &obj_used_list) {
1971 dist = vm_vec_dist_quick(&obj->pos, &hobjp->pos);
1973 if (hobjp->type == OBJ_SHIP) {
1976 aip = &Ai_info[Ships[hobjp->instance].ai_index];
1978 if ((aip->nearest_locked_object == -1) || (dist < aip->nearest_locked_distance)) {
1979 aip->nearest_locked_object = obj-Objects;
1980 aip->nearest_locked_distance = dist;
1985 // If the object it is homing on is still valid, home some more!
1986 if (hobjp != &obj_used_list) {
1989 vector target_pos; // position of what the homing missile is seeking
1991 vm_vec_zero(&target_pos);
1993 // the homing missile may be seeking a subsystem on a ship. If so, we need to calculate the
1994 // world coordinates of that subsystem so the homing missile can seek it out.
1995 // For now, March 7, 1997, MK, heat seeking homing missiles will be able to home on
1996 // any subsystem. Probably makes sense for them to only home on certain kinds of subsystems.
1997 if ( wp->homing_subsys != NULL ) {
1998 get_subsystem_world_pos(hobjp, Weapons[num].homing_subsys, &target_pos);
1999 wp->homing_pos = target_pos; // store the homing position in weapon data
2000 Assert( !vm_is_vec_nan(&wp->homing_pos) );
2005 dist = vm_vec_dist_quick(&obj->pos, &hobjp->pos);
2006 if (hobjp->type == OBJ_CMEASURE) {
2007 if (dist < CMEASURE_DETONATE_DISTANCE) {
2010 cmp = &Cmeasures[hobjp->instance];
2012 // Make this missile detonate soon. Not right away, not sure why. Seems better.
2013 if (cmp->team != wp->team) {
2014 detonate_nearby_missiles(cmp);
2015 //nprintf(("AI", "Frame %i: Weapon %i hit cmeasure, will die!\n", Framecount, wp-Weapons));
2022 if (wip->fov > 0.8f)
2025 int pick_homing_point = 0;
2026 if ( IS_VEC_NULL(&wp->homing_pos) ) {
2027 pick_homing_point = 1;
2030 // Update homing position if it hasn't been set, you're within 500 meters, or every half second, approximately.
2031 // For large objects, don't lead them.
2032 if (hobjp->radius < 40.0f) {
2033 target_pos = hobjp->pos;
2034 wp->homing_pos = target_pos;
2035 } else if ( pick_homing_point || (dist < 500.0f) || (rand_chance(flFrametime, 2.0f)) ) {
2037 if (hobjp->type == OBJ_SHIP) {
2038 if ( !pick_homing_point ) {
2039 // ensure that current attack point is only updated in world coords (ie not pick a different vertex)
2040 wp->pick_big_attack_point_timestamp = 0;
2043 if ( pick_homing_point ) {
2044 // If *any* player is parent of homing missile, then use position where lock indicator is
2045 if ( Objects[obj->parent].flags & OF_PLAYER_SHIP ) {
2048 // determine the player
2050 if ( Game_mode & GM_MULTIPLAYER ) {
2053 pnum = multi_find_player_by_object( &Objects[obj->parent] );
2055 pp = Net_players[pnum].player;
2059 // If player has apect lock, we don't want to find a homing point on the closest
2060 // octant... setting the timestamp to 0 ensures this.
2061 if (wip->wi_flags & WIF_HOMING_ASPECT) {
2062 wp->pick_big_attack_point_timestamp = 0;
2064 wp->pick_big_attack_point_timestamp = 1;
2067 if ( pp && pp->locking_subsys ) {
2068 wp->big_attack_point = pp->locking_subsys->system_info->pnt;
2070 vm_vec_zero(&wp->big_attack_point);
2075 ai_big_pick_attack_point(hobjp, obj, &target_pos, fov);
2078 target_pos = hobjp->pos;
2081 wp->homing_pos = target_pos;
2082 Assert( !vm_is_vec_nan(&wp->homing_pos) );
2083 // nprintf(("AI", "Attack point = %7.3f %7.3f %7.3f\n", target_pos.x, target_pos.y, target_pos.z));
2085 target_pos = wp->homing_pos;
2088 // Couldn't find a lock.
2089 if (IS_VEC_NULL(&target_pos))
2092 // Cause aspect seeking weapon to home at target's predicted position.
2093 // But don't use predicted position if dot product small or negative.
2094 // If do this, with a ship headed towards missile, could choose a point behind missile.``1
2095 float dist_to_target, time_to_target;
2097 dist_to_target = vm_vec_normalized_dir(&vec_to_goal, &target_pos, &obj->pos);
2098 time_to_target = dist_to_target/wip->max_speed;
2101 tvec = obj->phys_info.vel;
2102 vm_vec_normalize(&tvec);
2104 old_dot = vm_vec_dot(&tvec, &vec_to_goal);
2106 // If a weapon has missed its target, detonate it.
2107 // This solves the problem of a weapon circling the center of a subsystem that has been blown away.
2108 // Problem: It does not do impact damage, just proximity damage.
2109 if ((dist_to_target < flFrametime * obj->phys_info.speed * 4.0f + 10.0f) && (old_dot < 0.0f)) {
2110 int kill_missile = TRUE;
2111 if (wp->homing_object) {
2112 if (wp->homing_object->type == OBJ_SHIP) {
2113 ship *shipp = &Ships[wp->homing_object->instance];
2114 if (Ship_info[shipp->ship_info_index].flags & SIF_DONT_COLLIDE_INVIS) {
2115 kill_missile = FALSE;
2120 if (kill_missile && (wp->lifeleft > 0.01f)) {
2121 wp->lifeleft = 0.01f;
2125 // Only lead target if more than one second away. Otherwise can miss target. I think this
2126 // is what's causing Harbingers to miss the super destroyer. -- MK, 4/15/98
2127 if ((wip->wi_flags & WIF_HOMING_ASPECT) && (old_dot > 0.1f) && (time_to_target > 0.1f))
2128 vm_vec_scale_add2(&target_pos, &hobjp->phys_info.vel, min(time_to_target, 2.0f));
2130 //nprintf(("AI", "Dot = %7.3f, dist = %7.3f, time_to = %6.3f, deg/sec = %7.3f\n", old_dot, dist_to_target, time_to_target, angles/flFrametime));
2132 // nprintf(("AI", "Weapon %i, lifeleft = %7.3f, dist = %7.3f, dot = %6.3f\n", num, Weapons[num].lifeleft, vm_vec_dist_quick(&obj->pos, &Weapons[num].homing_object->pos), old_dot));
2134 // If a HEAT seeking (rather than ASPECT seeking) homing missile, verify that target is in viewcone.
2135 if (wip->wi_flags & WIF_HOMING_HEAT) {
2136 if ((old_dot < wip->fov) && (dist_to_target > wip->inner_radius*1.1f)) { // Delay finding new target one frame to allow detonation.
2137 find_homing_object(obj, num);
2138 return; // Maybe found a new homing object. Return, process more next frame.
2139 } else // Subtract out life based on how far from target this missile points.
2140 if (wip->fov < 0.95f) {
2141 wp->lifeleft -= flFrametime * (0.95f - old_dot);
2142 //Should only happen when time is compressed.
2143 //if (flFrametime * (1.0f - old_dot) > 1.0f)
2146 } else if (wip->wi_flags & WIF_HOMING_ASPECT) { // subtract life as if max turn is 90 degrees.
2147 if (wip->fov < 0.95f)
2148 wp->lifeleft -= flFrametime * (0.95f - old_dot);
2150 Assert(0); // Hmm, a homing missile, but not aspect or heat?
2153 // Control speed based on dot product to goal. If close to straight ahead, move
2154 // at max speed, else move slower based on how far from ahead.
2155 if (old_dot < 0.90f) {
2156 obj->phys_info.speed = max(0.2f, old_dot* (float) fabs(old_dot));
2157 if (obj->phys_info.speed < wip->max_speed*0.75f)
2158 obj->phys_info.speed = wip->max_speed*0.75f;
2160 obj->phys_info.speed = wip->max_speed;
2162 // For first second of weapon's life, it doesn't fly at top speed. It ramps up.
2163 if (Missiontime - wp->creation_time < i2f(1)) {
2166 t = f2fl(Missiontime - wp->creation_time);
2167 obj->phys_info.speed *= t*t;
2170 Assert( obj->phys_info.speed > 0.0f );
2172 vm_vec_copy_scale( &obj->phys_info.desired_vel, &obj->orient.fvec, obj->phys_info.speed);
2174 // turn the missile towards the target only if non-swarm. Homing swarm missiles choose
2175 // a different vector to turn towards, this is done in swarm_update_direction().
2176 // if ( !(wip->wi_flags & WIF_SWARM) ) {
2177 if ( wp->swarm_index < 0 ) {
2178 // nprintf(("AI", "Dot, dist = %7.3f, %7.3f, target pos = %7.3f %7.3f %7.3f\n", old_dot, vm_vec_dist_quick(&obj->pos, &target_pos), target_pos.x, target_pos.y, target_pos.z));
2179 ai_turn_towards_vector(&target_pos, obj, frame_time, wip->turn_time, NULL, NULL, 0.0f, 0, NULL);
2180 vel = vm_vec_mag(&obj->phys_info.desired_vel);
2182 vm_vec_copy_scale(&obj->phys_info.desired_vel, &obj->orient.fvec, vel);
2186 /* // If this weapon shot past its target, make it detonate.
2187 if ((old_dot < 0.0f) && (dist_to_target < 50.0f)) {
2188 if (wp->lifeleft > 0.01f)
2189 wp->lifeleft = 0.01f;
2194 // as Mike K did with ships -- break weapon into process_pre and process_post for code to execute
2195 // before and after physics movement
2197 void weapon_process_pre( object *obj, float frame_time)
2199 // if the object is a corkscrew style weapon, process it now
2200 if((obj->type == OBJ_WEAPON) && (Weapons[obj->instance].cscrew_index >= 0)){
2201 cscrew_process_pre(obj);
2204 // if the weapon is a flak weapon, maybe detonate it early
2205 if((obj->type == OBJ_WEAPON) && (Weapon_info[Weapons[obj->instance].weapon_info_index].wi_flags & WIF_FLAK) && (Weapons[obj->instance].flak_index >= 0)){
2206 flak_maybe_detonate(obj);
2210 int Homing_hits = 0, Homing_misses = 0;
2213 MONITOR( NumWeapons );
2215 // maybe play a "whizz sound" if close enough to view position
2216 void weapon_maybe_play_flyby_sound(object *weapon_objp, weapon *wp)
2218 // do a quick out if not a laser
2219 if ( Weapon_info[wp->weapon_info_index].subtype != WP_LASER ) {
2223 // don't play flyby sounds too close together
2224 if ( !timestamp_elapsed(Weapon_flyby_sound_timer) ) {
2228 if ( !(wp->weapon_flags & WF_PLAYED_FLYBY_SOUND) && (wp->weapon_flags & WF_CONSIDER_FOR_FLYBY_SOUND) ) {
2229 float dist, dot, radius;
2231 dist = vm_vec_dist_quick(&weapon_objp->pos, &Eye_position);
2234 radius = Viewer_obj->radius;
2239 if ( (dist > radius) && (dist < 55) ) {
2240 vector vec_to_weapon;
2242 vm_vec_sub(&vec_to_weapon, &weapon_objp->pos, &Eye_position);
2243 vm_vec_normalize(&vec_to_weapon);
2245 // ensure laser is in front of eye
2246 dot = vm_vec_dot(&vec_to_weapon, &Eye_matrix.fvec);
2251 // ensure that laser is moving in similar direction to fvec
2252 dot = vm_vec_dot(&vec_to_weapon, &weapon_objp->orient.fvec);
2254 // nprintf(("Alan", "Weapon dot: %.2f\n", dot));
2255 if ( (dot < -0.80) && (dot > -0.98) ) {
2256 snd_play_3d( &Snds[SND_WEAPON_FLYBY], &weapon_objp->pos, &Eye_position );
2257 Weapon_flyby_sound_timer = timestamp(200);
2258 wp->weapon_flags |= WF_PLAYED_FLYBY_SOUND;
2264 // process a weapon after physics movement. MWA reorders some of the code on 8/13 for multiplayer. When
2265 // adding something to this function, decide whether or not a client in a multiplayer game needs to do
2266 // what is normally done in a single player game. Things like plotting an object on a radar, effect
2267 // for exhaust are things that are done on all machines. Things which calculate weapon targets, new
2268 // velocities, etc, are server only functions and should go after the if ( !MULTIPLAYER_MASTER ) statement
2269 // See Allender if you cannot decide what to do.
2270 void weapon_process_post(object * obj, float frame_time)
2276 MONITOR_INC( NumWeapons, 1 );
2278 Assert(obj->type == OBJ_WEAPON);
2280 num = obj->instance;
2283 int objnum = OBJ_INDEX(obj);
2284 Assert( Weapons[num].objnum == objnum );
2289 wp->lifeleft -= frame_time;
2290 wip = &Weapon_info[wp->weapon_info_index];
2292 // check life left. Multiplayer client code will go through here as well. We must be careful in weapon_hit
2293 // when killing a missile that spawn child weapons!!!!
2294 if ( wp->lifeleft < 0.0f ) {
2295 if ( wip->subtype & WP_MISSILE ) {
2296 if(Game_mode & GM_MULTIPLAYER){
2297 if ( !MULTIPLAYER_CLIENT || (MULTIPLAYER_CLIENT && (wp->lifeleft < -2.0f)) || (MULTIPLAYER_CLIENT && (wip->wi_flags & WIF_CHILD))) { // don't call this function multiplayer client -- host will send this packet to us
2298 // nprintf(("AI", "Frame %i: Weapon %i detonated, dist = %7.3f!\n", Framecount, obj-Objects));
2299 weapon_detonate(obj);
2302 // nprintf(("AI", "Frame %i: Weapon %i detonated, dist = %7.3f!\n", Framecount, obj-Objects));
2303 weapon_detonate(obj);
2305 if (wip->wi_flags & WIF_HOMING) {
2307 // nprintf(("AI", "Miss! Hits = %i/%i\n", Homing_hits, (Homing_hits + Homing_misses)));
2310 obj->flags |= OF_SHOULD_BE_DEAD;
2311 // demo_do_flag_dead(OBJ_INDEX(obj));
2317 // plot homing missiles on the radar
2318 if (wip->wi_flags & WIF_HOMING) {
2319 if ( hud_gauge_active(HUD_RADAR) ) {
2320 radar_plot_object( obj );
2325 if ((wip->wi_flags & WIF_TRAIL) && !(wip->wi_flags & WIF_CORKSCREW)) {
2326 if ( wp->trail_num > -1 ) {
2327 if (trail_stamp_elapsed(wp->trail_num)) {
2329 trail_add_segment( wp->trail_num, &obj->pos );
2331 trail_set_stamp(wp->trail_num);
2333 trail_set_segment( wp->trail_num, &obj->pos );
2339 if ( wip->wi_flags & WIF_THRUSTER ) {
2340 ship_do_weapon_thruster_frame( wp, obj, flFrametime );
2343 // maybe play a "whizz sound" if close enough to view position
2345 if ( Weapon_flyby_sound_enabled ) {
2346 weapon_maybe_play_flyby_sound(obj, wp);
2349 weapon_maybe_play_flyby_sound(obj, wp);
2352 // If our target is still valid, then update some info.
2353 if (wp->target_num != -1) {
2354 if (Objects[wp->target_num].signature == wp->target_sig) {
2358 vm_vec_avg(&v0, &obj->pos, &obj->last_pos);
2360 cur_dist = vm_vec_dist_quick(&v0, &Objects[wp->target_num].pos);
2362 if (cur_dist < wp->nearest_dist) {
2363 wp->nearest_dist = cur_dist;
2364 } else if (cur_dist > wp->nearest_dist + 1.0f) {
2367 ai_info *parent_aip;
2368 float lead_scale = 0.0f;
2371 if (obj->parent != Player_obj-Objects) {
2372 parent_aip = &Ai_info[Ships[Objects[obj->parent].instance].ai_index];
2373 lead_scale = parent_aip->lead_scale;
2376 vm_vec_normalized_dir(&tvec, &v0, &Objects[wp->target_num].pos);
2377 dot = vm_vec_dot(&tvec, &Objects[wp->target_num].orient.fvec);
2378 // nprintf(("AI", "Miss dot = %7.3f, dist = %7.3f, lead_scale = %7.3f\n", dot, cur_dist, lead_scale));
2379 wp->target_num = -1;
2381 // Learn! If over-shooting or under-shooting, compensate.
2382 // Really need to compensate for left/right errors. This does no good against someone circling
2383 // in a plane perpendicular to the attacker's forward vector.
2384 if (parent_aip != NULL) {
2385 if (cur_dist > 100.0f)
2386 parent_aip->lead_scale = 0.0f;
2389 parent_aip->lead_scale += cur_dist/2000.0f;
2390 } else if (dot > 0.1f) {
2391 parent_aip->lead_scale -= cur_dist/2000.0f;
2394 if (fl_abs(parent_aip->lead_scale) > 1.0f){
2395 parent_aip->lead_scale *= 0.9f;
2402 if(wip->wi_flags & WIF_PARTICLE_SPEW){
2403 weapon_maybe_spew_particle(obj);
2406 // a single player or multiplayer server function -- it affects actual weapon movement.
2407 if (wip->wi_flags & WIF_HOMING) {
2408 weapon_home(obj, num, frame_time);
2410 /* if (wip->wi_flags & WIF_BOMB) {
2411 if (wip->lifetime - obj->lifeleft < 1.0f) {
2416 // If this is a swarm type missile,
2417 // if ( wip->wi_flags & WIF_SWARM )
2418 if ( wp->swarm_index >= 0 ) {
2419 swarm_update_direction(obj, frame_time);
2422 if( wp->cscrew_index >= 0) {
2423 cscrew_process_post(obj);
2428 // Update weapon tracking information.
2429 void weapon_set_tracking_info(int weapon_objnum, int parent_objnum, int target_objnum, int target_is_locked, ship_subsys *target_subsys)
2432 object *parent_objp;
2435 int targeting_same = 0;
2437 if ( weapon_objnum < 0 ) {
2441 Assert(Objects[weapon_objnum].type == OBJ_WEAPON);
2443 wp = &Weapons[Objects[weapon_objnum].instance];
2444 wip = &Weapon_info[wp->weapon_info_index];
2445 parent_objp = &Objects[parent_objnum];
2447 Assert(parent_objp->type == OBJ_SHIP);
2448 ai_index = Ships[parent_objp->instance].ai_index;
2450 if ( ai_index >= 0 ) {
2451 int target_team = -1;
2452 if ( target_objnum >= 0 ) {
2453 int obj_type = Objects[target_objnum].type;
2454 if ( (obj_type == OBJ_SHIP) || (obj_type == OBJ_WEAPON) ) {
2455 target_team = obj_team(&Objects[target_objnum]);
2459 // determining if we're targeting the same team
2460 if(Ships[parent_objp->instance].team == target_team){
2466 if ((target_objnum != -1) && (!targeting_same || ((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT) && (target_team == TEAM_TRAITOR))) ) {
2467 wp->target_num = target_objnum;
2468 wp->target_sig = Objects[target_objnum].signature;
2469 wp->nearest_dist = 99999.0f;
2470 if ( (wip->wi_flags & WIF_HOMING_ASPECT) && target_is_locked) {
2471 wp->homing_object = &Objects[target_objnum];
2472 wp->homing_subsys = target_subsys;
2473 weapon_maybe_play_warning(wp);
2474 } else if ( wip->wi_flags & WIF_HOMING_HEAT ) {
2475 // Make a heat seeking missile try to home. If the target is outside the view cone, it will
2476 // immediately drop it and try to find one in its view cone.
2477 if (target_objnum != -1) {
2478 wp->homing_object = &Objects[target_objnum];
2479 weapon_maybe_play_warning(wp);
2481 wp->homing_object = &obj_used_list;
2483 wp->homing_subsys = target_subsys;
2486 wp->target_num = -1;
2487 wp->target_sig = -1;
2490 // If missile is locked on target, increase its lifetime by 20% since missiles can be fired at limit of range
2491 // as defined by velocity*lifeleft, but missiles often slow down a bit, plus can be fired at a moving away target.
2492 // Confusing to many players when their missiles run out of gas before getting to target.
2493 // DB - removed 7:14 pm 9/6/99. was totally messing up lifetimes for all weapons.
2494 // MK, 7:11 am, 9/7/99. Put it back in, but with a proper check here to make sure it's an aspect seeker and
2495 // put a sanity check in the color changing laser code that was broken by this code.
2496 if (target_is_locked && (wp->target_num != -1) && (wip->wi_flags & WIF_HOMING_ASPECT) ) {
2497 wp->lifeleft *= 1.2f;
2500 ai_update_danger_weapon(target_objnum, weapon_objnum);
2505 // weapon_create() will create a weapon object
2507 // Returns: index of weapon in the Objects[] array, -1 if the weapon object was not created
2508 int Weapons_created = 0;
2509 int weapon_create( vector * pos, matrix * orient, int weapon_id, int parent_objnum, int secondary_flag, int group_id, int is_locked )
2513 object *objp, *parent_objp;
2517 Assert(weapon_id >= 0 && weapon_id < Num_weapon_types);
2519 // beam weapons should never come through here!
2520 Assert(!(Weapon_info[weapon_id].wi_flags & WIF_BEAM));
2523 if (Num_weapons >= MAX_WEAPONS-5) {
2525 //No, do remove for AI ships -- MK, 3/12/98 // don't need to try and delete weapons for ai ships
2526 //if ( !(Objects[parent_objnum].flags & OF_PLAYER_SHIP) )
2529 num_deleted = collide_remove_weapons();
2530 nprintf(("WARNING", "Deleted %d weapons because of lack of slots\n", num_deleted));
2531 if (num_deleted == 0){
2536 for (n=0; n<MAX_WEAPONS; n++ ){
2537 if (Weapons[n].weapon_info_index < 0){
2542 if (n == MAX_WEAPONS) {
2543 // if we supposedly deleted weapons above, what happened here!!!!
2545 Int3(); // get allender -- something funny is going on!!!
2552 objnum = obj_create( OBJ_WEAPON, parent_objnum, n, orient, pos, 2.0f, OF_RENDERS | OF_COLLIDES | OF_PHYSICS );
2553 Assert(objnum >= 0);
2554 Assert(First_secondary_index != -1);
2555 objp = &Objects[objnum];
2558 if(parent_objnum >= 0){
2559 parent_objp = &Objects[parent_objnum];
2564 wip = &Weapon_info[weapon_id];
2566 // check if laser or dumbfire missile
2567 // set physics flag to allow optimization
2568 if ((wip->subtype == WP_LASER) || ((wip->subtype == WP_MISSILE) && !(wip->wi_flags & WIF_HOMING))) {
2570 objp->phys_info.flags |= PF_CONST_VEL;
2573 wp->weapon_info_index = weapon_id;
2574 wp->lifeleft = wip->lifetime;
2576 wp->objnum = objnum;
2577 wp->homing_object = &obj_used_list; // Assume not homing on anything.
2578 wp->homing_subsys = NULL;
2579 wp->creation_time = Missiontime;
2580 wp->group_id = group_id;
2582 // we don't necessarily need a parent
2583 if(parent_objp != NULL){
2584 Assert(parent_objp->type == OBJ_SHIP); // Get Mike, a non-ship has fired a weapon!
2585 Assert((parent_objp->instance >= 0) && (parent_objp->instance < MAX_SHIPS));
2586 wp->team = Ships[parent_objp->instance].team;
2587 wp->species = Ship_info[Ships[parent_objp->instance].ship_info_index].species;
2592 wp->turret_subsys = NULL;
2593 vm_vec_zero(&wp->homing_pos);
2594 wp->weapon_flags = 0;
2595 wp->target_sig = -1;
2596 wp->cmeasure_ignore_objnum = -1;
2597 wp->cmeasure_chase_objnum = -1;
2599 // Init the thruster info
2600 wp->thruster_bitmap = -1;
2601 wp->thruster_frame = 0.0f;
2602 wp->thruster_glow_bitmap = -1;
2603 wp->thruster_glow_noise = 1.0f;
2604 wp->thruster_glow_frame = 0.0f;
2606 if ( wip->wi_flags & WIF_SWARM ) {
2607 wp->swarm_index = (short)swarm_create();
2609 wp->swarm_index = -1;
2612 // if this is a particle spewing weapon, setup some stuff
2613 if(wip->wi_flags & WIF_PARTICLE_SPEW){
2614 wp->particle_spew_time = -1;
2617 // assign the network signature. The starting sig is sent to all clients, so this call should
2618 // result in the same net signature numbers getting assigned to every player in the game
2619 if ( Game_mode & GM_MULTIPLAYER ) {
2620 if(wip->subtype == WP_MISSILE){
2621 Objects[objnum].net_signature = multi_assign_network_signature( MULTI_SIG_NON_PERMANENT );
2623 // for weapons that respawn, add the number of respawnable weapons to the net signature pool
2624 // to reserve N signatures for the spawned weapons
2625 if ( wip->wi_flags & WIF_SPAWN ){
2626 multi_set_network_signature( (ushort)(Objects[objnum].net_signature + wip->spawn_count), MULTI_SIG_NON_PERMANENT );
2629 Objects[objnum].net_signature = multi_assign_network_signature( MULTI_SIG_NON_PERMANENT );
2631 // for multiplayer clients, when creating lasers, add some more life to the lasers. This helps
2632 // to overcome some problems associated with lasers dying on client machine before they get message
2633 // from server saying it hit something.
2634 // removed 1/13/98 -- MWA if ( MULTIPLAYER_CLIENT && (wip->subtype == WP_LASER) )
2635 // removed 1/13/98 -- MWA wp->lifeleft += 1.5f;
2638 // Make remote detonate missiles look like they're getting detonated by firer simply by giving them variable lifetimes.
2639 if (!(Objects[parent_objnum].flags & OF_PLAYER_SHIP) && (wip->wi_flags & WIF_REMOTE)) {
2642 if ( Game_mode & GM_NORMAL ){
2645 rand_val = static_randf(Objects[objnum].net_signature);
2648 wp->lifeleft = wp->lifeleft/2.0f + rand_val * wp->lifeleft/2.0f;
2651 objp->phys_info.mass = wip->mass;
2652 objp->phys_info.side_slip_time_const = 0.0f;
2653 objp->phys_info.rotdamp = 0.0f;
2654 vm_vec_zero(&objp->phys_info.max_vel);
2655 objp->phys_info.max_vel.z = wip->max_speed;
2656 vm_vec_zero(&objp->phys_info.max_rotvel);
2657 objp->shields[0] = wip->damage;
2658 if (wip->wi_flags & WIF_BOMB){
2659 objp->hull_strength = 50.0f;
2661 objp->hull_strength = 0.0f;
2664 if ( wip->subtype == WP_MISSILE ){
2665 objp->radius = model_get_radius(wip->model_num);
2666 } else if ( wip->subtype == WP_LASER ) {
2667 objp->radius = wip->laser_head_radius;
2670 // Set desired velocity and initial velocity.
2671 // For lasers, velocity is always the same.
2672 // For missiles, it is a small amount plus the firing ship's velocity.
2673 // For missiles, the velocity trends towards some goal.
2674 // Note: If you change how speed works here, such as adding in speed of parent ship, you'll need to change the AI code
2675 // that predicts collision points. See Mike Kulas or Dave Andsager. (Or see ai_get_weapon_speed().)
2676 if (!(wip->wi_flags & WIF_HOMING)) {
2677 vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.fvec, objp->phys_info.max_vel.z );
2678 objp->phys_info.vel = objp->phys_info.desired_vel;
2679 objp->phys_info.speed = vm_vec_mag(&objp->phys_info.desired_vel);
2681 // For weapons that home, set velocity to sum of forward component of parent's velocity and 1/4 weapon's max speed.
2682 // Note that it is important to extract the forward component of the parent's velocity to factor out sliding, else
2683 // the missile will not be moving forward.
2684 if(parent_objp != NULL){
2685 vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.fvec, vm_vec_dot(&parent_objp->phys_info.vel, &parent_objp->orient.fvec) + objp->phys_info.max_vel.z/4 );
2687 vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.fvec, objp->phys_info.max_vel.z/4 );
2689 objp->phys_info.vel = objp->phys_info.desired_vel;
2690 objp->phys_info.speed = vm_vec_mag(&objp->phys_info.vel);
2693 // create the corkscrew
2694 if ( wip->wi_flags & WIF_CORKSCREW ) {
2695 wp->cscrew_index = (short)cscrew_create(objp);
2697 wp->cscrew_index = -1;
2700 // if this is a flak weapon shell, make it so
2701 // NOTE : this function will change some fundamental things about the weapon object
2702 if ( wip->wi_flags & WIF_FLAK ){
2705 wp->flak_index = -1;
2708 wp->missile_list_index = -1;
2709 // If this is a missile, then add it to the Missile_obj_list
2710 if ( wip->subtype == WP_MISSILE ) {
2711 wp->missile_list_index = missile_obj_list_add(objnum);
2714 if (wip->wi_flags & WIF_TRAIL /*&& !(wip->wi_flags & WIF_CORKSCREW) */) {
2715 wp->trail_num = trail_create(wip->tr_info);
2717 if ( wp->trail_num > -1 ) {
2718 // Add two segments. One to stay at launch pos, one to move.
2719 trail_add_segment( wp->trail_num, &objp->pos );
2720 trail_add_segment( wp->trail_num, &objp->pos );
2724 // Ensure weapon flyby sound doesn't get played for player lasers
2725 if ( parent_objp == Player_obj ) {
2726 wp->weapon_flags |= WF_PLAYED_FLYBY_SOUND;
2729 wp->pick_big_attack_point_timestamp = timestamp(1);
2731 // Set detail levels for POF-type weapons.
2732 if (Weapon_info[wp->weapon_info_index].model_num != -1) {
2735 pm = model_get(Weapon_info[wp->weapon_info_index].model_num);
2737 for (i=0; i<pm->n_detail_levels; i++){
2738 pm->detail_depth[i] = (objp->radius*20.0f + 20.0f) * i;
2742 // if the weapon was fired locked
2744 wp->weapon_flags |= WF_LOCKED_WHEN_FIRED;
2751 // Spawn child weapons from object *objp.
2752 void spawn_child_weapons(object *objp)
2757 ushort starting_sig;
2761 Assert(objp->type == OBJ_WEAPON);
2762 Assert((objp->instance >= 0) && (objp->instance < MAX_WEAPONS));
2764 wp = &Weapons[objp->instance];
2765 Assert((wp->weapon_info_index >= 0) && (wp->weapon_info_index < MAX_WEAPON_TYPES));
2766 wip = &Weapon_info[wp->weapon_info_index];
2768 child_id = wip->spawn_type;
2770 parent_num = objp->parent;
2772 if ((Objects[parent_num].type != objp->parent_type) || (Objects[parent_num].signature != objp->parent_sig)) {
2773 mprintf(("Warning: Parent of spawn weapon does not exist. Not spawning.\n"));
2778 if ( Game_mode & GM_MULTIPLAYER ) {
2779 // get the next network signature and save it. Set the next usable network signature to be
2780 // the passed in objects signature + 1. We "reserved" N of these slots when we created objp
2781 // for it's spawned children.
2782 starting_sig = multi_get_next_network_signature( MULTI_SIG_NON_PERMANENT );
2783 multi_set_network_signature( objp->net_signature, MULTI_SIG_NON_PERMANENT );
2786 for (i=0; i<wip->spawn_count; i++) {
2791 // for multiplayer, use the static randvec functions based on the network signatures to provide
2792 // the randomness so that it is the same on all machines.
2793 if ( Game_mode & GM_MULTIPLAYER ){
2794 static_randvec(objp->net_signature + i, &tvec);
2796 vm_vec_rand_vec_quick(&tvec);
2798 vm_vec_scale_add(&pos, &objp->pos, &tvec, objp->radius);
2800 vm_vector_2_matrix(&orient, &tvec, NULL, NULL);
2801 weapon_objnum = weapon_create(&pos, &orient, child_id, parent_num, 1, -1, wp->weapon_flags & WF_LOCKED_WHEN_FIRED);
2803 // Assign a little randomness to lifeleft so they don't all disappear at the same time.
2804 if (weapon_objnum != -1) {
2807 if ( Game_mode & GM_NORMAL ){
2810 rand_val = static_randf(objp->net_signature + i);
2813 Weapons[Objects[weapon_objnum].instance].lifeleft *= rand_val*0.4f + 0.8f;
2818 // in multiplayer, reset the next network signature to the one that was saved.
2819 if ( Game_mode & GM_MULTIPLAYER ){
2820 multi_set_network_signature( starting_sig, MULTI_SIG_NON_PERMANENT );
2824 // -----------------------------------------------------------------------
2825 // weapon_hit_do_sound()
2827 // Play a sound effect when a weapon hits a ship
2829 // To elimate the "stereo" effect of two lasers hitting at nearly
2830 // the same time, and to reduce the number of sound channels used,
2831 // only play one impact sound if IMPACT_SOUND_DELTA has elapsed
2833 // Note: Uses Weapon_impact_timer global for timer variable
2835 void weapon_hit_do_sound(object *hit_obj, weapon_info *wip, vector *hitpos)
2840 // If non-missiles (namely lasers) expire without hitting a ship, don't play impact sound
2841 if ( wip->subtype != WP_MISSILE ) {
2843 // flak weapons make sounds
2844 if(wip->wi_flags & WIF_FLAK){
2845 snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
2850 switch(hit_obj->type) {
2856 if ( timestamp_elapsed(Weapon_impact_timer) ) {
2857 snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
2858 Weapon_impact_timer = timestamp(IMPACT_SOUND_DELTA);
2868 if ( hit_obj == NULL ) {
2869 snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
2873 if ( timestamp_elapsed(Weapon_impact_timer) ) {
2876 if ( hit_obj->type == OBJ_SHIP ) {
2877 shield_str = ship_quadrant_shield_strength(hit_obj, hitpos);
2882 // play a shield hit if shields are above 10% max in this quadrant
2883 if ( shield_str > 0.1f ) {
2887 if ( !is_hull_hit ) {
2888 // Play a shield impact sound effect
2889 if ( hit_obj == Player_obj ) {
2890 snd_play_3d( &Snds[SND_SHIELD_HIT_YOU], hitpos, &Eye_position );
2891 // AL 12-15-97: Add missile impact sound even when shield is hit
2892 if ( wip->subtype == WP_MISSILE ) {
2893 snd_play_3d( &Snds[SND_PLAYER_HIT_MISSILE], hitpos, &Eye_position);
2896 snd_play_3d( &Snds[SND_SHIELD_HIT], hitpos, &Eye_position );
2899 // Play a hull impact sound effect
2900 switch ( wip->subtype ) {
2902 if ( hit_obj == Player_obj )
2903 snd_play_3d( &Snds[SND_PLAYER_HIT_LASER], hitpos, &Eye_position );
2905 if ( wip->impact_snd != -1 ) {
2906 snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
2911 if ( hit_obj == Player_obj )
2912 snd_play_3d( &Snds[SND_PLAYER_HIT_MISSILE], hitpos, &Eye_position);
2914 if ( wip->impact_snd != -1 ) {
2915 snd_play_3d( &Snds[wip->impact_snd], hitpos, &Eye_position );
2920 nprintf(("Warning","WARNING ==> Cannot determine sound to play for weapon impact\n"));
2925 Weapon_impact_timer = timestamp(IMPACT_SOUND_DELTA);
2929 // distrupt any subsystems that fall into damage sphere of this Electronics missile
2931 // input: ship_obj => pointer to ship that holds subsystem
2932 // blast_pos => world pos of weapon blast
2933 // wi_index => weapon info index of weapon causing blast
2934 void weapon_do_electronics_affect(object *ship_objp, vector *blast_pos, int wi_index)
2939 model_subsystem *psub;
2940 vector subsys_world_pos;
2943 shipp = &Ships[ship_objp->instance];
2944 wip = &Weapon_info[wi_index];
2946 for ( ss = GET_FIRST(&shipp->subsys_list); ss != END_OF_LIST(&shipp->subsys_list); ss = GET_NEXT(ss) ) {
2947 psub = ss->system_info;
2949 // convert subsys point to world coords
2950 vm_vec_unrotate(&subsys_world_pos, &psub->pnt, &ship_objp->orient);
2951 vm_vec_add2(&subsys_world_pos, &ship_objp->pos);
2953 // see if subsys point is within damage sphere
2954 dist = vm_vec_dist_quick(blast_pos, &subsys_world_pos);
2955 if ( dist < wip->outer_radius ) {
2956 ship_subsys_set_disrupted(ss, fl2i(6000.0f + frand()*4000.0f));
2961 // ----------------------------------------------------------------------
2962 // weapon_area_calc_damage()
2964 // Calculate teh damage for an object based on the location of an area-effect
2967 // input: objp => object pointer ship receiving blast effect
2968 // pos => world pos of blast center
2969 // inner_rad => smallest radius at which full damage is done
2970 // outer_rad => radius at which no damage is done
2971 // max_blast => maximum blast possible from explosion
2972 // max_damage => maximum damage possible from explosion
2973 // blast => OUTPUT PARAMETER: receives blast value from explosion
2974 // damage => OUTPUT PARAMETER: receives damage value from explosion
2975 // limit => a limit on the area, needed for shockwave damage
2977 // returns: no damage occurred => -1
2978 // damage occured => 0
2980 int weapon_area_calc_damage(object *objp, vector *pos, float inner_rad, float outer_rad, float max_blast, float max_damage, float *blast, float *damage, float limit)
2982 float dist, max_dist, min_dist;
2984 // only blast ships and asteroids
2985 if ( (objp->type != OBJ_SHIP) && (objp->type != OBJ_ASTEROID)) {
2989 max_dist = objp->radius + outer_rad;
2990 dist = vm_vec_dist_quick(&objp->pos, pos);
2991 if ( (dist > max_dist) || (dist > (limit+objp->radius)) ) {
2992 return -1; // spheres don't intersect at all
2995 if ( dist < (inner_rad+objp->radius) ) {
2996 // damage is maximum within inner radius
2997 *damage = max_damage;
3000 float dist_to_outer_rad_squared, total_dist_squared;
3001 min_dist = dist - objp->radius;
3002 Assert(min_dist < outer_rad);
3003 dist_to_outer_rad_squared = (outer_rad-min_dist)*(outer_rad-min_dist);
3004 total_dist_squared = (inner_rad-outer_rad)*(inner_rad-outer_rad);
3005 // AL 2-24-98: drop off damage relative to square of distance
3006 Assert(dist_to_outer_rad_squared <= total_dist_squared);
3007 *damage = max_damage * dist_to_outer_rad_squared/total_dist_squared;
3010 // *damage = (min_dist - outer_rad) * max_damage/(inner_rad - outer_rad);
3011 *blast = (min_dist - outer_rad) * max_blast /(inner_rad - outer_rad);
3014 // nprintf(("AI", "Frame %i: Damage = %7.3f, %7.3f meters away.\n", Framecount, *damage, dist));
3019 // ----------------------------------------------------------------------
3020 // weapon_area_apply_blast()
3022 // Apply the blast effects of an explosion to a ship
3024 // input: force_apply_pos => world pos of where force is applied to object
3025 // ship_obj => object pointer of ship receiving the blast
3026 // blast_pos => world pos of blast center
3027 // blast => force of blast
3028 // make_shockwave => boolean, whether to create a shockwave or not
3030 void weapon_area_apply_blast(vector *force_apply_pos, object *ship_obj, vector *blast_pos, float blast, int make_shockwave)
3032 #define SHAKE_CONST 3000
3033 vector force, vec_blast_to_ship, vec_ship_to_impact;
3036 // apply blast force based on distance from center of explosion
3037 vm_vec_sub(&vec_blast_to_ship, &ship_obj->pos, blast_pos);
3038 vm_vec_normalize_safe(&vec_blast_to_ship);
3039 vm_vec_copy_scale(&force, &vec_blast_to_ship, blast );
3042 vm_vec_sub(&vec_ship_to_impact, blast_pos, &ship_obj->pos);
3044 pm = model_get(Ships[ship_obj->instance].modelnum);
3045 Assert ( pm != NULL );
3047 if (make_shockwave) {
3048 physics_apply_shock (&force, blast, &ship_obj->phys_info, &ship_obj->orient, &pm->mins, &pm->maxs, pm->rad);
3049 if (ship_obj == Player_obj) {
3050 joy_ff_play_vector_effect(&vec_blast_to_ship, blast * 2.0f);
3053 ship_apply_whack( &force, &vec_ship_to_impact, ship_obj);
3057 // ----------------------------------------------------------------------
3058 // weapon_do_area_effect()
3060 // Do the area effect for a weapon
3062 // input: wobjp => object pointer to weapon causing explosion
3063 // pos => world pos of explosion center
3064 // other_obj => object pointer to ship that weapon impacted on (can be NULL)
3066 void weapon_do_area_effect(object *wobjp, vector *pos, object *other_obj)
3071 float damage, blast;
3073 wip = &Weapon_info[Weapons[wobjp->instance].weapon_info_index];
3074 wp = &Weapons[wobjp->instance];
3075 Assert(wip->inner_radius != 0);
3077 // only blast ships and asteroids
3078 for ( objp = GET_FIRST(&obj_used_list); objp !=END_OF_LIST(&obj_used_list); objp = GET_NEXT(objp) ) {
3079 if ( (objp->type != OBJ_SHIP) && (objp->type != OBJ_ASTEROID) ) {
3083 if ( objp->type == OBJ_SHIP ) {
3084 // don't blast navbuoys
3085 if ( ship_get_SIF(objp->instance) & SIF_NAVBUOY ) {
3090 if ( weapon_area_calc_damage(objp, pos, wip->inner_radius, wip->outer_radius, wip->blast_force, wip->damage, &blast, &damage, wip->outer_radius) == -1 ){
3095 damage *= weapon_get_damage_scale(wip, wobjp, other_obj);
3097 switch ( objp->type ) {
3099 ship_apply_global_damage(objp, wobjp, pos, damage);
3100 weapon_area_apply_blast(NULL, objp, pos, blast, 0);
3103 asteroid_hit(objp, NULL, NULL, damage);
3112 // if this weapon has the "Electronics" flag set, then disrupt subsystems in sphere
3113 if ( (other_obj != NULL) && (wip->wi_flags & WIF_ELECTRONICS) ) {
3114 if ( other_obj->type == OBJ_SHIP ) {
3115 weapon_do_electronics_affect(other_obj, pos, Weapons[wobjp->instance].weapon_info_index);
3121 // ----------------------------------------------------------------------
3124 // This function is called when a weapon hits something (or, in the case of
3125 // missiles explodes for any particular reason)
3127 void weapon_hit( object * weapon_obj, object * other_obj, vector * hitpos )
3129 Assert(weapon_obj != NULL);
3130 if(weapon_obj == NULL){
3133 Assert((weapon_obj->type == OBJ_WEAPON) && (weapon_obj->instance >= 0) && (weapon_obj->instance < MAX_WEAPONS));
3134 if((weapon_obj->type != OBJ_WEAPON) || (weapon_obj->instance < 0) || (weapon_obj->instance >= MAX_WEAPONS)){
3138 int num = weapon_obj->instance;
3139 int weapon_type = Weapons[num].weapon_info_index;
3140 object *weapon_parent_objp;
3144 Assert((weapon_type >= 0) && (weapon_type < MAX_WEAPONS));
3145 if((weapon_type < 0) || (weapon_type >= MAX_WEAPONS)){
3148 wip = &Weapon_info[weapon_type];
3149 weapon_parent_objp = &Objects[weapon_obj->parent];
3151 // if this is the player ship, and is a laser hit, skip it. wait for player "pain" to take care of it
3152 // if( ((wip->subtype != WP_LASER) || !MULTIPLAYER_CLIENT) && (Player_obj != NULL) && (other_obj == Player_obj) ){
3153 if((other_obj != Player_obj) || (wip->subtype != WP_LASER) || !MULTIPLAYER_CLIENT){
3154 weapon_hit_do_sound(other_obj, wip, hitpos);
3157 if ( wip->impact_weapon_expl_index > -1 ) {
3158 int expl_ani_handle = weapon_get_expl_handle(wip->impact_weapon_expl_index, hitpos, wip->impact_explosion_radius);
3159 particle_create( hitpos, &vmd_zero_vector, 0.0f, wip->impact_explosion_radius, PARTICLE_BITMAP_PERSISTENT, expl_ani_handle );
3162 weapon_obj->flags |= OF_SHOULD_BE_DEAD;
3164 int sw_flag = SW_WEAPON;
3166 // check if this is an area effect weapon
3167 if ( wip->wi_flags & WIF_AREA_EFFECT ) {
3168 // if ( wip->subtype & WP_MISSILE && wip->wi_flags & WIF_AREA_EFFECT ) {
3169 if ( wip->wi_flags & WIF_SHOCKWAVE ) {
3170 float actual_damage = wip->damage;
3171 // Shockwaves caused by weapons hitting weapons are 1/4 as powerful
3172 if ( ((other_obj) && (other_obj->type == OBJ_WEAPON)) || (Weapons[num].weapon_flags & WF_DESTROYED_BY_WEAPON)) {
3173 actual_damage /= 4.0f;
3174 sw_flag |= SW_WEAPON_KILL;
3176 shockwave_create_info sci;
3177 sci.blast = wip->blast_force;
3178 sci.damage = actual_damage;
3179 sci.inner_rad = wip->inner_radius;
3180 sci.outer_rad = wip->outer_radius;
3181 sci.speed = wip->shockwave_speed;
3182 sci.rot_angle = 0.0f;
3184 shockwave_create(OBJ_INDEX(weapon_obj), hitpos, &sci, sw_flag);
3185 // snd_play_3d( &Snds[SND_SHOCKWAVE_IMPACT], hitpos, &Eye_position );
3188 weapon_do_area_effect(weapon_obj, hitpos, other_obj);
3192 // check if this is an EMP weapon
3193 if(wip->wi_flags & WIF_EMP){
3194 emp_apply(&weapon_obj->pos, wip->inner_radius, wip->outer_radius, wip->emp_intensity, wip->emp_time);
3197 // spawn weapons - note the change from FS 1 multiplayer.
3198 if (wip->wi_flags & WIF_SPAWN){
3199 spawn_child_weapons(weapon_obj);
3203 void weapon_detonate(object *objp)
3205 Assert(objp != NULL);
3209 Assert((objp->type == OBJ_WEAPON) && (objp->instance >= 0));
3210 if((objp->type != OBJ_WEAPON) || (objp->instance < 0)){
3214 // send a detonate packet in multiplayer
3215 if(MULTIPLAYER_MASTER){
3216 send_weapon_detonate_packet(objp);
3220 weapon_hit(objp, NULL, &objp->pos);
3223 // Return the Weapon_info[] index of the weapon with name *name.
3224 int weapon_name_lookup(char *name)
3228 for ( i=0; i < Num_weapon_types; i++) {
3229 if (!stricmp(name, Weapon_info[i].name)) {
3237 // Group_id: If you should quad lasers, they should all have the same group id.
3238 // This will be used to optimize lighting, since each group only needs to cast one light.
3239 // Call this to get a new group id, then pass it to each weapon_create call for all the
3240 // weapons in the group. Number will be between 0 and WEAPON_MAX_GROUP_IDS and will
3242 int weapon_create_group_id()
3244 static int current_id = 0;
3249 if ( current_id >= WEAPON_MAX_GROUP_IDS ) {
3256 void weapons_page_in()
3260 // Page in bitmaps for all weapons
3261 for (i=0; i<Num_weapon_types; i++ ) {
3262 weapon_info *wip = &Weapon_info[i];
3264 wip->wi_flags &= (~WIF_THRUSTER); // Assume no thrusters
3266 switch( wip->render_type ) {
3269 wip->model_num = model_load( wip->pofbitmap_name, 0, NULL );
3271 polymodel *pm = model_get( wip->model_num );
3273 // If it has a model, and the model pof has thrusters, then set
3275 if ( pm->n_thrusters > 0 ) {
3276 //mprintf(( "Weapon %s has thrusters!\n", wip->name ));
3277 wip->wi_flags |= WIF_THRUSTER;
3280 for (j=0; j<pm->n_textures; j++ ) {
3281 int bitmap_num = pm->original_textures[j];
3283 if ( bitmap_num > -1 ) {
3284 // if we're in Glide (and maybe later with D3D), use nondarkening textures
3285 if(gr_screen.mode == GR_GLIDE){
3286 bm_page_in_nondarkening_texture( bitmap_num );
3288 bm_page_in_texture( bitmap_num );
3297 bm_page_in_texture( wip->laser_bitmap );
3299 if(wip->laser_glow_bitmap >= 0){
3300 bm_page_in_texture(wip->laser_glow_bitmap);
3306 Int3(); // Invalid weapon rendering type.
3309 // If this has an impact vclip page it in.
3310 // if ( wip->impact_explosion_ani > -1 ) {
3311 // int nframes, fps;
3312 // bm_get_info( wip->impact_explosion_ani, NULL, NULL, NULL, &nframes, &fps );
3313 // bm_page_in_xparent_texture( wip->impact_explosion_ani, nframes );
3317 if ( (wip->wi_flags & WIF_TRAIL) && (wip->tr_info.bitmap > -1) ) {
3318 bm_page_in_texture( wip->tr_info.bitmap );
3321 // if this is a beam weapon, page in its stuff
3322 if(wip->wi_flags & WIF_BEAM){
3323 // all beam sections
3324 for(idx=0; idx<wip->b_info.beam_num_sections; idx++){
3325 if((idx < MAX_BEAM_SECTIONS) && (wip->b_info.sections[idx].texture >= 0)){
3326 bm_page_in_texture(wip->b_info.sections[idx].texture);
3331 if(wip->b_info.beam_glow_bitmap >= 0){
3332 bm_page_in_texture(wip->b_info.beam_glow_bitmap);
3336 if(wip->b_info.beam_particle_ani >= 0){
3338 bm_get_info( wip->b_info.beam_particle_ani, NULL, NULL, NULL, &nframes, &fps );
3339 bm_page_in_texture( wip->b_info.beam_particle_ani, nframes );
3345 for (i=0; i<Num_weapon_expl; i++) {
3346 int bitmap_handle, nframes, fps;
3348 for (j=0; j<Weapon_expl_info[i].lod_count; j++) {
3350 bitmap_handle = bm_load_animation(Weapon_expl_info[i].lod[j].filename, &nframes, &fps, 1);
3351 Weapon_expl_info[i].lod[j].bitmap_id = bitmap_handle;
3352 Weapon_expl_info[i].lod[j].fps = fps;
3353 Weapon_expl_info[i].lod[j].num_frames = nframes;
3356 bm_page_in_xparent_texture(bitmap_handle, nframes);
3361 for (i=0; i<Num_cmeasure_types; i++ ) {
3362 cmeasure_info *cmeasurep;
3364 cmeasurep = &Cmeasure_info[i];
3366 cmeasurep->model_num = model_load( cmeasurep->pof_name, 0, NULL );
3368 polymodel *pm = model_get( cmeasurep->model_num );
3370 for (j=0; j<pm->n_textures; j++ ) {
3371 int bitmap_num = pm->original_textures[j];
3373 if ( bitmap_num > -1 ) {
3374 bm_page_in_texture( bitmap_num );
3377 Assert( cmeasurep->model_num > -1 );
3382 // call to get the "color" of the laser at the given moment (since glowing lasers can cycle colors)
3383 void weapon_get_laser_color(color *c, object *objp)
3395 Assert(objp->type == OBJ_WEAPON);
3396 Assert(objp->instance >= 0);
3397 Assert(Weapons[objp->instance].weapon_info_index >= 0);
3398 if((objp->type != OBJ_WEAPON) || (objp->instance < 0) || (Weapons[objp->instance].weapon_info_index < 0)){
3401 wep = &Weapons[objp->instance];
3402 winfo = &Weapon_info[wep->weapon_info_index];
3404 // if we're a one-color laser
3405 if((winfo->laser_color_2.red == 0) && (winfo->laser_color_2.green == 0) && (winfo->laser_color_2.blue == 0)){
3406 *c = winfo->laser_color_1;
3410 pct = 1.0f - (wep->lifeleft / winfo->lifetime);
3413 } else if (pct < 0.0f)
3418 // otherwise interpolate between the colors
3419 gr_init_color( c, (int)((float)winfo->laser_color_1.red + (((float)winfo->laser_color_2.red - (float)winfo->laser_color_1.red) * pct)),
3420 (int)((float)winfo->laser_color_1.green + (((float)winfo->laser_color_2.green - (float)winfo->laser_color_1.green) * pct)),
3421 (int)((float)winfo->laser_color_1.blue + (((float)winfo->laser_color_2.blue - (float)winfo->laser_color_1.blue) * pct)) );
3424 // default weapon particle spew data
3425 int Weapon_particle_spew_count = 1;
3426 int Weapon_particle_spew_time = 25;
3427 float Weapon_particle_spew_vel = 0.4f;
3428 float Weapon_particle_spew_radius = 2.0f;
3429 float Weapon_particle_spew_lifetime = 0.15f;
3430 float Weapon_particle_spew_scale = 0.8f;
3432 // for weapons flagged as particle spewers, spew particles. wheee
3433 void weapon_maybe_spew_particle(object *obj)
3437 vector direct, direct_temp, particle_pos;
3438 vector null_vec = ZERO_VECTOR;
3443 Assert(obj->type == OBJ_WEAPON);
3444 Assert(obj->instance >= 0);
3445 Assert(Weapons[obj->instance].weapon_info_index >= 0);
3446 Assert(Weapon_info[Weapons[obj->instance].weapon_info_index].wi_flags & WIF_PARTICLE_SPEW);
3448 wp = &Weapons[obj->instance];
3450 // if the weapon's particle timestamp has elapse`d
3451 if((wp->particle_spew_time == -1) || timestamp_elapsed(wp->particle_spew_time)){
3452 // reset the timestamp
3453 wp->particle_spew_time = timestamp(Weapon_particle_spew_time);
3455 // spew some particles
3456 for(idx=0; idx<Weapon_particle_spew_count; idx++){
3457 // get the backward vector of the weapon
3458 direct = obj->orient.fvec;
3459 vm_vec_negate(&direct);
3461 // randomly perturb x, y and z
3464 ang = fl_radian(frand_range(-90.0f, 90.0f));
3465 vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.fvec);
3466 direct = direct_temp;
3467 vm_vec_scale(&direct, Weapon_particle_spew_scale);
3470 ang = fl_radian(frand_range(-90.0f, 90.0f));
3471 vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.rvec);
3472 direct = direct_temp;
3473 vm_vec_scale(&direct, Weapon_particle_spew_scale);
3476 ang = fl_radian(frand_range(-90.0f, 90.0f));
3477 vm_rot_point_around_line(&direct_temp, &direct, ang, &null_vec, &obj->orient.uvec);
3478 direct = direct_temp;
3479 vm_vec_scale(&direct, Weapon_particle_spew_scale);
3481 // get a velovity vector of some percentage of the weapon's velocity
3482 vel = obj->phys_info.vel;
3483 vm_vec_scale(&vel, Weapon_particle_spew_vel);
3485 // emit the particle
3486 vm_vec_add(&particle_pos, &obj->pos, &direct);
3487 particle_create(&particle_pos, &vel, Weapon_particle_spew_lifetime, Weapon_particle_spew_radius, PARTICLE_SMOKE);
3492 // debug console functionality
3493 void pspew_display_dcf()
3495 dc_printf("Particle spew settings\n\n");
3496 dc_printf("Particle spew count (pspew_count) : %d\n", Weapon_particle_spew_count);
3497 dc_printf("Particle spew time (pspew_time) : %d\n", Weapon_particle_spew_time);
3498 dc_printf("Particle spew velocity (pspew_vel) : %f\n", Weapon_particle_spew_vel);
3499 dc_printf("Particle spew size (pspew_size) : %f\n", Weapon_particle_spew_radius);
3500 dc_printf("Particle spew lifetime (pspew_life) : %f\n", Weapon_particle_spew_lifetime);
3501 dc_printf("Particle spew scale (psnew_scale) : %f\n", Weapon_particle_spew_scale);
3504 DCF(pspew_count, "Number of particles spewed at a time")
3506 dc_get_arg(ARG_INT);
3507 if(Dc_arg_type & ARG_INT){
3508 Weapon_particle_spew_count = Dc_arg_int;
3511 pspew_display_dcf();
3514 DCF(pspew_time, "Time between particle spews")
3516 dc_get_arg(ARG_INT);
3517 if(Dc_arg_type & ARG_INT){
3518 Weapon_particle_spew_time = Dc_arg_int;
3521 pspew_display_dcf();
3524 DCF(pspew_vel, "Relative velocity of particles (0.0 - 1.0)")
3526 dc_get_arg(ARG_FLOAT);
3527 if(Dc_arg_type & ARG_FLOAT){
3528 Weapon_particle_spew_vel = Dc_arg_float;
3531 pspew_display_dcf();
3534 DCF(pspew_size, "Size of spewed particles")
3536 dc_get_arg(ARG_FLOAT);
3537 if(Dc_arg_type & ARG_FLOAT){
3538 Weapon_particle_spew_radius = Dc_arg_float;
3541 pspew_display_dcf();
3544 DCF(pspew_life, "Lifetime of spewed particles")
3546 dc_get_arg(ARG_FLOAT);
3547 if(Dc_arg_type & ARG_FLOAT){
3548 Weapon_particle_spew_lifetime = Dc_arg_float;
3551 pspew_display_dcf();
3554 DCF(pspew_scale, "How far away particles are from the weapon path")
3556 dc_get_arg(ARG_FLOAT);
3557 if(Dc_arg_type & ARG_FLOAT){
3558 Weapon_particle_spew_scale = Dc_arg_float;
3561 pspew_display_dcf();
3564 // return a scale factor for damage which should be applied for 2 collisions
3565 float weapon_get_damage_scale(weapon_info *wip, object *wep, object *target)
3568 int from_player = 0;
3569 float total_scale = 1.0f;
3571 int is_big_damage_ship = 0;
3574 if((wip == NULL) || (wep == NULL) || (target == NULL)){
3578 // don't scale any damage if its not a weapon
3579 if((wep->type != OBJ_WEAPON) || (wep->instance < 0) || (wep->instance >= MAX_WEAPONS)){
3582 wp = &Weapons[wep->instance];
3584 // was the weapon fired by the player
3586 if((wep->parent >= 0) && (wep->parent < MAX_OBJECTS) && (Objects[wep->parent].flags & OF_PLAYER_SHIP)){
3590 // if this is a lockarm weapon, and it was fired unlocked
3591 if((wip->wi_flags & WIF_LOCKARM) && !(wp->weapon_flags & WF_LOCKED_WHEN_FIRED)){
3592 total_scale *= 0.1f;
3595 // if the hit object was a ship
3596 if(target->type == OBJ_SHIP){
3600 // get some info on the ship
3601 Assert((target->instance >= 0) && (target->instance < MAX_SHIPS));
3602 if((target->instance < 0) || (target->instance >= MAX_SHIPS)){
3605 shipp = &Ships[target->instance];
3606 sip = &Ship_info[Ships[target->instance].ship_info_index];
3608 // get hull pct of the ship currently
3609 hull_pct = target->hull_strength / sip->initial_hull_strength;
3611 // if it has hit a supercap ship and is not a supercap class weapon
3612 if((sip->flags & SIF_SUPERCAP) && !(wip->wi_flags & WIF_SUPERCAP)){
3613 // if the supercap is around 3/4 damage, apply nothing
3614 if(hull_pct <= 0.75f){
3617 total_scale *= SUPERCAP_DAMAGE_SCALE;
3621 // determine if this is a big damage ship
3622 is_big_damage_ship = (sip->flags & SIF_BIG_DAMAGE);
3624 // if this is a large ship, and is being hit by flak
3625 if(is_big_damage_ship && (wip->wi_flags & WIF_FLAK)){
3626 total_scale *= FLAK_DAMAGE_SCALE;
3629 // if the player is firing small weapons at a big ship
3630 if( from_player && is_big_damage_ship && !(wip->wi_flags & (WIF_HURTS_BIG_SHIPS)) ){
3632 // if its a laser weapon
3633 if(wip->subtype == WP_LASER){
3634 total_scale *= 0.01f;
3636 total_scale *= 0.05f;
3640 // if the weapon is a small weapon being fired at a big ship
3641 if( is_big_damage_ship && !(wip->wi_flags & (WIF_HURTS_BIG_SHIPS)) ){
3642 if(hull_pct > 0.1f){
3643 total_scale *= hull_pct;
3653 int weapon_get_expl_handle(int weapon_expl_index, vector *pos, float size)
3655 weapon_expl_info *wei = &Weapon_expl_info[weapon_expl_index];
3657 if (wei->lod_count == 1) {
3658 return wei->lod[0].bitmap_id;
3661 // now we have to do some work
3663 int x, y, w, h, bm_size;
3669 extern float Viewer_zoom;
3670 extern int G3_count;
3676 g3_set_view_matrix(&Eye_position, &Eye_matrix, Viewer_zoom);
3678 // get extents of the rotated bitmap
3679 g3_rotate_vertex(&v, pos);
3681 // if vertex is behind, find size if in front, then drop down 1 LOD
3682 if (v.codes & CC_BEHIND) {
3683 float dist = vm_vec_dist_quick(&Eye_position, pos);
3687 vm_vec_scale_add(&temp, &Eye_position, &Eye_matrix.fvec, dist);
3688 g3_rotate_vertex(&v, &temp);
3690 // if still behind, bail and go with default
3691 if (v.codes & CC_BEHIND) {
3696 if (!g3_get_bitmap_dims(wei->lod[0].bitmap_id, &v, size, &x, &y, &w, &h, &bm_size)) {
3697 if (Detail.hardware_textures == 4) {
3701 } else if(w <= bm_size/2){
3703 } else if(w <= 1.3f*bm_size){
3709 // less aggressive LOD for lower detail settings
3712 } else if(w <= bm_size/3){
3714 } else if(w <= (1.15f*bm_size)){
3722 // if it's behind, bump up LOD by 1
3732 best_lod = min(best_lod, wei->lod_count - 1);
3733 return wei->lod[best_lod].bitmap_id;