Try to fix AI playerss getting bankrupt all the time
Fix z-fighting
This commit is contained in:
parent
2e3cea5a30
commit
5878827d6c
14 changed files with 511 additions and 105 deletions
|
|
@ -19,11 +19,15 @@ export interface LeaderboardRow {
|
|||
difficultyLabel?: string;
|
||||
aiSkill?: number | null;
|
||||
bankrupt: boolean;
|
||||
bankruptcyReason?: string | null;
|
||||
sponsorId: string | null;
|
||||
treasury: number;
|
||||
reputation: number;
|
||||
missionsCompleted: number;
|
||||
missionsFailed: number;
|
||||
careerMissionsCompleted?: number;
|
||||
careerMissionsFailed?: number;
|
||||
contractsAbandoned?: number;
|
||||
earnedTotal: number;
|
||||
score: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ export function renderMarketPanel(
|
|||
h(
|
||||
"span",
|
||||
{},
|
||||
`${row.missionsCompleted} OK / ${row.missionsFailed} FAIL`,
|
||||
`${row.missionsCompleted} OK / ${row.missionsFailed} FAIL${row.contractsAbandoned ? ` / ${row.contractsAbandoned} VOID` : ""}`,
|
||||
),
|
||||
),
|
||||
live
|
||||
|
|
|
|||
|
|
@ -133,7 +133,10 @@ function handleLiveEvent(ev: {
|
|||
void refreshWorld();
|
||||
if (isMine) void refreshMe();
|
||||
} else if (ev.type === "agency.bankrupt") {
|
||||
const msg = `INSOLVENCY ALERT: ${d.agency} declared bankruptcy.`;
|
||||
const reason = d.reason
|
||||
? ` (${String(d.reason).replace(/_/g, " ")})`
|
||||
: "";
|
||||
const msg = `INSOLVENCY ALERT: ${d.agency} declared bankruptcy${reason}.`;
|
||||
pushNotification(
|
||||
msg,
|
||||
isMine ? "err" : "warn",
|
||||
|
|
@ -179,6 +182,17 @@ function handleLiveEvent(ev: {
|
|||
"world",
|
||||
);
|
||||
void refreshWorld();
|
||||
} else if (ev.type === "contract.abandoned") {
|
||||
const reason = String(d.reason ?? "unknown").replace(/_/g, " ");
|
||||
const penalty = ((Number(d.penalty) || 0) / 1e6).toFixed(1);
|
||||
const msg = `${d.agency} abandoned contract ${d.missionId ?? d.offerId ?? "contract"} (${reason}) — $${penalty}M penalty.`;
|
||||
if (isMine) {
|
||||
toast(msg, "warn", false);
|
||||
void refreshMe();
|
||||
} else {
|
||||
pushNotification(msg, "warn", "world", false);
|
||||
}
|
||||
void refreshWorld();
|
||||
} else if (ev.type === "agency.updated" && isMine) {
|
||||
if (state.agency && d.rocketDesign) {
|
||||
state.agency.rocketDesign = d.rocketDesign;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {
|
|||
buildEngineClusterStandard,
|
||||
buildPayloadNode,
|
||||
buildStageConnector,
|
||||
cappedColumnGroup,
|
||||
fitPayloadInsideFairing,
|
||||
} from "./geometry.js";
|
||||
import {
|
||||
|
|
@ -190,7 +191,7 @@ export async function buildRocketMesh(
|
|||
const cR = Math.max(0.6, topDia * 0.48);
|
||||
const compGroup = new THREE.Group();
|
||||
const housing = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(cR * 1.03, cR * 1.03, 0.36, 28),
|
||||
new THREE.CylinderGeometry(cR * 1.03, cR * 1.03, 0.36, 28, 1, true),
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x1e293b,
|
||||
metalness: 0.75,
|
||||
|
|
@ -248,15 +249,18 @@ export async function buildRocketMesh(
|
|||
}
|
||||
payloadGroup = builtPayload;
|
||||
} else if (!isPro || topProPayload) {
|
||||
const generic = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(1.0, 1.2, 3.0, 16),
|
||||
const generic = cappedColumnGroup(
|
||||
1.0,
|
||||
1.2,
|
||||
3.0,
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x60a5fa,
|
||||
metalness: 0.6,
|
||||
roughness: 0.35,
|
||||
}),
|
||||
{ radialSegs: 16 },
|
||||
);
|
||||
generic.position.y = assembly.payloadY + 1.5;
|
||||
generic.position.y = assembly.payloadY;
|
||||
const genericGroup = new THREE.Group();
|
||||
genericGroup.add(generic);
|
||||
if (topProPayload) {
|
||||
|
|
@ -318,17 +322,20 @@ export async function buildRocketMesh(
|
|||
let lasGroup: THREE.Group | null = null;
|
||||
if (assembly.lasPart) {
|
||||
lasGroup = new THREE.Group();
|
||||
const tower = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(0.28, 0.75, assembly.lasPart.length, 16),
|
||||
const tower = cappedColumnGroup(
|
||||
0.28,
|
||||
0.75,
|
||||
assembly.lasPart.length,
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0xe2e8f0,
|
||||
metalness: 0.4,
|
||||
roughness: 0.5,
|
||||
}),
|
||||
{ radialSegs: 16 },
|
||||
);
|
||||
tower.position.y = assembly.lasY + assembly.lasPart.length / 2;
|
||||
tower.position.y = assembly.lasY;
|
||||
const tip = new THREE.Mesh(
|
||||
new THREE.ConeGeometry(0.28, 1.4, 16),
|
||||
new THREE.ConeGeometry(0.28, 1.4, 16, 1, true),
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0xf87171,
|
||||
metalness: 0.3,
|
||||
|
|
|
|||
|
|
@ -165,6 +165,40 @@ export function buildOgiveFairingGeo(
|
|||
|
||||
const CONNECTOR_RADIUS_FRAC = 0.94;
|
||||
|
||||
// Stacked parts butt end-to-end, so any two capped faces on the same plane
|
||||
// z-fight. Body columns are therefore built as an open wall plus cap discs
|
||||
// recessed CAP_INSET from each end; trim rings keep exact bounds and stay
|
||||
// clear of the recessed caps.
|
||||
const CAP_INSET = 0.035;
|
||||
|
||||
export function cappedColumnGroup(
|
||||
rt: number,
|
||||
rb: number,
|
||||
h: number,
|
||||
mat: THREE.Material,
|
||||
opts: { radialSegs?: number; heightSegs?: number; caps?: boolean } = {},
|
||||
): THREE.Group {
|
||||
const g = new THREE.Group();
|
||||
const segs = opts.radialSegs ?? 32;
|
||||
const wall = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(rt, rb, h, segs, opts.heightSegs ?? 1, true),
|
||||
mat,
|
||||
);
|
||||
wall.position.y = h / 2;
|
||||
g.add(wall);
|
||||
if (opts.caps !== false) {
|
||||
const inset = Math.min(CAP_INSET, h * 0.2);
|
||||
const top = new THREE.Mesh(new THREE.CircleGeometry(rt, segs), mat);
|
||||
top.rotation.x = -Math.PI / 2;
|
||||
top.position.y = h - inset;
|
||||
const bot = new THREE.Mesh(new THREE.CircleGeometry(rb, segs), mat);
|
||||
bot.rotation.x = Math.PI / 2;
|
||||
bot.position.y = inset;
|
||||
g.add(top, bot);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
export function buildStageConnector(
|
||||
botR: number,
|
||||
topR: number,
|
||||
|
|
@ -174,13 +208,13 @@ export function buildStageConnector(
|
|||
const g = new THREE.Group();
|
||||
const bR = Math.max(0.15, botR * CONNECTOR_RADIUS_FRAC);
|
||||
const tR = Math.max(0.15, topR * CONNECTOR_RADIUS_FRAC);
|
||||
const body = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(tR, bR, len, 48, 1, false),
|
||||
mat,
|
||||
);
|
||||
body.position.y = len / 2;
|
||||
body.castShadow = true;
|
||||
body.receiveShadow = true;
|
||||
const body = cappedColumnGroup(tR, bR, len, mat, { radialSegs: 48 });
|
||||
body.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(body);
|
||||
const flangeH = Math.min(0.22, len * 0.12);
|
||||
const lerpR = (y: number) => bR + (tR - bR) * (y / len);
|
||||
|
|
@ -227,16 +261,15 @@ export function buildEngineClusterStandard(
|
|||
ringR *= k;
|
||||
singleR *= k;
|
||||
}
|
||||
const dome = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(
|
||||
stageR * 0.88,
|
||||
stageR * 0.78,
|
||||
comp.length * 0.28,
|
||||
28,
|
||||
),
|
||||
const domeH = comp.length * 0.28;
|
||||
const dome = cappedColumnGroup(
|
||||
stageR * 0.88,
|
||||
stageR * 0.78,
|
||||
domeH,
|
||||
AVIONICS_RING_MAT,
|
||||
{ radialSegs: 28 },
|
||||
);
|
||||
dome.position.y = comp.yBottom + comp.length * 0.86;
|
||||
dome.position.y = comp.yBottom + comp.length * 0.86 - domeH / 2;
|
||||
cluster.add(dome);
|
||||
const offsets: Array<[number, number]> = [];
|
||||
if (count === 1) {
|
||||
|
|
@ -366,20 +399,18 @@ export async function buildPayloadNode(
|
|||
}
|
||||
}
|
||||
const g = new THREE.Group();
|
||||
const body = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(
|
||||
part.diameter * 0.42,
|
||||
part.diameter * 0.45,
|
||||
part.length * 0.85,
|
||||
20,
|
||||
),
|
||||
const body = cappedColumnGroup(
|
||||
part.diameter * 0.42,
|
||||
part.diameter * 0.45,
|
||||
part.length * 0.85,
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x94a3b8,
|
||||
metalness: 0.7,
|
||||
roughness: 0.3,
|
||||
}),
|
||||
{ radialSegs: 20 },
|
||||
);
|
||||
body.position.y = yPos + part.length * 0.425;
|
||||
body.position.y = yPos;
|
||||
g.add(body);
|
||||
return g;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
buildOgiveFairingGeo,
|
||||
buildParabolicBellGeo,
|
||||
buildStageConnector,
|
||||
cappedColumnGroup,
|
||||
} from "./geometry.js";
|
||||
import {
|
||||
ACCENT_STRIPE_MAT,
|
||||
|
|
@ -25,11 +26,14 @@ export function buildSinglePartCopy(
|
|||
const g = new THREE.Group();
|
||||
const r = comp.diameter / 2;
|
||||
if (comp.role === "engine") {
|
||||
const skirt = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r * 0.55, r * 0.38, comp.length * 0.22, 18),
|
||||
const skirt = cappedColumnGroup(
|
||||
r * 0.55,
|
||||
r * 0.38,
|
||||
comp.length * 0.22,
|
||||
AVIONICS_RING_MAT,
|
||||
{ radialSegs: 18 },
|
||||
);
|
||||
skirt.position.y = comp.length * 0.89;
|
||||
skirt.position.y = comp.length * 0.78;
|
||||
g.add(skirt);
|
||||
const bellH = comp.length * 0.8;
|
||||
const bell = new THREE.Mesh(
|
||||
|
|
@ -53,28 +57,37 @@ export function buildSinglePartCopy(
|
|||
const aftH = Math.max(0.28, comp.length * 0.06);
|
||||
const noseH = Math.max(0.55, comp.length * 0.22);
|
||||
const cylLen = Math.max(0.6, comp.length - aftH - noseH);
|
||||
const aftCap = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r, r * 0.62, aftH, 32),
|
||||
barrelMat,
|
||||
);
|
||||
aftCap.position.y = aftH / 2;
|
||||
aftCap.castShadow = true;
|
||||
aftCap.receiveShadow = true;
|
||||
const aftCap = cappedColumnGroup(r, r * 0.62, aftH, barrelMat, {
|
||||
radialSegs: 32,
|
||||
});
|
||||
aftCap.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(aftCap);
|
||||
const tankMesh = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r, r, cylLen, 36),
|
||||
barrelMat,
|
||||
);
|
||||
tankMesh.position.y = aftH + cylLen / 2;
|
||||
tankMesh.castShadow = true;
|
||||
tankMesh.receiveShadow = true;
|
||||
const tankMesh = cappedColumnGroup(r, r, cylLen, barrelMat, {
|
||||
radialSegs: 36,
|
||||
});
|
||||
tankMesh.position.y = aftH;
|
||||
tankMesh.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(tankMesh);
|
||||
const nose = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r * 0.14, r, noseH, 36),
|
||||
barrelMat,
|
||||
);
|
||||
nose.position.y = aftH + cylLen + noseH / 2;
|
||||
nose.castShadow = true;
|
||||
const nose = cappedColumnGroup(r * 0.14, r, noseH, barrelMat, {
|
||||
radialSegs: 36,
|
||||
});
|
||||
nose.position.y = aftH + cylLen;
|
||||
nose.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(nose);
|
||||
const noseTip = new THREE.Mesh(
|
||||
new THREE.SphereGeometry(r * 0.14, 16, 10),
|
||||
|
|
@ -91,13 +104,15 @@ export function buildSinglePartCopy(
|
|||
g.add(band);
|
||||
}
|
||||
} else {
|
||||
const tankMesh = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r, r, comp.length, 48),
|
||||
tankMat,
|
||||
);
|
||||
tankMesh.position.y = comp.length / 2;
|
||||
tankMesh.castShadow = true;
|
||||
tankMesh.receiveShadow = true;
|
||||
const tankMesh = cappedColumnGroup(r, r, comp.length, tankMat, {
|
||||
radialSegs: 48,
|
||||
});
|
||||
tankMesh.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(tankMesh);
|
||||
for (const frac of [0.15, 0.5, 0.85]) {
|
||||
const ring = new THREE.Mesh(
|
||||
|
|
@ -120,24 +135,28 @@ export function buildSinglePartCopy(
|
|||
g.add(raceway);
|
||||
}
|
||||
} else if (comp.role === "heatshield") {
|
||||
const shield = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r * 1.03, r * 1.03, comp.length, 32),
|
||||
const shield = cappedColumnGroup(
|
||||
r * 1.03,
|
||||
r * 1.03,
|
||||
comp.length,
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x451a03,
|
||||
metalness: 0.3,
|
||||
roughness: 0.85,
|
||||
}),
|
||||
{ radialSegs: 32 },
|
||||
);
|
||||
shield.position.y = comp.length / 2;
|
||||
g.add(shield);
|
||||
} else if (comp.role === "structure") {
|
||||
const avionics = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(r, r, comp.length, 48),
|
||||
tankMat,
|
||||
);
|
||||
avionics.position.y = comp.length / 2;
|
||||
avionics.castShadow = true;
|
||||
avionics.receiveShadow = true;
|
||||
const avionics = cappedColumnGroup(r, r, comp.length, tankMat, {
|
||||
radialSegs: 48,
|
||||
});
|
||||
avionics.traverse((o) => {
|
||||
if ((o as THREE.Mesh).isMesh) {
|
||||
o.castShadow = true;
|
||||
o.receiveShadow = true;
|
||||
}
|
||||
});
|
||||
g.add(avionics);
|
||||
const botTrim = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(
|
||||
|
|
@ -172,20 +191,19 @@ export function buildSinglePartCopy(
|
|||
const topR = nextStageDia > 0.2 ? nextStageDia / 2 : r;
|
||||
g.add(buildStageConnector(botR, topR, Math.max(0.6, comp.length), tankMat));
|
||||
} else if (comp.role === "computer") {
|
||||
const collar = new THREE.Mesh(
|
||||
new THREE.CylinderGeometry(
|
||||
r * 1.02,
|
||||
r * 1.02,
|
||||
Math.max(0.45, comp.length),
|
||||
24,
|
||||
),
|
||||
const collarH = Math.max(0.45, comp.length);
|
||||
const collar = cappedColumnGroup(
|
||||
r * 1.02,
|
||||
r * 1.02,
|
||||
collarH,
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x0f172a,
|
||||
metalness: 0.72,
|
||||
roughness: 0.28,
|
||||
}),
|
||||
{ radialSegs: 24 },
|
||||
);
|
||||
collar.position.y = Math.max(0.45, comp.length) / 2;
|
||||
g.add(collar);
|
||||
const ledColor =
|
||||
(comp.part.radHardeningLevel ?? 1) >= 3
|
||||
? 0x34d399
|
||||
|
|
@ -198,7 +216,7 @@ export function buildSinglePartCopy(
|
|||
);
|
||||
busRing.rotation.x = Math.PI / 2;
|
||||
busRing.position.y = Math.max(0.45, comp.length) * 0.55;
|
||||
g.add(collar, busRing);
|
||||
g.add(busRing);
|
||||
} else if (comp.role === "fairing") {
|
||||
const shroud = new THREE.Mesh(
|
||||
buildOgiveFairingGeo(r, comp.length),
|
||||
|
|
|
|||
|
|
@ -157,8 +157,11 @@ export function makeAiAgency(def: AiAgencyDef): AgencyState {
|
|||
profile.startingFunds * (sponsor?.budgetMult ?? 1.0) + skill * 4_000_000,
|
||||
),
|
||||
reputation: Math.round((1 + skill * 5) * 10) / 10,
|
||||
missionsCompleted: Math.floor(skill * 2),
|
||||
missionsFailed: Math.floor((1 - skill) * 2),
|
||||
missionsCompleted: 0,
|
||||
missionsFailed: 0,
|
||||
careerMissionsCompleted: Math.floor(skill * 2),
|
||||
careerMissionsFailed: Math.floor((1 - skill) * 2),
|
||||
contractsAbandoned: 0,
|
||||
earnedTotal: 0,
|
||||
rocketDesign: null,
|
||||
crewConfig: { crewSize: 0, lifeSupport: 1 },
|
||||
|
|
@ -166,6 +169,7 @@ export function makeAiAgency(def: AiAgencyDef): AgencyState {
|
|||
contractHistory: [],
|
||||
bankrupt: false,
|
||||
bankruptAt: null,
|
||||
bankruptcyReason: null,
|
||||
bailoutsTaken: 0,
|
||||
unlockedTechs: defaultTechsForDifficulty(def.difficulty),
|
||||
partHeritage: {},
|
||||
|
|
@ -232,6 +236,33 @@ export function seedAI(): void {
|
|||
agency.partHeritage = {};
|
||||
dirty = true;
|
||||
}
|
||||
if (
|
||||
agency.careerMissionsCompleted == null ||
|
||||
agency.careerMissionsFailed == null
|
||||
) {
|
||||
const careerSkill = def ? def.skill : clamp01(agency.aiSkill ?? 0.65);
|
||||
const seededCompleted = Math.floor(careerSkill * 2);
|
||||
const seededFailed = Math.floor((1 - careerSkill) * 2);
|
||||
agency.careerMissionsCompleted = seededCompleted;
|
||||
agency.careerMissionsFailed = seededFailed;
|
||||
agency.missionsCompleted = Math.max(
|
||||
0,
|
||||
(agency.missionsCompleted ?? 0) - seededCompleted,
|
||||
);
|
||||
agency.missionsFailed = Math.max(
|
||||
0,
|
||||
(agency.missionsFailed ?? 0) - seededFailed,
|
||||
);
|
||||
dirty = true;
|
||||
}
|
||||
if (agency.contractsAbandoned == null) {
|
||||
agency.contractsAbandoned = 0;
|
||||
dirty = true;
|
||||
}
|
||||
if (agency.bankruptcyReason === undefined) {
|
||||
agency.bankruptcyReason = agency.bankrupt ? "legacy_insolvency" : null;
|
||||
dirty = true;
|
||||
}
|
||||
if (agency.bailoutsTaken == null) {
|
||||
agency.bailoutsTaken = 0;
|
||||
dirty = true;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ import type {
|
|||
ActiveMission,
|
||||
AgencyState,
|
||||
ContractOffer,
|
||||
RocketAssembly,
|
||||
RocketDesign,
|
||||
ValidationResult,
|
||||
} from "../../shared/types.js";
|
||||
import {
|
||||
clamp01,
|
||||
|
|
@ -43,14 +46,122 @@ import { synthesizeAiRocket } from "./synthesizer.js";
|
|||
|
||||
let lastStartupAt = 0;
|
||||
|
||||
function estimateAiMissionCost(
|
||||
agency: AgencyState,
|
||||
offer: ContractOffer,
|
||||
): number {
|
||||
const payload = Math.max(0, effectivePayloadMass(agency, offer) || 0);
|
||||
const dv = Math.max(0, offer.requiredDv || 0);
|
||||
const base = 16_000_000 + payload * 2_600 + dv * 1_800;
|
||||
let mult = 1;
|
||||
if (offer.tier >= 2) mult *= 1.12;
|
||||
else if (offer.tier === 1) mult *= 1.05;
|
||||
if (offer.advanced || offer.isConvoluted) mult *= 1.18;
|
||||
if (offer.requiredDv > 12_500) mult *= 1.22;
|
||||
if (offer.crewed) mult *= 1.12;
|
||||
return Math.round(base * mult);
|
||||
}
|
||||
|
||||
function expectedContractPayout(offer: ContractOffer): number {
|
||||
return Math.round(offer.budget * 0.68);
|
||||
}
|
||||
|
||||
function estimateAiMissionEconomics(
|
||||
agency: AgencyState,
|
||||
contract: ContractOffer,
|
||||
design: RocketDesign,
|
||||
asm: RocketAssembly,
|
||||
validation: ValidationResult,
|
||||
totalCost: number,
|
||||
anomalyRiskPct: number,
|
||||
): {
|
||||
successCash: number;
|
||||
failureCash: number;
|
||||
expectedCash: number;
|
||||
launchNet: number;
|
||||
abandonCost: number;
|
||||
successProbability: number;
|
||||
} {
|
||||
const profile = getDifficultyProfile(agency.difficulty);
|
||||
const budget = contract.budget;
|
||||
const reqDv = contract.requiredDv ?? 9_000;
|
||||
const margin = Math.max(0, validation.dvMargin / Math.max(1, reqDv));
|
||||
const bus = validation.assembly?.spacecraftBus;
|
||||
const gradeBonusRate =
|
||||
bus?.efficiencyGrade === "S"
|
||||
? 0.05
|
||||
: bus?.efficiencyGrade === "A"
|
||||
? 0.025
|
||||
: 0;
|
||||
const effBonusRate =
|
||||
Math.min(
|
||||
0.1,
|
||||
margin * 0.4 +
|
||||
((validation.compliance.waivedCount ?? 0) === 0 ? 0.04 : 0),
|
||||
) + gradeBonusRate;
|
||||
const grossPayout = Math.round(budget * (0.65 + effBonusRate));
|
||||
const scienceBonus = Math.round(
|
||||
budget * ((bus?.scienceBonusPct ?? 0) / 100),
|
||||
);
|
||||
const canRecover =
|
||||
(contract.isReusable ||
|
||||
(agency.unlockedTechs ?? []).includes("methalox-reusable")) &&
|
||||
validation.dvMargin >= 450 &&
|
||||
(!!design.stages?.[0]?.hasFins || (design.stages?.length ?? 0) >= 2);
|
||||
const stage0Cost =
|
||||
asm.stages?.[0]?.stageCost ?? Math.round(totalCost * 0.55);
|
||||
const reusabilityBonus = canRecover ? Math.round(stage0Cost * 0.28) : 0;
|
||||
const successCash = grossPayout + scienceBonus + reusabilityBonus;
|
||||
|
||||
const exempt = profile.id === "explorer" || profile.id === "sandbox";
|
||||
const insured = !!agency.launchInsured;
|
||||
const insurancePayout = insured ? Math.round(totalCost * 0.7) : 0;
|
||||
const breachPenalty =
|
||||
exempt || insured ? 0 : Math.round(budget * profile.breachFineRate);
|
||||
const padRepairExpected = exempt
|
||||
? 0
|
||||
: Math.round(
|
||||
(6_000_000 + Math.min(8_000_000, Math.round(totalCost * 0.22))) *
|
||||
0.45,
|
||||
);
|
||||
const crewInquiryExpected =
|
||||
contract.crewed && !exempt ? 10_000_000 : 0;
|
||||
const failureCash =
|
||||
insurancePayout - breachPenalty - padRepairExpected - crewInquiryExpected;
|
||||
|
||||
const skill = clamp01(agency.aiSkill ?? 0.65);
|
||||
const successProbability = Math.max(
|
||||
0.55,
|
||||
Math.min(0.97, 0.88 + skill * 0.08 - anomalyRiskPct / 140),
|
||||
);
|
||||
const expectedCash = Math.round(
|
||||
successProbability * successCash +
|
||||
(1 - successProbability) * failureCash,
|
||||
);
|
||||
const abandonCost =
|
||||
Math.round(budget * 0.35) + Math.round(budget * profile.breachFineRate);
|
||||
return {
|
||||
successCash,
|
||||
failureCash,
|
||||
expectedCash,
|
||||
launchNet: expectedCash - totalCost,
|
||||
abandonCost,
|
||||
successProbability,
|
||||
};
|
||||
}
|
||||
|
||||
function isContractFeasibleForAi(
|
||||
agency: AgencyState,
|
||||
offer: ContractOffer,
|
||||
): boolean {
|
||||
const skill = clamp01(agency.aiSkill ?? 0.65);
|
||||
const advance = Math.round(offer.budget * 0.35);
|
||||
const estCost = offer.budget * 0.62;
|
||||
if (estCost > (agency.treasury + advance) * 0.72) return false;
|
||||
if (agency.treasury + advance - estCost < 10_000_000) return false;
|
||||
const estCost = estimateAiMissionCost(agency, offer);
|
||||
const expectedPayout = expectedContractPayout(offer);
|
||||
const requiredMargin = 1.08 - skill * 0.06;
|
||||
if (expectedPayout < estCost * requiredMargin) return false;
|
||||
if (estCost > (agency.treasury + advance) * 0.9) return false;
|
||||
if (agency.treasury + advance - estCost < INSOLVENCY_THRESHOLD) return false;
|
||||
const prof = getDifficultyProfile(agency.difficulty);
|
||||
if (!prof.allTechUnlocked && offer.requiredDv > 9800) {
|
||||
const unlocked = new Set(agency.unlockedTechs ?? []);
|
||||
|
|
@ -88,10 +199,14 @@ function chooseContractForAi(agency: AgencyState): ContractOffer | null {
|
|||
const skill = clamp01(agency.aiSkill ?? 0.65);
|
||||
const cryoUnlocked = isPartUnlocked("eng-rl10", agency);
|
||||
const scored = offers.map((offer) => {
|
||||
const feasible = isContractFeasibleForAi(agency, offer);
|
||||
const postAdvanceCash = agency.treasury + Math.round(offer.budget * 0.35);
|
||||
const estCost = offer.budget * 0.62;
|
||||
let score = offer.budget / 1e6;
|
||||
if (!isContractFeasibleForAi(agency, offer)) {
|
||||
const estCost = estimateAiMissionCost(agency, offer);
|
||||
const estMargin = expectedContractPayout(offer) - estCost;
|
||||
let score =
|
||||
offer.budget / 1e6 +
|
||||
Math.max(-25, Math.min(25, estMargin / 1e6)) * 0.5;
|
||||
if (!feasible) {
|
||||
score -= 1000;
|
||||
}
|
||||
if (estCost > postAdvanceCash * 1.05 && offer.tier > 0) {
|
||||
|
|
@ -107,10 +222,10 @@ function chooseContractForAi(agency: AgencyState): ContractOffer | null {
|
|||
score -= 40;
|
||||
}
|
||||
score += (Math.random() - 0.5) * (1 - skill) * 140;
|
||||
return { offer, score };
|
||||
return { offer, score, feasible };
|
||||
});
|
||||
scored.sort((a, b) => b.score - a.score);
|
||||
return scored[0]?.offer ?? offers[0];
|
||||
return scored.find((s) => s.feasible)?.offer ?? null;
|
||||
}
|
||||
|
||||
export function aiTick(): void {
|
||||
|
|
@ -124,6 +239,7 @@ export function aiTick(): void {
|
|||
if (!agency.isAI) continue;
|
||||
if (agency.terminatedReason) {
|
||||
agency.bankrupt = true;
|
||||
agency.bankruptcyReason = agency.terminatedReason;
|
||||
putAgency(agency.name, agency);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -167,6 +283,7 @@ export function aiTick(): void {
|
|||
agency.treasury += grant;
|
||||
agency.bankrupt = false;
|
||||
agency.bankruptAt = null;
|
||||
agency.bankruptcyReason = null;
|
||||
agency.bailoutsTaken = (agency.bailoutsTaken ?? 0) + 1;
|
||||
agency.reputation = Math.max(
|
||||
0,
|
||||
|
|
@ -188,9 +305,15 @@ export function aiTick(): void {
|
|||
if (!agency.bankrupt) {
|
||||
agency.bankrupt = true;
|
||||
agency.bankruptAt = simTime;
|
||||
agency.bankruptcyReason = "treasury_below_operating_threshold";
|
||||
clearActiveContract(agency);
|
||||
putAgency(agency.name, agency);
|
||||
emit("agency.bankrupt", { agency: agency.name, isAI: true });
|
||||
emit("agency.bankrupt", {
|
||||
agency: agency.name,
|
||||
isAI: true,
|
||||
reason: agency.bankruptcyReason,
|
||||
treasury: agency.treasury,
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -261,12 +384,14 @@ export function aiTick(): void {
|
|||
if ((agency.aiContractReadyAtSimTime ?? 0) > simTime) {
|
||||
continue;
|
||||
}
|
||||
const abandonContract = () => {
|
||||
const abandonContract = (reason: string) => {
|
||||
if (agency.activeContract) {
|
||||
const cur = agency.activeContract;
|
||||
const advanceRefund = Math.round(cur.budget * 0.35);
|
||||
const breachFine = Math.round(cur.budget * profile.breachFineRate);
|
||||
agency.treasury -= advanceRefund + breachFine;
|
||||
const penalty = advanceRefund + breachFine;
|
||||
agency.treasury -= penalty;
|
||||
agency.contractsAbandoned = (agency.contractsAbandoned ?? 0) + 1;
|
||||
agency.reputation = Math.max(
|
||||
0,
|
||||
Math.round((agency.reputation - 1.5) * 10) / 10,
|
||||
|
|
@ -278,6 +403,16 @@ export function aiTick(): void {
|
|||
);
|
||||
clearActiveContract(agency);
|
||||
putAgency(agency.name, agency);
|
||||
emit("contract.abandoned", {
|
||||
agency: agency.name,
|
||||
missionId: cur.id,
|
||||
offerId: cur.offerId,
|
||||
contractName: cur.name,
|
||||
reason,
|
||||
penalty,
|
||||
treasury: agency.treasury,
|
||||
ai: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
maybeUnlockAiTech(agency, contract);
|
||||
|
|
@ -289,7 +424,7 @@ export function aiTick(): void {
|
|||
{ chargeDryRuns: true },
|
||||
);
|
||||
if (design.maturity !== "flight-ready") {
|
||||
abandonContract();
|
||||
abandonContract("design_not_flight_ready");
|
||||
continue;
|
||||
}
|
||||
const effectiveMission = {
|
||||
|
|
@ -313,11 +448,11 @@ export function aiTick(): void {
|
|||
!validation.valid ||
|
||||
validation.compliance.mandatoryFailed.length > 0
|
||||
) {
|
||||
abandonContract();
|
||||
abandonContract("validation_failed");
|
||||
continue;
|
||||
}
|
||||
if (validation.totalMissionCost > agency.treasury) {
|
||||
abandonContract();
|
||||
abandonContract("unaffordable");
|
||||
continue;
|
||||
}
|
||||
const asm =
|
||||
|
|
@ -356,10 +491,23 @@ export function aiTick(): void {
|
|||
: 0;
|
||||
const totalCost = validation.totalMissionCost + insurancePremium;
|
||||
if (agency.treasury < totalCost) {
|
||||
putAgency(agency.name, agency);
|
||||
abandonContract("unaffordable");
|
||||
continue;
|
||||
}
|
||||
const reliability = computeDesignReliability(design, asm, agency);
|
||||
const economics = estimateAiMissionEconomics(
|
||||
agency,
|
||||
contract,
|
||||
design,
|
||||
asm,
|
||||
validation,
|
||||
totalCost,
|
||||
reliability.anomalyRiskPct,
|
||||
);
|
||||
if (economics.launchNet < -economics.abandonCost) {
|
||||
abandonContract("negative_expected_value");
|
||||
continue;
|
||||
}
|
||||
const ascent = simulateAscent(design, PARTS, MATERIALS, {
|
||||
weather: world.weather,
|
||||
activeHazards,
|
||||
|
|
@ -435,6 +583,10 @@ export function getLeaderboard() {
|
|||
return listAgencies()
|
||||
.map((a) => {
|
||||
const profile = getDifficultyProfile(a.difficulty);
|
||||
const recordCompleted =
|
||||
(a.missionsCompleted ?? 0) + (a.careerMissionsCompleted ?? 0);
|
||||
const recordFailed =
|
||||
(a.missionsFailed ?? 0) + (a.careerMissionsFailed ?? 0);
|
||||
return {
|
||||
name: a.name,
|
||||
isAI: !!a.isAI,
|
||||
|
|
@ -444,17 +596,21 @@ export function getLeaderboard() {
|
|||
difficultyLabel: profile.label,
|
||||
aiSkill: a.isAI ? clamp01(a.aiSkill ?? 0.65) : null,
|
||||
bankrupt: !!a.bankrupt,
|
||||
bankruptcyReason: a.bankruptcyReason ?? null,
|
||||
sponsorId: a.sponsorId,
|
||||
treasury: a.treasury,
|
||||
reputation: Math.round(a.reputation * 10) / 10,
|
||||
missionsCompleted: a.missionsCompleted,
|
||||
missionsFailed: a.missionsFailed,
|
||||
missionsCompleted: recordCompleted,
|
||||
missionsFailed: recordFailed,
|
||||
careerMissionsCompleted: a.careerMissionsCompleted ?? 0,
|
||||
careerMissionsFailed: a.careerMissionsFailed ?? 0,
|
||||
contractsAbandoned: a.contractsAbandoned ?? 0,
|
||||
earnedTotal: a.earnedTotal,
|
||||
score: Math.round(
|
||||
(a.bankrupt ? -1000 : 0) +
|
||||
a.reputation * 120 +
|
||||
a.missionsCompleted * 300 -
|
||||
a.missionsFailed * 90 +
|
||||
recordCompleted * 300 -
|
||||
recordFailed * 90 +
|
||||
Math.log10(Math.max(1, a.treasury) + 1) * 55,
|
||||
),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -102,7 +102,9 @@ export function agencyTier(agency: AgencyState | null | undefined): number {
|
|||
if (!agency) return 0;
|
||||
let score = 0;
|
||||
score += Math.max(0, (agency.reputation ?? 0) - 1) * 0.35;
|
||||
score += (agency.missionsCompleted ?? 0) * 0.95;
|
||||
score +=
|
||||
((agency.missionsCompleted ?? 0) + (agency.careerMissionsCompleted ?? 0)) *
|
||||
0.95;
|
||||
score += DIFF_TIER_BONUS[normalizeDifficulty(agency.difficulty)] ?? 0;
|
||||
return Math.max(0, Math.min(3, Math.floor(score)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ export function registerAgencyRoutes(router: Router): void {
|
|||
agency.sponsorId = sponsorId ?? null;
|
||||
agency.bankrupt = false;
|
||||
agency.bankruptAt = null;
|
||||
agency.bankruptcyReason = null;
|
||||
agency.terminatedReason = null;
|
||||
if (!agency.unlockedTechs?.length) {
|
||||
agency.unlockedTechs = profile.allTechUnlocked
|
||||
|
|
@ -140,6 +141,7 @@ export function registerAgencyRoutes(router: Router): void {
|
|||
agency.treasury += grant;
|
||||
agency.bankrupt = false;
|
||||
agency.bankruptAt = null;
|
||||
agency.bankruptcyReason = null;
|
||||
agency.bailoutsTaken = (agency.bailoutsTaken ?? 0) + 1;
|
||||
agency.reputation = Math.max(
|
||||
0,
|
||||
|
|
@ -165,6 +167,7 @@ export function registerAgencyRoutes(router: Router): void {
|
|||
agency.reputation = 1;
|
||||
agency.missionsCompleted = 0;
|
||||
agency.missionsFailed = 0;
|
||||
agency.contractsAbandoned = 0;
|
||||
agency.earnedTotal = 0;
|
||||
agency.rocketDesign = null;
|
||||
agency.crewConfig = { crewSize: 0, lifeSupport: 1 };
|
||||
|
|
@ -172,6 +175,7 @@ export function registerAgencyRoutes(router: Router): void {
|
|||
agency.contractHistory = [];
|
||||
agency.bankrupt = false;
|
||||
agency.bankruptAt = null;
|
||||
agency.bankruptcyReason = null;
|
||||
agency.bailoutsTaken = 0;
|
||||
agency.unlockedTechs = profile.allTechUnlocked
|
||||
? TECH_TREE.map((t) => t.id)
|
||||
|
|
|
|||
|
|
@ -177,6 +177,7 @@ export function settleMissionOutcome(
|
|||
"Catastrophic Loss of Crew — Flight Director License Revoked";
|
||||
agency.bankrupt = true;
|
||||
agency.bankruptAt = simTime;
|
||||
agency.bankruptcyReason = agency.terminatedReason;
|
||||
}
|
||||
summary =
|
||||
profile.id === "sandbox"
|
||||
|
|
@ -215,7 +216,13 @@ export function settleMissionOutcome(
|
|||
if (agency.treasury < 5_000_000 && !agency.bankrupt) {
|
||||
agency.bankrupt = true;
|
||||
agency.bankruptAt = simTime;
|
||||
emit("agency.bankrupt", { agency: agency.name, isAI: !!agency.isAI });
|
||||
agency.bankruptcyReason = "mission_failure_insolvency";
|
||||
emit("agency.bankrupt", {
|
||||
agency: agency.name,
|
||||
isAI: !!agency.isAI,
|
||||
reason: agency.bankruptcyReason,
|
||||
treasury: agency.treasury,
|
||||
});
|
||||
}
|
||||
emit("mission.failed", {
|
||||
agency: agency.name,
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ function chargeFacilityOverhead(simTime: number): void {
|
|||
if (agency.treasury < 0) {
|
||||
agency.bankrupt = true;
|
||||
agency.bankruptAt = simTime;
|
||||
agency.bankruptcyReason = "facility_overhead_insolvency";
|
||||
emit("agency.bankrupt", {
|
||||
agency: agency.name,
|
||||
isAI: !!agency.isAI,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,9 @@ export interface AgencyState {
|
|||
reputation: number;
|
||||
missionsCompleted: number;
|
||||
missionsFailed: number;
|
||||
careerMissionsCompleted?: number;
|
||||
careerMissionsFailed?: number;
|
||||
contractsAbandoned?: number;
|
||||
earnedTotal: number;
|
||||
rocketDesign: RocketDesign | null;
|
||||
crewConfig: CrewConfig | null;
|
||||
|
|
@ -67,6 +70,7 @@ export interface AgencyState {
|
|||
contractHistory: string[];
|
||||
bankrupt: boolean;
|
||||
bankruptAt?: number | null;
|
||||
bankruptcyReason?: string | null;
|
||||
bailoutsTaken?: number;
|
||||
unlockedTechs?: string[];
|
||||
partHeritage?: Record<string, number>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue