Decoded: OpenTTD (2003) v1.8 (2018) Source file: random_func.cpp Line-by-line code walkthrough by MaiZure random_func.cpp defines functions for a random number generator Original code: https://github.com/MaiZure/OpenTTD-1.8/blob/master/src/core/random_func.cpp 1 COMMENT (*) 2 BLANK (-) 3 * 4 * 5 * 6 * 7 * 8 * 9 - 10 * 11 - 12 Include the OpenTTD platform-specific header 13 Include the OpenTTD randomizer header 14 Include the OpenTTD bitmath header 15 - 16 Check if randomizer debugging is enabled 17 Include the OpenTTD network subsystem header 18 Include the OpenTTD network server header 19 Include the OpenTTD network internals header 20 Include the OpenTTD company functions header 21 Include the OpenTTD file I/O functions header 22 Include the OpenTTD date functions header 23 End check for randomizer debugging 24 - 25 Include the OpenTTD safeguards header 26 - 27 Declare two global randomizers 28 - 29 * 30 * 31 * 32 * 33 Define Randomizer::Next with no arguments 34 BLOCK START - Randomizer::Next, increments to the next random number 35 Stores the current state 0 36 Stores the current state 1 37 - 38 Updates state 0 with some crypto fun stuff (uses old state too) 39 Updates state 1 with the old state and returns the new value 40 BLOCK END - Randomizer::Next 41 - 42 * 43 * 44 * 45 * 46 * 47 * 48 Defines Randomizer::Next with one argument, the upper bound 49 BLOCK START - Randomizer::Next, gets a bounded random value 50 Returns the next random value ranged to the upper bound 51 BLOCK END - Randomizer::Next 52 - 53 * 54 * 55 * 56 * 57 Defines Randomizer::SetSeed with one argument: the seed 58 BLOCK START - Randomizer::SetSeed, changes the random seed 59 Set randomizer state 0 to the seed 60 Set randomizer state 1 to the seed 61 BLOCK END - Randomizer::SetSeed 62 - 63 * 64 * 65 * 66 * 67 Defines SetRandomSeed with one argument 68 BLOCK START - SetRandomSeed, updates seeds for global randomizers 69 Resets the first randomizer with the new seed 70 Bumps the second randomizer with the new seed 71 BLOCK END - SetRandomSeed 72 - 73 Check if randomizer debugging is enabled 74 Defines DoRandom with 2 arguments, a line number and output file name 75 BLOCK START - DoRandom, Pulls a random number with logging 76 Checks for an inactive networking state 77 Outputs random debug input to the provided file 78 End check for networking state 79 - 80 Returns a random number 81 BLOCK END - DoRandom 82 - 83 Defines DoRandomRange with three arguments, 84 BLOCK START - DoRandomRange, logs result of a ranged random call 85 Returns the value and write the output 86 BLOCK END - DoRandomRange 87 End check for randomizer debugging