Jump to content

R&D Modding Ammo


Amineri

Recommended Posts

  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

I have a bug that may be related to the new ammo code.

 

I had a heavy with Fire Rocket and Shredder Rocket, and also two aliens grenades via the grenadier perk.

 

I used Fire Rocket and one grenade in a shootout. Afterward, I was no longer able to activate the Shredder Rocket and the alien grenades -- it reported I was out of ammo.

 

I tried another mission, setting my rockets to suppression=505. I could fire both rockets once, as the perks allow, and the rocket icon on the tac screen lost 1/5 of its "fill" as if it was decrementing regular ammo.

 

Have not tried with smoke grenades or battlescanners.

 

I think this mod might have to be updated so the property eWP_Noreload is handled. Or maybe put unlimited ammo on the one-use items would do the trick?

Link to comment
Share on other sites

That's really interesting.

 

I wasn't really trying to create an ammo system that applied to the Rocket Launcher, but I guess inadvertently I did.

 

Every XGWeapon_<type> has it's own ammo variable, both the old iAmmo and the new m_iTurnFired replacement.

 

The new ammo code is actually a function within the XGAbility_Targeted base class (the old one was in XGTacticalGameCore). The function figures out which weapon's ammo to decrement by following the m_kWeapon attached to the kAbility called from XGAbilityTree.ApplyActionCost.

 

I don't know all of the ways in which the weapon is attached to the ability, but it sounds as though:

 

1) XGWeapon_RocketLauncher is the weapon attached to eAbility_FireRocket, which makes sense as that is how the damage is figured out (and with the new free-aim changes the range is determined). Since the Rocket Launcher wasn't marked with UnlimitedAmmo, it decremented the ammo counter. Since there was no setting for iSuppression, it defaulted to one shot.

 

Surprisingly (to me) the native code apparently checked the iAmmo level of the Rocket Launcher and disallowed the Fire Rocket ability because iAmmo was at 100.

 

2) XGWeapon_AlienGrenade is the weapon attached to the eAbility_AlienGrenade in the same manner.

 

Putting eWP_UnlimitedAmmo on these weapons should prevent their ammo counter from being decremented. The ammo bar should remain full, and the restriction based on charges should remain the limiting factor.

 

If that doesn't work, I can add an additional test to the beginning of the function to prevent ammo consumption if NoReload is set, but that makes a NoReload weapon automatically have UnlimitedAmmo, preventing the creation of a weapon with a large amount of ammo that can't be reloaded during the mission.

 

As an example, the LMG could be set to iSuppression = 2520, with eWP_NoReload. This means that the LMG would have a large number of shots (20) in the mission, but is not reloadable during the mission. Not sure if anyone is interested in this option, but probably worth preserving :smile:

Valid shot values above 12 are:

14, 16, 20, 25 and 50.

 

Setting a shot ammo in between will effectively default up to the next number of shots (e.g. setting 17 would result in 20 shots allowed, because it would use 100/17 = 5.88 rounded down to 5 ammo per shot, and 5 ammo per shot allows 20 shots).

 

------------------------------

 

However, this shows that there is a possibility of making the Rocket Launcher work more like other weapons, using the ammo system. It has both the number of charges AND the ammo that can act as limiters.

 

I wonder if you were to remove the NoReload restriction from the Rocket Launcher, and keep the iSuppression = 101 (so it would empty after each shot), then the soldier would have to perform a reload action before being able to fire the Rocket Launcher again.

 

The total number of Rocket Shots per mission would be limited by the number of charges of Fire Rocket / Shredder Rocket. The ammo situation would simply prevent the soldier from firing on consecutive turns, as the reload action would be required.

Link to comment
Share on other sites

Interesting proposal; I'll test it out. That sort of limitation might make me amenable to a fourth rocket. I'm not sure the rocket launcher icon is "selectable" (like a handgun) in a way that lets you get command icons for it, though. But perhaps turning off no-reload will do the trick. Will test and report back.

 

However, I'm NOT certain what items are impacted by this. Medikit charges? Thin Man Plague shots?

Link to comment
Share on other sites

Hmmmm.....

 

Yes, anything that is of type XGWeapon, and has an ability to which the weapon would be attached. Basically every item in the game is of type XGWeapon except for Armor, so it may have quite far-reaching impact.

 

Getting down into the nitty-gritty of the ammo system now :D.

 

I'd say that as part of the change pretty much any item that could be related to an ability that you do NOT want to be limited by ammo should get the eWP_UnlimitedAmmo property. Currently I'm only explicitly testing for eWP_UnlimitedAmmo and eWP_Melee.

 

And yes, the Thin Man poison spit is an equipped XGWeapon_Plague.

 

However, I look upon this as a feature, not a bug ^_^

 

This allows a mod designer to specify the maximum number of times each Thin Man can use the Plague ability during a mission so that they are limited in a similar manner as Rocketeers and Grenade users.

Link to comment
Share on other sites

What about adding a 1 turn cooldown to fire rocket? The space is tight in buildAbilities but maybe youmay find a way to free a couple of bytes.

btw, has anyone found where this "link" between ability and weapon is stablished? Is it just the ini property like eWP_FireRocket?

Link to comment
Share on other sites

I got a cooldown on Rapid Fire without any problem -- IIRC there's lots of 24 00 that can be changed to 25 to free up space in BuildAbilities. Only concern is that Fire Rocket and Shredder Rocket are two separate perks, and you could just fire the other while the first cooled down.

Link to comment
Share on other sites

What about adding a 1 turn cooldown to fire rocket? The space is tight in buildAbilities but maybe youmay find a way to free a couple of bytes.

btw, has anyone found where this "link" between ability and weapon is stablished? Is it just the ini property like eWP_FireRocket?

 

I think it's kind of a mix of different things.

 

The full-on XGUnit.BuildAbilities is the function that goes through and figures out which abilities are available to the unit. Unfortunately this is a native function.

 

Some abilities clearly have to have the ability set in the Weapons= DGC.ini file. For example, removing the eAbility_MedikitHeal from the Medikit will render it unable to perform the healing action, even if the charges are set to some positive value. However, adding the eAbility_MedikitHeal to another non-Medikit item will not grant the Heal ability. Apparently it requres both the item and the ability to be set. (probably similar to how the Bullet Swarm check was checking for the perk + Heavy class + eWP_Heavy weapon).

 

On the flip side, the Stabilize ability seems to be hard-coded to the Medikit item itself, as no ability has to be set, nor have I figured out how to remove the ability while having a Medikit equipped.

 

Just to add to the fun, it is possible to give eAbility_MedikitHeal directly to XCOM soldiers in the Characters= entry in the DGC.ini. Doing this makes the Heal ability available on every soldier (that are created after the change is made), but there are no charges by default. If charges are forced, then the soldier can heal, but the animation uses the primary weapon and firing animation and not the medikit spraying animation.

 

There is a var XGWeapon m_kWeapon variable in XGAbility_Targeted that stores which weapon is used for the ability. This is how the ammo mod tracks down which weapon to apply the ammo cost to (the new ammo cost function is a member of XGAbility_Targeted).

 

I haven't been able to determine where this variable is set. I'm guessing it is set during XGWeapon.Init(), which is called during Inventory loadout. Again, this Init() function is a native function so I haven't been able to pry any deeper than that.

 

-----------------

 

This is all for abilities. In terms of Actions, in XGAction_Fire.SimulatedInit the action's m_kWeapon is set with:

m_kWeapon = m_kUnit.GetInventory().GetActiveWeapon();
This is probably how a lot of perk-based abilities default to the current weapon and it's animation, so that not every weapon has to be given every ability.
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...