diff --git a/worlds/witness/entity_hunt.py b/worlds/witness/entity_hunt.py index 208c370079ef..451fac85ffe9 100644 --- a/worlds/witness/entity_hunt.py +++ b/worlds/witness/entity_hunt.py @@ -136,10 +136,12 @@ def _get_eligible_panels(self) -> Tuple[List[str], Dict[str, Set[str]]]: return all_eligible_panels, eligible_panels_by_area def _get_percentage_of_hunt_entities_by_area(self): + hunt_entities_picked_so_far_prevent_div_0 = max(len(self.HUNT_ENTITIES), 1) + contributing_percentage_per_area = dict() for area, eligible_entities in self.ELIGIBLE_ENTITIES_PER_AREA.items(): amount_of_already_chosen_entities = len(self.ELIGIBLE_ENTITIES_PER_AREA[area] & self.HUNT_ENTITIES) - current_percentage = amount_of_already_chosen_entities / len(self.HUNT_ENTITIES) + current_percentage = amount_of_already_chosen_entities / hunt_entities_picked_so_far_prevent_div_0 contributing_percentage_per_area[area] = current_percentage return contributing_percentage_per_area diff --git a/worlds/witness/data/generate_data_file.py b/worlds/witness/generate_data_file.py similarity index 53% rename from worlds/witness/data/generate_data_file.py rename to worlds/witness/generate_data_file.py index 62dadcca515c..50a63a374619 100644 --- a/worlds/witness/data/generate_data_file.py +++ b/worlds/witness/generate_data_file.py @@ -1,7 +1,9 @@ from collections import defaultdict +from data import static_logic as static_witness_logic + if __name__ == "__main__": - with open("APWitnessData.h", "w") as datafile: + with open("data/APWitnessData.h", "w") as datafile: datafile.write("""# pragma once # include @@ -9,32 +11,20 @@ # include """) + area_to_location_ids = defaultdict(list) area_to_entity_ids = defaultdict(list) - with open("WitnessLogic.txt") as w: - current_area = "" - - for line in w.readlines(): - line = line.strip() - if not line: - continue + for entity_id, entity_object in static_witness_logic.ENTITIES_BY_HEX.items(): + location_id = entity_object["id"] - if line.startswith("=="): - current_area = line[2:-2] - continue + area = entity_object["area"]["name"] + area_to_entity_ids[area].append(entity_id) - if line.endswith(":"): - continue + if location_id is None: + continue - line_split = line.split(" - ") - location_id = line_split[0] - if location_id.isnumeric(): - area_to_location_ids[current_area].append(location_id) - - entity_id = line_split[1].split(" ", 1)[0] - - area_to_entity_ids[current_area].append(entity_id) + area_to_location_ids[area].append(str(location_id)) datafile.write("inline std::map> areaNameToLocationIDs = {\n") datafile.write( @@ -52,4 +42,4 @@ for area, entity_ids in area_to_entity_ids.items() ) ) - datafile.write("\n};\n") + datafile.write("\n};\n\n")