Pie in the Sky: incidents in orbit and geopolitical spats
Solar storms (safe mode saves most pies), food fights (debris, launches dearer for a year, Space Roomba fix), rain fade on tropical dishes, backhoes at the dish, astronomers (VisorSat or science customers sulk), the Founder's 3 a.m. posts and the chaos monkey snipping laser links. Nine spats with two answers each on a bottom sheet: landing rights refused, data stays home, spectrum squabble, kill switch, orbital land grab, jamming, launch diplomacy, not over my airspace. All gated by chaos and 90 quiet days (O5), seeded, repaired by sanitize, translated in every language.
This commit is contained in:
parent
112450d158
commit
727541a9d8
20 changed files with 1266 additions and 11 deletions
|
|
@ -9,7 +9,7 @@
|
|||
- pieLicOk(cc) -> true when landing rights in that country are held and in force
|
||||
- pieCov(id), pieBaked(id), pieUp(id), pieLive(id), pieLiveLas(id) (10-catalog/70-pie.js and below)
|
||||
- PIE_ON.day / .launch / .fail: arrays of f(d) / f(L,ok) / f(L), called by pieDay() and pieFly()
|
||||
- S.pie.spat[id] with PIE_SPATS[id]={fix(o,s),day?(o,d)}: a spat's state, repaired by pieSanitize(), ticked and
|
||||
- S.pie.spat[id] with PIE_SPATS[id]={fix(o,s),day?(o,d),end?(o)}: a spat's state, repaired by pieSanitize(), ticked and
|
||||
dropped when o.until<=d by pieSpatDay(d)
|
||||
- S.pie.crusts[id].down: day a crust is out until (a solar storm); S.pie.dishes[i].down likewise (a backhoe)
|
||||
- pieGlobeData() -> {crusts:[{id,alt,inc,n,las}],dishes:[{city,lat,lon}],pads:[{city,lat,lon,next}],
|
||||
|
|
@ -31,15 +31,15 @@ const pieCoName=()=>{const n=S.pie&&S.pie.co&&S.pie.co.name;return !n?tr(PIE_NAM
|
|||
function pieSpend(v){const P=S.pie;if(pieSand()){P.book.wouldHave+=v;sfx('build');return true;}if(!spend(v))return false;P.book.spent+=v;return true;}
|
||||
function pieCharge(v){const P=S.pie;if(!P||!(v>0))return;if(pieSand())P.book.wouldHave+=v;else{S.cash-=v;P.book.spent+=v;}}
|
||||
function pieMo(){const P=S.pie;if(!P||!P.co)return 0;return PIE_CO_MO+(P.fac?PIE_FAC_MO:0)+P.pads.length*PIE_PAD_MO+P.dishes.length*PIE_DISH_MO;}
|
||||
const pieLiveLas=id=>{const c=S.pie&&S.pie.crusts[id];let n=0;if(c)for(const k of c.cohorts)if(k.las&&S.day-k.day<CRUSTS[id].life)n+=k.n;return n;};
|
||||
const pieLiveLas=id=>{const c=S.pie&&S.pie.crusts[id];let n=0;if(pieLasCut(id))return 0;if(c)for(const k of c.cohorts)if(k.las&&S.day-k.day<CRUSTS[id].life)n+=k.n;return n;};
|
||||
const pieLicOk=cc=>{const l=S.pie&&S.pie.lic[cc];return !!l&&l.state==='ok'&&l.until>S.day;};
|
||||
function pieDishes(){const P=S&&S.pie;if(!P)return [];const o=[];for(const x of P.dishes){if(!S.pops[x.city]||x.down>S.day)continue;const cc=CITY[x.city].cc;if(pieLicOk(cc))o.push({id:x.id,city:x.city,cc,ant:x.ant,g:x.ant*PIE_ANT_G});}return o;}
|
||||
function pieDishes(){const P=S&&S.pie;if(!P)return [];const o=[];for(const x of P.dishes){if(!S.pops[x.city]||x.down>S.day)continue;const cc=CITY[x.city].cc;if(pieLicOk(cc))o.push({id:x.id,city:x.city,cc,ant:x.ant,g:x.ant*PIE_ANT_G*pieDishMul(x)});}return o;}
|
||||
function pieHubs(){return S&&S.pie?Object.keys(CRUSTS).filter(pieUp):[];}
|
||||
function pieGlobeData(){const P=S&&S.pie;if(!P)return {crusts:[],dishes:[],pads:[],launches:[]};const ll=c=>({city:c,lat:CITY[c].lat,lon:CITY[c].lon});
|
||||
return {crusts:Object.keys(CRUSTS).map(id=>({id,alt:CRUSTS[id].alt,inc:CRUSTS[id].inc,n:pieLive(id),las:pieLiveLas(id)})),
|
||||
dishes:P.dishes.map(x=>ll(x.city)),pads:P.pads.map(p=>({...ll(p.city),next:p.next})),launches:P.q.map(L=>({id:L.id,rk:L.rk,cr:L.cr,n:L.n,day:L.day,pad:L.pad}))};}
|
||||
// Spats (geopolitics) register in PIE_SPATS and keep their state in S.pie.spat; this ticks and ends them.
|
||||
function pieSpatDay(d){const sp=S.pie.spat;for(const k of Object.keys(sp)){const o=sp[k],D=PIE_SPATS[k];if(!D||o.until<=d){delete sp[k];continue;}if(D.day)D.day(o,d);}}
|
||||
function pieSpatDay(d){const sp=S.pie.spat;for(const k of Object.keys(sp)){const o=sp[k],D=PIE_SPATS[k];if(!D||o.until<=d){delete sp[k];if(D&&D.end)D.end(o);continue;}if(D.day)D.day(o,d);}}
|
||||
const pieYear=d=>1+Math.floor(d/360);
|
||||
function pieFounder(k,v={}){const F=S.pie.founder,p={d:S.day,k};if(v.n!==undefined)p.n=v.n;if(v.c)p.c=v.c;F.posts.unshift(p);if(F.posts.length>PIE_POSTS)F.posts.length=PIE_POSTS;}
|
||||
// Every promise slips by a year: made today, due in a year, broken then.
|
||||
|
|
@ -60,7 +60,7 @@ function pieQuote(rk,cr,o={}){const P=S.pie;if(!P||!own(ROCKETS,rk)||!own(CRUSTS
|
|||
if(!test&&P.stock<n)return {why:tr('pie.why_stock',{n,have:Math.floor(P.stock)})};
|
||||
if(!test&&pieLive(cr)+P.crusts[cr].queued+n>C.full*PIE_SPARE)return {why:tr('pie.why_full')};
|
||||
const t0=S.day+leadDays(PIE_PREP),pad=pads.slice().sort((a,b)=>Math.max(t0,a.next)-Math.max(t0,b.next)||Math.abs(CITY[a.city].lat)-Math.abs(CITY[b.city].lat))[0];
|
||||
const rocket=piePrice(R0.cost)*(1-pieEq(pad.city)),boost=rk==='again'&&!pad.boosters.length?piePrice(PIE_BOOST):0,pies=n*piePrice(PIE_PIE+(o.las?PIE_LAS:0));
|
||||
const rocket=piePrice(R0.cost)*(1-pieEq(pad.city))*pieCrMul(cr),boost=rk==='again'&&!pad.boosters.length?piePrice(PIE_BOOST):0,pies=n*piePrice(PIE_PIE+(o.las?PIE_LAS:0));
|
||||
const ins=o.ins&&!test?Math.round((rocket+pies)*PIE_INS):0;
|
||||
return {ok:true,test,n,pad:pad.city,day:Math.max(t0,pad.next),cost:Math.round(rocket+boost+pies+ins),insured:Math.round(rocket+pies),ins:!!ins};}
|
||||
// The cheapest a crust can be filled from nothing (one-off costs only): rule O7.
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ function sanitize(s){
|
|||
{const r=s.rules&&typeof s.rules==='object'&&!Array.isArray(s.rules)?s.rules:{};
|
||||
const m={mods:r.mods};s.rules=s.scn&&typeof s.scn==='object'?makeRules('oncall',m):s.mode==='sandbox'?makeRules('sandbox',{...m,chaos:r.chaos}):makeRules(NORMAL_PRESETS.includes(r.preset)?r.preset:'oncall',m);}
|
||||
specSanitize(s);
|
||||
pieSanitize(s);
|
||||
pieSanitize(s);pieIncFix(s);
|
||||
if(s.te){if(typeof s.te!=='object')s.te=null;else{s.te.on=!!s.te.on;s.te.script=typeof s.te.script==='string'?s.te.script.slice(0,4000):'';}}
|
||||
return s;}
|
||||
function migrate(s){sanitize(s);
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ function fireFailure(only){
|
|||
}
|
||||
const gamingCount=()=>S.biz.reduce((n,b)=>n+(BIZ_T[b.type]?.gaming?1:0),0);
|
||||
const FLOOD_WHO=[N_('failures.a_botnet_of_40_000_smart'),N_('failures.every_unpatched_baby_monitor_in'),N_('failures.a_gaming_clan_that_lost_one'),N_('failures.a_fridge_that_achieved_sentience_and'),N_('failures.a_crypto_bro_shorting_your_stock'),N_('failures.a_teenager_with_a_stolen_credit'),N_('failures.a_rival_isp_s_stress_test'),N_('failures.ten_thousand_smart_light_bulbs'),N_('failures.a_printer_just_one_printer_nobody'),N_('failures.a_botnet_run_from_a_cloud'),N_('failures.somebody_who_did_not_like_your'),N_('failures.the_internet_connected_kettles_of_a')];
|
||||
function incTitle(t){return {ring:tr('failures.metro_ring_cut'),site:tr('common.site_outage'),cut:tr('common.fiber_cut'),crash:tr('common.router_crash'),power:tr('common.power_outage'),transit:tr('common.upstream_outage'),ixloop:tr('common.ix_meltdown'),leak:tr('common.route_leak'),ddos:tr('common.ddos_attack'),fabric:tr('common.fabric_outage'),depeer:tr('common.peering_spat'),fatwave:tr('failures.fat_fingered_wave'),label:tr('failures.patch_panel_mishap'),interop:tr('core.interop_failure'),mtu:tr('common.mtu_mismatch'),krroute:tr('failures.rerouted_via_hong_kong'),ctrlplane:tr('failures.control_plane_meltdown'),lacp:tr('common.lacp_trouble'),loss:tr('common.packet_loss'),pmtud:tr('failures.pmtud_black_hole'),oops:tr('common.oops'),cleaner:tr('common.vacuum_incident'),prepend:tr('common.prepend_ageddon'),rpki:tr('common.rpki_invalid'),amp:tr('common.amplifier_failure'),roadmff:tr('failures.fat_fingered_roadm'),optic:tr('common.dead_optic'),maint:tr('common.maintenance_window_3a92'),ac:tr('common.cooling_failure'),hijack:tr('common.bgp_hijack'),shutdown:tr('common.government_shutdown'),redsea:tr('failures.geopolitical_cable_cut')}[t]||tr('common.incident');}
|
||||
function incTitle(t){return {ring:tr('failures.metro_ring_cut'),site:tr('common.site_outage'),cut:tr('common.fiber_cut'),crash:tr('common.router_crash'),power:tr('common.power_outage'),transit:tr('common.upstream_outage'),ixloop:tr('common.ix_meltdown'),leak:tr('common.route_leak'),ddos:tr('common.ddos_attack'),fabric:tr('common.fabric_outage'),depeer:tr('common.peering_spat'),fatwave:tr('failures.fat_fingered_wave'),label:tr('failures.patch_panel_mishap'),interop:tr('core.interop_failure'),mtu:tr('common.mtu_mismatch'),krroute:tr('failures.rerouted_via_hong_kong'),ctrlplane:tr('failures.control_plane_meltdown'),lacp:tr('common.lacp_trouble'),loss:tr('common.packet_loss'),pmtud:tr('failures.pmtud_black_hole'),oops:tr('common.oops'),cleaner:tr('common.vacuum_incident'),prepend:tr('common.prepend_ageddon'),rpki:tr('common.rpki_invalid'),amp:tr('common.amplifier_failure'),roadmff:tr('failures.fat_fingered_roadm'),optic:tr('common.dead_optic'),maint:tr('common.maintenance_window_3a92'),ac:tr('common.cooling_failure'),hijack:tr('common.bgp_hijack'),shutdown:tr('common.government_shutdown'),redsea:tr('failures.geopolitical_cable_cut')}[t]||pieIncTitle(t)||tr('common.incident');}
|
||||
const LINKCUT_TR=['cut','redsea'],LINKCUT_ID=['fatwave','label','interop'],POPDOWN=['crash','power','oops','cleaner','maint','shutdown'],IXDOWN=['ixloop'],TDOWN=['transit','prepend'],LINKEQ=['mtu','amp','roadmff','optic'];
|
||||
function remainUntil(pred){let u=0;for(const x of S.inc)if(pred(x))u=Math.max(u,x.until);return u;}
|
||||
// Remove an incident, then restore each affected thing to whatever other incidents still hold it down.
|
||||
|
|
@ -145,6 +145,7 @@ function clearInc(i){
|
|||
else if(T==='ring'){if(S.pops[i.ref])S.pops[i.ref].ringcut=remainUntil(x=>x.type==='ring'&&x.ref===i.ref);}
|
||||
else if(T==='ac'){if(S.pops[i.ref])S.pops[i.ref].hot=remainUntil(x=>x.type==='ac'&&x.ref===i.ref);}
|
||||
else if(T==='amp'||T==='roadmff'){const l=S.links.find(x=>x.id===i.ref);if(l)l.eqDown=remainUntil(x=>(x.type==='amp'||x.type==='roadmff')&&x.ref===i.ref);}
|
||||
else if(T.startsWith('pie'))pieIncClear(i);
|
||||
else if(T==='optic'){const l=S.links.find(x=>x.id===i.ref);if(l&&!S.inc.some(x=>x.type==='optic'&&x.ref===i.ref))l.chFail=null;}
|
||||
}
|
||||
function purgeInc(){S.inc=S.inc.filter(i=>{const T=i.type;if(LINKCUT_TR.includes(T))return S.links.some(l=>(l.trench||l.id)===i.ref);if(LINKCUT_ID.includes(T)||LINKEQ.includes(T))return S.links.some(l=>l.id===i.ref);if(TDOWN.includes(T))return S.transit.some(t=>t.id===i.ref);if(IXDOWN.includes(T))return S.ixp[i.ref]!==undefined;if(POPDOWN.includes(T)||T==='ac')return !!S.pops[i.ref];return true;});}
|
||||
|
|
|
|||
71
src/game/85-incidents/60-pie.js
Normal file
71
src/game/85-incidents/60-pie.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ---------- Pie in the Sky: incidents in orbit (docs/plans/pie-in-the-sky.md) ----------
|
||||
Rule O5: only with chaos on (chaosMul() reads rule('chaos')), never in the first 90 days after the unlock, so a quiet
|
||||
ruleset (and a sandbox without chaos) has a quiet sky. Each one is an ordinary S.inc entry: the NOC list, fixInc
|
||||
(paying for a fix ends it), the day tick's "resolved", spicy stretching and standing orders all work as for cables.
|
||||
What an incident does is read back from S.inc, so nothing else has to be undone. A booster that tips over on the drone
|
||||
ship is in pieFly(); the astronomers ask a question, so they live with the spats (65-pie-spats.js). */
|
||||
const PIE_INC=['piedig','piefood','pielaser','pierain','piestorm'],PIE_TROPIC=23.5,PIE_ROOMBA=120e6,PIE_FOOD_MUL=0.25,PIE_INC_RATE=1/40,
|
||||
PIE_DIG_FIX=300000,PIE_RAIN=0.3,PIE_ASTRO_N=200;
|
||||
FOUNDER_POSTS.push(N_('pie.fp_3am'),N_('pie.fp_astro'),N_('pie.fp_debris'),N_('pie.fp_spat'),N_('pie.fp_storm'));
|
||||
// Chaos on, a company to annoy, and the 90 quiet days are over.
|
||||
function pieChaos(){const P=S&&S.pie;return !!P&&!!P.co&&chaosMul()>0&&S.day-P.born>=PIE_QUIET;}
|
||||
const pieIncOf=(t,r)=>S.inc.find(i=>i.type===t&&i.ref===r&&i.until>S.day)||null;
|
||||
const pieLiveAll=()=>Object.keys(CRUSTS).reduce((a,id)=>a+pieLive(id),0);
|
||||
// Read by pieDishes(), pieQuote() and pieLiveLas() in 60-features/99-pie-in-the-sky.js.
|
||||
function pieDishMul(x){let m=1;for(const i of S.inc)if(i.type==='pierain'&&i.ref===x.city&&i.until>S.day)m=PIE_RAIN;return m*pieSpatDishMul(x);}
|
||||
function pieCrMul(cr){return 1+(pieIncOf('piefood',cr)?PIE_FOOD_MUL:0)+pieGrabMul();}
|
||||
function pieLasCut(id){return !!S.inc.length&&!!pieIncOf('pielaser',id);}
|
||||
function pieIncTitle(t){return {piedig:tr('pie_inc.t_dig'),piefood:tr('pie_inc.t_food'),pielaser:tr('pie_inc.t_laser'),pierain:tr('pie_inc.t_rain'),piestorm:tr('pie_inc.t_storm')}[t]||'';}
|
||||
// clearInc(): a dish dug up comes back when no other backhoe still holds it.
|
||||
function pieIncClear(i){if(i.type!=='piedig'||!S.pie)return;const x=S.pie.dishes.find(d=>d.city===i.ref);if(x)x.down=remainUntil(o=>o.type==='piedig'&&o.ref===i.ref);}
|
||||
// sanitize(): orbit incidents point at a crust or a city, and go when the company does.
|
||||
function pieIncFix(s){const ok=!!s.pie;s.inc=s.inc.filter(i=>{if(!PIE_INC.includes(i.type))return true;if(!ok)return false;
|
||||
if(['piefood','pielaser','piestorm'].includes(i.type)?!own(CRUSTS,i.ref):!isCity(i.ref))return false;
|
||||
i.start=int(i.start,0,s.day,s.day);i.until=int(i.until,0,s.day+400,s.day);if(i.type==='piestorm')i.f=clamp(num(i.f,0),0,0.4);return true;});}
|
||||
// One day of a storm (its first is the day it starts; the day tick resolves it on its last).
|
||||
function pieStormBite(i){if(!own(CRUSTS,i.ref))return;const n=Math.max(1,i.until-i.start),q=(1-Math.pow(1-i.f,1/n))*(S.pie.safe?0.25:1);i.lost=(i.lost|0)+pieLose(i.ref,q);}
|
||||
// Pies lost from every cohort of a crust alike.
|
||||
function pieLose(cr,q){const c=S.pie.crusts[cr];let lost=0;for(const k of c.cohorts){const x=Math.min(k.n,Math.round(k.n*q));k.n-=x;lost+=x;}c.cohorts=c.cohorts.filter(k=>k.n>=1);return lost;}
|
||||
function pieIncToast(i,press,acts=[]){toast(`<b>🛰️ ${pieIncTitle(i.type)}</b><br>${esc(i.msg)}<br><i>${esc(press)}</i>`,'bad',(i.cost?[{l:`${i.fix||tr('common.rush_repair')} ${fmt$(i.cost)}`,act:'fixInc',args:{id:i.id}}]:[]).concat(acts),incOpen(i));sfx('alert');}
|
||||
const pieAdd=o=>{addInc(o);return S.inc[S.inc.length-1];};
|
||||
function pieIncDay(d){
|
||||
// A storm drags pies down a little every day; safe mode saves three quarters of them, and carries nothing meanwhile.
|
||||
for(const i of S.inc){if(i.type==='piestorm'&&i.until>d&&d>i.start)pieStormBite(i);
|
||||
// spicy chaos stretches an incident (stretchInc); the dish it holds down follows it
|
||||
else if(i.type==='piedig'&&i.until>d){const x=S.pie.dishes.find(o=>o.city===i.ref);if(x&&!(x.down>=i.until))x.down=i.until;}}
|
||||
if(!pieChaos())return;
|
||||
// Rule F4: while the chaos monkey visits, it snips laser links too.
|
||||
if(mkOn()&&Math.random()<1/20)pieIncFire('laser');
|
||||
if(Math.random()<PIE_INC_RATE*chaosMul())pieIncFire();}
|
||||
function pieIncOpts(){const P=S.pie,o=[],live=id=>pieLive(id),dish=x=>!!S.pops[x.city];
|
||||
if(Object.keys(CRUSTS).some(id=>live(id)>0&&!pieIncOf('piestorm',id)))o.push(['storm',2]);
|
||||
if(Object.keys(CRUSTS).some(id=>live(id)>=100&&!pieIncOf('piefood',id)))o.push(['food',0.4]);
|
||||
if(P.dishes.some(x=>dish(x)&&Math.abs(CITY[x.city].lat)<=PIE_TROPIC&&!pieIncOf('pierain',x.city)))o.push(['rain',3]);
|
||||
if(P.dishes.some(x=>dish(x)&&!(x.down>S.day)))o.push(['dig',2]);
|
||||
if(pieLiveAll()>=PIE_ASTRO_N&&!P.spat.astro)o.push(['astro',1]);
|
||||
o.push(['founder',2]);return o;}
|
||||
// Fires one orbit incident (k forces which, for tests and the monkey); true when something happened.
|
||||
function pieIncFire(k){const P=S.pie;if(!P||!P.co)return false;const d=S.day;
|
||||
if(!k){const o=pieIncOpts();let r=Math.random()*o.reduce((a,x)=>a+x[1],0);k=o[o.length-1][0];for(const x of o){r-=x[1];if(r<=0){k=x[0];break;}}}
|
||||
const crs=f=>Object.keys(CRUSTS).filter(f);
|
||||
if(k==='storm'){const c=crs(id=>pieLive(id)>0&&!pieIncOf('piestorm',id));if(!c.length)return false;const cr=pick(c),f=+(0.05+Math.random()*0.35).toFixed(3);
|
||||
const i=pieAdd({type:'piestorm',ref:cr,until:d+7,f,lost:0,cost:0,msg:tr('pie_inc.storm_msg',{crust:tr(CRUSTS[cr].n),p:pct(f)})});pieFounder(N_('pie.fp_storm'),{c:cr});pieStormBite(i);
|
||||
pieIncToast(i,tr('pie_inc.storm_press'),P.safe?[]:[{l:tr('pie_inc.safe_now'),act:'pieSafe',args:{}}]);return true;}
|
||||
if(k==='food'){const c=crs(id=>pieLive(id)>=100&&!pieIncOf('piefood',id));if(!c.length)return false;const cr=pick(c),n=pieLose(cr,0.1+Math.random()*0.1);
|
||||
const i=pieAdd({type:'piefood',ref:cr,until:d+360,cost:piePrice(PIE_ROOMBA),fix:tr('pie_inc.food_fix'),msg:tr('pie_inc.food_msg',{crust:tr(CRUSTS[cr].n),n,p:pct(PIE_FOOD_MUL)})});
|
||||
pieFounder(N_('pie.fp_debris'),{c:cr});pieIncToast(i,tr('pie_inc.food_press'));compute();return true;}
|
||||
if(k==='rain'){const c=P.dishes.filter(x=>S.pops[x.city]&&Math.abs(CITY[x.city].lat)<=PIE_TROPIC&&!pieIncOf('pierain',x.city));if(!c.length)return false;const x=pick(c);
|
||||
const i=pieAdd({type:'pierain',ref:x.city,until:d+rint(2,4),cost:0,msg:tr('pie_inc.rain_msg',{city:CITY[x.city].name})});pieIncToast(i,tr('pie_inc.rain_press'));compute();return true;}
|
||||
if(k==='dig'){const c=P.dishes.filter(x=>S.pops[x.city]&&!(x.down>S.day));if(!c.length)return false;const x=pick(c);
|
||||
const i=pieAdd({type:'piedig',ref:x.city,until:d+rint(2,3),cost:PIE_DIG_FIX,msg:tr('pie_inc.dig_msg',{city:CITY[x.city].name})});x.down=Math.max(x.down||0,i.until);
|
||||
pieIncToast(i,tr('pie_inc.dig_press'));compute();return true;}
|
||||
if(k==='laser'){const c=crs(id=>pieLiveLas(id)>0);if(!c.length)return false;const cr=pick(c);
|
||||
const i=pieAdd({type:'pielaser',ref:cr,until:d+rint(3,4),cost:0,msg:tr('pie_inc.laser_msg',{crust:tr(CRUSTS[cr].n)})});i.until=Math.min(i.until,d+7);
|
||||
if(S.monkey)S.monkey.n++;pieIncToast(i,tr('pie_inc.laser_press'));compute();return true;}
|
||||
if(k==='astro')return pieSpatStart('astro');
|
||||
if(k==='founder'){S.stats.incidents++;S.stats.survived++;pieFounder(N_('pie.fp_3am'));
|
||||
if(Math.random()<0.5){for(const b of S.biz)b.mood=Math.max(1,b.mood-5);toast(`<b>📱 ${tr('pie_inc.t_founder')}</b><br>${tr('pie_inc.founder_dip')}<br><i>${tr('pie_inc.founder_press')}</i>`,'bad');}
|
||||
else{S.ev.viral=Math.max(S.ev.viral||0,d+5);toast(`<b>📱 ${tr('pie_inc.t_founder')}</b><br>${tr('pie_inc.founder_spike')}<br><i>${tr('pie_inc.founder_press')}</i>`,'goal');}
|
||||
sfx('alert');return true;}
|
||||
return false;}
|
||||
PIE_ON.day.push(pieIncDay);
|
||||
129
src/game/85-incidents/65-pie-spats.js
Normal file
129
src/game/85-incidents/65-pie-spats.js
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/* ---------- Pie in the Sky: geopolitical spats (docs/plans/pie-in-the-sky.md) ----------
|
||||
Cartoon diplomacy, even-handed: countries come from the city table (CITIES[].cc, named by the browser), never a
|
||||
leader or a party, and the jokes are about paperwork, food, weather and national pride. Like every incident they need
|
||||
chaos on and 90 quiet days (rule O5); each asks one question with two answers (a bottom sheet, pieSpatSheet()), and an
|
||||
unanswered one decides itself on its deadline. State: S.pie.spat[id] = {st:'ask'|'on', cc, cc2?, ask, until, c, hold…},
|
||||
repaired by pieSpatFix() on load and ended by pieSpatDay() on o.until (then D.end()).
|
||||
Landing rights a spat takes away ('refused' or 'sus' in S.pie.lic) are held in o.hold {cc: days of rights left} and given
|
||||
back, those days and all, when the spat ends. For routing: pieSpatHome(cc) (that country's customers must land on a dish
|
||||
inside it) and pieAirBlock(a,b) (traffic from a must not use a dish in b), on top of pieDishes()' landing rights. */
|
||||
const PIE_SPAT_ASK=20,PIE_SPAT_RATE=1/90,PIE_SPAT_MAX=2,PIE_BAND_DAYS=180,PIE_KILL_DAYS=90,PIE_KILL_MOOD=15,PIE_ASTRO_MOOD=20,PIE_VISOR=50000,
|
||||
PIE_HOME_DAYS=90,PIE_PAD_DISHES=3,PIE_PAD_DAYS=180,PIE_PAD_AID=0.75,PIE_GRAB_N=5,PIE_GRAB_FEE=40e6,PIE_JAM=0.4,PIE_JAM_FILTER=0.8,PIE_JAM_ANT=2e6,
|
||||
PIE_AIR=0.75,PIE_AIR_DAYS=120,PIE_AIR_SUS=60,PIE_LOBBY_DAYS=30;
|
||||
// Country centroids from the city table, once; a neighbour is the nearest other one.
|
||||
let PIE_CC=null;
|
||||
function pieCcAll(){if(PIE_CC)return PIE_CC;const m={};for(const c of CITIES){const o=m[c.cc]||(m[c.cc]={lat:0,lon:0,n:0});o.lat+=c.lat;o.lon+=c.lon;o.n++;}
|
||||
for(const k in m){m[k].lat/=m[k].n;m[k].lon/=m[k].n;}return PIE_CC=m;}
|
||||
function pieNb(cc){const A=pieCcAll(),a=A[cc];let b=null,m=1e9;if(!a)return null;for(const k in A){if(k===cc)continue;const d=hav(a.lon,a.lat,A[k].lon,A[k].lat);if(d<m){m=d;b=k;}}return b;}
|
||||
const pieDishCc=()=>[...new Set(S.pie.dishes.filter(x=>S.pops[x.city]).map(x=>CITY[x.city].cc))].sort();
|
||||
const piePopCc=()=>[...new Set(Object.keys(S.pops).map(c=>CITY[c].cc))].sort();
|
||||
const pieDishesIn=cc=>S.pie.dishes.filter(x=>S.pops[x.city]&&CITY[x.city].cc===cc).length;
|
||||
// A country nobody is already holding hostage.
|
||||
const pieFree=cc=>{const l=S.pie.lic[cc];return !(l&&l.state!=='ok'&&l.until>S.day);};
|
||||
const pieCcN=cc=>esc(pieLicCountry(cc));
|
||||
function pieMood(f,dv){let n=0;for(const b of S.biz)if(f(b)){b.mood=clamp(b.mood+dv,1,100);n++;}return n;}
|
||||
const pieInCc=cc=>b=>isCity(b.city)&&CITY[b.city].cc===cc;
|
||||
// Take a country's landing rights away until o.until, remembering the days left; pieRelease() gives them back.
|
||||
function pieHold(o,cc,state){const P=S.pie,l=P.lic[cc],h=o.hold||(o.hold={});if(!(cc in h))h[cc]=l&&l.state==='ok'&&l.until>S.day?l.until-S.day:0;P.lic[cc]={state,until:o.until};}
|
||||
function pieRelease(o){const P=S.pie;for(const cc in o.hold||{}){const l=P.lic[cc];if(!l||l.state==='ok'||l.until!==o.until)continue;const r=o.hold[cc];if(r>0)P.lic[cc]={state:'ok',until:S.day+r};else delete P.lic[cc];}o.hold={};}
|
||||
const pieSpatEnd=o=>{o.until=S.day+1;};
|
||||
// Read by pieDishMul() (60-pie.js): jamming and a split network turn dishes down.
|
||||
function pieSpatDishMul(x){const sp=S.pie.spat;if(!sp.jam&&!sp.air)return 1;const cc=CITY[x.city].cc;let m=1;
|
||||
if(sp.jam&&(sp.jam.cc===cc||sp.jam.cc2===cc))m*=sp.jam.c===0?PIE_JAM_FILTER:PIE_JAM;
|
||||
if(sp.air&&sp.air.st==='on'&&sp.air.c===0&&(sp.air.cc===cc||sp.air.cc2===cc))m*=PIE_AIR;return m;}
|
||||
function pieGrabMul(){const o=S.pie&&S.pie.spat.grab;return o&&o.st==='on'&&o.left>0?o.m:0;}
|
||||
function pieSpatHome(cc){const o=S&&S.pie&&S.pie.spat.home;return !!o&&o.cc===cc&&!o.ok;}
|
||||
function pieAirBlock(a,b){const o=S&&S.pie&&S.pie.spat.air;return !!o&&o.st==='on'&&o.c===0&&((o.cc===a&&o.cc2===b)||(o.cc===b&&o.cc2===a));}
|
||||
// The spats. pick(o,c): c is 0, 1 or -1 (nobody answered); cost(o,c): what that answer costs now; def: the answer on the deadline.
|
||||
const PIE_SPAT_DEF={
|
||||
air:{n:2,def:0,can:()=>pieDishCc().filter(pieFree).filter(cc=>{const b=pieNb(cc);return b&&pieFree(b);}),
|
||||
start:(o,cc)=>{o.cc=cc;o.cc2=pieNb(cc);},
|
||||
txt:o=>({t:tr('pie_spat.air_t'),b:tr('pie_spat.air_b',{a:pieCcN(o.cc),b:pieCcN(o.cc2)}),p:tr('pie_spat.air_p'),
|
||||
c:[tr('pie_spat.air_c0',{p:pct(PIE_AIR),n:PIE_AIR_DAYS}),tr('pie_spat.air_c1',{n:PIE_AIR_SUS})]}),
|
||||
pick:(o,c)=>{if(c===0){o.until=S.day+PIE_AIR_DAYS;compute();return tr('pie_spat.air_r0',{n:PIE_AIR_DAYS});}
|
||||
o.until=S.day+PIE_AIR_SUS;pieHold(o,o.cc,'sus');pieHold(o,o.cc2,'sus');compute();return tr('pie_spat.air_r1',{a:pieCcN(o.cc),b:pieCcN(o.cc2),d:dateStr(o.until)});}},
|
||||
astro:{n:0,def:1,can:()=>pieLiveAll()>=PIE_ASTRO_N?['']:[],start:o=>{o.n=pieLiveAll();},
|
||||
cost:(o,c)=>c===0?piePrice(o.n*PIE_VISOR):0,
|
||||
txt:o=>({t:tr('pie_spat.astro_t'),b:tr('pie_spat.astro_b',{n:o.n}),p:tr('pie_spat.astro_p'),
|
||||
c:[tr('pie_spat.astro_c0',{cost:fmt$(piePrice(o.n*PIE_VISOR))}),tr('pie_spat.astro_c1',{n:PIE_ASTRO_MOOD})]}),
|
||||
pick:(o,c)=>{pieSpatEnd(o);if(c===0)return tr('pie_spat.astro_r0');pieMood(b=>b.type==='edu'||b.type==='mars',-PIE_ASTRO_MOOD);pieFounder(N_('pie.fp_astro'));return tr('pie_spat.astro_r1');}},
|
||||
band:{n:2,def:-1,can:()=>pieDishCc().filter(pieFree).filter(cc=>{const b=pieNb(cc);return b&&pieFree(b);}),
|
||||
start:(o,cc)=>{o.cc=cc;o.cc2=pieNb(cc);},
|
||||
txt:o=>({t:tr('pie_spat.band_t'),b:tr('pie_spat.band_b',{a:pieCcN(o.cc),b:pieCcN(o.cc2)}),p:tr('pie_spat.band_p'),
|
||||
c:[tr('pie_spat.band_c',{a:pieCcN(o.cc),b:pieCcN(o.cc2),n:PIE_BAND_DAYS}),tr('pie_spat.band_c',{a:pieCcN(o.cc2),b:pieCcN(o.cc),n:PIE_BAND_DAYS})]}),
|
||||
pick:(o,c)=>{if(c<0){o.until=S.day+PIE_BAND_DAYS/2;pieHold(o,o.cc,'sus');pieHold(o,o.cc2,'sus');compute();return tr('pie_spat.band_r_none',{a:pieCcN(o.cc),b:pieCcN(o.cc2),n:PIE_BAND_DAYS/2});}
|
||||
const lose=c===0?o.cc2:o.cc;o.until=S.day+PIE_BAND_DAYS;pieHold(o,lose,'sus');compute();return tr('pie_spat.band_r',{a:pieCcN(c===0?o.cc:o.cc2),b:pieCcN(lose),d:dateStr(o.until)});}},
|
||||
grab:{n:0,def:1,can:()=>S.pie.fac?['']:[],start:()=>{},cost:(o,c)=>c===0?piePrice(PIE_GRAB_FEE):0,
|
||||
txt:()=>({t:tr('pie_spat.grab_t'),b:tr('pie_spat.grab_b'),p:tr('pie_spat.grab_p'),
|
||||
c:[tr('pie_spat.grab_c0',{cost:fmt$(piePrice(PIE_GRAB_FEE)),n:PIE_GRAB_N,p:'10%'}),tr('pie_spat.grab_c1',{n:PIE_GRAB_N,p:'30%'})]}),
|
||||
pick:(o,c)=>{o.m=c===0?0.1:0.3;o.left=PIE_GRAB_N;o.until=S.day+720;return tr('pie_spat.grab_r',{n:PIE_GRAB_N,p:pct(o.m)});}},
|
||||
home:{n:1,def:0,can:()=>S.pie.dishes.length?piePopCc().filter(cc=>!pieDishesIn(cc)):[],start:(o,cc)=>{o.cc=cc;},
|
||||
cost:(o,c)=>c===1?Math.round(pieLicPrice(o.cc)*0.5):0,
|
||||
txt:o=>({t:tr('pie_spat.home_t'),b:tr('pie_spat.home_b',{a:pieCcN(o.cc)}),p:tr('pie_spat.home_p'),
|
||||
c:[tr('pie_spat.home_c0',{n:PIE_HOME_DAYS}),tr('pie_spat.home_c1',{cost:fmt$(Math.round(pieLicPrice(o.cc)*0.5))})]}),
|
||||
pick:(o,c)=>{if(c===1){o.ok=1;pieSpatEnd(o);return tr('pie_spat.home_r1');}o.until=S.day+PIE_HOME_DAYS;return tr('pie_spat.home_r0',{a:pieCcN(o.cc),d:dateStr(o.until)});},
|
||||
day:(o,d)=>{if(o.st==='on'&&!o.ok&&pieDishesIn(o.cc)){o.ok=1;pieSpatEnd(o);pieMood(pieInCc(o.cc),5);toast(tr('pie_spat.home_won',{a:pieCcN(o.cc)}),'good');}},
|
||||
end:o=>{if(o.st!=='on'||o.ok)return;const f=pieLicPrice(o.cc);pieCharge(f);pieMood(pieInCc(o.cc),-10);toast(tr('pie_spat.home_fined',{a:pieCcN(o.cc),cost:fmt$(f)}),'bad');}},
|
||||
jam:{n:2,def:1,can:()=>pieDishCc().filter(cc=>pieNb(cc)),
|
||||
start:(o,cc)=>{o.cc=cc;o.cc2=pieNb(cc);o.until=S.day+rint(5,6);o.ask=o.until-1;compute();},
|
||||
cost:(o,c)=>c===0?piePrice(PIE_JAM_ANT)*(pieDishesIn(o.cc)+pieDishesIn(o.cc2)):0,
|
||||
txt:o=>({t:tr('pie_spat.jam_t'),b:tr('pie_spat.jam_b',{a:pieCcN(o.cc),b:pieCcN(o.cc2),p:pct(PIE_JAM),d:dateStr(o.until)}),p:tr('pie_spat.jam_p'),
|
||||
c:[tr('pie_spat.jam_c0',{cost:fmt$(piePrice(PIE_JAM_ANT)*(pieDishesIn(o.cc)+pieDishesIn(o.cc2))),p:pct(PIE_JAM_FILTER)}),tr('pie_spat.jam_c1',{p:pct(PIE_JAM)})]}),
|
||||
pick:(o,c)=>{compute();return c===0?tr('pie_spat.jam_r0',{p:pct(PIE_JAM_FILTER)}):tr('pie_spat.jam_r1',{d:dateStr(o.until)});},end:()=>compute()},
|
||||
kill:{n:1,def:0,can:()=>pieDishCc().filter(pieFree),start:(o,cc)=>{o.cc=cc;},
|
||||
txt:o=>({t:tr('pie_spat.kill_t'),b:tr('pie_spat.kill_b',{a:pieCcN(o.cc)}),p:tr('pie_spat.kill_p'),
|
||||
c:[tr('pie_spat.kill_c0',{a:pieCcN(o.cc),n:PIE_KILL_MOOD}),tr('pie_spat.kill_c1',{n:PIE_KILL_DAYS})]}),
|
||||
pick:(o,c)=>{if(c===0){pieSpatEnd(o);const n=pieMood(pieInCc(o.cc),-PIE_KILL_MOOD);return tr('pie_spat.kill_r0',{n});}
|
||||
o.until=S.day+PIE_KILL_DAYS;pieHold(o,o.cc,'sus');compute();return tr('pie_spat.kill_r1',{a:pieCcN(o.cc),d:dateStr(o.until)});}},
|
||||
lic:{n:1,def:1,can:()=>pieDishCc().filter(pieFree),start:(o,cc)=>{o.cc=cc;o.n=rint(90,91);},
|
||||
cost:(o,c)=>c===0?Math.round(pieLicPrice(o.cc)*0.25):0,
|
||||
txt:o=>({t:tr('pie_spat.lic_t'),b:tr('pie_spat.lic_b',{a:pieCcN(o.cc)}),p:tr('pie_spat.lic_p',{a:pieCcN(o.cc)}),
|
||||
c:[tr('pie_spat.lic_c0',{cost:fmt$(Math.round(pieLicPrice(o.cc)*0.25)),n:PIE_LOBBY_DAYS}),tr('pie_spat.lic_c1',{n:o.n})]}),
|
||||
pick:(o,c)=>{o.until=S.day+(c===0?PIE_LOBBY_DAYS:o.n);pieHold(o,o.cc,'refused');compute();return tr('pie_spat.lic_r',{a:pieCcN(o.cc),d:dateStr(o.until)});}},
|
||||
pad:{n:1,def:1,can:()=>piePopCc().filter(cc=>CITIES.some(c=>c.cc===cc&&pieCoast(c.id))&&!S.pie.pads.some(p=>CITY[p.city].cc===cc)),start:(o,cc)=>{o.cc=cc;},
|
||||
txt:o=>({t:tr('pie_spat.pad_t'),b:tr('pie_spat.pad_b',{a:pieCcN(o.cc),n:PIE_PAD_DISHES}),p:tr('pie_spat.pad_p'),
|
||||
c:[tr('pie_spat.pad_c0',{n:PIE_PAD_DISHES,a:pieCcN(o.cc),d:PIE_PAD_DAYS}),tr('pie_spat.pad_c1')]}),
|
||||
pick:(o,c)=>{if(c!==0){pieSpatEnd(o);return tr('pie_spat.pad_r1');}o.until=S.day+PIE_PAD_DAYS;return tr('pie_spat.pad_r0',{n:PIE_PAD_DISHES,a:pieCcN(o.cc),d:dateStr(o.until)});},
|
||||
day:(o,d)=>{if(o.st!=='on'||o.ok||o.fail)return;
|
||||
if(pieDishesIn(o.cc)>=PIE_PAD_DISHES){o.ok=1;pieSpatEnd(o);const P=S.pie,c=Object.keys(S.pops).filter(x=>CITY[x].cc===o.cc&&pieCoast(x)&&!P.pads.some(p=>p.city===x)).sort()[0];
|
||||
if(c&&P.pads.length<PIE_PAD_MAX){P.pads.push({city:c,next:d,boosters:[]});toast(tr('pie_spat.pad_won',{city:CITY[c].name}),'goal');}
|
||||
else{const v=Math.round(piePrice(PIE_PAD)*PIE_PAD_AID);pieRefund(v);toast(tr('pie_spat.pad_cheque',{a:pieCcN(o.cc),cost:fmt$(v)}),'goal');}sfx('coin');return;}
|
||||
if(d>=o.until-1){o.fail=1;o.until=d+PIE_AIR_SUS;pieHold(o,o.cc,'sus');compute();toast(tr('pie_spat.pad_failed',{a:pieCcN(o.cc),d:dateStr(o.until)}),'bad');}}},
|
||||
};
|
||||
const PIE_SPAT_KEYS=Object.keys(PIE_SPAT_DEF);
|
||||
// Sanitize: only what the spat needs, countries that exist, days in range.
|
||||
function pieSpatFix(id,o,s){const D=PIE_SPAT_DEF[id],A=pieCcAll(),day=s.day,cc=v=>typeof v==='string'&&own(A,v);
|
||||
const v={st:o.st==='on'?'on':'ask',ask:int(o.ask,0,day+PIE_SPAT_ASK,day),until:int(o.until,0,day+720,day),c:int(o.c,-1,1,-1)};
|
||||
if(D.n>=1){if(!cc(o.cc))return null;v.cc=o.cc;}if(D.n>=2){if(!cc(o.cc2)||o.cc2===o.cc)return null;v.cc2=o.cc2;}
|
||||
if(o.hold&&typeof o.hold==='object'){v.hold={};for(const k of Object.keys(o.hold))if(cc(k))v.hold[k]=int(o.hold[k],0,PIE_LIC_DAYS*10,0);}
|
||||
if(o.n!==undefined)v.n=int(o.n,0,1e6,0);if(o.ok)v.ok=1;if(o.fail)v.fail=1;
|
||||
if(id==='grab'){v.m=clamp(num(o.m,0.3),0,0.3);v.left=int(o.left,0,PIE_GRAB_N,0);}
|
||||
return v;}
|
||||
// The day: an unanswered spat decides itself on its deadline.
|
||||
function pieSpatTick(id,o,d){const D=PIE_SPAT_DEF[id];if(o.st==='ask'&&d>=o.ask){pieSpatChoose(id,D.def,true);return;}if(D.day)D.day(o,d);}
|
||||
for(const id of PIE_SPAT_KEYS)PIE_SPATS[id]={fix:(o,s)=>pieSpatFix(id,o,s),day:(o,d)=>pieSpatTick(id,o,d),end:o=>{const D=PIE_SPAT_DEF[id];if(D.end)D.end(o);pieRelease(o);}};
|
||||
// Starts one (id forces which, for tests and the astronomers); true when it did.
|
||||
function pieSpatStart(id){const P=S.pie;if(!P||!P.co)return false;
|
||||
if(!id){const ok=PIE_SPAT_KEYS.filter(k=>k!=='astro'&&!P.spat[k]&&PIE_SPAT_DEF[k].can().length);if(!ok.length)return false;id=pick(ok);}
|
||||
const D=PIE_SPAT_DEF[id];if(!D||P.spat[id])return false;const cs=D.can();if(!cs.length)return false;
|
||||
const o={st:'ask',ask:S.day+PIE_SPAT_ASK,c:-1};D.start(o,pick(cs));if(!o.until)o.until=o.ask+1;P.spat[id]=o;
|
||||
S.stats.incidents++;S.stats.pieSpat=(S.stats.pieSpat||0)+1;pieFounder(N_('pie.fp_spat'));
|
||||
const t=D.txt(o);toast(`<b>🌍 ${t.t}</b><br>${t.b}`,'bad',[{l:tr('pie_spat.decide'),act:'pieSpatOpen',args:{id}}]);sfx('alert');return true;}
|
||||
// The answer: what it costs (sandbox keeps count), what happens, and the press office's line.
|
||||
function pieSpatChoose(id,c,auto){const P=S.pie,o=P&&P.spat[id],D=PIE_SPAT_DEF[id];if(!o||!D||o.st!=='ask')return false;
|
||||
const cost=D.cost&&c>=0?D.cost(o,c):0;if(cost>0&&!pieSpend(cost))return false;
|
||||
o.st='on';o.c=c;const r=D.pick(o,c);S.stats.survived++;
|
||||
toast(`<b>🌍 ${D.txt(o).t}</b><br>${auto?tr('pie_spat.auto')+' ':''}${r}<br><i>${D.txt(o).p}</i>`,auto?'bad':'',[]);return true;}
|
||||
// The NOC card and Pie Control list the questions waiting for an answer.
|
||||
function pieSpatCard(){const P=S&&S.pie;if(!P)return '';const ks=PIE_SPAT_KEYS.filter(k=>P.spat[k]&&P.spat[k].st==='ask');if(!ks.length)return '';
|
||||
return `<div class="pspat-l">${ks.map(k=>`<div class="kv"><span>🌍 ${PIE_SPAT_DEF[k].txt(P.spat[k]).t}</span>${btn(tr('pie_spat.decide'),'pieSpatOpen',{id:k},'pink sm')}</div>`).join('')}</div>`;}
|
||||
function pieSpatSheet(id){const o=S&&S.pie&&S.pie.spat[id],D=PIE_SPAT_DEF[id];if(!o||!D)return;const t=D.txt(o);
|
||||
let h=`<div style="display:flex;align-items:center"><div class="grow"><div class="eyebrow">🌍 ${tr('pie_spat.eyebrow')}</div><h2 style="font-size:22px">${t.t}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
h+=`<p class="lead">${t.b}</p><p class="meta"><i>${t.p}</i></p>`;
|
||||
if(o.st==='ask')h+=`<p class="meta">${tr('pie_spat.decide_by',{d:dateStr(o.ask)})}</p><div class="pspat-c">${t.c.map((l,c)=>{const v=D.cost?D.cost(o,c):0;return btn(l,'pieSpatPick',{id,c},c?'ghost':'pink',v>0&&!pieSand()&&S.cash<v);}).join('')}</div>`;
|
||||
else h+=`<p class="meta">${tr('pie_spat.decided')}</p>`;
|
||||
openModal(h,'pie-spat');}
|
||||
// A land grab bills the next few launches (counted when they are booked, which is when the quote is paid).
|
||||
function pieGrabUse(q){const o=S.pie&&S.pie.spat.grab;if(!o||o.st!=='on'||!(o.left>0))return;o.left--;if(!o.left)pieSpatEnd(o);}
|
||||
function pieSpatDayAll(d){if(!pieChaos())return;const P=S.pie;if(Object.keys(P.spat).length>=PIE_SPAT_MAX)return;if(Math.random()<PIE_SPAT_RATE*chaosMul())pieSpatStart();}
|
||||
PIE_ON.day.push(pieSpatDayAll);
|
||||
|
|
@ -14,7 +14,7 @@ Object.assign(ACT,{
|
|||
P.rd[k]=true;toast(tr('pie.t_rd',{rd:tr(PIE_RD[k].n)}),'good');if(k==='heavy')piePromise();pieRe();},
|
||||
pieLaunch:({rk,cr})=>{const P=pieGet();if(!P)return;const o={ins:!!UI.pieIns,las:!!UI.pieLas},q=pieQuote(rk,cr,o);if(!q.ok)return pieNo(q.why);if(!pieSpend(q.cost))return pieRe();
|
||||
const pad=P.pads.find(p=>p.city===q.pad);pad.next=q.day+leadDays(ROCKETS[rk].gap);if(rk==='again'&&!pad.boosters.length)pad.boosters.push({id:uid(),flights:0});
|
||||
P.stock=Math.max(0,P.stock-q.n);P.crusts[cr].queued+=q.n;P.q.push({id:uid(),rk,cr,pad:q.pad,n:q.n,day:q.day,cost:q.ins?q.insured:0,ins:q.ins,las:o.las&&!q.test,test:q.test});
|
||||
P.stock=Math.max(0,P.stock-q.n);P.crusts[cr].queued+=q.n;P.q.push({id:uid(),rk,cr,pad:q.pad,n:q.n,day:q.day,cost:q.ins?q.insured:0,ins:q.ins,las:o.las&&!q.test,test:q.test});pieGrabUse(q);
|
||||
{const v={n:q.n,crust:tr(CRUSTS[cr].n),city:CITY[q.pad].name,d:dateStr(q.day)};toast(q.test?tr('pie.t_queued_test',v):tr('pie.t_queued',v),'good');}pieRe();},
|
||||
pieIns:()=>{UI.pieIns=!UI.pieIns;sfx('click');pieModal();},
|
||||
pieLas:()=>{UI.pieLas=!UI.pieLas;sfx('click');pieModal();},
|
||||
|
|
|
|||
7
src/game/90-actions/98-pie-spats.js
Normal file
7
src/game/90-actions/98-pie-spats.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// Pie in the Sky: answering a geopolitical spat (85-incidents/65-pie-spats.js). Answers work while Tier 1 is lost too:
|
||||
// diplomacy is not building.
|
||||
Object.assign(ACT,{
|
||||
pieSpatOpen:({id})=>{if(!S||!S.pie||typeof id!=='string'||!own(PIE_SPAT_DEF,id)||!S.pie.spat[id])return;pieSpatSheet(id);},
|
||||
pieSpatPick:({id,c})=>{const P=S&&S.pie;c=+c;if(!P||typeof id!=='string'||!own(PIE_SPAT_DEF,id)||!(c===0||c===1))return;
|
||||
if(!pieSpatChoose(id,c,false)){if(P.spat[id])pieSpatSheet(id);return;}closeModal();after();},
|
||||
});
|
||||
|
|
@ -3,7 +3,7 @@ let PIE_CCN=null;
|
|||
function pieLicCountry(cc){try{PIE_CCN=PIE_CCN&&PIE_CCN.l===LANG?PIE_CCN:{l:LANG,d:new Intl.DisplayNames([LANG],{type:'region'})};return PIE_CCN.d.of(cc)||cc;}catch(e){return cc;}}
|
||||
function pieCard(){if(!pieOn())return '';const P=S.pie;
|
||||
return `<div class="ops-card pie-card"><div class="nm">🥧 ${tr('pie.pie_in_the_sky')}</div><div class="meta">${P&&P.co?esc(pieCoName())+' · '+tr('pie.card_live',{n:Object.keys(CRUSTS).reduce((a,id)=>a+pieLive(id),0),q:P.q.length}):tr('pie.card_pitch')}</div>
|
||||
<div class="btns">${btn(tr('pie.open_pie_control'),'pieOpen',{},P&&P.co?'sm':'pink sm')}</div></div>`;}
|
||||
${pieSpatCard()}<div class="btns">${btn(tr('pie.open_pie_control'),'pieOpen',{},P&&P.co?'sm':'pink sm')}</div></div>`;}
|
||||
const pieTag=(t,on)=>`<span class="tag ${on?'open':'selective'}">${t}</span>`;
|
||||
function pieModal(){if(!S||!pieOn())return;const P=S.pie||pieBlank(S.day),can=pieCanBuild(),T=['co','fly','dish','book'].includes(UI.pieTab)?UI.pieTab:'co';
|
||||
let h=`<div style="display:flex;align-items:center"><div class="grow"><div class="eyebrow">${tr('pie.pie_in_the_sky')}</div><h2 style="font-size:24px">${P.co?esc(pieCoName()):tr('pie.pie_control')}</h2></div><button class="x" data-act="closeModal" aria-label="${tr('common.close')}">×</button></div>`;
|
||||
|
|
@ -11,6 +11,7 @@ function pieModal(){if(!S||!pieOn())return;const P=S.pie||pieBlank(S.day),can=pi
|
|||
if(pieSand())h+=`<p class="note">${tr('pie.sandbox_note',{amt:fmt$(P.book.wouldHave)})}</p>`;
|
||||
if(!P.co){h+=`<p class="lead">${tr('pie.found_pitch')}</p><div class="btns">${btn(tr('pie.found_price',{price:fmt$(piePrice(PIE_CO)),mo:fmt$(PIE_CO_MO)}),'pieFound',{},'pink',!can)}</div>`;openModal(h,'pie');return;}
|
||||
const tab=(k,l)=>`<button class="b sm ${T===k?'pink':'ghost'}" data-act="pieTab" data-args='{"t":"${k}"}' aria-pressed="${T===k}">${l}</button>`;
|
||||
h+=pieGlobeHtml()+pieSpatCard();
|
||||
h+=`<div class="seg" style="margin:6px 0 10px">${tab('co',tr('pie.tab_company'))}${tab('fly',tr('pie.tab_launch'))}${tab('dish',tr('pie.tab_dishes'))}${tab('book',tr('pie.tab_founder'))}</div>`;
|
||||
const cities=Object.keys(S.pops).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)),c=S.pops[UI.pieCity]?UI.pieCity:cities[0];
|
||||
const sel=`<div class="trsel"><label>${tr('common.your_pop')}<select data-chg="pieCity">${cities.map(x=>`<option value="${x}"${x===c?' selected':''}>${esc(CITY[x].name)}</option>`).join('')}</select></label></div>`;
|
||||
|
|
@ -43,4 +44,4 @@ function pieModal(){if(!S||!pieOn())return;const P=S.pie||pieBlank(S.day),can=pi
|
|||
if(pieSand())h+=`<div class="kv"><span>${tr('pie.would_have')}</span><b>${fmt$(P.book.wouldHave)}</b></div>`;
|
||||
h+=`<h3 style="font-size:15px;margin:10px 0 4px">${tr('pie.founder_feed')}</h3>`+(F.posts.length?F.posts.map(p=>`<div class="ops-rep"><div class="eyebrow">${esc(dateStr(p.d))}</div><div>${esc(pieFpText(p))}</div></div>`).join(''):`<p class="meta">${tr('pie.feed_empty')}</p>`);
|
||||
}
|
||||
openModal(h,'pie');}
|
||||
openModal(h,'pie');{const cv=document.querySelector('#modal .pgcv');if(cv)pieGlobeOpen(cv,pieGlobeData);}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue