From b8d313b0299e29e8443da4ca573ea0c7bcb8d490 Mon Sep 17 00:00:00 2001 From: Frederic Jung Date: Thu, 5 Nov 2026 06:50:19 +0000 Subject: [PATCH] Alien waves priced against their fiber; crews halve a build at most (#203) An alien wave rented for about as much as leasing the whole fiber, so a route sold out to its market earned 11 to 35 times its lease and the gear paid back in one to three months. A wave now rents for 30% of the fiber's monthly cost (lease plus amplifiers), and each one sold between the same two cities goes cheaper, down to 40% of the first: a full route earns 2 to 6 times its lease. Signed contracts keep their price. Gameplay rule F6. Extra crews could bring any land build to the next day. They now cut it to half its planned time at most, and the button says when it would be done. Gameplay rule F7. A typed order (the agent API) could end a wave, dark fiber or cable in a city the map does not show, and opened a POP there. --- .claude/skills/gameplay-rules/SKILL.md | 2 + CHANGELOG.md | 3 + 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/agent/20-commands.js | 4 +- src/game/10-catalog/60-reach-and-subsea.js | 4 +- src/game/60-features/37-fiber-broker.js | 8 ++- src/game/80-simulation/50-sanitize.js | 2 +- src/game/80-simulation/60-requirements.js | 2 +- src/game/90-actions/60-links.js | 2 +- src/game/90-actions/87-fiber-and-hardware.js | 6 +- src/game/90-actions/90-action-helpers.js | 2 + src/game/93-ui/70-link-panels.js | 2 +- src/i18n/en.js | 3 +- tests/alien-wave-rent.test.js | 67 ++++++++++++++++++++ tests/cable-ships.test.js | 2 +- tests/gameplay-rules.test.js | 25 ++++++++ tests/issues.test.js | 2 +- tests/subsea-upgrade-timing.test.js | 13 +++- 22 files changed, 144 insertions(+), 20 deletions(-) create mode 100644 tests/alien-wave-rent.test.js diff --git a/.claude/skills/gameplay-rules/SKILL.md b/.claude/skills/gameplay-rules/SKILL.md index b258991..5622736 100644 --- a/.claude/skills/gameplay-rules/SKILL.md +++ b/.claude/skills/gameplay-rules/SKILL.md @@ -66,6 +66,8 @@ These are what the game promises, held up by `tests/gameplay-rules.test.js` (one | F3 | A specialist path (#187) only brings a customer type in below its level when the network can already serve it, or nearly: the spotted cities have POPs, the latency is met, the fiber carries at least three quarters of the smallest order. | Capability, not luck: an offer you cannot fulfil with a reasonable build is a trap. | | F4 | The chaos monkey visits only On-call and BGP at 3 a.m. (never Change Freeze, Sandbox, puzzles or scenarios), not before day 180, for 120 to 240 days; while it is here its snips replace the ordinary failures, each snip heals within a week, and it goes after tubes with no other way round first. | A test of resilience you can prepare for, not a pile-on: the reward goes to networks built with a second path. | | F5 | Capacity you rent to other carriers never outgrows the route's market: a broker listing sells over time as carriers between the two cities want it, and neither it nor a random offer sells past what both cities' eyeballs support (a landing town counts the big city it serves). | Rent that scales with your own glass and not with demand is a money machine (#203). | +| F6 | An alien wave rents for at most 30% of what its fiber costs a month (lease plus amplifiers), each wave sold between two cities is never dearer than the one before, and a route sold out to its market earns less than eight times that cost. | A buyer would lease the fiber rather than pay many times its price; the old price made one wave worth the whole fiber and a full route 11 to 35 times its lease (#203). | +| F7 | Extra crews cut a build on land to half its planned time at most. | Permits, rights of way and trenching set the pace; a 1,000-day build finishing tomorrow made lead times meaningless (#203). | ## DDoS diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a359ca..e1dc2b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ All notable changes to this project are documented here. The project follows - Bilbao joins the map, where the transatlantic cables really come ashore: Marea Carey, Grace Hopscotch and Sol Survivor now land there instead of Madrid. It has no exchange of its own, so traffic heads inland to Madrid, and Drizzle Electric, Tangerine Telecom and the big carriers sell transit there. A link you already run on the old Madrid landings keeps working as a plain subsea link, and the Mid-Atlantic Accent scenario now goes Azores, Bilbao, Madrid, and Marea Carey now leaves the American coast at Virginia Beach instead of crossing the northeast to New Jersey. Columbus III-and-a-half now comes ashore near Cádiz, where it really landed, on its way to Madrid. - Puzzles are easier to read, above all on phones: the three stars are now three goals in plain words, and the one you are working on says what is wrong and what to do, with a Show me button. The map marks it too: a red ring around a city that still needs traffic, and a pulsing ✂ on a link whose cut would hurt. On phones the sheet starts small so the map gets the screen; swipe it up for the rest. Cities far from the puzzle are left off the map, and stepping stones you are not using are small dots without a name until you tap one, build there or zoom in. - Clean traffic that a scrubbing center sends back to a customer under attack no longer shows as DDoS junk on your backbone links; a link now lists it as scrubbed clean traffic, so a small flood no longer looks like hundreds of gigabits of junk (#289). +- Alien waves you rent out on your dark fiber are now priced against the fiber itself: a wave costs a share of what leasing and lighting that fiber would cost the buyer, and each wave sold between the same two cities goes a little cheaper than the last. A route sold out to its market now earns a few times its lease, not dozens, and contracts already signed keep their price (#203). +- Extra crews can now cut a fiber build on land to half its planned time at most, since permits and rights of way do not speed up; the button shows the day it would be done (#203). +- A link ordered by typing both ends (the AI tools) can no longer end in a city the map does not show (#203). ## [2.9.1] — 2026-11-04 - Jokes in the game now poke fun at networks, cables and routers, never at people, countries or beliefs. A few networks have new names (Atlas Hold-the-Line Telecom, Star-Blink, Telekom Malay-tency, Oh Yas Sénégal, Afghan Tele-Pass, Island-Hop Micronesia, Tel-One-derful, Tango Two-Step), so do three of the names for your own cables, and about forty descriptions of networks, cities, cables and events were rewritten. diff --git a/site/i18n/de.js b/site/i18n/de.js index 4448902..159a8d4 100644 --- a/site/i18n/de.js +++ b/site/i18n/de.js @@ -2637,6 +2637,7 @@ "link_panels.abandon_the_fiber":"Glasfaser aufgeben", "link_panels.add_parallel_link":"Parallelen Link hinzufügen", "link_panels.additional_traffic_lost":"Zusätzlich verlorener Traffic", +"link_panels.all_crews_done_in_n_days_price":{"one":"Alle Trupps: fertig in {n} Tag {price}","other":"Alle Trupps: fertig in {n} Tagen {price}"}, "link_panels.an_alternate_path_exists_but_current":"Es gibt einen anderen Weg, aber mit dem jetzigen Routing und der Kapazität kommt weniger Traffic an.", "link_panels.apply_for_a_license_price_mo_n_days":"Lizenz beantragen {price} + {mo}/Monat · ~{n} Tage", "link_panels.at_this_pop_net_s_traffic_always":"In diesem POP nimmt der Verkehr zu {net} immer diesen Port. POPs ohne einen nehmen ihren nächsten Transit-Port.", @@ -2653,6 +2654,7 @@ "link_panels.connected_but_tight":"Verbunden, aber knapp.", "link_panels.cost_on_this_link_w_allowed":"Kosten auf diesem Link: {w}. Erlaubt: {lo} bis {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Kosten: genau diese Zahl, egal wie lang der Link ist.", +"link_panels.crews_can_halve_a_build_at_most":"Genehmigungen und Wegerechte geben das Tempo vor: Mehr Trupps halbieren die geplante Bauzeit höchstens, schneller geht es nicht.", "link_panels.dark_fiber_kind_km_km":"Dark Fiber · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"Personalisierte DE-KICKS-Preise: {p} % von dem, was ein normaler IX verlangen würde (Aktion, noch {n} Tage).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"Personalisierte DE-KICKS-Preise: {p} % von dem, was ein normaler IX verlangen würde.", @@ -2660,7 +2662,6 @@ "link_panels.each_channel_is_a_pair_of":"Jeder Kanal ist ein Paar Optiken, eine pro Ende. ZR+-Optiken stecken direkt in deinen Routern. Transponder sitzen in einem Shelf.", "link_panels.enters_your_network_at":"Kommt in dein Netz bei", "link_panels.every_pop_carries_net_s_traffic":"Jeder POP leitet den Verkehr zu {net} durch dein Netz bis zu diesem Port.", -"link_panels.finish_in_1_day_price":"In 1 Tag fertigstellen {price}", "link_panels.foreign_networks_need_a_local_joint":"Ausländische Netze brauchen ein lokales Joint Venture und eine Betriebslizenz, um hier Infrastruktur zu bauen.", "link_panels.found_your_own_ix_cost_mo":"Eigenen IX gründen {cost} + {mo}/Monat", "link_panels.full_links_during_the_test":"Volle Links während des Tests", diff --git a/site/i18n/es.js b/site/i18n/es.js index 4619591..6b51464 100644 --- a/site/i18n/es.js +++ b/site/i18n/es.js @@ -2635,6 +2635,7 @@ "link_panels.abandon_the_fiber":"Abandonar la fibra", "link_panels.add_parallel_link":"Añadir enlace paralelo", "link_panels.additional_traffic_lost":"Tráfico perdido adicional", +"link_panels.all_crews_done_in_n_days_price":{"one":"Todas las cuadrillas: listo en {n} día {price}","other":"Todas las cuadrillas: listo en {n} días {price}"}, "link_panels.an_alternate_path_exists_but_current":"Hay un camino alternativo, pero con el routing y la capacidad actuales llega menos tráfico.", "link_panels.apply_for_a_license_price_mo_n_days":"Solicitar una licencia {price} + {mo}/mes · ~{n} días", "link_panels.at_this_pop_net_s_traffic_always":"En este POP, el tráfico de {net} siempre usa este puerto. Los POP que no tienen uno usan su puerto de tránsito más cercano.", @@ -2651,6 +2652,7 @@ "link_panels.connected_but_tight":"Conectado, pero justo.", "link_panels.cost_on_this_link_w_allowed":"Coste en este enlace: {w}. Permitido: de {lo} a {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Coste: el número exacto, sea cual sea la distancia.", +"link_panels.crews_can_halve_a_build_at_most":"Los permisos y los derechos de paso marcan el ritmo: más cuadrillas reducen una obra como mucho a la mitad del tiempo previsto.", "link_panels.dark_fiber_kind_km_km":"Fibra oscura · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"Precio personalizado de DE-KICKS: {p} % de lo que cobraría un IX normal (promo, quedan {n} días).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"Precio personalizado de DE-KICKS: {p} % de lo que cobraría un IX normal.", @@ -2658,7 +2660,6 @@ "link_panels.each_channel_is_a_pair_of":"Cada canal es un par de ópticas, una por extremo. Las ópticas ZR+ se enchufan directo a tus routers. Los transpondedores van en un estante.", "link_panels.enters_your_network_at":"Entra en tu red por", "link_panels.every_pop_carries_net_s_traffic":"Cada POP lleva el tráfico de {net} por tu red hasta este puerto.", -"link_panels.finish_in_1_day_price":"Terminar en 1 día {price}", "link_panels.foreign_networks_need_a_local_joint":"Las redes extranjeras necesitan una empresa conjunta local y una licencia de operación para construir infraestructura aquí.", "link_panels.found_your_own_ix_cost_mo":"Funda tu propio IX {cost} + {mo}/mes", "link_panels.full_links_during_the_test":"Enlaces llenos durante la prueba", diff --git a/site/i18n/fr.js b/site/i18n/fr.js index 980158b..c530438 100644 --- a/site/i18n/fr.js +++ b/site/i18n/fr.js @@ -2635,6 +2635,7 @@ "link_panels.abandon_the_fiber":"Abandonner la fibre", "link_panels.add_parallel_link":"Ajouter un lien parallèle", "link_panels.additional_traffic_lost":"Trafic perdu en plus", +"link_panels.all_crews_done_in_n_days_price":{"one":"Toutes les équipes : fini en {n} jour {price}","other":"Toutes les équipes : fini en {n} jours {price}"}, "link_panels.an_alternate_path_exists_but_current":"Un autre chemin existe, mais avec le routage et la capacité actuels, moins de trafic arrive.", "link_panels.apply_for_a_license_price_mo_n_days":"Demander une licence {price} + {mo}/mois · ~{n} jours", "link_panels.at_this_pop_net_s_traffic_always":"Dans ce POP, le trafic de {net} passe toujours par ce port. Les POP qui n’en ont pas utilisent leur port de transit le plus proche.", @@ -2651,6 +2652,7 @@ "link_panels.connected_but_tight":"Connecté, mais de justesse.", "link_panels.cost_on_this_link_w_allowed":"Coût sur ce lien : {w}. Autorisé : de {lo} à {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Coût : le nombre exact, quelle que soit la distance.", +"link_panels.crews_can_halve_a_build_at_most":"Les permis et les droits de passage imposent le rythme : plus d’équipes réduisent un chantier à la moitié de sa durée prévue, pas moins.", "link_panels.dark_fiber_kind_km_km":"Fibre noire · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"Tarif personnalisé DE-KICKS : {p} % de ce que facturerait un IX normal (promo, encore {n} jours).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"Tarif personnalisé DE-KICKS : {p} % de ce que facturerait un IX normal.", @@ -2658,7 +2660,6 @@ "link_panels.each_channel_is_a_pair_of":"Chaque canal, c’est une paire d’optiques, une à chaque bout. Les optiques ZR+ se branchent directement dans tes routeurs. Les transpondeurs vivent sur une étagère.", "link_panels.enters_your_network_at":"Entre dans ton réseau à", "link_panels.every_pop_carries_net_s_traffic":"Chaque POP achemine le trafic de {net} à travers ton réseau jusqu’à ce port.", -"link_panels.finish_in_1_day_price":"Terminer en 1 jour {price}", "link_panels.foreign_networks_need_a_local_joint":"Les réseaux étrangers ont besoin d’une coentreprise locale et d’une licence d’opérateur pour construire ici.", "link_panels.found_your_own_ix_cost_mo":"Fonder ton propre IX {cost} + {mo}/mois", "link_panels.full_links_during_the_test":"Liens saturés pendant le test", diff --git a/site/i18n/it.js b/site/i18n/it.js index e0f2ee8..e37fafe 100644 --- a/site/i18n/it.js +++ b/site/i18n/it.js @@ -2635,6 +2635,7 @@ "link_panels.abandon_the_fiber":"Abbandona la fibra", "link_panels.add_parallel_link":"Aggiungi link parallelo", "link_panels.additional_traffic_lost":"Ulteriore traffico perso", +"link_panels.all_crews_done_in_n_days_price":{"one":"Tutte le squadre: finito in {n} giorno {price}","other":"Tutte le squadre: finito in {n} giorni {price}"}, "link_panels.an_alternate_path_exists_but_current":"Esiste un percorso alternativo, ma con routing e capacità attuali viene consegnato meno traffico.", "link_panels.apply_for_a_license_price_mo_n_days":"Richiedi una licenza {price} + {mo}/mese · ~{n} giorni", "link_panels.at_this_pop_net_s_traffic_always":"In questo POP il traffico di {net} usa sempre questa porta. I POP che non ne hanno una usano la porta di transit più vicina.", @@ -2651,6 +2652,7 @@ "link_panels.connected_but_tight":"Connesso, ma al limite.", "link_panels.cost_on_this_link_w_allowed":"Costo su questo link: {w}. Ammessi: da {lo} a {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Costo: il numero esatto, a prescindere dalla distanza.", +"link_panels.crews_can_halve_a_build_at_most":"Permessi e servitù di passaggio dettano i tempi: con più squadre un cantiere dura al massimo la metà del previsto, non di meno.", "link_panels.dark_fiber_kind_km_km":"Dark fiber · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"Prezzi personalizzati DE-KICKS: {p}% di quanto chiederebbe un IX normale (promo, ancora {n} giorni).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"Prezzi personalizzati DE-KICKS: {p}% di quanto chiederebbe un IX normale.", @@ -2658,7 +2660,6 @@ "link_panels.each_channel_is_a_pair_of":"Ogni canale è una coppia di ottiche, una per estremità. Le ottiche ZR+ si infilano direttamente nei tuoi router. I transponder stanno su uno scaffale.", "link_panels.enters_your_network_at":"Entra nella tua rete a", "link_panels.every_pop_carries_net_s_traffic":"Ogni POP instrada il traffico di {net} attraverso la tua rete fino a questa porta.", -"link_panels.finish_in_1_day_price":"Termina in 1 giorno {price}", "link_panels.foreign_networks_need_a_local_joint":"Per costruire infrastrutture qui, le reti straniere hanno bisogno di una joint venture locale e di una licenza operativa.", "link_panels.found_your_own_ix_cost_mo":"Fonda il tuo IX {cost} + {mo}/mese", "link_panels.full_links_during_the_test":"Collegamenti saturi durante il test", diff --git a/site/i18n/pt.js b/site/i18n/pt.js index a96a9e1..06e7c30 100644 --- a/site/i18n/pt.js +++ b/site/i18n/pt.js @@ -2635,6 +2635,7 @@ "link_panels.abandon_the_fiber":"Abandonar a fibra", "link_panels.add_parallel_link":"Adicionar link paralelo", "link_panels.additional_traffic_lost":"Tráfego perdido a mais", +"link_panels.all_crews_done_in_n_days_price":{"one":"Todas as equipes: pronto em {n} dia {price}","other":"Todas as equipes: pronto em {n} dias {price}"}, "link_panels.an_alternate_path_exists_but_current":"Existe um caminho alternativo, mas com o roteamento e a capacidade atuais chega menos tráfego.", "link_panels.apply_for_a_license_price_mo_n_days":"Pedir licença {price} + {mo}/mês · ~{n} dias", "link_panels.at_this_pop_net_s_traffic_always":"Neste POP, o tráfego de {net} sempre usa esta porta. POPs sem uma usam a porta de transit mais próxima.", @@ -2651,6 +2652,7 @@ "link_panels.connected_but_tight":"Conectado, mas no limite.", "link_panels.cost_on_this_link_w_allowed":"Custo neste link: {w}. Permitido: de {lo} a {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Custo: o número exato, seja qual for a distância.", +"link_panels.crews_can_halve_a_build_at_most":"Licenças e servidões de passagem ditam o ritmo: mais equipes encurtam uma obra no máximo à metade do prazo previsto.", "link_panels.dark_fiber_kind_km_km":"Dark fiber · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"Preço personalizado DE-KICKS: {p}% do que um IX normal cobraria (promo, faltam {n} dias).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"Preço personalizado DE-KICKS: {p}% do que um IX normal cobraria.", @@ -2658,7 +2660,6 @@ "link_panels.each_channel_is_a_pair_of":"Cada canal é um par de ópticas, uma em cada ponta. Ópticas ZR+ encaixam direto nos seus routers. Transponders ficam numa prateleira.", "link_panels.enters_your_network_at":"Entra na sua rede em", "link_panels.every_pop_carries_net_s_traffic":"Cada POP leva o tráfego de {net} pela sua rede até esta porta.", -"link_panels.finish_in_1_day_price":"Concluir em 1 dia {price}", "link_panels.foreign_networks_need_a_local_joint":"Redes estrangeiras precisam de uma joint venture local e de uma licença de operação para construir infraestrutura aqui.", "link_panels.found_your_own_ix_cost_mo":"Fundar seu próprio IX {cost} + {mo}/mês", "link_panels.full_links_during_the_test":"Links lotados durante o teste", diff --git a/src/agent/20-commands.js b/src/agent/20-commands.js index 7c58a63..a725106 100644 --- a/src/agent/20-commands.js +++ b/src/agent/20-commands.js @@ -179,8 +179,8 @@ const API_CMD={ quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:subUpgradeCost(l,a.k),days:SUB_UPGRADES[a.k].days}:{};}, doc:'Add premium submarine terminals or extra optical engineering to your own subsea cable. Level 4+, once each.'}, crews:{args:[['id','entityId'],['all','boolean',false]],watch:['links.#id'], - quote:a=>{const l=S.links.find(x=>x.id===a.id);if(!l)return {};const n=a.all?crewSteps(l):1;return {setup:n*crewCost(l),days:30*n};}, - doc:'Pay for more crews on a cable build: 30 days off per step. Only while more than a day of construction remains.'}, + quote:a=>{const l=S.links.find(x=>x.id===a.id);if(!l)return {};const n=a.all?crewSteps(l):Math.min(1,crewSteps(l));return {setup:n*crewCost(l),days:n?l.ready-Math.max(crewFloor(l),l.ready-30*n):0};}, + doc:'Pay for more crews on a cable build: 30 days off per step, down to half of the planned build at most.'}, addCh:{args:[['id','entityId'],['o','opticId']],watch:['links.#id'], quote:a=>{const l=S.links.find(x=>x.id===a.id);return l?{setup:chCost(l,a.o),blocked:[chWhy(l,a.o)].filter(Boolean)}:{};}, doc:'Light one channel on a dark-fiber span with a given optic; uses a spare from the shelf if you have one.'}, diff --git a/src/game/10-catalog/60-reach-and-subsea.js b/src/game/10-catalog/60-reach-and-subsea.js index e4bb4b1..305027c 100644 --- a/src/game/10-catalog/60-reach-and-subsea.js +++ b/src/game/10-catalog/60-reach-and-subsea.js @@ -22,7 +22,9 @@ function setCableReady(l,ready,day=S.day){const shift=ready-l.ready; } // Crews hurry a build on land. At sea only a cable ship does (85-incidents/50-cable-ships.js). const crewCost=l=>Math.round(15000+l.km*6); -const crewSteps=l=>Math.max(0,Math.ceil((l.ready-S.day-1)/30)); +// Permits and rights of way set the pace: crews cut at most half of the planned build (#203). +const crewFloor=l=>Math.max(S.day+1,Number.isFinite(l.day)?l.day+Math.ceil(dfBuildDays(l.km)/2):0); +const crewSteps=l=>Math.max(0,Math.ceil((l.ready-crewFloor(l))/30)); // Old saves lack purchase dates. Only shorten dates beyond any valid remaining // commissioning window. Credit elapsed time since the actual cable finish; // recent purchases and installed upgrades stay untouched. diff --git a/src/game/60-features/37-fiber-broker.js b/src/game/60-features/37-fiber-broker.js index a0f0275..e208f6f 100644 --- a/src/game/60-features/37-fiber-broker.js +++ b/src/game/60-features/37-fiber-broker.js @@ -15,6 +15,12 @@ const brMarket=(a,b)=>clamp(Math.round(Math.sqrt(brWeight(a)*brWeight(b))/BR_DIV function brSold(a,b){const k=edgeKey({a,b});let n=0;const ls=new Set(S.links.filter(l=>l.kind==='df'&&edgeKey(l)===k).map(l=>l.id)); for(const x of S.biz)if(ls.has(x.link))n+=x.type==='wwave'?(x.slots||0):x.type==='dfpair'?BR_PAIR:0;return n;} const brFree=l=>Math.max(0,brMarket(l.a,l.b)-brSold(l.a,l.b)); +/* What a carrier pays for one alien wave (#203): a share of what the fiber itself costs a month (lease plus amplifiers), + since a buyer would not pay more than leasing and lighting it. Each wave sold between the two cities makes the next + one cheaper, down to 40% of the first once the route's market is full: a full route earns a few times its lease. */ +const WW_SHARE=0.3,WW_FALL=0.6; +function wwRate(l,n,cut=1){const F=dfLeaseMo(l.km)+ampCount(l.km)*AMP_MO,M=brMarket(l.a,l.b),s=brSold(l.a,l.b);let r=0; + for(let i=0;i0)&&!(L.p>0))delete l.list;}} // A sale: a new carrier on this fiber, or more waves for one that already rents here. function brSell(l,t,n){const T=BIZ_T[t],nm=()=>{const list=T.names.filter(x=>!S.usedNames.includes(x)),x=list.length?pick(list):pick(T.names);useName(x);return x;}; - const o=fiberOffer(t,l,nm,0.9);if(t==='wwave'){o.slots=n;o.rate=Math.round(waveMo(l.km,false,2)*0.55*n*0.9);o.what=wwWhat(l,n);} + const o=fiberOffer(t,l,nm,0.9);if(t==='wwave'){o.slots=n;o.rate=wwRate(l,n,0.9);o.what=wwWhat(l,n);} const more=t==='wwave'&&S.biz.find(b=>b.type==='wwave'&&b.link===l.id&&b.name===o.name); if(more){more.slots=(more.slots||0)+n;more.rate+=o.rate;more.what=wwWhat(l,more.slots);}else S.biz.push(offerCustomer(o)); toast(tr('broker.sold',{name:esc(o.name),what:esc(t==='wwave'?wwWhat(l,n):o.what),price:fmt$(o.rate)}),'good'); diff --git a/src/game/80-simulation/50-sanitize.js b/src/game/80-simulation/50-sanitize.js index 6d25862..394874d 100644 --- a/src/game/80-simulation/50-sanitize.js +++ b/src/game/80-simulation/50-sanitize.js @@ -21,7 +21,7 @@ function sanitize(s){ if(!isCity(s.home))s.home=Object.keys(s.pops)[0]||'fra'; opsSanitize(s); const tier=v=>int(v,0,PORT.length-1,0),lag=v=>int(v,1,LAG_MAX,1),sid=v=>String(v==null?uid():v).slice(0,40); - s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);if(l.list!==undefined){const L=l.list;if(l.kind==='df'&&L&&typeof L==='object'&&!Array.isArray(L)){const w=int(L.w,0,256,0),p=int(L.p,0,2,0);if(w||p)l.list={w,p};else delete l.list;}else delete l.list;}l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&(!own(CAB,l.cable)||!cablePair(l.cable,l.a,l.b)))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.seaPath!==undefined){if(l.own&&l.sub&&Array.isArray(l.seaPath)&&l.seaPath.length>=2&&l.seaPath.length<=2048&&l.seaPath.every(p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90))l.seaPath=l.seaPath.map(p=>p.slice());else delete l.seaPath;}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);return l;}); + s.links=s.links.filter(l=>l&&isCity(l.a)&&isCity(l.b)&&l.a!==l.b).map(l=>{l.id=sid(l.id);if(l.list!==undefined){const L=l.list;if(l.kind==='df'&&L&&typeof L==='object'&&!Array.isArray(L)){const w=int(L.w,0,256,0),p=int(L.p,0,2,0);if(w||p)l.list={w,p};else delete l.list;}else delete l.list;}l.km=num(l.km,kmBetween(l.a,l.b));l.mo=num(l.mo,0);l.cut=num(l.cut,0);if(l.pairs!==undefined)l.pairs=Math.min(l.sub?SUB_PAIRS_MAX:s.lvl>=PAIRS_LV?PAIRS_BIG:PAIRS_MAX,Math.max(1,Math.floor(+l.pairs)||1));if(l.kind!=='df'&&l.kind!=='vxc')l.kind='wave';if(l.kind==='wave')l.tier=int(l.tier,0,LT.length-1,0);if(l.cable&&(!own(CAB,l.cable)||!cablePair(l.cable,l.a,l.b)))l.cable=null;if(l.kind==='vxc'&&!own(VXC,l.vt))l.vt=0;if(l.kind==='df'){if(!own(DF_SYS,l.sys))l.sys='lite';l.ch=Array.isArray(l.ch)?l.ch.filter(o=>own(OPT,o)):[];l.ready=num(l.ready,0);if(l.day!==undefined)l.day=Math.min(s.day,Math.max(0,num(l.day,s.day)));for(const k of Object.keys(SUB_UPGRADES)){const f='sub'+k;if(l[f]!==undefined){if(l.own&&l.sub&&Number.isFinite(l[f])&&l[f]>=0)l[f]=Math.round(l[f]);else delete l[f];}}if(l.seaPath!==undefined){if(l.own&&l.sub&&Array.isArray(l.seaPath)&&l.seaPath.length>=2&&l.seaPath.length<=2048&&l.seaPath.every(p=>Array.isArray(p)&&p.length===2&&p.every(Number.isFinite)&&Math.abs(p[0])<=180&&Math.abs(p[1])<=90))l.seaPath=l.seaPath.map(p=>p.slice());else delete l.seaPath;}if(l.paid!==undefined){if(l.own&&l.sub&&Number.isFinite(l.paid)&&l.paid>=0)l.paid=Math.round(l.paid);else delete l.paid;}if(l.own&&l.sub&&!own(SEA_DESIGNS,l.seaDesign))l.seaDesign='standard';l.regen=int(l.regen,0,REGEN_MAX,0);}const deg=v=>v&&typeof v==='object'?{until:num(v.until,0),f:Math.min(1,Math.max(0,num(v.f,1)))}:null;if(l.loss)l.loss=deg(l.loss);return l;}); for(const l of s.links)repairSubUpgradeDates(l,s.day); /* Metrics moved from each link to its city pair (#122). Older saves routed a pair at the lowest metric of its links, with all of them carrying traffic, so the pair keeps that metric and nothing goes on standby. */ diff --git a/src/game/80-simulation/60-requirements.js b/src/game/80-simulation/60-requirements.js index 97ebd4d..ca97bd6 100644 --- a/src/game/80-simulation/60-requirements.js +++ b/src/game/80-simulation/60-requirements.js @@ -77,5 +77,5 @@ const freeCh=(l,u)=>chMax(l)-(l.ch||[]).length-soldSlots(l,u),pairFree=(l,u)=>!! const wwWhat=(l,n)=>trn('requirements.n_400g_alien_wave_on_your',n,{a:CITY[l.a].name,b:CITY[l.b].name}); function fiberOffer(t,l,nm,cut=1){ if(t==='wwave'){const slots=1+Math.floor(Math.random()*Math.min(4,freeCh(l))); - return {id:uid(),city:l.a,city2:l.b,link:l.id,slots,what:wwWhat(l,slots),name:nm(),type:t,bw:1,rate:Math.round(waveMo(l.km,false,2)*0.55*slots*cut),reqs:[],exp:S.day+30};} + return {id:uid(),city:l.a,city2:l.b,link:l.id,slots,what:wwWhat(l,slots),name:nm(),type:t,bw:1,rate:wwRate(l,slots,cut),reqs:[],exp:S.day+30};} return {id:uid(),city:l.a,city2:l.b,link:l.id,what:tr('requirements.a_spare_fiber_pair_in_your',{a:CITY[l.a].name,b:CITY[l.b].name}),name:nm(),type:t,bw:1,rate:Math.round(dfLeaseMo(l.km)*0.9*cut),reqs:[],exp:S.day+30};} diff --git a/src/game/90-actions/60-links.js b/src/game/90-actions/60-links.js index 6864da7..d9d1ffe 100644 --- a/src/game/90-actions/60-links.js +++ b/src/game/90-actions/60-links.js @@ -15,7 +15,7 @@ Object.assign(ACT,{ foundIx:({city})=>{if(!isCity(city))return;const why=foundIxWhy(city);if(why){toast(why,'bad');sfx('err');return;}if(!spend(MYIX_COST))return;const nm=(S.name.split(' ')[0]||'My').replace(/[^A-Za-z0-9]/g,'').slice(0,10)+'-IX '+CITY[city].name; S.myIx[city]={name:nm,members:[],next:S.day+4};S.ixp[city]=2;toast(tr('links.you_founded_ix_networks_will_join',{ix:esc(nm)}),'goal');after();}, buildLink:({tier})=>{tier=+tier;const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;const km=kmBetween(a,b),sub=isSub(a,b),sib=pairLinks(a,b).filter(l=>l.kind!=='vxc'),jn=sib.length?routeJoin(a,b):null,same=!!jn,border=cnCity(a)!==cnCity(b),mult=(sib.length&&!(jn&&jn.k===(landTrenches(a,b)[0]||{}).k)?DIVERSE:1)*(border?3*(UI.cnPrem&&(a==='hkg'||b==='hkg')?1.6:1):1); - if(!linkFromOk(a)||((cnCity(a)||cnCity(b))&&!cnOk()))return; + if(!linkFromOk(a)||!linkToOk(b)||((cnCity(a)||cnCity(b))&&!cnOk()))return; if(!waveOk(a,b,tier)){toast(tr('links.a_wave_wave_needs_need_at',{wave:LT[tier].n,need:esc(waveNeed(tier))}),'bad');sfx('err');return;} const wr=waveRoute(a,b,mult,border);if(!wr){toast(tr('links.no_cable_available_for_that_route'),'bad');sfx('err');return;} {const so=soldOut(a,b,tier,wr.cab);if(so){toast(tr('links.no_wave_capacity_on_this_route',{wave:LT[tier].n,why:tr(so.why),n:Math.max(1,so.until-S.day)}),'bad');sfx('err');return;}}{const w=subWaveWhy(tier,wr.km,wr.sub);if(w){toast(tr('links.no_wave_waves_on_this_cable',{wave:LT[tier].n,why:esc(w)}),'bad');sfx('err');return;}}const base=Math.round(waveMo(wr.km,wr.sub,tier)*wr.wm),cost=base+(S.pops[b]?0:popCost(b)); diff --git a/src/game/90-actions/87-fiber-and-hardware.js b/src/game/90-actions/87-fiber-and-hardware.js index 39c333d..0413443 100644 --- a/src/game/90-actions/87-fiber-and-hardware.js +++ b/src/game/90-actions/87-fiber-and-hardware.js @@ -7,14 +7,14 @@ Object.assign(ACT,{ ownCab:()=>{UI.lmode='df';UI.dfSrc='cable';UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, dfSrc:({v})=>{UI.dfSrc=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, dfSys:({v})=>{UI.dfSys=v;if(UI.pending)openLinkModal(UI.pending.a,UI.pending.b);}, - orderCable:()=>{const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;if(ownCabWhy(a,b)||!linkFromOk(a))return;const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',up=seaUps(seaQuote(a,b,design).km),q=seaQuote(a,b,design,up),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(seaLack(km,up).length||!spend(cost))return; + orderCable:()=>{const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;if(ownCabWhy(a,b)||!linkFromOk(a)||!linkToOk(b))return;const design=own(SEA_DESIGNS,UI.seaDesign)?UI.seaDesign:'standard',up=seaUps(seaQuote(a,b,design).km),q=seaQuote(a,b,design,up),km=q.km,cost=q.cost+(S.pops[b]?0:popCost(b));if(seaLack(km,up).length||!spend(cost))return; if(!S.pops[b]){S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(b);} const used=new Set(S.links.map(l=>l.cname).filter(Boolean)),cname=OWNCAB_NAMES.find(n=>!used.has(n))||`${pick(OWNCAB_NAMES)} ${used.size+1}`,id=uid(),ship=layName({id}),days=q.days; S.links.push({id,a,b,kind:'df',own:true,sub:true,seaDesign:design,seaPath:q.pts.map(p=>p.slice()),sys:'roadm',ch:[],km,cable:null,cname,mo:Math.round(km*OWNCAB_OM),trench:'own:'+id,cut:0,day:S.day,ready:S.day+days,spares:false,pairs:1}); const laid=S.links[S.links.length-1];laid.paid=q.cost;for(const k of Object.keys(SUB_UPGRADES))if(up[k])laid['sub'+k]=laid.ready;UI.seaDesign='standard';UI.seaterminal=UI.seaengineering=false; S.stats.ownCab=(S.stats.ownCab||0)+1;UI.dfSrc='lease';closeModal();UI.sel={type:'link',id}; toast(tr('fiber_and_hardware.the_ship_sets_sail_name_your',{ship,name:cname,km:km.toLocaleString(),a:CITY[a].name,b:CITY[b].name,n:days}),'goal');sfx('build');after();}, - orderDf:()=>{const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;if(!dfAllowed(a,b)||!linkFromOk(a))return;const sc=isSub(a,b)?subDfCable(a,b):null,km=sc?sc.km:kmBetween(a,b); + orderDf:()=>{const p=UI.pending;if(!p||noTalk(p.a,p.b))return;const {a,b}=p;if(!dfAllowed(a,b)||!linkFromOk(a)||!linkToOk(b))return;const sc=isSub(a,b)?subDfCable(a,b):null,km=sc?sc.km:kmBetween(a,b); const own=UI.dfSrc==='build'&&!sc,sys=DF_SYS[UI.dfSys]&&techOk('sys',UI.dfSys,DF_SYS[UI.dfSys].lvl)?UI.dfSys:'lite';if(lvl()<2)return; const up=(own?digCost(km):0)+sysCost(sys)+ampCount(km)*AMP_COST+(S.pops[b]?0:popCost(b));if(!spend(up))return; if(!S.pops[b]){S.pops[b]={day:S.day,bb:null,boost:0,down:0,routers:1,gen:false,rgen:0};popStdApply(b);} @@ -37,6 +37,6 @@ Object.assign(ACT,{ seaRush:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l)return;const k=prepSteps(l);if(!k)return;const n=all?k:1;if(!spend(n*prepCost(l)))return;const ready=Math.max(prepFloor(l),l.ready-PREP_STEP*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('cable_ships.the_factory_runs_a_night_shift',saved,{n:saved}),'good');sfx('build');after();}, layShip:({id})=>{const l=S.links.find(x=>x.id===id);const q=l&&layQuote(l);if(!q||!spend(q.cost))return;l.ship2=1;setCableReady(l,l.ready-q.save); toast(trn('cable_ships.second_lay_ship_booked',q.save,{ship:esc(layName(l,1)),n:q.save}),'good');sfx('coin');after();}, - crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.sub||l.ready<=S.day+1)return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(S.day+1,l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();}, + crews:({id,all})=>{const l=S.links.find(x=>x.id===id);if(!l||l.kind!=='df'||!l.own||l.sub||!crewSteps(l))return;const n=all?crewSteps(l):1,c=n*crewCost(l);if(!spend(c))return;const ready=Math.max(crewFloor(l),l.ready-30*n),saved=l.ready-ready;setCableReady(l,ready);toast(trn('fiber_and_hardware.more_crews_on_site_construction_is',saved,{n:saved}),'good');after();}, addGen:({city})=>{const p=S.pops[city];if(!p||p.gen)return;if(!spend(GEN_COST))return;p.gen=true;floater(CITY[city].x,CITY[city].y-30,tr('common.generator'),'#FF8A3D');after();}, }); diff --git a/src/game/90-actions/90-action-helpers.js b/src/game/90-actions/90-action-helpers.js index 86afee0..bed742e 100644 --- a/src/game/90-actions/90-action-helpers.js +++ b/src/game/90-actions/90-action-helpers.js @@ -12,6 +12,8 @@ function dfAllowed(a,b){if(noTalk(a,b))return false;if(isSub(a,b))return !!subDf // A link starts at one of your POPs. The map only drags one from a POP, but a typed order (the agent API) names both ends. function linkFromWhy(a){return S.pops[a]?'':tr('action_helpers.you_have_no_pop_in_city',{city:CITY[a].name});} function linkFromOk(a){const w=linkFromWhy(a);if(w){toast(w,'bad');sfx('err');}return !w;} +// ...and ends at a city you could build a POP in (#203): a typed order can name one the map does not show. +function linkToOk(b){if(S.pops[b]||cityOn(b))return true;toast(popOffWhy(b),'bad');sfx('err');return false;} // A retired small city (off: true) takes no new POP; the nearest open city in its country stands in for it. function popOffWhy(c){const C=CITY[c],near=CITIES.filter(o=>!o.off&&o.cc===C.cc).sort((x,y)=>kmBetween(c,x.id)-kmBetween(c,y.id))[0]; return tr('action_helpers.city_is_off_the_map_small',{city:C.name,near:near?near.name:''});} diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js index 4e488d9..0880551 100644 --- a/src/game/93-ui/70-link-panels.js +++ b/src/game/93-ui/70-link-panels.js @@ -115,7 +115,7 @@ function dfPanel(l){ const load=R.load[l.id]||0,cap=dfCap(l),u=cap?load/cap:0,bld=l.ready>S.day,A=CITY[l.a].name,B=CITY[l.b].name,inc=S.inc.find(i=>i.ref===l.id||i.ref===(l.trench||l.id)),amps=ampCount(l.km),sysD=DF_SYS[l.sys]; let h=`
${tr('link_panels.dark_fiber_kind_km_km',{kind:l.own?tr('link_panels.your_own_build'):tr('common.leased_iru'),km:l.km.toLocaleString()})}

${A} ⇄ ${B}

`; if(bld){const tot=Math.max(1,l.ready-l.day),done=clamp((S.day-l.day)/tot,0,1); - h+=`

${l.own?tr('common.under_construction'):tr('common.being_spliced')}

${l.own?tr('link_panels.permits_trenching_splicing'):tr('common.iru_handover')}${tr('common.n_days_left',{n:l.ready-S.day})}
${l.own&&l.sub?layPanel(l):l.own?`
${btn(tr('link_panels.hire_extra_crews_price_30_days',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',l.ready<=S.day+1||S.cash`:''}

${tr('link_panels.you_can_pre_install_optics_now')}

`;} + h+=`

${l.own?tr('common.under_construction'):tr('common.being_spliced')}

${l.own?tr('link_panels.permits_trenching_splicing'):tr('common.iru_handover')}${tr('common.n_days_left',{n:l.ready-S.day})}
${l.own&&l.sub?layPanel(l):l.own?`
${btn(tr('link_panels.hire_extra_crews_price_30_days',{price:fmt$(crewCost(l))}),'crews',{id:l.id},'sm',!crewSteps(l)||S.cash${!crewSteps(l)&&l.ready>S.day+1?`

${tr('link_panels.crews_can_halve_a_build_at_most')}

`:''}`:''}

${tr('link_panels.you_can_pre_install_optics_now')}

`;} else if(inc&&linkDown(l))h+=`

${tr('common.dark_6bf5')}

${esc(inc.msg)}

${shipNote(inc)}${inc.cost?btn(`${esc(inc.fix||tr('common.rush_repair'))} ${fmt$(inc.cost)}`,'fixInc',{id:inc.id},'red',S.cash`; h+=`

${tr('common.capacity')}

${tr('link_panels.n_of_max_channels_lit',{n:(l.ch||[]).length,max:chMax(l)})}${soldSlots(l)?` · ${tr('link_panels.n_sold_as_alien_waves',{n:soldSlots(l)})}`:''}${fmtG(load)} / ${fmtG(cap)}
${seatPanel(l)}${l.own&&l.sub?`
${tr('common.cable_design')}${tr((SEA_DESIGNS[l.seaDesign]||SEA_DESIGNS.standard).n)}
`:''} diff --git a/src/i18n/en.js b/src/i18n/en.js index 40031a8..ad8a9de 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -2636,6 +2636,7 @@ "link_panels.abandon_the_fiber":"Abandon the fiber", "link_panels.add_parallel_link":"Add parallel link", "link_panels.additional_traffic_lost":"Additional traffic lost", +"link_panels.all_crews_done_in_n_days_price":{"one":"All the crews: done in {n} day {price}","other":"All the crews: done in {n} days {price}"}, "link_panels.an_alternate_path_exists_but_current":"An alternate path exists, but current routing and capacity deliver less traffic.", "link_panels.apply_for_a_license_price_mo_n_days":"Apply for a license {price} + {mo}/mo · ~{n} days", "link_panels.at_this_pop_net_s_traffic_always":"At this POP, {net}'s traffic always uses this port. POPs without one use their nearest transit port.", @@ -2652,6 +2653,7 @@ "link_panels.connected_but_tight":"Connected, but tight.", "link_panels.cost_on_this_link_w_allowed":"Cost on this link: {w}. Allowed: {lo} to {hi}.", "link_panels.cost_the_exact_number_whatever_the":"Cost: the exact number, whatever the distance.", +"link_panels.crews_can_halve_a_build_at_most":"Permits and rights of way set the pace: extra crews can cut a build to half its planned time, no further.", "link_panels.dark_fiber_kind_km_km":"Dark fiber · {kind} · {km} km", "link_panels.de_kicks_personalised_pricing_p_of":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge (promo, {n} days left).", "link_panels.de_kicks_personalised_pricing_p_of_3d4f":"DE-KICKS personalised pricing: {p}% of what a normal IX would charge.", @@ -2659,7 +2661,6 @@ "link_panels.each_channel_is_a_pair_of":"Each channel is a pair of optics, one per end. ZR+ optics plug straight into your routers. Transponders sit on a shelf.", "link_panels.enters_your_network_at":"Enters your network at", "link_panels.every_pop_carries_net_s_traffic":"Every POP carries {net}'s traffic across your network to this port.", -"link_panels.finish_in_1_day_price":"Finish in 1 day {price}", "link_panels.foreign_networks_need_a_local_joint":"Foreign networks need a local joint venture and an operating license to build infrastructure here.", "link_panels.found_your_own_ix_cost_mo":"Found your own IX {cost} + {mo}/mo", "link_panels.full_links_during_the_test":"Full links during the test", diff --git a/tests/alien-wave-rent.test.js b/tests/alien-wave-rent.test.js new file mode 100644 index 0000000..9bd353e --- /dev/null +++ b/tests/alien-wave-rent.test.js @@ -0,0 +1,67 @@ +// #203: renting out alien waves was a money machine. A wave is now priced against what the fiber itself costs, and gets +// cheaper as a route fills; extra crews cut a build to half its planned time at most; a typed order cannot end a link +// in a city the map does not show. +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { load } = require('./harness'); + +const fiber = (ev, id, a, b, km) => ev(`S.links.push({id:'${id}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'cl',ch:[],km:${km},ready:0,day:0,cut:0,mo:1,trench:'own:${id}',pairs:1})`); +const sell = (ev, id) => ev(`(()=>{const l=S.links.find(x=>x.id==='${id}'),r=wwRate(l,1);S.biz.push({id:uid(),type:'wwave',link:l.id,slots:1,rate:r,city:l.a,city2:l.b,name:'n'+S.biz.length,bw:1,mood:80,since:0,reqs:[]});return r})()`); + +test('#203 an alien wave rents for a share of the fiber, and each one sold on a route makes the next cheaper', () => { + const { ev, errors } = load(); + ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[];for(const c of ['lon','nyc'])if(!S.pops[c])ACT.buildPop({city:c})"); + fiber(ev, 'f', 'lon', 'nyc', 5570); + const F = ev('dfLeaseMo(5570)+ampCount(5570)*AMP_MO'), M = ev("brMarket('lon','nyc')"); + const rates = []; + for (let i = 0; i < M; i++) rates.push(sell(ev, 'f')); + assert.ok(rates[0] <= 0.3 * F + 1, `the first wave costs at most 30% of the fiber: ${rates[0]} vs ${F}`); + for (let i = 1; i < rates.length; i++) assert.ok(rates[i] <= rates[i - 1], 'never dearer than the one before'); + assert.ok(rates.at(-1) < rates[0] * 0.45, 'the last waves of a full route go cheap'); + const full = rates.reduce((a, b) => a + b, 0); + assert.ok(full / F > 2 && full / F < 8, `a full route earns a few times its lease, not dozens: ${(full / F).toFixed(1)}×`); + // The old price: one wave cost about as much as the whole fiber, and a full route earned ~29× its lease. + assert.ok(full < ev(`Math.round(waveMo(5570,false,2)*0.55)*${M}`) / 3); + // A random offer and a broker sale on the same route follow the same price. + fiber(ev, 'g', 'lon', 'nyc', 5570); + ev("S.biz=[]"); + assert.equal(ev("(()=>{let n=0;const o=fiberOffer('wwave',S.links.find(l=>l.id==='g'),()=>'x');return o.rate===wwRate(S.links.find(l=>l.id==='g'),o.slots)})()"), true); + assert.deepEqual(errors, []); +}); + +test('#203 extra crews cut a build to half its planned time, no further', () => { + const { ev, errors, dom } = load(); + ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;for(const c of ['fra','waw'])if(!S.pops[c])ACT.buildPop({city:c})"); + const km = Math.round(ev("kmBetween('fra','waw')")), days = ev(`dfBuildDays(${km})`); + ev(`S.links.push({id:'b',a:'fra',b:'waw',kind:'df',own:true,sys:'roadm',ch:[],km:${km},ready:S.day+${days},day:S.day,cut:0,mo:1,trench:'own:b',pairs:1});after();UI.sel={type:'link',id:'b'};renderPanel()`); + const start = ev('S.day'); + assert.match(ev("document.getElementById('panelBody').textContent"), new RegExp(`All the crews: done in ${Math.ceil(days / 2)} days`)); + const cash = ev('S.cash'); + ev("ACT.crews({id:'b',all:1})"); + assert.equal(ev("S.links.find(l=>l.id==='b').ready"), start + Math.ceil(days / 2), 'half the planned build'); + assert.ok(ev('S.cash') < cash); + const c2 = ev('S.cash'); + ev("ACT.crews({id:'b'});ACT.crews({id:'b',all:1})"); + assert.equal(ev('S.cash'), c2, 'no more crews to buy'); + ev('renderPanel()'); + const crews = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')]; + assert.ok(crews.length && crews.every((b) => b.disabled)); + assert.match(ev("document.getElementById('panelBody').textContent"), /half its planned time/); + // Phone: the panel still renders with the note. + ev("window.innerWidth=360;renderAll()"); + assert.deepEqual(errors, []); +}); + +test('#203 a dark fiber, cable or wave cannot be ordered to a city the map does not show', () => { + const { ev, errors } = load(); + ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6"); + ev("ACT.buildPop({city:'sao'})"); + const home = 'sao', off = ev("(()=>{const c=CITIES.find(c=>c.off&&!cityOn(c.id)&&dfAllowed('sao',c.id));return c?c.id:null})()"); + assert.ok(off, 'there is a hidden city to try'); + const pops = ev('Object.keys(S.pops).length'); + ev(`UI.pending={a:'${home}',b:'${off}'};UI.dfSrc='lease';UI.dfSys='lite';ACT.orderDf()`); + ev(`UI.pending={a:'${home}',b:'${off}'};ACT.buildLink({tier:0})`); + assert.equal(ev('Object.keys(S.pops).length'), pops, 'no POP appears there'); + assert.equal(ev(`S.links.some(l=>l.b==='${off}'||l.a==='${off}')`), false); + assert.deepEqual(errors, []); +}); diff --git a/tests/cable-ships.test.js b/tests/cable-ships.test.js index 5d00697..aea5daa 100644 --- a/tests/cable-ships.test.js +++ b/tests/cable-ships.test.js @@ -187,7 +187,7 @@ test('your own subsea cable: survey and factory first, then a lay ship; a second assert.match(panel(), /Survey, permits and the cable factory/); assert.match(panel(), /Laying starts in 560 days/); assert.match(panel(), /Book a second lay ship/); - assert.doesNotMatch(panel(), /Hire extra crews|Finish in 1 day/); + assert.doesNotMatch(panel(), /Hire extra crews|All the crews/); const cash = ev('S.cash'); ev("ACT.crews({id:'own'})"); assert.equal(ev('S.cash'), cash, 'no crews at sea'); diff --git a/tests/gameplay-rules.test.js b/tests/gameplay-rules.test.js index e40b5fa..bc0a0e1 100644 --- a/tests/gameplay-rules.test.js +++ b/tests/gameplay-rules.test.js @@ -412,6 +412,31 @@ test('F5: rented capacity never outgrows the route\'s market (#203)', () => { assert.deepEqual(g.errors, []); }); +test('F6: an alien wave is priced against its fiber, and a full route earns a few times its lease (#203)', () => { + const g = load(); + g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.biz=[];S.offers=[]"); + for (const [a, b] of [['lon', 'par'], ['lon', 'nyc'], ['fra', 'sin'], ['nyc', 'sjc'], ['jed', 'gdx']]) { + const r = JSON.parse(g.ev(`(()=>{const l={id:'f6${a}${b}',a:'${a}',b:'${b}',kind:'df',own:true,sys:'cl',ch:[],km:Math.round(kmBetween('${a}','${b}')),ready:0,day:0,cut:0,mo:1,pairs:2};S.links.push(l); + const F=dfLeaseMo(l.km)+ampCount(l.km)*AMP_MO,M=brMarket(l.a,l.b),rs=[]; + for(let i=0;i x + y, 0); + assert.ok(full < 8 * r.F, `F6: ${a}-${b} full route ${(full / r.F).toFixed(1)}× its lease`); + } + assert.deepEqual(g.errors, []); +}); + +test('F7: extra crews cut a build on land to half its planned time at most (#203)', () => { + const g = load(); + g.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e11;S.lvl=4;for(const c of ['fra','mad'])if(!S.pops[c])ACT.buildPop({city:c})"); + const km = Math.round(g.ev("kmBetween('fra','mad')")), days = g.ev(`dfBuildDays(${km})`), d0 = g.ev('S.day'); + g.ev(`S.links.push({id:'f7',a:'fra',b:'mad',kind:'df',own:true,sys:'roadm',ch:[],km:${km},ready:S.day+${days},day:S.day,cut:0,mo:1,trench:'own:f7',pairs:1});ACT.crews({id:'f7',all:1});for(let i=0;i<50;i++)ACT.crews({id:'f7'})`); + assert.ok(g.ev("S.links.find(l=>l.id==='f7').ready") - d0 >= days / 2, 'F7: never under half the planned build'); + assert.deepEqual(g.errors, []); +}); + // D1–D4: DDoS as networks see it (#242). tests/ddos-model.test.js plays each one in detail. const ddFra = (ev) => ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=4;S.nextFail=1e9;S.nextEvent=1e9;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=40;ACT.buyTransit({city:'fra',net:'cog',tier:1});S.pops.fra.rgen=RG.findIndex(r=>r.fsN===8);S.biz.push({id:'g',type:'game',name:'G',city:'fra',bw:10,rate:1,mood:80,since:0,reqs:[]},{id:'d',type:'dia',name:'D',city:'fra',bw:5,rate:1,mood:80,since:0,reqs:[]});compute()"); const ddHit = (ev, g) => ev(`S.ev.ddos={id:'x',city:'fra',tgt:'g',vec:'dns',gbps:${g},start:S.day,until:S.day+2,bh:false};compute()`); diff --git a/tests/issues.test.js b/tests/issues.test.js index 09271f2..c2e22ad 100644 --- a/tests/issues.test.js +++ b/tests/issues.test.js @@ -1267,7 +1267,7 @@ test('#51 a dark fiber shows what is rented out, and spare capacity can be liste ev("for(let i=0;i<120&&!S.biz.some(b=>b.link==='df1');i++)brTick();renderPanel()"); const b = JSON.parse(ev("JSON.stringify(S.biz.find(x=>x.link==='df1'))")); assert.equal(b.type, 'wwave'); - assert.equal(b.rate, ev(`Math.round(waveMo(450,false,2)*0.55*${b.slots}*0.9)`), 'the usual alien-wave price minus the broker'); + assert.equal(b.rate, ev(`(()=>{const F=dfLeaseMo(450)+ampCount(450)*AMP_MO,M=brMarket('fra','ams');let r=0;for(let i=0;i<${b.slots};i++)r+=F*WW_SHARE*(1-WW_FALL*Math.min(1,i/M));return Math.round(r*0.9)})()`), 'the alien-wave price, priced against the fiber, minus the broker'); assert.ok(txt().includes(b.name), 'the customer is listed on the fiber'); assert.match(txt(), new RegExp(`Free channels\\s*${62 - b.slots} / 64`)); assert.equal(ev("S.links[0].list?S.links[0].list.w:0"), 4 - b.slots, 'the listing shrinks by what sold'); diff --git a/tests/subsea-upgrade-timing.test.js b/tests/subsea-upgrade-timing.test.js index 77a7bde..30e26b2 100644 --- a/tests/subsea-upgrade-timing.test.js +++ b/tests/subsea-upgrade-timing.test.js @@ -8,6 +8,12 @@ function setup(ev, sub = true) { S.links=[{id:'cable',a:'lag',b:'bde',kind:'df',own:true,sub:${sub},sys:'roadm',km:15000,ch:[],day:100,ready:1000,cut:0,mo:1}];`); } +// Crews cut a land build to half its planned time at most (#203): plan these builds long enough that crews can still +// bring them to tomorrow, so the tests below check the price and the one-click purchase. +function plannedLong(ev) { + ev('S.links[0].day=101-Math.ceil(dfBuildDays(S.links[0].km)/2)'); +} + function dates(ev) { return JSON.parse(ev('JSON.stringify([S.links[0].ready,S.links[0].subterminal,S.links[0].subengineering])')); } @@ -126,6 +132,7 @@ test('one-click completion on land costs the same as repeated crew hires', () => const { ev, dom, errors } = load(); try { setup(ev, false); + plannedLong(ev); ev("UI.sel={type:'link',id:'cable'};renderPanel()"); const button = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all); assert.ok(button && !button.disabled, 'one-click option is available'); @@ -140,6 +147,7 @@ test('one-click completion on land costs the same as repeated crew hires', () => ev("ACT.crews({id:'cable',all:1})"); assert.equal(ev('S.cash'), bulkCash, 'repeat submission cannot charge again'); setup(ev, false); + plannedLong(ev); ev("for(let i=0;i<30;i++)ACT.crews({id:'cable'})"); assert.equal(ev('S.links[0].ready'), bulkReady); assert.equal(ev('S.cash'), bulkCash); @@ -156,6 +164,7 @@ test('one-click completion is atomic when unaffordable and handles short or comp const { ev, dom } = load(); try { setup(ev, false); + plannedLong(ev); ev("S.cash=30*105000-1;UI.sel={type:'link',id:'cable'};renderPanel()"); const bulk = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all); assert.equal(bulk.disabled, true); @@ -177,7 +186,9 @@ test('owned ground fiber exposes the one-click button and uses the same crew pri const { ev, dom, errors } = load(); try { setup(ev); - ev("ACT.buildPop({city:'ams'});Object.assign(S.links[0],{a:'fra',b:'ams',sub:false,km:800,ready:191});UI.sel={type:'link',id:'cable'};renderPanel()"); + ev("ACT.buildPop({city:'ams'});Object.assign(S.links[0],{a:'fra',b:'ams',sub:false,km:800,ready:191})"); + plannedLong(ev); + ev("UI.sel={type:'link',id:'cable'};renderPanel()"); const bulk = [...dom.window.document.querySelectorAll('#panelBody [data-act=crews]')].find(b => JSON.parse(b.dataset.args).all); assert.ok(bulk && !bulk.disabled, 'ground construction has the same one-click control'); assert.ok(bulk.textContent.includes(ev('fmt$(3*(15000+800*6))')), '91 days remaining requires three hires');