Skip to content

Commit

Permalink
Server biomes random generator reseeds itself after every map wipe. A…
Browse files Browse the repository at this point in the history
… different map every time, with one of 4 billion possible seeds. Made server wait 8 seconds after signalling apocalypse, to give clients plenty of time to white-out.
  • Loading branch information
jasonrohrer committed Jul 27, 2019
1 parent 806232a commit 59e226a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
6 changes: 6 additions & 0 deletions documentation/changeLog.txt
Expand Up @@ -51,6 +51,12 @@ Server Fixes
most kinds of useful trees (at least ones that are sensibly hardwood, like
maple, poplar, and rubber).

--Server biomes random generator reseeds itself after every map wipe. A
different map every time, with one of 4 billion possible seeds.

--Made server wait 8 seconds after signalling apocalypse, to give clients
plenty of time to white-out.




Expand Down
3 changes: 2 additions & 1 deletion server/makeFileList
Expand Up @@ -95,4 +95,5 @@ NEEDED_MINOR_GEMS_OBJECTS = \
${PRINT_LOG_O} \
${PRINT_UTILS_O} \
${DOUBLE_PAIR_O} \
${STRING_TREE_O}
${STRING_TREE_O} \
${CRC32_O}
54 changes: 53 additions & 1 deletion server/map.cpp
Expand Up @@ -26,6 +26,8 @@
//#include "lineardb.h"
#include "lineardb3.h"

#include "minorGems/util/crc32.h"


/*
#define DB KISSDB
Expand Down Expand Up @@ -232,6 +234,8 @@ static int barrierOn = 1;
static int longTermCullEnabled = 1;


static unsigned int biomeRandSeed = 723;


static SimpleVector<int> barrierItemList;

Expand Down Expand Up @@ -830,7 +834,7 @@ static int computeMapBiomeIndex( int inX, int inY,
for( int i=0; i<numBiomes; i++ ) {
int biome = biomes[i];

setXYRandomSeed( biome * 263 + 723 );
setXYRandomSeed( biome * 263 + biomeRandSeed );

double randVal = getXYFractal( inX,
inY,
Expand Down Expand Up @@ -2553,9 +2557,57 @@ static void deleteFileByName( const char *inFileName ) {
}


void reseedMap( char inForceFresh ) {

FILE *seedFile = NULL;

if( ! inForceFresh ) {
seedFile = fopen( "biomeRandSeed.txt", "r" );
}

if( seedFile != NULL ) {
fscanf( seedFile, "%d", &biomeRandSeed );
fclose( seedFile );
AppLog::infoF( "Reading map rand seed from file: %u\n", biomeRandSeed );
}
else {
// no seed set, or ignoring it, make a new one

char *secret =
SettingsManager::getStringSetting( "statsServerSharedSecret",
"secret" );

unsigned int seedBase =
crc32( (unsigned char*)secret, strlen( secret ) );

unsigned int modTimeSeed =
(unsigned int)fmod( Time::getCurrentTime() + seedBase,
4294967295U );

JenkinsRandomSource tempRandSource( modTimeSeed );

biomeRandSeed = tempRandSource.getRandomInt();

AppLog::infoF( "Generating fresh map rand seed and saving to file: "
"%u\n", biomeRandSeed );

// and save it
seedFile = fopen( "biomeRandSeed.txt", "w" );
if( seedFile != NULL ) {

fprintf( seedFile, "%d", biomeRandSeed );
fclose( seedFile );
}
}
}




char initMap() {

reseedMap( false );


numSpeechPipes = getMaxSpeechPipeIndex() + 1;

Expand Down
4 changes: 4 additions & 0 deletions server/map.h
Expand Up @@ -40,6 +40,10 @@ char initMap();
void freeMap( char inSkipCleanup = false );


// loads seed from file, or generates a new one and saves it to file
void reseedMap( char inForceFresh );


// can only be called before initMap or after freeMap
// deletes the underlying .db files for the map
void wipeMapFiles();
Expand Down
4 changes: 3 additions & 1 deletion server/server.cpp
Expand Up @@ -8130,7 +8130,7 @@ void apocalypseStep() {
}

if( apocalypseRequest == NULL &&
Time::getCurrentTime() - apocalypseStartTime >= 7 ) {
Time::getCurrentTime() - apocalypseStartTime >= 8 ) {

if( ! postApocalypseStarted ) {
AppLog::infoF( "Enough warning time, %d players still alive",
Expand All @@ -8149,6 +8149,8 @@ void apocalypseStep() {
AppLog::infoF( "Apocalypse wipeMapFiles took %f sec",
Time::getCurrentTime() - startTime );

reseedMap( true );

initMap();

AppLog::infoF( "Apocalypse initMap took %f sec",
Expand Down

0 comments on commit 59e226a

Please sign in to comment.