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>`:'';