Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
NewSoupVi committed Nov 27, 2024
1 parent 83fb023 commit 851998e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
28 changes: 16 additions & 12 deletions worlds/witness/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ def hint_from_location(world: "WitnessWorld", location: str) -> Optional[Witness

def get_item_and_location_names_in_random_order(world: "WitnessWorld",
own_itempool: List["WitnessItem"]) -> Tuple[List[str], List[str]]:
prog_item_names_in_this_world = [
progression_item_names_in_this_world = [
item.name for item in own_itempool
if item.advancement and item.code and item.location
]
world.random.shuffle(prog_item_names_in_this_world)
world.random.shuffle(progression_item_names_in_this_world)

locations_in_this_world = [
location for location in world.multiworld.get_locations(world.player)
Expand All @@ -318,34 +318,36 @@ def get_item_and_location_names_in_random_order(world: "WitnessWorld",

location_names_in_this_world = [location.name for location in locations_in_this_world]

return prog_item_names_in_this_world, location_names_in_this_world
return progression_item_names_in_this_world, location_names_in_this_world


def make_always_and_priority_hints(world: "WitnessWorld", own_itempool: List["WitnessItem"],
already_hinted_locations: Set[Location]
) -> Tuple[List[WitnessLocationHint], List[WitnessLocationHint]]:

prog_items_in_this_world, loc_in_this_world = get_item_and_location_names_in_random_order(world, own_itempool)
progression_items_in_this_world, locations_in_this_world = get_item_and_location_names_in_random_order(
world, own_itempool
)

always_items = [
item for item in get_always_hint_items(world)
if item in prog_items_in_this_world
if item in progression_items_in_this_world
]
priority_items = [
item for item in get_priority_hint_items(world)
if item in prog_items_in_this_world
if item in progression_items_in_this_world
]

if world.options.vague_hints:
always_locations, priority_locations = [], []
else:
always_locations = [
location for location in get_always_hint_locations(world)
if location in loc_in_this_world
if location in locations_in_this_world
]
priority_locations = [
location for location in get_priority_hint_locations(world)
if location in loc_in_this_world
if location in locations_in_this_world
]

# Get always and priority location/item hints
Expand Down Expand Up @@ -376,7 +378,9 @@ def make_always_and_priority_hints(world: "WitnessWorld", own_itempool: List["Wi
def make_extra_location_hints(world: "WitnessWorld", hint_amount: int, own_itempool: List["WitnessItem"],
already_hinted_locations: Set[Location], hints_to_use_first: List[WitnessLocationHint],
unhinted_locations_for_hinted_areas: Dict[str, Set[Location]]) -> List[WitnessWordedHint]:
prog_items_in_this_world, locations_in_this_world = get_item_and_location_names_in_random_order(world, own_itempool)
progression_items_in_this_world, locations_in_this_world = get_item_and_location_names_in_random_order(
world, own_itempool
)

next_random_hint_is_location = world.random.randrange(0, 2)

Expand All @@ -390,7 +394,7 @@ def make_extra_location_hints(world: "WitnessWorld", hint_amount: int, own_itemp
}

while len(hints) < hint_amount:
if not prog_items_in_this_world and not locations_in_this_world and not hints_to_use_first:
if not progression_items_in_this_world and not locations_in_this_world and not hints_to_use_first:
logging.warning(f"Ran out of items/locations to hint for player {world.player_name}.")
break

Expand All @@ -399,8 +403,8 @@ def make_extra_location_hints(world: "WitnessWorld", hint_amount: int, own_itemp
location_hint = hints_to_use_first.pop()
elif next_random_hint_is_location and locations_in_this_world:
location_hint = hint_from_location(world, locations_in_this_world.pop())
elif not next_random_hint_is_location and prog_items_in_this_world:
location_hint = hint_from_item(world, prog_items_in_this_world.pop(), own_itempool)
elif not next_random_hint_is_location and progression_items_in_this_world:
location_hint = hint_from_item(world, progression_items_in_this_world.pop(), own_itempool)
# The list that the hint was supposed to be taken from was empty.
# Try the other list, which has to still have something, as otherwise, all lists would be empty,
# which would have triggered the guard condition above.
Expand Down
6 changes: 3 additions & 3 deletions worlds/witness/player_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ def finalize_items(self) -> None:
self.PROGRESSION_ITEMS_ACTUALLY_IN_THE_GAME.add(progressive_item_name)
child_items = cast(ProgressiveItemDefinition,
static_witness_logic.ALL_ITEMS[progressive_item_name]).child_item_names
multi_list = [child_item for child_item in child_items
progressive_list = [child_item for child_item in child_items
if child_item in self.BASE_PROGESSION_ITEMS_ACTUALLY_IN_THE_GAME]
self.PARENT_ITEM_COUNT_PER_BASE_ITEM[item] = multi_list.index(item) + 1
self.PROGRESSIVE_LISTS[progressive_item_name] = multi_list
self.PARENT_ITEM_COUNT_PER_BASE_ITEM[item] = progressive_list.index(item) + 1
self.PROGRESSIVE_LISTS[progressive_item_name] = progressive_list
else:
self.PROGRESSION_ITEMS_ACTUALLY_IN_THE_GAME.add(item)

Expand Down
4 changes: 2 additions & 2 deletions worlds/witness/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ def _has_item(item: str, world: "WitnessWorld",
if item == "Theater to Tunnels":
return lambda state: _can_do_theater_to_tunnels(state, world)

prog_item = static_witness_logic.get_parent_progressive_item(item)
actual_item = static_witness_logic.get_parent_progressive_item(item)
needed_amount = player_logic.PARENT_ITEM_COUNT_PER_BASE_ITEM[item]

simple_rule: SimpleItemRepresentation = SimpleItemRepresentation(prog_item, needed_amount)
simple_rule: SimpleItemRepresentation = SimpleItemRepresentation(actual_item, needed_amount)
return simple_rule


Expand Down

0 comments on commit 851998e

Please sign in to comment.