Schall Recharging Weapon

Experimental recharge mechanism. Introduced energy weapons, which recharge from personal batteries! Currently includes laser rifle, laser sniper rifle, laser shotgun, laser machine gun, mega laser cannon, chainsaw. (Locale: English, Deutsch, 正體中文, 简体中文, Português Brasileiro, Русский)

3 months ago
0.17 - 0.18

i [Solved] AmmoType.energy_consumption

1 year, 22 days ago

Hello Schall, I noticed that AmmoType has a field called 'energy_consumption' which seems intended for what you're doing in this mod--is there a reason you didn't use it in control.lua? I ask because I made another energy gun for use among my friends, but there is no way to make it work without modifying your mod or copying your recharge function into my mod.

energy_consumption = ammo[i].prototype.get_ammo_type().energy_consumption

1 year, 22 days ago

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

7 months ago

Just want to notice you that I have just released 0.17.9, which includes a remote interface that modders can now easily add guns to this recharge mechanism.
It should be much easier than looking into and editing my files. Instructions in FAQ section.

New response