Caravans: crewed wagons, town stock by vote, roads, ambushes; war table shows all scouted threats and march impact
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a4c9977e5c
commit
3486897630
6 changed files with 724 additions and 24 deletions
|
|
@ -4126,6 +4126,261 @@ class KingdomTest(unittest.TestCase):
|
|||
game._loot_banks(new, {"slot": 5}, 0.4, T0)
|
||||
self.assertEqual(self.a["bank"]["stone"], 900)
|
||||
|
||||
def caravan(self, new, goods=None, freight=(), now=T0):
|
||||
self.assertIsNone(game.form_caravan(self.world, self.a, new.here, goods or {}, list(freight), now))
|
||||
return self.world["convoys"][-1]
|
||||
|
||||
def raid_on(self, world, strength=1000.0, at=T0 + 10**6):
|
||||
raid = {"id": 900 + len(world["events"]), "kind": "raid", "status": "upcoming", "fire_at": at, "slot": at, "strength": strength,
|
||||
"sabotage": 0.0, "recon": 0, "jitter": 0, "group": "the Red Hand", "trait": "x", "announced": T0}
|
||||
world["events"].append(raid)
|
||||
return raid
|
||||
|
||||
def test_a_caravan_carries_your_goods_to_your_bank_there(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 1000}
|
||||
convoy = self.caravan(new, {"stone": 800})
|
||||
self.assertEqual(self.a["bank"]["stone"], 200)
|
||||
self.assertEqual(convoy["status"], "loading")
|
||||
self.assertIsNone(game.depart_caravan(self.world, self.a, convoy["id"], T0))
|
||||
arrive = convoy["arrive"]
|
||||
self.assertEqual(arrive, T0 + game.CARAVAN_TIME)
|
||||
convoy["rolled"] = True
|
||||
game.tick(self.world, arrive, random.Random(1))
|
||||
game.catch_up(self.world, arrive, random.Random(1))
|
||||
self.assertEqual(self.a["at"], new.here)
|
||||
self.assertEqual(self.a["bank"]["stone"], 800)
|
||||
self.assertEqual(self.a["banks"][game.HOME_CITY]["stone"], 200)
|
||||
self.assertEqual(self.world["convoys"], [])
|
||||
|
||||
def test_the_crew_stops_work_on_the_road(self):
|
||||
new = self.found()
|
||||
self.assertIsNone(game.start_action(self.world, self.a, "mine_stone", T0))
|
||||
convoy = self.caravan(new)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
xp = self.a["xp"]["mining"]
|
||||
game.process_player(self.world, self.a, convoy["arrive"] - 1)
|
||||
self.assertEqual(self.a["xp"]["mining"], xp)
|
||||
|
||||
def test_more_crew_means_more_load(self):
|
||||
new = self.found()
|
||||
self.a["bank"], self.b["bank"] = {"stone": 5000}, {"stone": 5000}
|
||||
limit = game.CARAVAN_LOAD
|
||||
self.assertIn("hold", game.form_caravan(self.world, self.a, new.here, {"stone": limit + 1}, [], T0))
|
||||
convoy = self.caravan(new, {"stone": limit})
|
||||
self.assertIn("hold", game.board_caravan(self.world, self.b, convoy["id"], {"stone": limit + 1}, [], T0))
|
||||
self.assertIsNone(game.board_caravan(self.world, self.b, convoy["id"], {"stone": limit}, [], T0))
|
||||
self.assertEqual(convoy["crew"], ["a", "b"])
|
||||
self.assertEqual(game._convoy_load(convoy), 2 * limit)
|
||||
|
||||
def test_road_works_at_either_end_help(self):
|
||||
new = self.found()
|
||||
bare = game.caravan_route(self.world, game.HOME_CITY, new.here)
|
||||
self.world["city"]["buildings"]["roads"]["level"] = 3
|
||||
new["city"]["buildings"]["roads"]["level"] = 1
|
||||
paved = game.caravan_route(self.world, game.HOME_CITY, new.here)
|
||||
self.assertEqual(paved["level"], 4)
|
||||
self.assertAlmostEqual(paved["time"], bare["time"] * 0.6)
|
||||
self.assertEqual(paved["load"], bare["load"] * 2)
|
||||
self.assertAlmostEqual(paved["odds"], bare["odds"] * 0.6)
|
||||
|
||||
def test_roads_dont_speed_up_guards(self):
|
||||
new = self.found()
|
||||
self.garrisoned_home()
|
||||
self.world["city"]["buildings"]["roads"]["level"] = 3
|
||||
march = self.march(new)
|
||||
self.assertEqual(march["arrive"], T0 + game.MARCH_TIME)
|
||||
|
||||
def test_town_stock_needs_the_council(self):
|
||||
new = self.found()
|
||||
self.a["last_active"] = self.b["last_active"] = T0
|
||||
stock = self.world["city"]["stockpile"]
|
||||
self.assertIn("holds", game.propose_freight(self.world, self.a, new.here, "provisions", 10**6, T0))
|
||||
self.assertIsNone(game.propose_freight(self.world, self.a, new.here, "provisions", 100, T0))
|
||||
proposal = self.world["council"][-1]
|
||||
self.assertEqual((proposal["status"], stock["provisions"]), ("open", 300))
|
||||
game.vote_march(self.world, self.b, proposal["id"], True, T0)
|
||||
self.assertEqual((proposal["status"], stock["provisions"]), ("sent", 200))
|
||||
self.assertEqual(self.world["freight"][0]["items"], {"provisions": 100})
|
||||
|
||||
def ship(self, new, qty=100):
|
||||
self.a["last_active"] = self.b["last_active"] = T0
|
||||
game.propose_freight(self.world, self.a, new.here, "provisions", qty, T0)
|
||||
game.vote_march(self.world, self.b, self.world["council"][-1]["id"], True, T0)
|
||||
return self.world["freight"][-1]
|
||||
|
||||
def test_a_caravan_delivers_town_stock_and_earns_its_crew_favour_there(self):
|
||||
new = self.found()
|
||||
shipment = self.ship(new)
|
||||
convoy = self.caravan(new, freight=[shipment["id"]])
|
||||
self.assertEqual(self.world["freight"], [])
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["rolled"] = True
|
||||
before = new["city"]["stockpile"]["provisions"]
|
||||
self.a["favour"] = 0
|
||||
game.tick(self.world, convoy["arrive"], random.Random(1))
|
||||
self.assertEqual(new["city"]["stockpile"]["provisions"], before + 100)
|
||||
game.catch_up(self.world, convoy["arrive"], random.Random(1))
|
||||
self.assertEqual(self.a["favour"], game.ITEMS["provisions"]["value"] * 100 * game.CARRIAGE)
|
||||
|
||||
def test_too_much_freight_leaves_the_rest_waiting(self):
|
||||
new = self.found()
|
||||
self.world["city"]["stockpile"]["provisions"] = game.CARAVAN_LOAD + 500
|
||||
shipment = self.ship(new, game.CARAVAN_LOAD + 500)
|
||||
convoy = self.caravan(new, freight=[shipment["id"]])
|
||||
self.assertEqual(convoy["freight"]["provisions"], game.CARAVAN_LOAD)
|
||||
self.assertEqual(self.world["freight"][0]["items"]["provisions"], 500)
|
||||
|
||||
def test_unclaimed_freight_goes_home(self):
|
||||
new = self.found()
|
||||
self.ship(new)
|
||||
stock = self.world["city"]["stockpile"]
|
||||
game._caravan_road_tick(self.world, T0 + game.FREIGHT_WAIT, random.Random(1))
|
||||
self.assertEqual(stock["provisions"], 300)
|
||||
self.assertEqual(self.world["freight"], [])
|
||||
|
||||
def test_calling_off_a_caravan_gives_it_all_back(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 100}
|
||||
shipment = self.ship(new)
|
||||
convoy = self.caravan(new, {"stone": 50}, [shipment["id"]])
|
||||
self.assertIn("isn't yours", game.cancel_caravan(self.world, self.b, convoy["id"]))
|
||||
self.assertIsNone(game.cancel_caravan(self.world, self.a, convoy["id"]))
|
||||
self.assertEqual(self.a["bank"]["stone"], 100)
|
||||
self.assertEqual(self.world["freight"][0]["items"], {"provisions": 100})
|
||||
|
||||
def test_a_caravan_that_never_leaves_unloads(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": 100}
|
||||
self.caravan(new, {"stone": 100})
|
||||
game.tick(self.world, T0 + game.CARAVAN_WAIT, random.Random(1))
|
||||
self.assertEqual(self.world["convoys"], [])
|
||||
self.assertEqual(self.a["bank"]["stone"], 100)
|
||||
|
||||
def test_who_left_town_stays_behind_with_their_goods(self):
|
||||
new = self.found()
|
||||
self.b["bank"] = {"stone": 100}
|
||||
convoy = self.caravan(new)
|
||||
game.board_caravan(self.world, self.b, convoy["id"], {"stone": 100}, [], T0)
|
||||
self.go(self.b, new.here)
|
||||
self.assertIsNone(game.depart_caravan(self.world, self.a, convoy["id"], T0))
|
||||
self.assertEqual(convoy["crew"], ["a"])
|
||||
self.assertEqual(self.b["banks"].get(game.HOME_CITY, self.b["bank"])["stone"], 100)
|
||||
|
||||
def ambushed(self, new, power, raid, cargo=None):
|
||||
self.a["bank"] = {"stone": 1000}
|
||||
convoy = self.caravan(new, cargo or {})
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["odds"] = 1.0
|
||||
self.a["xp"]["combat"] = power
|
||||
game._ambush(self.world, convoy, T0, random.Random(1))
|
||||
return convoy
|
||||
|
||||
def test_beating_an_ambush_weakens_the_coming_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100.0)
|
||||
convoy = self.ambushed(new, 10**7, raid, {"stone": 1000})
|
||||
self.assertEqual(convoy["ambush"], "won")
|
||||
self.assertEqual(raid["sabotage"], game.AMBUSH_WEAKEN)
|
||||
self.assertEqual(convoy["goods"]["a"]["stone"], 1000)
|
||||
|
||||
def test_losing_an_ambush_costs_cargo_and_feeds_the_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100000.0)
|
||||
convoy = self.ambushed(new, 0, raid, {"stone": 1000})
|
||||
self.assertEqual(convoy["ambush"], "lost")
|
||||
self.assertEqual(convoy["goods"]["a"]["stone"], 700)
|
||||
self.assertEqual(raid["strength"], 102000.0)
|
||||
self.assertEqual(raid["sabotage"], 0.0)
|
||||
|
||||
def test_the_ambush_comes_from_the_bigger_raid(self):
|
||||
new = self.found()
|
||||
small, big = self.raid_on(new, 10.0), self.raid_on(self.world, 1000.0)
|
||||
self.ambushed(new, 10**7, big)
|
||||
self.assertEqual((small["sabotage"], big["sabotage"]), (0.0, game.AMBUSH_WEAKEN))
|
||||
|
||||
def test_an_empty_wagon_isnt_worth_robbing(self):
|
||||
new = self.found()
|
||||
self.raid_on(self.world, 1000.0)
|
||||
convoy = self.caravan(new)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
self.assertEqual(convoy["odds"], 0.0)
|
||||
|
||||
def test_fuller_wagons_draw_more_ambushes(self):
|
||||
new = self.found()
|
||||
self.a["bank"] = {"stone": game.CARAVAN_LOAD}
|
||||
convoy = self.caravan(new, {"stone": game.CARAVAN_LOAD // 2})
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
self.assertAlmostEqual(convoy["odds"], game.AMBUSH_ODDS / 2)
|
||||
|
||||
def test_only_so_many_ambushes_count_for_one_raid(self):
|
||||
new = self.found()
|
||||
raid = self.raid_on(self.world, 100.0)
|
||||
self.a["xp"]["combat"] = 10**7
|
||||
for _ in range(game.AMBUSH_MOST + 3):
|
||||
convoy = {"from": game.HOME_CITY, "to": new.here, "crew": ["a"], "goods": {}, "freight": {}, "odds": 1.0}
|
||||
game._ambush(self.world, convoy, T0, random.Random(1))
|
||||
self.assertAlmostEqual(raid["sabotage"], game.AMBUSH_MOST * game.AMBUSH_WEAKEN)
|
||||
|
||||
def test_no_raid_no_ambush(self):
|
||||
new = self.found()
|
||||
convoy = self.ambushed(new, 0, None, {"stone": 1000})
|
||||
self.assertNotIn("ambush", convoy)
|
||||
|
||||
def test_a_second_crew_member_can_win_an_ambush_one_would_lose(self):
|
||||
new = self.found()
|
||||
for member in (self.a, self.b):
|
||||
member["xp"]["combat"] = game.XP_TABLE[50]
|
||||
solo = game.combat_power(self.a)
|
||||
results = []
|
||||
for crew in (1, 2):
|
||||
raid = self.raid_on(self.world, 1.5 * solo / game.AMBUSH_SHARE)
|
||||
convoy = self.caravan(new)
|
||||
if crew == 2:
|
||||
game.board_caravan(self.world, self.b, convoy["id"], {}, [], T0)
|
||||
game.depart_caravan(self.world, self.a, convoy["id"], T0)
|
||||
convoy["odds"] = 1.0
|
||||
game._ambush(self.world, convoy, T0, random.Random(5))
|
||||
results.append(convoy["ambush"])
|
||||
self.world["events"].remove(raid)
|
||||
self.world["convoys"].remove(convoy)
|
||||
for member in (self.a, self.b):
|
||||
member["travel"] = None
|
||||
self.assertEqual(results, ["lost", "won"])
|
||||
|
||||
def test_the_curve_matches_a_real_march(self):
|
||||
new = self.found()
|
||||
self.garrisoned_home()
|
||||
curve = game.march_curve(self.world)
|
||||
before = game.defence(self.world)["total"]
|
||||
march = self.march(new, 30)
|
||||
self.assertAlmostEqual(curve[30], game.march_power(march), delta=1)
|
||||
self.assertAlmostEqual(before - game.defence(self.world)["total"], curve[30], delta=1)
|
||||
self.assertEqual(curve[0], 0.0)
|
||||
|
||||
def test_the_war_table_shows_scouted_threats_at_their_level(self):
|
||||
new = self.found()
|
||||
game.tick(self.world, T0 + 13 * game.HOUR, random.Random(4))
|
||||
game.tick(self.world, T0 + 13 * game.HOUR + 1, random.Random(4))
|
||||
view = game.kingdom_view(self.world, T0 + 13 * game.HOUR + 1, "a")
|
||||
far = next(c for c in view["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["threat"]["intel"], 0)
|
||||
self.assertNotIn("strength", far["threat"])
|
||||
self.assertNotIn("range", far["threat"])
|
||||
raid = game.upcoming_raid(new)
|
||||
raid["recon"] = 10**6
|
||||
now = raid["fire_at"] - 3600
|
||||
far = next(c for c in game.kingdom_view(self.world, now, "a")["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["threat"]["intel"], 3)
|
||||
self.assertEqual(far["threat"]["strength"], round(raid["strength"]))
|
||||
self.assertIn("group", far["threat"])
|
||||
|
||||
def test_minor_troubles_show_on_the_war_table(self):
|
||||
new = self.found()
|
||||
new["city"]["problems"].append({"kind": "wolves", "work": 0})
|
||||
far = next(c for c in game.kingdom_view(self.world, T0, "a")["cities"] if c["id"] == new.here)
|
||||
self.assertEqual(far["problems"][0]["name"], game.PROBLEMS["wolves"]["name"])
|
||||
|
||||
def test_old_saves_gain_towns(self):
|
||||
doc = json.loads(json.dumps(self.world.doc))
|
||||
doc["version"] = 39
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue