*** Yes, I'm aware that MarkVeiermann has made an excellent explanation about track code and how it works. I just felt that it was missing a few details. Free Rider has a fairly complex code "compression" system that is modular and logical. Seriously, Pete did a good job on that. But without access to the decompressed FRHD code, it's hard to decipher and hard to understand. My hopes in creating this thread are that it will help people better understand the code. Just to be clear, this is not an "autogen" tutorial. Hopefully nobody will comment on that. 1. Structure The FRHD track code can be split into 3 parts: physics lines, scenery lines, and powerups. Older tracks specify a vehicle type at the end, while on newer tracks it is stored in the track's JS file on the FRHD server. The structure is as follows: Code: <Physics Lines>#<Scenery Lines>#<Powerups> On older tracks: Code: <Physics Lines>#<Scenery Lines>#<Powerups> One important thing to remember is that lower y values actually correspond to higher positions on screen. Lower x values behave as they would on a graph. 2. Base32 Integers in FRHD track code are stored in Triacontakaidecimal code, also known as base32hex. The alphabet for this variant of base32 is "0123456789abcdefghijklmnopqrstuv". Since they are integers, there are strictly NO decimal values in FRHD code. Examples: Code: Decimal | Base32hex 10 a 50 1i 100 34 25 P 75 2b -10 -a -50 -1i -100 -34 3. Line Format Lines must consist of 4 or more points. Points are encoded in base32hex and stored with spaces in between values. Basically, this is the line format: Code: -1i 0 1i 0 ^ Simple line. Consists of 4 points (x1,y1,x2,y2). In this case, it is a single line going from (-50,0) to (50,0). -1i 0 1i 0 2b 34 ^ Double line. Consists of 6 points (x1,y1,x2,y2,x3,y3). In this case, it is 2 lines, one of which goes from (-50,0) to (50,0), and another connected line, going from (50,0) to (75,100). -1i 0 1i 0, -a -1i p 2b ^ 2 separate lines. Consists of 8 points (x1,y1,x2,y2) and (x3,y3,x4,y4). Notice that these are in different lists. The first line goes from (-50,0) to (50,0), and the second goes from (-10,-50) to (25,75). 4. Powerup Format Powerups are comprised of a powerup code, an x value, a y value, and other optional values. These can be rotation or time. Formats: *Rotation values are in degrees, and yes, they are in base32hex as well. Star (Powerup code T): x,y Boost (Powerup code B): x,y,rotation Gravity (Powerup code G): x,y,rotation Slow Motion (Powerup code S): x,y Bomb (Powerup code O): x,y Checkpoint (Powerup code C): x,y Helicopter (Powerup code V): x,y,1,time (seconds) ***The helicopter powerup MUST have a 1 appended after the x and y values. Examples: Code: T 1i 0 ^ Powerup code spawns a star at (50,0) B 1i 0 1i ^ Powerup code spawns a boost at (50,0) with rotation 50 degrees G 1i 0 1i ^ Powerup code spawns a gravity at (50,0) with rotation 50 degrees S 1i 0 ^ Powerup code spawns a slow motion at (50,0) 0 1i 0 ^ Powerup code spawns a bomb at (50,0) C 1i 0 ^ Powerup code spawns a checkpoint at (50,0) V 1i 0 1 1s ^ Powerup code spawns a helicopter at (50,0) that lasts for 60 seconds 6. Putting it All Together Below is a track example, straight off of Free Rider HD. Notice that: Some lines are made of more than 4 points, making it have more segments. Lines are separated with commas. The powerups are also separated with commas. The hashtags octathorpes are in the correct places. Code: -18 1i 18 1i 29 1b,t -1v 1o -12,4u 7 3c 24,-3b o -2b 26#29 1b 8 -27 -18 1i,-1l -1d -11 -1g,3c -k 2s h,1s -2o 2j -2l#B 1c e 2g,G 3s 6 0,T 2h 7 7. Conclusion The FR track storage system is by no means a simple algorithm, but it is logically organized in a way that makes it efficient and fast. I hope you got something out of this thread and that you liked it. Feedback is greatly appreciated. Thanks.
Well of course, but it's really irrational and would increase the chance of screwing up tenfold. Not to mention it'd take way longer and would give you no room to revise what you've drawn. But yeah, technically if you understand the code you could 'write' a track. Useless, but kinda cool.
Also, I think you may have skipped over this but maybe I just read over it. What distinguishes a scenery line from a physics line? Is it the use of negatives? Just curious.
CityShep A scenery line is distinguished from a physics line because of its position in the track's structure. A track starts with the physics line code, then a hashtag, then the scenery line code, hashtag, then powerups. The use of negatives does not affect the type or line, but it does affect the position. Thanks for asking
For fun I used to type in random things to the import part and see what crazy things happened, don't know if it still works though
Ah, I see! So it categorizes them all into their groups. Thanks for explaining, I kinda failed to pick that up haha
My guess is that the 1 for the helicopter powerup is the ID of the powerup, so they can expand it later if they want to. Like maybe add other powerups.
Wow! This looks really complex and I'll have to have a read over it later when I have a clearer mind! Thanks so much for this - I can see that you've put a heap of hard work and effect into it.
For those interested Ive out together a little JS script for convert from decimal to base32hex. It hasn't really been optimized, but it gets the job done (10,000+ numbers in a couple seconds). This was written on the p5.js Web editor so anybody reading has access. Enjoy function convert (decimal){ let memDec = decimal; let outBase = ""; let baseStr = "0123456789abcdefghijklmnopqrstuv"; let sign = ""; if (memDec < 0){ memDec *= -1; sign = "-"; } while (memDec != 0){ outBase = baseStr[memDec % 32] + outBase; memDec -= (memDec % 32); memDec /= 32; } return sign + outBase; }