hm
This commit is contained in:
parent
7455d630fc
commit
4d3fc2cd47
84 changed files with 3429 additions and 3480 deletions
|
|
@ -84,32 +84,35 @@
|
|||
return occupancy < capacity || (tarinai.insideNestBoxId && tarinai.insideNestBoxId === item.id);
|
||||
}
|
||||
|
||||
function findOwnedStructure(worldRef, tarinai, type = "", maxDist = Infinity) {
|
||||
function findStructure(worldRef, tarinai, opts = {}) {
|
||||
const type = String(opts.type || "");
|
||||
const maxDist = Number.isFinite(Number(opts.maxDist)) ? Number(opts.maxDist) : Infinity;
|
||||
const owned = opts.owned === true;
|
||||
const unowned = opts.unowned === true;
|
||||
const blocked = typeof opts.blocked === "function" ? opts.blocked : sleepTargetBlocked;
|
||||
let best = null, bestD = maxDist;
|
||||
for (const item of worldRef?.items || []) {
|
||||
if (!item?.isStructure || item.dead || item.ownerId !== tarinai?.id) continue;
|
||||
if (!item?.isStructure || item.dead) continue;
|
||||
if (owned && item.ownerId !== tarinai?.id) continue;
|
||||
if (unowned && item.ownerId) continue;
|
||||
if (!owned && !unowned && opts.ownerId !== undefined && item.ownerId !== opts.ownerId) continue;
|
||||
if (Number(item.unreachableUntil || 0) > Number(worldRef?.time || 0)) continue;
|
||||
if (unowned && item.abandonedById && item.abandonedById === tarinai?.id && Number(item.abandonedUntil || 0) > Number(worldRef?.time || 0)) continue;
|
||||
if (type && item.type !== type) continue;
|
||||
if (sleepTargetBlocked(worldRef, tarinai, item)) continue;
|
||||
if (unowned && tarinai?.shouldAvoidTarget?.(item)) continue;
|
||||
if (blocked(worldRef, tarinai, item)) continue;
|
||||
const d = distFn(tarinai, item);
|
||||
if (d < bestD) { best = item; bestD = d; }
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function findUnownedStructure(worldRef, tarinai, type = "", maxDist = Infinity) {
|
||||
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;
|
||||
const d = distFn(tarinai, item);
|
||||
if (d < bestD) { best = item; bestD = d; }
|
||||
}
|
||||
return best;
|
||||
function findOwnedStructure(worldRef, tarinai, type = "", maxDist = Infinity, opts = {}) {
|
||||
return findStructure(worldRef, tarinai, { ...opts, owned: true, type, maxDist });
|
||||
}
|
||||
|
||||
function findUnownedStructure(worldRef, tarinai, type = "", maxDist = Infinity, opts = {}) {
|
||||
return findStructure(worldRef, tarinai, { ...opts, unowned: true, type, maxDist });
|
||||
}
|
||||
|
||||
function nearestSleepPlaceOfType(worldRef, tarinai, type, maxDist = 520) {
|
||||
|
|
@ -148,6 +151,9 @@
|
|||
bedOccupancy,
|
||||
bedComfort,
|
||||
sleepPlaceAvailableFor,
|
||||
findStructure,
|
||||
findOwnedStructure,
|
||||
findUnownedStructure,
|
||||
nearestSleepPlaceOfType,
|
||||
findPrioritySleepPlaceBeforeGrassBedBuild,
|
||||
findNearestSleepPlace,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue