Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Racing plug-in... need guidance from gurus

 
Post new topic   Reply to topic Printable version
 View previous topic  *objon / *objset Post :: Post How do I  View next topic  
Author Message
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Tue Jun 19, 2007 7:41 pm    Post subject: Racing plug-in... need guidance from gurus Reply to topic Reply with quote

I'm making this racing plug-in for F1-type racing.
I want to be able to know the position (1st, 2nd...) of each racer during the race, at any time...

I've just thought of a solution that makes sense, but I was just wondering maybe you more experienced coders out there might have a better, or more efficient idea...

Basically I'll have to put a lot of checkpoints... atleast whenever the road changes angle

I already have code that identifies through which waypoint the player goes, and stacks them. If player goes through his last visited checkpoint (in reverse), it unstacks it.

In the checkpoint structure, I'd put an angle that indicates the angle of the following road segment.

Now to calculate a player's rank...
Pretty simple, basically its in order of number of checkpoints crossed... But if 2 have the same amount, they're in the same road segment. Knowing the angle of the road segment, it would be pretty easy to sort them according to their x,y coordinates.
I'm just not too sure about this part, how to sort them exactly (ideas?)... Since I check player by player, I guess the best thing to do would be a linkedlist, scroll through it, find the desired rank of the current player, delete the old node, and insert a new one where needed...

By the way I'm coding this for Merv

So emmm... Does it all makes sense?

Any help/hints appreciated

Thanks icon_smile.gif
_________________
(Insert a bunch of dead links here)
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Wed Jun 20, 2007 5:55 am    Post subject: Reply to topic Reply with quote

Assuming you have checkpoints on all the bends, all you need to do when 2 players are in the same segment is compare their distance from the last checkpoint. No need to directly compare player xy's and use the angle to make some weird rotation.

This solution might not work so well if the track was very wide.

Also I wouldn't count the number of checkpoints passed, simply the current lap # and the last checkpoint #. This means you don't have to worry about removing links when players go in reverse. Of course you would only update the "last checkpoint #" if it was greater than the old value, or the lap # had increased.
_________________
ss news




checkpoint-solution.png - 3.98 KB
File downloaded or viewed 17 time(s)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Witchie NL
Seasoned Helper


Age:35
Gender:Gender:Male
Joined: Jul 24 2005
Posts: 112
Location: Veere, Zeeland, Netherlands
Offline

PostPosted: Wed Jun 20, 2007 6:22 am    Post subject: Reply to topic Reply with quote

or add some checkpoints every 20? tiles and the first person to cross it gets position 1 2nd person gets pos 2 etc etc.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website MSN Messenger
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Wed Jun 20, 2007 10:38 am    Post subject: Reply to topic Reply with quote

Another option is to draw a polyline of the course, and find the player's shortest normal to that line. You then know his position on the line, and the line's total length. You now know how far he is in the course and how much is left.

This does fail if the course is soft (can run outside the track), but can correct for that by drawing border lines, and once a user crosses that, you can record his last known position on course. If he reenters the course too far away from where he left, you can know he tried to cheat the course and can warp him back to where he last left the course.
Back to top
View users profile Send private message Add User to Ignore List Send email
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Wed Jun 20, 2007 11:05 am    Post subject: Reply to topic Reply with quote

Quote:
Another option is to draw a polyline of the course, and find the player's shortest normal to that line. You then know his position on the line, and the line's total length. You now know how far he is in the course and how much is left.
How would you exactly 'draw a polyline' ? You need like... an array of points or something ?.o

The course is not soft... walls make a big metal crunching noise tongue.gif

I like smong's idea... You're right only the distance would work fine
Though I do have to unstack checkpoints, cause for example, if 2 players cross the same checkpoint... Player A stops there
Player B goes back 100 tiles in reverse
B's distance from 'last checkpoint #' will be greater than A's... So B's last checkpoint should also change when going back in reverse through checkpoints.
Anyways the stacking part for forward/reverse is already done

Only using the distance would be somewhat less accurate than if I know the angle of the road segment though... As you say it depends on the width of the track

Quote:
or add some checkpoints every 20? tiles and the first person to cross it gets position 1 2nd person gets pos 2 etc etc.
That's what I'm trying to avoid... I don't want to add a hundred checkpoints.

thanks, that gave me some more ideas
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Wed Jun 20, 2007 11:46 am    Post subject: Reply to topic Reply with quote

Samapico wrote:
How would you exactly 'draw a polyline' ? You need like... an array of points or something ?.o

Exactly. The first point is the midpoint of the starting line, and each point is the next 'turn' of the course, always using the midpoint of the track. Thus, each set of two adjacent points is a line, including the last/first points.

You create a normal between the player's current position against each line created by the array, and determine the normal's length to that line. The shortest normal is the line the user is closest to.

Now that you know which line section he is at, you can determine his length along that line, because you have a direction that the track goes with that line. That gives you his length of that line, which you can add the length of all the previous lines to get his current distance in the course. Compare to the total length of the whole polyline, and you can determine his percent of the course completed for pretty displays/stats.

Since you are recording each point, you can always name each section as well with the polyline method. And example structure that you can use:
Code: Show/Hide
struct Point
{
   int x, y; //Obviously the X/Y coords of the point
   char name[50]; //The name of this section of the course
   int distance; //The sum of all previous lines (so don't need to recalc)
};
So you have a struct Point polyline[20] defined and filled in. polyline[0] -> polyline[1] would be the first line, with a distance of 0 in polyline[0], and a name of "First leg" or something. polyline[19] -> polyline[0] would have a distance of the total sum of all previous lines in polyline[19] with a name of "starting point" or "finishing line" if the course is looped. If the course isn't looped, polyline[19] would be the end of the course and it wouldn't loop.
Back to top
View users profile Send private message Add User to Ignore List Send email
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Fri Jun 22, 2007 7:26 pm    Post subject: Reply to topic Reply with quote

Samapico wrote:
thanks, that gave me some more ideas

Give them a try yet? I never actually used the method I suggested, but would be what I would do in your situation. Be interested in knowing how it turned out if you tried it.
Back to top
View users profile Send private message Add User to Ignore List Send email
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 62 page(s) served in previous 5 minutes.

phpBB Created this page in 0.522467 seconds : 33 queries executed (91.2%): GZIP compression disabled