14 static inline uint32 ROR(uint32 x, int n) |
15 static inline uint32 ROR(uint32 x, int n) |
15 { |
16 { |
16 return (x >> n) + (x << ((sizeof(x)*8)-n)); |
17 return (x >> n) + (x << ((sizeof(x)*8)-n)); |
17 } |
18 } |
18 |
19 |
19 // For multiplayer, we introduced this new way of random-seeds |
20 /* XXX - Player-seeds don't seem to be used anymore.. which is a good thing |
20 // It is player-based, so 2 clients can do 2 commands at the same time |
21 so I just disabled them for now. If there are no problems, we can remove |
21 // without the game desyncing. |
22 it completely! -- TrueLight */ |
22 // It is not used for non-multiplayer games |
23 #undef PLAYER_SEED_RANDOM |
23 #ifdef ENABLE_NETWORK |
24 |
24 #define PLAYER_SEED_RANDOM |
25 #ifdef RANDOM_DEBUG |
|
26 #include "network_data.h" |
|
27 |
|
28 uint32 DoRandom(uint line, char *file) |
25 #else |
29 #else |
26 #undef PLAYER_SEED_RANDOM |
30 uint32 Random() |
27 #endif |
31 #endif |
28 |
32 { |
29 // its for now not used at all because it is still desyncing :( |
33 #ifdef RANDOM_DEBUG |
30 #undef PLAYER_SEED_RANDOM |
34 if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server)) |
31 |
35 printf("Random [%d/%d] %s:%d\n",_frame_counter, _current_player, file, line); |
32 uint32 Random() |
36 #endif |
33 { |
37 |
34 #ifdef PLAYER_SEED_RANDOM |
38 #ifdef PLAYER_SEED_RANDOM |
35 if (_current_player>=MAX_PLAYERS || !_networking) { |
39 if (_current_player>=MAX_PLAYERS || !_networking) { |
36 uint32 s = _random_seeds[0][0]; |
40 uint32 s = _random_seeds[0][0]; |
37 uint32 t = _random_seeds[0][1]; |
41 uint32 t = _random_seeds[0][1]; |
38 _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
42 _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
39 return _random_seeds[0][1] = ROR(s, 3); |
43 return _random_seeds[0][1] = ROR(s, 3); |
40 } else { |
44 } else { |
41 uint32 s = _player_seeds[_current_player][0]; |
45 uint32 s = _player_seeds[_current_player][0]; |
42 uint32 t = _player_seeds[_current_player][1]; |
46 uint32 t = _player_seeds[_current_player][1]; |
43 _player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7); |
47 _player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7); |
|
48 DEBUG(net, 1)("[NET-Seeds] Player seed called!"); |
44 return _player_seeds[_current_player][1] = ROR(s, 3); |
49 return _player_seeds[_current_player][1] = ROR(s, 3); |
45 } |
50 } |
46 #else |
51 #else |
47 uint32 s = _random_seeds[0][0]; |
52 uint32 s = _random_seeds[0][0]; |
48 uint32 t = _random_seeds[0][1]; |
53 uint32 t = _random_seeds[0][1]; |
49 _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
54 _random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
50 return _random_seeds[0][1] = ROR(s, 3); |
55 return _random_seeds[0][1] = ROR(s, 3); |
51 #endif |
56 #endif |
52 } |
57 } |
53 |
58 |
|
59 #ifdef RANDOM_DEBUG |
|
60 uint DoRandomRange(uint max, uint line, char *file) |
|
61 { |
|
62 return (uint16)DoRandom(line, file) * max >> 16; |
|
63 } |
|
64 #else |
54 uint RandomRange(uint max) |
65 uint RandomRange(uint max) |
55 { |
66 { |
56 return (uint16)Random() * max >> 16; |
67 return (uint16)Random() * max >> 16; |
57 } |
68 } |
|
69 #endif |
58 |
70 |
59 uint32 InteractiveRandom() |
71 uint32 InteractiveRandom() |
60 { |
72 { |
61 uint32 t = _random_seeds[1][1]; |
73 uint32 t = _random_seeds[1][1]; |
62 uint32 s = _random_seeds[1][0]; |
74 uint32 s = _random_seeds[1][0]; |
73 { |
85 { |
74 int i; |
86 int i; |
75 for (i=0; i<MAX_PLAYERS; i++) { |
87 for (i=0; i<MAX_PLAYERS; i++) { |
76 _player_seeds[i][0]=InteractiveRandom(); |
88 _player_seeds[i][0]=InteractiveRandom(); |
77 _player_seeds[i][1]=InteractiveRandom(); |
89 _player_seeds[i][1]=InteractiveRandom(); |
78 } |
90 } |
79 } |
91 } |
80 |
92 |
81 void SetDate(uint date) |
93 void SetDate(uint date) |
82 { |
94 { |
83 YearMonthDay ymd; |
95 YearMonthDay ymd; |
84 ConvertDayToYMD(&ymd, _date = date); |
96 ConvertDayToYMD(&ymd, _date = date); |
85 _cur_year = ymd.year; |
97 _cur_year = ymd.year; |
86 _cur_month = ymd.month; |
98 _cur_month = ymd.month; |
|
99 } |
|
100 |
|
101 |
|
102 // multi os compatible sleep function |
|
103 |
|
104 #if defined(__AMIGA__) |
|
105 // usleep() implementation |
|
106 # include <devices/timer.h> |
|
107 # include <dos/dos.h> |
|
108 |
|
109 static struct Device *TimerBase = NULL; |
|
110 static struct MsgPort *TimerPort = NULL; |
|
111 static struct timerequest *TimerRequest = NULL; |
|
112 #endif // __AMIGA__ |
|
113 |
|
114 void CSleep(int milliseconds) |
|
115 { |
|
116 #if defined(WIN32) |
|
117 Sleep(milliseconds); |
|
118 #endif |
|
119 #if defined(UNIX) |
|
120 #if !defined(__BEOS__) && !defined(__AMIGAOS__) |
|
121 usleep(milliseconds * 1000); |
|
122 #endif |
|
123 #ifdef __BEOS__ |
|
124 snooze(milliseconds * 1000); |
|
125 #endif |
|
126 #if defined(__AMIGAOS__) && !defined(__MORPHOS__) |
|
127 { |
|
128 ULONG signals; |
|
129 ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
|
130 |
|
131 // send IORequest |
|
132 TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
|
133 TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
|
134 TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
|
135 SendIO((struct IORequest *)TimerRequest); |
|
136 |
|
137 if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
|
138 AbortIO((struct IORequest *)TimerRequest); |
|
139 } |
|
140 WaitIO((struct IORequest *)TimerRequest); |
|
141 } |
|
142 #endif // __AMIGAOS__ && !__MORPHOS__ |
|
143 #endif |
87 } |
144 } |
88 |
145 |
89 void InitializeClearLand(); |
146 void InitializeClearLand(); |
90 void InitializeRail(); |
147 void InitializeRail(); |
91 void InitializeRailGui(); |
148 void InitializeRailGui(); |
590 /* check if we entered a new month? */ |
651 /* check if we entered a new month? */ |
591 ConvertDayToYMD(&ymd, _date); |
652 ConvertDayToYMD(&ymd, _date); |
592 if ((byte)ymd.month == _cur_month) |
653 if ((byte)ymd.month == _cur_month) |
593 return; |
654 return; |
594 _cur_month = ymd.month; |
655 _cur_month = ymd.month; |
595 |
|
596 // printf("Month %d, %X\n", ymd.month, _random_seeds[0][0]); |
|
597 |
656 |
598 /* yes, call various monthly loops */ |
657 /* yes, call various monthly loops */ |
599 if (_game_mode != GM_MENU) { |
658 if (_game_mode != GM_MENU) { |
600 if (HASBIT(_autosave_months[_opt.autosave], _cur_month)) { |
659 if (HASBIT(_autosave_months[_opt.autosave], _cur_month)) { |
601 _do_autosave = true; |
660 _do_autosave = true; |