Abandoned Ruins - Updated (core)

by Keysivi

This mod doesn't do anything by itself. You need to install ruin-set mods or no ruin will be spawned. It then can spawn randomly choosen ruins in the world. These ruins are destroyed fragments of bases, forts, small oases, and more. (Now co-authored with roland77)

Content
5 days ago
2.0
4.50K

b [FIXED] Bugs in ruin size randomization and clear_area() debug

a month ago
(updated a month ago)

thresholds[size] = thresholds[size] + thresholds[ruin_sizes[i]]
needs to be i - 1 to add previous threshold to current instead of doubling current.

      if spawn_chance <= storage.spawn_chances[size] then
        if debug_log then log(string.format("[on_chunk_generated]: Trying to spawn ruin of size='%s' at event.surface='%s' ...", size, event.surface)) end
        try_ruin_spawn(size, min_distance, center, event.surface, event.tick)
      end

needs break before end . Currently when spawning small ruin it will also try to spawn all bigger sizes.

a month ago

In clear_area(half_size, center, surface)
the loop
for _, entity in pairs(surface.find_entities_filtered({area = area, type = {"resource"}, invert = true})) do
handles entities that are sometimes invalid and sometimes deletes invalid entities. Every time you log invalid entity.name or entity.type it causes a crash.

a month ago

Thank you for reporting this. I wasn't noticing the first two errors during game play.

For the last one, I posted such a crash here. So what do you suggest here? Skip every entity that has entity.valid == false? Can surface.find_entities_filtered() return an empty entity (nil) as well?

a month ago
(updated a month ago)

According to the documentation https://lua-api.factorio.com/latest/classes/LuaSurface.html#find_entities_filtered - it doesn't support a filter for valid entities. So I have to skip them in my code instead, if that's the proper fix.

EDIT: Filtering directly for valid = true or something isn't supported:
https://lua-api.factorio.com/latest/concepts/EntitySearchFilters.html

So my debug message crashes it?

a month ago
(updated a month ago)

Gee! I cannot tell Factorio to update it's GUI after a ruin set has been added to current-ruin-set's selection box. :-(

Okay, I can add lua/constants.lua which needs to be included and then get the proper "constant" from it. The mod realistic-ruins-updated will demonstrate it.

a month ago

clear_area() is clearly deleting even invalid entities on purpose. What you need to do is make sure that you don't log entity.name and entity.type when entity is invalid. e.g:

  for _, entity in pairs(surface.find_entities_filtered({area = area, type = {"resource"}, invert = true})) do
    if debug_log then log(string.format("[clear_area]: entity.valid='%s'", entity.valid)) end
    if debug_log and entity.valid then log(string.format("[clear_area]: entity.type='%s',entity.name='%s'", entity.type, entity.name)) end
    if (entity.valid and entity.type ~= "tree") or math.random() < (half_size / 14) then
      if debug_log then
        if entity.valid then
          log(string.format("[clear_area]: Destroying entity.name='%s' ...", entity.name))
        else
          log("[clear_area]: Destroying invalid entity")
        end
      end
      entity.destroy({do_cliff_correction = true, raise_destroy = true})
    end
  end
a month ago
(updated a month ago)

Ah, it doesn't work all together when the entity is invalid. I wasn't noticing this error since it didn't happen so often here.

EDIT: And thank you for reporting this. 1.3.4 addresses this now.

This thread has been locked.