Shield upgrade research

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Shield upgrade research

Post by AngledLuffa »

I was thinking of working on a mod where researching shield technology upgrades your shields to soak more damage. Naturally, this would be much easier if a shield upgrade technology bonus already existed.

Currently I think the only way to do it would be to find all existing shield items and replace them with a new upgraded item when the research finishes. This probably means all items in player inventories, on the ground, in chests, being hand crafted, being machine crafted, or installed in a grid. Seems like a complicated, error-prone process.

If there's an easier way to do it, such as by changing the existing item prototype when a research finishes, I'd love to hear about that instead. So far all of my google searching suggests that once an item prototype is created, it can't be changed in-game for the existing items.

Thanks!

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Shield upgrade research

Post by Honktown »

on_player_placed_equipment, on_player_removed_equipment, and on_player_armor_inventory changed. Write functions needed so when a player inserts the equipment, if the research is completed, a different shield item is inserted. On removing the equipment prototype can have defined that it returns the base shield item (take_result).

on_player_placed_equipment: swap base shield for best, in the proper entity/equipment grid

on_player_removed_equipment: not needed maybe, since the shield is an actual item, and can be "converted" by setting the take_result

on_player_armor_inventory_changed: scan for the earlier versions of shields that are equipped, replace with current version.

Probably wouldn't be compatible with vehicle equipment. I want to get some sleep, but I can post a request for it in the mod API requests you want: add an "entity" whose armor changed, instead of just a player index. I'm sure somebody would want that if there are no events already.
I have mods! I guess!
Link

AngledLuffa
Fast Inserter
Fast Inserter
Posts: 187
Joined: Fri Jan 05, 2018 5:18 pm
Contact:

Re: Shield upgrade research

Post by AngledLuffa »

It sounds like your suggestion is basically to only apply the bonus when the shield is equipped. Would this work for existing armor / vehicles / other grids that have the upgraded shield? Also, it would be great to be able to show the bonus as part of the tooltip when hovering over the item, which wouldn't happen unless unequipped items also got upgraded.

Thanks for the advice!

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Shield upgrade research

Post by Honktown »

The last bit of my post. Interestingly, the events hint that only players are supposed to be able to equip armor.

https://lua-api.factorio.com/latest/events.html

Vehicles can have equipment grids, but they're fixed (not armor). This should mean that only player inserted/removed equipment should be relevant for non-character entities.
Now I have to see if I can make a vehicle have an armor slot and crash the game somehow
As for the tooltip, yeah, it's not a real effect you can apply to a prototype, so it can't show up in the tooltip for the item, but in the equipment grid it would show on the inserted item/armor.

As far as I know, only players can insert equipment, outside of scripting (a script could write a player to the event, I guess).

You could upgrade all the items, but you'll have to check for all the items on removal/insertion, and worse: recipes. It'd be kind of inconsistent: do you let people make the old shield only, and it always upgrades on insertion? Can they make the better shield (which would be required for every bonus) and then you do or don't try and convert all assemblers in existence? Do you lock out the old recipe and only permit the new one, but don't replace existing crafts?

I'd prefer to lean towards the no-recipe side, it'd just be much simpler. It does make it more confusing since you can't know your current shield bonus without checking the technology or having a shield inserted somewhere. On that note: when the new tech finishes, go through all players and vehicles with equipment grids and upgrade the shields : P . Easiest way: use in game.entity_prototypes, and do a surface filtered search on each of them.
I have mods! I guess!
Link

Post Reply

Return to “Modding interface requests”