64 Commits
Author SHA1 Message Date
Goober5000andClaude Fable 5.1 04e698c29b fix weapon substitution bank attribution and turret ammo accounting
Follow-up to #7635.

Pass the firing bank explicitly through weapon_create() and beam_fire()
instead of searching the ship's banks by weapon class, which could
attribute substitution patterns to the wrong bank.  Factor the
substitution logic into get_weapon_substitution_tuple() and only apply
linked/dual-fire pairing to ship-level fire, not turret fire.  Skip
substitution on multiplayer clients, since the server already resolved it.

Derive turret bank indices from the weapon slot being fired rather than
the turret's bank cursor, so ammo and substitution state are tracked on
the bank that actually fired.  Previously a single-selection turret could
consume ammo from a bank it never fired, and non-ammo turrets (whose
cursors stay at -1) would have skipped substitution entirely.

Use the Player_ship object flag rather than Player_obj in
ship_secondary_bank_can_dual_fire() so the server and clients agree on
dual fire for remote players, and guard ship_secondary_has_ammo() against
a negative bank index.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-05 19:22:45 -04:00
Goober5000 ee4b554dd4 standardize and update the various _INDEX macros 2026-08-23 21:38:52 -04:00
Asteroth c085f87e6f clean up condition 2025-05-07 23:31:22 -04:00
Asteroth 447119ed7e small fix for turret swarm stuff 2025-05-07 23:07:33 -04:00
Mike Nelson 36d6fbe7e5 Lab firing upgrades (#6703)
* Fix some issues preventing various secondary types from firing in the lab

* Add ability to fire turrets from the lab

* const char*, mjn please

* more cleanup

* range-based for loop

* Update comment
2025-05-01 09:50:27 -04:00
Goober5000 f4669db41c constify some turret code
Apply `const` to a whole bunch of functions.  Also change a bunch of ints to bools.
2023-12-30 00:00:31 -05:00
Goober5000 7f05f775af fix Assertion in turret_swarm_set_up_info
It appears that `(turret->turret_enemy_objnum < 0)` is an expected and allowed condition, so just assert that the objnum does not exceed MAX_OBJECTS.

Fixes #5470.
2023-06-23 22:55:41 -04:00
BMagnu a6093dd8c4 Add ammoless secondaries (#3589)
* Add ammoless secondaries

* Macroify 'ammo>0 || no ammo' check
2021-10-02 04:40:03 +09:00
Asteroth d971f34ee2 make all asinf and acosf safe (#3384) 2021-05-05 00:53:24 -04:00
Baezon 7b2c8304ff typo 2021-02-01 13:25:44 -05:00
Baezon 9b7cc77b55 revert multi compatability :( 2021-01-31 13:11:27 -05:00
Baezon d3355b0783 experimental multi compatability 2021-01-31 12:29:25 -05:00
Baezon 055784dcff clean up swarm missiles 2021-01-28 22:33:01 -05:00
Baezon 9abc253023 v1 2020-08-26 23:27:34 -04:00
Baezon 1e56ad942c clarity comment 2020-08-05 01:40:07 -04:00
Baezon 8bd033705f swarmers lead targets 2020-07-21 14:48:24 -04:00
Goober5000 c9df8a13f1 add functions to remove the clutter of static casts for ship and weapon info vectors 2020-03-14 13:02:12 -04:00
Goober5000 fde7fdd854 address feedback 2020-03-07 13:35:17 -05:00
Goober5000 c0a7be50b4 fixes for CI 2020-03-06 12:23:40 -05:00
Goober5000 bb8fcd428e address feedback 2020-03-06 03:11:31 -05:00
Goober5000 1926d3c341 oof, more changes 2020-03-05 20:49:16 -05:00
Goober5000 20835adef6 convert Weapon_info to a SCP_vector 2020-03-05 19:12:43 -05:00
Peter Mitsis 923265988c Fix warnings found by clang_tidy.sh
Signed-off-by: Peter Mitsis <[email protected]>
2018-07-19 19:24:23 -04:00
Peter Mitsis 3aacb6cb42 aicode: Update ai_turn_towards_vector() API
The routine ai_turn_towards_vector() had an unused parameter (frametime)
and it has been removed.

Each of the instances where this routine is called have also been updated
to reflect the parameter removal. As this resulted in the routine
swarm_update_direction() suddenly having an unused parameter, that routine
and the places where it is called have also been updated (remove
unused parameter).

Signed-off-by: Peter Mitsis <[email protected]>
2018-07-17 15:25:22 -04:00
z64555 0f942afaae Simplify out-of-frame calls.
*Homing conditions are now consistant with in-frame checks
*Swarm missiles will now only change their homing pos during a change frame. This'll reduce their hit rate if SWARM_FRAME_STOP_SWARMING is too low, but will make their pathing more cinematic.
2017-10-22 14:42:33 -05:00
z64555 cdde87662a Refactors swarm_update_direction() a bit for readability and consistency.
* Changed stop distance to a stop frame. Frame was chosen instead of distance or time to ensure missiles won't appear to jerk twice in succession.
2017-10-22 02:00:01 -05:00
asarium 92cb2140aa Replace _isnan with std::isnan 2016-10-15 19:37:18 +02:00
Fabian Woltermann 1acfaa8157 Converts model subsystem flags 2016-08-19 14:59:15 +02:00
Fabian Woltermann 127976cd74 Weapon info flags conversion (#851) 2016-08-18 23:17:41 -07:00
Peter Mitsis 180674154c trig: Use floating point versions of trig functions
Replaces calls to double-precision floating point trig functions with
calls to single-precision floating point trig functions as follows:
    cos() -> cosf()
    sin() -> sinf()
    tan() -> tanf()
    acos() -> acosf()
    asin() -> asinf()
    atan() -> atanf()

This allows the compiler to avoid generating unnecessary instructions
that convert a float to a double and then a double back to a float.

Signed-off-by: Peter Mitsis <[email protected]>
2016-04-24 21:56:06 -04:00
Goober5000 bd3cd7eb18 Merge pull request #195 from Echelon9/fix/sort-uniq-includes
Review and refactor #include's
2015-08-19 00:05:02 -04:00
DahBlount 5c3d7b0f64 Turret bank fix and ammo removal
A turret's current_primary_bank/current_secondary_bank is always
initialized to -1, this is set to 0 if it is still -1 when a turret
tries to fire. Ammo removal for swarm and corkscrew weapons is now done
using a single flag check instead of the original two.
2015-08-09 19:29:16 -05:00
DahBlount 688baa2bb6 Turret Ammo Implementation
This creates the foundation of turret ammo through the "turret use ammo" subsystem flag. Turret ammo works in the same manner as ship ammo, where the ammo is equal to bank capacity divided by the cargo size of the weapon. This was tested using the Blue Planet: War in Heaven mod.
Test case: UEFg Narayana turrets 19 through 21, all of which contain Apocalypse torpedos with a $Cargo Size: of 2.5, were changed to use ammo with a $SBank Capacity of 20, resulting in a total ammo capacity of 8 torpedos. The Narayana was ordered to attack a GTCv Diomedes; it fired 8 torpedos each from turrets 19 through 21 before stopping. The mission was left to proceed for an additional 2 minutes, in which time the Narayana did not fire any more torpedos. Note: The Apocalypse takes 20 seconds to fire each 4 torpedo burst.
Conclusion: Success
2015-07-28 12:32:08 -05:00
Echelon9 a93215f781 Ensure input domain to asin() does not lead to irrational results (implementation defined behaviour) 2015-07-01 23:15:36 +10:00
Echelon9 c5493bb480 Scripted sort and uniq on (internal) project includes. Improves search time and as a by product removed a number of duplicative includes. 2015-06-22 20:24:30 +10:00
niffiwan 6579133220 Remove unnecessary Int3() - already gracefully handles running out of turret swarm slots 2012-08-07 09:11:41 +00:00
niffiwan 9a6611198e GCC warnings: more 'variable set but not used' 2012-06-14 11:21:09 +00:00
niffiwan bcea3057f5 GCC warnings: declaration of ‘ship_obj’ shadows a global declaration (weapon/*.cpp) 2012-06-14 10:30:01 +00:00
The_E acffa5b358 Fix for Mantis 2606: Local SSMs fired in swarm may cause propagating NaN errors 2012-05-10 20:54:40 +00:00
niffiwan f75e83c900 Fix for Mantis #0002604: using m_m's patch, allow swarm/corkscrew bank to keep firing if current bank changes 2012-03-06 10:09:04 +00:00
Echelon9 53d407332f Fix LLVM warnings in weapon folder 2012-01-15 07:05:20 +00:00
Wanderer 06a3381dd9 fix for mantis 2309's corkscrew issue 2011-04-23 12:18:30 +00:00
Echelon9 4ccc6ba9a0 MAGIC numbers aren't for hiding in code... 2010-11-22 13:01:41 +00:00
The_E e2c5ff679c Swarm weapons should respect "$Free flight time" as well 2010-05-10 17:17:49 +00:00
The_E 132ba60085 Patch for Mantis 2202 (Children of swarm weapons do not inherit parent target) 2010-05-09 14:53:29 +00:00
karajorma 74d1c139ed Doh x2 2009-11-05 06:16:15 +00:00
karajorma 9f44258319 Bump MAX_OBJECTS, WEAPONS, SPLIT_PLANES, and SWARM_MISSILES. This stuff has been tested by Diaspora for months now so it should be fine. 2009-11-02 03:37:36 +00:00
portej05 719825f80d The big CVS comment removal. This chops approx. 3.5mb off a full checkout.
I've tested this through compiling and through hand checking. 
Normalises line endings in ALL files to \n.
2009-06-20 08:08:20 +00:00
Wanderer fdb2de32e7 fix swarm issue - again 2009-05-20 19:44:18 +00:00
Wanderer 4cd2a011db merge from wanderer branch - fixed firingpoint and 'fire on target' subsystem flags 2009-05-20 13:24:57 +00:00