79 lines
3.2 KiB
Python
79 lines
3.2 KiB
Python
from BaseClasses import Entrance, MultiWorld, Region, ItemClassification
|
|
from .Helpers import is_category_enabled, is_location_enabled, is_event_enabled
|
|
from .Data import region_table
|
|
from .Locations import ManualLocation, location_name_to_location
|
|
from .Items import ManualItem
|
|
from worlds.AutoWorld import World
|
|
|
|
|
|
if not region_table:
|
|
region_table = {}
|
|
|
|
regionMap = { **region_table }
|
|
starting_regions = [ name for name in regionMap if "starting" in regionMap[name].keys() and regionMap[name]["starting"] ]
|
|
|
|
if len(starting_regions) == 0:
|
|
starting_regions = region_table.keys() # the Manual region connects to all user-defined regions automatically if you specify no starting regions
|
|
|
|
regionMap["Manual"] = {
|
|
"requires": [],
|
|
"connects_to": starting_regions
|
|
}
|
|
|
|
|
|
def create_regions(world: World, multiworld: MultiWorld, player: int):
|
|
# Create regions and assign locations to each region
|
|
for region in regionMap:
|
|
if "connects_to" not in regionMap[region]:
|
|
exit_array = None
|
|
else:
|
|
exit_array = regionMap[region]["connects_to"] or None
|
|
|
|
# safeguard for bad value at the end
|
|
if not exit_array:
|
|
exit_array = None
|
|
|
|
locations = []
|
|
for location in world.location_table:
|
|
if "region" in location and location["region"] == region:
|
|
if is_location_enabled(multiworld, player, location):
|
|
locations.append(location["name"])
|
|
|
|
new_region = create_region(world, multiworld, player, region, locations, exit_array)
|
|
multiworld.regions += [new_region]
|
|
|
|
# Link regions together
|
|
for region in regionMap:
|
|
if "connects_to" in regionMap[region] and regionMap[region]["connects_to"]:
|
|
for linkedRegion in regionMap[region]["connects_to"]:
|
|
connection = multiworld.get_entrance(getConnectionName(region, linkedRegion), player)
|
|
connection.connect(multiworld.get_region(linkedRegion, player))
|
|
|
|
def create_region(world: World, multiworld: MultiWorld, player: int, name: str, locations=None, exits=None):
|
|
ret = Region(name, player, multiworld)
|
|
|
|
if locations:
|
|
for location in locations:
|
|
loc_id = world.location_name_to_id.get(location, 0)
|
|
locationObj = ManualLocation(player, location, loc_id, ret)
|
|
if location_name_to_location[location].get('prehint'):
|
|
world.options.start_location_hints.value.add(location)
|
|
ret.locations.append(locationObj)
|
|
if exits:
|
|
for exit in exits:
|
|
ret.exits.append(Entrance(player, getConnectionName(name, exit), ret))
|
|
return ret
|
|
|
|
def getConnectionName(entranceName: str, exitName: str):
|
|
return entranceName + "To" + exitName
|
|
|
|
def create_events(world: World, multiworld: MultiWorld, player: int):
|
|
for name, event in world.event_name_to_event.items():
|
|
if not is_event_enabled(multiworld, player, event):
|
|
continue
|
|
region = multiworld.get_region(event.get("region", "Manual"), player)
|
|
item = ManualItem(event["name"], ItemClassification.progression, None, player=player)
|
|
location = ManualLocation(player, name, None, region)
|
|
region.locations.append(location)
|
|
location.place_locked_item(item)
|