Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -2654,27 +2654,26 @@ if (!cmpPosition || !cmpPosition.IsInWorld()) return true; - // If we have no known initial position of our target, look around our own position - // as a fallback. - if (!initPos) - { - let pos = cmpPosition.GetPosition(); - initPos = { 'x': pos.X, 'z': pos.Z }; + let pos = cmpPosition.GetPosition(); + let filter = (ent, type, template) => { + if (previousTarget == ent) + return false; + + if (type.generic == "treasure" && resourceType.generic == "treasure") + return true; + + return type.specific == resourceType.specific && + (type.specific != "meat" || resourceTemplate == template); } // Try to find a new resource of the same specific type near the initial resource position: - // Also don't switch to a different type of huntable animal - let nearbyResource = this.FindNearbyResource(new Vector2D(initPos.x, initPos.z), - (ent, type, template) => { - if (previousTarget == ent) - return false; - - if (type.generic == "treasure" && resourceType.generic == "treasure") - return true; + // Also don't switch to a different type of huntable animal unless it is a domestic one. + let nearbyResource = this.FindNearbyResource(Vector2D.from3D(pos), filter); - return type.specific == resourceType.specific && - (type.specific != "meat" || resourceTemplate == template); - }); + if (!initPos) + initPos = { 'x': pos.X, 'z': pos.Z }; + else if (!nearbyResource) + nearbyResource = this.FindNearbyResource(new Vector2D(initPos.X, initPos.Z), filter); if (nearbyResource) {