duu
This commit is contained in:
parent
88f618cadf
commit
8f9f5b5100
108 changed files with 2139 additions and 1500 deletions
|
|
@ -161,17 +161,24 @@ function findNearestItemWithRole(world, tarinai, role, maxDist = 520) {
|
|||
const primary = (foodLikeRole && world?.nearbyFood)
|
||||
? world.nearbyFood(tarinai.x, tarinai.y, searchDist, true)
|
||||
: (world?.nearbyItems?.(tarinai.x, tarinai.y, searchDist, true) || world?.items || []);
|
||||
const candidates = Array.isArray(primary) ? primary.slice() : [];
|
||||
const candidates = [];
|
||||
const seen = new Set();
|
||||
const addCandidate = (it) => {
|
||||
if (it && !it.dead && !candidates.includes(it)) candidates.push(it);
|
||||
if (it && !it.dead && !seen.has(it)) {
|
||||
seen.add(it);
|
||||
candidates.push(it);
|
||||
}
|
||||
};
|
||||
if (Array.isArray(primary)) for (const it of primary) addCandidate(it);
|
||||
|
||||
// \u98DF\u6599\u30FB\u6C34\u30FB\u85AC\u306F\u3001\u901A\u5E38\u6642\u304B\u3089\u7A7A\u9593\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u3060\u3051\u306B\u4F9D\u5B58\u3057\u306A\u3044\u3002
|
||||
// \u751F\u6210\u76F4\u5F8C/\u79FB\u52D5\u76F4\u5F8C\u306E\u30A2\u30A4\u30C6\u30E0\u304C nearbyFood \u306E\u30AD\u30E3\u30C3\u30B7\u30E5\u304B\u3089\u6F0F\u308C\u3066\u3082\u3001\u8DDD\u96E2\u3068 roleMatches \u3067\u6700\u7D42\u5224\u5B9A\u3059\u308B\u3002
|
||||
// 食料・水・薬は、生成直後/移動直後の spatial cache 漏れにも耐える。
|
||||
// item type buckets が使える場合は role ごとの型だけを見ることで、
|
||||
// crowded world で毎回 world.items 全体を足す経路を避ける。
|
||||
if (foodLikeRole) {
|
||||
if (Array.isArray(world?.items)) for (const it of world.items) addCandidate(it);
|
||||
if (world?.itemsOfType) {
|
||||
for (const type of foodRoleSearchTypes(role)) for (const it of world.itemsOfType(type) || []) addCandidate(it);
|
||||
} else if (Array.isArray(world?.items)) {
|
||||
for (const it of world.items) addCandidate(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue