257b06d6d2
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
811 lines
75 KiB
JavaScript
811 lines
75 KiB
JavaScript
// Reach Ladder plan simulator (unlisted /plan-lab). Built from the working artifact, 2026-09-27.
|
||
(function(){
|
||
// ── the plan: width, ladder, gap rule ──
|
||
// unq: what a pass-up does at an unqualified member ('skip' = passes over them; 'licence' = buys their next licence, never cash)
|
||
// wm: cash watermark. A member who qualifies late is paid cash only by their own directs and by positions created after they qualified.
|
||
const PLAN = { w: 4, maxL: 8, shape: 'stepped', steps: [20,40,75,125,200,300,500,750], gap: 'fund', unq: 'licence', wm: true,
|
||
// placeholder products, one per level, until the real ones exist (Marty, 27 Sep): edit in the plan row
|
||
place: 'spread', // DECIDED 28 Sep: spillover placement: 'shallow' = shallowest open slot; 'spread' = the position with the fewest under it first (then shallowest)
|
||
zero: false, // cash with no recruits: false = entries only; true = entries + level-2 cash from your own depth 1
|
||
split: 0.25, // entry split: this share of the net entry to the placement upline, the rest to the recruiter (PROPOSED 28 Sep: 25/75, was 50/50)
|
||
sponsor: 0.5, // PROPOSED 28 Sep: this share of every level purchase follows the SPONSOR line (the recruiter, their recruiter...). The rest takes the depth/reach route
|
||
fsTake: 0.20, // Fast Start: share of new joins who buy levels 2..fsLevels on the day they join (uptake is a guess; drag it)
|
||
fsLevels: 3,
|
||
half: true, // one-direct half step: one recruit unlocks cash from depths 1-2 (levels 2-3); two recruits unlock full reach
|
||
fee: 0.20, // admin fee, OUT of every price, to a receiver wallet in the same block (Marty, 27 Sep: 20%, same as InstantAdPay). The other 80% climbs.
|
||
products: ['Widget 1','Widget 2','Widget 3','Widget 4','Widget 5','Widget 6','Widget 7','Widget 8'] };
|
||
function product(L){ return PLAN.products[L - 1] || ('Widget ' + L); }
|
||
function net(L){ return price(L) * (1 - PLAN.fee); } // what climbs after the admin fee
|
||
const MAXD = { 2: 8, 3: 5, 4: 4, 5: 3 }, DEFD = { 2: 6, 3: 4, 4: 3, 5: 3 }; // drawable depth per width
|
||
function price(L){
|
||
const P = Number(document.getElementById('price').value) || 0;
|
||
if (PLAN.shape === 'flat') return P;
|
||
if (PLAN.shape === 'linear') return P * L;
|
||
if (PLAN.shape === 'ratio') return Math.round(P * Math.pow(1.25, L - 1));
|
||
const s = PLAN.steps; if (L <= s.length) return s[L - 1];
|
||
const r = s.length > 1 && s[s.length - 2] ? s[s.length - 1] / s[s.length - 2] : 1.5;
|
||
return Math.round(s[s.length - 1] * Math.pow(r, L - s.length));
|
||
}
|
||
const $$ = n => '$' + Math.round(n).toLocaleString('en-US');
|
||
const cnt = n => Math.round(n).toLocaleString('en-US');
|
||
|
||
// ── the drawn tree ──
|
||
let DEPTHS = 3, W = 1400, ROW = 0;
|
||
const H = 470, TOP = 48, GUT = 250;
|
||
const svg = document.getElementById('tree');
|
||
const NS = 'http://www.w3.org/2000/svg';
|
||
function geometry(){ W = Math.max(1400, GUT + Math.pow(PLAN.w, DEPTHS) * 9 + 30); ROW = (H - TOP - 30) / DEPTHS; svg.setAttribute('viewBox', '0 0 ' + W + ' ' + H); svg.style.minWidth = Math.max(980, Math.round(W * 0.8)) + 'px'; }
|
||
let quiet = false, tally = null, tallyOrigin = null, licUpFlag = false;
|
||
// audit: every dollar spent must be received by someone (a position, or 'above'); licences are never money
|
||
const AUD = { spent: 0, received: 0, above: 0, treasury: 0, entryFee: 0 };
|
||
function feeOn(gross, entry){ const f = gross * PLAN.fee; AUD.received += f; if (entry) AUD.entryFee += f; else AUD.treasury += f; } // the admin wallet's share of a gross price
|
||
window.reachAudit = () => ({ treasury: Math.round(AUD.treasury * 100) / 100, entryFee: Math.round(AUD.entryFee * 100) / 100, spent: Math.round(AUD.spent * 100) / 100, received: Math.round(AUD.received * 100) / 100, above: Math.round(AUD.above * 100) / 100, ok: Math.abs(AUD.spent - AUD.received) <= 0.01 + 1e-9 * AUD.spent });
|
||
function tallyFor(d){ return tally[d] || (tally[d] = { n: 0, L: 0, youCash: 0, youLic: 0, above: 0, licUp: 0, cash: {}, lic: {} }); }
|
||
let nodes = [], byId = {}, you, totals, youLedger = [], nextId = 0;
|
||
function mkNode(depth, parent, idx){
|
||
const n = { id: nextId++, depth, parent, idx, children: [], level: 1, directs: 2, get qual(){ return this.directs >= 2; }, cashFrom: 0, cashFromHalf: 0, cash: 0, entry: 0, x: 0, y: 0 };
|
||
nodes.push(n); byId[n.id] = n;
|
||
if (parent) { parent.children.push(n); parent.entry += net(1); AUD.spent += price(1); AUD.received += net(1); feeOn(price(1), true); if (parent === you) { totals.entry += net(1); } } // Rule 0: the entry pays the upline directly above
|
||
return n;
|
||
}
|
||
function layout(){
|
||
for (const n of nodes) {
|
||
const slots = Math.pow(PLAN.w, n.depth), slotW = (W - GUT - 30) / slots;
|
||
n.x = GUT + slotW * (n.idx + 0.5); n.y = TOP + n.depth * ROW;
|
||
}
|
||
}
|
||
function radius(n){ if (n === you) return 17; const s = Math.pow(PLAN.w, n.depth); return s <= 4 ? 14 : s <= 16 ? 12 : s <= 64 ? 10 : s <= 256 ? 7 : s <= 1024 ? 5 : 4; }
|
||
function labelled(n){ return n === you || Math.pow(PLAN.w, n.depth) <= 64; }
|
||
|
||
function build(){
|
||
DEPTHS = DEFD[PLAN.w];
|
||
geometry();
|
||
nodes = []; byId = {}; nextId = 0; AUD.spent = 0; AUD.received = 0; AUD.above = 0; AUD.treasury = 0; AUD.entryFee = 0;
|
||
totals = { entry: 0, cash: 0, lic: 0, licV: 0, cashN: 0 }; youLedger = [];
|
||
function mk(depth, parent, idx){
|
||
const n = mkNode(depth, parent, idx);
|
||
if (depth < DEPTHS) for (let k = 0; k < PLAN.w; k++) mk(depth + 1, n, idx * PLAN.w + k);
|
||
return n;
|
||
}
|
||
you = null;
|
||
you = mk(0, null, 0);
|
||
// entries from your directs were credited before `you` existed: count them now
|
||
totals.entry = you.children.length * net(1); you.entry = totals.entry;
|
||
you.level = Number(document.getElementById('youLevel').value);
|
||
layout();
|
||
draw(); paintPays(); renderTotals(); depthLabel(); clearLog('Reset. Click a position, or run a wave.');
|
||
const le = document.getElementById('last'); if (le) { le.className = 'last'; le.textContent = 'Nothing bought yet. Your ' + you.children.length + ' directs each paid their entry (' + $$(price(1)) + ') to you. Click a ringed position: its next purchase reaches you.'; }
|
||
}
|
||
|
||
function draw(){
|
||
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
||
for (let d = 1; d <= DEPTHS; d++) {
|
||
const r = document.createElementNS(NS, 'rect');
|
||
r.setAttribute('x', 0); r.setAttribute('y', TOP + d * ROW - ROW/2); r.setAttribute('width', W); r.setAttribute('height', ROW);
|
||
r.setAttribute('class', 'band'); r.setAttribute('id', 'band' + d);
|
||
svg.appendChild(r);
|
||
const t = document.createElementNS(NS, 'text');
|
||
t.setAttribute('x', 12); t.setAttribute('y', TOP + d * ROW + 4); t.setAttribute('class', 'bandlabel'); t.setAttribute('id', 'bl' + d);
|
||
svg.appendChild(t);
|
||
}
|
||
for (const n of nodes) if (n.parent) {
|
||
const p = document.createElementNS(NS, 'path');
|
||
p.setAttribute('d', `M${n.parent.x},${n.parent.y} C${n.parent.x},${(n.parent.y+n.y)/2} ${n.x},${(n.parent.y+n.y)/2} ${n.x},${n.y}`);
|
||
p.setAttribute('class', 'edge'); p.setAttribute('id', 'e' + n.id);
|
||
svg.appendChild(p);
|
||
}
|
||
for (const n of nodes) {
|
||
const g = document.createElementNS(NS, 'g');
|
||
g.setAttribute('class', 'node' + (n === you ? ' you' : '') + (n.qual ? '' : ' unq'));
|
||
g.setAttribute('id', 'n' + n.id); g.setAttribute('tabindex', '0'); g.setAttribute('role', 'button');
|
||
const r = radius(n);
|
||
const c = document.createElementNS(NS, 'circle');
|
||
c.setAttribute('cx', n.x); c.setAttribute('cy', n.y); c.setAttribute('r', r);
|
||
g.appendChild(c);
|
||
const t = document.createElementNS(NS, 'text');
|
||
t.setAttribute('x', n.x); t.setAttribute('y', n.y); t.setAttribute('id', 't' + n.id);
|
||
if (labelled(n)) t.textContent = n.level;
|
||
if (r <= 10) t.setAttribute('style', 'font-size:9px');
|
||
g.appendChild(t);
|
||
if (n.depth === 1 && n.idx === 0) {
|
||
const dl = document.createElementNS(NS, 'text');
|
||
dl.setAttribute('x', n.x); dl.setAttribute('y', n.y - r - 4); dl.setAttribute('class', 'bandlabel'); dl.setAttribute('style', 'text-anchor:middle;font-weight:700');
|
||
dl.textContent = 'YOUR DIRECTS'; g.appendChild(dl);
|
||
}
|
||
const m = document.createElementNS(NS, 'text');
|
||
m.setAttribute('x', n.x); m.setAttribute('y', n.y + r + 3); m.setAttribute('class', 'mny'); m.setAttribute('id', 'm' + n.id);
|
||
g.appendChild(m);
|
||
const title = document.createElementNS(NS, 'title');
|
||
g.appendChild(title);
|
||
g.addEventListener('click', e => { e.stopPropagation(); onClick(n, g); });
|
||
g.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick(n, g); } });
|
||
svg.appendChild(g);
|
||
}
|
||
for (const n of nodes) refreshNode(n);
|
||
const yl = document.createElementNS(NS, 'text');
|
||
yl.setAttribute('x', you.x + 26); yl.setAttribute('y', you.y + 4); yl.setAttribute('class', 'bandlabel'); yl.textContent = 'YOU';
|
||
svg.appendChild(yl);
|
||
paintReach();
|
||
}
|
||
|
||
function paintReach(){
|
||
const A = you.level;
|
||
for (let d = 1; d <= DEPTHS; d++) {
|
||
const band = document.getElementById('band' + d), lbl = document.getElementById('bl' + d);
|
||
if (!band) continue;
|
||
if (d < A) { band.setAttribute('fill', 'var(--reach-soft)'); lbl.textContent = `depth ${d} · cash to you at level ${d+1}` + (d === 1 ? ' (and entries)' : ''); }
|
||
else if (d === A) { band.setAttribute('fill', 'var(--lic-soft)'); lbl.textContent = `depth ${d} · 1st level-${d+1} = your licence`; }
|
||
else { band.setAttribute('fill', 'transparent'); lbl.textContent = `depth ${d} · past you until level ${d}`; }
|
||
}
|
||
}
|
||
|
||
function refreshNode(n){
|
||
const g = document.getElementById('n' + n.id), t = document.getElementById('t' + n.id);
|
||
if (!g) return;
|
||
g.classList.toggle('unq', !n.qual);
|
||
if (labelled(n)) t.textContent = n.level;
|
||
const got = n.cash + n.entry;
|
||
g.querySelector('title').textContent = (n === you ? `You · level ${n.level}` : `#${n.id} · depth ${n.depth} · level ${n.level} · ${n.directs} direct${n.directs === 1 ? '' : 's'}`) + (got ? ` · collected ${$$(got)}` : '');
|
||
const m = document.getElementById('m' + n.id);
|
||
if (m) m.textContent = got && radius(n) >= 7 ? $$(got) : '';
|
||
}
|
||
|
||
// Rule 1 plus the gap rule. A payment of `amt` for level L, starting from `from`: skip `skipN`
|
||
// uplines, then climb to the first qualified upline. Under 'skip' a qualified upline more than one
|
||
// level behind is passed over too. Returns {to, skipped[], path[]}; to === null means it climbed past you.
|
||
// `rem`: a remainder left over after funding a licence. Remainders are cash only, to the first qualified
|
||
// upline that already holds the level; they never issue a licence, because they can be smaller than one.
|
||
// may `u` take CASH from a payment whose buyer is `origin`? Qualified, and (watermark off, or the buyer is
|
||
// u's own direct, or the buyer's position was created after u qualified)
|
||
// may `u` take CASH for a level-L payment whose buyer is `origin`?
|
||
// two directs: any level, from own directs or positions created after the second direct arrived
|
||
// one direct (half step on): levels 2-3 only (depths 1-2), from own directs or positions created after the first arrived
|
||
function cashOk(u, origin, L){
|
||
const own = !PLAN.wm || !origin || origin.parent === u;
|
||
if (u.directs >= 2) return own || origin.id >= u.cashFrom;
|
||
if (PLAN.half && u.directs === 1 && L <= 3) return own || origin.id >= u.cashFromHalf;
|
||
if (PLAN.zero && L <= 2) return true;
|
||
return false;
|
||
}
|
||
function route(from, L, skipN, rem, origin){
|
||
const skipped = [], path = [];
|
||
let cur = from.parent;
|
||
for (let i = 0; i < skipN && cur; i++) { path.push(cur); cur = cur.parent; }
|
||
while (cur) {
|
||
path.push(cur);
|
||
if (cur.level >= L) {
|
||
if (cashOk(cur, origin, L)) return { to: cur, kind: 'cash', skipped, path };
|
||
skipped.push({ n: cur, why: cur.directs === 0 ? 'no directs, holds the level: cash passes them' : cur.directs === 1 ? (PLAN.half && L <= 3 ? 'one direct: this position joined before it: cash passes them' : 'one direct: cash only from depths 1-2' + (PLAN.half ? '' : ' (half step off)')) : 'qualified after this position joined: cash passes them' });
|
||
} else if (!rem) {
|
||
const behindOk = PLAN.gap === 'fund' || cur.level >= L - 1, licOk = cur.qual || PLAN.unq === 'licence';
|
||
if (behindOk && licOk) return { to: cur, kind: 'lic', skipped, path };
|
||
skipped.push({ n: cur, why: !licOk ? 'fewer than two directs' : `holds level ${cur.level}, needs ${L-1}` });
|
||
} else skipped.push({ n: cur, why: `holds level ${cur.level}, a remainder pays only holders of ${L}` });
|
||
cur = cur.parent;
|
||
}
|
||
return { to: null, skipped, path };
|
||
}
|
||
|
||
// One payment and everything that follows from it: licence, cascade, remainder.
|
||
function pay(from, L, amt, skipN, steps, flashes, rem, origin){
|
||
const r = route(from, L, skipN, rem, origin);
|
||
for (const s of r.skipped) { steps.push({ kind: 'skip', text: `${name(s.n)} skipped (${s.why})` }); flashes.push([s.n, 'flash-skip']); }
|
||
if (!r.to) {
|
||
if (tally) { const t = tallyFor(tallyOrigin); if (licUpFlag) t.licUp += amt; else t.above += amt; }
|
||
AUD.received += amt; AUD.above += amt;
|
||
steps.push({ kind: 'cash', text: `${$$(amt)} of level-${L} money went on above you, to your own upline (the company, in this view).` });
|
||
markPath(from, null, 'hot-cash'); return;
|
||
}
|
||
const to = r.to;
|
||
if (r.kind === 'cash') {
|
||
to.cash += amt; AUD.received += amt; refreshNode(to);
|
||
if (tally) { const t = tallyFor(tallyOrigin); if (to === you) t.youCash += amt; else t.cash[to.depth] = (t.cash[to.depth] || 0) + amt; }
|
||
if (to === you) { totals.cash += amt; totals.cashN++; youLedger.unshift({ from, L, kind: 'cash', amt }); renderTotals(); }
|
||
steps.push({ kind: 'cash', text: `${name(to)} already holds level ${to.level}: cash, ${$$(amt)}.` });
|
||
flashes.push([to, 'flash-cash']); markPath(from, to, 'hot-cash'); return;
|
||
}
|
||
// behind the level: this payment is their next licence (under 'skip' that is always level L)
|
||
const n = to.level + 1, cost = net(n); // a licence is worth the level's climbing amount, after the fee
|
||
to.level = n; refreshNode(to);
|
||
if (tally) { const t = tallyFor(tallyOrigin); if (to === you) t.youLic++; else t.lic[to.depth] = (t.lic[to.depth] || 0) + 1; }
|
||
if (to === you) { totals.lic++; totals.licV += cost; youLedger.unshift({ from, L: n, kind: 'lic', amt: cost }); paintReach(); renderTotals(); }
|
||
steps.push({ kind: 'lic', text: `${name(to)} held level ${n-1}: this is their licence ${n}${n < L ? ' (funded by a level-' + L + ' payment)' : ''}${to.qual ? '' : ' (fewer than two directs: a licence, never cash)'}. Upgraded. Their level-${n} cost climbs from their position…` });
|
||
flashes.push([to, 'flash-lic']); markPath(from, to, 'hot-lic');
|
||
const wasYou = licUpFlag; if (to === you) licUpFlag = true;
|
||
pay(to, n, cost, n - 2, steps, flashes, false, origin); // the cascade: the licence cost climbs (same buyer's money)
|
||
licUpFlag = wasYou;
|
||
const left = amt - cost;
|
||
if (left > 0.005) { steps.push({ kind: 'cash', text: `The remaining ${$$(left)} of that level-${L} payment climbs on as cash to the first upline holding level ${L}.` }); pay(to, L, left, 0, steps, flashes, true, origin); }
|
||
}
|
||
function purchase(from, L, steps, flashes){ AUD.spent += price(L); feeOn(price(L)); pay(from, L, net(L), L - 2, steps, flashes, false, from); }
|
||
|
||
function markPath(from, to, cls){
|
||
if (quiet) return;
|
||
let cur = from;
|
||
while (cur && cur !== to) { const e = document.getElementById('e' + cur.id); if (e) e.classList.add(cls); cur = cur.parent; }
|
||
}
|
||
function name(n){ return n === you ? 'YOU' : `#${n.id} (${n.depth === 1 ? 'your direct' : n.depth === 2 ? 'grandchild, depth 2' : 'depth ' + n.depth})`; }
|
||
|
||
function clearHot(){
|
||
svg.querySelectorAll('.edge').forEach(e => e.classList.remove('hot-cash', 'hot-lic', 'hot-skip'));
|
||
svg.querySelectorAll('.node').forEach(g => g.classList.remove('flash-cash', 'flash-lic', 'flash-skip', 'flash-src'));
|
||
}
|
||
|
||
function onClick(n, g){ if (n === you) return; openPop(n, g); }
|
||
const pop = document.createElement('div'); pop.className = 'pop'; pop.hidden = true; document.body.appendChild(pop);
|
||
function closePop(){ pop.hidden = true; }
|
||
function openPop(n, g){
|
||
const r = g.querySelector('circle').getBoundingClientRect();
|
||
const nxt = n.level + 1;
|
||
const rt = nxt <= PLAN.maxL ? route(n, nxt, nxt - 2, false, n) : { to: null };
|
||
const where = rt.to === you ? '<b>lands on YOU</b>' : rt.to ? 'pays ' + name(rt.to) : 'goes above you (to your own upline)';
|
||
const how = rt.to ? (rt.kind === 'lic' ? ' as their <b>licence ' + (rt.to.level + 1) + '</b>' + (rt.to.level + 1 < nxt ? ', the remainder climbs on' : '') : ' as cash, ' + $$(price(nxt))) : '';
|
||
const skipped = rt.skipped && rt.skipped.length ? '<br>skipping ' + rt.skipped.map(x => name(x.n)).join(', ') : '';
|
||
pop.innerHTML = '<div class="t">' + (n.depth === 1 ? '<b>YOUR DIRECT</b> · ' : n.depth === 2 ? '<b>A GRANDCHILD</b> (depth 2) · ' : 'depth ' + n.depth + ' · ') + '#' + n.id + ' · holds level ' + n.level + ' · ' + n.directs + ' direct' + (n.directs === 1 ? '' : 's') + '</div>'
|
||
+ '<div class="hint">' + (nxt <= PLAN.maxL ? 'Buying level ' + nxt + ' (' + $$(price(nxt)) + ') ' + where + how + skipped + '.' : 'At the top of the ladder.') + '</div>'
|
||
+ (nxt <= PLAN.maxL ? '<button class="primary" id="popBuy">Buy level ' + nxt + ' · ' + product(nxt) + ' · ' + $$(price(nxt)) + (PLAN.fee ? ' (' + $$(net(nxt)) + ' climbs)' : '') + '</button>' : '')
|
||
+ '<div class="t" style="margin-top:8px">Directs: ' + n.directs + '</div>'
|
||
+ [0, 1, 2].filter(k => k !== n.directs).map(k => '<button data-dir="' + k + '">' + (k === 0 ? 'Mark as no directs' : k === 1 ? 'Mark as one direct (from now)' : 'Mark as two directs (from now)') + '</button>').join('');
|
||
pop.hidden = false;
|
||
const w = 250, h = pop.offsetHeight || 140;
|
||
let left = r.left + r.width / 2 - w / 2, top = r.bottom + 8;
|
||
left = Math.max(8, Math.min(left, window.innerWidth - w - 8));
|
||
if (top + h > window.innerHeight - 8) top = r.top - h - 8;
|
||
pop.style.left = left + 'px'; pop.style.top = top + 'px';
|
||
const pb = document.getElementById('popBuy'); if (pb) pb.onclick = () => { closePop(); buy(n); };
|
||
pop.querySelectorAll('[data-dir]').forEach(b => b.onclick = () => {
|
||
closePop(); const k = Number(b.dataset.dir);
|
||
if (k >= 1 && n.directs < 1) n.cashFromHalf = nextId; // the first direct arrives now: depths 1-2 pay from here on
|
||
if (k >= 2 && n.directs < 2) n.cashFrom = nextId; // the second: full reach from here on
|
||
n.directs = k; refreshNode(n); paintPays();
|
||
const older = cnt(nodes.filter(x => x.id < nextId && x !== n).length);
|
||
const msg = k === 2 ? name(n) + ' now has two directs: full reach, cash from its own directs and from positions that join from now on. The ' + older + ' existing positions keep passing it.'
|
||
: k === 1 ? name(n) + ' now has one direct: ' + (PLAN.half ? 'cash from depths 1-2 (levels 2-3), from its own directs and from positions that join from now on' : 'no cash until the second (half step is off)') + (PLAN.unq === 'licence' ? '; licences still reach it.' : '.')
|
||
: name(n) + ' now has no directs: cash passes over it' + (PLAN.unq === 'licence' ? ', licences still reach it.' : '.');
|
||
renderLast(null, null, null, msg, k ? 'cash' : 'none');
|
||
addLog([{ kind: k ? 'cash' : 'skip', text: msg }], name(n));
|
||
});
|
||
}
|
||
document.addEventListener('click', e => { if (!pop.hidden && !pop.contains(e.target) && !e.target.closest('.node')) closePop(); });
|
||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closePop(); });
|
||
|
||
function renderLast(n, L, steps, override, cls){
|
||
const el = document.getElementById('last');
|
||
if (override) { el.className = 'last ' + (cls || ''); el.innerHTML = override; return; }
|
||
const lic = steps.filter(s => s.kind === 'lic');
|
||
const cash = steps.filter(s => s.kind === 'cash');
|
||
const youLic = lic.some(s => /^YOU held/.test(s.text));
|
||
const youCash = cash.some(s => /^YOU already/.test(s.text));
|
||
let text = '<b>' + name(n) + ' bought level ' + L + ' (' + product(L) + ') for ' + $$(price(L)) + '.</b> ';
|
||
if (youLic) text += 'That payment was <b>your licence</b>: you were upgraded in the same transaction and the cost went on above you.';
|
||
else if (youCash) text += 'It reached you as <b>cash</b>' + (lic.length ? ', after issuing ' + lic.length + ' licence' + (lic.length > 1 ? 's' : '') + ' on the way up' : '') + '.';
|
||
else if (lic.length) text += 'It became <b>a licence for ' + lic[0].text.split(' held')[0] + '</b> and the money climbed on from there.';
|
||
else if (cash.length && !/above you/.test(cash[0].text)) text += 'It paid <b>' + cash[0].text.split(' already')[0] + '</b> as cash.';
|
||
else text += 'It went <b>above you</b>, to your own upline.';
|
||
const why = youLic || youCash ? '' : '<span class="why">Not yours: a depth-' + n.depth + ' position pays you only when it buys level ' + (n.depth + 1) + '. It holds level ' + L + ' now' + (L < n.depth + 1 ? ', so ' + (n.depth + 1 - L) + ' more purchase' + (n.depth + 1 - L > 1 ? 's' : '') + ' until its next one reaches you.' : '.') + '</span>';
|
||
el.className = 'last ' + (youLic ? 'lic' : youCash ? 'cash' : 'none');
|
||
el.innerHTML = text + why;
|
||
}
|
||
|
||
function buy(n){
|
||
const L = n.level + 1;
|
||
if (L > PLAN.maxL) return;
|
||
clearHot();
|
||
n.level = L; refreshNode(n);
|
||
const steps = [], flashes = [[n, 'flash-src']];
|
||
purchase(n, L, steps, flashes);
|
||
for (const [m, c] of flashes) { const g = document.getElementById('n' + m.id); if (g) g.classList.add(c); }
|
||
addLog(steps, `${name(n)} bought level ${L} for ${$$(price(L))}`);
|
||
renderLast(n, L, steps);
|
||
paintPays();
|
||
return steps;
|
||
}
|
||
|
||
function paintPays(){
|
||
for (const n of nodes) {
|
||
if (n === you) continue;
|
||
const g = document.getElementById('n' + n.id); if (!g) continue;
|
||
const r = n.level + 1 <= PLAN.maxL ? route(n, n.level + 1, n.level - 1, false, n) : { to: null };
|
||
g.classList.toggle('pays', r.to === you);
|
||
}
|
||
}
|
||
|
||
function wave(){
|
||
clearHot();
|
||
const before = you.level, cashBefore = totals.cash;
|
||
const steps = [];
|
||
quiet = true; tally = {};
|
||
const order = nodes.filter(n => n !== you).sort((a, b) => a.depth - b.depth || a.idx - b.idx);
|
||
let bought = 0, licYou = 0, skipYou = 0;
|
||
for (const n of order) {
|
||
if (!n.qual) continue;
|
||
const L = n.level + 1; if (L > PLAN.maxL) continue;
|
||
tallyOrigin = n.depth; const tf = tallyFor(n.depth); tf.n++; tf.L = L;
|
||
n.level = L; refreshNode(n); bought++;
|
||
const sub = [], fl = [];
|
||
const licBefore = totals.lic;
|
||
purchase(n, L, sub, fl);
|
||
if (totals.lic > licBefore) licYou++;
|
||
if (sub.some(s => /went on above you/.test(s.text))) skipYou++;
|
||
}
|
||
quiet = false;
|
||
renderWaveTable();
|
||
const after = you.level;
|
||
steps.push({ kind: 'lic', text: `${bought} positions each bought one level, shallow to deep.` });
|
||
steps.push({ kind: after > before ? 'lic' : 'cash', text: after > before
|
||
? `YOU went from level ${before} to ${after} without buying anything: ${licYou} licence${licYou === 1 ? '' : 's'} were funded from below.`
|
||
: (before >= DEPTHS
|
||
? `YOU stayed at level ${before}: your org is only ${DEPTHS} deep, and licence ${before + 1} is funded by a depth-${before} position buying level ${before + 1}. Nothing that deep exists here. Grow the org to keep climbing.`
|
||
: `YOU stayed at level ${before}: nothing at depth ${before} bought level ${before + 1} this wave.`) });
|
||
steps.push({ kind: 'cash', text: `Cash to you this wave: ${$$(totals.cash - cashBefore)}.` });
|
||
if (skipYou) steps.push({ kind: 'skip', text: `${skipYou} payment${skipYou === 1 ? '' : 's'} went on above you: levels that pay uplines higher than you. Not a miss.` });
|
||
addLog(steps, 'Wave');
|
||
renderLast(null, null, null, '<b>Wave:</b> ' + steps.map(s => s.text).join(' '), after > before ? 'lic' : 'cash');
|
||
paintPays();
|
||
}
|
||
|
||
function renderWaveTable(){
|
||
const box = document.getElementById('waveBox'), tb = document.querySelector('#waveTable tbody');
|
||
if (!box || !tb || !tally) return;
|
||
tb.innerHTML = '';
|
||
for (const d of Object.keys(tally).map(Number).sort((a, b) => a - b)) {
|
||
const t = tally[d];
|
||
const toYou = [t.youLic ? '<span class="chip lic">' + t.youLic + ' licence' + (t.youLic > 1 ? 's' : '') + '</span>' : '', t.youCash ? '<b>' + $$(t.youCash) + '</b>' : ''].filter(Boolean).join(' + ') || '—';
|
||
const others = Object.keys(t.cash).concat(Object.keys(t.lic)).filter((v, i, a) => a.indexOf(v) === i).map(Number).sort((a, b) => a - b)
|
||
.map(k => 'depth ' + k + ': ' + (t.cash[k] ? $$(t.cash[k]) : '') + (t.lic[k] ? (t.cash[k] ? ' + ' : '') + t.lic[k] + ' licence' + (t.lic[k] > 1 ? 's' : '') : '')).join('<br>') || '—';
|
||
const tr = document.createElement('tr');
|
||
const above = [t.above ? $$(t.above) : '', t.licUp ? $$(t.licUp) + ' <span class="note">(your licence cost, climbing)</span>' : ''].filter(Boolean).join(' + ') || '—';
|
||
tr.innerHTML = '<td>' + d + '</td><td>' + t.L + ' (' + $$(price(t.L)) + ')</td><td>' + t.n + '</td><td>' + toYou + '</td><td style="text-align:left">' + others + '</td><td>' + above + '</td>';
|
||
tb.appendChild(tr);
|
||
}
|
||
box.hidden = false;
|
||
}
|
||
function addLog(steps, head){
|
||
const ol = document.getElementById('logList');
|
||
if (ol.firstChild && /Nothing yet|Reset\./.test(ol.firstChild.textContent)) ol.innerHTML = '';
|
||
const h = document.createElement('li'); h.className = 'head'; h.textContent = head; ol.prepend(h);
|
||
let after = h;
|
||
for (const s of steps) {
|
||
const li = document.createElement('li');
|
||
const chip = document.createElement('span'); chip.className = 'chip ' + s.kind; chip.textContent = s.kind === 'lic' ? 'licence' : s.kind === 'skip' ? 'skip' : 'cash';
|
||
li.appendChild(chip); li.appendChild(document.createTextNode(' ' + s.text));
|
||
after.after(li); after = li;
|
||
}
|
||
while (ol.children.length > 60) ol.removeChild(ol.lastChild);
|
||
}
|
||
function clearLog(msg){ document.getElementById('logList').innerHTML = `<li class="head">${msg}</li>`; }
|
||
const lastShown = {};
|
||
function setV(id, text){
|
||
const el = document.getElementById(id); if (!el) return;
|
||
if (lastShown[id] !== undefined && lastShown[id] !== text) { el.classList.remove('bump'); void el.offsetWidth; el.classList.add('bump'); }
|
||
lastShown[id] = text; el.textContent = text;
|
||
}
|
||
function renderTotals(){
|
||
if (!you) return;
|
||
setV('mLevel', you.level);
|
||
const sl = document.getElementById('youLevel'); if (sl && Number(sl.value) !== you.level && you.level <= Number(sl.max)) { sl.value = you.level; document.getElementById('youLevelVal').textContent = you.level; }
|
||
const mr = document.getElementById('mReach'); if (mr) mr.textContent = you.level;
|
||
setV('mEntry', $$(totals.entry));
|
||
const en = document.getElementById('mEntryN'); if (en) en.textContent = you.children.length + ' directs × ' + $$(net(1)) + ' (the ' + $$(price(1)) + ' entry after the fee), no qualification';
|
||
setV('mCash', $$(totals.cash));
|
||
const cn = document.getElementById('mCashN'); if (cn) cn.textContent = totals.cashN + ' payment' + (totals.cashN === 1 ? '' : 's');
|
||
setV('mLic', totals.lic);
|
||
const lv = document.getElementById('mLicV'); if (lv) lv.textContent = 'worth ' + $$(totals.licV) + ', paid by your org';
|
||
setV('mTotal', $$(totals.entry + totals.cash + totals.licV));
|
||
setV('mFuel', $$(AUD.treasury)); const fs = document.getElementById('mFuelS'); if (fs) fs.textContent = PLAN.fee ? Math.round(PLAN.fee * 100) + '% of every level bought so far (plus ' + $$(AUD.entryFee) + ' on the entries paid when this org joined)' : 'no fee: the whole price climbs';
|
||
const ol = document.getElementById('youLedger');
|
||
if (ol) {
|
||
ol.innerHTML = '';
|
||
if (!youLedger.length) ol.innerHTML = '<li><span>Nothing yet.</span><span></span></li>';
|
||
for (const e of youLedger.slice(0, 10)) {
|
||
const li = document.createElement('li');
|
||
li.innerHTML = '<span><span class="chip ' + e.kind + '">' + (e.kind === 'lic' ? 'licence' : 'cash') + '</span> ' + (e.kind === 'lic' ? 'your licence ' + e.L + ', funded by ' : 'level-' + e.L + ' money from ') + name(e.from) + '</span><span>' + (e.kind === 'lic' ? 'licence ' + e.L + ' (' + $$(e.amt) + ')' : '+' + $$(e.amt)) + '</span>';
|
||
ol.appendChild(li);
|
||
}
|
||
}
|
||
const ln = document.getElementById('ledgerNote'); if (ln) ln.textContent = 'Each position pays you at most once per level, so the count is what matters: at level L there are ' + PLAN.w + '^' + '(L−1) positions at the depth that pays you, and each pays the level-L price.';
|
||
ladder();
|
||
}
|
||
|
||
document.getElementById('youLevel').addEventListener('input', e => {
|
||
document.getElementById('youLevelVal').textContent = e.target.value;
|
||
you.level = Number(e.target.value); refreshNode(you); paintReach(); paintPays(); renderTotals();
|
||
});
|
||
document.getElementById('wave').addEventListener('click', wave);
|
||
|
||
function at(path){ let n = you; for (const ch of path) n = n.children[ch === 'L' ? 0 : 1]; return n; }
|
||
const TOUR = [
|
||
{ step: 'Step 1 of 7 · your licence', say: 'You hold level 1, like every new member, and so do your directs (labelled). Their entries already paid you. Your FIRST direct buys level 2. Level-2 money pays the first upline, which is you, and you hold exactly one level below, so this payment IS your licence 2: you are upgraded in the same transaction and the money continues above you. No cash yet.',
|
||
act: () => buy(at('L')) },
|
||
{ step: 'Step 2 of 7 · cash', say: 'Your SECOND direct buys level 2. You now hold level 2, so this one is cash: the level-2 price to you. Watch the bar.',
|
||
act: () => buy(at('R')) },
|
||
{ step: 'Step 3 of 7 · not yours', say: 'A grandchild, under your first direct, buys level 2. Level-2 money stops at the FIRST upline, its own parent, who already holds level 2, so it is that parent\'s cash and never reaches you. That is why the rings matter: a position pays you only at the one level that maps to its depth.',
|
||
act: () => buy(at('LL')) },
|
||
{ step: 'Step 4 of 7 · your licence 3', say: 'The same grandchild buys level 3. Level-3 money skips one upline and lands on you; you hold level 2, exactly one below, so this is your licence 3. The amber band steps down a depth and the rings move.',
|
||
act: () => buy(at('LL')) },
|
||
{ step: 'Step 5 of 7 · cascade', say: 'One purchase can pay two people. A depth-3 position under your second direct buys level 2. It pays its parent (depth 2), who holds exactly level 1: that parent gets licence 2, and the parent\'s own level-2 cost climbs to your second direct as cash. One buyer, one licence issued, one cash payment.',
|
||
act: () => buy(at('RLL')) },
|
||
{ step: 'Step 6 of 7 · skipped', say: 'Your first direct now has NO directs of its own (dashed). Its other child buys level 2. That money would pay the parent, but the parent has recruited nobody, so cash passes over it and keeps climbing: you catch it. Qualification decides who is skipped; it never holds money back. (With one direct, the half step would let the parent keep this one.)',
|
||
act: () => { const l = at('L'); l.directs = 0; refreshNode(l); paintPays(); buy(at('LR')); } },
|
||
{ step: 'Step 7 of 7 · the wave', say: 'Everything at once: every position buys one level, shallow to deep. Read the table that appears under the strip: one row per depth, where that depth\'s money went. Then press Run a wave again and watch your level climb without buying anything.',
|
||
act: () => wave() },
|
||
{ step: 'Done', say: 'That is the whole plan. Now switch the gap rule and the width at the top and run waves again: the tree resets, and the difference shows up in the money bar.', act: null }
|
||
];
|
||
let ti = -1;
|
||
function tourShow(){
|
||
const t = TOUR[ti]; document.getElementById('tourStep').textContent = t.step; document.getElementById('tourSay').textContent = t.say;
|
||
const nx = document.getElementById('tourNext'); nx.hidden = false; nx.textContent = t.act ? 'Show me' : 'Finish';
|
||
document.getElementById('tourStart').textContent = 'Restart tour';
|
||
}
|
||
document.getElementById('tourStart').addEventListener('click', () => { document.getElementById('youLevel').value = 1; document.getElementById('youLevelVal').textContent = '1'; build(); ti = 0; tourShow(); });
|
||
document.getElementById('tourNext').addEventListener('click', () => {
|
||
const t = TOUR[ti];
|
||
if (t.act) { t.act(); }
|
||
if (ti < TOUR.length - 1) { ti++; tourShow(); }
|
||
else { document.getElementById('tourNext').hidden = true; }
|
||
});
|
||
document.getElementById('reset').addEventListener('click', () => { document.getElementById('youLevel').value = 1; document.getElementById('youLevelVal').textContent = '1'; build(); });
|
||
document.getElementById('grow').addEventListener('click', grow);
|
||
function depthLabel(){ const el = document.getElementById('depthLabel'); if (el) el.textContent = DEPTHS + ' deep, ' + cnt(nodes.length - 1) + ' positions'; const g = document.getElementById('grow'); if (g) g.disabled = DEPTHS >= MAXD[PLAN.w]; }
|
||
function grow(){
|
||
if (DEPTHS >= MAXD[PLAN.w]) return;
|
||
const leaves = nodes.filter(n => n.depth === DEPTHS);
|
||
DEPTHS++;
|
||
let entries = 0;
|
||
for (const n of leaves) for (let k = 0; k < PLAN.w; k++) { mkNode(n.depth + 1, n, n.idx * PLAN.w + k); entries += net(1); }
|
||
geometry(); layout(); draw(); paintPays(); renderTotals(); depthLabel();
|
||
addLog([{ kind: 'lic', text: `The org is now ${DEPTHS} deep: ${leaves.length * PLAN.w} new level-1 positions joined at the bottom and paid ${$$(entries)} of entries to the row above. Everything else is as it was.` }], 'Grew one depth');
|
||
}
|
||
|
||
// ── ladder table ──
|
||
const priceEl = document.getElementById('price');
|
||
function ladder(){
|
||
document.getElementById('priceVal').textContent = '$' + priceEl.value;
|
||
const tb = document.querySelector('#ladder tbody'); if (!tb) return; tb.innerHTML = '';
|
||
const rows = [1]; const top = Math.min(12, PLAN.maxL);
|
||
for (let L = 2; L <= top; L++) rows.push(L);
|
||
if (PLAN.maxL > 12) rows.push('gap', 20, 'gap', PLAN.maxL);
|
||
let climb = 0; for (let L = 1; L <= PLAN.maxL; L++) climb += price(L);
|
||
for (const L of rows) {
|
||
const tr = document.createElement('tr');
|
||
if (L === 'gap') { tr.className = 'gap'; tr.innerHTML = '<td colspan="6">⋮</td>'; tb.appendChild(tr); continue; }
|
||
const d = L === 1 ? 1 : L - 1, pos = Math.pow(PLAN.w, d);
|
||
if (you && L === you.level + 1) tr.className = 'you';
|
||
tr.innerHTML = `<td>${L}${you && L === you.level + 1 ? ' <span class="chip lic">your next</span>' : ''}</td><td style="text-align:left">${product(L)} <span class="note">placeholder</span></td><td>${L === 1 ? 'entries from depth 1, no qualification' : 'depth ' + d + ', buying level ' + L}</td><td>${cnt(pos)}</td><td>${$$(pos * net(L))}</td><td>${$$(price(L))}${L === 1 ? ' <span class="note">everyone pays this to enter</span>' : ' <span class="note">or the first payment from depth ' + d + '</span>'}</td>`;
|
||
tb.appendChild(tr);
|
||
}
|
||
const ln = document.getElementById('ladderNote'); if (ln) ln.textContent = PLAN.w + '-wide, ' + PLAN.maxL + ' levels. Potential is one payment from every position at the depth that pays that level, so it grows ' + PLAN.w + '× per level on its own; the price ladder only sets the dollars, and ' + Math.round(PLAN.fee * 100) + '% of every price goes to the admin wallet before anything climbs. Climbing all ' + PLAN.maxL + ' levels yourself would cost ' + $$(climb) + ', which nobody has to do: the first payment at each depth is the licence.';
|
||
}
|
||
priceEl.addEventListener('input', () => { renderTotals(); for (const n of nodes) refreshNode(n); if (dp) deepRender(); });
|
||
|
||
// ── deep simulator: the same rules on counts per depth ──
|
||
let dp = null;
|
||
function deepReset(){
|
||
const fill = Number(document.getElementById('deepFill').value) / 100, D = PLAN.maxL;
|
||
dp = { D, levels: [], counts: [], lic: [], licV: [], cash: [], entry: [], pays: [], waves: 0, above: 0, spent: 0, treasury: 0, entryFee: 0 }; // treasury = fee on purchases made in waves; entryFee = fee on the entries paid when the org was built
|
||
window.deepAudit = () => { const rec = dp.cash.reduce((a, b) => a + b, 0) + dp.entry.reduce((a, b) => a + b, 0) + dp.above + dp.treasury + dp.entryFee; return { spent: Math.round(dp.spent), received: Math.round(rec), ok: Math.abs(dp.spent - rec) <= 1 + 1e-9 * dp.spent }; };
|
||
for (let d = 0; d <= D; d++) {
|
||
dp.levels[d] = 1;
|
||
dp.counts[d] = d === 0 ? 1 : Math.max(1, Math.round(Math.pow(PLAN.w * fill, d)));
|
||
dp.lic[d] = 0; dp.licV[d] = 0; dp.cash[d] = 0; dp.entry[d] = 0; dp.pays[d] = 0;
|
||
}
|
||
for (let d = 1; d <= D; d++) { dp.entry[d - 1] += dp.counts[d] * net(1); dp.spent += dp.counts[d] * price(1); dp.entryFee += dp.counts[d] * price(1) * PLAN.fee; } // Rule 0, once, when the org is built
|
||
deepRender('Reset. Everyone at level 1, you included; entries paid.');
|
||
const ol = document.getElementById('deepStory'); if (ol) ol.innerHTML = '<li class="head">Start. You and everyone under you hold level 1. Your ' + cnt(dp.counts[1]) + ' directs paid their entries: <b>' + $$(dp.entry[0]) + '</b> to you after the fee. (All ' + cnt(dp.counts.reduce((a, b) => a + b, 0) - 1) + ' positions paid an entry when they joined; the admin wallet took ' + $$(dp.entryFee) + ' on those, which is not in the running total below.) Press Run one wave.</li>';
|
||
}
|
||
// n payments of `amt` for level L from depth `from`: skip `skipN`, then the gap rule on aggregate levels
|
||
function deepPay(n, from, L, amt, skipN, rem){
|
||
if (n <= 0) return;
|
||
let r = from - 1 - skipN;
|
||
while (r >= 0 && !(rem ? dp.levels[r] >= L : (PLAN.gap === 'fund' || dp.levels[r] >= L - 1))) r--;
|
||
if (r < 0) { dp.above += n * amt; return; }
|
||
if (dp.levels[r] >= L) { dp.cash[r] += n * amt; dp.pays[r] += n; return; }
|
||
const nl = dp.levels[r] + 1, cost = net(nl);
|
||
const granted = Math.min(dp.counts[r], n);
|
||
dp.lic[r] += granted; dp.licV[r] += granted * cost; dp.levels[r] = nl;
|
||
deepPay(granted, r, nl, cost, nl - 2); // the licence costs climb from depth r
|
||
if (amt - cost > 0.005) deepPay(granted, r, L, amt - cost, 0, true); // the remainder climbs on, cash only
|
||
deepPay(n - granted, from, L, amt, skipN); // the rest of this depth's payments, now that r has moved up
|
||
}
|
||
function deepWave(){
|
||
if (!dp) deepReset();
|
||
for (let d = 1; d <= dp.D; d++) { const L = dp.levels[d] + 1; if (L > PLAN.maxL) continue; dp.spent += dp.counts[d] * price(L); dp.treasury += dp.counts[d] * price(L) * PLAN.fee; deepPay(dp.counts[d], d, L, net(L), L - 2); dp.levels[d] = Math.max(dp.levels[d], L); }
|
||
dp.waves++;
|
||
}
|
||
function deepRender(note){
|
||
document.getElementById('dLevel').textContent = dp.levels[0];
|
||
document.getElementById('dReach').textContent = Math.min(dp.levels[0], dp.D);
|
||
document.getElementById('dEntry').textContent = $$(dp.entry[0]);
|
||
document.getElementById('dCash').textContent = $$(dp.cash[0]);
|
||
document.getElementById('dCashN').textContent = cnt(dp.pays[0]) + ' payment' + (dp.pays[0] === 1 ? '' : 's');
|
||
document.getElementById('dLic').textContent = dp.lic[0];
|
||
document.getElementById('dLicV').textContent = 'worth ' + $$(dp.licV[0]);
|
||
document.getElementById('dWaves').textContent = dp.waves;
|
||
document.getElementById('dAbove').textContent = $$(dp.above);
|
||
document.getElementById('dFuel').textContent = $$(dp.treasury);
|
||
const tb = document.querySelector('#deepTable tbody'); tb.innerHTML = '';
|
||
const maxCash = Math.max(1, ...dp.cash.map((c, d) => d === 0 ? 0 : c));
|
||
for (let d = 0; d <= dp.D; d++) {
|
||
const tr = document.createElement('tr');
|
||
tr.className = d === 0 ? 'you' : d <= dp.levels[0] ? 'reach' : d === dp.levels[0] + 1 ? 'next' : '';
|
||
const per = dp.counts[d] ? (dp.cash[d] + dp.entry[d]) / dp.counts[d] : 0;
|
||
tr.innerHTML = '<td>' + (d === 0 ? 'YOU' : d) + '</td><td>' + cnt(dp.counts[d]) + '</td><td>' + dp.levels[d] + '</td><td>' + cnt(dp.lic[d]) + '</td><td>' + $$(dp.entry[d]) + '</td><td>' + $$(dp.cash[d]) + '</td>'
|
||
+ '<td class="bar">' + (d === 0 ? '' : '<i style="width:' + Math.round(100 * dp.cash[d] / maxCash) + '%"></i>') + '</td><td>' + $$(per) + '</td>';
|
||
tb.appendChild(tr);
|
||
}
|
||
if (note) document.getElementById('deepNote').textContent = note;
|
||
}
|
||
function storyLine(html, cls){ const ol = document.getElementById('deepStory'); if (!ol) return; if (ol.firstChild && /Nothing has happened/.test(ol.firstChild.textContent)) ol.innerHTML = ''; const li = document.createElement('li'); if (cls) li.className = cls; li.innerHTML = html; ol.prepend(li); while (ol.children.length > 40) ol.removeChild(ol.lastChild); }
|
||
function deepRun(k){
|
||
if (!dp) deepReset();
|
||
let ran = 0;
|
||
for (let i = 0; i < k; i++) {
|
||
if (dp.levels[0] >= PLAN.maxL) break;
|
||
const lv0 = dp.levels[0], cash0 = dp.cash[0], lic0 = dp.lic[0], adm0 = dp.treasury, above0 = dp.above;
|
||
deepWave(); ran++;
|
||
const lv1 = dp.levels[0], dCash = dp.cash[0] - cash0, dLic = dp.lic[0] - lic0;
|
||
const d = lv0; // the depth whose purchase this wave could reach you
|
||
const L = d + 1;
|
||
let html = '<b>Wave ' + dp.waves + '.</b> Every position bought its next level. ';
|
||
if (d <= dp.D) html += 'The ' + cnt(dp.counts[d]) + ' positions at depth ' + d + ' bought level ' + L + ' (' + product(L) + ', ' + $$(price(L)) + ' each, ' + $$(net(L)) + ' after the fee), and level-' + L + ' money is yours. ';
|
||
if (dLic) html += 'The <span class="chip lic">first one</span> was your licence ' + lv1 + ': you were upgraded in the same block and its cost climbed on above you. ';
|
||
if (dCash > 0) html += 'The rest reached you as <span class="chip cash">cash</span>: <b>' + $$(dCash) + '</b>. ';
|
||
if (!dLic && dCash <= 0) html += 'Nothing reached you: that depth is empty at this fill, or you are at the top. ';
|
||
html += 'Everything the other depths bought paid the people between you and them, or climbed past you. Admin wallet took ' + $$(dp.treasury - adm0) + ' this wave. ';
|
||
html += '<span class="chip reach">You: level ' + lv1 + ', reach depth 1 to ' + Math.min(lv1, dp.D) + '</span>';
|
||
storyLine(html, dLic ? 'lic' : 'cash');
|
||
}
|
||
const after = dp.levels[0];
|
||
if (after >= PLAN.maxL) storyLine('<b>Top of the ladder.</b> You hold level ' + PLAN.maxL + '. From here every payment from every depth is cash, and there is no level 9: positions ' + PLAN.maxL + ' deep pay the people between you and them.', 'head');
|
||
deepRender(ran + ' wave' + (ran === 1 ? '' : 's') + ' run.');
|
||
}
|
||
document.getElementById('deepWave').addEventListener('click', () => deepRun(1));
|
||
document.getElementById('deepWave5').addEventListener('click', () => deepRun(5));
|
||
document.getElementById('deepToTop').addEventListener('click', () => deepRun(80));
|
||
document.getElementById('deepReset').addEventListener('click', deepReset);
|
||
document.getElementById('deepFill').addEventListener('input', e => { document.getElementById('deepFillVal').textContent = e.target.value + '%'; deepReset(); });
|
||
|
||
|
||
// ── grow a real org, month by month (the realistic run) ──
|
||
const SEED = {"apex":1,"m":[[1,0,6,18],[2,1,4,32],[3,1,4,17],[4,21,2,2],[5,3,1,2],[6,2,2,2],[7,2,2,5],[8,1,2,3],[9,2,1,2],[10,2,3,95],[11,3,2,2],[12,1,2,2],[13,8,2,2],[14,8,2,4],[15,14,2,4],[16,1,1,2],[17,1,2,2],[18,2,1,2],[19,3,1,2],[20,2,2,2],[21,2,3,9],[22,2,1,2],[23,3,1,2],[24,2,1,2],[25,11,1,2],[26,8,1,2],[27,12,1,2],[28,4,1,2],[29,4,1,2],[30,5,1,2],[31,5,1,2],[32,3,1,2],[33,7,2,2],[34,7,2,2],[35,9,1,2],[36,9,1,2],[37,15,1,2],[38,10,2,7],[39,10,2,3],[40,16,1,2],[41,10,2,2],[42,10,1,2],[43,16,1,2],[44,17,1,2],[45,17,1,2],[46,18,1,2],[47,18,1,2],[48,19,1,2],[49,19,1,2],[50,20,1,2],[51,10,1,2],[52,20,1,2],[53,10,1,2],[54,1,2,13],[55,22,1,2],[56,22,1,2],[57,23,1,2],[58,10,1,2],[59,10,1,2],[60,23,1,2],[61,10,1,2],[62,24,1,2],[63,10,2,2],[64,10,1,2],[65,54,1,2],[66,10,1,2],[67,24,1,2],[68,63,1,2],[69,25,1,2],[70,3,1,2],[71,54,1,2],[72,15,1,2],[73,54,1,2],[74,10,1,2],[75,25,1,2],[76,26,1,2],[77,26,1,2],[78,2,3,5],[79,27,1,2],[80,27,3,2],[81,10,1,2],[82,10,1,2],[83,28,1,2],[84,10,1,2],[85,10,1,2],[86,28,1,2],[87,29,1,2],[88,29,1,2],[89,30,1,2],[90,12,1,2],[91,54,2,0],[92,30,1,0],[93,2,3,3],[94,31,1,0],[95,54,1,0],[96,10,1,0],[97,54,1,3],[98,31,1,0],[99,32,1,0],[100,10,1,0],[101,1,2,12],[102,101,2,39],[103,32,1,0],[104,101,1,0],[105,101,2,39],[106,10,1,0],[107,101,1,0],[108,10,1,0],[109,3,1,0],[110,33,1,0],[111,33,1,0],[112,34,1,0],[113,2,2,7],[114,34,1,0],[115,102,1,0],[116,113,2,2],[117,101,2,19],[118,101,2,0],[119,11,1,0],[120,101,3,2],[121,101,1,0],[122,120,2,0],[123,116,1,0],[124,113,2,5],[125,113,3,2],[126,113,2,0],[127,124,2,0],[128,125,2,0],[129,120,1,0],[130,125,2,2],[131,130,1,0],[132,124,3,6],[133,3,1,0],[134,113,2,2],[135,10,1,0],[136,134,1,0],[137,134,2,0],[138,10,1,11],[139,132,2,5],[140,105,1,0],[141,102,1,0],[142,124,2,0],[143,102,1,0],[144,116,2,2],[145,144,1,0],[146,132,2,0],[147,139,3,10],[148,54,1,0],[149,147,2,2],[150,149,1,0],[151,139,2,0],[152,124,2,0],[153,124,2,0],[154,102,1,0],[155,35,1,0],[156,113,2,0],[157,147,2,0],[158,2,1,0],[159,10,1,0],[160,102,1,0],[161,2,2,2],[162,101,2,0],[163,101,2,2],[164,144,2,0],[165,10,1,2],[166,102,1,0],[167,35,1,0],[168,101,2,0],[169,10,2,5],[170,102,1,0],[171,10,1,0],[172,165,1,0],[173,97,1,0],[174,10,2,0],[175,10,2,5],[176,117,1,0],[177,10,1,0],[178,117,1,0],[179,102,1,0],[180,2,1,0],[181,113,2,0],[182,117,1,0],[183,10,1,0],[184,117,2,17],[185,102,1,0],[186,10,1,0],[187,117,1,0],[188,36,1,0],[189,36,1,0],[190,40,1,0],[191,117,1,0],[192,139,2,0],[193,117,1,3],[194,102,1,0],[195,139,2,3],[196,130,2,0],[197,102,1,0],[198,10,2,2],[199,101,1,10],[200,10,1,0],[201,10,1,0],[202,37,1,0],[203,117,1,0],[204,117,1,0],[205,40,1,0],[206,117,1,0],[207,41,1,0],[208,117,1,0],[209,41,1,0],[210,3,1,0],[211,117,1,0],[212,10,1,0],[213,238,1,0],[214,42,1,0],[215,54,1,0],[216,117,1,0],[217,10,2,2],[218,62,1,0],[219,62,1,0],[220,117,1,0],[221,169,1,0],[222,1,1,0],[223,199,2,7],[224,97,1,0],[225,42,1,0],[226,184,1,0],[227,217,2,2],[228,102,1,0],[229,184,1,0],[230,195,1,0],[231,227,1,0],[232,43,1,0],[233,43,1,0],[234,102,1,0],[235,1,2,4],[236,102,1,0],[237,169,1,0],[238,184,2,7],[239,169,1,0],[240,78,1,0],[241,184,1,2],[242,21,1,0],[243,132,2,0],[244,139,2,0],[245,223,1,0],[246,132,2,0],[247,184,1,0],[248,2,1,0],[249,241,1,2],[250,10,1,0],[251,10,1,0],[252,117,2,0],[253,102,1,0],[254,117,2,0],[255,227,1,0],[256,199,1,0],[257,10,1,0],[258,241,1,0],[259,184,1,0],[260,10,1,0],[261,249,1,0],[262,44,1,0],[263,138,1,0],[264,44,1,0],[265,10,1,0],[266,45,1,0],[267,10,1,0],[268,184,1,0],[269,45,1,0],[270,184,1,0],[271,138,1,0],[272,10,1,0],[273,46,1,0],[274,21,1,0],[275,46,1,0],[276,223,1,0],[277,10,1,0],[278,47,1,0],[279,1,1,0],[280,10,3,0],[281,184,1,0],[282,184,3,0],[283,47,1,0],[284,48,1,0],[285,102,1,0],[286,48,1,0],[287,49,1,0],[288,49,1,0],[289,50,1,0],[290,199,2,6],[291,184,1,0],[292,10,1,0],[293,199,1,2],[294,138,1,0],[295,10,1,0],[296,10,1,0],[297,199,1,0],[298,21,1,0],[299,223,1,0],[300,184,1,0],[301,10,1,0],[302,50,1,0],[303,293,1,0],[304,102,1,0],[305,51,1,0],[306,138,1,0],[307,51,1,0],[308,52,1,0],[309,52,1,0],[310,223,3,2],[311,310,1,0],[312,10,2,3],[313,53,1,0],[314,21,1,0],[315,249,1,0],[316,184,1,0],[317,184,1,0],[318,21,1,0],[319,184,1,0],[320,53,1,0],[321,195,1,0],[322,55,1,0],[323,55,1,0],[324,238,1,0],[325,199,1,0],[326,117,1,0],[327,56,1,0],[328,10,3,3],[329,238,1,0],[330,138,1,0],[331,199,3,2],[332,3,1,0],[333,10,1,0],[334,10,1,0],[335,199,1,0],[336,93,1,0],[337,293,1,0],[338,138,1,0],[339,217,2,0],[340,56,1,0],[341,238,1,0],[342,2,1,0],[343,138,1,0],[344,10,1,0],[345,37,1,0],[346,138,1,0],[347,10,2,2],[348,57,1,0],[349,184,1,0],[350,10,1,0],[351,57,1,0],[352,58,1,0],[353,138,1,0],[354,328,2,0],[355,328,2,2],[356,147,1,2],[357,102,1,0],[358,102,1,0],[359,132,1,0],[360,238,1,0],[361,58,1,0],[362,102,1,0],[363,312,2,2],[364,105,1,0],[365,105,1,0],[366,105,1,0],[367,102,1,0],[368,39,1,0],[369,105,1,0],[370,355,1,0],[371,10,1,0],[372,312,4,2],[373,238,1,0],[374,356,1,0],[375,105,1,0],[376,10,1,0],[377,223,1,0],[378,102,1,0],[379,310,1,0],[380,105,1,0],[381,2,1,0],[382,105,1,0],[383,102,1,0],[384,10,3,3],[385,290,1,0],[386,105,1,0],[387,105,1,0],[388,372,1,0],[389,331,1,0],[390,59,1,0],[391,21,1,0],[392,21,1,0],[393,102,1,0],[394,102,2,0],[395,328,2,0],[396,117,1,0],[397,21,1,0],[398,290,1,2],[399,105,1,0],[400,59,1,0],[401,102,1,0],[402,105,1,0],[403,199,1,0],[404,105,1,0],[405,102,1,0],[406,138,1,0],[407,54,1,0],[408,2,1,0],[409,105,1,0],[410,97,1,0],[411,105,1,0],[412,14,1,0],[413,355,1,0],[414,10,1,0],[415,398,1,2],[416,356,1,0],[417,105,1,0],[418,14,1,0],[419,105,1,0],[420,10,1,0],[421,415,2,2],[422,2,1,0],[423,54,1,0],[424,2,2,2],[425,424,1,0],[426,102,1,0],[427,105,1,0],[428,10,1,0],[429,105,1,0],[430,421,1,0],[431,93,1,0],[432,149,1,0],[433,147,1,0],[434,105,1,0],[435,2,1,0],[436,10,1,2],[437,93,1,0],[438,2,1,0],[439,398,1,0],[440,102,1,0],[441,38,1,0],[442,235,1,0],[443,331,1,0],[444,421,1,0],[445,102,1,0],[446,105,2,7],[447,312,1,0],[448,10,1,0],[449,235,1,0],[450,415,1,0],[451,2,1,0],[452,105,1,0],[453,105,1,0],[454,2,2,0],[455,10,1,0],[456,105,1,0],[457,424,1,0],[458,138,1,0],[459,10,1,0],[460,10,1,0],[461,10,1,0],[462,436,1,0],[463,10,3,2],[464,102,1,0],[465,10,1,0],[466,223,1,0],[467,10,1,0],[468,363,2,0],[469,363,2,0],[470,105,1,0],[471,10,1,0],[472,347,1,0],[473,132,1,0],[474,105,1,0],[475,446,1,0],[476,38,1,0],[477,463,1,0],[478,60,1,0],[479,2,1,0],[480,147,1,0],[481,199,1,0],[482,54,1,0],[483,105,1,0],[484,238,1,0],[485,105,1,0],[486,10,1,0],[487,60,1,0],[488,290,1,0],[489,10,1,0],[490,38,1,0],[491,10,1,0],[492,290,1,0],[493,61,1,0],[494,10,1,0],[495,10,1,0],[496,10,2,0],[497,2,1,0],[498,10,1,0],[499,61,1,0],[500,64,1,0],[501,10,1,0],[502,1,1,0],[503,10,1,0],[504,147,1,0],[505,10,1,0],[506,147,1,0],[507,64,1,0],[508,10,1,0],[509,195,1,0],[510,102,1,0],[511,193,1,0],[512,446,1,0],[513,65,1,0],[514,65,1,0],[515,102,1,0],[516,105,1,0],[517,66,1,0],[518,66,1,0],[519,175,1,0],[520,10,1,0],[521,67,1,0],[522,67,1,0],[523,68,1,0],[524,2,1,0],[525,3,1,0],[526,3,1,0],[527,1,1,0],[528,223,1,0],[529,78,1,0],[530,68,1,0],[531,69,1,0],[532,69,1,0],[533,105,1,0],[534,102,1,0],[535,70,1,0],[536,70,1,0],[537,10,1,0],[538,290,1,0],[539,38,1,0],[540,10,1,0],[541,71,1,0],[542,10,1,0],[543,71,1,0],[544,72,1,0],[545,63,1,0],[546,105,1,0],[547,10,2,0],[548,290,1,0],[549,235,1,0],[550,72,1,0],[551,384,1,0],[552,436,1,0],[553,105,1,0],[554,384,1,0],[555,73,1,0],[556,73,1,0],[557,161,1,0],[558,161,1,0],[559,446,1,0],[560,6,1,0],[561,74,1,0],[562,105,1,0],[563,384,1,0],[564,74,1,0],[565,2,1,0],[566,7,1,0],[567,1,1,0],[568,7,1,0],[569,105,1,0],[570,75,1,0],[571,446,1,0],[572,105,1,0],[573,3,1,0],[574,75,1,0],[575,13,1,0],[576,175,1,0],[577,13,1,0],[578,163,1,0],[579,102,1,0],[580,117,1,0],[581,347,1,0],[582,10,1,0],[583,76,1,0],[584,105,1,0],[585,76,1,0],[586,169,1,0],[587,6,1,0],[588,463,1,0],[589,446,1,0],[590,77,1,0],[591,193,1,0],[592,10,1,0],[593,15,1,0],[594,77,1,0],[595,10,1,0],[596,175,1,0],[597,38,1,0],[598,175,1,0],[599,446,1,0],[600,79,1,0],[601,79,1,0],[602,3,1,0],[603,81,1,0],[604,198,1,0],[605,2,1,0],[606,81,1,0],[607,102,1,0],[608,2,1,0],[609,163,1,0],[610,198,1,0],[611,165,1,0],[612,102,1,0],[613,3,1,0],[614,82,1,0],[615,3,1,0],[616,38,2,0],[617,39,1,0],[618,14,1,0],[619,147,1,0],[620,15,1,0],[621,193,1,0],[622,175,1,0],[623,105,1,0],[624,82,1,0],[625,83,1,0],[626,83,1,0],[627,84,1,0],[628,102,1,0],[629,84,1,0],[630,85,1,0],[631,10,2,0],[632,85,1,0],[633,86,1,0],[634,10,1,0],[635,105,1,0],[636,54,1,0],[637,102,1,0],[638,86,1,0],[639,87,1,0],[640,105,1,0],[641,3,1,0],[642,372,1,0],[643,184,1,0],[644,87,1,0],[645,78,1,0],[646,2,1,0],[647,78,1,0],[648,54,1,0],[649,38,1,0],[650,7,1,0],[651,1,2,15],[652,1,1,0],[653,88,1,0],[654,39,1,0],[655,10,1,0],[656,1,1,0],[657,147,1,0],[658,78,1,0],[659,88,1,0],[660,89,1,0],[661,651,1,0],[662,651,2,3],[663,651,1,0],[664,651,1,0],[665,651,1,0],[666,651,1,0],[667,651,1,0],[668,651,2,0],[669,662,1,0],[670,89,1,0],[671,90,1,0],[672,80,1,0],[673,662,1,0],[674,90,1,0],[675,662,1,0],[676,169,1,0],[677,446,1,0],[678,651,1,0],[679,651,1,0],[680,80,1,0],[681,651,1,0],[682,1,3,1],[683,651,1,0],[684,651,1,0],[685,147,1,0],[686,651,1,0],[687,682,2,0],[688,235,1,0],[689,651,1,0]]}; // the InstantAdPay org: [id, recruiterId, levelBought, recruits], no names
|
||
let G = null; window.reachG = () => ({ G, PLAN }); // read-only handle for the check scripts
|
||
let rnd = mulberry32(7);
|
||
function mulberry32(a){ return function(){ a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }
|
||
function gAdd(parent, recruiter, month){
|
||
const m = { id: G.nextId++, parent, kids: [], depth: parent ? parent.depth + 1 : 0, level: 1, directs: 0, recruiter, cash: 0, entry: 0, lic: 0, licV: 0, cashFrom: 0, cashFromHalf: 0, month, m0: 0, mDirects: 0, sp: 0 };
|
||
G.members.push(m); if (parent) parent.kids.push(m);
|
||
return m;
|
||
}
|
||
function gSlot(root){
|
||
if (PLAN.place !== 'spread') { const q = [root]; while (q.length) { const n = q.shift(); if (n.kids.length < PLAN.w) return n; for (const k of n.kids) q.push(k); } return root; }
|
||
// spread: still fill the shallowest depth first, but within that depth give the position with the fewest
|
||
// children the next one, so each gets one before any gets two (plain breadth-first fills one position to
|
||
// four before the next gets any). A pure "fewest children anywhere" rule turns the org into a chain.
|
||
let level = [root];
|
||
while (level.length) {
|
||
const open = level.filter(n => n.kids.length < PLAN.w);
|
||
if (open.length) { let best = open[0]; for (const n of open) if (n.kids.length < best.kids.length) best = n; return best; }
|
||
const next = []; for (const n of level) for (const k of n.kids) next.push(k); level = next;
|
||
}
|
||
return root;
|
||
}
|
||
// an entry: placed breadth-first under the recruiter (or assigned to a member short of a direct), paid, split
|
||
function gJoin(recruiter, month, unsponsored){
|
||
if (!recruiter) { // assigned: earliest member with one recruit, else earliest with none (never you)
|
||
recruiter = G.members.find(x => x !== G.you && x.directs === 1) || G.members.find(x => x !== G.you && x.directs === 0) || G.you;
|
||
}
|
||
const parent = gSlot(recruiter);
|
||
const m = gAdd(parent, recruiter, month); m.unsponsored = !!unsponsored;
|
||
recruiter.directs++; recruiter.mDirects++; if (recruiter.directs === 1) recruiter.cashFromHalf = m.id; if (recruiter.directs === 2) recruiter.cashFrom = m.id;
|
||
const gross = price(1), fee = gross * PLAN.fee, n = gross - fee;
|
||
G.aud.spent += gross; G.aud.entryFee += fee; G.aud.received += fee;
|
||
const toRec = n * (1 - PLAN.split), toUp = n * PLAN.split;
|
||
recruiter.entry += toRec; parent.entry += toUp; G.aud.received += n;
|
||
G.mon.in += gross; G.mon.admin += fee; G.mon.joins++; if (unsponsored) G.mon.assigned++;
|
||
if (month > 0 && PLAN.fsTake > 0 && rnd() < PLAN.fsTake) for (let L = 2; L <= Math.min(PLAN.fsLevels, PLAN.maxL); L++) gBuy(m, L); // Fast Start at join
|
||
return m;
|
||
}
|
||
function gCashOk(u, origin, L){
|
||
const own = !PLAN.wm || origin.recruiter === u;
|
||
if (u.directs >= 2) return own || origin.id >= u.cashFrom;
|
||
if (PLAN.half && u.directs === 1 && L <= 3) return own || origin.id >= u.cashFromHalf;
|
||
if (PLAN.zero && L <= 2) return true; // level-2 money from your own depth 1 needs no recruits
|
||
return false;
|
||
}
|
||
// The sponsor leg: a share of every level purchase follows the recruiter line (your sponsor, their sponsor...),
|
||
// not the placement line. Cash to the first one who holds the level and may take cash; a licence for one who is
|
||
// behind, only when the money covers it; otherwise it climbs as cash-only. Never a licence from money that is short.
|
||
function gRouteS(from, L, rem, origin){
|
||
let cur = from.recruiter;
|
||
while (cur) {
|
||
if (cur.level >= L) { if (gCashOk(cur, origin, L)) return { to: cur, kind: 'cash' }; }
|
||
else if (!rem) { const licOk = cur.directs >= 2 || PLAN.unq === 'licence'; if (licOk) return { to: cur, kind: 'lic' }; }
|
||
cur = cur.recruiter;
|
||
}
|
||
return { to: null };
|
||
}
|
||
function gPayS(from, L, amt, origin, rem){
|
||
let r = gRouteS(from, L, rem, origin);
|
||
if (r.to && r.kind === 'lic' && amt < net(r.to.level + 1) - 0.005) r = gRouteS(from, L, true, origin);
|
||
if (!r.to) { G.aud.above += amt; G.aud.received += amt; G.mon.above += amt; return; }
|
||
if (r.kind === 'cash') { r.to.cash += amt; r.to.sp += amt; G.mon.sp += amt; G.aud.received += amt; return; }
|
||
const n = r.to.level + 1, cost = net(n);
|
||
r.to.level = n; r.to.lic++; r.to.licV += cost; G.mon.lics++;
|
||
gFlow(r.to, n, cost, origin);
|
||
if (amt - cost > 0.005) gPayS(r.to, L, amt - cost, origin, true);
|
||
}
|
||
// every purchase, paid or licence, splits the same way: sponsor leg first, the rest by depth
|
||
function gFlow(m, L, amt, origin){ const sp = amt * PLAN.sponsor; if (sp > 0) gPayS(m, L, sp, origin, false); gPay(m, L, amt - sp, L - 2, origin, false); }
|
||
function gRoute(from, L, skipN, rem, origin){
|
||
let cur = from.parent; for (let i = 0; i < skipN && cur; i++) cur = cur.parent;
|
||
while (cur) {
|
||
if (cur.level >= L) { if (gCashOk(cur, origin, L)) return { to: cur, kind: 'cash' }; }
|
||
else if (!rem) { const behindOk = PLAN.gap === 'fund' || cur.level >= L - 1, licOk = cur.directs >= 2 || PLAN.unq === 'licence'; if (behindOk && licOk) return { to: cur, kind: 'lic' }; }
|
||
cur = cur.parent;
|
||
}
|
||
return { to: null };
|
||
}
|
||
function gPay(from, L, amt, skipN, origin, rem){
|
||
let r = gRoute(from, L, skipN, rem, origin);
|
||
if (r.to && r.kind === 'lic' && amt < net(r.to.level + 1) - 0.005) r = gRoute(from, L, skipN, true, origin); // short money never buys a licence; it climbs as cash
|
||
if (!r.to) { G.aud.above += amt; G.aud.received += amt; G.mon.above += amt; return; }
|
||
if (r.kind === 'cash') { r.to.cash += amt; G.aud.received += amt; return; }
|
||
const n = r.to.level + 1, cost = net(n);
|
||
r.to.level = n; r.to.lic++; r.to.licV += cost; G.mon.lics++;
|
||
gFlow(r.to, n, cost, origin);
|
||
if (amt - cost > 0.005) gPay(r.to, L, amt - cost, 0, origin, true);
|
||
}
|
||
function gBuy(m, L){ m.bought = (m.bought || 0) + 1; const gross = price(L), fee = gross * PLAN.fee; G.aud.spent += gross; G.aud.admin += fee; G.aud.received += fee; G.mon.in += gross; G.mon.admin += fee; G.mon.buys++; m.level = Math.max(m.level, L); gFlow(m, L, gross - fee, m); }
|
||
function gNewMonth(){ G.mon = { in: 0, admin: 0, joins: 0, assigned: 0, buys: 0, lics: 0, above: 0, sp: 0 }; for (const m of G.members) { m.m0 = m.cash + m.entry; m.mDirects = 0; } }
|
||
function gReset(){
|
||
rnd = mulberry32(7);
|
||
G = { month: 0, members: [], nextId: 1, you: null, rows: [], aud: { spent: 0, received: 0, admin: 0, entryFee: 0, above: 0 } };
|
||
gNewMonth();
|
||
G.you = gAdd(null, null, 0);
|
||
const seed = document.getElementById('gSeed').value;
|
||
if (seed === 'iap') {
|
||
const map = new Map([[SEED.apex, G.you]]);
|
||
const rows = SEED.m.filter(r => r[0] !== SEED.apex).sort((a, b) => a[0] - b[0]);
|
||
for (const r of rows) { const rec = map.get(r[1]); const m = gJoin(rec && rec !== G.you ? rec : (r[1] === SEED.apex ? G.you : null), 0, !rec); map.set(r[0], m); m.seedLevel = r[2]; }
|
||
for (let L = 2; L <= PLAN.maxL; L++) for (const m of G.members.slice().sort((a, b) => a.depth - b.depth || a.id - b.id)) if (m !== G.you && (m.seedLevel || 1) >= L && m.level < L) gBuy(m, L);
|
||
}
|
||
// Start over means start over (Marty, 28 Sep): the replay above only builds the org. Its money is reported once,
|
||
// in the story head, then every counter goes back to zero and members keep only the levels they actually bought.
|
||
G.replay = { in: G.aud.spent, admin: G.aud.admin + G.aud.entryFee, you: G.you.cash + G.you.entry, youLevel: G.you.level };
|
||
for (const m of G.members) { m.cash = 0; m.entry = 0; m.lic = 0; m.licV = 0; m.level = m === G.you ? 1 : (m.seedLevel || 1); }
|
||
G.aud = { spent: 0, received: 0, admin: 0, entryFee: 0, above: 0 }; gNewMonth();
|
||
G.rows.push(gSnap(0));
|
||
const ol = document.getElementById('gStory'); if (ol) ol.innerHTML = '<li class="head">' + (seed === 'iap' ? 'Start: the InstantAdPay org today, placed 4-wide under each member\u2019s real recruiter: <b>' + cnt(G.members.length - 1) + ' members</b>, ' + cnt(G.members.filter(x => x.level >= 2).length) + ' of them past level 1 (the levels they actually bought), ' + cnt(G.members.filter(x => x.directs >= 2).length) + ' qualified. Every counter starts at zero and counts only what happens from month 1. For reference, had these rules been running all along, their past purchases would have moved <b>' + $$(G.replay.in) + '</b>, put <b>' + $$(G.replay.admin) + '</b> in the admin wallet and <b>' + $$(G.replay.you) + '</b> to you, funding you to level ' + G.replay.youLevel + '.' : 'Start: just you at level 1, nobody under you yet. In month 1 you recruit two people yourself (everyone needs two to receive cash at full reach); after that the org grows the way InstantAdPay’s did.') + ' Now run a month.</li>';
|
||
gRender();
|
||
window.growAudit = () => ({ spent: Math.round(G.aud.spent), received: Math.round(G.aud.received), ok: Math.abs(G.aud.spent - G.aud.received) <= 0.01 + 1e-9 * G.aud.spent });
|
||
}
|
||
function gSnap(month){
|
||
const ms = G.members.filter(x => x !== G.you);
|
||
const grp = f => { const g = ms.filter(f), v = g.map(x => x.cash + x.entry).sort((a, b) => b - a); return { n: g.length, paid: g.filter(x => x.cash + x.entry > 0).length, total: v.reduce((a, b) => a + b, 0), median: v.length ? v[Math.floor(v.length / 2)] : 0, top: v[0] || 0, lic: g.reduce((a, x) => a + x.lic, 0) }; };
|
||
let topB = null; for (const x of ms) if (!topB || x.mDirects > topB.mDirects) topB = x;
|
||
const b20 = ms.filter(x => x.mDirects >= 20);
|
||
const extra = { sp: G.mon.sp, heavy: grp(x => x.directs >= 10), light: grp(x => x.directs >= 1 && x.directs < 10), passive: grp(x => x.directs === 0),
|
||
top: topB && topB.mDirects > 0 ? { id: topB.id, n: topB.mDirects, m: topB.cash + topB.entry - topB.m0, total: topB.cash + topB.entry, level: topB.level, directs: topB.directs } : null,
|
||
b20: { n: b20.length, avg: b20.length ? b20.reduce((a, x) => a + x.cash + x.entry - x.m0, 0) / b20.length : 0 } };
|
||
return { ...extra, month, joins: G.mon.joins, assigned: G.mon.assigned, buys: G.mon.buys, lics: G.mon.lics, members: ms.length, in: G.mon.in, admin: G.mon.admin, above: G.mon.above,
|
||
toMembers: ms.reduce((a, x) => a + x.cash + x.entry, 0), toYou: G.you.cash + G.you.entry, youLevel: G.you.level, youLic: G.you.lic,
|
||
paid: ms.filter(x => x.cash + x.entry > 0).length, l2: ms.filter(x => x.level >= 2).length, qualified: ms.filter(x => x.directs >= 2).length };
|
||
}
|
||
function gMonth(){
|
||
G.month++; gNewMonth();
|
||
const J0 = Number(document.getElementById('gJoins').value), g = Number(document.getElementById('gGrowth').value) / 100, pBuy = Number(document.getElementById('gBuy').value) / 100;
|
||
const joins = Math.round(J0 * Math.pow(1 + g, G.month - 1));
|
||
const U = 0.24; // share who arrive with no recruiter (InstantAdPay: 164 of 688)
|
||
for (let i = 0; i < joins; i++) {
|
||
let rec = null, unsp = false;
|
||
if (G.you.directs < 2 && G.month === 1 && i < 2) rec = G.you; // starting from just you: you bring your first two yourself, like everyone must
|
||
else if (rnd() < U) { unsp = true; }
|
||
else {
|
||
const pool = G.members.filter(x => x !== G.you);
|
||
if (rnd() < 0.85 && pool.some(x => x.directs > 0)) { // an existing recruiter, weighted by how many they already brought (top tenth bring half)
|
||
const rs = pool.filter(x => x.directs > 0); let tot = 0; for (const x of rs) tot += x.directs + 1; let t = rnd() * tot;
|
||
for (const x of rs) { t -= x.directs + 1; if (t <= 0) { rec = x; break; } } if (!rec) rec = rs[rs.length - 1];
|
||
} else if (pool.length) { rec = pool[Math.floor(rnd() * pool.length)]; } // a first-time recruiter
|
||
else rec = G.you;
|
||
}
|
||
gJoin(rec, G.month, unsp);
|
||
}
|
||
// upgrades: each member at level L buys L+1 with probability pBuy, shallow to deep; licences from below make some of these free
|
||
for (const m of G.members.slice().sort((a, b) => a.depth - b.depth || a.id - b.id)) { if (m === G.you || m.level >= PLAN.maxL) continue; if (rnd() < pBuy) gBuy(m, m.level + 1); }
|
||
const s = gSnap(G.month); G.rows.push(s);
|
||
const prev = G.rows[G.rows.length - 2];
|
||
const dYou = s.toYou - prev.toYou;
|
||
storyG('<b>Month ' + G.month + '.</b> ' + cnt(s.joins) + ' joined' + (s.assigned ? ', ' + cnt(s.assigned) + ' of them with no recruiter, assigned to members short of a direct' : '') + '. ' + cnt(s.buys) + ' bought a level with their own money and ' + cnt(s.lics) + ' licences were funded by pass-ups. Money in <b>' + $$(s.in) + '</b>: admin wallet <b>' + $$(s.admin) + '</b>, the rest to members' + (s.above ? ' (' + $$(s.above) + ' climbed past you to the company)' : '') + '. You: <b>' + (dYou >= 0 ? '+' : '') + $$(dYou) + '</b>' + (s.youLevel > prev.youLevel ? ', and your team moved you to <span class="chip lic">level ' + s.youLevel + '</span>' : '') + '. ' + cnt(s.paid) + ' of ' + cnt(s.members) + ' members have been paid something; ' + cnt(s.l2) + ' are past level 1.' + (s.top ? ' <b>Heaviest builder this month:</b> #' + s.top.id + ' brought ' + cnt(s.top.n) + ' and made <b>' + $$(s.top.m) + '</b> this month (' + $$(s.top.total) + ' so far, level ' + s.top.level + ', ' + cnt(s.top.directs) + ' recruits in all).' : '') + (s.b20.n ? ' Builders who brought 20+ this month: ' + cnt(s.b20.n) + ', averaging <b>' + $$(s.b20.avg) + '</b> this month.' : '') + (s.sp ? ' Sponsor leg paid ' + $$(s.sp) + ' this month.' : ''), s.youLevel > prev.youLevel ? 'lic' : 'cash');
|
||
gRender();
|
||
}
|
||
function storyG(html, cls){ const ol = document.getElementById('gStory'); if (!ol) return; const li = document.createElement('li'); if (cls) li.className = cls; li.innerHTML = html; ol.prepend(li); while (ol.children.length > 40) ol.removeChild(ol.lastChild); }
|
||
function gRender(){
|
||
const s = G.rows[G.rows.length - 1];
|
||
document.getElementById('gMonth').textContent = G.month; document.getElementById('gMembers').textContent = cnt(s.members) + ' members';
|
||
document.getElementById('gLevel').textContent = s.youLevel; document.getElementById('gLevelS').textContent = 'reach = depth 1 to ' + s.youLevel + ' \u00b7 ' + s.youLic + ' licence' + (s.youLic === 1 ? '' : 's') + ' funded for you';
|
||
document.getElementById('gYou').textContent = $$(s.toYou); document.getElementById('gYouS').textContent = 'cash ' + $$(G.you.cash) + ' + entries ' + $$(G.you.entry) + '; licences worth ' + $$(G.you.licV) + ' apart';
|
||
document.getElementById('gAdmin').textContent = $$(G.aud.admin + G.aud.entryFee);
|
||
document.getElementById('gPaid').textContent = cnt(s.paid); document.getElementById('gPaidS').textContent = 'of ' + cnt(s.members) + ' (' + (s.members ? Math.round(100 * s.paid / s.members) : 0) + '%) \u00b7 ' + cnt(s.qualified) + ' qualified';
|
||
document.getElementById('gIn').textContent = $$(G.aud.spent);
|
||
const tb = document.querySelector('#gTable tbody'); if (tb) { tb.innerHTML = ''; for (const r of G.rows) { const tr = document.createElement('tr'); tr.innerHTML = '<td>' + r.month + '</td><td>' + cnt(r.joins) + '</td><td>' + cnt(r.members) + '</td><td>' + cnt(r.buys) + '</td><td>' + $$(r.in) + '</td><td>' + $$(r.admin) + '</td><td>' + $$(r.in - r.admin - r.above) + '</td><td>' + $$(r.toYou) + '</td><td>' + r.youLevel + '</td><td>' + cnt(r.paid) + '</td><td>' + cnt(r.l2) + '</td>'; tb.appendChild(tr); } }
|
||
const sp = document.getElementById('gSpread');
|
||
if (sp) {
|
||
const ms = G.members.filter(x => x !== G.you).map(x => x.cash + x.entry).sort((a, b) => b - a);
|
||
const pct = (p) => ms.length ? ms[Math.min(ms.length - 1, Math.floor(ms.length * p))] : 0;
|
||
const top10 = ms.slice(0, Math.max(1, Math.round(ms.length * 0.1))).reduce((a, b) => a + b, 0), all = ms.reduce((a, b) => a + b, 0);
|
||
const lv = {}; for (const x of G.members) if (x !== G.you) lv[x.level] = (lv[x.level] || 0) + 1;
|
||
const older = G.members.filter(x => x !== G.you && G.month - x.month >= 6), olderPaid = older.filter(x => x.cash + x.entry > 0);
|
||
const olderVals = older.map(x => x.cash + x.entry).sort((a, b) => b - a), olderMed = olderVals.length ? olderVals[Math.floor(olderVals.length / 2)] : 0;
|
||
const carried = G.members.filter(x => x !== G.you && x.level >= 2 && !(x.bought || 0)).length, ownBuy = G.members.filter(x => x !== G.you && (x.bought || 0) > 0).length;
|
||
sp.innerHTML = 'Top earner in the org: <b>' + $$(ms[0] || 0) + '</b>. Top 10% of members took ' + (all ? Math.round(100 * top10 / all) : 0) + '% of what members received. Median member: <b>' + $$(pct(0.5)) + '</b>. Members with nothing: ' + cnt(ms.filter(v => v <= 0).length) + ' (most of them joined recently).'
|
||
+ '<br><b>Members in for 6 months or more:</b> ' + cnt(older.length) + ', of whom ' + cnt(olderPaid.length) + ' (' + (older.length ? Math.round(100 * olderPaid.length / older.length) : 0) + '%) have been paid; their median is <b>' + $$(olderMed) + '</b>.'
|
||
+ '<br><b>Product without paying:</b> ' + cnt(carried) + ' members hold level 2 or higher purely from licences their team funded; ' + cnt(ownBuy) + ' bought at least one level themselves.'
|
||
+ (() => { const s0 = G.rows[G.rows.length - 1]; const line = (name, g) => '<br><b>' + name + ':</b> ' + cnt(g.n) + ' members, ' + cnt(g.paid) + ' paid (' + (g.n ? Math.round(100 * g.paid / g.n) : 0) + '%), median <b>' + $$(g.median) + '</b>, top ' + $$(g.top) + ', ' + cnt(g.lic) + ' licences, ' + (all ? Math.round(100 * g.total / all) : 0) + '% of member income'; return '<br><b>The mix.</b>' + line('Builders, 10+ recruits', s0.heavy) + line('Light builders, 1 to 9', s0.light) + line('Join-and-pay members, no recruits', s0.passive); })()
|
||
+ '<br>Levels held: ' + Object.keys(lv).map(Number).sort((a, b) => a - b).map(L => 'L' + L + ' ' + cnt(lv[L])).join(' \u00b7 ') + '.';
|
||
}
|
||
}
|
||
function gRun(k){ for (let i = 0; i < k; i++) gMonth(); }
|
||
document.getElementById('gRun1').addEventListener('click', () => gRun(1));
|
||
document.getElementById('gRun6').addEventListener('click', () => gRun(6));
|
||
document.getElementById('gRun12').addEventListener('click', () => gRun(12));
|
||
document.getElementById('gReset').addEventListener('click', gReset);
|
||
document.getElementById('gSeed').addEventListener('change', gReset);
|
||
document.getElementById('gJoins').addEventListener('input', e => { document.getElementById('gJoinsVal').textContent = e.target.value; });
|
||
document.getElementById('gGrowth').addEventListener('input', e => { document.getElementById('gGrowthVal').textContent = (Number(e.target.value) >= 0 ? '+' : '') + e.target.value + '%'; });
|
||
document.getElementById('gBuy').addEventListener('input', e => { document.getElementById('gBuyVal').textContent = e.target.value + '%'; });
|
||
|
||
// ── plan controls ──
|
||
function applyPlan(){
|
||
PLAN.w = Number(document.getElementById('width').value);
|
||
PLAN.maxL = Number(document.getElementById('levels').value);
|
||
PLAN.shape = document.getElementById('shape').value;
|
||
PLAN.steps = document.getElementById('steps').value.split(',').map(s => Number(s.trim())).filter(n => n > 0);
|
||
PLAN.products = document.getElementById('products').value.split(',').map(s => s.trim()).filter(Boolean);
|
||
PLAN.fee = Number(document.getElementById('fee').value) || 0;
|
||
if (!PLAN.steps.length) PLAN.steps = [10];
|
||
document.getElementById('stepsCtl').hidden = PLAN.shape !== 'stepped';
|
||
document.getElementById('priceCtl').hidden = PLAN.shape === 'stepped';
|
||
document.getElementById('gapSkip').setAttribute('aria-pressed', String(PLAN.gap === 'skip'));
|
||
document.getElementById('gapFund').setAttribute('aria-pressed', String(PLAN.gap === 'fund'));
|
||
document.getElementById('unqSkip').setAttribute('aria-pressed', String(PLAN.unq === 'skip'));
|
||
document.getElementById('unqLic').setAttribute('aria-pressed', String(PLAN.unq === 'licence'));
|
||
document.getElementById('plShallow').setAttribute('aria-pressed', String(PLAN.place === 'shallow'));
|
||
document.getElementById('plSpread').setAttribute('aria-pressed', String(PLAN.place === 'spread'));
|
||
document.getElementById('zeroOff').setAttribute('aria-pressed', String(!PLAN.zero));
|
||
document.getElementById('zeroOn').setAttribute('aria-pressed', String(PLAN.zero));
|
||
for (const [id, v] of [['sp0', 0], ['sp30', 0.3], ['sp50', 0.5]]) document.getElementById(id).setAttribute('aria-pressed', String(PLAN.sponsor === v));
|
||
for (const [id, v] of [['en50', 0.5], ['en75', 0.25], ['en100', 0]]) document.getElementById(id).setAttribute('aria-pressed', String(PLAN.split === v));
|
||
for (const [id, v] of [['fs0', 0], ['fs10', 0.1], ['fs20', 0.2], ['fs35', 0.35]]) document.getElementById(id).setAttribute('aria-pressed', String(PLAN.fsTake === v));
|
||
document.getElementById('halfOff').setAttribute('aria-pressed', String(!PLAN.half));
|
||
document.getElementById('halfOn').setAttribute('aria-pressed', String(PLAN.half));
|
||
document.getElementById('wmOff').setAttribute('aria-pressed', String(!PLAN.wm));
|
||
document.getElementById('wmOn').setAttribute('aria-pressed', String(PLAN.wm));
|
||
const yl = document.getElementById('youLevel'); yl.max = PLAN.maxL; yl.value = 1; // a new plan starts you at level 1, like everyone
|
||
document.getElementById('youLevelVal').textContent = yl.value;
|
||
{ const dh = document.getElementById('deepHead'); if (dh) dh.textContent = 'Watch one position climb all ' + PLAN.maxL + ' levels'; }
|
||
svg.setAttribute('aria-label', PLAN.w + '-wide matrix under you');
|
||
build(); deepReset(); gReset();
|
||
}
|
||
for (const id of ['width', 'levels', 'shape']) document.getElementById(id).addEventListener('change', applyPlan);
|
||
document.getElementById('steps').addEventListener('change', applyPlan);
|
||
document.getElementById('products').addEventListener('change', applyPlan);
|
||
document.getElementById('fee').addEventListener('change', applyPlan);
|
||
document.getElementById('gapSkip').addEventListener('click', () => { PLAN.gap = 'skip'; applyPlan(); });
|
||
document.getElementById('gapFund').addEventListener('click', () => { PLAN.gap = 'fund'; applyPlan(); });
|
||
document.getElementById('unqSkip').addEventListener('click', () => { PLAN.unq = 'skip'; applyPlan(); });
|
||
document.getElementById('unqLic').addEventListener('click', () => { PLAN.unq = 'licence'; applyPlan(); });
|
||
document.getElementById('plShallow').addEventListener('click', () => { PLAN.place = 'shallow'; applyPlan(); });
|
||
document.getElementById('plSpread').addEventListener('click', () => { PLAN.place = 'spread'; applyPlan(); });
|
||
document.getElementById('zeroOff').addEventListener('click', () => { PLAN.zero = false; applyPlan(); });
|
||
document.getElementById('zeroOn').addEventListener('click', () => { PLAN.zero = true; applyPlan(); });
|
||
for (const [id, v] of [['sp0', 0], ['sp30', 0.3], ['sp50', 0.5]]) document.getElementById(id).addEventListener('click', () => { PLAN.sponsor = v; applyPlan(); });
|
||
for (const [id, v] of [['en50', 0.5], ['en75', 0.25], ['en100', 0]]) document.getElementById(id).addEventListener('click', () => { PLAN.split = v; applyPlan(); });
|
||
for (const [id, v] of [['fs0', 0], ['fs10', 0.1], ['fs20', 0.2], ['fs35', 0.35]]) document.getElementById(id).addEventListener('click', () => { PLAN.fsTake = v; applyPlan(); });
|
||
document.getElementById('halfOff').addEventListener('click', () => { PLAN.half = false; applyPlan(); });
|
||
document.getElementById('halfOn').addEventListener('click', () => { PLAN.half = true; applyPlan(); });
|
||
document.getElementById('wmOff').addEventListener('click', () => { PLAN.wm = false; applyPlan(); });
|
||
document.getElementById('wmOn').addEventListener('click', () => { PLAN.wm = true; applyPlan(); });
|
||
|
||
applyPlan();
|
||
})();
|