← Back to the gamebug or idea?Terrapin Trail//Code BibleIIhow the game works, archive to van
Reel 08 · 6 min read

Money, fuel, and upgrades

The numbers you manage, their limits, and how buying van parts quietly changes those limits.

The game asks you to juggle numbers: money, fuel, food, van health, morale, tapes, and reputation. Some of those have a ceiling you can't go over — and, cleverly, buying upgrades can raise the ceiling. This chapter is about how the game manages those limits.

Concept: a "cap" (limit). A cap is a maximum. Your fuel tank only holds so much; pouring in more than fits is wasted. The game gives fuel, food, van health, and morale each a cap.

The starting caps are written down as a fixed set of numbers:

var BASE_CAP = { gas: 20, grub: 40, van: 100, vibes: 100 };   // the starting limits
var CAP      = { gas: 20, grub: 40, van: 100, vibes: 100 };   // the CURRENT limits (can change!)

Notice there are two: the starting limits, and the current limits. Why two? Because upgrades can change the current ones.

Upgrades that quietly raise your limits

Some van parts increase a cap — a bigger fuel tank lets you carry more gas. When you install or remove parts, the game recalculates all your bonuses and resets the current limits:

●assets/game/game.js : 1123–1136trace ↗
1123  function recomputeBuffs(s) {
1124    var b = { gasCap: 0, grubCap: 0, wearReduce: 0, showVibes: 0, bustGuard: 0, tapeQuality: 0, roadLuck: 0 };
1125    s.vanmods = s.vanmods || {};
1126    Object.keys(s.vanmods).forEach(function (slot) {
1127      var pid = s.vanmods[slot];
1128      var part = pid && VAN_PARTS.filter(function (p) { return p.id === pid; })[0];
1129      if (part) part.buff(b);
1130    });
1131    s.buff = b;
1132    CAP.gas = BASE_CAP.gas + b.gasCap;
1133    CAP.grub = BASE_CAP.grub + b.grubCap;
1134    // Clamp current gas/grub down if a part was removed and lowered the cap.
1135    if (s.gas > CAP.gas) s.gas = CAP.gas;
1136    if (s.grub > CAP.grub) s.grub = CAP.grub;
Recalculate bonuses from your installed parts, then set the current fuel/food limits to the starting limits plus those bonuses. If a limit dropped, trim what you're carrying to fit.

You don't need the details. The important idea: the current limits are calculated from your upgrades, so they must be recalculated whenever your upgrades change.

Concept: "derived" values. Some numbers aren't stored directly — they're worked out from other things. Your fuel limit is derived from "base limit + tank upgrade." Derived values are powerful but come with a rule: whenever the inputs change, you must recalculate the result, or it goes stale.

The gotcha the developers had to remember

This is the single trickiest thing in the whole game, and it's a great lesson: because the current limits are derived from your upgrades, they can go stale. Two moments especially:

  • When you add or remove a van part (handled above).
  • When you load a saved game — the save remembers your parts, but not the calculated limits, so the game has to recalculate them right after loading (we'll see that in How the game remembers).

Forget to recalculate, and you'd load a game with the wrong fuel limit. Bugs like this — where a stored answer and its inputs drift apart — are extremely common in real software, which is why spotting "derived values" is a genuinely useful skill.

The ideas to keep
  • A cap is a maximum; fuel, food, van health, and morale each have one.
  • Upgrades change your current caps, which are derived from your parts — so they're recalculated whenever parts change.
  • Derived values going stale (e.g. after loading a save) is a classic bug source; the game guards against it deliberately.