An idea for a pitlane exit (and enter) AI steward. I post it here, because it contains more technical details than general discussion. Besides, there are many other tools and marshals, so I think it's better for their authors to make this feature, than for me to start another narrow-purpose InSim tool.
Everybody has seen the oval tracks on public hosts: the pit entrance and exit lanes are separated with barriers along the turns, because few drivers follow the marks. Usually a driver joins and at the pits' exit goes straight into the racing line.
The similar, though not that dangerous things may take place on the other tracks.
The idea is to punish those drivers. For usual races, drive-through penalty would be enough. Also there is a quite typical case: a noob joins a host during a race at oval and exits straightforward to the racing line. In this case, it would be safer to make him spectate instantly.
Forcing to spectate can also be applied to those who use the known bug wiyh Kyoto ring pits, which allows resetting from pits on the racing line.
How I'd make the app work
In each case there are two actions together: entering or exiting pits and crossing the line. Line crossing takes place on the same lap with entry/exit. So, for each player we keep an array of data:
1) XY(-1) coordinates
2) XY(-2) coordinates
3) "crossed the line" flag = 1
4) "exited pits" flag = 2
5) "entered pits" flag = 4
6) "joined race right this moment" flag (i.e. the player joined the race or shift+s-ed and hasn't yet left the pitlane) = 8
7) "abnormally accelerated" (to catch car reset) = 16
When a driver enters pit lane, the program sets the player's corresponding flag to "1", and the same for exiting pits. When the driver crosses the separating line, that flag is set to "1". If someone has joined the race (IS_NPL packet received), he also "gets" the flag 6). When crossing a splint or finish line (IS_LAP, IS_SPX packets), all flags are set to 0.
If someone exits pits and crosses the line, we'll have a set of flags: 1 + 2 = 3 (see the list above). If someone enters pitlane crossing a line, it will be 1 + 4 = 5. If someone joins the race and exits from pits, he will have 2 + 8, and if he crosses the line, he will have 2 + 8 + 1 = 11. Kyoto ring pitlane trick: 1 + 2 + 16 (the separating line should continue along the pit lane).
And so on. Simple binary operations. If someone gets a special combination, he is punished. As you see, entering pits may be distinguished from exiting, and punished in a different way, if one cares.
So, the algorythm is the following:
1. get packet of data
2. process it: calculate coordinates, check some conditions and set flags
3. check flags and set punishments to those having specific combinations
Defining the line and pits if needed
I suppose, it should be a set of vectors:
[1: [x1][y1][x2][y2]]
[2: [x1][y1][x2][y2]]
[3: [x1][y1][x2][y2]]
...
that would draw the line. It should be, of course, unique for each track configuration.
Crossing the line basically means that car's movement line crosses this line. We have 2 straights, each set by 2 points and check if they cross and where is the crossing (one point of each straight would be 0, another 1, and we check if the crossing is in this range for each straight).
Acceleration checking is also simple:
speed vector: (vx(t), vy(t)) = (x(t) - x(t-1), y(t) - y(t-1))
acceleration vector: (ax(t), ay(t)) = (vx(t) - vx(t-1), vy(t) - vy(t-1)) = (x(t) - 2x(t-1) + x(t-2), y(t) - 2y(t-1) + y(t-2)).
I haven't found any packet to report pits exiting and entering when driving. So, if pits are needed to be defined, they can be made as set of triangles. Each triangle should have apexes coords and normal vectors per each side (directed inside of the triangle).
(coords of car) - (coords of an apex) will give a vector of car's relative position. Scalar product is positive (not negative) if the car is to the inside of this triangle side. The same for all 3 sides. If all the scalar products for each normal vectors are positive, the point is inside of the triangle.
Another idea: SMX track co-ordinates operating utility
An application that would draw a track and let the user place points and vectors in WYSIWYG mode and give the necessary information:
For a single point:
XY co-ordinates, Z coord of the ground in the place
For 2 points:
1) vector between the 2 points
2) straight line equation coefficients3
3) normal vector to the left and to the right (drawing the normal vector on the map)
For 3 points (triangle):
1) size, square, perimeter, angles
2) normal vectors
For 3 points (angle mode):
1) degrees, radians
2) cosine, sine, tangent and so on
3) bisector vector
Well, maybe even without the latter, but with a possibility to export the values (or just open/save).
P.S. Going to sleep right now. If illustrations are needed, ask me, I'll make them.
Everybody has seen the oval tracks on public hosts: the pit entrance and exit lanes are separated with barriers along the turns, because few drivers follow the marks. Usually a driver joins and at the pits' exit goes straight into the racing line.
The similar, though not that dangerous things may take place on the other tracks.
The idea is to punish those drivers. For usual races, drive-through penalty would be enough. Also there is a quite typical case: a noob joins a host during a race at oval and exits straightforward to the racing line. In this case, it would be safer to make him spectate instantly.
Forcing to spectate can also be applied to those who use the known bug wiyh Kyoto ring pits, which allows resetting from pits on the racing line.
How I'd make the app work
In each case there are two actions together: entering or exiting pits and crossing the line. Line crossing takes place on the same lap with entry/exit. So, for each player we keep an array of data:
1) XY(-1) coordinates
2) XY(-2) coordinates
3) "crossed the line" flag = 1
4) "exited pits" flag = 2
5) "entered pits" flag = 4
6) "joined race right this moment" flag (i.e. the player joined the race or shift+s-ed and hasn't yet left the pitlane) = 8
7) "abnormally accelerated" (to catch car reset) = 16
When a driver enters pit lane, the program sets the player's corresponding flag to "1", and the same for exiting pits. When the driver crosses the separating line, that flag is set to "1". If someone has joined the race (IS_NPL packet received), he also "gets" the flag 6). When crossing a splint or finish line (IS_LAP, IS_SPX packets), all flags are set to 0.
If someone exits pits and crosses the line, we'll have a set of flags: 1 + 2 = 3 (see the list above). If someone enters pitlane crossing a line, it will be 1 + 4 = 5. If someone joins the race and exits from pits, he will have 2 + 8, and if he crosses the line, he will have 2 + 8 + 1 = 11. Kyoto ring pitlane trick: 1 + 2 + 16 (the separating line should continue along the pit lane).
And so on. Simple binary operations. If someone gets a special combination, he is punished. As you see, entering pits may be distinguished from exiting, and punished in a different way, if one cares.
So, the algorythm is the following:
1. get packet of data
2. process it: calculate coordinates, check some conditions and set flags
3. check flags and set punishments to those having specific combinations
Defining the line and pits if needed
I suppose, it should be a set of vectors:
[1: [x1][y1][x2][y2]]
[2: [x1][y1][x2][y2]]
[3: [x1][y1][x2][y2]]
...
that would draw the line. It should be, of course, unique for each track configuration.
Crossing the line basically means that car's movement line crosses this line. We have 2 straights, each set by 2 points and check if they cross and where is the crossing (one point of each straight would be 0, another 1, and we check if the crossing is in this range for each straight).
Acceleration checking is also simple:
speed vector: (vx(t), vy(t)) = (x(t) - x(t-1), y(t) - y(t-1))
acceleration vector: (ax(t), ay(t)) = (vx(t) - vx(t-1), vy(t) - vy(t-1)) = (x(t) - 2x(t-1) + x(t-2), y(t) - 2y(t-1) + y(t-2)).
I haven't found any packet to report pits exiting and entering when driving. So, if pits are needed to be defined, they can be made as set of triangles. Each triangle should have apexes coords and normal vectors per each side (directed inside of the triangle).
(coords of car) - (coords of an apex) will give a vector of car's relative position. Scalar product is positive (not negative) if the car is to the inside of this triangle side. The same for all 3 sides. If all the scalar products for each normal vectors are positive, the point is inside of the triangle.
Another idea: SMX track co-ordinates operating utility
An application that would draw a track and let the user place points and vectors in WYSIWYG mode and give the necessary information:
For a single point:
XY co-ordinates, Z coord of the ground in the place
For 2 points:
1) vector between the 2 points
2) straight line equation coefficients3
3) normal vector to the left and to the right (drawing the normal vector on the map)
For 3 points (triangle):
1) size, square, perimeter, angles
2) normal vectors
For 3 points (angle mode):
1) degrees, radians
2) cosine, sine, tangent and so on
3) bisector vector
Well, maybe even without the latter, but with a possibility to export the values (or just open/save).
P.S. Going to sleep right now. If illustrations are needed, ask me, I'll make them.