From 93d7c87dc70086940c9a1dc13087dd570d741cf7 Mon Sep 17 00:00:00 2001 From: Christopher Hawker Date: Fri, 6 Nov 2026 20:52:48 +1100 Subject: [PATCH 1/2] Move a customer to another path between the same two POPs Alien waves and leased fiber pairs sit on one fiber (b.link), so they move to another working fiber between the same cities, under the rules for selling capacity on it. Circuits have no link of their own, so moving one pins it to a list of cities (b.pin), which routing follows while every link on it is up. When one is down the circuit follows routing, and it comes back by itself. The window lists the most diverse options first, compared by trench. Moves are free and instant, and contracts keep their price. --- CHANGELOG.md | 1 + docs/ARCHITECTURE.md | 2 +- scripts/lib/route-fuzz.js | 4 +- site/i18n/de.js | 24 +++ site/i18n/es.js | 24 +++ site/i18n/fr.js | 24 +++ site/i18n/it.js | 24 +++ site/i18n/pt.js | 24 +++ src/agent/20-commands.js | 9 +- src/game/60-features/37-customer-paths.js | 66 ++++++ src/game/80-simulation/30-compute.js | 2 +- src/game/80-simulation/50-sanitize.js | 2 +- src/game/90-actions/53-customer-paths.js | 13 ++ src/game/90-actions/85-routing-and-routers.js | 2 +- src/game/93-ui/50-city-panel.js | 2 +- src/game/93-ui/70-link-panels.js | 2 +- src/i18n/en.js | 24 +++ tests/customer-paths.test.js | 191 ++++++++++++++++++ 18 files changed, 431 insertions(+), 9 deletions(-) create mode 100644 src/game/60-features/37-customer-paths.js create mode 100644 src/game/90-actions/53-customer-paths.js create mode 100644 tests/customer-paths.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf0969..98ecb9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project are documented here. The project follows - Big networks no longer freeze for a moment at every new game day, above all with a NOC intern on duty. The intern now plans cache boxes, router ports and PNIs for every POP in one pass. On a network of 190 POPs the intern's shift held the page for about a tenth of a second on a computer and half a second on a phone; it now takes a few thousandths, and a whole day holds the page a quarter as long. The game plays exactly as before. - A low-latency boutique with a lot of its own fiber no longer stalls every day while it times its finance routes. On a big fiber network that check held the page for about a third of a second and now takes a few hundredths; checking customers who want a path without subsea or under a latency limit got quicker too. The game plays exactly as before. - The NOC intern no longer holds a big network for more than half a second each time it weighs taking out a spare wave. Before it decides, it checks every customer promised diverse paths, no subsea or a latency limit, and on a network of 390 POPs that check now takes a few hundredths of a second. Spotting new sovereign cloud and trading offers is about ten times quicker too, and the game plays exactly as before. +- You can now move a customer to another path between the same two POPs, with the most diverse options listed first. Alien waves and leased fiber pairs move to another fiber, and circuits can be pinned to a path of your choice, falling back to normal routing while a link on it is down. ## [3.2.0] — 2026-11-07 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 65247b3..2724f6f 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -31,7 +31,7 @@ hoisted across files, and top-level statements run in path order. Find code by n | `30-networks/` | Other ASes (`NETS`), rival exchanges (`XIX`), the long tail, traffic shares (`NSH`) | | `40-progress/` | Customer types (`BIZ_T`), `LEVELS` and their requirements, `GOALS`; the per-save ruleset (`S.rules`, `rule()`, `PRESETS`, `chaosMul()`, `leadDays()`) | | `50-state.js` | The globals `S`, `R`, `UI`; `emptyR()` | -| `60-features/` | Banks and loans, scenarios and the weekly challenge, puzzles and the published weekly puzzle, conferences, the tutorial, traceroute, the share card, `newGame()`, the offer trial (`autoOffer()`), standing orders (`S.ops`, `opsDay()`, run from `dayTick()`), the sales desk (`S.sales`, `salesDay()`, `salesShape()` on new offers, orbit ones through `pieSlShape()`; signing for you: `S.slAuto`, `slAutoDay()`; renewal haggles: `S.slAuto.ren`, `slRenDay()`) | +| `60-features/` | Moving a customer to another path (`37-customer-paths.js`), banks and loans, scenarios and the weekly challenge, puzzles and the published weekly puzzle, conferences, the tutorial, traceroute, the share card, `newGame()`, the offer trial (`autoOffer()`), standing orders (`S.ops`, `opsDay()`, run from `dayTick()`), the sales desk (`S.sales`, `salesDay()`, `salesShape()` on new offers, orbit ones through `pieSlShape()`; signing for you: `S.slAuto`, `slAutoDay()`; renewal haggles: `S.slAuto.ren`, `slRenDay()`) | | `70-rules/` | Formatting helpers and market rules: exchanges, PNIs, the peering desk (requests answered by policy), peering policy and snubs, DE-KICKS, sold-out routes, hot ports and the Tier 1/2/3 rank | | `80-simulation/` | Dijkstra, RouteScript, where a DDoS flood goes (`ddosLoad()`/`ddosAfter()`, called by `compute()`), `compute()`, monthly prices, `sanitize()`/`migrate()`, customer requirements, events, the customer lifecycle (contracts, renewals, the bandwidth market, why customers leave), geography pricing and latency, second sites and service | | `85-incidents/` | `addInc()`, DDoS attacks (targets, sizes, scoring, the NOC card) and scrubbing, `failureRun()`/`fireFailure()`, `clearInc()`, `fireEvent()`, the chaos monkey, cable ships (`50-cable-ships.js`: a subsea cut sends a club ship from its port along the cable routes; voyages in `S.fleet`, drawn by `96-map/88-cable-ships.js`) | diff --git a/scripts/lib/route-fuzz.js b/scripts/lib/route-fuzz.js index 283b41c..1c2a064 100644 --- a/scripts/lib/route-fuzz.js +++ b/scripts/lib/route-fuzz.js @@ -55,8 +55,8 @@ const TABS = ['cust', 'up', 'peer', 'links']; const LEFT = ['nets', 'noc', 'deals', 'goals']; const PRESETS = ['freeze', 'oncall', 'bgp']; // How often a button is pressed against the others on screen: what changes the network often, looking around rarely. -const BUILD = /^(buy\w*|pni\w*All|pni|peer|peerAll|unpeer|cache|cacheSite|rmCache|buildLink|buildPop|launchBB|accept|decline|dropBiz|takeLoan|repayLoan|lag[TPI]x?|setPref|setCarry|setStandby|setMetric|togglePrem|cleanPipe|sacrif|rs|foundIx|myIxUp|addRouter|rmRouter|upRouter|addSite|rmSite|siteSet|decomToggle|rmLink|upLink|addParallel|cancel\w*|upVxc|buyNni|rmNni|buildScrub|scrubUp|rmScrub|addGen|regen|addCh|rmCh|addPair|upSys|spares|layShip|crews|fixInc|seaPackage|subUpgrade|orderCable|orderDf|ownCab|opsHire|opsToggle|opsParam|opsCap|opsPop|opsTpl|opsNewPop|popStdSet|coreSet|teRecipe|dkOptOut|dkStay|utility\w*|listFiber|unlistFiber|leaseSwap|custGo|confGo|confSponsor|seatBuy|charter|cnPrem|applyCn|ad|ddosAuto|pz(Pop|RmPop|Link|AddPar|Tier|RmLink|RtAdd|RtRm|RtModel|Route|Via|Div)|setRoute|route|via|metricSet)$/; -const UIACT = /^(tab|dashTab|leftTab|\w*Sort|\w*Filter|pniGrp|trace\w*|focusCity|findGo|selLink|dashLink|logAll|tailTog|listMore|netFocus|netFilter|meetGo|phoneTab|dashClose|connF|connCity|connNet|connFor|custF|custCity|popGo|popsReg|opsOpen|decomOpen|linkCheck)$/; +const BUILD = /^(buy\w*|pni\w*All|pni|peer|peerAll|unpeer|cache|cacheSite|rmCache|buildLink|buildPop|launchBB|accept|decline|dropBiz|pathMove|pathPin|pathAuto|takeLoan|repayLoan|lag[TPI]x?|setPref|setCarry|setStandby|setMetric|togglePrem|cleanPipe|sacrif|rs|foundIx|myIxUp|addRouter|rmRouter|upRouter|addSite|rmSite|siteSet|decomToggle|rmLink|upLink|addParallel|cancel\w*|upVxc|buyNni|rmNni|buildScrub|scrubUp|rmScrub|addGen|regen|addCh|rmCh|addPair|upSys|spares|layShip|crews|fixInc|seaPackage|subUpgrade|orderCable|orderDf|ownCab|opsHire|opsToggle|opsParam|opsCap|opsPop|opsTpl|opsNewPop|popStdSet|coreSet|teRecipe|dkOptOut|dkStay|utility\w*|listFiber|unlistFiber|leaseSwap|custGo|confGo|confSponsor|seatBuy|charter|cnPrem|applyCn|ad|ddosAuto|pz(Pop|RmPop|Link|AddPar|Tier|RmLink|RtAdd|RtRm|RtModel|Route|Via|Div)|setRoute|route|via|metricSet)$/; +const UIACT = /^(tab|dashTab|leftTab|\w*Sort|\w*Filter|pniGrp|trace\w*|focusCity|findGo|selLink|dashLink|logAll|tailTog|listMore|netFocus|netFilter|meetGo|phoneTab|dashClose|connF|connCity|connNet|connFor|custF|custCity|popGo|popsReg|opsOpen|decomOpen|linkCheck|pathOpen)$/; const DW = { launchBB: 4, accept: 4, buyTransit: 3, pni: 3, buyIx: 3, setPref: 4, cache: 2, peerAll: 2, setCarry: 2, takeLoan: 2 }; const weight = (b) => (BUILD.test(b.act) ? 8 : UIACT.test(b.act) ? 0.3 : 1); diff --git a/site/i18n/de.js b/site/i18n/de.js index a6a5f86..39c300f 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -1759,6 +1759,30 @@ "core.vendor_zoo":"Hersteller-Zoo", "core.your_auto_te_predates_backbones":"Dein Auto-TE wurde installiert, bevor Backbones eine Technik hatten, also läuft es wie immer. Wechselst du das Backbone, gelten die neuen Regeln.", "core.your_backbone_now_runs_lv":"Dein Backbone läuft jetzt mit {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Passen nur {g} von {bw}", +"customer_paths.fully_diverse":"Komplett divers", +"customer_paths.its_spare_pairs_are_taken":"Die freien Paare sind schon vermietet", +"customer_paths.let_routing_choose_again":"Wieder das Routing entscheiden lassen", +"customer_paths.move":"Umziehen", +"customer_paths.move_name":"{name} umziehen", +"customer_paths.move_to_another_path":"Auf einen anderen Pfad umziehen", +"customer_paths.name_follows_routing_again":"{name} folgt wieder dem Routing.", +"customer_paths.name_moved_to_fiber":"{name} ist auf {fiber} umgezogen.", +"customer_paths.name_now_rides_path":"{name} läuft jetzt über {path}.", +"customer_paths.no_other_path":"Zwischen {a} und {b} gibt es gerade keinen anderen funktionierenden Pfad.", +"customer_paths.no_other_working_fiber":"Zwischen {a} und {b} gibt es keine andere funktionierende Glasfaser. Bau eine, dann kannst du diesen Kunden darauf umziehen.", +"customer_paths.not_enough_free_channels":"Zu wenig freie Kanäle: {free} frei, {n} nötig", +"customer_paths.now_on":"Aktuell auf", +"customer_paths.only_your_own_fiber_rents_pairs":"Nur deine eigene Glasfaser kann Paare vermieten", +"customer_paths.over_the_ms_budget":"Über dem Budget von {ms} ms", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Festgelegt auf {path}", +"customer_paths.routing_chooses_this_circuit":"Das Routing wählt den Pfad dieses Circuits zwischen {a} und {b} jeden Tag neu. Ein Umzug legt ihn kostenlos auf den gewählten Pfad fest. Fällt ein Link auf diesem Pfad aus, folgt er dem Routing, bis der Link wieder da ist.", +"customer_paths.same_trench":"Gleicher Graben", +"customer_paths.shares_n_spans":{"one":"Teilt {n} Abschnitt","other":"Teilt {n} Abschnitte"}, +"customer_paths.that_path_is_down":"Dieser Pfad ist down, vorerst folgt er dem Routing", +"customer_paths.this_customer_rides_one_fiber":"Dieser Kunde läuft über eine Glasfaser zwischen {a} und {b}. Der Umzug auf eine andere ist kostenlos und passiert sofort.", "customers.attacks_on_city_are_hauled_to":"Angriffe auf {city} werden zum Scrubbing nach {to} geschleppt: +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Alle, die dich bezahlen, die Zufriedensten zuletzt. Unter 60 % fangen sie an zu meckern, unter 30 % sind sie wütend, und bei 0 % kündigen sie.", "customers.from_unhappy_customers":"von unzufriedenen Kunden", diff --git a/site/i18n/es.js b/site/i18n/es.js index 6c8f123..06a6d27 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -1757,6 +1757,30 @@ "core.vendor_zoo":"Zoológico de fabricantes", "core.your_auto_te_predates_backbones":"Tu Auto-TE se instaló antes de que los backbones tuvieran una tecnología, así que funciona como siempre. Cambiar el backbone pasa a las reglas nuevas.", "core.your_backbone_now_runs_lv":"Tu backbone ahora corre {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Solo caben {g} de {bw}", +"customer_paths.fully_diverse":"Totalmente diversa", +"customer_paths.its_spare_pairs_are_taken":"Sus pares libres ya están alquilados", +"customer_paths.let_routing_choose_again":"Que el enrutamiento vuelva a elegir", +"customer_paths.move":"Mover", +"customer_paths.move_name":"Mover a {name}", +"customer_paths.move_to_another_path":"Mover a otra ruta", +"customer_paths.name_follows_routing_again":"{name} vuelve a seguir el enrutamiento.", +"customer_paths.name_moved_to_fiber":"{name} se ha movido a {fiber}.", +"customer_paths.name_now_rides_path":"{name} ahora va por {path}.", +"customer_paths.no_other_path":"Ahora mismo no hay otra ruta operativa entre {a} y {b}.", +"customer_paths.no_other_working_fiber":"No hay otra fibra operativa entre {a} y {b}. Construye una y podrás mover a este cliente a ella.", +"customer_paths.not_enough_free_channels":"No hay canales libres suficientes: {free} libres, necesita {n}", +"customer_paths.now_on":"Ahora en", +"customer_paths.only_your_own_fiber_rents_pairs":"Solo tu propia fibra puede alquilar pares", +"customer_paths.over_the_ms_budget":"Supera el presupuesto de {ms} ms", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Fijado a {path}", +"customer_paths.routing_chooses_this_circuit":"El enrutamiento elige cada día la ruta de este circuito entre {a} y {b}. Moverlo lo fija a la ruta que elijas, gratis. Mientras un enlace de esa ruta esté caído, seguirá el enrutamiento hasta que vuelva.", +"customer_paths.same_trench":"Misma zanja", +"customer_paths.shares_n_spans":{"one":"Comparte {n} tramo","other":"Comparte {n} tramos"}, +"customer_paths.that_path_is_down":"Esa ruta está caída, así que de momento sigue el enrutamiento", +"customer_paths.this_customer_rides_one_fiber":"Este cliente va por una fibra entre {a} y {b}. Moverlo a otra es gratis e inmediato.", "customers.attacks_on_city_are_hauled_to":"los ataques a {city} se desvían a {to} para depurarlos: +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Todos los que te pagan, los más felices al final. Por debajo del 60 % empiezan a quejarse, por debajo del 30 % están furiosos y al 0 % cancelan.", "customers.from_unhappy_customers":"de clientes descontentos", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 4598446..2d7fb90 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -1757,6 +1757,30 @@ "core.vendor_zoo":"Zoo de constructeurs", "core.your_auto_te_predates_backbones":"Ton Auto-TE a été installé avant que les backbones aient une technologie, il tourne donc comme toujours. Changer de backbone passe aux nouvelles règles.", "core.your_backbone_now_runs_lv":"Ton backbone tourne maintenant en {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Seuls {g} sur {bw} passent", +"customer_paths.fully_diverse":"Totalement diversifié", +"customer_paths.its_spare_pairs_are_taken":"Ses paires libres sont déjà louées", +"customer_paths.let_routing_choose_again":"Laisser le routage choisir à nouveau", +"customer_paths.move":"Déplacer", +"customer_paths.move_name":"Déplacer {name}", +"customer_paths.move_to_another_path":"Déplacer vers un autre chemin", +"customer_paths.name_follows_routing_again":"{name} suit de nouveau le routage.", +"customer_paths.name_moved_to_fiber":"{name} a été déplacé vers {fiber}.", +"customer_paths.name_now_rides_path":"{name} passe maintenant par {path}.", +"customer_paths.no_other_path":"Il n'y a pas d'autre chemin en service entre {a} et {b} pour le moment.", +"customer_paths.no_other_working_fiber":"Il n'y a pas d'autre fibre en service entre {a} et {b}. Construis-en une et tu pourras y déplacer ce client.", +"customer_paths.not_enough_free_channels":"Pas assez de canaux libres : {free} libres, il en faut {n}", +"customer_paths.now_on":"Actuellement sur", +"customer_paths.only_your_own_fiber_rents_pairs":"Seule ta propre fibre peut louer des paires", +"customer_paths.over_the_ms_budget":"Au-delà du budget de {ms} ms", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Épinglé sur {path}", +"customer_paths.routing_chooses_this_circuit":"Le routage choisit chaque jour le chemin de ce circuit entre {a} et {b}. Le déplacer l'épingle gratuitement sur le chemin de ton choix. Tant qu'un lien de ce chemin est coupé, il suit le routage jusqu'au retour du lien.", +"customer_paths.same_trench":"Même tranchée", +"customer_paths.shares_n_spans":{"one":"Partage {n} tronçon","other":"Partage {n} tronçons"}, +"customer_paths.that_path_is_down":"Ce chemin est coupé, il suit donc le routage pour l'instant", +"customer_paths.this_customer_rides_one_fiber":"Ce client passe par une fibre entre {a} et {b}. Le déplacer vers une autre est gratuit et immédiat.", "customers.attacks_on_city_are_hauled_to":"les attaques sur {city} sont acheminées vers {to} pour le scrubbing : +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Tous ceux qui te paient, les plus contents en dernier. Sous 60 % ils commencent à râler, sous 30 % ils sont furieux, et à 0 % ils résilient.", "customers.from_unhappy_customers":"venant des clients mécontents", diff --git a/site/i18n/it.js b/site/i18n/it.js index edb8ab5..5497bfb 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -1757,6 +1757,30 @@ "core.vendor_zoo":"Zoo dei vendor", "core.your_auto_te_predates_backbones":"Il tuo Auto-TE è stato installato prima che i backbone avessero una tecnologia, quindi funziona come ha sempre fatto. Cambiare il backbone passa alle nuove regole.", "core.your_backbone_now_runs_lv":"Il tuo backbone ora gira su {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Ci stanno solo {g} su {bw}", +"customer_paths.fully_diverse":"Totalmente diverso", +"customer_paths.its_spare_pairs_are_taken":"Le sue coppie libere sono già affittate", +"customer_paths.let_routing_choose_again":"Lascia di nuovo scegliere al routing", +"customer_paths.move":"Sposta", +"customer_paths.move_name":"Sposta {name}", +"customer_paths.move_to_another_path":"Sposta su un altro percorso", +"customer_paths.name_follows_routing_again":"{name} segue di nuovo il routing.", +"customer_paths.name_moved_to_fiber":"{name} spostato su {fiber}.", +"customer_paths.name_now_rides_path":"{name} ora passa per {path}.", +"customer_paths.no_other_path":"Al momento non c'è un altro percorso funzionante tra {a} e {b}.", +"customer_paths.no_other_working_fiber":"Non c'è un'altra fibra funzionante tra {a} e {b}. Costruiscine una e potrai spostarci questo cliente.", +"customer_paths.not_enough_free_channels":"Canali liberi insufficienti: {free} liberi, ne servono {n}", +"customer_paths.now_on":"Ora su", +"customer_paths.only_your_own_fiber_rents_pairs":"Solo la tua fibra può affittare coppie", +"customer_paths.over_the_ms_budget":"Oltre il budget di {ms} ms", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Fissato su {path}", +"customer_paths.routing_chooses_this_circuit":"Il routing sceglie ogni giorno il percorso di questo circuito tra {a} e {b}. Spostarlo lo fissa gratis sul percorso che scegli. Finché un link di quel percorso è giù, segue il routing fino al suo ritorno.", +"customer_paths.same_trench":"Stessa trincea", +"customer_paths.shares_n_spans":{"one":"Condivide {n} tratta","other":"Condivide {n} tratte"}, +"customer_paths.that_path_is_down":"Quel percorso è giù, quindi per ora segue il routing", +"customer_paths.this_customer_rides_one_fiber":"Questo cliente passa su una fibra tra {a} e {b}. Spostarlo su un'altra è gratis e immediato.", "customers.attacks_on_city_are_hauled_to":"gli attacchi su {city} vengono portati a {to} per lo scrubbing: +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Tutti quelli che ti pagano, i più contenti in fondo. Sotto il 60% iniziano a brontolare, sotto il 30% sono furiosi, e a 0% disdicono.", "customers.from_unhappy_customers":"dai clienti scontenti", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 08f4586..46bb3fc 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -1757,6 +1757,30 @@ "core.vendor_zoo":"Zoológico de fornecedores", "core.your_auto_te_predates_backbones":"Seu Auto-TE foi instalado antes de os backbones terem uma tecnologia, então ele funciona como sempre. Mudar o backbone passa para as regras novas.", "core.your_backbone_now_runs_lv":"Seu backbone agora roda {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Só cabem {g} de {bw}", +"customer_paths.fully_diverse":"Totalmente diverso", +"customer_paths.its_spare_pairs_are_taken":"Os pares livres já estão alugados", +"customer_paths.let_routing_choose_again":"Deixar o roteamento escolher de novo", +"customer_paths.move":"Mover", +"customer_paths.move_name":"Mover {name}", +"customer_paths.move_to_another_path":"Mover para outro caminho", +"customer_paths.name_follows_routing_again":"{name} volta a seguir o roteamento.", +"customer_paths.name_moved_to_fiber":"{name} movido para {fiber}.", +"customer_paths.name_now_rides_path":"{name} agora passa por {path}.", +"customer_paths.no_other_path":"Agora não há outro caminho funcionando entre {a} e {b}.", +"customer_paths.no_other_working_fiber":"Não há outra fibra funcionando entre {a} e {b}. Construa uma e você poderá mover este cliente para ela.", +"customer_paths.not_enough_free_channels":"Canais livres insuficientes: {free} livres, precisa de {n}", +"customer_paths.now_on":"Agora em", +"customer_paths.only_your_own_fiber_rents_pairs":"Só a sua própria fibra pode alugar pares", +"customer_paths.over_the_ms_budget":"Acima do orçamento de {ms} ms", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Fixado em {path}", +"customer_paths.routing_chooses_this_circuit":"O roteamento escolhe todo dia o caminho deste circuito entre {a} e {b}. Movê-lo o fixa no caminho que você escolher, de graça. Enquanto um link desse caminho estiver fora, ele segue o roteamento até o link voltar.", +"customer_paths.same_trench":"Mesma vala", +"customer_paths.shares_n_spans":{"one":"Compartilha {n} trecho","other":"Compartilha {n} trechos"}, +"customer_paths.that_path_is_down":"Esse caminho está fora, então por enquanto segue o roteamento", +"customer_paths.this_customer_rides_one_fiber":"Este cliente passa por uma fibra entre {a} e {b}. Movê-lo para outra é grátis e imediato.", "customers.attacks_on_city_are_hauled_to":"os ataques em {city} são levados a {to} para scrubbing: +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Todo mundo que te paga, os mais felizes por último. Abaixo de 60% começam a reclamar, abaixo de 30% ficam furiosos, e em 0% cancelam.", "customers.from_unhappy_customers":"de clientes insatisfeitos", diff --git a/src/agent/20-commands.js b/src/agent/20-commands.js index 266cf70..de2324b 100644 --- a/src/agent/20-commands.js +++ b/src/agent/20-commands.js @@ -262,7 +262,13 @@ const API_CMD={ dropBiz:{args:[['id','entityId']],confirm:'double', doc:'Terminate a signed customer. Rejected once an event contract\'s event has started.'}, setRoute:{args:[['id','entityId'],['m','routeMode']],watch:['biz.#id'], - doc:'How a customer\'s traffic is routed: normal follows metrics, fast takes the lowest latency, scenic the quietest links.'}, + doc:'How a customer\'s traffic is routed: normal follows metrics, fast takes the lowest latency, scenic the quietest links. Clears a pinned path.'}, + pathMove:{args:[['id','entityId'],['link','entityId']],watch:['biz.#id'], + doc:'Move a fiber customer (alien wave, dark fiber pair, fiber pairs) to another working fiber between the same two cities. Free. Rejected if that fiber has no room for it.'}, + pathPin:{args:[['id','entityId'],['via','string']],watch:['biz.#id'], + doc:'Pin a circuit to a path: via is its city ids in order, comma-separated, from the customer\'s city to its city2, every hop a working link. Free. While a link on it is down the circuit follows routing.'}, + pathAuto:{args:[['id','entityId']],watch:['biz.#id'], + doc:'Unpin a circuit, so routing chooses its path again.'}, /* ---------- traffic engineering ---------- */ buyTE:{args:[],quote:a=>({setup:TE_COST,monthly:TE_MO,blocked:coreTE()||(S&&S.te)?[]:[tr('core.auto_te_needs_an_rsvp_te_or')]}), doc:'Buy the Auto-TE controller, which spills overflow onto alternate paths. Level 3+, and it needs an RSVP-TE-or-higher backbone.'}, @@ -491,6 +497,7 @@ const API_VIEW={ focusCity:{args:[['city','cityId']],doc:'Select and centre a city.'}, selLink:{args:[['id','entityId']],doc:'Select a link.'}, custGo:{args:[['id','entityId']],doc:'Jump from the dashboard to a customer.'}, + pathOpen:{args:[['id','entityId']],doc:'Open the window listing the other paths a customer can move to: fibers for a fiber customer, routes for a circuit. pathMove and pathPin make the move.'}, listMore:{args:[['k','listPage']],doc:'Show another page of the dashboard list.'}, custF:{args:[['v','string']],doc:'Filter the customers list.'}, custCity:{args:[['v','string']],doc:'Filter the customers list by city.'}, diff --git a/src/game/60-features/37-customer-paths.js b/src/game/60-features/37-customer-paths.js new file mode 100644 index 0000000..8a0510a --- /dev/null +++ b/src/game/60-features/37-customer-paths.js @@ -0,0 +1,66 @@ +/* ---------- moving a customer to another path between the same two POPs ---------- */ +/* Fiber customers (an alien wave, leased pairs) sit on one fiber, b.link, so they move to a parallel one. Circuits have + no link of their own: routing picks their path every day. Moving one pins it to a list of cities, b.pin. While a link + on the pin is down it follows routing, as a protected wave would, and it comes back by itself. */ +const PATH_ALT=3,PATH_FAR=1000; +const pathKind=b=>{const T=BIZ_T[b.type];if(pzOn()||!T||capPend(b)||!b.city2)return '';return T.fiber?(b.link?'fiber':''):T.l2&&!b.sites?'circuit':'';}; +const trenchOf=l=>l.kind==='vxc'?'fab:'+l.prov:(l.trench||l.id); +const pathCity=c=>CITY[c].name,pathStr=p=>p.map(pathCity).join(' → '); +const samePair=(l,a,b)=>(l.a===a&&l.b===b)||(l.a===b&&l.b===a); +const fibLab=l=>tr('customer_paths.fiber_label',{name:l.cname?esc(l.cname):capName(l),km:Math.round(l.km).toLocaleString()}); +// Why this fiber cannot take this customer, in the same terms as the offers for it. +function fiberNo(b,l){if(b.type==='wwave'){const n=b.slots||1,free=freeCh(l);return free>=n?'':tr('customer_paths.not_enough_free_channels',{free:Math.max(0,free),n});} + if(!l.own)return tr('customer_paths.only_your_own_fiber_rents_pairs'); + if(b.type==='dfpair')return pairFree(l)?'':tr('customer_paths.its_spare_pairs_are_taken'); + return S.biz.some(x=>x!==b&&x.link===l.id&&['pairs','capfib','dfpair'].includes(x.type))?tr('customer_paths.its_spare_pairs_are_taken'):'';} +// The working fibers it could go to, those on another trench first. +function fiberTargets(b){const cur=S.links.find(l=>l.id===b.link),t=cur?trenchOf(cur):''; + return S.links.filter(l=>l.kind==='df'&&l.id!==b.link&&samePair(l,b.city,b.city2)&&l.ready<=S.day&&!(l.cut>S.day)&&!(l.eqDown>S.day)) + .map(l=>({l,diverse:trenchOf(l)!==t,no:fiberNo(b,l)})).sort((x,y)=>(y.diverse-x.diverse)||(!!x.no-!!y.no)||x.l.km-y.l.km);} +// The live backbone by city pair, as compute() sees it: every link of a pair is one edge. +function pathEdges(){const E={},N={};for(const l of S.links){if(linkDown(l)||!popUp(l.a)||!popUp(l.b))continue;const k=edgeKey(l);let e=E[k]; + if(!e){e=E[k]={k,a:l.a,b:l.b,w:Infinity,km:Infinity,lat:Infinity,cap:0,load:0,ts:new Set()};(N[l.a]=N[l.a]||[]).push(e);(N[l.b]=N[l.b]||[]).push(e);} + e.w=Math.min(e.w,pairW(k,l.km));e.km=Math.min(e.km,l.km);e.lat=Math.min(e.lat,linkLat(l));e.cap+=capOf(l);e.load+=(R.load&&R.load[l.id])||0;e.ts.add(trenchOf(l));} + return {E,N};} +const hopKey=(a,b)=>a{const o=[];for(let i=1;i!!pathHops(pathEdges(),b.pin); +// Where the circuit runs today. Scenic circuits remember it; the others take the shortest path of their kind. +function pathNow(b,G){if(b.pin&&pathHops(G,b.pin))return b.pin; + const r=R.l2route&&R.l2route[b.id+'>'+b.city+'>'+b.city2];if(r&&r[0]){const p=r[0].ns.slice();if(p[0]!==b.city)p.reverse();if(pathHops(G,p))return p;} + return pathWalk(G,b.city,b.city2,b.route==='fast'?e=>e.lat+0.05:e=>e.w);} +// Paths that avoid what is in use: each one is priced as if every trench already used were nearly unusable, so the next +// one is the most diverse there is, sharing a trench only if there is no way round it. +function circuitTargets(b){const G=pathEdges(),now=pathNow(b,G);if(!now)return {now:null,alts:[]}; + const hops=pathHops(G,now)||[],used=new Set(),seen=new Set([now.join()]),own=new Set(hops.map(e=>e.k)),got=R.l2&&R.l2[b.id]||0,alts=[]; + const nowT=new Set();for(const e of hops)for(const t of e.ts){nowT.add(t);used.add(t);} + for(let i=0;i{for(const t of e.ts)if(used.has(t))return (e.w+1)*PATH_FAR;return e.w+1;});if(!p)break; + const h=pathHops(G,p);for(const e of h)for(const t of e.ts)used.add(t);if(seen.has(p.join()))continue;seen.add(p.join()); + alts.push({p,shared:h.filter(e=>[...e.ts].some(t=>nowT.has(t))).length,km:h.reduce((a,e)=>a+e.km,0),lat:h.reduce((a,e)=>a+e.lat+0.05,0), + room:Math.max(0,Math.min(...h.map(e=>e.cap-e.load+(own.has(e.k)?got:0))))});} + alts.sort((x,y)=>x.shared-y.shared||x.lat-y.lat);return {now,alts};} +// The pin as compute() walks it. Null while a link on it is down, and routing takes over. +function pinRoute(p,edges){const path=[];for(let i=1;iCIDX[x]),share:1};} +// Under a customer in the panels. +function pathCtl(b){if(!pathKind(b))return ''; + const pin=b.pin?`
${tr('customer_paths.pinned_to_path',{path:esc(pathStr(b.pin))})}${pinUp(b)?'':` · ${tr('customer_paths.that_path_is_down')}`}
`:''; + return `${pin}
${btn(tr('customer_paths.move_to_another_path'),'pathOpen',{id:b.id},'ghost sm')}
`;} +function pathModal(b){const a=pathCity(b.city),z=pathCity(b.city2),k=pathKind(b);let h=`

${tr('customer_paths.move_name',{name:esc(b.name)})}

`; + const row=(nm,meta,tag,button)=>`
${nm}${tag?` ${tag}`:''}
${meta?`
${meta}
`:''}
${button}
`; + if(k==='fiber'){const cur=S.links.find(l=>l.id===b.link),T=fiberTargets(b); + h+=`

${tr('customer_paths.this_customer_rides_one_fiber',{a,b:z})}

`; + if(cur)h+=`
${tr('customer_paths.now_on')}${fibLab(cur)}
`; + if(!T.length)h+=`

${tr('customer_paths.no_other_working_fiber',{a,b:z})}

`; + for(const t of T)h+=row(fibLab(t.l),t.no,t.diverse?tr('customer_paths.fully_diverse'):tr('customer_paths.same_trench'),btn(tr('customer_paths.move'),'pathMove',{id:b.id,link:t.l.id},'sm',!!t.no));} + else{const {now,alts}=circuitTargets(b); + h+=`

${tr('customer_paths.routing_chooses_this_circuit',{a,b:z})}

`; + if(now)h+=`
${tr('customer_paths.now_on')}${esc(pathStr(now))}
`; + if(b.pin)h+=`
${btn(tr('customer_paths.let_routing_choose_again'),'pathAuto',{id:b.id},'ghost sm')}
`; + if(!alts.length)h+=`

${tr('customer_paths.no_other_path',{a,b:z})}

`; + for(const t of alts){const warn=[t.room${tr('customer_paths.fits_only_g_of_bw',{g:fmtG(t.room),bw:fmtG(b.bw)})}`:'',b.latMax&&t.lat>b.latMax?`${tr('customer_paths.over_the_ms_budget',{ms:b.latMax})}`:''].filter(Boolean).join(' · '); + h+=row(esc(pathStr(t.p)),tr('customer_paths.path_facts',{km:Math.round(t.km).toLocaleString(),ms:t.lat.toFixed(1)})+(warn?' · '+warn:''),t.shared?trn('customer_paths.shares_n_spans',t.shared):tr('customer_paths.fully_diverse'),btn(tr('customer_paths.move'),'pathPin',{id:b.id,via:t.p.join()},'sm'));}} + openModal(h);} diff --git a/src/game/80-simulation/30-compute.js b/src/game/80-simulation/30-compute.js index 6b28350..9d632c5 100644 --- a/src/game/80-simulation/30-compute.js +++ b/src/game/80-simulation/30-compute.js @@ -146,7 +146,7 @@ function compute(){RW.gen++; if(!seen[b])return null;const path=[];let v=b;while(v!==a){const l=prev[v];path.push(l);v=CIDX[l.a]===v?CIDX[l.b]:CIDX[l.a];}return path;}; const disjointI=(A,B)=>{const a=CIDX[A],b=CIDX[B],p1=bfsI(a,b,null);return !!p1&&!!bfsI(a,b,new Set(p1.map(srlg)));}; for(const k in edges){const e=edges[k];let ld=0;for(const l of e.links)ld+=(R.load&&R.load[l.id])||0;e.pl=ld;} - const l2Routes=(A,B,b)=>{const m=b.route||'normal',Ai=CIDX[A],Bi=CIDX[B]; + const l2Routes=(A,B,b)=>{if(b.pin){const r=pinRoute(b.pin,edges);if(r)return [r];}const m=b.route||'normal',Ai=CIDX[A],Bi=CIDX[B]; if(PX&&m==='fast')return pieFast(PX,fastSP,A,B,b,wLat); if(m!=='scenic')return [{...walkI(m==='fast'?(fastSP[A]||(fastSP[A]=dijkstra(adj,Ai,wLat))).P:SPP[A],Ai,Bi),share:1}]; const ek='l2:'+b.id,own=e=>(R.efg&&R.efg[e.id]&&R.efg[e.id].get(ek))||0; diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 7e33b48..db35e34 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -54,7 +54,7 @@ function sanitize(s){ for(const k of Object.keys(s.peers)){const [n,c]=k.split('@');if(!isNet(n)||!isIx(c))delete s.peers[k];} for(const c of Object.keys(s.myIx)){const m=s.myIx[c];if(!isCity(c)||!m||typeof m!=='object'){delete s.myIx[c];continue;}m.members=Array.isArray(m.members)?m.members.filter(isNet):[];m.name=String(m.name||tr('common.your_ix')).slice(0,40);m.next=num(m.next,s.day);m.fab=int(m.fab,0,MYIX_FAB.length-1,0);} const okBiz=b=>b&&own(BIZ_T,b.type)&&(!BIZ_T[b.type].nni||own(FAB,b.prov))&&isCity(b.city)&&(!b.city2||isCity(b.city2))&&(!b.sites||Array.isArray(b.sites)&&b.sites.every(isCity)); - const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('common.customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';if(b.due!==undefined)b.due=num(b.due,0);if(b.win!==undefined)b.win=num(b.win,180);if(b.live!==undefined)b.live=!!b.live;if(b.link!==undefined&&typeof b.link!=='string')delete b.link;return b;}; + const fixBiz=b=>{b.id=sid(b.id);b.name=String(b.name||tr('common.customer')).slice(0,80);b.bw=num(b.bw,1);b.rate=num(b.rate,0);if(b.fee!==undefined)b.fee=num(b.fee,0);if(b.start!==undefined)b.start=num(b.start,0);if(b.dur!==undefined)b.dur=num(b.dur,1);if(b.slots!==undefined)b.slots=num(b.slots,0);if(b.what!==undefined)b.what=String(b.what).slice(0,200);if(b.broker!==undefined)b.broker=!!b.broker;if(!Array.isArray(b.reqs))b.reqs=[];b.reqs=b.reqs.filter(r=>own(REQS,r));if(b.mood!==undefined)b.mood=num(b.mood,100);if(b.pm!==undefined)b.pm=num(b.pm,b.mood||100);if(b.exp!==undefined)b.exp=num(b.exp,0);if(b.latMax!=null)b.latMax=num(b.latMax,10);if(b.route&&!own(RT,b.route))b.route='normal';if(b.due!==undefined)b.due=num(b.due,0);if(b.win!==undefined)b.win=num(b.win,180);if(b.live!==undefined)b.live=!!b.live;if(b.link!==undefined&&typeof b.link!=='string')delete b.link;if(b.pin!==undefined){const p=b.pin;if(!Array.isArray(p)||p.length<2||p.length>64||!p.every(isCity)||new Set(p).size!==p.length||!BIZ_T[b.type].l2||b.sites||p[0]!==b.city||p[p.length-1]!==b.city2)delete b.pin;}return b;}; {const ids=new Map(s.links.map(l=>[l.id,l]));s.biz=s.biz.filter(okBiz).map(b=>clFix(s,unpackBiz(fixBiz(b),ids)));}s.offers=s.offers.filter(okBiz).map(fixBiz); // Contracts (#178): the bandwidth market an offer was priced in, who referred it, and the month-by-month tally. for(const o of s.offers){if(!(typeof o.mk==='number'&&o.mk>0&&o.mk<=5))delete o.mk;if(typeof o.ref!=='string')delete o.ref;if(o.refN!==undefined)o.refN=String(o.refN).slice(0,80);}clFixState(s);salesFix(s); diff --git a/src/game/90-actions/53-customer-paths.js b/src/game/90-actions/53-customer-paths.js new file mode 100644 index 0000000..c362a64 --- /dev/null +++ b/src/game/90-actions/53-customer-paths.js @@ -0,0 +1,13 @@ +Object.assign(ACT,{ + pathOpen:({id})=>{const b=S.biz.find(x=>x.id===id);if(b&&pathKind(b))pathModal(b);}, + pathMove:({id,link})=>{const b=S.biz.find(x=>x.id===id),l=b&&pathKind(b)==='fiber'&&fiberTargets(b).find(t=>t.l.id===link&&!t.no);if(!l)return; + // A carrier already renting waves on that fiber: one contract, as when it orders more there. + const more=b.type==='wwave'&&S.biz.find(x=>x!==b&&x.type==='wwave'&&x.link===link&&x.name===b.name); + if(more){more.slots=(more.slots||0)+(b.slots||0);more.rate+=b.rate;more.since=Math.min(more.since??0,b.since??0);more.mood=Math.min(more.mood??100,b.mood??100);more.what=wwWhat(l.l,more.slots);S.biz=S.biz.filter(x=>x!==b);} + else{b.link=link;if(b.type==='wwave')b.what=wwWhat(l.l,b.slots||1);} + closeModal();toast(tr('customer_paths.name_moved_to_fiber',{name:esc(b.name),fiber:fibLab(l.l)}),'good');sfx('build');after();}, + pathPin:({id,via})=>{const b=S.biz.find(x=>x.id===id);if(!b||pathKind(b)!=='circuit'||typeof via!=='string')return;const p=via.split(','); + if(p.length<2||p[0]!==b.city||p[p.length-1]!==b.city2||new Set(p).size!==p.length||!pathHops(pathEdges(),p))return; + b.pin=p;closeModal();toast(tr('customer_paths.name_now_rides_path',{name:esc(b.name),path:esc(pathStr(p))}),'good');sfx('build');after();}, + pathAuto:({id})=>{const b=S.biz.find(x=>x.id===id);if(!b||!b.pin)return;delete b.pin;closeModal();toast(tr('customer_paths.name_follows_routing_again',{name:esc(b.name)}),'good');sfx('click');after();}, +}); diff --git a/src/game/90-actions/85-routing-and-routers.js b/src/game/90-actions/85-routing-and-routers.js index 6a6822f..45502f4 100644 --- a/src/game/90-actions/85-routing-and-routers.js +++ b/src/game/90-actions/85-routing-and-routers.js @@ -9,7 +9,7 @@ Object.assign(ACT,{ routingOpen:()=>{if(S&&!pzOn())routingModal();}, coreSet:({v})=>{if(!S.core)return;v=+v;if(!(v>=0&&v<=S.core.lv)||(v===S.core.run&&!S.core.legacy))return;S.core.run=v;delete S.core.legacy;sfx('click');after();}, via:({v})=>{UI.via=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, - setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;sfx('click');after();}}, + setRoute:({id,m})=>{if(!own(RT,m))return;const b=S.biz.find(x=>x.id===id);if(b){b.route=m;delete b.pin;sfx('click');after();}}, route:({r})=>{UI.route=r;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, addParallel:({id})=>{const l=S.links.find(x=>x.id===id);if(l)openLinkModal(l.a,l.b);}, popStdSet:({city})=>{const p=S.pops[city];if(!p||pzOn())return;S.popStd={g:p.rgen||0,rt:p.routers||1};toast(tr('pop_std.new_pops_now_start_with',{n:S.popStd.rt,model:esc(RG[S.popStd.g].n)}),'good');sfx('click');after();}, diff --git a/src/game/93-ui/50-city-panel.js b/src/game/93-ui/50-city-panel.js index ed2eb74..5a89d6a 100644 --- a/src/game/93-ui/50-city-panel.js +++ b/src/game/93-ui/50-city-panel.js @@ -37,7 +37,7 @@ function cityPanel(c){ h+=`

${tr('common.business_customers')}

`; const bz=S.biz.filter(b=>bCities(b).includes(c)); if(!bz.length)h+=`

${tr('city_panel.no_businesses_yet_offers_pop_up')}

`; - for(const b of bz)h+=`
${esc(b.name)}
${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${clTermTxt(b)?' · '+clTermTxt(b):''}${BIZ_T[b.type].l2?` · ${b.sites?tr('city_panel.carrying_g_per_site',{g:fmtG(R.l2[b.id]||0)}):tr('city_panel.carrying_g',{g:fmtG(R.l2[b.id]||0)})}`:''}${BIZ_T[b.type].fiber&&!fiberOk(b)?' · '+tr('city_panel.fiber_is_down')+'':''}${BIZ_T[b.type].event&&eventLive(b)?` · ${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}`:''}${b.type==='scrub'&&!hasScrub()?' · '+tr('common.needs_a_scrubbing_center')+'':''}${S.day-(b.since||0)<15?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${bRisk(b)}${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}
${tr('common.happiness_p',{p:Math.round(b.mood)})}
${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}
`; + for(const b of bz)h+=`
${esc(b.name)}
${esc(BIZ_T[b.type].l)}${b.city2?` ${CITY[b.city].name} ⇄ ${CITY[b.city2].name}`:''} · ${bTerms(b)}${clTermTxt(b)?' · '+clTermTxt(b):''}${BIZ_T[b.type].l2?` · ${b.sites?tr('city_panel.carrying_g_per_site',{g:fmtG(R.l2[b.id]||0)}):tr('city_panel.carrying_g',{g:fmtG(R.l2[b.id]||0)})}`:''}${BIZ_T[b.type].fiber&&!fiberOk(b)?' · '+tr('city_panel.fiber_is_down')+'':''}${BIZ_T[b.type].event&&eventLive(b)?` · ${tr('city_panel.serving_v',{v:pct(sfOf(R,b.city))})}`:''}${b.type==='scrub'&&!hasScrub()?' · '+tr('common.needs_a_scrubbing_center')+'':''}${S.day-(b.since||0)<15?` · ${tr('common.provisioning_n_d_grace',{n:15-(S.day-(b.since||0))})}`:''}
${bRisk(b)}${reqList(b)}${BIZ_T[b.type].l2?routeCtl(b):''}${pathCtl(b)}
${tr('common.happiness_p',{p:Math.round(b.mood)})}
${btn(UI.confirm===b.id?tr('common.really_drop'):tr('common.drop'),'dropBiz',{id:b.id},'ghost sm')}
`; h+=`
`+offersHere(c); }else if(UI.tab==='up'){ h+=portNote(c)+latNote(c); diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js index 44ab4bb..705313a 100644 --- a/src/game/93-ui/70-link-panels.js +++ b/src/game/93-ui/70-link-panels.js @@ -122,7 +122,7 @@ function dfPanel(l){
${tr('common.latency')}${tr('common.ms_ms_one_way',{ms:linkLat(l).toFixed(1)})}
${l.own?tr('link_panels.right_of_way_upkeep'):tr('common.iru_lease')}${tr('common.price_mo',{price:fmt$(l.mo)})}
${tr('link_panels.n_amp_huts',{n:amps})}${tr('common.price_mo',{price:fmt$(amps*AMP_MO)})}
${!bld&&!(l.ch||[]).length?`

${tr('link_panels.this_fiber_is_dark_add_optics')}

`:''}`; if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='mwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l); h+=`

${tr('link_panels.selling_spare_capacity')}

${tr('link_panels.other_carriers_rent_what_you_do')}

-
${tr('common.free_channels')}${fc} / ${chMax(l)}
${sold.map(b=>`
${esc(b.name)}
${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}
`).join('')} +
${tr('common.free_channels')}${fc} / ${chMax(l)}
${sold.map(b=>`
${esc(b.name)}
${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}
${pathCtl(b)}
`).join('')} ${off?`
${esc(off.name)}
${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}
${btn(tr('common.accept'),'accept',{id:off.id},'pink sm')}
`:brListHtml(l,fc)}
`;} h+=`

${tr('common.optics')}

${tr('link_panels.each_channel_is_a_pair_of')}

`; if(l.own&&l.sub&&!l.seat)h+=subUpgradePanel(l); diff --git a/src/i18n/en.js b/src/i18n/en.js index 5323950..3f82fb1 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -1758,6 +1758,30 @@ "core.vendor_zoo":"Vendor zoo", "core.your_auto_te_predates_backbones":"Your Auto-TE was installed before backbones had a technology, so it runs as it always did. Changing the backbone switches to the new rules.", "core.your_backbone_now_runs_lv":"Your backbone now runs {lv}.", +"customer_paths.fiber_label":"{name} · {km} km", +"customer_paths.fits_only_g_of_bw":"Fits only {g} of {bw}", +"customer_paths.fully_diverse":"Fully diverse", +"customer_paths.its_spare_pairs_are_taken":"Its spare pairs are already rented", +"customer_paths.let_routing_choose_again":"Let routing choose again", +"customer_paths.move":"Move", +"customer_paths.move_name":"Move {name}", +"customer_paths.move_to_another_path":"Move to another path", +"customer_paths.name_follows_routing_again":"{name} follows routing again.", +"customer_paths.name_moved_to_fiber":"{name} moved to {fiber}.", +"customer_paths.name_now_rides_path":"{name} now rides {path}.", +"customer_paths.no_other_path":"There is no other working path between {a} and {b} right now.", +"customer_paths.no_other_working_fiber":"There is no other working fiber between {a} and {b}. Build one, and you can move this customer onto it.", +"customer_paths.not_enough_free_channels":"Not enough free channels: {free} free, needs {n}", +"customer_paths.now_on":"Now on", +"customer_paths.only_your_own_fiber_rents_pairs":"Only your own fiber can rent out pairs", +"customer_paths.over_the_ms_budget":"Over the {ms} ms budget", +"customer_paths.path_facts":"{km} km · {ms} ms", +"customer_paths.pinned_to_path":"Pinned to {path}", +"customer_paths.routing_chooses_this_circuit":"Routing chooses this circuit's path between {a} and {b} every day. Moving it pins it to the path you pick, for free. While a link on that path is down, it follows routing until the link is back.", +"customer_paths.same_trench":"Same trench", +"customer_paths.shares_n_spans":{"one":"Shares {n} span","other":"Shares {n} spans"}, +"customer_paths.that_path_is_down":"That path is down, so it follows routing for now", +"customer_paths.this_customer_rides_one_fiber":"This customer rides one fiber between {a} and {b}. Moving it to another one is free and happens at once.", "customers.attacks_on_city_are_hauled_to":"attacks on {city} are hauled to {to} for scrubbing: +{ms} ms", "customers.everyone_who_pays_you_happiest_last":"Everyone who pays you, happiest last. Below 60% they start to grumble, below 30% they are furious, and at 0% they cancel.", "customers.from_unhappy_customers":"from unhappy customers", diff --git a/tests/customer-paths.test.js b/tests/customer-paths.test.js new file mode 100644 index 0000000..2b6c3d2 --- /dev/null +++ b/tests/customer-paths.test.js @@ -0,0 +1,191 @@ +// Moving a customer to another path between the same two POPs: fiber customers to another fiber, circuits by a pin. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); +const { lit } = require('../scripts/lib/js-literal'); + +// New York and Ashburn, with Boston as the way round, for the test's sake. Fiber a is the direct one, on its own trench; +// b runs beside it in the same trench; c is direct on another trench; d and e go through Boston on trenches of their own. +const fib = (id, a, z, km, trench, n = 8) => `S.links.push({id:'${id}',a:'${a}',b:'${z}',kind:'df',own:true,sys:'roadm',pairs:1,ch:Array(${n}).fill('zr4'),km:${km},sub:false,cable:null,mo:1,trench:'${trench}',cut:0,day:0,ready:0,spares:false});`; +const BASE = "ACT.start({});S.cash=1e9;for(const g of GOALS)S.done[g.id]=0;S.lvl=13;S.nextFail=S.nextEvent=1e9;UI.speed=0;S.rules=makeRules('freeze');" + + "for(const c of ['nyc','ash','bos'])if(!S.pops[c])S.pops[c]={day:0,bb:null,boost:0,down:0,routers:4,gen:false,rgen:RG.length-3};S.links=[];" + + fib('a', 'nyc', 'ash', 350, 'ta') + fib('b', 'nyc', 'ash', 350, 'ta') + fib('c', 'ash', 'nyc', 420, 'tc') + fib('d', 'nyc', 'bos', 130, 'td') + fib('e', 'bos', 'ash', 220, 'te'); +const hasCities = (ev) => ev("['nyc','ash','bos'].every(isCity)"); +const wave = "S.biz.push({id:'w',type:'wwave',name:'Zay-No Fiber',city:'nyc',city2:'ash',link:'a',slots:2,bw:1,rate:9000,reqs:[],mood:80,since:0,day:0,route:'normal',what:'x'});"; +const pair = (type, id = 'p', link = 'a') => `S.biz.push({id:'${id}',type:'${type}',name:'A Customer ${id}',city:'nyc',city2:'ash',link:'${link}',slots:0,bw:1,rate:9000,reqs:[],mood:80,since:0,day:0,route:'normal',what:'x'});`; +const circuit = (bw = 100) => `S.biz.push({id:'k',type:'l2vpn',name:'Big Circuit',city:'nyc',city2:'ash',bw:${bw},rate:10,reqs:[],mood:80,since:0,day:0,route:'normal'});`; +function game(t, extra = '') { const h = load({ seed: 777 }); t.after(() => h.dom.window.close()); + h.ev(BASE); assert.equal(hasCities(h.ev), true); h.ev(extra + 'compute();'); return h; } +const biz = (ev, id, k) => ev(`S.biz.find(b=>b.id===${lit(id)}).${k}`); +const modal = (ev) => ev("document.getElementById('modal').textContent"); + +test('a wave moves to another fiber: free, its channels go with it, and the first choice is on another trench', (t) => { + const { ev, errors } = game(t, wave); + const cash = ev('S.cash'); + assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>[x.l.id,x.diverse,x.no]))")), [['c', true, ''], ['b', false, '']]); + assert.equal(ev("soldSlots(S.links.find(l=>l.id==='a'))"), 2); + ev("ACT.pathOpen({id:'w'})"); + assert.match(modal(ev), /Fully diverse/); assert.match(modal(ev), /Same trench/); + ev("ACT.pathMove({id:'w',link:'c'})"); + assert.equal(biz(ev, 'w', 'link'), 'c'); + assert.equal(ev("soldSlots(S.links.find(l=>l.id==='a'))"), 0); + assert.equal(ev("soldSlots(S.links.find(l=>l.id==='c'))"), 2); + assert.equal(ev('S.cash'), cash, 'free'); + assert.equal(biz(ev, 'w', 'rate'), 9000, 'the contract stands'); + assert.equal(ev("document.getElementById('modal').hidden"), true); + assert.deepEqual(errors, []); +}); + +test('a wave needs room on the new fiber; a move is checked again when it is made', (t) => { + const { ev, errors } = game(t, wave + "S.links.find(l=>l.id==='c').ch=Array(63).fill('zr4');"); + const c = JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).find(x=>x.l.id==='c'))")); + assert.match(c.no, /1 free, needs 2/); + ev("ACT.pathMove({id:'w',link:'c'})"); + assert.equal(biz(ev, 'w', 'link'), 'a', 'refused'); + for (const link of ['a', 'd', 'nope']) { ev(`ACT.pathMove({id:'w',link:${lit(link)}})`); assert.equal(biz(ev, 'w', 'link'), 'a', `${link}: not a fiber it can go to`); } + assert.deepEqual(errors, []); +}); + +test('a carrier already renting waves on the new fiber ends up with one contract', (t) => { + const { ev, errors } = game(t, wave + "S.biz.push({id:'w2',type:'wwave',name:'Zay-No Fiber',city:'nyc',city2:'ash',link:'c',slots:3,bw:1,rate:1000,reqs:[],mood:90,since:5,day:0,route:'normal',what:'x'});"); + ev("ACT.pathMove({id:'w',link:'c'})"); + assert.equal(ev("S.biz.filter(b=>b.type==='wwave').length"), 1); + assert.equal(biz(ev, 'w2', 'slots'), 5); assert.equal(biz(ev, 'w2', 'rate'), 10000); assert.equal(biz(ev, 'w2', 'mood'), 80, 'the unhappier of the two'); assert.equal(biz(ev, 'w2', 'since'), 0); + assert.match(biz(ev, 'w2', 'what'), /5/); + assert.deepEqual(errors, []); +}); + +test('fiber pairs follow the same rules as signing them: your own fiber, and pairs still free', (t) => { + for (const type of ['dfpair', 'pairs', 'capfib']) { + const { ev, errors } = game(t, pair(type) + pair('pairs', 'q', 'b') + "S.links.find(l=>l.id==='e').x=1;"); + const T = JSON.parse(ev("JSON.stringify(Object.fromEntries(fiberTargets(S.biz[0]).map(x=>[x.l.id,x.no])))")); + assert.equal(T.c, '', `${type} can go to the free fiber`); + assert.match(T.b, /already rented/, `${type} cannot join a fiber whose pairs are sold`); + ev("ACT.pathMove({id:'p',link:'b'})"); assert.equal(biz(ev, 'p', 'link'), 'a'); + ev("ACT.pathMove({id:'p',link:'c'})"); assert.equal(biz(ev, 'p', 'link'), 'c'); + assert.deepEqual(errors, []); + } + const { ev } = game(t, pair('dfpair') + "S.links.find(l=>l.id==='c').own=false;"); + assert.match(ev("fiberTargets(S.biz[0]).find(x=>x.l.id==='c').no"), /your own fiber/); +}); + +test('only working fibers are offered, and a customer on a cut fiber can be moved off it', (t) => { + const { ev, errors } = game(t, wave + "S.links.find(l=>l.id==='a').cut=S.day+9;S.links.find(l=>l.id==='b').eqDown=S.day+9;" + fib('f', 'nyc', 'ash', 300, 'tf') + "S.links.at(-1).ready=S.day+5;"); + assert.equal(ev("fiberOk(S.biz[0])"), false); + assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>x.l.id))")), ['c']); + ev("ACT.pathMove({id:'w',link:'c'})"); + assert.equal(ev("fiberOk(S.biz[0])"), true); + ev("S.links.find(l=>l.id==='c').ready=S.day+5;"); + assert.deepEqual(JSON.parse(ev("JSON.stringify(fiberTargets(S.biz[0]).map(x=>x.l.id))")), [], 'nothing left'); + ev("ACT.pathOpen({id:'w'})"); + assert.match(modal(ev), /no other working fiber/); + assert.deepEqual(errors, []); +}); + +test('a pinned circuit rides its path, and takes the load off the direct fibers', (t) => { + const { ev, errors } = game(t, circuit(100)); + const cash = ev('S.cash'); + const load = () => JSON.parse(ev("JSON.stringify(Object.fromEntries(['a','b','c','d','e'].map(i=>[i,R.load[i]||0])))")); + const direct = load(); + assert.equal(Math.round(direct.a + direct.b + direct.c), 100, 'by default it takes the direct edge'); + assert.equal(Math.round(direct.d), 0); + const T = JSON.parse(ev("JSON.stringify(circuitTargets(S.biz[0]))")); + assert.deepEqual(T.now, ['nyc', 'ash']); + assert.deepEqual(T.alts.map((x) => x.p), [['nyc', 'bos', 'ash']]); + assert.equal(T.alts[0].shared, 0, 'nothing in common with the direct fibers'); + ev("ACT.pathOpen({id:'k'})"); + assert.match(modal(ev), /Fully diverse/); + ev("ACT.pathPin({id:'k',via:'nyc,bos,ash'})"); + const on = load(); + assert.equal(Math.round(on.a + on.b + on.c), 0); + assert.equal(Math.round(on.d), 100); assert.equal(Math.round(on.e), 100); + assert.equal(ev("R.l2.k"), 100); + assert.ok(ev('R.l2lat.k') > 0); + assert.equal(ev('S.cash'), cash, 'free'); + assert.deepEqual(errors, []); +}); + +test('a pin falls back to routing while a link on it is down, comes back by itself, and can be undone', (t) => { + const { ev, errors } = game(t, circuit(100) + "S.biz[0].pin=['nyc','bos','ash'];"); + assert.equal(ev('Math.round(R.load.d)'), 100); + ev("S.links.find(l=>l.id==='e').cut=S.day+9;compute();"); + assert.equal(ev('Math.round(R.load.d||0)'), 0, 'off the broken path'); + assert.equal(ev('R.l2.k'), 100, 'and the customer keeps its service'); + assert.deepEqual(JSON.parse(ev('JSON.stringify(S.biz[0].pin)')), ['nyc', 'bos', 'ash'], 'the pin is kept'); + assert.equal(ev('pinUp(S.biz[0])'), false); + assert.match(ev('pathCtl(S.biz[0])'), /That path is down/); + ev("S.links.find(l=>l.id==='e').cut=0;compute();"); + assert.equal(ev('Math.round(R.load.d)'), 100, 'back by itself'); + assert.doesNotMatch(ev('pathCtl(S.biz[0])'), /That path is down/); + ev("ACT.pathOpen({id:'k'})"); + assert.match(modal(ev), /Let routing choose again/); + ev("ACT.pathAuto({id:'k'})"); + assert.equal(ev("S.biz[0].pin===undefined"), true); + assert.equal(ev('Math.round(R.load.d||0)'), 0); + assert.deepEqual(errors, []); +}); + +test('choosing a route mode unpins; a bad path is refused; SD-WANs, pending deals and puzzles have no move', (t) => { + const { ev, errors } = game(t, circuit(100)); + for (const via of ['nyc,ash,bos', 'bos,nyc,ash', 'nyc', 'nyc,nowhere,ash', 'nyc,bos,nyc,ash', 'nyc,ash,ash']) { + ev(`ACT.pathPin({id:'k',via:${lit(via)}})`); + assert.equal(ev('S.biz[0].pin===undefined'), true, via); + } + ev("ACT.pathPin({id:'k',via:null})"); ev("ACT.pathPin({id:'k',via:7})"); ev("ACT.pathPin({id:'nope',via:'nyc,ash'})"); + assert.equal(ev('S.biz[0].pin===undefined'), true); + ev("S.links=S.links.filter(l=>l.id!=='e');compute();ACT.pathPin({id:'k',via:'nyc,bos,ash'})"); + assert.equal(ev('S.biz[0].pin===undefined'), true, 'a hop with no link'); + ev("ACT.pathPin({id:'k',via:'nyc,ash'})"); + assert.equal(ev('S.biz[0].pin.length'), 2); + ev("ACT.setRoute({id:'k',m:'fast'})"); + assert.equal(ev('S.biz[0].pin===undefined'), true); + assert.equal(ev("pathKind({type:'mtrain',city:'nyc',city2:'ash',sites:['nyc','ash']})"), ''); + assert.equal(ev("pathKind({type:'capw',city:'nyc',city2:'ash',due:9,live:false})"), '', 'not delivered yet'); + assert.equal(ev("pathKind({type:'capw',city:'nyc',city2:'ash',due:9,live:true})"), 'circuit'); + assert.equal(ev("pathKind({type:'l2vpn',city:'nyc'})"), '', 'no second city'); + assert.equal(ev("pathKind({type:'wwave',city:'nyc',link:'a'})"), '', 'no second city'); + assert.equal(ev("pathKind({type:'wwave',city:'nyc',city2:'ash'})"), '', 'no fiber yet'); + assert.deepEqual(errors, []); +}); + +test('with no way round, the most diverse path shares what it must and says so', (t) => { + // Boston reaches Ashburn only over the direct fibers' trench. + const { ev, errors } = game(t, circuit(100) + "S.links.find(l=>l.id==='e').trench='ta';S.links=S.links.filter(l=>l.id!=='c');"); + const T = JSON.parse(ev('JSON.stringify(circuitTargets(S.biz[0]))')); + assert.deepEqual(T.alts.map((x) => [x.p, x.shared]), [[['nyc', 'bos', 'ash'], 1]]); + ev("ACT.pathOpen({id:'k'})"); + assert.match(modal(ev), /Shares 1 span/); + assert.deepEqual(errors, []); +}); + +test('the window warns when a path is too small or too slow for the customer', (t) => { + const { ev, errors } = game(t, circuit(1e6) + "S.biz[0].latMax=0.1;"); + ev("ACT.pathOpen({id:'k'})"); + assert.match(modal(ev), /Fits only/); + assert.match(modal(ev), /Over the 0.1 ms budget/); + assert.deepEqual(errors, []); +}); + +test('saves: a pin survives a reload, and a bad one is dropped, leaving old saves alone', (t) => { + const { ev, errors } = game(t, circuit(100) + "S.biz[0].pin=['nyc','bos','ash'];"); + const again = (pin) => ev(`(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));s.biz[0].pin=${lit(pin)};return JSON.stringify(migrate(s).biz[0].pin);})()`); + assert.deepEqual(JSON.parse(again(['nyc', 'bos', 'ash'])), ['nyc', 'bos', 'ash']); + for (const bad of ['nyc', [], ['nyc'], ['nyc', 'nowhere', 'ash'], ['bos', 'ash'], ['nyc', 'bos'], ['nyc', 'bos', 'nyc', 'ash'], [1, 2], { a: 1 }]) + assert.equal(again(bad), undefined, JSON.stringify(bad)); + assert.equal(ev("(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));delete s.biz[0].pin;return migrate(s).biz[0].pin===undefined;})()"), true); + // Not a circuit: no pin. + assert.equal(ev("(()=>{const s=JSON.parse(JSON.stringify(packSave(S)));s.biz[0].type='wwave';s.biz[0].pin=['nyc','ash'];return migrate(s).biz[0].pin===undefined;})()"), true); + // A stale pin (a POP on it was closed) does no harm: routing carries the circuit. + ev("delete S.pops.bos;S.links=S.links.filter(l=>l.a!=='bos'&&l.b!=='bos');compute();"); + assert.equal(ev('R.l2.k'), 100); + assert.deepEqual(errors, []); +}); + +test('the buttons are in the panels: under a customer in its city, and on the fiber it rents', (t) => { + const { ev, errors } = game(t, wave + circuit(100)); + ev("UI.tab='cust';UI.sel={type:'city',id:'nyc'};selectCity('nyc');UI.tab='cust';renderPanel();"); + assert.equal(ev("document.querySelectorAll('#panel [data-act=pathOpen]').length"), 2); + ev("selectLink('a');renderPanel();"); + assert.equal(ev("[...document.querySelectorAll('#panel [data-act=pathOpen]')].length"), 1); + assert.deepEqual(errors, []); +}); From 3554e9f700956908266a988b25f91b7315997051 Mon Sep 17 00:00:00 2001 From: Christopher Hawker Date: Mon, 9 Nov 2026 16:45:08 +1100 Subject: [PATCH 2/2] Moving waves checks the room the broker would sell: bandwidth for managed waves, and what is kept back Managed waves need a channel as big as the wave and their bandwidth spare after your own traffic and the share kept back, on leased fiber too. A move bumps CM_V so their capacity follows them, merging needs the same size, and alien waves leave the kept-back channels alone. Pinned customers' badges share one path graph per routing result. --- CHANGELOG.md | 2 +- site/i18n/de.js | 3 ++ site/i18n/es.js | 3 ++ site/i18n/fr.js | 3 ++ site/i18n/it.js | 3 ++ site/i18n/pt.js | 3 ++ src/game/60-features/37-customer-paths.js | 14 ++++-- src/game/90-actions/53-customer-paths.js | 10 ++-- src/i18n/en.js | 3 ++ tests/customer-paths.test.js | 60 +++++++++++++++++++++++ 10 files changed, 96 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ecb9a..c8eadb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ All notable changes to this project are documented here. The project follows - Big networks no longer freeze for a moment at every new game day, above all with a NOC intern on duty. The intern now plans cache boxes, router ports and PNIs for every POP in one pass. On a network of 190 POPs the intern's shift held the page for about a tenth of a second on a computer and half a second on a phone; it now takes a few thousandths, and a whole day holds the page a quarter as long. The game plays exactly as before. - A low-latency boutique with a lot of its own fiber no longer stalls every day while it times its finance routes. On a big fiber network that check held the page for about a third of a second and now takes a few hundredths; checking customers who want a path without subsea or under a latency limit got quicker too. The game plays exactly as before. - The NOC intern no longer holds a big network for more than half a second each time it weighs taking out a spare wave. Before it decides, it checks every customer promised diverse paths, no subsea or a latency limit, and on a network of 390 POPs that check now takes a few hundredths of a second. Spotting new sovereign cloud and trading offers is about ten times quicker too, and the game plays exactly as before. -- You can now move a customer to another path between the same two POPs, with the most diverse options listed first. Alien waves and leased fiber pairs move to another fiber, and circuits can be pinned to a path of your choice, falling back to normal routing while a link on it is down. +- You can now move a customer to another path between the same two POPs, with the most diverse options listed first. Waves and leased fiber pairs move to another fiber with room for them, leaving alone what you keep back for your own traffic, and circuits can be pinned to a path of your choice, falling back to normal routing while a link on it is down. ## [3.2.0] — 2026-11-07 diff --git a/site/i18n/de.js b/site/i18n/de.js index 39c300f..3d0e0a9 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -1770,9 +1770,12 @@ "customer_paths.name_follows_routing_again":"{name} folgt wieder dem Routing.", "customer_paths.name_moved_to_fiber":"{name} ist auf {fiber} umgezogen.", "customer_paths.name_now_rides_path":"{name} läuft jetzt über {path}.", +"customer_paths.needs_a_g_channel":"Braucht einen Kanal mit {g} oder mehr", "customer_paths.no_other_path":"Zwischen {a} und {b} gibt es gerade keinen anderen funktionierenden Pfad.", "customer_paths.no_other_working_fiber":"Zwischen {a} und {b} gibt es keine andere funktionierende Glasfaser. Bau eine, dann kannst du diesen Kunden darauf umziehen.", "customer_paths.not_enough_free_channels":"Zu wenig freie Kanäle: {free} frei, {n} nötig", +"customer_paths.not_enough_spare_capacity":"Zu wenig freie Kapazität: {free} übrig nach deinem eigenen Traffic und den {hold} %, die du zurückhältst, {g} nötig", +"customer_paths.not_enough_spare_channels":"Zu wenig freie Kanäle: {free} übrig nach den {hold} %, die du für deinen eigenen Traffic zurückhältst, {n} nötig", "customer_paths.now_on":"Aktuell auf", "customer_paths.only_your_own_fiber_rents_pairs":"Nur deine eigene Glasfaser kann Paare vermieten", "customer_paths.over_the_ms_budget":"Über dem Budget von {ms} ms", diff --git a/site/i18n/es.js b/site/i18n/es.js index 06a6d27..4348512 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -1768,9 +1768,12 @@ "customer_paths.name_follows_routing_again":"{name} vuelve a seguir el enrutamiento.", "customer_paths.name_moved_to_fiber":"{name} se ha movido a {fiber}.", "customer_paths.name_now_rides_path":"{name} ahora va por {path}.", +"customer_paths.needs_a_g_channel":"Necesita un canal iluminado a {g} o más", "customer_paths.no_other_path":"Ahora mismo no hay otra ruta operativa entre {a} y {b}.", "customer_paths.no_other_working_fiber":"No hay otra fibra operativa entre {a} y {b}. Construye una y podrás mover a este cliente a ella.", "customer_paths.not_enough_free_channels":"No hay canales libres suficientes: {free} libres, necesita {n}", +"customer_paths.not_enough_spare_capacity":"No hay capacidad libre suficiente: quedan {free} tras tu propio tráfico y el {hold} % que reservas, necesita {g}", +"customer_paths.not_enough_spare_channels":"No hay canales libres suficientes: quedan {free} tras el {hold} % que reservas para tu propio tráfico, necesita {n}", "customer_paths.now_on":"Ahora en", "customer_paths.only_your_own_fiber_rents_pairs":"Solo tu propia fibra puede alquilar pares", "customer_paths.over_the_ms_budget":"Supera el presupuesto de {ms} ms", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 2d7fb90..a3c7813 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -1768,9 +1768,12 @@ "customer_paths.name_follows_routing_again":"{name} suit de nouveau le routage.", "customer_paths.name_moved_to_fiber":"{name} a été déplacé vers {fiber}.", "customer_paths.name_now_rides_path":"{name} passe maintenant par {path}.", +"customer_paths.needs_a_g_channel":"Il faut un canal allumé à {g} ou plus", "customer_paths.no_other_path":"Il n'y a pas d'autre chemin en service entre {a} et {b} pour le moment.", "customer_paths.no_other_working_fiber":"Il n'y a pas d'autre fibre en service entre {a} et {b}. Construis-en une et tu pourras y déplacer ce client.", "customer_paths.not_enough_free_channels":"Pas assez de canaux libres : {free} libres, il en faut {n}", +"customer_paths.not_enough_spare_capacity":"Pas assez de capacité libre : il reste {free} après ton propre trafic et les {hold} % que tu gardes de côté, il en faut {g}", +"customer_paths.not_enough_spare_channels":"Pas assez de canaux libres : il en reste {free} après les {hold} % que tu gardes pour ton propre trafic, il en faut {n}", "customer_paths.now_on":"Actuellement sur", "customer_paths.only_your_own_fiber_rents_pairs":"Seule ta propre fibre peut louer des paires", "customer_paths.over_the_ms_budget":"Au-delà du budget de {ms} ms", diff --git a/site/i18n/it.js b/site/i18n/it.js index 5497bfb..0c57513 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -1768,9 +1768,12 @@ "customer_paths.name_follows_routing_again":"{name} segue di nuovo il routing.", "customer_paths.name_moved_to_fiber":"{name} spostato su {fiber}.", "customer_paths.name_now_rides_path":"{name} ora passa per {path}.", +"customer_paths.needs_a_g_channel":"Serve un canale acceso a {g} o più", "customer_paths.no_other_path":"Al momento non c'è un altro percorso funzionante tra {a} e {b}.", "customer_paths.no_other_working_fiber":"Non c'è un'altra fibra funzionante tra {a} e {b}. Costruiscine una e potrai spostarci questo cliente.", "customer_paths.not_enough_free_channels":"Canali liberi insufficienti: {free} liberi, ne servono {n}", +"customer_paths.not_enough_spare_capacity":"Capacità libera insufficiente: restano {free} dopo il tuo traffico e il {hold}% che tieni da parte, ne servono {g}", +"customer_paths.not_enough_spare_channels":"Canali liberi insufficienti: ne restano {free} dopo il {hold}% che tieni da parte per il tuo traffico, ne servono {n}", "customer_paths.now_on":"Ora su", "customer_paths.only_your_own_fiber_rents_pairs":"Solo la tua fibra può affittare coppie", "customer_paths.over_the_ms_budget":"Oltre il budget di {ms} ms", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index 46bb3fc..f915c74 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -1768,9 +1768,12 @@ "customer_paths.name_follows_routing_again":"{name} volta a seguir o roteamento.", "customer_paths.name_moved_to_fiber":"{name} movido para {fiber}.", "customer_paths.name_now_rides_path":"{name} agora passa por {path}.", +"customer_paths.needs_a_g_channel":"Precisa de um canal aceso a {g} ou mais", "customer_paths.no_other_path":"Agora não há outro caminho funcionando entre {a} e {b}.", "customer_paths.no_other_working_fiber":"Não há outra fibra funcionando entre {a} e {b}. Construa uma e você poderá mover este cliente para ela.", "customer_paths.not_enough_free_channels":"Canais livres insuficientes: {free} livres, precisa de {n}", +"customer_paths.not_enough_spare_capacity":"Capacidade livre insuficiente: sobram {free} depois do seu próprio tráfego e dos {hold}% que você reserva, precisa de {g}", +"customer_paths.not_enough_spare_channels":"Canais livres insuficientes: sobram {free} depois dos {hold}% que você reserva para o seu próprio tráfego, precisa de {n}", "customer_paths.now_on":"Agora em", "customer_paths.only_your_own_fiber_rents_pairs":"Só a sua própria fibra pode alugar pares", "customer_paths.over_the_ms_budget":"Acima do orçamento de {ms} ms", diff --git a/src/game/60-features/37-customer-paths.js b/src/game/60-features/37-customer-paths.js index 8a0510a..e6eb4ae 100644 --- a/src/game/60-features/37-customer-paths.js +++ b/src/game/60-features/37-customer-paths.js @@ -8,8 +8,13 @@ const trenchOf=l=>l.kind==='vxc'?'fab:'+l.prov:(l.trench||l.id); const pathCity=c=>CITY[c].name,pathStr=p=>p.map(pathCity).join(' → '); const samePair=(l,a,b)=>(l.a===a&&l.b===b)||(l.a===b&&l.b===a); const fibLab=l=>tr('customer_paths.fiber_label',{name:l.cname?esc(l.cname):capName(l),km:Math.round(l.km).toLocaleString()}); -// Why this fiber cannot take this customer, in the same terms as the offers for it. -function fiberNo(b,l){if(b.type==='wwave'){const n=b.slots||1,free=freeCh(l);return free>=n?'':tr('customer_paths.not_enough_free_channels',{free:Math.max(0,free),n});} +// Why this fiber cannot take this customer, in the same terms as the market that sold it: waves only where the broker +// could sell them, after the share kept back for your own traffic. +function fiberNo(b,l){const n=b.slots||1,hold=S.cm.hold; + if(b.type==='wwave'){const free=freeCh(l),spare=cmSpare(l,'spec');return spare>=n?'':free=n*g?'':tr('customer_paths.not_enough_spare_capacity',{free:fmtCap(free),g:fmtCap(n*g),hold});} if(!l.own)return tr('customer_paths.only_your_own_fiber_rents_pairs'); if(b.type==='dfpair')return pairFree(l)?'':tr('customer_paths.its_spare_pairs_are_taken'); return S.biz.some(x=>x!==b&&x.link===l.id&&['pairs','capfib','dfpair'].includes(x.type))?tr('customer_paths.its_spare_pairs_are_taken'):'';} @@ -28,7 +33,10 @@ function pathWalk(G,a,b,cost){const dist={[a]:0},prev={},done=new Set();for(;;){ for(const e of G.N[u]||[]){const v=e.a===u?e.b:e.a,nd=ud+cost(e);if(nd<(dist[v]??Infinity)){dist[v]=nd;prev[v]=u;}}} if(dist[b]===undefined)return null;const p=[b];while(p[0]!==a)p.unshift(prev[p[0]]);return p;} const pathHops=(G,p)=>{const o=[];for(let i=1;i!!pathHops(pathEdges(),b.pin); +// The panels ask for every pinned customer: one graph per routing (a new R), not one per customer. +let PIN_G=null; +const pinG=()=>{const c=PIN_G;if(!c||c.R!==R||c.S!==S||c.d!==S.day||c.n!==S.links.length)PIN_G={R,S,d:S.day,n:S.links.length,G:pathEdges()};return PIN_G.G;}; +const pinUp=b=>!!pathHops(pinG(),b.pin); // Where the circuit runs today. Scenic circuits remember it; the others take the shortest path of their kind. function pathNow(b,G){if(b.pin&&pathHops(G,b.pin))return b.pin; const r=R.l2route&&R.l2route[b.id+'>'+b.city+'>'+b.city2];if(r&&r[0]){const p=r[0].ns.slice();if(p[0]!==b.city)p.reverse();if(pathHops(G,p))return p;} diff --git a/src/game/90-actions/53-customer-paths.js b/src/game/90-actions/53-customer-paths.js index c362a64..8f723e7 100644 --- a/src/game/90-actions/53-customer-paths.js +++ b/src/game/90-actions/53-customer-paths.js @@ -1,10 +1,12 @@ Object.assign(ACT,{ pathOpen:({id})=>{const b=S.biz.find(x=>x.id===id);if(b&&pathKind(b))pathModal(b);}, pathMove:({id,link})=>{const b=S.biz.find(x=>x.id===id),l=b&&pathKind(b)==='fiber'&&fiberTargets(b).find(t=>t.l.id===link&&!t.no);if(!l)return; - // A carrier already renting waves on that fiber: one contract, as when it orders more there. - const more=b.type==='wwave'&&S.biz.find(x=>x!==b&&x.type==='wwave'&&x.link===link&&x.name===b.name); - if(more){more.slots=(more.slots||0)+(b.slots||0);more.rate+=b.rate;more.since=Math.min(more.since??0,b.since??0);more.mood=Math.min(more.mood??100,b.mood??100);more.what=wwWhat(l.l,more.slots);S.biz=S.biz.filter(x=>x!==b);} - else{b.link=link;if(b.type==='wwave')b.what=wwWhat(l.l,b.slots||1);} + // A carrier already renting waves of that kind (and size) on that fiber: one contract, as when it orders more there. + const wv=b.type==='wwave'||b.type==='mwave',what=(x,n)=>b.type==='wwave'?wwWhat(l.l,n):cmWhat(l.l,cmWP(x.g),n); + const more=wv&&S.biz.find(x=>x!==b&&x.type===b.type&&x.link===link&&x.name===b.name&&x.g===b.g); + if(more){more.slots=(more.slots||0)+(b.slots||0);more.rate+=b.rate;more.since=Math.min(more.since??0,b.since??0);more.mood=Math.min(more.mood??100,b.mood??100);more.what=what(more,more.slots);S.biz=S.biz.filter(x=>x!==b);} + else{b.link=link;if(wv)b.what=what(b,b.slots||1);} + CM_V++; // managed waves come off their fiber's capacity (mwG()), which caches by fiber closeModal();toast(tr('customer_paths.name_moved_to_fiber',{name:esc(b.name),fiber:fibLab(l.l)}),'good');sfx('build');after();}, pathPin:({id,via})=>{const b=S.biz.find(x=>x.id===id);if(!b||pathKind(b)!=='circuit'||typeof via!=='string')return;const p=via.split(','); if(p.length<2||p[0]!==b.city||p[p.length-1]!==b.city2||new Set(p).size!==p.length||!pathHops(pathEdges(),p))return; diff --git a/src/i18n/en.js b/src/i18n/en.js index 3f82fb1..89e662f 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -1769,9 +1769,12 @@ "customer_paths.name_follows_routing_again":"{name} follows routing again.", "customer_paths.name_moved_to_fiber":"{name} moved to {fiber}.", "customer_paths.name_now_rides_path":"{name} now rides {path}.", +"customer_paths.needs_a_g_channel":"Needs a channel lit at {g} or more", "customer_paths.no_other_path":"There is no other working path between {a} and {b} right now.", "customer_paths.no_other_working_fiber":"There is no other working fiber between {a} and {b}. Build one, and you can move this customer onto it.", "customer_paths.not_enough_free_channels":"Not enough free channels: {free} free, needs {n}", +"customer_paths.not_enough_spare_capacity":"Not enough spare capacity: {free} left after your own traffic and the {hold}% you keep back, needs {g}", +"customer_paths.not_enough_spare_channels":"Not enough spare channels: {free} left after the {hold}% you keep back for your own traffic, needs {n}", "customer_paths.now_on":"Now on", "customer_paths.only_your_own_fiber_rents_pairs":"Only your own fiber can rent out pairs", "customer_paths.over_the_ms_budget":"Over the {ms} ms budget", diff --git a/tests/customer-paths.test.js b/tests/customer-paths.test.js index 2b6c3d2..01d5aae 100644 --- a/tests/customer-paths.test.js +++ b/tests/customer-paths.test.js @@ -55,6 +55,66 @@ test('a carrier already renting waves on the new fiber ends up with one contract assert.deepEqual(errors, []); }); +test('a wave leaves alone the channels kept back for your own traffic', (t) => { + // 47 channels lit of 64: 17 free, but a quarter of the fiber is kept back, so 1 spare. + const { ev, errors } = game(t, wave + "S.cm.hold=25;S.links.find(l=>l.id==='c').ch=Array(47).fill('zr4');"); + assert.match(ev("fiberTargets(S.biz[0]).find(x=>x.l.id==='c').no"), /1 left after the 25% you keep back.*needs 2/); + ev("ACT.pathMove({id:'w',link:'c'})"); + assert.equal(biz(ev, 'w', 'link'), 'a', 'refused'); + ev("S.cm.hold=0;ACT.pathMove({id:'w',link:'c'})"); + assert.equal(biz(ev, 'w', 'link'), 'c', 'nothing kept back: it fits'); + assert.deepEqual(errors, []); +}); + +// Four managed 400G waves, 1.6T in all, carved out of fiber a's lit capacity. +const mwave = (id = 'm', link = 'a', g = 400, slots = 4) => `S.biz.push({id:'${id}',type:'mwave',g:${g},name:'Photon Express',city:'nyc',city2:'ash',link:'${link}',slots:${slots},bw:1,rate:5000,reqs:[],mood:80,since:0,day:0,route:'normal',what:'x'});`; + +test('managed waves need that much spare lit capacity on the new fiber, on leased fiber too, and their capacity moves with them', (t) => { + // c has 1.6T lit, but a quarter is kept back: 1.2T spare, room for three of the four. b has 3.2T: 2.4T spare. + const { ev, errors } = game(t, mwave() + "S.cm.hold=25;S.links.find(l=>l.id==='c').ch=Array(4).fill('zr4');"); + const no = () => JSON.parse(ev("JSON.stringify(Object.fromEntries(fiberTargets(S.biz[0]).map(x=>[x.l.id,x.no])))")); + assert.match(no().c, /Not enough spare capacity/); + assert.equal(no().b, ''); + ev("ACT.pathMove({id:'m',link:'c'})"); + assert.equal(biz(ev, 'm', 'link'), 'a', '1.6T does not fit in 1.2T'); + // A leased fiber is lit capacity like any other: the reason is the room, not whose glass it is. + ev("S.links.find(l=>l.id==='b').own=false;S.links.find(l=>l.id==='c').own=false;"); + assert.equal(no().b, ''); + assert.doesNotMatch(no().c, /own fiber/); + assert.match(no().c, /spare capacity/); + // What the fiber gives your own traffic follows the waves, at once. + assert.equal(ev("mwG(S.links.find(l=>l.id==='a'))"), 1600); + ev("ACT.pathMove({id:'m',link:'b'})"); + assert.equal(biz(ev, 'm', 'link'), 'b'); + assert.equal(ev("mwG(S.links.find(l=>l.id==='a'))"), 0); + assert.equal(ev("mwG(S.links.find(l=>l.id==='b'))"), 1600); + assert.equal(ev("dfCap0(S.links.find(l=>l.id==='a'))"), 3200); + assert.equal(ev("dfCap0(S.links.find(l=>l.id==='b'))"), 1600); + assert.match(biz(ev, 'm', 'what'), /4/); + assert.deepEqual(errors, []); +}); + +test('a managed wave needs a channel as big as it is; a carrier renting the same size there gets one contract, another size does not', (t) => { + { const { ev, errors } = game(t, mwave('m', 'a', 800, 1) + "S.cm.hold=0;"); + assert.match(ev("fiberTargets(S.biz[0]).find(x=>x.l.id==='c').no"), /Needs a channel lit at/, '400G optics only'); + ev("S.links.find(l=>l.id==='c').ch=Array(8).fill('zr8');"); + assert.equal(ev("fiberTargets(S.biz[0]).find(x=>x.l.id==='c').no"), ''); + assert.deepEqual(errors, []); } + { const { ev, errors } = game(t, mwave() + mwave('m2', 'b', 100, 2) + "S.cm.hold=0;"); + ev("ACT.pathMove({id:'m',link:'b'})"); + assert.equal(ev("S.biz.filter(b=>b.type==='mwave'&&b.link==='b').length"), 2, '400G and 100G waves stay apart'); + assert.equal(biz(ev, 'm2', 'slots'), 2); + assert.equal(ev("mwG(S.links.find(l=>l.id==='b'))"), 1800); + assert.deepEqual(errors, []); } + { const { ev, errors } = game(t, mwave() + mwave('m2', 'b', 400, 2) + "S.cm.hold=0;"); + ev("ACT.pathMove({id:'m',link:'b'})"); + assert.equal(ev("S.biz.filter(b=>b.type==='mwave').length"), 1); + assert.equal(biz(ev, 'm2', 'slots'), 6); assert.equal(biz(ev, 'm2', 'rate'), 10000); assert.equal(biz(ev, 'm2', 'g'), 400); + assert.match(biz(ev, 'm2', 'what'), /6/); + assert.equal(ev("mwG(S.links.find(l=>l.id==='b'))"), 2400); + assert.deepEqual(errors, []); } +}); + test('fiber pairs follow the same rules as signing them: your own fiber, and pairs still free', (t) => { for (const type of ['dfpair', 'pairs', 'capfib']) { const { ev, errors } = game(t, pair(type) + pair('pairs', 'q', 'b') + "S.links.find(l=>l.id==='e').x=1;");