Council sells useless stockpile items into the treasury
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b82f979b4c
commit
656693cc84
2 changed files with 31 additions and 1 deletions
21
game.py
21
game.py
|
|
@ -379,7 +379,7 @@ RAID_TRAITS = ["lightly armoured, heavy on archers", "mounted and fast, few bows
|
|||
|
||||
# --- world ---------------------------------------------------------------
|
||||
|
||||
WORLD_VERSION = 3
|
||||
WORLD_VERSION = 4
|
||||
|
||||
|
||||
def new_world(now: float, speed: float = 1.0) -> dict:
|
||||
|
|
@ -429,9 +429,28 @@ def migrate(world: dict) -> dict:
|
|||
player.setdefault("hp", max_hp(player))
|
||||
player.setdefault("hp_at", now)
|
||||
world["version"] = 3
|
||||
if world["version"] < 4:
|
||||
_sell_useless_stock(world, world["city"]["last_tick"])
|
||||
world["version"] = 4
|
||||
return world
|
||||
|
||||
|
||||
def _sell_useless_stock(world: dict, now: float) -> None:
|
||||
"""The council sells what the city can't use, into the treasury."""
|
||||
city = world["city"]
|
||||
sold = {item: qty for item, qty in city["stockpile"].items() if item in ITEMS and not city_uses(item)}
|
||||
if not sold:
|
||||
return
|
||||
gold = sum(qty * ITEMS[item]["value"] for item, qty in sold.items())
|
||||
for item in sold:
|
||||
del city["stockpile"][item]
|
||||
city["treasury"] += gold
|
||||
names = [amount(i, q) for i, q in sold.items()]
|
||||
names = ", ".join(names[:-1]) + " and " + names[-1] if len(names) > 1 else names[0]
|
||||
log(world, now, "city", f"The council sold {names} "
|
||||
f"from the stockpile for {gold:,} gold")
|
||||
|
||||
|
||||
def speed(world: dict) -> float:
|
||||
return world["config"]["speed"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue