mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
Spieler gründen ab Stufe 5 eine eigene AG in Wiborien (Steckbrief, Logo aus dem Pool, Mitgründer), führen sie als Startup über Hebel und Quartalszahlen und bringen sie über das IPO-Modul an die Börse. Danach entscheidet je Quartal die Vorstandssitzung (Investitionen, Ausrichtung, Expansion, Dividende, Kapital- maßnahmen, Kredit, Prognose). Fairness: Haltefrist, Handelsfenster nach den Zahlen, Directors' Dealings, Deckel je Fenster, 75-%-Grenze, Glaubwürdigkeit. Grenzen in den Admin-Einstellungen (Gruppe Spielerfirmen), Admin-Übersicht, Hilfe/Handbuch, Simulation scripts/firmsim.mjs mit Ergebnis in BALANCING.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
273 lines
15 KiB
JavaScript
273 lines
15 KiB
JavaScript
// Hauptversammlungen: Jede Aktie hält einmal pro Saison eine Hauptversammlung ab – abends oder am Wochenende.
|
||
// – Tagesordnung je nach Unternehmen: Sonderdividende, Ermächtigung zum Aktienrückkauf, Kapitalerhöhung,
|
||
// neues Vergütungssystem für den Vorstand.
|
||
// – Ein (fiktiver) Stimmrechtsberater gibt vorab Empfehlungen; der Markt preist das erwartete Ergebnis ein.
|
||
// – Abstimmen dürfen alle, die die Aktie im Hauptdepot halten: Stimmen = Stückzahl, gezählt wird das Minimum aus
|
||
// Bestand bei der Stimmabgabe und Bestand bei Versammlungsende (kein Stimmenkauf in letzter Sekunde, kein Leihen).
|
||
// – Dazu stimmen Rivalen nach ihrem Charakter und institutionelle Anleger (Fonds) ab. Sind sich die Spieler einig,
|
||
// können sie die Fonds überstimmen.
|
||
// – Ergebnis zum Versammlungsende; Überraschungen gegenüber der Empfehlung bewegen den Kurs.
|
||
import { rnd, clamp, uid, fmt, r2 } from './util.js';
|
||
|
||
const ITEMS = {
|
||
dividend: { title: 'Sonderdividende', icon: 'euro' },
|
||
buyback: { title: 'Ermächtigung zum Aktienrückkauf', icon: 'repeat' },
|
||
capital: { title: 'Kapitalerhöhung', icon: 'plus' },
|
||
pay: { title: 'Neues Vergütungssystem für den Vorstand', icon: 'briefcase' },
|
||
};
|
||
const ADVISOR = 'Stimmrechtsberatung Glass & Lewitz'; // fiktiv
|
||
|
||
export class Agm {
|
||
constructor(g, saved) {
|
||
this.g = g;
|
||
this.state = { meetings: [], history: [], held: {}, ...(saved ?? {}) };
|
||
}
|
||
get cfg() { return this.g.cfg; }
|
||
snapshot() { return this.state; }
|
||
get open() { return this.state.meetings.filter((m) => m.status === 'open'); }
|
||
|
||
// ================================================================ Planen
|
||
/** Ende des nächsten Abend-/Wochenendfensters, das frühestens nach minMs beginnt */
|
||
#windowEnd(minMs) {
|
||
const c = this.g.clock, now = c.now();
|
||
const step = c.turbo ? Math.max(1000, this.cfg.dayMs / 40) : 30 * 60_000;
|
||
for (let t = now + minMs; t < now + minMs + (c.turbo ? 3 * this.cfg.dayMs : 6 * 86_400_000); t += step) {
|
||
const st = c.state(t);
|
||
if (st.after && st.afterEndsAt > t) return st.afterEndsAt;
|
||
}
|
||
return now + minMs + (c.turbo ? this.cfg.dayMs : 86_400_000);
|
||
}
|
||
|
||
/** Vorbörse: fällige Versammlungen planen */
|
||
newDay() {
|
||
const g = this.g, cfg = this.cfg;
|
||
if (!cfg.agmEnabled) return;
|
||
const n = g.season.n;
|
||
const todo = [...g.stocks.values()].filter((s) => s.kind === 'stock' && !s.delisted && !s.firm && this.state.held[s.symbol] !== n && !this.open.some((m) => m.symbol === s.symbol));
|
||
if (!todo.length) return;
|
||
const perDay = Math.max(1, Math.ceil([...g.stocks.values()].filter((s) => s.kind === 'stock' && !s.delisted).length / Math.max(1, cfg.seasonDays * 0.7)));
|
||
const slots = Math.max(0, cfg.agmMaxOpen - this.open.length);
|
||
for (let i = 0; i < Math.min(perDay, slots) && todo.length; i++) {
|
||
const s = todo.splice(Math.floor(Math.random() * todo.length), 1)[0];
|
||
try { this.announce(s); } catch (e) { console.warn('[hv]', e.message); }
|
||
}
|
||
}
|
||
|
||
/** Hauptversammlung einberufen (Admin oder Planung) */
|
||
announce(s) {
|
||
const g = this.g;
|
||
if (!s || s.kind !== 'stock') throw new Error('Unbekannte Aktie');
|
||
if (s.delisted) throw new Error(g.delist.error(s));
|
||
if (this.open.some((m) => m.symbol === s.symbol)) throw new Error('Für diese Aktie läuft bereits eine Hauptversammlung');
|
||
const items = this.#agenda(s);
|
||
const minMs = g.clock.turbo ? this.cfg.dayMs * 0.5 : 8 * 3_600_000;
|
||
const m = {
|
||
id: uid(4), symbol: s.symbol, name: s.name, items, announcedAt: g.clock.now(), announcedDay: g.day,
|
||
endsAt: this.#windowEnd(minMs), status: 'open', votes: {}, season: g.season.n,
|
||
};
|
||
this.state.meetings.push(m);
|
||
this.state.held[s.symbol] = g.season.n;
|
||
// Der Markt preist die erwarteten Beschlüsse sofort ein
|
||
let pre = 1;
|
||
for (const it of items) pre *= Math.exp(it.impact * it.p);
|
||
g.causes?.set('Hauptversammlung angekündigt (Erwartung eingepreist)');
|
||
g.econ.shiftFair(s, pre);
|
||
const when = new Date(m.endsAt).toLocaleString('de-DE', { timeZone: this.cfg.timezone, weekday: 'short', hour: '2-digit', minute: '2-digit' });
|
||
const txt = `${s.name} lädt zur Hauptversammlung (Abstimmung bis ${g.clock.turbo ? 'Ende des nächsten Abendhandels' : when}): ${items.map((i) => i.title).join(', ')}`;
|
||
g.chronicle?.add?.(s.symbol, { kind: 'agm', title: 'Einladung zur Hauptversammlung', text: `Tagesordnung: ${items.map((i) => i.title).join(', ')}` });
|
||
g.addNews({ id: `hv-${m.id}`, title: txt, source: 'Unternehmensmeldung', real: false, sentiment: 0, sectors: [s.sector], symbol: s.symbol, ts: Date.now() }, false);
|
||
g.log('corporate', txt, { symbol: s.symbol });
|
||
for (const p of g.players.values()) {
|
||
if (p.rival || (p.positions[s.symbol]?.qty ?? 0) <= 0) continue;
|
||
g.notify(p.id, { kind: 'agm', title: `Einladung: Hauptversammlung ${s.name}`, text: `Als Aktionär stimmst du mit ${p.positions[s.symbol].qty} Stimmen über ${items.length} Punkte ab.`, action: { view: 'termine' } });
|
||
}
|
||
g.metaDirty = true;
|
||
g.broadcast({ type: 'agm', agm: this.publicView(m) });
|
||
return m;
|
||
}
|
||
|
||
#agenda(s) {
|
||
const f = s.fund, items = [];
|
||
const payout = f?.payout ?? s.payout ?? 0.3;
|
||
const growth = f?.g ?? s.growth ?? 0.1;
|
||
const add = (key, extra) => {
|
||
const it = { key, ...ITEMS[key], ...extra };
|
||
// Empfehlung des Stimmrechtsberaters → erwarteter Zustimmungsanteil der Fonds
|
||
it.advice = it.good >= 0 ? 'yes' : 'no';
|
||
it.inst = clamp((it.advice === 'yes' ? 0.66 : 0.36) + rnd(-0.12, 0.12), 0.1, 0.9);
|
||
it.p = r2(clamp(0.5 + (it.inst - 0.5) * 2.2, 0.08, 0.92)); // Wahrscheinlichkeit der Annahme (Markterwartung)
|
||
items.push(it);
|
||
};
|
||
// Ausschüttungen und Rückkäufe nur, soweit die Bilanz sie trägt (credit.js: Gewinn, überschüssige Kasse bzw. Eigenkapital)
|
||
const cap = this.g.credit?.payoutCapacity(s) ?? 0.05;
|
||
if (payout > 0 && cap >= 0.01) {
|
||
const amount = r2(Math.max(0.05, s.last * Math.min(cap, rnd(0.01, 0.03))));
|
||
add('dividend', { amount, desc: `Einmalige Ausschüttung von ${fmt(amount)} € je Aktie aus den Rücklagen (zahlbar bei Annahme sofort).`, good: growth < 0.15 ? 1 : -0.2, impact: 0.004 });
|
||
}
|
||
if (Math.random() < 0.3 && cap >= 0.015) { // seltener als früher (0,55): sonst ≈ 50 Rückkäufe je Spieljahr (BALANCING.md Abschn. 14)
|
||
const k = r2(Math.min(cap, rnd(0.02, 0.05)));
|
||
add('buyback', { k, desc: `Der Vorstand darf bis zu ${Math.round(k * 100)} % der Aktien zurückkaufen.`, good: growth < 0.2 ? 1 : 0.2, impact: 0.005 });
|
||
}
|
||
if (growth > 0.15 || Math.random() < 0.15) {
|
||
const k = r2(rnd(0.05, 0.12));
|
||
add('capital', { k, desc: `Ausgabe von bis zu ${Math.round(k * 100)} % neuen Aktien, um Wachstum zu finanzieren.`, good: growth > 0.2 ? 0.3 : -1, impact: -0.005 });
|
||
}
|
||
if (Math.random() < 0.5 || items.length < 2) {
|
||
const rich = Math.random() < 0.5;
|
||
add('pay', { rich, desc: rich ? 'Höhere Boni, die sich am Aktienkurs orientieren – Kritiker sprechen von Selbstbedienung.' : 'Vergütung stärker an langfristige Ziele (Gewinn, Klimaziele) gekoppelt.', good: rich ? -1 : 1, impact: rich ? -0.004 : 0.003 });
|
||
}
|
||
return items;
|
||
}
|
||
|
||
// ================================================================ Abstimmen
|
||
vote(p, id, choices) {
|
||
const m = this.open.find((x) => x.id === String(id ?? ''));
|
||
if (!m) throw new Error('Diese Hauptversammlung ist beendet oder unbekannt');
|
||
if (this.g.clock.now() >= m.endsAt) throw new Error('Die Abstimmung ist bereits geschlossen');
|
||
const qty = Math.max(0, p.positions[m.symbol]?.qty ?? 0);
|
||
if (qty <= 0) throw new Error(`Abstimmen dürfen nur Aktionäre von ${m.symbol} (Bestand im Hauptdepot)`);
|
||
const v = {};
|
||
for (const it of m.items) {
|
||
const c = choices?.[it.key];
|
||
if (c === undefined || c === null || c === '') continue;
|
||
if (!['yes', 'no', 'abstain'].includes(c)) throw new Error('Ungültige Stimme');
|
||
v[it.key] = c;
|
||
}
|
||
if (!Object.keys(v).length) throw new Error('Bitte mindestens einen Punkt abstimmen');
|
||
const first = !m.votes[p.id];
|
||
m.votes[p.id] = { qty, choices: { ...(m.votes[p.id]?.choices ?? {}), ...v }, ts: this.g.clock.now() };
|
||
this.g.metaDirty = true;
|
||
if (first && !p.rival) { this.g.prog.event(p, 'agm'); this.g.prog.addXp(p, 10); }
|
||
return this.publicView(m, p);
|
||
}
|
||
|
||
/** Rivalen stimmen nach Charakter ab (aus rivals.js, gelegentlich) */
|
||
rivalVotes() {
|
||
const g = this.g;
|
||
for (const m of this.open) {
|
||
for (const p of g.rivals?.active() ?? []) {
|
||
if (m.votes[p.id] || (p.positions[m.symbol]?.qty ?? 0) <= 0) continue;
|
||
const style = g.rivals.character(p).style;
|
||
const ch = {};
|
||
for (const it of m.items) {
|
||
let yes = it.advice === 'yes';
|
||
if (style === 'income' && it.key === 'dividend') yes = true;
|
||
if (style === 'value' && (it.key === 'buyback' || it.key === 'dividend')) yes = true;
|
||
if (style === 'value' && it.key === 'capital') yes = false;
|
||
if (style === 'contra') yes = !yes;
|
||
if (style === 'momentum' && it.key === 'pay') yes = true;
|
||
if (style === 'index') { ch[it.key] = it.advice; continue; }
|
||
ch[it.key] = yes ? 'yes' : 'no';
|
||
}
|
||
try { this.vote(p, m.id, ch); } catch { /* egal */ }
|
||
}
|
||
}
|
||
}
|
||
|
||
// ================================================================ Takt
|
||
tick() {
|
||
const now = this.g.clock.now();
|
||
for (const m of this.open) if (now >= m.endsAt) { try { this.#close(m); } catch (e) { console.warn('[hv]', e.message); m.status = 'done'; } }
|
||
}
|
||
|
||
#close(m) {
|
||
const g = this.g, s = g.stocks.get(m.symbol);
|
||
m.status = 'done';
|
||
// gültige Stimmen: Minimum aus Bestand bei Abgabe und jetzt
|
||
let playerVotes = 0;
|
||
const tally = Object.fromEntries(m.items.map((it) => [it.key, { yes: 0, no: 0, abstain: 0, players: { yes: 0, no: 0 } }]));
|
||
for (const [pid, v] of Object.entries(m.votes)) {
|
||
const p = g.players.get(pid);
|
||
const w = Math.min(v.qty, Math.max(0, p?.positions[m.symbol]?.qty ?? 0));
|
||
if (w <= 0) continue;
|
||
playerVotes += w;
|
||
for (const [k, c] of Object.entries(v.choices)) {
|
||
if (!tally[k]) continue;
|
||
tally[k][c] += w;
|
||
if (c !== 'abstain') tally[k].players[c] += w;
|
||
}
|
||
}
|
||
// Fonds: Präsenz etwa anderthalbmal so groß wie die Spielerstimmen (mindestens 2.000 Stimmen)
|
||
const inst = Math.max(2000, Math.round(playerVotes * this.cfg.agmFundWeight));
|
||
const results = [];
|
||
let factor = 1;
|
||
for (const it of m.items) {
|
||
const t = tally[it.key];
|
||
const instYes = clamp(it.inst + rnd(-0.08, 0.08), 0.02, 0.98);
|
||
t.yes += Math.round(inst * instYes);
|
||
t.no += Math.round(inst * (1 - instYes));
|
||
const share = t.yes / Math.max(1, t.yes + t.no);
|
||
const ok = share > 0.5;
|
||
results.push({ key: it.key, title: it.title, ok, share: r2(share * 100), yes: t.yes, no: t.no, abstain: t.abstain, players: t.players, advice: it.advice });
|
||
// Überraschung gegenüber der Erwartung
|
||
factor *= Math.exp(it.impact * ((ok ? 1 : 0) - it.p));
|
||
if (!s) continue;
|
||
if (ok && it.key === 'dividend') { g.ex.exDividend(s, it.amount, 'Sonderdividende'); g.credit?.onPayout(s, it.amount * s.shares); }
|
||
if (ok && it.key === 'buyback') g.corp.buyback(s, it.k);
|
||
if (ok && it.key === 'capital') g.corp.capitalIncrease(s, it.k);
|
||
}
|
||
g.causes?.set('Beschlüsse der Hauptversammlung');
|
||
if (s) g.econ.shiftFair(s, factor);
|
||
m.results = results;
|
||
m.playerVotes = playerVotes;
|
||
m.instVotes = inst;
|
||
const swung = results.filter((r) => (r.ok ? 'yes' : 'no') !== r.advice);
|
||
const txt = `Hauptversammlung ${m.name}: ${results.map((r) => `${r.title} ${r.ok ? 'angenommen' : 'abgelehnt'} (${String(r.share).replace('.', ',')} %)`).join(' · ')}`;
|
||
{ const ok = results.filter((r) => r.ok).map((r) => r.title); g.chronicle?.add?.(m.symbol, { kind: 'agm', title: ok.length ? `Hauptversammlung: ${ok.join(', ')} beschlossen` : 'Hauptversammlung: alle Vorschläge abgelehnt', text: txt.replace(/^Hauptversammlung [^:]*: /, ''), data: { swung: swung.length } }); }
|
||
g.addNews({ id: `hv-r-${m.id}`, title: txt, source: 'Unternehmensmeldung', real: false, sentiment: 0, sectors: s ? [s.sector] : [], symbol: m.symbol, ts: Date.now() }, false);
|
||
g.log('corporate', txt, { symbol: m.symbol });
|
||
for (const pid of Object.keys(m.votes)) {
|
||
const p = g.players.get(pid);
|
||
if (!p || p.rival) continue;
|
||
const mine = m.votes[pid].choices;
|
||
const won = results.filter((r) => mine[r.key] && mine[r.key] !== 'abstain' && (mine[r.key] === 'yes') === r.ok).length;
|
||
g.notify(pid, { kind: 'agm', title: `Ergebnis der Hauptversammlung ${m.name}`, text: `${won} von ${results.length} Punkten wie von dir gewünscht entschieden.${swung.length ? ' Die Aktionäre haben gegen die Empfehlung der Stimmrechtsberatung gestimmt!' : ''}`, action: { view: 'termine' } });
|
||
}
|
||
this.state.history.unshift({ id: m.id, symbol: m.symbol, name: m.name, endsAt: m.endsAt, results, playerVotes, instVotes: inst, voters: Object.keys(m.votes).length });
|
||
this.state.history = this.state.history.slice(0, 30);
|
||
this.state.meetings = this.state.meetings.filter((x) => x.status === 'open');
|
||
g.metaDirty = true;
|
||
g.broadcast({ type: 'agm', agm: { id: m.id, symbol: m.symbol, status: 'done', results } });
|
||
}
|
||
|
||
/**
|
||
* Offene Hauptversammlung einer Aktie absagen (z. B. Insolvenz mit Schuldenschnitt: Ausschüttungen, Rückkauf und
|
||
* Kapitalerhöhung wären auf die alte Aktienzahl berechnet). Abstimmende Spieler werden benachrichtigt.
|
||
*/
|
||
cancel(sym, why) {
|
||
const g = this.g;
|
||
const hit = this.open.filter((m) => m.symbol === sym);
|
||
for (const m of hit) {
|
||
m.status = 'cancelled';
|
||
for (const pid of Object.keys(m.votes ?? {})) { const p = g.players.get(pid); if (p && !p.rival) g.notify(pid, { kind: 'agm', title: `Hauptversammlung ${m.name} abgesagt`, text: `${why}.` }); }
|
||
g.chronicle?.add?.(sym, { kind: 'agm', title: 'Hauptversammlung abgesagt', text: why });
|
||
}
|
||
if (hit.length) { this.state.meetings = this.state.meetings.filter((x) => x.status === 'open'); g.metaDirty = true; }
|
||
return hit.length;
|
||
}
|
||
|
||
/** neue Saison: Zählung beginnt neu */
|
||
onSeason() { this.state.meetings = []; }
|
||
|
||
// ================================================================ Ansichten
|
||
publicView(m, viewer = null) {
|
||
const myQty = viewer ? Math.max(0, viewer.positions?.[m.symbol]?.qty ?? 0) : 0;
|
||
return {
|
||
id: m.id, symbol: m.symbol, name: m.name, endsAt: m.endsAt, status: m.status, advisor: ADVISOR,
|
||
live: !!this.g.afterHours(),
|
||
items: m.items.map((it) => ({ key: it.key, title: it.title, icon: it.icon, desc: it.desc, advice: it.advice, p: it.p })),
|
||
voters: Object.keys(m.votes).length, votes: Object.values(m.votes).reduce((a, v) => a + v.qty, 0),
|
||
mine: viewer ? m.votes[viewer.id]?.choices ?? null : null, myQty, results: m.results ?? null,
|
||
};
|
||
}
|
||
view(viewer) {
|
||
return {
|
||
open: this.open.map((m) => this.publicView(m, viewer)).sort((a, b) => b.myQty - a.myQty || a.endsAt - b.endsAt),
|
||
history: this.state.history.slice(0, 10), advisor: ADVISOR,
|
||
};
|
||
}
|
||
calendarItems() {
|
||
return this.open.map((m) => ({ ts: m.endsAt, kind: 'agm', symbol: m.symbol, title: `Hauptversammlung ${m.name}`, detail: m.items.map((i) => i.title).join(', ') }));
|
||
}
|
||
}
|