Skip to content
Permalink
Browse files

New custom seed system

This allows the player to set a custom seed which will randomize non-hardcoded solar system planets, textures, minerals, etc
  • Loading branch information...
Serosis committed Aug 30, 2018
1 parent 8b56837 commit ca9fa7af931ce48eb0783bda4f3cdf2b625adaf0
BIN +0 Bytes (100%) bin/UrQuanMasters.exe
Binary file not shown.
BIN +2 KB (100%) bin/UrQuanMastersDebug.exe
Binary file not shown.
@@ -25,12 +25,12 @@
#include "random.h"

#include "libs/memlib.h"
#include "../options.h"


#define A 16807 /* a relatively prime number -- also M div Q */
#define M 2147483647 /* 0xFFFFFFFF / 2 */
#define Q 127773 /* M div A */
#define R 2836 /* M mod A */
#define A (savedSeed != NULL ? savedSeed : optCustomSeed) // Serosis - Default: 16807 - a relatively prime number - also M div Q
#define M 2147483647 // 0xFFFFFFFF div 2
#define Q (M / A) // Serosis - Default: 127773L - M div A
#define R (M % A) // Serosis - Default: 2836 - M mod A

RandomContext *
RandomContext_New (void)
@@ -89,6 +89,8 @@ BOOLEAN optScalePlanets;
BOOLEAN optSuperMelee;
BOOLEAN optLoadGame;
BOOLEAN optCustomBorder;
int optCustomSeed;
int savedSeed;

BOOLEAN opt3doMusic;
BOOLEAN optRemixMusic;
@@ -79,6 +79,8 @@ extern BOOLEAN optScalePlanets;
extern BOOLEAN optSuperMelee;
extern BOOLEAN optLoadGame;
extern BOOLEAN optCustomBorder;
extern int optCustomSeed;
extern int savedSeed;

extern BOOLEAN opt3doMusic;
extern BOOLEAN optRemixMusic;
@@ -158,6 +158,7 @@ struct options_struct
DECL_CONFIG_OPTION(bool, addDevices);
DECL_CONFIG_OPTION(bool, scalePlanets);
DECL_CONFIG_OPTION(bool, customBorder);
DECL_CONFIG_OPTION(int, customSeed);

#define INIT_CONFIG_OPTION(name, val) \
{ val, false }
@@ -311,13 +312,15 @@ main (int argc, char *argv[])
INIT_CONFIG_OPTION( texturedPlanets, false),
// Nic
INIT_CONFIG_OPTION( optDateFormat, 0),
//Serosis
INIT_CONFIG_OPTION( infiniteFuel, false),
INIT_CONFIG_OPTION( thraddStory, false),
INIT_CONFIG_OPTION( partialPickup, false),
INIT_CONFIG_OPTION( submenu, true),
INIT_CONFIG_OPTION( addDevices, false),
INIT_CONFIG_OPTION( scalePlanets, true),
INIT_CONFIG_OPTION( customBorder, true),
INIT_CONFIG_OPTION( customSeed, 16807),
};
struct options_struct defaults = options;
int optionsResult;
@@ -481,6 +484,7 @@ main (int argc, char *argv[])
optAddDevices = options.addDevices.value;
optScalePlanets = options.scalePlanets.value;
optCustomBorder = options.customBorder.value;
optCustomSeed = options.customSeed.value;
optRequiresReload = FALSE; // Serosis
optRequiresRestart = FALSE; // JMS_GFX

@@ -810,6 +814,9 @@ getUserConfigOptions (struct options_struct *options)
getBoolConfigValue (&options->addDevices, "cheat.addDevices");
getBoolConfigValue (&options->scalePlanets, "config.scalePlanets");
getBoolConfigValue (&options->customBorder, "config.customBorder");
if (res_IsInteger ("config.customSeed") && !options->customSeed.set) {
options->customSeed.value = res_GetInteger ("config.customSeed");
}

if (res_IsInteger ("config.player1control"))
{
@@ -869,9 +876,10 @@ enum
SUBMENU_OPT,
DEVICES_OPT,
SCALEPLAN_OPT,
CUSTBORD_OPT,
EXSEED_OPT,
MELEE_OPT,
LOADGAME_OPT,
CUSTBORD_OPT,
#ifdef NETPLAY
NETHOST1_OPT,
NETPORT1_OPT,
@@ -932,16 +940,17 @@ static struct option longOptions[] =
{"nebulae", 0, NULL, NEBU_OPT},
{"orbitingplanets", 0, NULL, ORBITS_OPT},
{"texturedplanets", 0, NULL, TEXTPLAN_OPT},
{"dateformat", 0, NULL, DATE_OPT},
{"dateformat", 1, NULL, DATE_OPT},
{"infinitefuel", 0, NULL, INFFUEL_OPT},
{"thraddstory", 0, NULL, THRADD_OPT},
{"partialpickup", 0, NULL, PICKUP_OPT},
{"submenu", 0, NULL, SUBMENU_OPT},
{"adddevices", 0, NULL, DEVICES_OPT},
{"scaledevices", 0, NULL, SCALEPLAN_OPT},
{"customborder", 0, NULL, CUSTBORD_OPT},
{"customseed", 1, NULL, EXSEED_OPT},
{"melee", 0, NULL, MELEE_OPT},
{"loadgame", 0, NULL, LOADGAME_OPT},
{"customborder", 0, NULL, CUSTBORD_OPT},
#ifdef NETPLAY
{"nethost1", 1, NULL, NETHOST1_OPT},
{"netport1", 1, NULL, NETPORT1_OPT},
@@ -1280,15 +1289,29 @@ parseOptions (int argc, char *argv[], struct options_struct *options)
case SCALEPLAN_OPT:
setBoolOption (&options->scalePlanets, true);
break;
case CUSTBORD_OPT:
optCustomBorder = TRUE;
break;
case EXSEED_OPT:{
int temp;
if (parseIntOption (optarg, &temp, "Custom Seed") == -1) {
badArg = true;
break;
} else if (temp <= 1 || temp >= 2147483646) {
saveError ("\nCustom Seed can not be 1, less than 1, 2147483646, or greater than 2147483646.\n");
badArg = true;
} else {
options->customSeed.value = temp;
options->customSeed.set = true;
}
break;
}
case MELEE_OPT:
optSuperMelee = TRUE;
break;
case LOADGAME_OPT:
optLoadGame = TRUE;
break;
case CUSTBORD_OPT:
optCustomBorder = TRUE;
break;
case ADDON_OPT:
options->numAddons++;
options->addons = HRealloc ((void *) options->addons,
@@ -512,6 +512,7 @@ LoadStarDesc (STAR_DESC *SDPtr, void *fh)
read_8 (fh, &SDPtr->Index);
read_8 (fh, &SDPtr->Prefix);
read_8 (fh, &SDPtr->Postfix);
read_32s (fh, &savedSeed);
}

static void
@@ -1117,6 +1117,7 @@ SaveStarDesc (const STAR_DESC *SDPtr, uio_Stream *fh)
write_8 (fh, SDPtr->Index);
write_8 (fh, SDPtr->Prefix);
write_8 (fh, SDPtr->Postfix);
write_32 (fh, (savedSeed != NULL ? savedSeed : optCustomSeed));
}

static void
@@ -1445,6 +1445,7 @@ GetGlobalOptions (GLOBALOPTS *opts)
opts->addDevices = optAddDevices ? OPTVAL_ENABLED : OPTVAL_DISABLED;
opts->scalePlanets = optScalePlanets ? OPTVAL_ENABLED : OPTVAL_DISABLED;
opts->customBorder = optCustomBorder ? OPTVAL_ENABLED : OPTVAL_DISABLED;
opts->customSeed = res_GetInteger ("config.customSeed");
opts->loresBlowup = res_GetInteger ("config.loresBlowupScale");

// JMS_GFX: 1280x960
@@ -1510,7 +1511,8 @@ SetGlobalOptions (GLOBALOPTS *opts)
int NewGfxFlags = GfxFlags;
int NewWidth = ScreenWidthActual;
int NewHeight = ScreenHeightActual;
int NewDriver = GraphicsDriver;
int NewDriver = GraphicsDriver;
int SeedStuff;

unsigned int oldResFactor = resolutionFactor; // JMS_GFX

@@ -1785,6 +1787,13 @@ SetGlobalOptions (GLOBALOPTS *opts)
// Serosis: Show custom border
res_PutBoolean ("config.customBorder", opts->customBorder == OPTVAL_ENABLED);
optCustomBorder = opts->customBorder == OPTVAL_ENABLED;

// Serosis: Externalized Seed Generation
SeedStuff = res_GetInteger ("config.customSeed");
if(SeedStuff == NULL || SeedStuff <= 0 || SeedStuff >= 2147483647){
opts->customSeed = 16807;
res_PutInteger ("config.customSeed", opts->customSeed);
}

if (opts->scanlines && RESOLUTION_FACTOR == 0) {
NewGfxFlags |= TFB_GFXFLAGS_SCANLINES;
@@ -98,15 +98,15 @@ typedef struct globalopts_struct {
OPT_ADRIVERTYPE adriver;
OPT_AQUALITYTYPE aquality;
OPT_TDTYPE tdType; // Serosis
OPT_DATETYPE dateType; //
OPT_DATETYPE dateType; // Serosis
OPT_ENABLABLE fullscreen, subtitles, scanlines, fps, stereo, music3do, musicremix, speech, keepaspect,
cheatMode, godMode, bubbleWarp, unlockShips, headStart, unlockUpgrades, infiniteRU, skipIntro, // Serosis: except for cheatMode = JMS
mainMenuMusic, nebulae, orbitingPlanets, texturedPlanets, // JMS
infiniteFuel, thraddStory, partialPickup, submenu, addDevices, scalePlanets, customBorder; // Serosis
OPT_CONSOLETYPE menu, text, cscan, scroll, intro, meleezoom, shield;
CONTROL_TEMPLATE player1, player2;
int speechvol, musicvol, sfxvol;
int gamma;
int gamma, customSeed;
} GLOBALOPTS;

void SetupMenu (void);

0 comments on commit ca9fa7a

Please sign in to comment.
You can’t perform that action at this time.