h
This commit is contained in:
parent
e00bfd8879
commit
f941200504
70 changed files with 1856 additions and 429 deletions
|
|
@ -5,7 +5,6 @@
|
|||
// selection policy so nest-box entrance logic and bed targeting do not drift.
|
||||
(function (global) {
|
||||
const distFn = typeof dist === "function" ? dist : ((a, b) => Math.hypot((a?.x || 0) - (b?.x || 0), (a?.y || 0) - (b?.y || 0)));
|
||||
const distXYFn = typeof distXY === "function" ? distXY : ((ax, ay, bx, by) => Math.hypot((ax || 0) - (bx || 0), (ay || 0) - (by || 0)));
|
||||
const clampFn = typeof clamp === "function" ? clamp : ((v, a, b) => Math.max(a, Math.min(b, v)));
|
||||
|
||||
function isSleepFurniture(item) {
|
||||
|
|
@ -75,7 +74,10 @@
|
|||
|
||||
function sleepPlaceAvailableFor(worldRef, tarinai, item) {
|
||||
if (!worldRef || !tarinai || !item || item.dead || !isSleepFurniture(item)) return false;
|
||||
if (Number(item.unreachableUntil || 0) > Number(worldRef.time || 0)) return false;
|
||||
if (item.abandonedById && item.abandonedById === tarinai?.id && Number(item.abandonedUntil || 0) > Number(worldRef.time || 0)) return false;
|
||||
if (tarinai.shouldAvoidTarget?.(item)) return false;
|
||||
if (worldRef?.sleepTargetTemperatureBlocked?.(tarinai, item)) return false;
|
||||
if (sleepTargetBlocked(worldRef, tarinai, item)) return false;
|
||||
const capacity = item.type === "nest_box" ? nestBoxCapacity(worldRef, item) : 1;
|
||||
const occupancy = bedOccupancy(worldRef, item);
|
||||
|
|
@ -86,6 +88,7 @@
|
|||
let best = null, bestD = maxDist;
|
||||
for (const item of worldRef?.items || []) {
|
||||
if (!item?.isStructure || item.dead || item.ownerId !== tarinai?.id) continue;
|
||||
if (Number(item.unreachableUntil || 0) > Number(worldRef?.time || 0)) continue;
|
||||
if (type && item.type !== type) continue;
|
||||
if (sleepTargetBlocked(worldRef, tarinai, item)) continue;
|
||||
const d = distFn(tarinai, item);
|
||||
|
|
@ -98,6 +101,8 @@
|
|||
let best = null, bestD = maxDist;
|
||||
for (const item of worldRef?.items || []) {
|
||||
if (!item?.isStructure || item.dead || item.ownerId) continue;
|
||||
if (item.abandonedById && item.abandonedById === tarinai?.id && Number(item.abandonedUntil || 0) > Number(worldRef?.time || 0)) continue;
|
||||
if (Number(item.unreachableUntil || 0) > Number(worldRef?.time || 0)) continue;
|
||||
if (type && item.type !== type) continue;
|
||||
if (tarinai?.shouldAvoidTarget?.(item)) continue;
|
||||
if (sleepTargetBlocked(worldRef, tarinai, item)) continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue