y
This commit is contained in:
parent
61718e2981
commit
f657b6a4a4
94 changed files with 3970 additions and 1241 deletions
|
|
@ -5,22 +5,6 @@
|
|||
(function (global) {
|
||||
function avgOf(list, fn) { return list.length ? list.reduce((sum, t) => sum + (Number(fn(t)) || 0), 0) / list.length : 0; }
|
||||
function countOf(list, fn) { return list.reduce((sum, t) => sum + (fn(t) ? 1 : 0), 0); }
|
||||
function nearestAverage(alive) {
|
||||
if (alive.length < 2) return Infinity;
|
||||
let total = 0;
|
||||
for (const a of alive) {
|
||||
let best = Infinity;
|
||||
for (const b of alive) {
|
||||
if (a === b) continue;
|
||||
const dx = (a.x || 0) - (b.x || 0);
|
||||
const dy = (a.y || 0) - (b.y || 0);
|
||||
const d2 = dx * dx + dy * dy;
|
||||
if (d2 < best) best = d2;
|
||||
}
|
||||
if (Number.isFinite(best)) total += Math.sqrt(best);
|
||||
}
|
||||
return total / alive.length;
|
||||
}
|
||||
function collect(worldRef) {
|
||||
const now = worldRef?.time || 0;
|
||||
const alive = (worldRef?.tarinai || []).filter(t => t && !t.dead);
|
||||
|
|
@ -29,12 +13,10 @@
|
|||
const panicCount = countOf(alive, t => t.state === "panic" || (t.fearTimer || 0) > 0.2 || (t.panicTargetUntil || 0) > now);
|
||||
const safetyHighCount = countOf(alive, t => (t.needs?.safety || 0) >= 52 || (t.fearTimer || 0) > 0.35);
|
||||
const weakCount = countOf(alive, t => (t.energy || 0) < 45 || (t.hunger || 0) > 88 || (t.needs?.health || 0) > 58);
|
||||
const criticalCount = countOf(alive, t => (t.energy || 0) < 25 || (t.hunger || 0) > 94 || (t.needs?.health || 0) > 75);
|
||||
const diseasedCount = countOf(alive, t => t.zunchiDisease || t.sleepDisease || t.explosionDisease || t.fightDisease);
|
||||
const breedingCount = countOf(alive, t => (t.loveMochiTimer || 0) > 0.1 || t.state === "birth_ritual" || (t.birthRitualTimer || 0) > 0.1);
|
||||
const recentDeaths = (Array.isArray(worldRef?.recentDeathTimes) ? worldRef.recentDeathTimes : []).filter(t => now - (Number(t) || -999) <= 30).length;
|
||||
const nearestAvg = nearestAverage(alive);
|
||||
const fieldId = String(worldRef?.fieldType || "garden");
|
||||
const overcrowdLimit = fieldId === "cage" ? 28 : (fieldId === "park" ? 140 : 75);
|
||||
const previousPopulation = Number(worldRef?.lastColonyMoodPopulation);
|
||||
const populationIncreasing = Number.isFinite(previousPopulation) && n > previousPopulation;
|
||||
return {
|
||||
|
|
@ -50,35 +32,36 @@
|
|||
panicCount,
|
||||
safetyHighCount,
|
||||
weakCount,
|
||||
criticalCount,
|
||||
diseasedCount,
|
||||
breedingCount,
|
||||
recentDeaths,
|
||||
nearestAvg,
|
||||
recentShock: (now - (worldRef?.lastShootAt || -999) <= 8) || (now - (worldRef?.lastGenkotsuAt || -999) <= 8),
|
||||
panicRatio: ratio(panicCount),
|
||||
safetyRatio: ratio(safetyHighCount),
|
||||
weakRatio: ratio(weakCount),
|
||||
criticalRatio: ratio(criticalCount),
|
||||
diseaseRatio: ratio(diseasedCount),
|
||||
breedingRatio: ratio(breedingCount),
|
||||
overcrowdLimit,
|
||||
denseCrowd: Number.isFinite(nearestAvg) && nearestAvg < 58 && n >= Math.max(12, Math.floor(overcrowdLimit * 0.75)),
|
||||
};
|
||||
}
|
||||
function choose(worldRef, m) {
|
||||
const candidates = [];
|
||||
const add = (id, priority, ok) => { if (ok) candidates.push({ id, priority }); };
|
||||
const devastationSignal = m.recentDeaths >= 3 || (m.n <= 2 && (worldRef?.deadCount || 0) > 0 && (m.recentDeaths > 0 || m.weakRatio >= 0.35 || m.panicRatio >= 0.20));
|
||||
const crisisExhaustionSignal = m.avgEnergy < 30 && m.weakRatio >= 0.48;
|
||||
const crisisDeathThreshold = Math.max(5, Math.ceil(m.n * 0.10));
|
||||
const crisisMortalitySignal = m.recentDeaths >= crisisDeathThreshold;
|
||||
const crisisSystemicStress = m.weakRatio >= 0.50 && m.criticalRatio >= 0.35;
|
||||
const crisisCollapseSignal = m.weakRatio >= 0.70 && m.criticalRatio >= 0.60;
|
||||
add("devastation", 120, m.n <= 10 && devastationSignal);
|
||||
add("crisis", 110, m.recentDeaths >= 2 || crisisExhaustionSignal || (m.avgHunger > 92 && m.weakRatio >= 0.48));
|
||||
add("crisis", 110, !m.populationIncreasing && ((crisisMortalitySignal && crisisSystemicStress) || crisisCollapseSignal));
|
||||
add("confusion", 100, (m.recentShock && (m.panicRatio >= 0.10 || m.safetyRatio >= 0.18)) || m.panicRatio >= 0.25);
|
||||
add("fearful", 90, (m.avgSafety >= 50 && m.safetyRatio >= 0.28) || (m.recentShock && m.safetyRatio >= 0.18));
|
||||
add("disease_spread", 82, m.diseaseRatio >= 0.25 || (m.diseasedCount >= 3 && m.diseaseRatio >= 0.16));
|
||||
add("weakened", 74, !m.populationIncreasing && ((m.avgEnergy < 54 && m.weakRatio >= 0.18) || m.avgHunger > 82 || m.weakRatio >= 0.34));
|
||||
add("breeding", 66, m.breedingRatio >= 0.10 || m.breedingCount >= 2 || m.now - (worldRef?.lastBirthAt || -999) <= 45);
|
||||
add("happy", 46, m.avgStress < 28 && m.panicRatio < 0.08 && m.diseaseRatio < 0.12 && m.weakRatio < 0.18);
|
||||
add("overcrowded", 34, m.n >= m.overcrowdLimit || m.denseCrowd);
|
||||
add("isolated", 28, m.n <= 1 || (m.n <= 3 && m.nearestAvg > Math.max(180, Math.min(worldRef?.w || 900, worldRef?.h || 600) * 0.32)));
|
||||
add("isolated", 28, m.n <= 1);
|
||||
if (!candidates.length) return "relaxed";
|
||||
candidates.sort((a, b) => b.priority - a.priority);
|
||||
return candidates[0].id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue