diff options
Diffstat (limited to 'randomizer/steady.gd')
-rw-r--r-- | randomizer/steady.gd | 78 |
1 files changed, 78 insertions, 0 deletions
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 @@ | |||
1 | extends Node | ||
2 | |||
3 | const layout = { | ||
4 | "outside": ["Panel_begin_begin",[["Door_3", "carnation"], ["Door_2", "rose"], ["Door_1", "lilac"]]], | ||
5 | "lilac":["Panel_lielack_lilac",[["Door_1","outside"],["Door_5","amethyst"],["Door_vert_1","rose"]]], | ||
6 | "rose":["Panel_soar_rose",[["Door_vert_1","lilac"],["Door_6","ruby"],["Door_vert_2","carnation"],["Door_2","outside"]]], | ||
7 | "carnation":["Panel_incarnation_carnation",[["Door_vert_2","rose"],["Door_7","amber"],["Door_vert_3","sunflower"],["Door_3","outside"]]], | ||
8 | "sunflower":["Panel_sun_sunflower",[["Door_8","topaz"],["Door_vert_3","carnation"],["Door_4","achievement"],["","lime"]]], | ||
9 | "emerald":["Panel_herald_emerald",[["Door_9","lime"],["Door_vert_4","sapphire"],["","lemon"]]], | ||
10 | "sapphire":["Panel_sap_sapphire",[["Door_vert_4","emerald"],["Door_10","blueberry"],["Door_vert_5","amethyst"]]], | ||
11 | "amethyst":["Panel_thistle_amethyst",[["Door_vert_5","sapphire"],["Door_11","plum"],["Door_vert_6","ruby"],["Door_5","lilac"]]], | ||
12 | "ruby":["Panel_bury_ruby",[["Door_vert_6","amethyst"],["Door_12","cherry"],["Door_vert_7","amber"],["Door_6","rose"]]], | ||
13 | "amber":["Panel_antechamber_amber",[["Door_vert_7","ruby"],["Door_13","orange"],["Door_vert_8","topaz"],["Door_7","carnation"]]], | ||
14 | "topaz":["Panel_top_topaz",[["Door_vert_8","amber"],["Door_14","lemon"],["Door_8","sunflower"]]], | ||
15 | "lime":["Panel_limelight_lime",[["Door_vert_9","blueberry"],["Door_9","emerald"]]], | ||
16 | "blueberry":["Panel_blue_blueberry",[["Door_vert_9","lime"],["Door_10","sapphire"],["Door_vert_10","plum"]]], | ||
17 | "plum":["Panel_lump_plum",[["Door_vert_10","blueberry"],["Door_11","amethyst"],["Door_vert_11","cherry"]]], | ||
18 | "cherry":["Panel_hairy_cherry",[["Door_vert_11","plum"],["Door_12","ruby"],["Door_vert_12","orange"]]], | ||
19 | "orange":["Panel_blue_orange",[["Door_vert_12","cherry"],["Door_13","amber"],["Door_vert_13","lemon"]]], | ||
20 | "lemon":["Panel_melon_lemon",[["Door_vert_13","orange"],["Door_14","topaz"]]], | ||
21 | } | ||
22 | |||
23 | var _visited | ||
24 | var _door_mapping | ||
25 | var _flood_boundary | ||
26 | var _panel_boundary | ||
27 | |||
28 | |||
29 | func generate(rng): | ||
30 | _visited = [] | ||
31 | _door_mapping = {} | ||
32 | _flood_boundary = [] | ||
33 | _panel_boundary = [] | ||
34 | |||
35 | enterRoom("outside") | ||
36 | |||
37 | while !_panel_boundary.empty(): | ||
38 | var filtered = [] | ||
39 | for door in _flood_boundary: | ||
40 | if _door_mapping.has(door[1]): | ||
41 | continue | ||
42 | if _visited.size() < 18: | ||
43 | if _visited.has(door[2]): | ||
44 | continue | ||
45 | if _panel_boundary.size() == 1 and door[2] == "achievement": | ||
46 | continue | ||
47 | if _door_mapping.size() == 16 and door[2] == "achievement" and !_visited.has("achievement"): | ||
48 | filtered = [door] | ||
49 | break | ||
50 | filtered.append(door) | ||
51 | |||
52 | var chosen_door = _pickRandom(filtered, rng) | ||
53 | _door_mapping[chosen_door[1]] = _panel_boundary.pop_front() | ||
54 | |||
55 | enterRoom(chosen_door[2]) | ||
56 | _flood_boundary.erase(chosen_door) | ||
57 | |||
58 | |||
59 | func enterRoom(room): | ||
60 | if _visited.has(room): | ||
61 | return | ||
62 | |||
63 | _visited.append(room) | ||
64 | |||
65 | if room == "achievement": | ||
66 | return | ||
67 | |||
68 | _panel_boundary.append(layout[room][0]) | ||
69 | for door in layout[room][1]: | ||
70 | if door[0] == "": | ||
71 | enterRoom(door[1]) | ||
72 | else: | ||
73 | _flood_boundary.append([room, door[0], door[1]]) | ||
74 | |||
75 | |||
76 | func _pickRandom(set, rng): | ||
77 | var id = rng.randi_range(0, set.size() - 1) | ||
78 | return set[id] | ||