Add chart randomization
@@ -6,6 +6,7 @@ from pathlib import Path
import re
import random
from collections import OrderedDict
+import copy
from fs_helpers import *
from yaz0_decomp import Yaz0Decompressor
@@ -62,6 +63,8 @@ class Randomizer:
self.logic.add_owned_item("Hero's Shield")
self.logic.add_owned_item("Boat's Sail")
+ self.randomize_charts()
+
self.randomize_items()
self.write_spoiler_log()
@@ -305,6 +308,35 @@ class Randomizer:
item_name = random.choice(self.logic.consumable_items)
self.logic.set_location_to_item(location_name, item_name)
+ def randomize_charts(self):
+ # Shuffles around which chart points to each sector.
+
+ chart_list = self.get_arc("files/res/Msg/fmapres.arc").chart_lists[0]
+ randomizable_charts = [chart for chart in chart_list.charts if chart.type in [0, 1, 2, 6]]
+
+ original_charts = copy.deepcopy(randomizable_charts)
+ # Sort the charts by their texture ID so we get the same results even if we randomize them multiple times.
+ original_charts.sort(key=lambda chart: chart.texture_id)
+ random.shuffle(original_charts)
+
+ for chart in randomizable_charts:
+ chart_to_copy_from = original_charts.pop()
+
+ chart.texture_id = chart_to_copy_from.texture_id
+ chart.sector_x = chart_to_copy_from.sector_x
+ chart.sector_y = chart_to_copy_from.sector_y
+
+ for random_pos_index in range(4):
+ possible_pos = chart.possible_random_positions[random_pos_index]
+ possible_pos_to_copy_from = chart_to_copy_from.possible_random_positions[random_pos_index]
+
+ possible_pos.chart_texture_x_offset = possible_pos_to_copy_from.chart_texture_x_offset
+ possible_pos.chart_texture_y_offset = possible_pos_to_copy_from.chart_texture_y_offset
+ possible_pos.salvage_x_pos = possible_pos_to_copy_from.salvage_x_pos
+ possible_pos.salvage_y_pos = possible_pos_to_copy_from.salvage_y_pos
+
+ chart.save_changes()
+
def write_spoiler_log(self):
spoiler_log = ""
