Aidiakapi / early_construction

Factorio mod that adds early game construction robots. Inspired by Nanobots.
Other
2 stars 4 forks source link

Bug: Drones don't die after completing a task when logging into factorissimo-2-notnotmelon #7

Open Eldrinn-Elantey opened 2 years ago

Eldrinn-Elantey commented 2 years ago

I play with your mod and with mods for factories from https://mods.factorio.com/mod/factorissimo-2-notnotmelon and I noticed that if you go into the factory when the drones return after dismantling, they are not destroyed but go into the inventory

Aidiakapi commented 1 year ago

Sorry for the late response, but this is probably because the robots themselves are "recreated" when they get teleported by the mod.

The way this mod works, is that essentially when a robot builds an entity, it's destroyed immediately, and when a robot destroys an entity, it's tracked, and destroyed once its inventory is empty (ie. it has dropped the items off at the player). If the original robot entity that picked something up, is recreated, the mod doesn't know that it should now destroy the next robot.

It'd probably be possible to fix it, with cooperation from the devs of the other mod, however, it's probably not really worth the time and effort, since the difference in gameplay is quite marginal.

Thanks for reporting it though.

notnotmelon commented 1 year ago

Hello! I am the dev of the other mod. Let me know if theres any way I can help.

Aidiakapi commented 1 year ago

Hey @notnotmelon!

There's essentially one of two things we'd have to make sure of:

  1. The robot entity's unit_number needs to remain unchanged, or
  2. Your mod needs to inform mine when a unit_number changes.

In essence, all robots that mine an item, are added to a "tracked" map, indexed by their unit_number, once their inventory is emptied (by depositing them into the user's inventory), it'll be destroyed. See this code for details.

I'm not entirely sure what causes the unit_number to change, since it doesn't seem like your mod is actively destroying and recreating the robots. That said, it's possible that it simply gets changed when it's teleported across surfaces. In any case, if you're interesting in adding it, I can expose an API to try_untrack(unit_number) -> bool and try_track(entity) -> bool which you could call on a pre-teleported robot, and post-teleported robot. This would look something like:

local was_tracked = early_construction.try_untrack(robot.unit_number)
robot.teleport(…)
if was_tracked then
    early_construction.try_track(robot)
end

I haven't diagnosed in-depth, so please correct me if I misunderstood how your mod moves robots between surfaces, and if you want me to add such an API.