From 6e04dbb1ebb811429bbfdb53bd8c4c079ef63732 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 4 Feb 2024 11:30:04 -0500 Subject: Randomize layout of The Steady --- randomizer/doorControl.gd | 18 ++++++++++ randomizer/load.gd | 8 +++++ randomizer/randomizer.gd | 8 +++++ randomizer/settings_screen.gd | 2 ++ randomizer/steady.gd | 78 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 randomizer/doorControl.gd create mode 100644 randomizer/steady.gd diff --git a/randomizer/doorControl.gd b/randomizer/doorControl.gd new file mode 100644 index 0000000..3f70026 --- /dev/null +++ b/randomizer/doorControl.gd @@ -0,0 +1,18 @@ +extends "res://scripts/doorControl.gd" + + +func remap(new_panels): + for panel in panels: + get_node(panel).get_node("Viewport/GUI/Panel/TextEdit").disconnect("answer_correct", self, "handle_correct") + get_node(panel).get_node("Viewport/GUI/Panel/TextEdit").disconnect("answer_unsolved", self, "handle_unsolve") + + panels = new_panels.duplicate() + + if complete_at > 0: + total = complete_at + else: + total = panels.size() + + for panel in panels: + get_node(panel).get_node("Viewport/GUI/Panel/TextEdit").connect("answer_correct", self, "handle_correct") + get_node(panel).get_node("Viewport/GUI/Panel/TextEdit").connect("answer_unsolved", self, "handle_unsolve") diff --git a/randomizer/load.gd b/randomizer/load.gd index aad221f..55e4efc 100644 --- a/randomizer/load.gd +++ b/randomizer/load.gd @@ -206,6 +206,14 @@ func _load(): $CountdownPanels.add_child(pilgrim_cdp) pilgrim_real.translation.y = -33 + # Remap The Steady's doors. + for door in randomizer.steady._door_mapping.keys(): + get_node("Doors/Rock Room Doors").get_node(door).remap(["../../../Panels/Rock Room/%s" % randomizer.steady._door_mapping[door]]) + + for door in get_node("Doors/Rock Room Doors").get_children(): + if !randomizer.steady._door_mapping.has(door.name) and door.name != "Door_hint": + door.remap(["../../../Panels/Countdown Panels/Panel_steady_steady"]) + # Proceed with the rest of the load. global._print("Hooked Load End") ._load() diff --git a/randomizer/randomizer.gd b/randomizer/randomizer.gd index 0738cb6..681567d 100644 --- a/randomizer/randomizer.gd +++ b/randomizer/randomizer.gd @@ -3,8 +3,10 @@ extends Node const my_version = "0.1.0" var SCRIPT_generator +var SCRIPT_steady var generator +var steady var thread = Thread.new() signal finished_randomizing @@ -21,6 +23,12 @@ func _thread_func(gen_seed): generator.connect("generator_status", self, "statusUpdate") generator.generate(gen_seed) + var rng = RandomNumberGenerator.new() + rng.seed = generator.gen_seed + + steady = SCRIPT_steady.new() + steady.generate(rng) + emit_signal("finished_randomizing") diff --git a/randomizer/settings_screen.gd b/randomizer/settings_screen.gd index 842b046..9b3ddeb 100644 --- a/randomizer/settings_screen.gd +++ b/randomizer/settings_screen.gd @@ -14,6 +14,7 @@ func _ready(): global.add_child(randomizer_instance) randomizer_instance.SCRIPT_generator = load("user://maps/randomizer/generator.gd") + randomizer_instance.SCRIPT_steady = load("user://maps/randomizer/steady.gd") var generated_puzzles = ResourceLoader.load("user://maps/randomizer/generated_puzzles.gd") var generated_puzzles_instance = generated_puzzles.new() @@ -26,6 +27,7 @@ func _ready(): randomizer_instance.add_child(extradata_instance) # Let's also inject any scripts we need to inject now. + installScriptExtension(ResourceLoader.load("user://maps/randomizer/doorControl.gd")) installScriptExtension(ResourceLoader.load("user://maps/randomizer/load.gd")) installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelEnd.gd")) installScriptExtension(ResourceLoader.load("user://maps/randomizer/panelInput.gd")) diff --git a/randomizer/steady.gd b/randomizer/steady.gd new file mode 100644 index 0000000..3153e79 --- /dev/null +++ b/randomizer/steady.gd @@ -0,0 +1,78 @@ +extends Node + +const layout = { + "outside": ["Panel_begin_begin",[["Door_3", "carnation"], ["Door_2", "rose"], ["Door_1", "lilac"]]], + "lilac":["Panel_lielack_lilac",[["Door_1","outside"],["Door_5","amethyst"],["Door_vert_1","rose"]]], + "rose":["Panel_soar_rose",[["Door_vert_1","lilac"],["Door_6","ruby"],["Door_vert_2","carnation"],["Door_2","outside"]]], + "carnation":["Panel_incarnation_carnation",[["Door_vert_2","rose"],["Door_7","amber"],["Door_vert_3","sunflower"],["Door_3","outside"]]], + "sunflower":["Panel_sun_sunflower",[["Door_8","topaz"],["Door_vert_3","carnation"],["Door_4","achievement"],["","lime"]]], + "emerald":["Panel_herald_emerald",[["Door_9","lime"],["Door_vert_4","sapphire"],["","lemon"]]], + "sapphire":["Panel_sap_sapphire",[["Door_vert_4","emerald"],["Door_10","blueberry"],["Door_vert_5","amethyst"]]], + "amethyst":["Panel_thistle_amethyst",[["Door_vert_5","sapphire"],["Door_11","plum"],["Door_vert_6","ruby"],["Door_5","lilac"]]], + "ruby":["Panel_bury_ruby",[["Door_vert_6","amethyst"],["Door_12","cherry"],["Door_vert_7","amber"],["Door_6","rose"]]], + "amber":["Panel_antechamber_amber",[["Door_vert_7","ruby"],["Door_13","orange"],["Door_vert_8","topaz"],["Door_7","carnation"]]], + "topaz":["Panel_top_topaz",[["Door_vert_8","amber"],["Door_14","lemon"],["Door_8","sunflower"]]], + "lime":["Panel_limelight_lime",[["Door_vert_9","blueberry"],["Door_9","emerald"]]], + "blueberry":["Panel_blue_blueberry",[["Door_vert_9","lime"],["Door_10","sapphire"],["Door_vert_10","plum"]]], + "plum":["Panel_lump_plum",[["Door_vert_10","blueberry"],["Door_11","amethyst"],["Door_vert_11","cherry"]]], + "cherry":["Panel_hairy_cherry",[["Door_vert_11","plum"],["Door_12","ruby"],["Door_vert_12","orange"]]], + "orange":["Panel_blue_orange",[["Door_vert_12","cherry"],["Door_13","amber"],["Door_vert_13","lemon"]]], + "lemon":["Panel_melon_lemon",[["Door_vert_13","orange"],["Door_14","topaz"]]], +} + +var _visited +var _door_mapping +var _flood_boundary +var _panel_boundary + + +func generate(rng): + _visited = [] + _door_mapping = {} + _flood_boundary = [] + _panel_boundary = [] + + enterRoom("outside") + + while !_panel_boundary.empty(): + var filtered = [] + for door in _flood_boundary: + if _door_mapping.has(door[1]): + continue + if _visited.size() < 18: + if _visited.has(door[2]): + continue + if _panel_boundary.size() == 1 and door[2] == "achievement": + continue + if _door_mapping.size() == 16 and door[2] == "achievement" and !_visited.has("achievement"): + filtered = [door] + break + filtered.append(door) + + var chosen_door = _pickRandom(filtered, rng) + _door_mapping[chosen_door[1]] = _panel_boundary.pop_front() + + enterRoom(chosen_door[2]) + _flood_boundary.erase(chosen_door) + + +func enterRoom(room): + if _visited.has(room): + return + + _visited.append(room) + + if room == "achievement": + return + + _panel_boundary.append(layout[room][0]) + for door in layout[room][1]: + if door[0] == "": + enterRoom(door[1]) + else: + _flood_boundary.append([room, door[0], door[1]]) + + +func _pickRandom(set, rng): + var id = rng.randi_range(0, set.size() - 1) + return set[id] -- cgit 1.4.1