Skip to content

Commit

Permalink
research items shuffle rides separately from scenery
Browse files Browse the repository at this point in the history
so you don't end up with 0 rides and all scenery
  • Loading branch information
Die4Ever committed Nov 16, 2023
1 parent 0f991d5 commit f104792
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ function randomize(value, difficulty) {
return ret;
}

function shuffle(items:Array<any>) {
for(let i=0; i<items.length; i++) {
let a = items[i];
let slot = rng(0, items.length - 1);
items[i] = items[slot];
items[slot] = a;
}
}

var crcTable = makeCRCTable();
function makeCRCTable(){
var c;
Expand Down
45 changes: 33 additions & 12 deletions src/modules/research.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@ class RCTRResearch extends ModuleBase {
setLocalSeed('ShuffleResearch');

const origNumResearched = park.research.inventedItems.length;
let numResearched = origNumResearched;

let rides = [];
let scenery = [];

// first just the inventedItems so we can count them and scale the amount
SplitResearchItems(park.research.inventedItems, rides, scenery);

// difficulty is -0.7 for Very Easy and 0.4 for Extreme
numResearched -= Math.round(settings.difficulty/2 * numResearched);
let researchItems = park.research.inventedItems.concat(park.research.uninventedItems);
for(let i=0; i<researchItems.length; i++) {
let a = researchItems[i];
let slot = rng(0, researchItems.length - 1);
researchItems[i] = researchItems[slot];
researchItems[slot] = a;
}
park.research.inventedItems = researchItems.slice(0, numResearched);
park.research.uninventedItems = researchItems.slice(numResearched);
let numRides = rides.length;
numRides = Math.round(settings.difficulty/2 * numRides);
let numScenery = scenery.length;
numScenery = Math.round(settings.difficulty/2 * numScenery);

// now add the uninventedItems and shuffle
SplitResearchItems(park.research.uninventedItems, rides, scenery);
shuffle(rides);
shuffle(scenery);

// write back new arrays
park.research.inventedItems = rides.slice(0, numRides).concat(scenery.slice(0, numScenery));
park.research.uninventedItems = rides.slice(numRides).concat(scenery.slice(numScenery));

this.AddChange('ShuffledResearch', 'Shuffled research items', null, null, null);
this.AddChange('NumInventedItems', 'Invented items', origNumResearched, numResearched);
this.AddChange('NumInventedItems', 'Invented items', origNumResearched, park.research.inventedItems.length);
}
}

function SplitResearchItems(items:Array<ResearchItem>, rides:Array<ResearchItem>, scenery:Array<ResearchItem>) {
for(let i=0; i < items.length; i++) {
let item = items[i];
if(item.type == 'ride') {
rides.push(item);
} else {
scenery.push(item);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rctrando_init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const rando_name = 'RollerCoaster Tycoon Randomizer';
const rando_version = '0.9.2';
const rando_version = '0.9.3 Alpha';

const bDebug:boolean = true;
function debug(message?: any, ...optionalParams: any[]): void {
Expand Down

0 comments on commit f104792

Please sign in to comment.