Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into that_plando_thing_a…
Browse files Browse the repository at this point in the history
…gain
  • Loading branch information
NewSoupVi committed Apr 11, 2024
2 parents 97c603e + cf59cfa commit c360f38
Show file tree
Hide file tree
Showing 170 changed files with 2,231 additions and 2,366 deletions.
33 changes: 24 additions & 9 deletions Fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,16 @@ def fill_restrictive(multiworld: MultiWorld, base_state: CollectionState, locati
# There are leftover unplaceable items and locations that won't accept them
if multiworld.can_beat_game():
logging.warning(
f'Not all items placed. Game beatable anyway. (Could not place {unplaced_items})')
f"Not all items placed. Game beatable anyway.\nCould not place:\n"
f"{', '.join(str(item) for item in unplaced_items)}")
else:
raise FillError(f'No more spots to place {unplaced_items}, locations {locations} are invalid. '
f'Already placed {len(placements)}: {", ".join(str(place) for place in placements)}')
raise FillError(f"No more spots to place {len(unplaced_items)} items. Remaining locations are invalid.\n"
f"Unplaced items:\n"
f"{', '.join(str(item) for item in unplaced_items)}\n"
f"Unfilled locations:\n"
f"{', '.join(str(location) for location in locations)}\n"
f"Already placed {len(placements)}:\n"
f"{', '.join(str(place) for place in placements)}")

item_pool.extend(unplaced_items)

Expand Down Expand Up @@ -273,8 +279,13 @@ def remaining_fill(multiworld: MultiWorld,

if unplaced_items and locations:
# There are leftover unplaceable items and locations that won't accept them
raise FillError(f'No more spots to place {unplaced_items}, locations {locations} are invalid. '
f'Already placed {len(placements)}: {", ".join(str(place) for place in placements)}')
raise FillError(f"No more spots to place {len(unplaced_items)} items. Remaining locations are invalid.\n"
f"Unplaced items:\n"
f"{', '.join(str(item) for item in unplaced_items)}\n"
f"Unfilled locations:\n"
f"{', '.join(str(location) for location in locations)}\n"
f"Already placed {len(placements)}:\n"
f"{', '.join(str(place) for place in placements)}")

itempool.extend(unplaced_items)

Expand Down Expand Up @@ -457,7 +468,9 @@ def mark_for_locking(location: Location):
fill_restrictive(multiworld, multiworld.state, defaultlocations, progitempool, name="Progression")
if progitempool:
raise FillError(
f'Not enough locations for progress items. There are {len(progitempool)} more items than locations')
f"Not enough locations for progression items. "
f"There are {len(progitempool)} more progression items than there are available locations."
)
accessibility_corrections(multiworld, multiworld.state, defaultlocations)

for location in lock_later:
Expand All @@ -470,7 +483,9 @@ def mark_for_locking(location: Location):
remaining_fill(multiworld, excludedlocations, filleritempool, "Remaining Excluded")
if excludedlocations:
raise FillError(
f"Not enough filler items for excluded locations. There are {len(excludedlocations)} more locations than items")
f"Not enough filler items for excluded locations. "
f"There are {len(excludedlocations)} more excluded locations than filler or trap items."
)

restitempool = filleritempool + usefulitempool

Expand All @@ -481,13 +496,13 @@ def mark_for_locking(location: Location):

if unplaced or unfilled:
logging.warning(
f'Unplaced items({len(unplaced)}): {unplaced} - Unfilled Locations({len(unfilled)}): {unfilled}')
f"Unplaced items({len(unplaced)}): {unplaced} - Unfilled Locations({len(unfilled)}): {unfilled}")
items_counter = Counter(location.item.player for location in multiworld.get_locations() if location.item)
locations_counter = Counter(location.player for location in multiworld.get_locations())
items_counter.update(item.player for item in unplaced)
locations_counter.update(location.player for location in unfilled)
print_data = {"items": items_counter, "locations": locations_counter}
logging.info(f'Per-Player counts: {print_data})')
logging.info(f"Per-Player counts: {print_data})")


def flood_items(multiworld: MultiWorld) -> None:
Expand Down
25 changes: 11 additions & 14 deletions Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from Main import main as ERmain
from settings import get_settings
from Utils import parse_yamls, version_tuple, __version__, tuplize_version
from worlds.alttp import Options as LttPOptions
from worlds.alttp.EntranceRandomizer import parse_arguments
from worlds.alttp.Text import TextTable
from worlds.AutoWorld import AutoWorldRegister
from worlds.generic import PlandoConnection
from worlds import failed_world_loads


def mystery_argparse():
Expand All @@ -34,8 +34,8 @@ def mystery_argparse():

parser = argparse.ArgumentParser(description="CMD Generation Interface, defaults come from host.yaml.")
parser.add_argument('--weights_file_path', default=defaults.weights_file_path,
help='Path to the weights file to use for rolling game settings, urls are also valid')
parser.add_argument('--samesettings', help='Rolls settings per weights file rather than per player',
help='Path to the weights file to use for rolling game options, urls are also valid')
parser.add_argument('--sameoptions', help='Rolls options per weights file rather than per player',
action='store_true')
parser.add_argument('--player_files_path', default=defaults.player_files_path,
help="Input directory for player files.")
Expand Down Expand Up @@ -103,8 +103,8 @@ def main(args=None, callback=ERmain):
del(meta_weights["meta_description"])
except Exception as e:
raise ValueError("No meta description found for meta.yaml. Unable to verify.") from e
if args.samesettings:
raise Exception("Cannot mix --samesettings with --meta")
if args.sameoptions:
raise Exception("Cannot mix --sameoptions with --meta")
else:
meta_weights = None
player_id = 1
Expand Down Expand Up @@ -156,7 +156,7 @@ def main(args=None, callback=ERmain):
erargs.skip_output = args.skip_output

settings_cache: Dict[str, Tuple[argparse.Namespace, ...]] = \
{fname: (tuple(roll_settings(yaml, args.plando) for yaml in yamls) if args.samesettings else None)
{fname: (tuple(roll_settings(yaml, args.plando) for yaml in yamls) if args.sameoptions else None)
for fname, yamls in weights_cache.items()}

if meta_weights:
Expand Down Expand Up @@ -310,13 +310,6 @@ def handle_name(name: str, player: int, name_counter: Counter):
return new_name


def prefer_int(input_data: str) -> Union[str, int]:
try:
return int(input_data)
except:
return input_data


def roll_percentage(percentage: Union[int, float]) -> bool:
"""Roll a percentage chance.
percentage is expected to be in range [0, 100]"""
Expand Down Expand Up @@ -458,7 +451,11 @@ def roll_settings(weights: dict, plando_options: PlandoOptions = PlandoOptions.b

ret.game = get_choice("game", weights)
if ret.game not in AutoWorldRegister.world_types:
picks = Utils.get_fuzzy_results(ret.game, AutoWorldRegister.world_types, limit=1)[0]
picks = Utils.get_fuzzy_results(ret.game, list(AutoWorldRegister.world_types) + failed_world_loads, limit=1)[0]
if picks[0] in failed_world_loads:
raise Exception(f"No functional world found to handle game {ret.game}. "
f"Did you mean '{picks[0]}' ({picks[1]}% sure)? "
f"If so, it appears the world failed to initialize correctly.")
raise Exception(f"No world found to handle game {ret.game}. Did you mean '{picks[0]}' ({picks[1]}% sure)? "
f"Check your spelling or installation of that world.")

Expand Down
2 changes: 1 addition & 1 deletion Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def update_settings():
# Functions
Component("Open host.yaml", func=open_host_yaml),
Component("Open Patch", func=open_patch),
Component("Generate Template Settings", func=generate_yamls),
Component("Generate Template Options", func=generate_yamls),
Component("Discord Server", icon="discord", func=lambda: webbrowser.open("https://discord.gg/8Z65BR2")),
Component("18+ Discord Server", icon="discord", func=lambda: webbrowser.open("https://discord.gg/fqvNCCRsu4")),
Component("Browse Files", func=browse_files),
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ We recognize that there is a strong community of incredibly smart people that ha
Archipelago was directly forked from bonta0's `multiworld_31` branch of ALttPEntranceRandomizer (this project has a long legacy of its own, please check it out linked above) on January 12, 2020. The repository was then named to _MultiWorld-Utilities_ to better encompass its intended function. As Archipelago matured, then known as "Berserker's MultiWorld" by some, we found it necessary to transform our repository into a root level repository (as opposed to a 'forked repo') and change the name (which came later) to better reflect our project.

## Running Archipelago
For most people all you need to do is head over to the [releases](https://github.com/ArchipelagoMW/Archipelago/releases) page then download and run the appropriate installer. The installers function on Windows only.
For most people, all you need to do is head over to the [releases](https://github.com/ArchipelagoMW/Archipelago/releases) page then download and run the appropriate installer, or AppImage for Linux-based systems.

If you are running Archipelago from a non-Windows system then the likely scenario is that you are comfortable running source code directly. Please see our doc on [running Archipelago from source](docs/running%20from%20source.md).
If you are a developer or are running on a platform with no compiled releases available, please see our doc on [running Archipelago from source](docs/running%20from%20source.md).

## Related Repositories
This project makes use of multiple other projects. We wouldn't be here without these other repositories and the contributions of their developers, past and present.
Expand Down
23 changes: 21 additions & 2 deletions WebHostLib/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from typing import List, Tuple
from uuid import UUID

from flask import Blueprint, abort
from flask import Blueprint, abort, url_for

import worlds.Files
from .. import cache
from ..models import Room, Seed

Expand All @@ -21,12 +22,30 @@ def room_info(room: UUID):
room = Room.get(id=room)
if room is None:
return abort(404)

def supports_apdeltapatch(game: str):
return game in worlds.Files.AutoPatchRegister.patch_types
downloads = []
for slot in sorted(room.seed.slots):
if slot.data and not supports_apdeltapatch(slot.game):
slot_download = {
"slot": slot.player_id,
"download": url_for("download_slot_file", room_id=room.id, player_id=slot.player_id)
}
downloads.append(slot_download)
elif slot.data:
slot_download = {
"slot": slot.player_id,
"download": url_for("download_patch", patch_id=slot.id, room_id=room.id)
}
downloads.append(slot_download)
return {
"tracker": room.tracker,
"players": get_players(room.seed),
"last_port": room.last_port,
"last_activity": room.last_activity,
"timeout": room.timeout
"timeout": room.timeout,
"downloads": downloads,
}


Expand Down
13 changes: 12 additions & 1 deletion WebHostLib/autolauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import threading
import time
import typing
from uuid import UUID
from datetime import timedelta, datetime

from pony.orm import db_session, select, commit
Expand Down Expand Up @@ -62,6 +63,16 @@ def autohost(config: dict):
def keep_running():
try:
with Locker("autohost"):
# delete unowned user-content
with db_session:
# >>> bool(uuid.UUID(int=0))
# True
rooms = Room.select(lambda room: room.owner == UUID(int=0)).delete(bulk=True)
seeds = Seed.select(lambda seed: seed.owner == UUID(int=0) and not seed.rooms).delete(bulk=True)
slots = Slot.select(lambda slot: not slot.seed).delete(bulk=True)
# Command gets deleted by ponyorm Cascade Delete, as Room is Required
if rooms or seeds or slots:
logging.info(f"{rooms} Rooms, {seeds} Seeds and {slots} Slots have been deleted.")
run_guardian()
while 1:
time.sleep(0.1)
Expand Down Expand Up @@ -191,6 +202,6 @@ def guard():
guardian = threading.Thread(name="Guardian", target=guard)


from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed
from .models import Room, Generation, STATE_QUEUED, STATE_STARTED, STATE_ERROR, db, Seed, Slot
from .customserver import run_server_process, get_static_server_data
from .generate import gen_game
2 changes: 1 addition & 1 deletion WebHostLib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def check():
results, _ = roll_options(options)
if len(options) > 1:
# offer combined file back
combined_yaml = "---\n".join(f"# original filename: {file_name}\n{file_content.decode('utf-8-sig')}"
combined_yaml = "\n---\n".join(f"# original filename: {file_name}\n{file_content.decode('utf-8-sig')}"
for file_name, file_content in options.items())
combined_yaml = base64.b64encode(combined_yaml.encode("utf-8-sig")).decode()
else:
Expand Down
6 changes: 0 additions & 6 deletions WebHostLib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def weighted_options():
return render_template("weighted-options.html")


# TODO for back compat. remove around 0.4.5
@app.route("/games/<string:game>/player-settings")
def player_settings(game: str):
return redirect(url_for("player_options", game=game), 301)


# Player options pages
@app.route("/games/<string:game>/player-options")
@cache.cached()
Expand Down
3 changes: 0 additions & 3 deletions WebHostLib/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
{% elif patch.game | supports_apdeltapatch %}
<a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}" download>
Download Patch File...</a>
{% elif patch.game == "Dark Souls III" %}
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
Download JSON File...</a>
{% elif patch.game == "Final Fantasy Mystic Quest" %}
<a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}" download>
Download APMQ File...</a>
Expand Down
3 changes: 2 additions & 1 deletion WebHostLib/templates/tracker__Starcraft2.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ <h3>{{ player_name }}&apos;s Starcraft 2 Tracker</h3>
<td>{{ sc2_icon('HERC') }}</td>
<td>{{ sc2_icon('Juggernaut Plating (HERC)') }}</td>
<td>{{ sc2_icon('Kinetic Foam (HERC)') }}</td>
<td colspan="5"></td>
<td>{{ sc2_icon('Resource Efficiency (HERC)') }}</td>
<td colspan="4"></td>
<td>{{ sc2_icon('Widow Mine') }}</td>
<td>{{ sc2_icon('Drilling Claws (Widow Mine)') }}</td>
<td>{{ sc2_icon('Concealment (Widow Mine)') }}</td>
Expand Down
4 changes: 4 additions & 0 deletions WebHostLib/templates/userContent.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2>Your Rooms</h2>
<th class="center">Players</th>
<th>Created (UTC)</th>
<th>Last Activity (UTC)</th>
<th>Mark for deletion</th>
</tr>
</thead>
<tbody>
Expand All @@ -35,6 +36,7 @@ <h2>Your Rooms</h2>
<td>{{ room.seed.slots|length }}</td>
<td>{{ room.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
<td>{{ room.last_activity.strftime("%Y-%m-%d %H:%M") }}</td>
<td><a href="{{ url_for("disown_room", room=room.id) }}">Delete next maintenance.</td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -51,6 +53,7 @@ <h2>Your Seeds</h2>
<th>Seed</th>
<th class="center">Players</th>
<th>Created (UTC)</th>
<th>Mark for deletion</th>
</tr>
</thead>
<tbody>
Expand All @@ -60,6 +63,7 @@ <h2>Your Seeds</h2>
<td>{% if seed.multidata %}{{ seed.slots|length }}{% else %}1{% endif %}
</td>
<td>{{ seed.creation_time.strftime("%Y-%m-%d %H:%M") }}</td>
<td><a href="{{ url_for("disown_seed", seed=seed.id) }}">Delete next maintenance.</td>
</tr>
{% endfor %}
</tbody>
Expand Down
17 changes: 12 additions & 5 deletions WebHostLib/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ def get_player_received_items(self, team: int, player: int) -> List[NetworkItem]
@_cache_results
def get_player_inventory_counts(self, team: int, player: int) -> collections.Counter:
"""Retrieves a dictionary of all items received by their id and their received count."""
items = self.get_player_received_items(team, player)
received_items = self.get_player_received_items(team, player)
starting_items = self.get_player_starting_inventory(team, player)
inventory = collections.Counter()
for item in items:
for item in received_items:
inventory[item.item] += 1
for item in starting_items:
inventory[item] += 1

return inventory

Expand Down Expand Up @@ -358,10 +361,13 @@ def get_enabled_multiworld_trackers(room: Room) -> Dict[str, Callable]:
def render_generic_tracker(tracker_data: TrackerData, team: int, player: int) -> str:
game = tracker_data.get_player_game(team, player)

# Add received index to all received items, excluding starting inventory.
received_items_in_order = {}
for received_index, network_item in enumerate(tracker_data.get_player_received_items(team, player), start=1):
received_items_in_order[network_item.item] = received_index
starting_inventory = tracker_data.get_player_starting_inventory(team, player)
for index, item in enumerate(starting_inventory):
received_items_in_order[item] = index
for index, network_item in enumerate(tracker_data.get_player_received_items(team, player),
start=len(starting_inventory)):
received_items_in_order[network_item.item] = index

return render_template(
template_name_or_list="genericTracker.html",
Expand Down Expand Up @@ -1674,6 +1680,7 @@ def render_Starcraft2_tracker(tracker_data: TrackerData, team: int, player: int)
"Resource Efficiency (Spectre)": github_icon_base_url + "blizzard/btn-ability-hornerhan-salvagebonus.png",
"Juggernaut Plating (HERC)": organics_icon_base_url + "JuggernautPlating.png",
"Kinetic Foam (HERC)": organics_icon_base_url + "KineticFoam.png",
"Resource Efficiency (HERC)": github_icon_base_url + "blizzard/btn-ability-hornerhan-salvagebonus.png",

"Hellion": "https://static.wikia.nocookie.net/starcraft/images/5/56/Hellion_SC2_Icon1.jpg",
"Vulture": github_icon_base_url + "blizzard/btn-unit-terran-vulture.png",
Expand Down
Loading

0 comments on commit c360f38

Please sign in to comment.