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 42 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.

@johnb432
Copy link
Contributor

johnb432 commented Dec 18, 2023

I went ahead and pushed some fixes and a change.

EDIT:
The change is: Forbidding interactions with hostile CSWs (checking ammo count, loading, linking & unloading).

Comment on lines +57 to +60
// Don't remove ammo if it failed to load
_ammoRemaining = _ammoRemaining + _ammoUsed;

ERROR_1("failed to setAmmo - %1",_this);
Copy link
Contributor

Choose a reason for hiding this comment

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

I've adding this change because I feel it's wrong to punish a player if a reload can't happen, but I'm not sure if this can be abused.

@LinkIsGrim
Copy link
Contributor Author

Ref review, see https://github.com/LinkIsGrim/ACE3/blob/f5f14b77594d28c938822740602de83b7c30b010/addons/csw/functions/fnc_reload_canLoadMagazine.sqf#L29-L36

Calling FUNC(reload_canLoadMagazine) without a source is just a check for magazine/turret compatibility.

For FUNC(reload_handleAddTurretMag):

  • At this point the magazine has already been removed from the source, so we can skip distance and inventory checks.

For FUNC(reload_getLoadableMagazines):

  • We only need to know if the mag can be loaded/linked, we already know the sources are close enough and that they have the mag. Check for mag presence in source inventory will be done during progress bar.

For FUNC(reload_loadMagazine):

  • We're only calling that to get _neededAmmo.

Writing this I remembered that I wanted to split that function up for readability while writing this PR but never got around to it.

@johnb432
Copy link
Contributor

For FUNC(reload_handleAddTurretMag):

  • At this point the magazine has already been removed from the source, so we can skip distance and inventory checks.

_magSource isn't used in FUNC(reload_handleAddTurretMag) anymore - might as well remove it, no?

@LinkIsGrim
Copy link
Contributor Author

For FUNC(reload_handleAddTurretMag):

  • At this point the magazine has already been removed from the source, so we can skip distance and inventory checks.

_magSource isn't used in FUNC(reload_handleAddTurretMag) anymore - might as well remove it, no?

Need to check if API won't break with that, but should be fine otherwise, yeah.

@LinkIsGrim LinkIsGrim marked this pull request as draft February 7, 2024 20:55
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