Files
Battle-for-Tismo/tests/trade_route_test.js
T
adrien 71dad18e8d Let central banks work their reserves and cleared the landlocked famines
Central banks now redeem the national money foreign banks hold, sell reserves to defend a weak rate, and cover part of strategic imports from reserves. Five repeatable technologies raise each commodity's output per unit of energy. Hostile troops on a road or sea lane sever trade, power and unit supply. Middlemen buy food to resell to neighbours at a markup, and starving regions buy before those topping up their buffers, which clears the landlocked famines. The economic map's trade graph gains a colour legend.
2026-09-22 15:28:11 +02:00

56 lines
2.1 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { smallState, cityOf } from "./framework/helpers.js";
import { key } from "../shared/hex.js";
// Puts a food-holding producer on an adjacent owned land tile and wires the road,
// so it is a reachable supplier for the city.
function placeSupplier(state, city) {
const neighbour = state.topology.neighbours(city.coords.x, city.coords.y)
.find((n) => state._isLand(n) && state.civAt(n) === city.civ);
const k = key(neighbour.x, neighbour.y);
if (!state.roads.has(k) && !state.railways.has(k)) state.roads.add(k);
state.tileImprovements.set(k, "steel_mill");
state.tileImprovementOwner.set(k, city.civ);
state.tileImprovementHp.set(k, 1000);
state._ensureResourceStock(k).food = 1_000_000;
state._ensureBuildingAgent(k);
return { coords: neighbour, k };
}
function hasSupplierAt(result, coords) {
return result.some((entry) => entry.coords.x === coords.x && entry.coords.y === coords.y);
}
export class TradeRouteTest extends TestCase {
test_a_hostile_unit_cuts_a_trade_route() {
const state = smallState();
const city = cityOf(state, 0);
const supplier = placeSupplier(state, city);
const nodes = state._resourceNodes();
this.assertTrue(
hasSupplierAt(state._nearbySuppliers(city, "food", nodes), supplier.coords),
"the supplier is reachable while the road is clear"
);
// A hostile army standing on the road closes it.
state._declareWar(0, 1);
state._spawnUnit(supplier.coords, 1, state.protoUnits[0]);
this.assertFalse(
hasSupplierAt(state._nearbySuppliers(city, "food", nodes), supplier.coords),
"the hostile unit cut the route"
);
}
test_a_neutral_unit_leaves_the_route_open() {
const state = smallState();
const city = cityOf(state, 0);
const supplier = placeSupplier(state, city);
// No war: the same troops are neutral traffic.
state._spawnUnit(supplier.coords, 1, state.protoUnits[0]);
const nodes = state._resourceNodes();
this.assertTrue(
hasSupplierAt(state._nearbySuppliers(city, "food", nodes), supplier.coords),
"neutral troops do not cut the route"
);
}
}