Super Metroid: Replace random module with world random in variaRandomizer (#4429)

This commit is contained in:
Mysteryem
2025-04-01 17:14:47 +01:00
committed by GitHub
parent 5a6b02dbd3
commit ca08e4b950
16 changed files with 154 additions and 142 deletions

View File

@@ -1,4 +1,3 @@
import random
from enum import IntEnum,IntFlag
import copy
from ..logic.smbool import SMBool
@@ -123,7 +122,7 @@ class Door(object):
else:
return [color for color in colorsList if color not in self.forbiddenColors]
def randomize(self, allowGreyDoors):
def randomize(self, allowGreyDoors, random):
if self.canRandomize():
if self.canGrey and allowGreyDoors:
self.setColor(random.choice(self.filterColorList(colorsListGrey)))
@@ -347,9 +346,9 @@ class DoorsManager():
currentDoors['CrabShaftRight'].forceBlue()
@staticmethod
def randomize(allowGreyDoors, player):
def randomize(allowGreyDoors, player, random):
for door in DoorsManager.doorsDict[player].values():
door.randomize(allowGreyDoors)
door.randomize(allowGreyDoors, random)
# set both ends of toilet to the same color to avoid soft locking in area rando
toiletTop = DoorsManager.doorsDict[player]['PlasmaSparkBottom']
toiletBottom = DoorsManager.doorsDict[player]['OasisTop']

View File

@@ -1,5 +1,4 @@
import copy
import random
from ..rom.addresses import Addresses
from ..rom.rom import pc_to_snes
from ..logic.helpers import Bosses
@@ -28,7 +27,7 @@ class Synonyms(object):
]
alreadyUsed = []
@staticmethod
def getVerb():
def getVerb(random):
verb = random.choice(Synonyms.killSynonyms)
while verb in Synonyms.alreadyUsed:
verb = random.choice(Synonyms.killSynonyms)
@@ -88,10 +87,10 @@ class Goal(object):
# not all objectives require an ap (like limit objectives)
return self.clearFunc(smbm, ap)
def getText(self):
def getText(self, random):
out = "{}. ".format(self.rank)
if self.useSynonym:
out += self.text.format(Synonyms.getVerb())
out += self.text.format(Synonyms.getVerb(random))
else:
out += self.text
assert len(out) <= 28, "Goal text '{}' is too long: {}, max 28".format(out, len(out))
@@ -676,7 +675,7 @@ class Objectives(object):
return [goal.name for goal in _goals.values() if goal.available and (not removeNothing or goal.name != "nothing")]
# call from rando
def setRandom(self, nbGoals, availableGoals):
def setRandom(self, nbGoals, availableGoals, random):
while self.nbActiveGoals < nbGoals and availableGoals:
goalName = random.choice(availableGoals)
self.addGoal(goalName)
@@ -702,7 +701,7 @@ class Objectives(object):
LOG.debug("tourianRequired: {}".format(self.tourianRequired))
# call from rando
def writeGoals(self, romFile):
def writeGoals(self, romFile, random):
# write check functions
romFile.seek(Addresses.getOne('objectivesList'))
for goal in self.activeGoals:
@@ -736,7 +735,7 @@ class Objectives(object):
space = 3 if self.nbActiveGoals == 5 else 4
for i, goal in enumerate(self.activeGoals):
addr = baseAddr + i * lineLength * space
text = goal.getText()
text = goal.getText(random)
romFile.seek(addr)
for c in text:
if c not in char2tile:

View File

@@ -1,5 +1,5 @@
import io
import os, json, re, random
import os, json, re
import pathlib
import sys
from typing import Any
@@ -88,7 +88,7 @@ def normalizeRounding(n):
# gauss random in [0, r] range
# the higher the slope, the less probable extreme values are.
def randGaussBounds(r, slope=5):
def randGaussBounds(random, r, slope=5):
r = float(r)
n = normalizeRounding(random.gauss(r/2, r/slope))
if n < 0:
@@ -111,7 +111,7 @@ def getRangeDict(weightDict):
return rangeDict
def chooseFromRange(rangeDict):
def chooseFromRange(rangeDict, random):
r = random.random()
val = None
for v in sorted(rangeDict, key=rangeDict.get):