Page 1 of 1

LuaSurface::entity_prototype_collides incorrect with curved rails

Posted: Sat Mar 16, 2024 11:00 pm
by _CodeGreen
I'm assuming this is because of the secondary collision box that curved rails have, but when the curved part collides with something and the straight part does not, the method returns the incorrect result.
I don't expect this to be fixed for 1.1.x, but I at least wanted to make sure this was made aware of in case it is relevant for 2.0.

To reproduce, place a curved rail ghost like this:
curved-rail-ghost.png
curved-rail-ghost.png (356.51 KiB) Viewed 857 times

Then, run the following command while selecting the curved rail with your mouse cursor:

Code: Select all

/c local entity = game.player.selected
game.print(game.player.surface.entity_prototype_collides(entity.ghost_prototype, entity.position, false, entity.direction))
-- false
There is a workaround for this specific scenario, which is the LuaSurface::can_place_entity method instead, however I have been told that the underlying c++ function is used for autoplace, so if anyone ever tries to give curved rails an autoplace then this would be a real issue.

Code: Select all

/c local entity = game.player.selected
game.print(not game.player.surface.can_place_entity{name = entity.ghost_name, position = entity.position, direction = entity.direction})
-- true

Re: LuaSurface::entity_prototype_collides incorrect with curved rails

Posted: Sun Mar 17, 2024 1:56 pm
by Rseding91
Thanks for the report. We're specifically doing away with the secondary-bounding-box logic in 2.0 at some point so this will resolve itself. The new rails in 2.0 do not use the logic and once we have allowed a sufficient amount of time for saves to be migrated to 2.0 we will be removing the feature entirely in a then-future update.

Re: LuaSurface::entity_prototype_collides incorrect with curved rails

Posted: Mon Mar 18, 2024 5:10 pm
by boskid
This is not relevant for 2.0 since we are trying to get rid of secondary collision box logic, however this function seems to be far more broken when considering rails given that rails have custom set of collision box orientations for each direction and this specific check directly takes bounding box from prototype and rotates it to the provided direction.

Re: LuaSurface::entity_prototype_collides incorrect with curved rails

Posted: Mon Mar 18, 2024 6:12 pm
by boskid
I am considering this to be a wont fix. Those checks are primarily for being compatible with map generator and we never assumed rails would be placable by map generator.

Re: LuaSurface::entity_prototype_collides incorrect with curved rails

Posted: Tue Mar 19, 2024 4:24 am
by _CodeGreen
As I suspected, just wanted to put it here for public record.
For clarification, would the custom collision box orientations still be an issue in 2.0 with rails having hard coded collision boxes, or is that part irrelevant as well due to the new rails?