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

Improve Rebel Weapon and Other Items Selection #427

Open
wants to merge 16 commits into
base: unstable
Choose a base branch
from

Conversation

jwoodruff40
Copy link

@jwoodruff40 jwoodruff40 commented Dec 25, 2024

What type of PR is this?

  1. Bug
  2. Change
  3. Enhancement
  4. Miscellaneous

What have you changed and why?

Information:

Why:

It was bothering me that when you start to accumulate / unlock better weapons in your arsenal, AI Rebels will just randomly 'pick' any weapon in a given category, instead of trying to 'pick' a better weapon. E.g. when playing as 3CB FIA, my rebels will quite often be equipped with M1 Garands (initial equipment) even when I have M16s, AK74s, AK105s, etc unlocked. This severely limits the Rebels' firepower compared to enemy AI.

I also noticed that fn_generateRebelGear / the A3A_rebelGear it creates is structured as a weighted list but doesn't currently make use of weights, adding everything with a weight of 1.

What:

This update to fn_generateRebelGear calculates a weaponWeight for each primary weapon added to A3A_rebelGear based on the weapon's attributes (positive and negative):

Positive attributes (higher is better):

  • accuracy
  • rate of fire
  • magazine capacity
  • 'impact force'
  • effective range (currently only for snipers and launchers)
  • penetration (launchers)

Negative attributes (higher is worse):

  • weight
  • disposable (launchers)

It's heavily inspired by the weapon statistics shown in ACE3 Arsenal (especially the impact attribute), but the only code copied from ACE is the impact force calculation, a combination of muzzle velocity and bullet / ammo damage.

The end state is that when AI rebels are equipped, they'll be much more likely to equip better weapons, without entirely precluding use of 'lower tier' weapons. To that end, I attempted to weigh the weapon attributes sensibly.

Example weapon weights from a pretty new save (not very many weapons) with 3CB FIA vs 3CB AAF (some output omitted):

A3A_rebelGear; ==>

[
[["GrenadeLaunchers",[
    "UK3CB_M16A2_UGL",40
]],
["MissileLaunchersAA",[
    "rhs_weap_fim92",
    "UK3CB_Blowpipe"
]],
["Shotguns",[
    "rhs_weap_M590_5RD",7
]],
["SniperRifles",[
    "UK3CB_Enfield",10,
    "UK3CB_M1903A1",3
]],
["Rifles,[
    "rhs_weap_m1garand_sa43",16,
    "rhs_weap_ak74m",45,
    "UK3CB_M16A2",47,
    "UK3CB_HK33KA1",40,
    "UK3CB_HK33KA3",40,
    "rhs_weap_ak105",53
]],
["SMGs",["rhs_weap_m3a1",53]]
]

Please specify which Issue this PR Resolves (If Applicable).

None as far as I'm aware.

Please verify the following.

  1. Have you loaded the mission in LAN host?
  2. Have you loaded the mission on a dedicated server?

Is further testing or are further changes required?

  1. No
  2. Yes (Please provide further detail below.)

Modification has only been tested with RHS and 3CBF factions / weapons, with a few randomly picked selections of test weapons and on a couple save files that use those factions. Needs more testing to ensure compatibility across other supported factions / weapon mods. I would also be interested in expanding to include weighing launchers and potentially other items, but need feedback on if that's wanted and what stats would make sense to weigh those items.

How can the changes be tested?

Steps:

Best way to test is probably to get a bunch of people running different factions and such to copy their save(s), load the copied save, and in the debug console input A3A_rebelGear; and analyze the output for discrepancies, weapons whose stats / weight weren't properly identified / calculated, or if the weights seem to be either too close or too disparate strongly favoring certain weapons or not.


Notes:

I wanted to include weapon max range (or max effective range?) as an additional attribute, but I found that at least for RHS weapons the most ideal attributes to use (_config >> maxRange / _config >> maxRangeProbab) are generally all the same in the weapon config root, and are only updated under the fire modes, but a lot of RHS weapons use several custom fire modes instead of the normal "SINGLE" or "BURST" or "FULLAUTO", and I didn't want to have to iterate through all fire modes to attempt to find the best values like is done in ACE. Ultimately I decided that the impact force alone should be sufficient, given that generally, longer range weapons have higher muzzle velocity / larger bullets - the same things that affect impact force. May be worth revisiting though.

Effective range is now calculated, but loops through all firemodes so probably best not to use for every weapon type.

SilenceIsFatto and others added 2 commits December 10, 2024 14:42
Weigh weapons added to rebel arsenal by their stats (accuracy, rate of fire, magazine capacity, impact force, weight) to improve rebel AI weapon selection.
@jwoodruff40
Copy link
Author

Another thought I had – I don't play with unlocks disabled, but for those that do, the amount of each weapon in the arsenal could also be included in the weapon weight calculation such that AI will be more likely to be equipped with weapons the rebels have more of, all else being equal.

@wersal454
Copy link

That looks really nice

For those who play with unlocks disabled, system I think should be adapted yes(if you can figure it out ofc)

Also maybe add a weights for secondary weapons(i.e. launchers)? Not sure how to qualify some launchers to be better then others, but maybe take a look at it
also I want to add handguns in #418, so maybe weights system for them as well?

@SilenceIsFatto
Copy link
Owner

The base branch should be unstable rather than stable, changing it may cause merge conflicts so be aware of those

@wersal454
Copy link

just in case

Click "Edit" and this menu will pop up
image
there you can select different base branch

@jwoodruff40 jwoodruff40 changed the base branch from stable to unstable December 25, 2024 21:50
@jwoodruff40
Copy link
Author

Thanks team for the input. I changed the base branch.

I have some thoughts on how to go about weighing other item types, but don't want to get too into the weeds lest it starts becoming too much of a subjective / playstyle-dependent approach. More to follow.

Merry Christmas / happy holidays to all and thanks for the awesome mod!

…g, A3A_fnc_itemConfigMass) instead of reimplementing the same code
…weight param default value of 1 if not provided for backwards compat; update _fnc_addItemNoUnlocks to scale weight by ratio of item in arsenal : max items
@jwoodruff40
Copy link
Author

jwoodruff40 commented Dec 26, 2024

I fixed my rookie mistake of changing the param order for _fnc_addItem and did some initial rework of the existing code for less code reuse.

Also pushed an initial implementation for _fnc_addItemNoUnlocks. It uses the already existing linearconversion of amount of item to range between 0 and 1 as a scalar for the item weight variable. So items with similar weight will be selected more often if there are more of them, and vice versa. Should make for some interesting results with varying item weights and amounts.

Personally, I think that's a good enough implementation, but I don't ever play with unlocks disabled, so we could use some input from the crowd that do.

Edit: I am curious though - why do we divide the amount of rifles (and only rifles) by 2 when passing the amount to the addItem function? This does significantly skew how many you need to get for AI to realistically start using them, which I guess is maybe the intent? But then why not for other types of primary weapons?

…ght and _fnc_weaponWeight to _fnc_weaponArrayWeight to mitigate confusion in the future
…ndary weapons, handguns, armor, etc). Rename to _fnc_itemArrayWeight, add switch statement with fallthrough and placeholders to support more items in future.
@jwoodruff40 jwoodruff40 changed the title Improve Rebel Primary Weapon Selection Improve Rebel Weapon and Othe Items Selection Dec 26, 2024
@jwoodruff40 jwoodruff40 changed the title Improve Rebel Weapon and Othe Items Selection Improve Rebel Weapon and Other Items Selection Dec 26, 2024
@jwoodruff40
Copy link
Author

Refactored / generalized function to support whatever item types we want to implement custom weight / preference calculation for (secondaries, handguns, armor, etc).

@UAC-MaxxLite
Copy link
Collaborator

I would also suggest that you limit the type of secondaries for each class if possible I.e.
only AT and AA units being able to use guided launchers.
And disable secondary use for marksman medic and such.

This will make it harder for players that spam launchers on all types of units which just makes the game easier.

… launchers, and handguns. Value weighting decisions explained in comments. Needs testing across modsets.
@jwoodruff40
Copy link
Author

jwoodruff40 commented Dec 26, 2024

@UAC-MaxxLite that's done already in fn_equipRebel unless I'm misunderstanding what you mean. If you mean restricting players from override the AI loadouts with that kind of thing, I get what you mean. Not sure if that's in the scope of this PR or not though.

In any case, latest commit implements specific weight calculations for sniper rifles, rocket launchers (LAT), and handguns (per @wersal454 's suggestion / PR). How and why the attributes are weighted the way they are for those is commented in the file, but as stated before, definitely needs a lot of testing across supported mod sets.

The func is getting pretty long and will only get longer with more variable / calculations for additional item types, so I also broke it out into its own file.

…ers less. Update fn_equipRebel to equip rebel rifleman with disposable launchers (likelihood to get launcher increases by 10% with each war level
@wersal454
Copy link

I would also suggest that you limit the type of secondaries for each class if possible I.e. only AT and AA units being able to use guided launchers. And disable secondary use for marksman medic and such.

This will make it harder for players that spam launchers on all types of units which just makes the game easier.

restricting players from equipping any AI with launchers would take A TON of work, it would require changing arsenal code(probably) which is a bitch

@SilenceIsFatto SilenceIsFatto added the misc A miscellaneous change label Dec 27, 2024
Copy link
Owner

@SilenceIsFatto SilenceIsFatto left a comment

Choose a reason for hiding this comment

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

Looks fine, can be tested when you feel it ready

Squashed commit of the following:

commit 6a7a3d1c2b1a9e05bd9049b18b63ecb529043baf
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 14:06:45 2024 -0500

    Fix weapons getting added to multiple categories, e.g. weaps with UGL getting added to GrenadeLaunchers AND Rifles

commit a94554f6d148faae4afbdcc603ec715b25799698
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 13:53:15 2024 -0500

    Pass _categories to fn_itemArrayWeight to avoid calling fn_equipmentClassToCategories again

commit 0bbb1f56c5ee5fe5699c53da65c3085a5a6c537a
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 13:36:00 2024 -0500

    Return item weight 1 if calculated weight is negative
Squashed commit of the following:

commit 763fb6a3356d34c3bdcd7dbff76b61524d135c2c
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 19:57:47 2024 -0500

    Remove / refactor redundant function param

commit d9272d4065072cbbf036b60cb362e26bc0ea95ea
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 16:58:24 2024 -0500

    I'm dumb, copied this backwards
Squashed commit of the following:

commit 4d98099500599c838f848377f9b9b21635fecc83
Author: jwoodruff40 <[email protected]>
Date:   Tue Dec 31 00:09:27 2024 -0500

    Lower chance of rifleman equipping a disposable launcher.

commit bd26f00838b6f1c65504c853b40535d2f0265b63
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 23:44:55 2024 -0500

    Fix disposable launcher distribution to rifleman. In very brief testing, may be slightly excessive. Needs more testing.

commit aa13a85eee2efbad026c5973188de11f2c7f9cea
Author: jwoodruff40 <[email protected]>
Date:   Mon Dec 30 22:54:48 2024 -0500

    Only calculate weapon attributes when a weapon class is passed to the func. Fix divide by 0 condition in _rof calc when _reloadTime is 0 (e.g. for some disposable launchers)
@jwoodruff40
Copy link
Author

jwoodruff40 commented Dec 31, 2024

Pushed a few more fixes and things. I would call it ready for testing now. Can't (or don't know how) to set that label myself.

In summary (things to look for with testing the code), this PR does two main things:

  • Makes rebel forces (personal and HC squads) more likely to equip better weapons in each category, while still maintaining a equipping a variety of weaponry
  • Equips some rebel rifleman (percentage increases by war level) with disposable AT launcher

And sets the conditions for crafting interesting weights for other item types in the future - e.g. preferencing vests by some combination of weight, load capacity, armor value.

@wersal454 – I did some minor manual testing of weighting for handguns just to make sure they looked kinda right, but if you want to give this a test along with your PR that actually equips rebels with handguns, that would be helpful.


I also pushed a larger refactor of fn_generateRebelGear (last commit). Intent was to remove a lot of the duplicate code between item types. Understand code style is very subjective and how it is now is probably more readable (if much more verbose), so can revert if not wanted. Can test with or without that commit.

Copy link
Owner

@SilenceIsFatto SilenceIsFatto left a comment

Choose a reason for hiding this comment

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

Code looks fine

We'll try to test this in our next server campaign, will help bring any potential issues to light

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc A miscellaneous change ready-for-testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants