Simplify fare calculation logic by separating length and congestion components for better clarity.

This commit is contained in:
scamiv
2025-11-21 18:30:20 +01:00
parent 66af4715b1
commit e6736e4698
+5 -8
View File
@@ -38,15 +38,12 @@ export class Railroad {
return this.tiles.length;
}
/**
* Dynamic fare based on railroad length and current busyness.
* Longer railroads cost more, but overcrowded edges become less profitable.
* Uses integer math to keep amounts precise.
*/
getFare(): bigint {
const baseFare = BigInt(this.getLength() * 100); // Base fare proportional to length
const busynessFactor = Math.max(1, 10 - this.trainCount); // 10,9,...,1 (capped)
return (baseFare * BigInt(busynessFactor)) / 10n;
const lengthFare = BigInt(this.getLength() * 100); // Base fare proportional to length
// Busy railroads should be more expensive: each train adds a congestion premium
const congestionFactor = BigInt(1 + this.trainCount); // 1,2,3,...
const congestionFare = (lengthFare * congestionFactor) / 10n;
return lengthFare + congestionFare;
}
}