Skip to content

Commit

Permalink
Random start map selection can avoid repeating the same starting map
Browse files Browse the repository at this point in the history
over and over.  Make sure all the starting maps can actually be picked
  • Loading branch information
theastropath committed Aug 4, 2023
1 parent aae2c67 commit bb71377
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion DXRCore/DeusEx/Classes/DXRMenuSetupRando.uc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function BindControls(optional string action)
EnumOption("Area 51", 150, f.settings.starting_map);
if(EnumOption("Random", -1)) {
f.SetGlobalSeed("random starting map");
f.settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(f.dxr,True);
f.settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(f.dxr,0);
}

BreakLine();
Expand Down
10 changes: 5 additions & 5 deletions DXRModules/DeusEx/Classes/DXRFlags.uc
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ function FlagsSettings SetDifficulty(int new_difficulty)
bingo_scale = 0;

SetGlobalSeed("random starting map");
settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(dxr,False);
settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(dxr,10);
}
return settings;
}
Expand Down Expand Up @@ -938,7 +938,7 @@ function NewGamePlus()
local DXRAugmentations augs;
local int i, bingo_win,bingo_freespaces;
local float exp;
local bool randomStart;
local int randomStart;

if( flagsversion == 0 ) {
warning("NewGamePlus() flagsversion == 0");
Expand All @@ -956,7 +956,7 @@ function NewGamePlus()
bingoBoardRoll=0;
p.saveCount=0;
exp = 1;
randomStart = (settings.starting_map!=0);
randomStart = settings.starting_map;
bingo_win = settings.bingo_win;
bingo_freespaces = settings.bingo_freespaces;

Expand Down Expand Up @@ -989,8 +989,8 @@ function NewGamePlus()
NewGamePlusVal(settings.merchants, 0.9, exp);
settings.bingo_win = bingo_win;
settings.bingo_freespaces = bingo_freespaces;
if (randomStart){
settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(dxr,False);
if (randomStart!=0){
settings.starting_map = class'DXRStartMap'.static.ChooseRandomStartMap(dxr,randomStart);
}

if (p.KeyRing != None)
Expand Down
94 changes: 57 additions & 37 deletions DXRModules/DeusEx/Classes/DXRStartMap.uc
Original file line number Diff line number Diff line change
Expand Up @@ -343,47 +343,67 @@ static function bool BingoGoalImpossible(string bingo_event, int start_map)
return False;
}

static function int ChooseRandomStartMap(DXRando dxr, bool skipVanilla)
static function int ChooseRandomStartMap(DXRando dxr, int avoidStart)
{
local int i;
local int max;

max=8;
if (skipVanilla){
max-=1;
}

i = staticrng(dxr,max);

if (skipVanilla){
i++;
local int startMap;
local int attempts;

startMap=-1;
attempts=0;

//Don't try forever. If we manage to grab the avoided map 5 times, it was meant to be.
while ((startMap==-1 || startMap==avoidStart) && attempts<5){
i = staticrng(dxr,12);

//Should be able to legitimately return Liberty Island (even if that's as a value of 10), but needs additional special handling
switch(i)
{
case 0:
startMap = 10;
break;
case 1:
startMap = 20;
break;
case 2:
startMap = 30;
break;
case 3:
startMap = 40;
break;
case 4:
startMap = 50;
break;
case 5:
startMap = 61;
break;
case 6:
startMap = 81;
break;
case 7:
startMap = 90;
break;
case 8:
startMap = 99;
break;
case 9:
startMap = 119;
break;
case 10:
startMap = 140;
break;
case 11:
startMap = 150;
break;
default:
dxr.err("Random Starting Map picked value "$i$" which is unhandled!");
startMap = 0; //Fall back on Liberty Island
break;
}
log("Start map selection attempt "$attempts$" was "$startMap);
}

//Should be able to legitimately return Liberty Island (even if that's as a value of 10), but needs additional special handling
switch(i)
{
case 0:
return 10;
case 1:
return 40;
case 2:
return 50;
case 3:
return 61;
case 4:
return 81;
case 5:
return 99;
case 6:
return 119;
case 7:
return 140;
case 8:
return 150;
default:
dxr.err("Random Starting Map picked value "$i$" which is unhandled!");
return 0; //Fall back on Liberty Island
}
return startMap;
}

static function AddStartingCredits(DXRando dxr, #var(PlayerPawn) p)
Expand Down

0 comments on commit bb71377

Please sign in to comment.