mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-12 19:06:09 -10:00
* Fix isWeaponAllowedOnShip bank lookup for secondary banks isWeaponAllowedOnShip numbers banks per ship class, with the secondaries right after the primaries, but the bank restriction lists keep secondary bank n at MAX_SHIP_PRIMARY_BANKS + n. On a ship with fewer than three primary banks, the secondary banks were checked against the wrong list. Map the bank before the lookup. The restriction lists are only allocated for ship classes that have $Allowed PBanks/SBanks, so both this function and the loadout weapon setter read past the end of an empty vector for any other class. Skip the bank check when there are no lists. The loadout weapon setter also treated a primary slot the ship does not have (bank 3 on a two-primary ship) as a secondary bank. Fixes #7985 * Cover more bank layouts and the loadout setter in the shipclass tests Add classes with one and three primary banks, a restricted primary bank, the bank-omitted case, and tests for the loadout weapon setter's bank range and restriction checks. * Fall back to the class weapon list in loadout bank checks The weapon loadout's slot and pool moves read a ship class's per-bank restriction lists without checking they exist. Those lists are only allocated for classes with $Allowed PBanks/SBanks, so a move request for any other class (from a script through sendWeaponRequestPacket, or a multiplayer client) read past the end of an empty vector and crashed. When a class has no per-bank lists, check the weapon against the class-wide allowed weapons instead. Classes with lists behave as before. * Simplify the loadout bank checks and tidy the loadout setter wl_bank_allows_weapon already allows a bank with no restriction, so the four loadout checks call it directly. The comment now says what the empty case means: a class without bank lists allows no weapons. The Loadout_Weapon setter rejects a weapon index one past the end, and only resets the amount when it actually stored the weapon. * Check the class weapon list in the loadout bank check A bank without its own list accepted any weapon of the right type, so a move request from a script or a multiplayer client could load a weapon the ship class can't carry. Check the class-wide list first, as the rearm code does. An empty slot coming back from a swap has nothing to check, which also stops it adding a -1 entry to the weapon pool. --------- Co-authored-by: Dustinspace217 <[email protected]>