// Open-travel tariff. All amounts are minor units (1 DM = 100). Pure functions, no I/O. // Race world and Lobby are free. Any other world costs 150 DM for the first trip and 10% more // (compounding) for each later paid trip, capped at 5000 DM. The counter resets after 30 days // without a paid trip. A clan or company registered on the destination world halves the fare. // The bounty placed on an unsanctioned arrival is five times the fare actually paid. export const TRAVEL_BASE_MINOR=15000; export const TRAVEL_CAP_MINOR=500000; export const TRAVEL_STEP_PERCENT=10; export const TRAVEL_RESET_MS=30*24*60*60*1000; export const BOUNTY_MULTIPLIER=5; export const FREE_WORLDS=Object.freeze(['lobby']); const whole=(value,max)=>Number.isSafeInteger(value)&&value>=0&&value<=max; /** Fare in minor units for the trip number `trips` (0 = first paid trip), before any reduction. */ export function ladderFare(trips){ if(!whole(trips,1e9))throw RangeError('Invalid trip count'); let fare=TRAVEL_BASE_MINOR; for(let i=0;iMath.ceil(fare/2); /** Fare and bounty for a paid route. `reduced` is true when the traveller has a clan or company on that world. */ export function paidTariff({trips,reduced}){ const base=ladderFare(trips),fare=reduced?reducedFare(base):base; return{fareMinor:fare,bountyMinor:fare*BOUNTY_MULTIPLIER,reduced:!!reduced,trip:trips+1}; } /** * Classifies a destination for a traveller. Free routes carry no fare and no bounty: * Lobby, the traveller's own race world, and a destination covered by an Emperor free-passage decree. */ export function classifyRoute({destination,raceWorld,decree=false}){ if(FREE_WORLDS.includes(destination))return{free:true,reason:'lobby'}; if(destination===raceWorld)return{free:true,reason:'race-world'}; if(decree)return{free:true,reason:'decree'}; return{free:false,reason:'paid'}; }