mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 21:33:59 +02:00
- updated random seed generation to be more random
This commit is contained in:
@@ -341,7 +341,10 @@ void Ai::update() {
|
||||
int factionSwitchTeamRequestCountCurrent = factionSwitchTeamRequestCount[vote->factionIndex];
|
||||
|
||||
//int allowJoinTeam = random.randRange(0, 100);
|
||||
srand(time(NULL) + aiInterface->getMyFaction()->getIndex());
|
||||
//srand(time(NULL) + aiInterface->getMyFaction()->getIndex());
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks() + aiInterface->getMyFaction()->getIndex());
|
||||
|
||||
int allowJoinTeam = rand() % 100;
|
||||
|
||||
SwitchTeamVote *voteResult = aiInterface->getMyFaction()->getSwitchTeamVote(vote->factionIndex);
|
||||
|
@@ -234,8 +234,9 @@ Intro::Intro(Program *program):
|
||||
if(showIntroModelsRandom == true) {
|
||||
std::vector<Model *> modelList;
|
||||
|
||||
unsigned int seed = time(NULL);
|
||||
srand(seed);
|
||||
//unsigned int seed = time(NULL);
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks());
|
||||
int failedLookups=0;
|
||||
std::map<int,bool> usedIndex;
|
||||
for(;modelList.size() < models.size();) {
|
||||
@@ -243,14 +244,13 @@ Intro::Intro(Program *program):
|
||||
if(usedIndex.find(index) != usedIndex.end()) {
|
||||
failedLookups++;
|
||||
seed = time(NULL) / failedLookups;
|
||||
srand(seed);
|
||||
srand(seed.getCurTicks());
|
||||
continue;
|
||||
}
|
||||
//printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size());
|
||||
modelList.push_back(models[index]);
|
||||
usedIndex[index]=true;
|
||||
seed = time(NULL) / modelList.size();
|
||||
srand(seed);
|
||||
srand(seed.getCurTicks() / modelList.size());
|
||||
}
|
||||
models = modelList;
|
||||
}
|
||||
@@ -425,23 +425,22 @@ Intro::Intro(Program *program):
|
||||
|
||||
std::vector<Texture2D *> intoTexList;
|
||||
if(showIntroPicsRandom == true) {
|
||||
unsigned int seed = time(NULL);
|
||||
srand(seed);
|
||||
//unsigned int seed = time(NULL);
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks());
|
||||
int failedLookups=0;
|
||||
std::map<int,bool> usedIndex;
|
||||
for(;intoTexList.size() < showIntroPics;) {
|
||||
int picIndex = rand() % coreData.getMiscTextureList().size();
|
||||
if(usedIndex.find(picIndex) != usedIndex.end()) {
|
||||
failedLookups++;
|
||||
seed = time(NULL) / failedLookups;
|
||||
srand(seed);
|
||||
srand(seed.getCurTicks() / failedLookups);
|
||||
continue;
|
||||
}
|
||||
//printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size());
|
||||
intoTexList.push_back(coreData.getMiscTextureList()[picIndex]);
|
||||
usedIndex[picIndex]=true;
|
||||
seed = time(NULL) / intoTexList.size();
|
||||
srand(seed);
|
||||
srand(seed.getCurTicks() / intoTexList.size());
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@@ -253,7 +253,10 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu,
|
||||
listBoxTileset.init(xoffset+460, mapPos, 150);
|
||||
//listBoxTileset.setItems(results);
|
||||
setupTilesetList("");
|
||||
srand((unsigned int)time(NULL));
|
||||
//srand((unsigned int)time(NULL));
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks());
|
||||
|
||||
listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount());
|
||||
|
||||
//tech Tree listBox
|
||||
@@ -1556,7 +1559,10 @@ void MenuStateCustomGame::PlayNow(bool saveGame) {
|
||||
|
||||
// Max 1000 tries to get a random, unused faction
|
||||
for(int findRandomFaction = 1; findRandomFaction < 1000; ++findRandomFaction) {
|
||||
srand((unsigned int)time(NULL) + findRandomFaction);
|
||||
//srand((unsigned int)time(NULL) + findRandomFaction);
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks() + findRandomFaction);
|
||||
|
||||
int selectedFactionIndex = rand() % listBoxFactions[i].getItemCount();
|
||||
string selectedFactionName = listBoxFactions[i].getItem(selectedFactionIndex);
|
||||
|
||||
|
@@ -250,7 +250,10 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen
|
||||
GraphicComponent::applyAllCustomProperties(containerName);
|
||||
|
||||
char szIRCNick[80]="";
|
||||
srand(time(NULL));
|
||||
//srand(time(NULL));
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks());
|
||||
|
||||
int randomNickId = rand() % 999;
|
||||
string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str());
|
||||
string ircname=netPlayerName.substr(0,9);
|
||||
|
@@ -453,7 +453,10 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||
if(this->isConnected() == true) {
|
||||
//RandomGen random;
|
||||
//sessionKey = random.randRange(-100000, 100000);
|
||||
srand((unsigned int)time(NULL) / (this->playerIndex + 1));
|
||||
//srand((unsigned int)time(NULL) / (this->playerIndex + 1));
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks() / (this->playerIndex + 1));
|
||||
|
||||
sessionKey = rand() % 1000000;
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] accepted new client connection, serverInterface->getOpenSlotCount() = %d, sessionKey = %d\n",__FILE__,__FUNCTION__,__LINE__,serverInterface->getOpenSlotCount(),sessionKey);
|
||||
|
@@ -536,14 +536,20 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit,
|
||||
|
||||
if(foundSpecificAnimation == false) {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL) + unit->getId());
|
||||
//srand(time(NULL) + unit->getId());
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks() + unit->getId());
|
||||
|
||||
modelIndex = rand() % animations.size();
|
||||
|
||||
//const AnimationAttributes &attributes = animationAttributes[modelIndex];
|
||||
//printf("SELECTING RANDOM Model index = %d [%s] model attributes [%d to %d] for unit [%s - %d] with HP = %d\n",modelIndex,animations[modelIndex]->getFileName().c_str(),attributes.fromHp,attributes.toHp,unit->getType()->getName().c_str(),unit->getId(),unit->getHp());
|
||||
}
|
||||
else {
|
||||
srand(time(NULL) + unit->getId());
|
||||
//srand(time(NULL) + unit->getId());
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks() + unit->getId());
|
||||
|
||||
int filteredModelIndex = rand() % filteredAnimations.size();
|
||||
modelIndex = filteredAnimations[filteredModelIndex];
|
||||
}
|
||||
|
@@ -425,6 +425,10 @@ const string Properties::getRandomKey(const bool realrandom) const{
|
||||
int max=getPropertyCount();
|
||||
int randomIndex=-1;
|
||||
if(realrandom == true){
|
||||
//srand((unsigned int)time(NULL));
|
||||
Chrono seed(true);
|
||||
srand(seed.getCurTicks());
|
||||
|
||||
randomIndex=rand()%max;
|
||||
}
|
||||
else{
|
||||
|
Reference in New Issue
Block a user