Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSW - Fix and Improve reloading #9234

Draft
wants to merge 62 commits into
base: master
Choose a base branch
from

Conversation

LinkIsGrim
Copy link
Contributor

@LinkIsGrim LinkIsGrim commented Jun 30, 2023

When merged this pull request will:

  • Fix linking belts not returning unspent ammo.
  • Change bad params usage.
  • Close CSW - Belt Linking does not return unspent rounds #9233.
  • Change progress bar text to match rest of project ("load [magazine]" > "loading [magazine]...", etc)
  • Improve FUNC(reload_canLoadMagazine) conditions.
  • Improve function headers and comments where applicable.
  • Improve reloading to always pull from best ammo source, not just best magazine in ammo source.
  • Reduce range of nearSupplies check. 10 meters was excessive.
  • Remove distance check for latter part of AI reloading. Justification in comments.
  • Return ammo from belt linking to unit doing the action directly if the magSource can't be found or if it is a WeaponHolder.
  • Fix missing _unit param in events and logging.
  • Fix AI GetIn on an empty static before any weapon is fired.
  • Move getting mag sources to FUNC(getNearbySources).
  • Cache nearby mag sources.
  • Add public function FUNC(getSourceCompatibleMags): returns a source's compatible carry magazines with ammo count.
  • Add public function FUNC(compatibleMagazines): returns a CSW's compatible carry magazines.
  • Add ammo to return of FUNC(reload_getLoadableMagazines). Done to optimize the checks for best ammo to send.
  • Make FUNC(getCarryMagazine) public.
  • Cache compatible vehicle and carry magazines of CSW weapons.
  • Improve FUNC(reload_getLoadableMagazines) by making use of new functions.
  • Make FUNC(ai_reload) use FUNC(reload_getLoadableMagazines) directly: parameter was added to use the turret path in the latter.
  • Change all instances of _staticWeapon in parameters to _vehicle.
  • Change all instances of "Static Weapon" in function headers to "CSW".
  • Add ace_csw >> container property to Mk6 Mortar variants.
  • Add public function FUNC(getAvailableAmmo): returns nearby compatible magazine types and sum of their ammo. Intended for ZEN compatibility.
  • Add support for limiting AI reload to a single type of carry magazines by setting ace_csw_forcedMag.
  • Add public function FUNC(unloadMagazines): unloads magazines in turret path.
  • Add public function FUNC(ai_switchMagazine): forces AI to reload specified magazine.
  • Add support for getting vehicle magazine from weapon magazineWells.

MP tested and objNull/no container/full inventory-resistant.

I did not intend for this to grow so much, but here we are.

Review after #9238 and #9255.

IMPORTANT

  • If the contribution affects the documentation, please include your changes in this pull request so the documentation will appear on the website.
  • Development Guidelines are read, understood and applied.
  • Title of this PR uses our standard template Component - Add|Fix|Improve|Change|Make|Remove {changes}.

@LinkIsGrim LinkIsGrim added the kind/bug-fix Release Notes: **FIXED:** label Jun 30, 2023
@LinkIsGrim LinkIsGrim added this to the 3.16.0 milestone Jun 30, 2023
@LinkIsGrim LinkIsGrim changed the title CSW - Fix belt linking issues CSW - Fix belt linking not returning ammo properly Jun 30, 2023
@LinkIsGrim LinkIsGrim changed the title CSW - Fix belt linking not returning ammo properly CSW - Fix and Improve reloading Jul 1, 2023
@LinkIsGrim
Copy link
Contributor Author

The public functions were made with ZEN compatibility for CSW Artillery in mind, I intend to make another PR for the remainder of that. Sorry for the scope on this, but it'd have been merge conflict or PR-dependency hell otherwise.

@LinkIsGrim LinkIsGrim marked this pull request as draft February 7, 2024 20:55
addons/csw/functions/fnc_ai_reload.sqf Outdated Show resolved Hide resolved
addons/csw/functions/fnc_ai_switchMagazine.sqf Outdated Show resolved Hide resolved
Comment on lines +40 to +45
private _carryMagazines = createHashMap; // hashmap for constant lookup
{
private _weapon = _x;
if !(_weapon in GVAR(compatibleMagsCache)) then {continue};
_carryMagazines merge [GVAR(compatibleMagsCache) get _weapon, true];
} forEach _weapons;
Copy link
Contributor

@johnb432 johnb432 Jul 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. Add comment describing that this is handling proxy weapons. That's some bullshit I wrote, it handles carry magazines.
2. GVAR(compatibleMagsCache) is not a good name for this imo, should be renamed to something that includes "proxyWeapon" (e.g. GVAR(compatibleCarryMags)).

addons/csw/functions/fnc_getAvailableAmmo.sqf Outdated Show resolved Hide resolved
addons/csw/functions/fnc_getAvailableAmmo.sqf Outdated Show resolved Hide resolved
addons/csw/functions/fnc_getCarryMagazine.sqf Show resolved Hide resolved
addons/csw/functions/fnc_reload_handleReturnAmmo.sqf Outdated Show resolved Hide resolved
Comment on lines +67 to +70
clearItemCargoGlobal _container;
clearWeaponCargoGlobal _container;
clearBackpackCargoGlobal _container;
clearMagazineCargoGlobal _container;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the container has forceSupply set to 1 and you empty it (either by using the commands above or using other cargo manipulation commands), it will be marked for deletion, regardless of if you add items after the execution of this command.

Comment on lines +24 to +26
if (_turretPath isEqualTo []) then {
_turretPath = [0];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?
FUNC(reload_getLoadableMagazines) doesn't follow the same logic, which could lead to a desync of information.

Comment on lines +42 to +44
if (_clearForcedMag) then {
_vehicle setVariable [QGVAR(forcedMag), nil, true];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description of _clearForcedMag is Clear forced magazine after reloading. However, in line 46 it can still fail. Furthermore, this variable technically reset before reload. Do we need to absolutely reset it after the reload has finished (so when the turret events are called) or can it be called just after line 53?

// Cache compatible magazines
if !(_proxyWeapon in GVAR(compatibleMagsCache)) then {
private _compatibleMagazines = compatibleMagazines _proxyWeapon;
GVAR(compatibleVehicleMagsCache) set [_proxyWeapon, _compatibleMagazines];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. GVAR(compatibleVehicleMagsCache) is only used in FUNC(getVehicleMagazine), which in turn is only called when mags are either loaded or unloaded. Imo caching this is not necessary.
  2. Both GVAR(compatibleVehicleMagsCache) and GVAR(compatibleMagsCache) don't save magazines belonging to non-proxy weapons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-fix Release Notes: **FIXED:**
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSW - Belt Linking does not return unspent rounds
4 participants