e
This commit is contained in:
parent
f657b6a4a4
commit
d163ceb291
76 changed files with 1385 additions and 524 deletions
|
|
@ -35,15 +35,16 @@
|
|||
|
||||
function nestBoxCapacity(worldRef, box = null) {
|
||||
if (typeof worldRef?.nestBoxCapacity === "function") return worldRef.nestBoxCapacity(box);
|
||||
if (box?.type === "pipe") return Math.max(3, pipeItems(worldRef).length * 3);
|
||||
if (box?.type === "pipe") return 3;
|
||||
return 5;
|
||||
}
|
||||
|
||||
function nestBoxOccupants(worldRef, box, limit = 5) {
|
||||
if (!worldRef || !box || box.dead || !isNestContainer(box)) return [];
|
||||
const occupants = box.type === "pipe"
|
||||
? (worldRef.tarinai || []).filter(t => tarinaiInsidePipeNetwork(worldRef, t))
|
||||
: (worldRef.tarinai || []).filter(t => t && !t.dead && t.insideNestBoxId === box.id);
|
||||
// Each pipe mouth has its own local sleeping capacity. The underground
|
||||
// network is still shared for exits, but occupancy/reservations must stay
|
||||
// attached to the entrance pipe or every tarinai piles into the nearest one.
|
||||
const occupants = (worldRef.tarinai || []).filter(t => t && !t.dead && t.insideNestBoxId === box.id);
|
||||
return Number.isFinite(limit) ? occupants.slice(0, Math.max(0, limit)) : occupants;
|
||||
}
|
||||
|
||||
|
|
@ -65,9 +66,7 @@
|
|||
if (box.type === "pipe" && t.insideNestBoxId && tarinaiInsidePipeNetwork(t.world || null, t)) return false;
|
||||
if (box.type !== "pipe" && t.insideNestBoxId === box.id) return false;
|
||||
const target = tarinaiTargetContainer(t);
|
||||
if (box.type === "pipe") {
|
||||
if (target?.type !== "pipe") return false;
|
||||
} else if (target !== box) return false;
|
||||
if (target !== box) return false;
|
||||
if (t._nestBoxAvoidId === box.id && now < (t._nestBoxAvoidUntil || -Infinity)) return false;
|
||||
const seekingNest = t.state === "seek_bed" || t.state === "sleep" || t.sleeping || t.state === "seek_temperature" || t.behavior?.actionId === "sleep_in_bed";
|
||||
if (!seekingNest) return false;
|
||||
|
|
@ -159,7 +158,12 @@
|
|||
const d = distFn(tarinai, item);
|
||||
if (d > maxDist) continue;
|
||||
const comfort = bedComfort(worldRef, item);
|
||||
const score = d - comfort * 18;
|
||||
const occupancy = bedOccupancy(worldRef, item);
|
||||
const pipeLoadPenalty = type === "pipe" ? occupancy * 44 : 0;
|
||||
const spread = type === "pipe" && typeof global.stableUnit === "function"
|
||||
? global.stableUnit(tarinai?.id || tarinai?.familyKey || "tarinai", `pipe-choice:${item.id || "pipe"}`) * 14
|
||||
: 0;
|
||||
const score = d - comfort * 18 + pipeLoadPenalty + spread;
|
||||
if (score < bestScore) { best = item; bestScore = score; }
|
||||
}
|
||||
return best;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue