summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorsignde <signde@openttd.org>2004-09-11 19:34:11 +0000
committersignde <signde@openttd.org>2004-09-11 19:34:11 +0000
commit1fb915df69aaa77ec8be39bb96650e5ec568e245 (patch)
treea7f24d905e8470f6331b816f08ef922fb43b8532 /misc.c
parentd03afadad23fced4bbb11df12a01f26cdbaf6844 (diff)
downloadopenttd-1fb915df69aaa77ec8be39bb96650e5ec568e245.tar.xz
(svn r207) -Codechange: randomizer handling
-Fix: desync problem fixes -Fix: server doesnt hang anymore when a client timed out -Feature: low latency connection enhancements [*net_sync_freq, *net_ready_ahead]
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/misc.c b/misc.c
index b15ca7e1b..dcaf494db 100644
--- a/misc.c
+++ b/misc.c
@@ -8,8 +8,6 @@
extern void StartupEconomy();
extern void InitNewsItemStructs();
-static uint32 _random_seed_3, _random_seed_4;
-
byte _name_array[512][32];
static INLINE uint32 ROR(uint32 x, int n)
@@ -20,10 +18,17 @@ static INLINE uint32 ROR(uint32 x, int n)
uint32 Random()
{
- uint32 t = _random_seed_2;
- uint32 s = _random_seed_1;
- _random_seed_1 = s + ROR(t ^ 0x1234567F, 7);
- return _random_seed_2 = ROR(s, 3);
+ if (_current_player>=MAX_PLAYERS) {
+ uint32 s = _random_seeds[0][0];
+ uint32 t = _random_seeds[0][1];
+ _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7);
+ return _random_seeds[0][1] = ROR(s, 3);
+ } else {
+ uint32 s = _player_seeds[_current_player][0];
+ uint32 t = _player_seeds[_current_player][1];
+ _player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7);
+ return _player_seeds[_current_player][1] = ROR(s, 3);
+ }
}
uint RandomRange(uint max)
@@ -33,10 +38,19 @@ uint RandomRange(uint max)
uint32 InteractiveRandom()
{
- uint32 t = _random_seed_4;
- uint32 s = _random_seed_3;
- _random_seed_3 = s + ROR(t ^ 0x1234567F, 7);
- return _random_seed_4 = ROR(s, 3);
+ uint32 t = _random_seeds[1][1];
+ uint32 s = _random_seeds[1][0];
+ _random_seeds[1][0] = s + ROR(t ^ 0x1234567F, 7);
+ return _random_seeds[1][1] = ROR(s, 3);
+}
+
+void InitPlayerRandoms()
+{
+ int i;
+ for (i=0; i<MAX_PLAYERS; i++) {
+ _player_seeds[i][0]=InteractiveRandom();
+ _player_seeds[i][1]=InteractiveRandom();
+ }
}
void memswap(void *a, void *b, size_t size) {
@@ -561,7 +575,7 @@ void IncreaseDate()
return;
_cur_month = ymd.month;
-// printf("Month %d, %X\n", ymd.month, _random_seed_1);
+// printf("Month %d, %X\n", ymd.month, _random_seeds[0][0]);
/* yes, call various monthly loops */
if (_game_mode != GM_MENU) {
@@ -693,8 +707,8 @@ static const SaveLoadGlobVarList _date_desc[] = {
{&_cur_tileloop_tile, SLE_UINT16, 0, 255},
{&_disaster_delay, SLE_UINT16, 0, 255},
{&_station_tick_ctr, SLE_UINT16, 0, 255},
- {&_random_seed_1, SLE_UINT32, 0, 255},
- {&_random_seed_2, SLE_UINT32, 0, 255},
+ {&_random_seeds[0][0], SLE_UINT32, 0, 255},
+ {&_random_seeds[0][1], SLE_UINT32, 0, 255},
{&_cur_town_ctr, SLE_UINT8, 0, 255},
{&_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_UINT, 0, 255},
{&_next_competitor_start, SLE_FILE_U16 | SLE_VAR_UINT, 0, 255},