To my knowledge, in vanilla Factorio, AmmoType.energy_consumption
is only used in laser turret and personal laser defense. This is a property of the "fake ammo types", which is embedded in the turret/equipment definitions.
It is totally unused/undefined in other "actual ammo types".
For current game version (0.17.50), a player gun or vehicle gun cannot use fake ammo types, because it needs some actual ammo in the respective ammo slot just to fire. So actual ammo types are needed, and this mod introduce the "charging mechanism" to fill the ammo from grid power.
Then finally to the point of your question: why don't I just define it in each ammo type, and use it in control.lua?
A) Firstly, I have no idea how the game handles such an "unused property" of actual ammo types. Maybe I can access these values in control.lua under current version, but what about future versions? Maybe the devs will change the policy (say, for bug prevention measures) in some version. So it is better to store these values in a safer way.
B) Secondly, in theory, a gun can use multiple ammo types, it is not one-to-one mapping. (Say, pistol has 3 ammo types: yellow, red and green magazines.) But guns in this mod can have one possible ammo type only. (There is no way to tell a gun to charge another ammo type.) So my charging script in control.lua have to "remember" what ammo type to charge anyway... So why don't I just put the values of shot energy also there?
C) Thirdly, it is about update time / UPS. In multiplayer games or using weapons of high fire rates, the (re)charge script is executed more than you could expect. Accessing ammo prototypes every time, just for this same shot energy values, can increase the update time.
But I understand that you want to add your own guns to use my charging script.
I am thinking of allowing my table recharge_charges
accessible by external mods, so other mods (including yours) can add new entries of guns to the table...
I am not knowledgeable about inter-mod communications... Is it sufficient, if removing the local
label in control.lua line 4, then in your mod add the following code:
recharge_charges[$your_ammo_name$] = {energy=2000, stack_size=4, magazine_size=25}
Note that your mod also needs a dependency to this mod, to make sure your code is loaded AFTER mine, to prevent overwriting.
If all these works, then I will upload a new version, which will be modified as above, and use a better variable name than recharge_charges
. (As a local variable, I don't expect it to be accessible by external mods...)