[Klonan] collision_mask_util.masks_collide does improper check with "not-colliding-with-itself"

This subforum contains all the issues which we already resolved.
FuryoftheStars
Smart Inserter
Smart Inserter
Posts: 2768
Joined: Tue Apr 25, 2017 2:01 pm
Contact:

[Klonan] collision_mask_util.masks_collide does improper check with "not-colliding-with-itself"

Post by FuryoftheStars »

According to all of the documentation, in the "not-colliding-with-itself" checks, all other flags should be ignored. However, that doesn't appear to be what is happening here.

collision-mask-util.lua:

Code: Select all

collision_mask_util.masks_collide = function(mask_1, mask_2)

  local map = util.list_to_map(mask_1)
  if map["not-colliding-with-itself"] and collision_mask_util.masks_are_same(mask_1, mask_2) then
    return false
  end

  clear_flags(map)

  for k, layer in pairs (mask_2) do
    if map[layer] then
      return true
    end
  end
  return false
end

collision_mask_util.masks_are_same = function(mask_1, mask_2)
  local map = util.list_to_map(mask_1)
  for k, v in pairs (mask_2) do
    if not map[v] then return false end
    map[v] = nil
  end
  return not next(map)
end
I set up a few masks to run against each other:

Code: Select all

log("Test 1: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"object-layer"})))
log("Test 2: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"not-colliding-with-itself", "object-layer"})))
log("Test 3: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "object-layer"}, {"not-colliding-with-itself", "consider-tile-transitions", "object-layer"})))
log("Test 4: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "consider-tile-transitions", "object-layer"}, {"not-colliding-with-itself", "object-layer"})))
log("Test 5: " .. tostring(collision_mask_util.masks_collide({"not-colliding-with-itself", "consider-tile-transitions", "object-layer"}, {"not-colliding-with-itself", "consider-tile-transitions", "object-layer"})))
And this was what it returned:

Code: Select all

   2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:5: Test 1: true
   2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:6: Test 2: false
   2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:7: Test 3: true
   2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:8: Test 4: true
   2.561 Script @__RestrictionsOnArtificialTiles__/data-final-fixes.lua:9: Test 5: false
Unless my understanding of things is wrong, tests 3 & 4 should've returned false as well.
My Mods: Classic Factorio Basic Oil Processing | Sulfur Production from Oils | Wood to Oil Processing | Infinite Resources - Normal Yield | Tree Saplings (Redux) | Alien Biomes Tweaked | Restrictions on Artificial Tiles | New Gear Girl & HR Graphics
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [Klonan] collision_mask_util.masks_collide does improper check with "not-colliding-with-itself"

Post by Klonan »

Thanks for the report

It is fixed for the next release
Post Reply

Return to “Resolved Problems and Bugs”