Thank you for the detailed reply!
I'm not really sure what behavior is intended in that scenario, whether it's not being allowed to build on top of a corpse or replacing the visible corpse entity if it gets destroyed before it's supposed to, but I'll tinker around with it and see what fits. I don't think destroying it when built over is a good idea, because it would be very easy to accidentally destroy the items inside, and that kind of goes against the point of the mod :P
I haven't looked at your code yet, but using the Lua API global Variable Viewer (gvv), I noticed that you don't save as many data as possible. For instance, after killing a crawler vehicle, I found this in global.corpse_data:
{
names = {
["medium-remnants"] = LuaEntityPrototype,
},
position = {
x = -20.328125,
y = -167.79296875,
},
surface = LuaSurface,
}
Why would you care only about the LuaEntityPrototype of the default remnants? Hovering over the remnants and pressing CTRL+SHIFT+F, I see something that seems much more useful: it's a CharacterCorpsePrototype named "crawler-corpse-dummy"! I would add at least the vehicle name derived from CharacterCorpsePrototype by stripping off the suffix "-corpse-dummy", i.e. "crawler". This way, if an entity is built on top of the corpse, you could check (using surface and position) if the name of the new entity matches that of the destroyed vehicle. If so -- why not let the new vehicle inherit the loot left behind by the old one? It would save players from having to pick up the corpse and manually adding fuel and ammo to the new vehicle, inserting whatever was in the vehicle's equipment grid, and collecting the stuff from the trunk.
In your handler for on_entity_died, you have
store_inventory(entity, temp, di.fuel)
store_inventory(entity, temp, di.burnt_result)
store_inventory(entity, temp, di.car_ammo) -- covers spider_ammo
store_inventory(entity, temp, di.car_trunk) -- covers spider_trunk
store_inventory(entity, temp, di.spider_trash)
store_grid(entity, temp)
This puts everything in the inventory of the dummy corpse, after sorting/merging. If you were to restore that to the newly built vehicle, you couldn't tell anymore what fuel was in the fuel inventory and what was just inside the trunk. Therefore, I'd modify store_inventory and store_grid in such a way that they also call game.create_inventory(#source_inventory)
and copy each stack from the real to the script inventory (script inventories are just virtual, so they don't interfere with the actual corpse inventory), to be stored with the corpse data. This way, the dummy corpse could be mined as usual by the player, but if a new vehicle of the same type as the destroyed one is placed on that position, you could move the contents of each script inventory back to the ammo, fuel, trunk, trash, or grid inventory of the new vehicle. As far as I can tell, this should also raise on_equipment_inserted
, which my mod Autodrive depends on to keep track of its active sensors. :-D