From 5c15a0e9f435e7cce98ab798eb59fa9667958ed3 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 30 Oct 2012 17:12:04 +0000 Subject: [PATCH] - cast to unsigned int for all calls to srand --- source/glest_game/ai/ai.cpp | 2 +- source/glest_game/main/intro.cpp | 12 ++++++------ source/glest_game/menu/menu_state_custom_game.cpp | 6 ++---- source/glest_game/menu/menu_state_masterserver.cpp | 3 +-- source/glest_game/network/connection_slot.cpp | 3 +-- source/glest_game/types/skill_type.cpp | 6 ++---- .../sources/platform/common/platform_common.cpp | 2 +- source/shared_lib/sources/util/properties.cpp | 1 - 8 files changed, 14 insertions(+), 21 deletions(-) diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index 893fb8428..2a85b94bd 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -346,7 +346,7 @@ void Ai::update() { //int allowJoinTeam = random.randRange(0, 100); //srand(time(NULL) + aiInterface->getMyFaction()->getIndex()); Chrono seed(true); - srand(seed.getCurTicks() + aiInterface->getMyFaction()->getIndex()); + srand((unsigned int)seed.getCurTicks() + aiInterface->getMyFaction()->getIndex()); int allowJoinTeam = rand() % 100; diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index fee76da6a..e64ff77bb 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -236,20 +236,20 @@ Intro::Intro(Program *program): //unsigned int seed = time(NULL); Chrono seed(true); - srand(seed.getCurTicks()); + srand((unsigned int)seed.getCurTicks()); int failedLookups=0; std::map usedIndex; for(;modelList.size() < models.size();) { int index = rand() % models.size(); if(usedIndex.find(index) != usedIndex.end()) { failedLookups++; - srand(seed.getCurTicks() / failedLookups); + srand((unsigned int)seed.getCurTicks() / failedLookups); continue; } //printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size()); modelList.push_back(models[index]); usedIndex[index]=true; - srand(seed.getCurTicks() / modelList.size()); + srand((unsigned int)seed.getCurTicks() / modelList.size()); } models = modelList; } @@ -426,14 +426,14 @@ Intro::Intro(Program *program): if(showIntroPicsRandom == true) { //unsigned int seed = time(NULL); Chrono seed(true); - srand(seed.getCurTicks()); + srand((unsigned int)seed.getCurTicks()); int failedLookups=0; std::map usedIndex; for(;intoTexList.size() < showIntroPics;) { int picIndex = rand() % coreData.getMiscTextureList().size(); if(usedIndex.find(picIndex) != usedIndex.end()) { failedLookups++; - srand(seed.getCurTicks() / failedLookups); + srand((unsigned int)seed.getCurTicks() / failedLookups); if(failedLookups > 10000) { for(unsigned int i = 0; @@ -451,7 +451,7 @@ Intro::Intro(Program *program): //printf("picIndex = %d list count = %d\n",picIndex,coreData.getMiscTextureList().size()); intoTexList.push_back(coreData.getMiscTextureList()[picIndex]); usedIndex[picIndex]=true; - srand(seed.getCurTicks() / intoTexList.size()); + srand((unsigned int)seed.getCurTicks() / intoTexList.size()); } } else { diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 31bc9598f..bdb460a8f 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -253,9 +253,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, listBoxTileset.init(xoffset+460, mapPos, 150); //listBoxTileset.setItems(results); setupTilesetList(""); - //srand((unsigned int)time(NULL)); Chrono seed(true); - srand(seed.getCurTicks()); + srand((unsigned int)seed.getCurTicks()); listBoxTileset.setSelectedItemIndex(rand() % listBoxTileset.getItemCount()); @@ -1568,9 +1567,8 @@ 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); Chrono seed(true); - srand(seed.getCurTicks() + findRandomFaction); + srand((unsigned int)seed.getCurTicks() + findRandomFaction); int selectedFactionIndex = rand() % listBoxFactions[i].getItemCount(); string selectedFactionName = listBoxFactions[i].getItem(selectedFactionIndex); diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 21271b27e..cee5e19bb 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -250,9 +250,8 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen GraphicComponent::applyAllCustomProperties(containerName); char szIRCNick[80]=""; - //srand(time(NULL)); Chrono seed(true); - srand(seed.getCurTicks()); + srand((unsigned int)seed.getCurTicks()); int randomNickId = rand() % 999; string netPlayerName=Config::getInstance().getString("NetPlayerName",Socket::getHostName().c_str()); diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index 839f3d407..8b2a8c886 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -453,9 +453,8 @@ 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)); Chrono seed(true); - srand(seed.getCurTicks() / (this->playerIndex + 1)); + srand((unsigned int)seed.getCurTicks() / (this->playerIndex + 1)); sessionKey = rand() % 1000000; diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 06bfbfa51..0d99baf40 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -536,9 +536,8 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit, if(foundSpecificAnimation == false) { //int modelIndex = random.randRange(0,animations.size()-1); - //srand(time(NULL) + unit->getId()); Chrono seed(true); - srand(seed.getCurTicks() + unit->getId()); + srand((unsigned int)seed.getCurTicks() + unit->getId()); modelIndex = rand() % animations.size(); @@ -546,9 +545,8 @@ Model *SkillType::getAnimation(float animProgress, const Unit *unit, //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()); Chrono seed(true); - srand(seed.getCurTicks() + unit->getId()); + srand((unsigned int)seed.getCurTicks() + unit->getId()); int filteredModelIndex = rand() % filteredAnimations.size(); modelIndex = filteredAnimations[filteredModelIndex]; diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 6d115fcfa..788b8fb5c 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -734,7 +734,7 @@ void writeCachedFileCRCValue(string crcCacheFile, uint32 &crcValue) { if(fp != NULL) { //RandomGen random; //int offset = random.randRange(5, 15); - srand((unsigned long)time(NULL) + (unsigned long)crcCacheFile.length()); + srand((unsigned int)time(NULL) + (unsigned long)crcCacheFile.length()); int offset = rand() % 15; if(offset == 0) { offset = 3; diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 83db3157a..a7fd10006 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -440,7 +440,6 @@ 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((unsigned int)seed.getCurTicks());