Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ The screens try to do the arithmetic for you rather than making you do it: each
### Exporting to Other Villages
Gilbert's shop only has so much money each day, so once your crew is landing more fish than the village can absorb, the surplus just piles up. A **Trawler or better** can carry a hold out to neighbouring villages (and a boat dedicated to **hauling** carries half again as much), which have no daily limit at all — choose **Export Fish to Other Villages** at the docks. Three markets are reachable: **Saltmarsh** down the coast (cheap freight, modest prices), **Kestrel Cove** (a real harbour town that pays well for a proper haul), and **Thornhaven**, the far city market, which only a **Fishing Fleet** can reach and which pays double the village rate.

Each market charges more freight for a better price, so which one is worth sailing to depends on how much is in the hold — the menu shows what your current load would fetch at each before you commit. Your boat's hold sets how many fish go per run (a Trawler carries 250, a Fishing Fleet 600), the best fish are loaded first, and anything that doesn't fit waits for the next run. Freight is charged before you sail, so a run can never put you in debt, and the round trip costs you a day — your crew fish, wages come due, and rent falls while you're away.
Each market charges more freight for a better price, so which one is worth sailing to depends on how much is in the hold — the menu shows what your current load would fetch at each before you commit. Your boat's hold sets how many fish go per run (a Trawler carries 250, a Fishing Fleet 600). The run sails on the biggest hold that can put to sea, and that boat also decides which markets are in reach: a boat too damaged to sail stays in port until she's repaired. The best fish are loaded first, and anything that doesn't fit waits for the next run. Freight is charged before you sail, so a run can never put you in debt, and the round trip costs you a day — your crew fish, wages come due, and rent falls while you're away.

### Home Ownership
You start **Homeless** — no home, and a low energy cap to show for it. From the Home menu, choose **Manage Home** to work your way up a housing ladder: Homeless → Rented Room → Driftwood Shack → Cozy Cottage → Sturdy Cabin → Waterfront Manor. Renting a room costs a daily fee (charged automatically each morning — miss a payment and you're evicted back to homeless) but builds no equity, so it's a bridge, not a destination. Buying a home costs money up front but is a real asset: moving to a different owned tier trades your current place in for the target one, so the price is the difference between what you get back for your old home and what the new one costs — moving up costs money, moving down (even back to renting) puts cash back in your pocket. Every rung raises the energy cap you refill to when you sleep, letting you fish longer between rests.
Expand Down
80 changes: 52 additions & 28 deletions src/business/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,76 @@
},
]

def exportCapacity(player):
"""How many fish one run can carry (0 with no boat, or none big enough to
make the crossing).
def holdFor(boat):
"""How many fish this boat carries on an export run, whatever her state.

A hauling boat's hold is fitted for cargo, so it beats a same-sized hull in
any other role - which is the passive half of what dedicating a boat to
hauling buys you."""
capacity = business.tierInfo(boat["tier"]).get("exportCapacity", 0)
if boat["role"] == boats.ROLE_HAULING:
capacity = int(capacity * boats.HAULING_CAPACITY_BONUS)
return capacity

The run goes out on whichever boat carries the most: a hauling boat's hold
is fitted for cargo, so it beats a same-sized hull in any other role - which
is the passive half of what dedicating a boat to hauling buys you."""
best = 0
for boat in player.boats:
capacity = business.tierInfo(boat["tier"]).get("exportCapacity", 0)
if boat["role"] == boats.ROLE_HAULING:
capacity = int(capacity * boats.HAULING_CAPACITY_BONUS)
best = max(best, capacity)
return best

def canSail(boat):
"""Whether this boat can make a crossing at all. The same hull test Take
the Helm uses (Docks.readyToSail), so a boat the docks screen calls too
damaged to sail isn't sent across the water anyway (#279). No crew is
needed - the player sails the run."""
return boats.isSeaworthy(boat) and not boats.isAtSea(boat)


def exportBoat(player):
"""The boat an export run would actually sail on - the one with the biggest
effective hold. None if nothing in the fleet can make the crossing."""
"""The boat an export run would actually sail on - the seaworthy one with
the biggest effective hold. None if nothing in the fleet that could sail
can make the crossing."""
best = None
bestCapacity = 0
for boat in player.boats:
capacity = business.tierInfo(boat["tier"]).get("exportCapacity", 0)
if boat["role"] == boats.ROLE_HAULING:
capacity = int(capacity * boats.HAULING_CAPACITY_BONUS)
if not canSail(boat):
continue
capacity = holdFor(boat)
if capacity > bestCapacity:
best, bestCapacity = boat, capacity
return best


def exportCapacity(player):
"""How many fish one run can carry: the hold of the boat it sails on (0
with no boat, or none both seaworthy and big enough to make the crossing)."""
runner = exportBoat(player)
return holdFor(runner) if runner else 0


def canExport(player):
"""Whether the player's boat can export at all."""
"""Whether the player's fleet can export at all."""
return exportCapacity(player) > 0


def runnerTier(player):
"""The hull tier the run actually sails on, which is what decides how far
it can go - not the fleet's best hull, which may be laid up for repairs.
0 if no boat can make the crossing."""
runner = exportBoat(player)
return runner["tier"] if runner else 0


def availableMarkets(player):
"""The markets the player's fleet can reach, in order."""
if not player.boats:
return []
tier = business.currentTier(player)
"""The markets the boat an export run would sail on can reach, in order."""
tier = runnerTier(player)
return [market for market in EXPORT_MARKETS if market["minBoatTier"] <= tier]


def _hullRefusal(player, minTier):
"""Why no boat can make a crossing that needs minTier: one big enough is
only laid up with damage, or there's none big enough at all."""
for boat in player.boats:
if boat["tier"] >= minTier and not boats.isSeaworthy(boat):
return "boat_too_damaged"
return "boat_too_small"


def buildCargo(player):
"""The fish that would be loaded on the next run: the most valuable species
first, up to what the hold can carry."""
Expand Down Expand Up @@ -130,11 +157,8 @@ def runExport(player, market, stats=None):
"earned": 0.0,
}

if exportCapacity(player) <= 0:
summary["reason"] = "boat_too_small"
return summary
if market["minBoatTier"] > business.currentTier(player):
summary["reason"] = "boat_too_small"
if exportCapacity(player) <= 0 or market["minBoatTier"] > runnerTier(player):
summary["reason"] = _hullRefusal(player, market["minBoatTier"])
return summary
if player.fishCount <= 0:
summary["reason"] = "empty_hold"
Expand Down
9 changes: 9 additions & 0 deletions src/location/docks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,15 @@ def _exportRefusal(self, summary, market):
"Sell a few fish at the shop to cover it, or ship somewhere "
"nearer." % (market["name"], market["shippingCost"], self.player.money)
)
if summary["reason"] == "boat_too_damaged":
return (
"The crossing to %s needs a %s, and yours is too damaged to "
"sail. Repair her under Manage Fleet first."
% (
market["name"],
business.tierInfo(market["minBoatTier"])["name"],
)
)
return "Your boat can't make the crossing to %s. You'd need a %s." % (
market["name"],
business.tierInfo(market["minBoatTier"])["name"],
Expand Down
96 changes: 96 additions & 0 deletions tests/business/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,102 @@ def test_exportBoat_prefers_a_hauling_hold_over_a_same_sized_hull():
)


def test_a_boat_too_damaged_to_sail_cannot_export():
# prepare - the only boat that could make the crossing is laid up (#279)
player = createExporter(tier=3, fish={"Bass": 100})
player.boats[0]["damage"] = 92
farMarket = next(m for m in export.EXPORT_MARKETS if m["minBoatTier"] == 3)

# call
summary = export.runExport(player, farMarket)

# check - the docks call her too damaged to sail, so she doesn't sail
assert boats.isSeaworthy(player.boats[0]) is False
assert export.exportBoat(player) is None
assert export.exportCapacity(player) == 0
assert export.canExport(player) is False
assert export.availableMarkets(player) == []
assert summary["shipped"] is False
assert summary["reason"] == "boat_too_damaged"
assert player.fishCount == 100
assert player.money == 1000


def test_a_boat_just_under_the_damage_threshold_still_exports():
# prepare - the same line Take the Helm draws
player = createExporter(tier=2)
player.boats[0]["damage"] = boats.UNSEAWORTHY_DAMAGE - 1

# check
assert export.exportBoat(player) is player.boats[0]
assert export.canExport(player) is True


def test_a_boat_at_sea_cannot_export():
# prepare - the player has her out as captain
player = createExporter(tier=2)
player.boats[0]["atSea"] = True

# check
assert export.exportBoat(player) is None
assert export.canExport(player) is False


def test_a_damaged_fleet_leaves_the_run_to_a_sound_trawler():
# prepare - a wrecked Fishing Fleet and a sound Trawler
player = createExporter(tier=2, fish={"Bass": 700})
trawler = player.boats[0]
fleet = boats.addBoat(player, 3)
fleet["damage"] = 92
farMarket = next(m for m in export.EXPORT_MARKETS if m["minBoatTier"] == 3)

# call
summary = export.runExport(player, farMarket)

# check - the Trawler's hold and reach, not the laid-up Fleet's
assert export.exportBoat(player) is trawler
assert export.exportCapacity(player) == business.tierInfo(2)["exportCapacity"]
assert farMarket not in export.availableMarkets(player)
assert export.availableMarkets(player)
assert summary["shipped"] is False
assert summary["reason"] == "boat_too_damaged"
assert player.fishCount == 700


def test_holdFor_canSail_and_runnerTier_report_on_the_boat_itself():
# prepare - a hauling Trawler and a laid-up Fishing Fleet
player = createExporter(tier=2)
boats.setRole(player, player.boats[0]["id"], boats.ROLE_HAULING)
hauler = player.boats[0]
fleet = boats.addBoat(player, 3)
fleet["damage"] = 92

# check - holdFor ignores her state, canSail is the hull test, and the
# run's tier is the boat that sails, not the fleet's best hull
assert export.holdFor(hauler) == int(
business.tierInfo(2)["exportCapacity"] * boats.HAULING_CAPACITY_BONUS
)
assert export.holdFor(fleet) == business.tierInfo(3)["exportCapacity"]
assert export.canSail(hauler) is True
assert export.canSail(fleet) is False
assert export.runnerTier(player) == 2
assert export.runnerTier(Player()) == 0


def test_a_damaged_rowboat_beside_a_trawler_is_still_a_small_boat_refusal():
# prepare - nothing big enough for the far market, damaged or not
player = createExporter(tier=2, fish={"Bass": 10})
rowboat = boats.addBoat(player, 1)
rowboat["damage"] = 92
farMarket = next(m for m in export.EXPORT_MARKETS if m["minBoatTier"] == 3)

# call
summary = export.runExport(player, farMarket)

# check
assert summary["reason"] == "boat_too_small"


def test_buildCargo_loads_the_most_valuable_fish_first():
# prepare - more fish than a Trawler's hold can take
capacity = business.tierInfo(2)["exportCapacity"]
Expand Down
50 changes: 50 additions & 0 deletions tests/location/test_docks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,56 @@ def test_exportRefusal_explains_a_boat_that_is_too_small():
assert business.tierInfo(farMarket["minBoatTier"])["name"] in text


def test_exportRefusal_explains_a_boat_that_is_too_damaged():
# prepare - a Fishing Fleet laid up with damage, aimed at the far market
docksInstance = createExportingDocks(tier=3)
docksInstance.player.boats[0]["damage"] = 92
farMarket = next(m for m in export.EXPORT_MARKETS if m["minBoatTier"] == 3)

# call
docksInstance._runExport(farMarket)

# check - points at the repair, not at buying a boat she already is (#279)
text = docksInstance.currentPrompt.text
assert farMarket["name"] in text
assert "too damaged to sail" in text
assert "Manage Fleet" in text
assert "You'd need" not in text
assert docksInstance.player.fishCount == 100


def test_run_hides_export_when_the_only_crossing_boat_is_too_damaged():
# prepare - the docks screen already calls her too damaged to sail
docksInstance = createExportingDocks(tier=2)
docksInstance.player.boats[0]["damage"] = 92
docksInstance.userInterface.showOptions = MagicMock(
side_effect=dockChooser("Go Home")
)

# call
docksInstance.run()

# check - so she isn't offered for a crossing either (#279)
options = docksInstance.userInterface.showOptions.call_args[0][1]
assert "Export Fish to Other Villages" not in options


def test_exportStatus_names_the_sound_boat_rather_than_a_damaged_bigger_one():
# prepare - a wrecked Fishing Fleet and a sound Trawler
docksInstance = createExportingDocks(tier=2)
docksInstance.player.boats[0]["name"] = "Gull"
fleet = boats.addBoat(docksInstance.player, 3, name="Leviathan")
fleet["damage"] = 92

# call
status = docksInstance._exportStatus()

# check
capacity = business.tierInfo(2)["exportCapacity"]
assert "Gull can carry %d fish per run" % capacity in status
assert "Leviathan" not in status


def test_exportStatus_describes_the_load():
# prepare - more fish than the hold takes
capacity = business.tierInfo(2)["exportCapacity"]
Expand Down
Loading