[MOD 1.1] Recharging Armor - unequipped armor charges

Topics and discussion about specific mods
Post Reply
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 490
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

[MOD 1.1] Recharging Armor - unequipped armor charges

Post by Silari »

Name: Recharging Armor
Factorio Version: 1.1
URL: https://mods.factorio.com/mod/Recharging_Armor
Description: This mod attempts to fake allowing unequipped armor to recharge it's equipment. When the armor is re-equipped, it'll gain charge to all it's equipment equivalent to how much it would have gained during the time it was unequipped. Most types of equipment should be supported, vanilla or modded, with the exception of burner generator equipment. The coding on those is a bit more complicated and aren't in vanilla (or all that many mods) so I haven't bothered yet, though there's already code in place to add them in later if there's demand.

Known Issues:
If the mod is added to a save, it won't know about all the armor that exists and thus can't track it. It will search all player's inventory to find any armor, but armor in containers/vehicles won't be found as searching everywhere would be both complicated and time consuming (since AFAIK you can't just iterate all items with an item_number), and chances are important armor is going to be on the player anyway. You can make the mod start tracking any armor piece by opening it's equipment grid.
Solar panel equipment assumes a vanilla day/night cycle and doesn't track the actual time/length of day, again for simplicity reasons. Any solar panel will charge at 70% efficiency, the average rate for vanilla. TBH it probably shouldn't allow them at all - not much solar power in a pocket.
Not really an issue but kind of an oddity - unequipped armor will still distribute power from it's batteries to equipment, despite the game not allowing charging. I've only noticed this with the armor GUI open, so it might not happen if the armor is closed.

How it works:
Some items in the game have a unique item_number associated with them - this includes armor with an equipment grid. When a player equips armor, the mod stores the number for that armor. If the player changes armor, it stores the old armor's number with the tick it was removed. If a newly equipped armor is in that table of removed armor, or the player opens armor that is in the removed table, it iterates through all the equipment to sort out what's a burner generator (though these aren't currently used), what's a fusion generator, what's a solar panel, and what can store energy (basically anything else). It calculates the energy it can make per tick from solar and fusion, and distributes it to each equipment in order (based on the order of the LuaEquipmentGrid.equipment array of the armor. This part is currently slightly different to how the game normally distributes energy). If the armor isn't equipped, it then updates the tick stored for that armor.
This means armor is only updated when it's reequipped, or opened, which in vanilla should be the only time it really matters at all. It's simple and prevents needing to calculate a bunch of stuff on_tick.

Post Reply

Return to “Mods”