The sales desk answers renewal haggles, each salesperson their way

With the new switch at the sales desk, whoever runs sales answers a
renewal haggle three days after it opens, unless the player did first.
The engineer gives business customers their discount and keeps nerdy
ones at the market price (nobody leaves); the shark holds the old price,
often with a fresh promise, bills a month of the saving, and loses some
(nerds most); the CEO gives 10% more off for a double term, says yes, or
picks a fight. Every answer is a hash of the contract. The switch is
stored only when on, so existing saves are unchanged.
This commit is contained in:
Frederic Jung 2026-11-06 20:56:50 +01:00
parent d7aad7d965
commit 74e8611f8e
No known key found for this signature in database
17 changed files with 238 additions and 6 deletions

View file

@ -16,7 +16,7 @@ const slAutoOn=()=>!!(S&&S.slAuto&&slP()&&(S.slAuto.on||S.slAuto.min));
function slWkOk(x){if(!x||typeof x!=='object'||Array.isArray(x)||!own(SALES,x.p))return null;const n=v=>int(v,0,1e6,0);return {w:n(x.w),p:x.p,n:n(x.n),rev:int(x.rev,0,1e10,0),x:n(x.x),y:n(x.y)};}
const slWkAny=x=>!!x&&(x.n>0||x.x>0);
function slAutoFix(s){const a=s.slAuto&&typeof s.slAuto==='object'&&!Array.isArray(s.slAuto)?s.slAuto:{};
s.slAuto={on:a.on===true,min:SL_MINS.includes(a.min)?a.min:0,wk:slWkOk(a.wk),rep:slWkOk(a.rep)};}
s.slAuto={on:a.on===true,min:SL_MINS.includes(a.min)?a.min:0,wk:slWkOk(a.wk),rep:slWkOk(a.rep)};if(a.ren===true)s.slAuto.ren=true;}
// An old save whose intern ran the sales order: the same switch and minimum, now at the sales desk (they run once someone is there).
function slAutoFrom(s,on,p){if(!on||(s.slAuto&&typeof s.slAuto==='object'))return;s.slAuto={on:p.acc!==false,min:SL_MINS.includes(p.min)?p.min:0,wk:null,rep:null};}
// "This week Dave signed 3 customers (+$41k/mo), declined 17 tiny offers."

View file

@ -0,0 +1,36 @@
/* ---------- The sales desk answers renewal haggles ----------
A customer near the end of its term may ask for a discount (#178, 75-customer-lifecycle.js). With S.slAuto.ren on,
whoever runs sales answers it SL_REN_WAIT days after it opens, so the player can still answer first. Each in their way:
- the engineer talks technology, not price: nerdy customers get an afternoon with the network diagrams and renew at
the market price, now and then halfway; everyone else gets the discount they asked for. Nobody leaves.
- the shark gives nothing away: most renew at the old price, often with a fresh promise, and he bills a month of what
he saved you. Some walk, nerdy ones most of all.
- the CEO settles it on the golf course: a deeper discount than asked for a contract twice as long, a quick yes, or
a fight that ends with the customer gone.
Each answer is a hash of the contract (clR), so no random numbers are drawn. */
const SL_REN_WAIT=3;
const slRenOn=()=>!!(S&&S.slAuto&&S.slAuto.ren&&slP());
// The day the desk answers this haggle: a few days after it opened (30 days before the term ends), today at the earliest.
const slRenAt=b=>b.hag.until-30+SL_REN_WAIT;
function slRenDay(d){if(!slRenOn())return;const p=slP();let any=false;
for(const b of S.biz.slice())if(b.hag&&d>=slRenAt(b)&&d<b.hag.until){slRenOne(b,p);any=true;}
if(any)compute();}
// One haggle: returns what happened (for the tests): 'tech', 'mid', 'cave', 'hold', 'walk', 'golf', 'yes', 'fight'.
function slRenOne(b,p){const ask=b.hag.rate,was=b.rate,mid=clMid(b),nerd=SALES_NERDS.includes(b.type),r=clR(b,'sl|'+p);
const v=x=>({name:esc(slCap()),cust:esc(b.name),...x}),bill=rate=>fmt$(clBill(b,rate));
const keep=(rate,how,key,x,s)=>{clRenew(b,rate);clNote('ren');toast(tr(key,v({price:bill(b.rate),...x})),s===undefined?'good':s,[{l:tr('common.show_me'),act:'custGo',args:{id:b.id}}]);return how;};
const gone=(how,key)=>{clGone(b,'cheap');toast(tr(key,v({})),'bad');sfx('err');return how;};
if(p==='eng'){if(!nerd)return keep(ask,'cave','sales.ren_eng_cave');
return r<0.7?keep(Math.max(ask,Math.min(was,clFair(b))),'tech','sales.ren_eng_tech'):keep(mid,'mid','sales.ren_mid');}
if(p==='shark'){const walk=nerd?0.4:0.12;if(r<walk)return gone('walk','sales.ren_shark_walk');
if(r<walk+0.5){const fee=Math.round(clBill(b,was-ask)),k=clR(b,'slp')<0.5?salesPromise(b):null;
if(k)b.reqs=(b.reqs||[]).concat(k);S.cash-=fee;
const req=k?' '+tr('sales.ceo_promised',{req:esc(typeof REQS[k].l==='function'?REQS[k].l(b):REQS[k].l)}):'';
clRenew(b,was);clNote('ren');toast(tr('sales.ren_shark_hold',v({price:bill(b.rate),fee:fmt$(fee)}))+req,'',[{l:tr('common.show_me'),act:'custGo',args:{id:b.id}}]);return 'hold';}
return keep(mid,'mid','sales.ren_mid');}
if(r<0.25)return gone('fight','sales.ren_ceo_fight');
if(r<0.6){clRenew(b,Math.round(ask*0.9));b.te=clTerm(b,b.te);clNote('ren');
toast(tr('sales.ren_ceo_golf',v({price:bill(b.rate),date:dateStr(b.te)})),'',[{l:tr('common.show_me'),act:'custGo',args:{id:b.id}}]);return 'golf';}
return keep(ask,'yes','sales.ren_ceo_yes',{},'');}
// Under a haggle in Deals: when the desk will answer it.
const slRenRow=b=>slRenOn()&&b.hag.until>S.day?`<div class="meta">${tr('sales.ren_when',{name:esc(slCap()),date:dateStr(Math.max(S.day+1,slRenAt(b)))})}</div>`:'';

View file

@ -117,7 +117,7 @@ const clHags=()=>S?S.biz.reduce((a,b)=>a+(b.hag?1:0),0):0;
function clDealsHtml(){const hs=S.biz.filter(b=>b.hag).sort((a,b)=>a.hag.until-b.hag.until);if(!hs.length)return '';
return `<h3 class="sub4">${tr('lifecycle.renewals')}</h3><p class="meta" style="margin:0 0 6px">${tr('lifecycle.unanswered_matches')}</p>`+hs.map(b=>{const now=BIZ_T[b.type].fiber?b.hag.rate:b.bw*b.hag.rate,was=bizMo(b);
return `<div class="row"><div class="grow"><div class="nm">${esc(b.name)}</div><div class="meta">${esc(BIZ_T[b.type].l)} · ${esc(clWhere(b))} · ${tr('ui.n_d_left',{n:b.hag.until-S.day})}</div>
<div class="meta">${tr('lifecycle.wants_price',{was:fmt$(was),price:fmt$(now),p:pct(1-now/Math.max(1,was))})}</div>
<div class="meta">${tr('lifecycle.wants_price',{was:fmt$(was),price:fmt$(now),p:pct(1-now/Math.max(1,was))})}</div>${slRenRow(b)}
<div class="btns">${btn(tr('lifecycle.match'),'renewMatch',{id:b.id},'green sm')}${btn(tr('lifecycle.meet_halfway',{price:fmt$(clBill(b,clMid(b)))}),'renewMeet',{id:b.id},'sm')}${btn(tr('lifecycle.let_them_go'),'renewLet',{id:b.id},'ghost sm')}</div></div></div>`;}).join('');}
// The contract line on a customer row.
const clTermTxt=b=>clOn(b)&&b.te?(b.hag?tr('lifecycle.renewal_haggle',{date:dateStr(b.te)}):tr('lifecycle.contract_until',{date:dateStr(b.te)})):'';

View file

@ -62,7 +62,7 @@ function dayPost(d){
// contracts: renewals, growth, haggles and leaving (75-customer-lifecycle.js)
clDay(d);
// the sales desk: meetings booked, golf played (38-sales-desk.js)
salesDay(d);
salesDay(d);slRenDay(d);
// own IX members join
for(const c in S.myIx){const m=S.myIx[c];if(d>=m.next&&m.members.length<myFab(c).max){
const cands=NETS.filter(n=>n.type!=='t1'&&!m.members.includes(n.id)&&(n.pops.includes(c)||n.pops.some(p=>CITY[p].reg===CITY[c].reg)));

View file

@ -10,6 +10,7 @@ Object.assign(ACT,{
// The CEO cannot be fired. A board meeting (and its catering) can get you a VP of Sales, who takes over a month later.
// Signing for you (39-sales-auto.js): on or off, and the minimum under which offers are declined.
salesAuto:()=>{if(!slP())return;const A=S.slAuto||(S.slAuto=slAutoNew());A.on=!A.on;sfx('click');after();salesModal();},
salesRen:()=>{if(!slP())return;const A=S.slAuto||(S.slAuto=slAutoNew());if(A.ren)delete A.ren;else A.ren=true;sfx('click');after();salesModal();},
salesMin:()=>{if(!slP())return;const A=S.slAuto||(S.slAuto=slAutoNew());A.min=opsCycle(SL_MINS,A.min);sfx('click');after();salesModal();},
salesVp:()=>{if(slP()!=='ceo'||S.sales.vp)return;if(!spend(SALES_VP))return;S.sales.vp=S.day+SALES_VP_DAYS;toast(tr('sales.vp_asked',{n:SALES_VP_DAYS}),'');after();salesModal();},
});

View file

@ -19,12 +19,15 @@ function salesModal(){if(!S)return;const p=slP(),L=S.sales||{};
// What each of them does in orbit, shown once there is a rocket company to sell for (99-pie-sales.js).
const SL_SKY={eng:N_('sales.eng_sky'),shark:N_('sales.shark_sky'),ceo:N_('sales.ceo_sky')};
const SL_AUTO={eng:N_('sales.auto_eng'),shark:N_('sales.auto_shark'),ceo:N_('sales.auto_ceo')};
const SL_REN={eng:N_('sales.ren_eng'),shark:N_('sales.ren_shark'),ceo:N_('sales.ren_ceo')};
// Signing for you (39-sales-auto.js): the switch, the minimum, and this week's and last week's tally.
function slAutoHtml(p){const A=S.slAuto||slAutoNew(),w=Math.floor(S.day/7),cur=A.wk&&A.wk.w===w&&slWkAny(A.wk)?A.wk:null,rep=A.rep&&A.rep.w===w-1?A.rep:null;
const row=(x,last)=>`<div class="ops-rep">${esc(slWeekLine(x,last))}</div>`;
return `<section class="sl-auto"><h3>${tr('sales.auto')}</h3><p class="meta">${tr(SL_AUTO[p],{name:esc(slCap())})}</p>
<div class="ops-p"><button class="b sm ${A.on?'green':'ghost'}" data-act="salesAuto" data-args='{}' aria-pressed="${A.on}">${tr('sales.p_sign')}: <b>${A.on?tr('common.on'):tr('common.off')}</b></button>
${btn(`${tr('sales.decline_below')}: <b>${A.min?tr('common.price_mo',{price:fmt$(A.min)}):tr('sales.never')}</b>`,'salesMin',{},'ghost sm')}</div>
${rep?row(rep,true):''}${cur?row(cur,false):''}</section>`;}
${rep?row(rep,true):''}${cur?row(cur,false):''}</section>
<section class="sl-auto"><h3>${tr('sales.ren')}</h3><p class="meta">${tr(SL_REN[p],{name:esc(slCap())})}</p>
<div class="ops-p"><button class="b sm ${A.ren?'green':'ghost'}" data-act="salesRen" data-args='{}' aria-pressed="${!!A.ren}">${tr('sales.p_ren')}: <b>${A.ren?tr('common.on'):tr('common.off')}</b></button></div></section>`;}
// On the card in Deals: this week's tally, once there is one.
function slCardLine(){if(!slAutoOn())return '';const A=S.slAuto,x=A.wk&&A.wk.w===Math.floor(S.day/7)&&slWkAny(A.wk)?A.wk:null;return x?esc(slWeekLine(x,false)):'';}