misc.c
changeset 2078 548ff600bb11
parent 2073 2d63300e4a44
child 2084 65639f898a50
equal deleted inserted replaced
2077:a271195b2722 2078:548ff600bb11
    22 static inline uint32 ROR(uint32 x, int n)
    22 static inline uint32 ROR(uint32 x, int n)
    23 {
    23 {
    24 	return (x >> n) + (x << ((sizeof(x)*8)-n));
    24 	return (x >> n) + (x << ((sizeof(x)*8)-n));
    25 }
    25 }
    26 
    26 
    27 /* XXX - Player-seeds don't seem to be used anymore.. which is a good thing
       
    28      so I just disabled them for now. If there are no problems, we can remove
       
    29      it completely! -- TrueLight */
       
    30 #undef PLAYER_SEED_RANDOM
       
    31 
       
    32 #ifndef MERSENNE_TWISTER
    27 #ifndef MERSENNE_TWISTER
    33 
    28 
    34 #ifdef RANDOM_DEBUG
    29 #ifdef RANDOM_DEBUG
    35 #include "network_data.h"
    30 #include "network_data.h"
    36 uint32 DoRandom(int line, const char *file)
    31 uint32 DoRandom(int line, const char *file)
    45 #ifdef RANDOM_DEBUG
    40 #ifdef RANDOM_DEBUG
    46 	if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server))
    41 	if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server))
    47 		printf("Random [%d/%d] %s:%d\n",_frame_counter, _current_player, file, line);
    42 		printf("Random [%d/%d] %s:%d\n",_frame_counter, _current_player, file, line);
    48 #endif
    43 #endif
    49 
    44 
    50 #ifdef PLAYER_SEED_RANDOM
       
    51 	if (_current_player>=MAX_PLAYERS || !_networking) {
       
    52 		s = _random_seeds[0][0];
       
    53 		t = _random_seeds[0][1];
       
    54 		_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1;
       
    55 		return _random_seeds[0][1] = ROR(s, 3) - 1;
       
    56 	} else {
       
    57 		uint32 s = _player_seeds[_current_player][0];
       
    58 		uint32 t = _player_seeds[_current_player][1];
       
    59 		_player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7) + 1;
       
    60 		DEBUG(net, 1)("[NET-Seeds] Player seed called!");
       
    61 		return _player_seeds[_current_player][1] = ROR(s, 3) - 1;
       
    62 	}
       
    63 #else
       
    64 	s = _random_seeds[0][0];
    45 	s = _random_seeds[0][0];
    65 	t = _random_seeds[0][1];
    46 	t = _random_seeds[0][1];
    66 	_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1;
    47 	_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1;
    67 	return _random_seeds[0][1] = ROR(s, 3) - 1;
    48 	return _random_seeds[0][1] = ROR(s, 3) - 1;
    68 #endif
       
    69 }
    49 }
    70 #endif // MERSENNE_TWISTER
    50 #endif // MERSENNE_TWISTER
    71 
    51 
    72 #if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER)
    52 #if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER)
    73 uint DoRandomRange(uint max, int line, const char *file)
    53 uint DoRandomRange(uint max, int line, const char *file)
    92 
    72 
    93 uint InteractiveRandomRange(uint max)
    73 uint InteractiveRandomRange(uint max)
    94 {
    74 {
    95 	return (uint16)InteractiveRandom() * max >> 16;
    75 	return (uint16)InteractiveRandom() * max >> 16;
    96 }
    76 }
    97 
       
    98 
       
    99 #ifdef PLAYER_SEED_RANDOM
       
   100 void InitPlayerRandoms(void)
       
   101 {
       
   102 	int i;
       
   103 	for (i=0; i<MAX_PLAYERS; i++) {
       
   104 		_player_seeds[i][0]=InteractiveRandom();
       
   105 		_player_seeds[i][1]=InteractiveRandom();
       
   106 	}
       
   107 }
       
   108 #endif
       
   109 
    77 
   110 void SetDate(uint date)
    78 void SetDate(uint date)
   111 {
    79 {
   112 	YearMonthDay ymd;
    80 	YearMonthDay ymd;
   113 	ConvertDayToYMD(&ymd, _date = date);
    81 	ConvertDayToYMD(&ymd, _date = date);