Page 1 of 1

[0.16.15] regenerate_entity() ignores runtime map settings

Posted: Tue Jan 09, 2018 3:38 pm
by Dustine
When you change the map_gen_settings of a surface (I've only experimented with autogen_control sizes), regenerate_entity doesn't seem to respect these new settings.

Easiest way to replicate it that I found was:
  • Create a small 256x256 world with iron ore gen size set to none.
    Image
  • Check how much iron there is and what the iron ore gen size is. It should be "none" and "0", respectively.

    Code: Select all

    game.print("Iron gen: "..game.surfaces.nauvis.map_gen_settings.autoplace_controls["iron-ore"].size);
    game.print("Iron count: "..game.surfaces.nauvis.count_entities_filtered{name="iron-ore"})
  • Change the iron gen size to normal. The console should now print "Iron gen: normal." (ran the same code as in the previous step).

    Code: Select all

    local settings=game.surfaces.nauvis.map_gen_settings;
    settings.autoplace_controls["iron-ore"].size="normal";
    game.surfaces.nauvis.map_gen_settings=settings;
    game.print("Iron gen: "..game.surfaces.nauvis.map_gen_settings.autoplace_controls["iron-ore"].size)
  • Run surface.regenerate_entity() and wait a bit. Count how much iron ore there is, which it'll be 0 still.

    Code: Select all

    for _, e in pairs(game.surfaces.nauvis.find_entities()) do e.destroy() end;
    game.surfaces.nauvis.regenerate_entity();
    Image
  • Finally, delete all chunks so they are recreated, and count how much ore you have, a non-zero amount now. If you're using the seed I showed above, it'll be 738.

    Code: Select all

    for chunk in game.surfaces.nauvis.get_chunks() do game.surfaces.nauvis.delete_chunk(chunk) end
    Image
Edit: forgot to delete entities before running regenerate, but the bug still occurs when I do so.

Re: [0.16.15] regenerate_entity() ignores runtime map settings

Posted: Tue Jan 09, 2018 9:39 pm
by Rseding91
Thanks for the report. I'm not sure what's best here: you can use regenerate_entity with an entity that doesn't exist in the surface settings so it can't always use those values.

Re: [0.16.15] regenerate_entity() ignores runtime map settings

Posted: Tue Jan 09, 2018 11:51 pm
by Dustine
Rseding91 wrote:Thanks for the report. I'm not sure what's best here: you can use regenerate_entity with an entity that doesn't exist in the surface settings so it can't always use those values.
Um, true, the sticking point for me is the inconsistent behaviour with how deleting chunks respect the settings and creates stuff using them, there are cases (I mean, that's how I found it) where I can't afford to delete a chunk to recreate stuff in it based on new settings (like toggling back on an ore resource that the player disabled on map gen). But I hadn't thought on entities outside said settings...