Pie in the Sky: government money for rocket companies
A Gov tab in Pie Control with three state programmes: - Rural Digital Pie Fund: reverse auctions for towns only orbit reaches (a cut-off POP on backhaul, or a small town of your terminals). Ask 90%, 70% or 50% of the reserve against a rival; the lower ask is paid monthly for five years while the town stays 70% served (monthly average) from a 90-day deadline. One bad month warns, two revoke the award and claw back half of the last year's support. - Ex-Im Pie Bank: a BANKS loan of half the value of the pies flying and booked (at most 20% of a full Shortcrust, counted by O7), 1.5-2.5% over 60 months, never offered by the usual banks. Space covenants: launch n pies in a year, keep a pie dish in the lending country. A breach brings the bank's penalty, +3 points, a new launch deadline and, with chaos on, a "data stays home" or landing-rights spat there. - Pitcairn: served from orbit (backhaul or home terminals) at 90% of its demand, latency forgiven, the UK pays a $120k/mo satellite grant. Subsidies count in the orbit's books. tests/pie-gov.test.js covers the features; pie-balance.test.js gains a run with government money, which must pay back sooner by at most two years.
This commit is contained in:
parent
1de0723c35
commit
8b92adcaa8
23 changed files with 719 additions and 27 deletions
|
|
@ -18,6 +18,8 @@ const BANKS={
|
|||
ppp:{name:'Peer Pressure Partners',col:'#00897B',min:'B',amt:[2,5],term:[24,36],covs:['nocache'],model:'transit',blurb:tr('banks.you_repay_with_30_of_your')},
|
||||
astro:{name:'Horoscope Holdings',col:'#5E35B1',min:'CCC',apr:[.02,.3],amt:[1,4],term:[12,24],covs:['friday','nobude'],model:'astro',blurb:tr('banks.your_rate_is_set_by_the')},
|
||||
pizza:{name:'Papa Pizza Capital',col:'#FF7043',min:'BB',apr:[.03,.05],amt:[1,3],term:[12,24],covs:['pizza'],blurb:tr('banks.the_cheapest_money_in_town_there')},
|
||||
// The rocket company's state lender: never calls on its own, offered in Pie Control (99-pie-subsidies.js), sized there.
|
||||
exim:{name:'Ex-Im Pie Bank',col:'#1565C0',min:'C',apr:[.015,.025],amt:[0,0],term:[60,60],covs:['pielaunch','piedish'],pie:true,blurb:tr('banks.exim_blurb')},
|
||||
shark:{name:'Loan Shark Telecom Finance',col:'#37474F',min:'C',apr:[.6,.9],amt:[1,2],term:[4,8],covs:[],shark:true,blurb:tr('banks.always_open_ask_no_questions_do')},
|
||||
};
|
||||
const RATINGS=['C','CCC','B','BB','BBB','A','AA','AAA'];
|
||||
|
|
@ -49,10 +51,13 @@ const COVS={
|
|||
nephew:{l:tr('banks.give_our_ceo_s_nephew_a'),fee:3000,ok:()=>true},
|
||||
yacht:{l:tr('banks.our_chairman_needs_a_yacht_for'),fee:8000,ok:()=>true},
|
||||
pizza:{l:tr('banks.pizza_for_the_whole_noc_after'),each:400,ok:()=>true},
|
||||
// The Ex-Im Pie Bank's space covenants: their numbers live on the loan (l.pie).
|
||||
pielaunch:{l:l=>l&&l.pie?tr('banks.exim_launch_n_pies_by',{n:l.pie.n,d:dateStr(l.pie.by),f:Math.min(l.pie.flown,l.pie.n)}):tr('banks.exim_launch_pies'),ok:l=>pieEximLaunchOk(l)},
|
||||
piedish:{l:l=>tr('banks.exim_keep_a_dish_in',{a:l&&l.pie?pieLicCountry(l.pie.cc):'?'}),ok:l=>pieEximDishOk(l)},
|
||||
blitz:{l:tr('banks.open_a_new_pop_at_least'),ok:l=>S.day-Math.max(l.start,...Object.values(S.pops).map(p=>p.day||0))<=90},
|
||||
};
|
||||
// Conditions read with their price filled in; some cost money every month, one costs money per incident.
|
||||
const covLabel=c=>COVS[c]?COVS[c].l.replace('{price}',fmt$(COVS[c].fee||COVS[c].each||0)):c;
|
||||
const covLabel=(c,l)=>{const C=COVS[c];return !C?c:typeof C.l==='function'?C.l(l):C.l.replace('{price}',fmt$(C.fee||C.each||0));};
|
||||
const loanFees=l=>(l.covs||[]).reduce((a,c)=>a+((COVS[c]&&COVS[c].fee)||0),0);
|
||||
// Good terms are for good credit: every notch below AAA adds to the rate.
|
||||
const RATE_PREM={AAA:0,AA:.005,A:.01,BBB:.02,BB:.04,B:.07,CCC:.12,C:.2};
|
||||
|
|
@ -67,7 +72,7 @@ function rating(){if(!S)return 'BB';const rev=R.revMo||0,pay=(R.cost&&R.cost.loa
|
|||
const rIdx=r=>RATINGS.indexOf(r);
|
||||
function annuity(P,apr,n){const r=apr/12;return r?P*r/(1-Math.pow(1+r,-n)):P/n;}
|
||||
function spawnLoanOffer(emergency){
|
||||
const rt=rating(),keys=Object.keys(BANKS).filter(k=>rIdx(rt)>=rIdx(BANKS[k].min)&&!S.loanOffers.some(o=>o.bank===k)&&!(BANKS[k].equity&&S.loans.some(l=>l.bank===k)));
|
||||
const rt=rating(),keys=Object.keys(BANKS).filter(k=>rIdx(rt)>=rIdx(BANKS[k].min)&&!S.loanOffers.some(o=>o.bank===k)&&!(BANKS[k].equity&&S.loans.some(l=>l.bank===k))&&!BANKS[k].pie);
|
||||
let pool=emergency?keys.filter(k=>['shark','gov','crypto','vult','rev','spk','astro','balloon'].includes(k)):keys.filter(k=>k!=='shark');if(!pool.length)pool=keys;if(!pool.length)return;
|
||||
const k=pick(pool),B=BANKS[k],base=Math.max(60000,R.revMo||0),ra=(a)=>a[0]+Math.random()*(a[1]-a[0]);
|
||||
const amount=niceAmt(base*ra(B.amt)*(emergency?0.6:1)),o={id:uid(),bank:k,amount,exp:S.day+(emergency?10:25),covs:B.covs.slice()};
|
||||
|
|
@ -105,10 +110,10 @@ function loanTick(d){
|
|||
const broken=l.covs.filter(c=>COVS[c]&&!COVS[c].ok(l));
|
||||
if(d-l.start<15||!broken.length){l.breach=0;continue;}
|
||||
l.breach=(l.breach||0)+1;
|
||||
if(l.breach===1)toast(tr('banks.bank_is_unhappy_you_broke_a',{bank:esc(B.name),cond:esc(covLabel(broken[0]))}),'bad',[{l:tr('common.open_bank'),act:'bank',args:{}}]);
|
||||
if(l.breach===1)toast(tr('banks.bank_is_unhappy_you_broke_a',{bank:esc(B.name),cond:esc(covLabel(broken[0],l))}),'bad',[{l:tr('common.open_bank'),act:'bank',args:{}}]);
|
||||
if(l.breach===10||(l.breach>10&&(l.breach-10)%30===0)){
|
||||
if(B.equity){l.share=+(l.share+0.02).toFixed(3);toast(tr('banks.bank_are_circling_they_now_take',{bank:esc(B.name),pct:pct(l.share)}),'bad');}
|
||||
else{const fee=Math.round(l.bal*0.05);l.bal+=fee;l.pay=Math.round(annuity(l.bal,l.apr,Math.max(1,l.left)));S.loanStrikes=(S.loanStrikes||0)+1;toast(tr('banks.penalty_from_bank_fee_added_to',{bank:esc(B.name),fee:fmt$(fee),pay:fmt$(l.pay)}),'bad');}
|
||||
else{const fee=Math.round(l.bal*0.05);l.bal+=fee;l.pay=Math.round(annuity(l.bal,l.apr,Math.max(1,l.left)));S.loanStrikes=(S.loanStrikes||0)+1;toast(tr('banks.penalty_from_bank_fee_added_to',{bank:esc(B.name),fee:fmt$(fee),pay:fmt$(l.pay)}),'bad');if(B.pie)pieEximBreach(l,broken);}
|
||||
sfx('err');}}
|
||||
// monthly statement: payments already leave your cash daily as part of costs
|
||||
for(const l of S.loans.slice()){const B0=BANKS[l.bank];if(B0.equity||!monthiversary(l.start,d))continue;
|
||||
|
|
|
|||
|
|
@ -2,4 +2,11 @@
|
|||
islanders are online through you: a POP with broadband, up and nearly fully served. */
|
||||
const GRANT_MO=300000;
|
||||
const grantOn=r=>!!(S&&S.pops.pcn&&S.pops.pcn.bb&&!(S.pops.pcn.down>S.day)&&sfOf(r,'pcn')>=0.9);
|
||||
function grantFact(c){if(c!=='pcn')return '';const on=grantOn(R);return `<span class="fact${on?' mine':''}">${on?tr('pitcairn.uk_grant_mo',{mo:fmt$(GRANT_MO)}):tr('pitcairn.uk_grant_mo_once_islanders',{mo:fmt$(GRANT_MO)})}</span>`;}
|
||||
/* Satellite tier: Pitcairn online through your pies (its POP on backhaul, or home terminals there) is good enough for the
|
||||
UK at a lower bar, orbit's latency forgiven (sfOf() counts it, so the fiber grant never comes), for less money. */
|
||||
const GRANT_SKY_MO=120000,GRANT_SKY_Q=0.9;
|
||||
function grantSky(r){if(!S||!S.pie||!r||!r.pie||grantOn(r))return false;const p=S.pops.pcn;
|
||||
if(p&&p.bb&&!(p.down>S.day)&&r.pie.bh.some(b=>b.city==='pcn'&&b.g>0)){const d=r.cityDem.pcn||0;if(d>1e-6&&(r.citySrv.pcn||0)/d>=GRANT_SKY_Q)return true;}
|
||||
return S.biz.some(b=>b.city==='pcn'&&b.type==='pizza'&&(r.pie.sf[b.id]||0)>=GRANT_SKY_Q);}
|
||||
function grantFact(c){if(c!=='pcn')return '';const on=grantOn(R),sky=!on&&grantSky(R);
|
||||
return `<span class="fact${on||sky?' mine':''}">${on?tr('pitcairn.uk_grant_mo',{mo:fmt$(GRANT_MO)}):sky?tr('pitcairn.uk_sky_grant_mo',{mo:fmt$(GRANT_SKY_MO),full:fmt$(GRANT_MO)}):tr('pitcairn.uk_grant_mo_once_islanders',{mo:fmt$(GRANT_MO)})}</span>`;}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
- book.earned: revenue from orbit, for the customers that come with routing. */
|
||||
function pieBlank(day){const crusts={};for(const id in CRUSTS)crusts[id]={cohorts:[],queued:0};
|
||||
return {born:day,co:null,fac:false,stock:0,rd:{reuse:false,heavy:false,heavyTests:0},pads:[],crusts,dishes:[],lic:{},q:[],
|
||||
founder:{posts:[],promises:0,broken:0,due:[]},book:{spent:0,earned:0,wouldHave:0},spat:{},safe:false};}
|
||||
founder:{posts:[],promises:0,broken:0,due:[]},book:{spent:0,earned:0,wouldHave:0},spat:{},safe:false,gov:pieGovBlank()};}
|
||||
function pieInit(){if(!S.pie)S.pie=pieBlank(S.day);return S.pie;}
|
||||
// The unlock: only on the Tier 1 transition of a save of this version, and only in a normal game.
|
||||
function pieUnlock(){if(S.pie||!(S.pieV>=1)||S.mode!=='normal'||S.scn)return;pieInit();track('pie_unlock');
|
||||
|
|
@ -107,7 +107,7 @@ function pieDay(d){const P=S.pie;if(!P)return;
|
|||
function pieTier(){const P=S.pie,t1=pieT1();if(P.t1&&!t1&&P.q.length&&!S.stats.pieTour){S.stats.pieTour=1;pieFounder(N_('pie.fp_tour'));}P.t1=t1;}
|
||||
/* The save gate for S.pie: everything clamped, unknown crusts, rockets and cities dropped, pads and dishes only where a
|
||||
POP is. A save without pieV (older versions) never unlocks it; puzzles, scenarios and the Architect never have it. */
|
||||
function pieSanitize(s){s.pieV=int(s.pieV,0,1,0);const p=s.pie,ob=x=>x&&typeof x==='object'&&!Array.isArray(x);
|
||||
function pieSanitize(s){s.pieV=int(s.pieV,0,1,0);pieEximFix(s);const p=s.pie,ob=x=>x&&typeof x==='object'&&!Array.isArray(x);
|
||||
if(!ob(p)||(s.pieV<1&&s.mode!=='sandbox')||s.scn||s.mode==='puzzle'){s.pie=null;return;}
|
||||
const o=pieBlank(int(p.born,0,s.day,s.day)),day=s.day,n=(v,hi)=>int(v,0,hi,0),m=(v,hi)=>clamp(num(v,0),0,hi);
|
||||
if(ob(p.co)){const nm=p.co.name;o.co={name:typeof nm==='string'&&nm.trim()?(PIE_NAMES.includes(nm)?nm:nm.replace(/\s+/g,' ').trim().slice(0,40)):PIE_NAMES[0]};}
|
||||
|
|
@ -132,5 +132,6 @@ function pieSanitize(s){s.pieV=int(s.pieV,0,1,0);const p=s.pie,ob=x=>x&&typeof x
|
|||
o.founder.due=(Array.isArray(F.due)?F.due:[]).map(v=>int(v,0,day+720,day)).sort((a,b)=>a-b).slice(-8);}
|
||||
if(ob(p.book))for(const k of ['spent','earned','wouldHave'])o.book[k]=m(p.book[k],1e15);
|
||||
if(ob(p.spat))for(const k of Object.keys(p.spat)){const D=PIE_SPATS[k];if(!D||!ob(p.spat[k]))continue;const v=D.fix?D.fix(p.spat[k],s):null;if(v)o.spat[k]=v;}
|
||||
o.gov=pieGovFix(p.gov,s);
|
||||
s.pie=o;}
|
||||
const sid0=v=>typeof v==='string'&&v&&v.length<=40?v:uid();
|
||||
|
|
|
|||
117
src/game/60-features/99-pie-subsidies.js
Normal file
117
src/game/60-features/99-pie-subsidies.js
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/* ---------- Pie in the Sky: government money (docs/plans/pie-in-the-sky.md) ----------
|
||||
Two state programmes for a rocket company, kept in S.pie.gov (pieBlank(), repaired by pieGovFix()):
|
||||
- The Rural Digital Pie Fund: reverse auctions for support of a remote town that only orbit reaches (a cut-off POP on
|
||||
backhaul, or a town of your terminal customers with no POP of yours). The lowest ask wins; a rival bids too. A win
|
||||
pays a monthly subsidy (V.gov in compute()) for PIE_RDF_TERM days, while the town's service, averaged over each
|
||||
month, stays at PIE_RDF_NEED from the deadline on. A month below it is a warning; two in a row revoke the award, and
|
||||
PIE_RDF_CLAW of the last year's support goes back.
|
||||
- The Ex-Im Pie Bank: a cheap state loan sized to the constellation (a BANKS entry, so it bills and shows like any
|
||||
loan), with space covenants: launch n pies by a day, keep a pie dish in the lending country. A breach is a loan
|
||||
breach (the bank's penalty), plus tighter terms (PIE_EXIM_PEN on the rate, the launch target rescheduled) and, with
|
||||
chaos on (rule O5), a geopolitical spat in the lending country.
|
||||
Pitcairn's satellite tier of the UK grant is in 85-pitcairn.js. Subsidies count in the orbit's books (book.earned). */
|
||||
const PIE_RDF_MO=5e6,PIE_RDF_P=30,PIE_RDF_TERM=1800,PIE_RDF_DUE=90,PIE_RDF_NEED=0.7,PIE_RDF_CLAW=0.5,PIE_RDF_MAX=6,
|
||||
PIE_RDF_DAYS=20,PIE_RDF_RATE=1/45,PIE_RDF_FAR=60,PIE_RDF_BIDS=[0.9,0.7,0.5],PIE_RDF_RIV=0.4,
|
||||
PIE_EXIM_SHARE=0.5,PIE_EXIM_MIN=250e6,PIE_EXIM_CAPF=0.2,PIE_EXIM_APR=0.015,PIE_EXIM_TERM=60,PIE_EXIM_BY=360,PIE_EXIM_PEN=0.03,
|
||||
PIE_EXIM_RESCHED=180,PIE_EXIM_EVERY=90;
|
||||
// Rival bidders: the old satellite crowd and the local co-op.
|
||||
const PIE_RIVALS=[N_('pie_gov.rival_viasad'),N_('pie_gov.rival_hugsnet'),N_('pie_gov.rival_coop')];
|
||||
const pieGovBlank=()=>({auc:[],aw:[],ex:null,told:0});
|
||||
// A town's service today, from the last compute: a POP's share of its demand served (orbit's latency is accepted: the
|
||||
// fund pays for coverage), or the share its terminal customers get.
|
||||
function pieRdfSrv(c){if(!R||!R.pie)return 0;if(S.pops[c]){const d=R.cityDem[c]||0;return d>1e-6?clamp((R.citySrv[c]||0)/d,0,1):0;}
|
||||
let w=0,g=0;for(const b of S.biz)if(b.city===c&&BIZ_T[b.type].orbit){w+=b.bw;g+=b.bw*Math.min(1,R.pie.sf[b.id]||0);}return w>0?g/w:0;}
|
||||
// Towns the fund will auction: cut-off POPs with home broadband on backhaul, and small towns with no POP of yours where
|
||||
// your terminals are, that are not up for auction or awarded already.
|
||||
function pieRdfCands(){if(!R||!R.pie||!R.pie.hubs.length)return [];const G=S.pie.gov,busy=new Set([...G.auc,...G.aw].map(x=>x.city)),o=new Set();
|
||||
for(const b of R.pie.bh)if(b.land&&S.pops[b.city]&&S.pops[b.city].bb)o.add(b.city);
|
||||
for(const b of S.biz)if(BIZ_T[b.type].orbit&&!S.pops[b.city]&&CITY[b.city].P<=PIE_RDF_FAR)o.add(b.city);
|
||||
return [...o].filter(c=>!busy.has(c)&&!CITY[c].cn).sort();}
|
||||
// The reserve grows with the town, up to a small one's worth: the fund is for the last mile, not for cities.
|
||||
const pieRdfAsk=c=>Math.round(PIE_RDF_MO*(1+Math.min(CITY[c].P,PIE_RDF_FAR)/PIE_RDF_P)/1e5)*1e5;
|
||||
function pieRdfOpen(c){const G=S.pie.gov,a={id:uid(),city:c,ask:pieRdfAsk(c),close:S.day+PIE_RDF_DAYS,riv:+(PIE_RDF_RIV+(1-PIE_RDF_RIV)*Math.random()).toFixed(3),rv:Math.floor(Math.random()*PIE_RIVALS.length)%PIE_RIVALS.length,bid:0};
|
||||
G.auc.push(a);toast(`<b>🏛️ ${tr('pie_gov.t_auction_title')}</b><br>${tr('pie_gov.t_auction',{city:esc(CITY[c].name),mo:fmt$(a.ask),y:PIE_RDF_TERM/360,d:dateStr(a.close)})}`,'goal',[{l:tr('pie_gov.bid'),act:'pieGovOpen',args:{}}]);}
|
||||
// Bids close: the lower ask wins. Silent when you did not bid.
|
||||
function pieRdfClose(a){const G=S.pie.gov,c=esc(CITY[a.city].name);if(!a.bid)return;
|
||||
if(a.bid<=a.riv&&G.aw.length<PIE_RDF_MAX){const d=S.day,w={id:a.id,city:a.city,mo:Math.round(a.ask*a.bid),start:d,due:d+PIE_RDF_DUE,end:d+PIE_RDF_TERM,s:0,n:0,k:0,paid:0};G.aw.push(w);
|
||||
S.stats.pieRdf=(S.stats.pieRdf||0)+1;toast(tr('pie_gov.t_won',{city:c,mo:fmt$(w.mo),p:pct(PIE_RDF_NEED),d:dateStr(w.due)}),'goal',[{l:tr('pie_gov.open'),act:'pieGovOpen',args:{}}]);sfx('coin');}
|
||||
else toast(tr('pie_gov.t_lost',{city:c,rival:tr(PIE_RIVALS[a.rv]),mo:fmt$(Math.round(a.ask*a.riv))}),'bad');}
|
||||
// Revoked: the award ends and part of what it paid goes back (the sandbox only keeps count).
|
||||
function pieRdfRevoke(w,avg){const P=S.pie,G=P.gov,claw=Math.round(Math.min(w.paid,12*w.mo)*PIE_RDF_CLAW);G.aw=G.aw.filter(x=>x!==w);
|
||||
if(!pieSand())S.cash-=claw;P.book.earned=Math.max(0,P.book.earned-claw);S.stats.pieRdfLost=(S.stats.pieRdfLost||0)+1;
|
||||
toast(tr('pie_gov.t_revoked',{city:esc(CITY[w.city].name),p:pct(avg),need:pct(PIE_RDF_NEED),amt:fmt$(claw)}),'bad',[{l:tr('pie_gov.open'),act:'pieGovOpen',args:{}}]);sfx('err');}
|
||||
// What the fund pays this month: every award in force (compute()).
|
||||
function pieGovMo(){const G=S.pie&&S.pie.gov;if(!G)return 0;let v=0;for(const w of G.aw)v+=w.mo;return v;}
|
||||
/* ---- The Ex-Im Pie Bank ---- */
|
||||
// What a pie in orbit is worth to a lender: the pie, its laser and its seat on the cheapest rocket.
|
||||
const pieEximUnit=()=>piePrice(PIE_PIE+PIE_LAS)+piePrice(ROCKETS.falcon.cost)/ROCKETS.falcon.pies;
|
||||
// The most it lends: a share of the cheapest full Shortcrust (rule O7 counts it).
|
||||
const pieEximCap=()=>Math.round(pieFullCost('short')*PIE_EXIM_CAPF/50e6)*50e6;
|
||||
// Sized to the constellation: half the value of the pies flying and booked, between PIE_EXIM_MIN and the cap.
|
||||
function pieEximAmt(){const P=S.pie;let n=pieLiveAll();for(const id in CRUSTS)n+=P.crusts[id].queued;return clamp(Math.round(n*pieEximUnit()*PIE_EXIM_SHARE/50e6)*50e6,PIE_EXIM_MIN,pieEximCap());}
|
||||
const pieEximLoan=()=>(S.loans||[]).find(l=>l.bank==='exim')||null;
|
||||
// The covenants (COVS.pielaunch / COVS.piedish, 10-banks.js).
|
||||
function pieEximLaunchOk(l){const q=l&&l.pie;return !q||S.day<q.by||q.flown>=q.n;}
|
||||
function pieEximDishOk(l){const q=l&&l.pie;return !q||!!S.pie&&S.pie.dishes.some(x=>S.pops[x.city]&&CITY[x.city].cc===q.cc);}
|
||||
// A fresh offer every PIE_EXIM_EVERY days, from a country you have a POP in, while you have a factory and no Ex-Im loan.
|
||||
function pieEximOffer(d){const P=S.pie,G=P.gov;if(!P.fac||pieEximLoan()||!pieCanBuild()){if(G.ex&&pieEximLoan())G.ex=null;return;}if(G.ex&&G.ex.exp>d)return;
|
||||
const ccs=piePopCc();if(!ccs.length)return;const amt=pieEximAmt();
|
||||
G.ex={cc:pick(ccs),amt,apr:+(PIE_EXIM_APR+0.01*Math.random()).toFixed(3),term:PIE_EXIM_TERM,n:Math.ceil(amt/pieEximUnit()/20)*20,exp:d+PIE_EXIM_EVERY};
|
||||
if(!G.told){G.told=1;toast(`<b>🏦 ${tr('pie_gov.t_exim_title')}</b><br>${tr('pie_gov.t_exim',{amt:fmt$(amt),a:esc(pieLicCountry(G.ex.cc))})}`,'goal',[{l:tr('pie_gov.open'),act:'pieGovOpen',args:{}}]);}}
|
||||
// Taking it: a loan like any other, plus its space covenants.
|
||||
function pieEximTake(){const P=S.pie,o=P.gov.ex;if(!o||pieEximLoan())return false;const pay=Math.round(annuity(o.amt,o.apr,o.term));
|
||||
S.cash+=o.amt;S.stats.loans=(S.stats.loans||0)+1;
|
||||
S.loans.push({id:uid(),bank:'exim',start:S.day,amount:o.amt,got:o.amt,bal:o.amt,apr:o.apr,apr0:o.apr,pay,left:o.term,term:o.term,share:0,covs:['pielaunch','piedish'],base:{sub:S.links.filter(x=>x.sub).length},
|
||||
pie:{cc:o.cc,n:o.n,by:S.day+PIE_EXIM_BY,flown:0,br:0}});
|
||||
P.gov.ex=null;track('loan_taken');return true;}
|
||||
// A breach (loanTick(), after the bank's own penalty): tighter terms, the launch target rescheduled, and a spat.
|
||||
function pieEximBreach(l,broken){const q=l.pie;if(!q)return;q.br=(q.br||0)+1;l.apr=+(l.apr+PIE_EXIM_PEN).toFixed(3);l.pay=Math.round(annuity(l.bal,l.apr,Math.max(1,l.left)));
|
||||
if(broken.includes('pielaunch'))q.by=S.day+PIE_EXIM_RESCHED;
|
||||
let sp='';if(S.pie&&pieChaos()){const ids=broken.includes('piedish')?['home','lic']:['lic','home'];for(const id of ids)if(!S.pie.spat[id]&&pieSpatStart(id,q.cc)){sp=id;break;}}
|
||||
toast(tr('pie_gov.t_breach',{a:esc(pieLicCountry(q.cc)),apr:(l.apr*100).toFixed(1)})+(sp?' '+tr('pie_gov.t_breach_spat'):''),'bad');}
|
||||
/* ---- The day ---- */
|
||||
function pieGovDay(d){const P=S.pie;if(!P.co)return;const G=P.gov;
|
||||
if(G.auc.length)for(const a of G.auc.slice())if(d>=a.close){G.auc=G.auc.filter(x=>x!==a);pieRdfClose(a);}
|
||||
for(const w of G.aw.slice()){if(w.start===d)continue;if(d>=w.end){G.aw=G.aw.filter(x=>x!==w);toast(tr('pie_gov.t_done',{city:esc(CITY[w.city].name),amt:fmt$(w.paid)}),'good');continue;}
|
||||
w.paid+=w.mo/30;w.s+=pieRdfSrv(w.city);w.n++;
|
||||
if(w.n>=30){const avg=w.s/w.n;w.s=0;w.n=0;if(d<w.due||avg>=PIE_RDF_NEED){w.k=0;continue;}
|
||||
if(w.k){pieRdfRevoke(w,avg);continue;}w.k=1;toast(tr('pie_gov.t_warn',{city:esc(CITY[w.city].name),p:pct(avg),need:pct(PIE_RDF_NEED)}),'bad',[{l:tr('pie_gov.open'),act:'pieGovOpen',args:{}}]);}}
|
||||
if(!G.auc.length&&G.aw.length<PIE_RDF_MAX&&Math.random()<PIE_RDF_RATE){const cs=pieRdfCands();if(cs.length)pieRdfOpen(pick(cs));}
|
||||
pieEximOffer(d);
|
||||
// The books: the fund and Pitcairn's satellite grant, as compute() counted them.
|
||||
if(R&&R.pie&&R.pie.gov){const v=R.pie.gov.rdf+R.pie.gov.sky;if(v>0)P.book.earned+=v/30;}}
|
||||
PIE_ON.day.push(pieGovDay);
|
||||
// Pies launched count towards the Ex-Im target.
|
||||
PIE_ON.launch.push((L,ok)=>{const l=ok&&!L.test&&pieEximLoan();if(l&&l.pie)l.pie.flown+=L.n;});
|
||||
/* ---- The save gate ---- */
|
||||
function pieGovFix(g,s){const o=pieGovBlank(),day=s.day,ob=x=>x&&typeof x==='object'&&!Array.isArray(x);if(!ob(g))return o;
|
||||
const ccs=new Set(CITIES.map(c=>c.cc)),seen=new Set(),one=x=>isCity(x.city)&&!seen.has(x.city)&&seen.add(x.city),mx=PIE_RDF_MO*20;
|
||||
o.auc=(Array.isArray(g.auc)?g.auc:[]).filter(a=>ob(a)&&one(a)).slice(0,1).map(a=>({id:sid0(a.id),city:a.city,ask:clamp(num(a.ask,0),0,mx),close:int(a.close,0,day+PIE_RDF_DAYS,day),
|
||||
riv:clamp(num(a.riv,1),PIE_RDF_RIV,1),rv:int(a.rv,0,PIE_RIVALS.length-1,0),bid:PIE_RDF_BIDS.includes(a.bid)?a.bid:0}));
|
||||
o.aw=(Array.isArray(g.aw)?g.aw:[]).filter(w=>ob(w)&&one(w)).slice(0,PIE_RDF_MAX).map(w=>{const st=int(w.start,0,day,day);
|
||||
return {id:sid0(w.id),city:w.city,mo:clamp(num(w.mo,0),0,mx),start:st,due:int(w.due,st,st+PIE_RDF_DUE,st+PIE_RDF_DUE),end:int(w.end,st,st+PIE_RDF_TERM,st+PIE_RDF_TERM),
|
||||
s:clamp(num(w.s,0),0,30),n:int(w.n,0,29,0),k:w.k?1:0,paid:clamp(num(w.paid,0),0,mx*PIE_RDF_TERM/30)};}).map(w=>(w.s=Math.min(w.s,w.n),w));
|
||||
if(ob(g.ex)&&ccs.has(g.ex.cc)){const x=g.ex;o.ex={cc:x.cc,amt:clamp(num(x.amt,PIE_EXIM_MIN),0,pieEximCap()),apr:clamp(num(x.apr,PIE_EXIM_APR),0,0.2),term:PIE_EXIM_TERM,n:int(x.n,0,1e5,0),exp:int(x.exp,0,day+PIE_EXIM_EVERY,day)};}
|
||||
o.told=g.told?1:0;return o;}
|
||||
// Ex-Im loans live in S.loans (sanitized there); their covenants' numbers are repaired here, or reset when unreadable.
|
||||
function pieEximFix(s){const ccs=new Set(CITIES.map(c=>c.cc)),home=isCity(s.home)?CITY[s.home].cc:CITIES[0].cc;
|
||||
for(const l of s.loans||[]){if(l.bank!=='exim')continue;const q=l.pie&&typeof l.pie==='object'?l.pie:{};
|
||||
l.pie={cc:ccs.has(q.cc)?q.cc:home,n:int(q.n,0,1e5,0),by:int(q.by,0,s.day+PIE_EXIM_BY,0),flown:int(q.flown,0,1e6,0),br:int(q.br,0,1e4,0)};l.covs=['pielaunch','piedish'];}}
|
||||
/* ---- Pie Control: the Gov tab ---- */
|
||||
function pieGovHtml(){const P=S.pie,G=P.gov,can=pieCanBuild();let h=`<div class="ops-o"><div class="nm">🏛️ ${tr('pie_gov.rdf')}</div><p class="meta">${tr('pie_gov.rdf_note',{y:PIE_RDF_TERM/360,p:pct(PIE_RDF_NEED),c:pct(PIE_RDF_CLAW)})}</p>`;
|
||||
for(const a of G.auc)h+=`<div class="kv"><span>${esc(CITY[a.city].name)} · ${tr('pie_gov.up_to',{mo:fmt$(a.ask)})}</span><b>${tr('pie_gov.closes',{d:dateStr(a.close)})}</b></div>
|
||||
<div class="ops-p">${PIE_RDF_BIDS.map(f=>btn(tr('pie_gov.ask',{mo:fmt$(Math.round(a.ask*f))}),'pieBid',{id:a.id,f},a.bid===f?'pink sm':'ghost sm',!can)).join('')}</div>`;
|
||||
if(!G.auc.length)h+=`<p class="meta">${tr('pie_gov.no_auction')}</p>`;
|
||||
for(const w of G.aw){const s=pieRdfSrv(w.city),ok=s>=PIE_RDF_NEED;
|
||||
h+=`<div class="kv"><span>${esc(CITY[w.city].name)} · ${tr('common.price_mo',{price:fmt$(w.mo)})}</span><b style="color:${ok?'var(--eye)':'var(--bad)'}">${tr('pie_gov.served',{p:pct(s)})}</b></div>
|
||||
<div class="meta">${S.day<w.due?tr('pie_gov.due',{p:pct(PIE_RDF_NEED),d:dateStr(w.due)}):tr('pie_gov.until',{d:dateStr(w.end)})}${w.k?' · <b style="color:var(--bad)">'+tr('pie_gov.warned')+'</b>':''}</div>`;}
|
||||
h+=`</div><div class="ops-o"><div class="nm">🇵🇳 ${tr('pie_gov.pitcairn')}</div><p class="meta">${tr('pie_gov.pitcairn_note',{mo:fmt$(GRANT_MO),sky:fmt$(GRANT_SKY_MO)})}</p>${grantFact('pcn')}</div>`;
|
||||
const l=pieEximLoan(),o=G.ex;h+=`<div class="ops-o"><div class="nm">🏦 ${tr('pie_gov.exim')}</div>`;
|
||||
if(l){const q=l.pie;h+=`<div class="kv"><span>${tr('common.still_owed')}</span><b>${fmt$(l.bal)}</b></div><div class="meta">${loanLine(l)}</div>
|
||||
<div class="meta"><b style="color:${pieEximLaunchOk(l)?'var(--eye)':'var(--bad)'}">${pieEximLaunchOk(l)?'✓':'✗'}</b> ${esc(covLabel('pielaunch',l))}</div>
|
||||
<div class="meta"><b style="color:${pieEximDishOk(l)?'var(--eye)':'var(--bad)'}">${pieEximDishOk(l)?'✓':'✗'}</b> ${esc(covLabel('piedish',l))}</div>`;}
|
||||
else if(o){const pay=Math.round(annuity(o.amt,o.apr,o.term));h+=`<p class="meta">${tr('pie_gov.exim_offer',{amt:fmt$(o.amt),apr:(o.apr*100).toFixed(1),n:o.term,pay:fmt$(pay)})}</p>
|
||||
<div class="meta">• ${tr('pie_gov.cov_launch',{n:o.n,d:dateStr(S.day+PIE_EXIM_BY)})}</div><div class="meta">• ${tr('pie_gov.cov_dish',{a:esc(pieLicCountry(o.cc))})}</div>
|
||||
<p class="meta">${tr('pie_gov.exim_breach',{apr:(PIE_EXIM_PEN*100).toFixed(0)})}</p><div class="btns">${btn(tr('bank.take_the_money'),'pieExim',{},'pink sm',!can)}</div>`;}
|
||||
else h+=`<p class="meta">${tr('pie_gov.exim_none')}</p>`;
|
||||
return h+'</div>';}
|
||||
Loading…
Add table
Add a link
Reference in a new issue