I’m making a vehicle power mod for tools. Currently I have a hacky implementation where I set fake item charges for all modded tools whenever jumper cable active item function ticks. This works most of the time, but can be exploited by dropping the item, detaching the cable and picking item back up.
While this will still work properly with tools that ask nicely, crafting functions just go straight for item.charges.
Also, I eventually want to make it so that the item doesn’t need to be held by the player, but can just share a tile with special vehicle part, so charges should also be reset when picked up.
All my problems would be solved by wrapping item.charges with a virtual getter and using that (this would also make UPS powered tools much more… UPS powered), but that’s probably not an option. Or is it?
Any other solution?
All my problems would be solved by wrapping item.charges with a virtual getter and using that (this would also make UPS powered tools much more... UPS powered), but that's probably not an option. Or is it?
There is no need for virtual, the item class is not inherited by any other class, so the only function would be in the item class.
However, how does the item know where it is? You’d need at least the items coordinates, so the function would be [tt]item::get_charges(point location) const[/tt]. Next thing: how do you prevent several items drawing power from the same source (UPS or vehicle) concurrently? Imagine an UPS with 10 charges and two items that can use that UPS. How many charges do those items have - 10 each, or 5 each, or one 10, the other none? How is the power distributed?
Crafting is a long action and there are more problems: how do you make sure the required charges are still there at the end of the action? Imagine an UPS with some charges, but a worn item (flashlight or whatever) draws from it, the crafting takes a while, the worn items could have consumed all the UPS charges, there would be none left for the crafting tool. And if you think about consuming the charges upfront: how do you give back charges when the crafting is aborted?
Any other solution?
No, sadly, but it bothers me, too.