mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
- Magically appeared reinforcements for enemy and militia just turn after they are called from now could be delayed and randomized. Details: - Practically all enemy reinforcement which can populate available slots was always appeared next turn after they are called so now we have game settings under "Strategic Gameplay Settings" for fine tunning enemy and militia reinforce entry: MIN_DELAY_ENEMY_REINFORCEMENTS enemy reinforcement will arrive minimum this number of turns after they are called, if 0 then is disabled. RND_DELAY_ENEMY_REINFORCEMENTS additional random delay added to minimum when reinforcements will arrive after they are called. MIN_ENTER_ENEMY_REINFORCEMENTS minimum enemy units which will enter after above delay is over. RND_ENTER_ENEMY_REINFORCEMENTS additional random enemy units to appear after passing delay. MIN_DELAY_MILITIA_REINFORCEMENTS enemy reinforcement will arrive minimum this number of turns after they are called, if 0 then is disabled. RND_DELAY_MILITIA_REINFORCEMENTS additional random delay added to minimum when reinforcements will arrive after they are called. MIN_ENTER_MILITIA_REINFORCEMENTS minimum enemy units which will enter after above delay is over. RND_ENTER_MILITIA_REINFORCEMENTS additional random enemy units to appear after passing delay. - After first delay ends any other reinforcement appeared more frequently or if already arrive (but no free slot), they will pop up soon after slot is free. - Add option NO_REMOVE_RANDOM_SECTOR_ITEMS under "Strategic Gameplay Settings" to prevent permanent random removal of your sector items. - Add missing function DisplaySectorItemsInfo. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6386 3b4a5df2-a311-0410-b5c6-a8a6f20db521
96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
#include "Random.h"
|
|
#include "debug control.h"
|
|
|
|
extern bool is_client;
|
|
extern bool is_server;
|
|
extern bool is_networked;
|
|
|
|
bool gfMPDebugOutputRandoms = false;
|
|
|
|
// OJW - 091024 - MP random syncing
|
|
// need to syncronise the randomness of events in a multiplayer game on all clients
|
|
UINT32 MPPreRandom( UINT32 uiRange )
|
|
{
|
|
UINT32 uiNum;
|
|
if( uiRange == 0 )
|
|
return 0;
|
|
//Extract the current pregenerated number
|
|
uiNum = guiPreRandomNums[ guiPreRandomIndex ] * uiRange / RAND_MAX % uiRange;
|
|
|
|
if (gfMPDebugOutputRandoms)
|
|
{
|
|
char tmpMPDbgString[512];
|
|
sprintf(tmpMPDbgString,"MPPreRandom ( uiRange : %i , uiPreRandomIndex : %i , uiResult : %i )\n",uiRange, guiPreRandomIndex , uiNum );
|
|
MPDebugMsg(tmpMPDbgString);
|
|
}
|
|
|
|
//Go to the next index.
|
|
guiPreRandomIndex++;
|
|
|
|
if (guiPreRandomIndex >= MAX_PREGENERATED_NUMS)
|
|
guiPreRandomIndex = 0;
|
|
|
|
return uiNum;
|
|
}
|
|
|
|
#ifdef BMP_RANDOM//dnl ch55 111009
|
|
|
|
#include <windows.h>
|
|
|
|
UINT32 guiPreRandomIndex;
|
|
UINT32 guiPreRandomNums[MAX_PREGENERATED_NUMS];
|
|
|
|
UINT32 GetRndNum(UINT32 maxnum)
|
|
{
|
|
if (is_networked && is_client)
|
|
return MPPreRandom(maxnum);
|
|
|
|
static UINT32 rnd=0, cnt=0;
|
|
POINT pt;
|
|
|
|
if(!(cnt++%RAND_MAX))
|
|
{
|
|
GetCursorPos(&pt);// Get cursor location
|
|
srand(maxnum ^ rnd ^ pt.x ^ pt.y ^ GetTickCount());
|
|
//SendFmtMsg("Random Number Generator Reinitialized.");
|
|
//for(int l=0;l<100;l++)SendFmtMsg("%2d", Random(100));
|
|
}
|
|
if(maxnum == 0)
|
|
return(0);
|
|
rnd = rand();
|
|
rnd <<= 11;
|
|
rnd ^= rand();
|
|
rnd <<= 7;
|
|
rnd ^= rand();
|
|
return(rnd % maxnum);
|
|
}
|
|
|
|
void InitializeRandom(void)
|
|
{
|
|
// Pregenerate all of the random numbers.
|
|
for(guiPreRandomIndex = 0; guiPreRandomIndex<MAX_PREGENERATED_NUMS; guiPreRandomIndex++)
|
|
guiPreRandomNums[guiPreRandomIndex] = GetRndNum(0xFFFFFFFF);
|
|
guiPreRandomIndex = 0;
|
|
}
|
|
|
|
#else
|
|
|
|
UINT32 guiPreRandomIndex = 0;
|
|
std::vector<UINT32> guiPreRandomNums(MAX_PREGENERATED_NUMS, 0);
|
|
|
|
void InitializeRandom()
|
|
{
|
|
// Seed the random-number generator with current time so that
|
|
// the numbers will be different every time we run.
|
|
srand( (unsigned) time(NULL) );
|
|
|
|
//Pregenerate all of the random numbers.
|
|
for( guiPreRandomIndex = 0; guiPreRandomIndex < MAX_PREGENERATED_NUMS; guiPreRandomIndex++ )
|
|
{
|
|
guiPreRandomNums[ guiPreRandomIndex ] = rand();
|
|
}
|
|
guiPreRandomIndex = 0;
|
|
}
|
|
|
|
#endif
|