Garrison on by default, active since last threat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-11-10 17:49:44 +00:00
parent 6697545ba0
commit 5809be59de
4 changed files with 63 additions and 28 deletions

43
game.py
View file

@ -1720,7 +1720,7 @@ RAID_TRAITS = ["lightly armoured, heavy on archers", "mounted and fast, few bows
# --- world ---------------------------------------------------------------
WORLD_VERSION = 44
WORLD_VERSION = 45
HOME_CITY = "guildhall"
CITY_KEYS = ("events", "next_event_at", "next_minor_at", "next_hardship_at", "next_fortune_at", "caravan", "orders")
TRAVEL_TIME = 12 * 60 # game seconds on the road between two towns
@ -2137,6 +2137,11 @@ def migrate(world: dict, now: float | None = None) -> World:
city["buildings"].setdefault("outworks", {"level": 0, "damaged": False, "fund": {}, "fittings": []})
city["works_base"] = city["repelled"]
world["version"] = 44
if world["version"] < 45:
# Everyone stands guard unless they step down.
for player in world["players"].values():
player["garrison"] = True
world["version"] = 45
return world
@ -2473,7 +2478,7 @@ def new_player(uid: str, name: str, cls: str, now: float) -> dict:
"last_active": now, "overflow": "city", "bury": True,
"perks": {"bank_slot": 0}, "manual": [], "patterns": [], "found": [], "eat_below": EAT_BELOW,
"rented": 0, "boosts": [], "bought": None, "deeds": {}, "owned": [], "look": dict(DEFAULT_LOOK),
"garrison": False,
"garrison": True, # stands guard wherever they are, see on_guard()
"at": HOME_CITY, "banks": {}, "travel": None, # banks: what you left in the towns you're not in
"town_favour": {}, # likewise your favour: `favour` is what you hold in the town you're in
"town_slots": {}, # bank slots bought with favour, each good only in its town
@ -4638,12 +4643,24 @@ def donate(world: dict, player: dict, item: str, qty: int, now: float) -> str |
return None
def stand_guard(world: World, player: dict, join: bool, now: float) -> str | None:
"""Join or leave this town's garrison. Whoever wasn't here when the gates closed stays out."""
def _shut_out(world: World, player: dict) -> bool:
"""Whoever wasn't here when the gates closed stays out of this threat."""
raid = upcoming_raid(world)
if join and not raid:
return "There's no raid to stand guard for"
if join and player.get("arrived", 0) > raid["fire_at"] - GATES_WARNING / speed(world):
return bool(raid) and player.get("arrived", 0) > raid["fire_at"] - GATES_WARNING / speed(world)
def on_guard(world: World, player: dict) -> bool:
"""Standing guard is the default and follows you around; you only count where you stand,
and only if you've been around since the last threat."""
if not player["garrison"] or player["at"] != world.here or player["travel"] or _shut_out(world, player):
return False
last = last_threat(world)
return not last or player["last_active"] >= last["resolved"]
def stand_guard(world: World, player: dict, join: bool, now: float) -> str | None:
"""Step down from the garrison, or back into it."""
if join and _shut_out(world, player):
return "The gates have closed"
player["garrison"] = bool(join)
return None
@ -4651,7 +4668,7 @@ def stand_guard(world: World, player: dict, join: bool, now: float) -> str | Non
def travel(world: World, player: dict, to: str, pouch: dict, now: float) -> str | None:
"""Set off for another town with what fits in a pouch. Work waits until you arrive,
but a shared fight or a work order stays behind, and so does your place in the garrison."""
but a shared fight or a work order stays behind."""
if to not in world.doc["cities"]:
return "No such town"
if to == player["at"]:
@ -4666,7 +4683,6 @@ def travel(world: World, player: dict, to: str, pouch: dict, now: float) -> str
current = player["action"]
if current and (current.get("party") or "order" in current):
drop_out(world, player, now, "Left for another town")
player["garrison"] = False
for item, qty in pouch.items():
bank_take(player, item, qty)
player["travel"] = {"from": player["at"], "to": to, "left": now, "arrive": now + TRAVEL_TIME / speed(world), "pouch": pouch}
@ -5013,7 +5029,6 @@ def depart_caravan(world: World, player: dict, convoy_id, now: float) -> str | N
current = member["action"]
if current and (current.get("party") or "order" in current):
drop_out(source, member, now, "Left with a caravan")
member["garrison"] = False
member["travel"] = {"from": convoy["from"], "to": convoy["to"], "left": now, "arrive": arrive, "pouch": {}, "convoy": convoy["id"]}
fullness = _convoy_load(convoy) / (route["load"] * len(convoy["crew"]))
convoy.update(status="road", left=now, arrive=arrive, midway=now + route["time"] / 2, odds=route["odds"] * fullness, rolled=False)
@ -5688,7 +5703,7 @@ def defence(world: dict, guards: int | None = None, dragon: bool = False) -> dic
parts["reinforcements"] = round(sum(march_power(march) for march in helping), 1)
garrison = []
for player in world["players"].values():
if player["garrison"] and player["at"] == world.here:
if on_guard(world, player):
power = combat_power(player)
garrison.append({"id": player["id"], "name": player["name"], "power": round(power, 1)})
parts["garrison"] += power
@ -6317,9 +6332,6 @@ def _resolve_raid(world: dict, event: dict, now: float, rng: random.Random) -> N
report["lines"] = lines
event["report"] = report
_pay_guards(world, report)
for player in world["players"].values():
if player["at"] == world.here:
player["garrison"] = False
city["rally"] = city["rallies"] = 0
city["devotion"] = 0
city["hired"] = 0
@ -6383,9 +6395,6 @@ def _resolve_dragon(world: dict, event: dict, now: float, rng: random.Random) ->
report["lines"] = lines
event["report"] = report
_pay_guards(world, report)
for player in world["players"].values():
if player["at"] == world.here:
player["garrison"] = False
city["rally"] = city["rallies"] = 0
city["devotion"] = 0
city["hired"] = 0