summary refs log tree commit diff stats
path: root/randomizer/load.gd
blob: 456e135886b5e9badc69ecf242257ef6defa16f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
extends "res://scripts/load.gd"


func _load():
	global._print("Hooked Load Start")

	var randomizer = global.get_node("Randomizer")
	var panels_parent = $Panels

	# Hide the countdown true panels.
	for child in $CountdownPanels.get_children():
		if child.is_class("Spatial"):
			child.get_node(child.replace_with).translation.y -= 100.0

	# Create "The Wanderer".
	set_gridmap_tile(-4.5, 6.5, 56.5, "MeshInstance4")
	set_gridmap_tile(-3.5, 6.5, 56.5, "MeshInstance18")
	set_gridmap_tile(-3.5, 6.5, 57.5, "MeshInstance5")

	var door_scene = load("res://nodes/door.tscn")
	var door_script = load("res://scripts/doorControl.gd")
	var wanderer_entrance = door_scene.instance()
	wanderer_entrance.name = "Door_wanderer_entrance"
	wanderer_entrance.translation = Vector3(7.5, 5, 53)
	wanderer_entrance.rotation = Vector3(0, -PI / 2, 0)
	wanderer_entrance.scale = Vector3(1, 1.5, 1)
	wanderer_entrance.set_script(door_script)
	wanderer_entrance.panels.append("../../../Panels/Tower Room/Panel_wanderlust_1234567890")
	get_node("Doors/Tower Room Area Doors").add_child(wanderer_entrance)

	var wanderer_achieve = get_node("Panels/Tower Room/Panel_1234567890_wanderlust")
	wanderer_achieve.get_parent().remove_child(wanderer_achieve)
	get_node("Panels/Countdown Panels").add_child(wanderer_achieve)

	var countdown_scene = load("res://nodes/panel_countdown.tscn")
	var wanderer_cdp = countdown_scene.instance()
	wanderer_cdp.name = "CountdownPanel_wanderer"
	wanderer_cdp.panels = [
		"../../Panels/Tower Room/Panel_wanderlust_1234567890",
		"../../Panels/Orange Room/Panel_lust",
		"../../Panels/Orange Room/Panel_read",
		"../../Panels/Orange Room/Panel_sew",
		"../../Panels/Orange Room/Panel_dead",
		"../../Panels/Orange Room/Panel_learn",
		"../../Panels/Orange Room/Panel_dust",
		"../../Panels/Orange Room/Panel_star",
		"../../Panels/Orange Room/Panel_wander"
	]
	wanderer_cdp.translation = wanderer_achieve.translation
	wanderer_cdp.rotation = wanderer_achieve.rotation
	get_node("CountdownPanels").add_child(wanderer_cdp)

	wanderer_achieve.translation = Vector3(-51, -33, 35)  # way under the map

	# Apply the randomized panels.
	randomizer.generator.apply(self)

	# Write static panels.
	set_static_panel("Entry Room/Panel_hi_hi", "hi")
	if randomizer.generator.is_set_seed:
		set_static_panel("Entry Room/Panel_write_write", "set seed")
	else:
		set_static_panel("Entry Room/Panel_write_write", "random seed")
	set_static_panel("Entry Room/Panel_same_same", str(randomizer.generator.gen_seed))
	set_static_panel("Entry Room/Panel_type_type", "version")
	set_static_panel("Entry Room/Panel_this_this", randomizer.my_version)
	set_static_panel("Entry Room/Panel_hi_high", "goode", "good")
	set_static_panel("Entry Room/Panel_low_low", "serendipity", "luck")
	set_static_panel("Shuffle Room/Panel_secret_secret", "trans rights", "human rights")
	set_static_panel("Color Arrow Room/Panel_me", "me", "hatkirby")

	# HOT CRUSTS should be at eye-level, have a yellow block behind it, and
	# not vanish when solved.
	var hotcrusts = panels_parent.get_node("Shuffle Room/Panel_shortcuts")
	hotcrusts.translation.y = 1.5
	hotcrusts.get_node("Viewport/GUI/Panel/TextEdit").disconnect(
		"answer_correct", hotcrusts, "handle_correct"
	)

	set_gridmap_tile(-20.5, 1.5, -79.5, "MeshInstance9")

	# TRANS RIGHTS should be bottom white, like it used to be.
	var trans_rights = panels_parent.get_node("Shuffle Room/Panel_secret_secret")
	trans_rights.translation.y = 0.5

	# Move LOW/LOW back to where it used to be.
	var panel_low = panels_parent.get_node("Entry Room/Panel_low_low")
	var sign_low = $Decorations/PanelSign/sign21
	panel_low.translation = sign_low.translation
	panel_low.rotation = sign_low.rotation
	sign_low.queue_free()

	# Require LOW/LOW for opening the second door.
	get_node("Doors/Entry Room Area Doors/Door_hi_high").panels.append(
		"../../../Panels/Entry Room/Panel_low_low"
	)
	get_node("Doors/Entry Room Area Doors/Door_hi_high")._ready()

	# Finish up with The Wanderer.
	wanderer_achieve.achieved_text = "the wanderer"
	wanderer_cdp.replace_with = "../../Panels/Countdown Panels/Panel_1234567890_wanderlust"

	get_node("Doors/Tower Room Area Doors/Door_wanderlust_start").panels = [
		"../../../Panels/Countdown Panels/Panel_1234567890_wanderlust"
	]

	# Make stack/double puzzles into proxies.
	var proxyscript = load("res://scripts/panelProxy.gd")

	var extradata_proxies = randomizer.get_node("Extradata").proxies
	for truepanel in extradata_proxies:
		var proxies = extradata_proxies[truepanel]
		for proxypanel in proxies:
			var proxynode = panels_parent.get_node(proxypanel)
			var oldparent = proxynode.get_parent()
			oldparent.remove_child(proxynode)
			var oldtext = proxynode.text
			var oldanswer = proxynode.answer
			proxynode.set_script(proxyscript)
			proxynode.text = oldtext
			proxynode.answer = oldanswer
			proxynode.proxied_panels = ["../../%s" % truepanel]
			proxynode.exact_proxy = true
			proxynode.request_ready()
			oldparent.add_child(proxynode)
	
	# Transform the Pilgrim Room.
	transform_panel("Lingo Room/Panel_lingo_1", 3, 2, 25.001, 0, 0, 0, 2, 2, 1)
	transform_panel("Lingo Room/Panel_lingo_8", 6.999, 1, 27, 0, -90, 0, 2, 2, 1)
	transform_panel("Lingo Room/Panel_lingo_3", 10, 1, 75.999, 0, 180, 0, 2, 2, 1)
	transform_panel("Lingo Room/Panel_lingo_2", -11, 1, 68.999, 0, 180, 0, 2, 2, 1)
	transform_panel("Lingo Room/Panel_lingo_5", -24.999, 1, 63, 0, 90, 0, 2, 2, 1)
	transform_panel("Lingo Room/Panel_lingo_11", -25.999, 2, 45, 0, 90, 0, 2, 2, 1)

	clear_gridmap_tile(2.5, 2.5, 23.5)
	set_gridmap_tile(2.5, 1.5, 23.5, "MeshInstance18")
	set_gridmap_tile(3.5, 1.5, 23.5, "MeshInstance18")
	set_gridmap_tile(2.5, 2.5, 24.5, "MeshInstance8")
	set_gridmap_tile(2.5, 1.5, 24.5, "MeshInstance8")
	set_gridmap_tile(3.5, 2.5, 24.5, "MeshInstance8")
	set_gridmap_tile(3.5, 1.5, 24.5, "MeshInstance8")

	set_gridmap_tile(8.5, 1.5, 27.5, "MeshInstance18")
	set_gridmap_tile(8.5, 0.5, 26.5, "MeshInstance18")
	set_gridmap_tile(7.5, 1.5, 27.5, "MeshInstance6")
	set_gridmap_tile(7.5, 1.5, 26.5, "MeshInstance6")
	set_gridmap_tile(7.5, 0.5, 27.5, "MeshInstance6")
	set_gridmap_tile(7.5, 0.5, 26.5, "MeshInstance6")

	set_gridmap_tile(9.5, 0.5, 76.5, "MeshInstance5")
	set_gridmap_tile(9.5, 1.5, 76.5, "MeshInstance5")
	set_gridmap_tile(10.5, 1.5, 76.5, "MeshInstance5")
	set_gridmap_tile(10.5, 1.5, 77.5, "MeshInstance18")
	set_gridmap_tile(9.5, 1.5, 77.5, "MeshInstance18")

	set_gridmap_tile(-10.5, 0.5, 69.5, "MeshInstance4")
	set_gridmap_tile(-10.5, 1.5, 69.5, "MeshInstance4")
	set_gridmap_tile(-11.5, 0.5, 69.5, "MeshInstance9")
	set_gridmap_tile(-11.5, 1.5, 69.5, "MeshInstance9")
	set_gridmap_tile(-10.5, 0.5, 70.5, "MeshInstance18")
	set_gridmap_tile(-11.5, 0.5, 70.5, "MeshInstance18")

	clear_gridmap_tile(-26.5, 1.5, 64.5)
	set_gridmap_tile(-26.5, 1.5, 63.5, "MeshInstance18")
	clear_gridmap_tile(-26.5, 1.5, 62.5)
	clear_gridmap_tile(-26.5, 1.5, 61.5)
	set_gridmap_tile(-26.5, 0.5, 62.5, "MeshInstance18")
	set_gridmap_tile(-25.5, 1.5, 63.5, "MeshInstance6")
	set_gridmap_tile(-25.5, 0.5, 63.5, "MeshInstance6")
	set_gridmap_tile(-25.5, 1.5, 62.5, "MeshInstance4")
	set_gridmap_tile(-25.5, 0.5, 62.5, "MeshInstance4")

	set_gridmap_tile(-26.5, 1.5, 45.5, "MeshInstance9")
	set_gridmap_tile(-26.5, 2.5, 45.5, "MeshInstance9")
	set_gridmap_tile(-26.5, 2.5, 44.5, "MeshInstance9")
	set_gridmap_tile(-27.5, 1.5, 45.5, "MeshInstance18")
	set_gridmap_tile(-27.5, 2.5, 44.5, "MeshInstance18")

	var cdp_template = load("res://nodes/panel_countdown.tscn")
	var pilgrim_cdp = cdp_template.instance()
	var pilgrim_real = panels_parent.get_node("Lingo Room/Panel_lingo_9")
	pilgrim_real.text = "you"
	pilgrim_real.answer = "the pilgrim"
	pilgrim_real.achieved_text = "the pilgrim"
	pilgrim_cdp.translation = pilgrim_real.translation
	pilgrim_cdp.rotation = pilgrim_real.rotation
	pilgrim_cdp.scale = pilgrim_real.scale
	pilgrim_cdp.replace_with = "../../Panels/Countdown Panels/Panel_lingo_9"
	pilgrim_cdp.panels = [
		"../../Panels/Lingo Room/Panel_lingo_1",
		"../../Panels/Lingo Room/Panel_lingo_2",
		"../../Panels/Lingo Room/Panel_lingo_3",
		"../../Panels/Lingo Room/Panel_lingo_4",
		"../../Panels/Lingo Room/Panel_lingo_5",
		"../../Panels/Lingo Room/Panel_lingo_6",
		"../../Panels/Lingo Room/Panel_lingo_7",
		"../../Panels/Lingo Room/Panel_lingo_8",
		"../../Panels/Lingo Room/Panel_lingo_10",
		"../../Panels/Lingo Room/Panel_lingo_11",
		"../../Panels/Lingo Room/Panel_lingo_12",
		"../../Panels/Lingo Room/Panel_lingo_13"
	]
	pilgrim_real.get_parent().remove_child(pilgrim_real)
	panels_parent.get_node("Countdown Panels").add_child(pilgrim_real)
	pilgrim_cdp.set_name("CountdownPanel_pilgrim")
	$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"])

	# Sunwarps 1 and 6 are rotated differently from the rest, so we have to fix that.
	get_node("Decorations/Teleporter Windows/localmap").rotation_degrees.y = 0
	get_node("Decorations/Teleporter Windows/localmap2").rotation_degrees.y = 0
	get_node("Decorations/Teleporter Windows/localmap11").rotation_degrees.y = 0
	get_node("Decorations/Teleporter Windows/localmap12").rotation_degrees.y = 0
	get_node("Decorations/Teleporter Windows/localmap13").rotation_degrees.y = -90

	get_node("Warps/Teleporter Warps/Sunwarp_enter_1").translation.x = 19.5
	get_node("Warps/Teleporter Warps/Sunwarp_exit_1").translation.x = -15.5
	get_node("Warps/Teleporter Warps/Sunwarp_enter_6").translation.x = 4.5
	get_node("Warps/Teleporter Warps/Sunwarp_exit_6").translation.x = -37.5
	get_node("Warps/Teleporter Warps/Sunwarp_exit_7").translation.z = 23.5

	# Randomize the sunwarps.
	var sw_orig_translations = []
	var sw_rotations = [0, 0, 90, 180, 0, 0, 0, 90, 270, 270, 0, 0]
	var sw_text_translations = []
	var sw_text_rotations = []
	for i in range (1,7):
		sw_orig_translations.append(get_node("Warps/Teleporter Warps/Sunwarp_enter_%d" % i).translation)
		sw_text_translations.append(get_node("Decorations/Signs/Sunwarp Numbers/enter_%d" % i).translation)
		sw_text_rotations.append(get_node("Decorations/Signs/Sunwarp Numbers/enter_%d" % i).rotation_degrees)
	for i in range (1,7):
		sw_orig_translations.append(get_node("Warps/Teleporter Warps/Sunwarp_exit_%d" % i).translation)
		sw_text_translations.append(get_node("Decorations/Signs/Sunwarp Numbers/exit_%d" % i).translation)
		sw_text_rotations.append(get_node("Decorations/Signs/Sunwarp Numbers/exit_%d" % i).rotation_degrees)
	for i in range (1,7):
		get_node("Warps/Teleporter Warps/Sunwarp_enter_%d" % i).translation = sw_orig_translations[randomizer.sunwarps[i-1]-1]
		get_node("Warps/Teleporter Warps/Sunwarp_exit_%d" % i).translation = sw_orig_translations[randomizer.sunwarps[i+5]-1]

		get_node("Decorations/Signs/Sunwarp Numbers/enter_%d" % i).translation = sw_text_translations[randomizer.sunwarps[i-1]-1]
		get_node("Decorations/Signs/Sunwarp Numbers/enter_%d" % i).rotation_degrees = sw_text_rotations[randomizer.sunwarps[i-1]-1]

		get_node("Decorations/Signs/Sunwarp Numbers/exit_%d" % i).translation = sw_text_translations[randomizer.sunwarps[i+5]-1]
		get_node("Decorations/Signs/Sunwarp Numbers/exit_%d" % i).rotation_degrees = sw_text_rotations[randomizer.sunwarps[i+5]-1]

		var final_rot = sw_rotations[randomizer.sunwarps[i-1]-1] - sw_rotations[randomizer.sunwarps[i+5]-1]
		if final_rot < 0:
			final_rot += 360
		get_node("Warps/Teleporter Warps/Sunwarp_enter_%d" % i).rotate = str(final_rot)

	# Proceed with the rest of the load.
	global._print("Hooked Load End")
	._load()


func set_static_panel(name, question, answer = ""):
	if answer == "":
		answer = question

	var node = self.get_node("Panels").get_node(name)

	node.text = question
	node.answer = answer


func set_gridmap_tile(x, y, z, tile):
	var gridmap = self.get_node("GridMap")
	var mesh_library = gridmap.mesh_library
	var mapvec = gridmap.world_to_map(gridmap.to_local(Vector3(x, y, z)))

	gridmap.set_cell_item(mapvec.x, mapvec.y, mapvec.z, mesh_library.find_item_by_name(tile))


func clear_gridmap_tile(x, y, z):
	var gridmap = self.get_node("GridMap")
	var mesh_library = gridmap.mesh_library
	var mapvec = gridmap.world_to_map(gridmap.to_local(Vector3(x, y, z)))

	gridmap.set_cell_item(mapvec.x, mapvec.y, mapvec.z, GridMap.INVALID_CELL_ITEM)


func transform_panel(path, tx, ty, tz, rx, ry, rz, sx, sy, sz):
	var panel_node = self.get_node("Panels").get_node(path)
	panel_node.translation.x = tx
	panel_node.translation.y = ty
	panel_node.translation.z = tz
	panel_node.rotation_degrees.x = rx
	panel_node.rotation_degrees.y = ry
	panel_node.rotation_degrees.z = rz
	panel_node.scale.x = sx
	panel_node.scale.y = sy
	panel_node.scale.z = sz