[1.1.94] Entity build_grid_size produces unexpected results for bigger entities

Things that we don't consider worth fixing at this moment.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

[1.1.94] Entity build_grid_size produces unexpected results for bigger entities

Post by sparr »

Entities with a build_grid_size of 2 and a width (based on the collision and selection boxes) of 2, 4, 8, 12, 16, ... follow the normal 2x2 rail grid.
Otherwise identical entities with a width of 6, 10, 14, ... are placed on a grid that is offset by one tile if you consider their bounding boxes.

If you instead consider the entity center points, then width 2 is placed on the rail grid and every other width is placed one tile offset horizontally.

This behavior does not seem desirable or expected, either way.
factorio_bug_build_grid_size.png
factorio_bug_build_grid_size.png (52.22 KiB) Viewed 499 times

Code: Select all

local function get_recipe_and_item_prototypes(name, icon)
  return {
    { type = "recipe", name = name, enabled = true, result = name, ingredients = {}, },
    { type = "item", name = name, icon = icon, icon_size = 64, place_result = name, stack_size = 100, },
  }
end

local function get_entity_prototype(name, icon, size)
  local entity = table.deepcopy(data.raw["simple-entity-with-owner"]["simple-entity-with-owner"])
  entity.name = name
  entity.icon = icon
  entity.build_grid_size = 2
  entity.collision_box = {{-size[1]/2+0.1, -size[2]/2+0.1}, {size[1]/2-0.1, size[2]/2-0.1}}
  entity.selection_box = {{-size[1]/2, -size[2]/2}, {size[1]/2, size[2]/2}}
  return entity
end

for i=1,6 do
  local name = "test-" .. i
  local icon = "__base__/graphics/entity/land-mine/hr-land-mine.png" -- arbitrary 64x64 image
  data:extend(get_recipe_and_item_prototypes(name, icon))
  local entity = get_entity_prototype(name, icon, {2*i,2})
  entity.picture = { filename = icon, width = 64, height = 64, }
  data:extend({entity})
end

sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

Re: [1.1.94] Entity build_grid_size produces unexpected results for bigger entities

Post by sparr »

If the 2.0 ramp entity had been 14 or 18 tiles wide instead of 16, I suspect a dev would have encountered this bug.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.94] Entity build_grid_size produces unexpected results for bigger entities

Post by boskid »

Thanks for the report however i am going to move this to `Won't fix` because there are not enough places in code that would allow me to decide what values are correct (in 1.1.x only entities using build_grid_size are TrainStop which is 2x2 and Rails, where StraightRail always is 2x2 and CurvedRail always is 8x4 or 4x8). I do not want to touch this logic in 1.1.x because it could easily become a mod breaking change if there are mods that are based on current behavior.

As for 2.0 and ramp, rails and rail support, i was indeed going through this logic however i was unable to find pieces of code that are strictly dependent on the tileGridSize being correct so i decided to force some of the entities to be 2x2 if i want them to be buildable on 2x2 grid center, 2x4 if i want them to be buildable on 2x2 grid edges and 4x4 to force them to be buildable on 2x2 grid corners. If you specify EntityPrototype::tile_width and EntityPrototype::tile_height, then those values will be used as entity's tileGridSize which affects the build position function. When those values are not specified the EntityPrototype will try to deduce those values as the CollisionBox width and height rounded up. Support in 2.0 will be quite an exception because it has custom build position function so it always snaps to the correct grid depending on the direction of the support. Well... All rails in 2.0 will have quite cusom build position function because i did not want to understand the tileGridSize logic as it was not cooperating.

Check if you can bend behavior of the build position function by having 2x6 entity which reports as being 2x4 tile grid size.

Post Reply

Return to “Won't fix.”