Page 1 of 1

[kovarex] [0.16.36] create_entity locomotive direction maybe backwards

Posted: Sun Apr 15, 2018 9:12 pm
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.

Re: [0.16.36] create_entity locomotive direction maybe backwards

Posted: Sat Apr 28, 2018 11:49 am
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.

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

Posted: Mon May 14, 2018 12:47 pm
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.

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

Posted: Tue May 15, 2018 6:22 am
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.

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

Posted: Tue May 15, 2018 7:21 am
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

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

Posted: Thu May 17, 2018 1:41 pm
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.

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

Posted: Thu May 17, 2018 4:08 pm
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.

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

Posted: Fri May 18, 2018 3:30 am
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.