[kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Bugs that are actually features.
Post Reply
sparr
Smart Inserter
Smart Inserter
Posts: 1327
Joined: Fri Feb 14, 2014 5:52 pm
Contact:

[kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by sparr »

Code: Select all

local rails = {
{"straight-rail", {x = -11, y = -7}, 7},
{"straight-rail", {x = -11, y = -9}, 3},
{"straight-rail", {x = -13, y = -5}, 7},
{"straight-rail", {x = -13, y = -7}, 3},
{"straight-rail", {x = 3, y = -3}, 0},
{"straight-rail", {x = 3, y = -1}, 0},
{"straight-rail", {x = 3, y = 1}, 0},
}
for _,rail in ipairs(rails) do
  game.surfaces.nauvis.create_entity{name=rail[1],position=rail[2],direction=rail[3],force="player"}
end

local locos = {
  {"locomotive", {x = -11.67578125, y = -7.3203125}, 1},
  {"locomotive", {x = 3, y = -0.78125}, 0},
}
for _,loco in ipairs(locos) do
  game.surfaces.nauvis.create_entity{name=loco[1],position=loco[2],direction=loco[3],force="player"}
end
This should make a train pointed northeast (direction=1) and a train pointed north (direction=0). Instead, the first train ends up pointed southwest, with an orientation of 0.625.

Also, the train location coordinates seem to be rounded. The coordinates in the test case code above were produced by manually placing locomotives in game then checking their position attribute. After running the code on a fresh map, the produced locmotives' position attributes are rounded to five(?) decimal places.

PS: this does not happen with every non-orthogonal locomotive. In my experiments with my entity mirror mod only about 1 in 4 attempts to place a locomotive on a diagonal or curved track ends up pointed the wrong way.

fstd
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Apr 28, 2018 11:42 am
Contact:

Re: [0.16.36] create_entity locomotive direction maybe backwards

Post by fstd »

I was about to report something that I suspect is the same bug.

Here's a minimal testcase to reproduce it: savegame
Instructions: There's a train stop with a single engine, add the two engines in your inventory to it by dragging, the last one (that ends up on the curved rail) will be pointed backwards.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by kovarex »

Well, the direction specification of the train is somewhat an internal thing and it is specified this way:

Horizontal direction (east or west) means natural direction, otherwise opposite.

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

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by sparr »

kovarex wrote:Horizontal direction (east or west) means natural direction, otherwise opposite.
I will experiment and see if I can figure out what this means. It is not at all clear from reading it.

User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2632
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by steinio »

sparr wrote:
kovarex wrote:Horizontal direction (east or west) means natural direction, otherwise opposite.
I will experiment and see if I can figure out what this means. It is not at all clear from reading it.

Sounds like in north and south direction backward means forward at placing...

There might be a valid reason to do it this way... ;D
Image

Transport Belt Repair Man

View unread Posts

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

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by sparr »

steinio wrote:Sounds like in north and south direction backward means forward at placing...
Sure, that's a reasonable interpretation, but that means I'm going to have to experiment to figure out where the threshold is that "forward" and "backward" switch. I'm guessing it's at or near 22.5 or 67.5 degrees, but it could be on one side or the other of one of a dozen other angles.

PS: Also none of the above addresses the position rounding. If this thread ends up dying with just an official response to the orientation part, I'll start a new thread for the position rounding.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by kovarex »

The result position won't be exact the same, as it is derived from the back and front joints. And the joint positions are kind of derived from the input position. It ends up to be similar to the location, but it won't be exact.

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

Re: [kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Post by sparr »

kovarex wrote:The result position won't be exact the same, as it is derived from the back and front joints. And the joint positions are kind of derived from the input position. It ends up to be similar to the location, but it won't be exact.
That feels like a bug. If there's a real existing entity already in the game, I should be able to record its properties, destroy it, then recreate it with the same properties, without the game interfering and rounding things.

Post Reply

Return to “Not a bug”