Aetheria/Assets/Scripts/ServerShared/Targeting/EntityTargets.cs
Meta Vens f803151681 Mining index: a general targeting index fed by providers; the linear chunk scan goes
Zone.Targets (TargetingIndex) answers Within and best-first Best over
ITargetProvider regions. EntityTargets offers the observer's VisibleEntities;
BeltTargets keys each belt's rocks into kinetic bands and bounds each segment's
annular sector for distance, bearing and visibility. Entity.VisibleChunksInReach
queries the index with DetectionReachPerVisibility, an upper bound from the
sensors' hull. Zone.ChunksNear and AsteroidBelt.InnerRadius are deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:02:51 +02:00

39 lines
1.5 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
using static CultMath.math;
// Mining index: entities as targets. Perception stays Entity's: the only entities a search can be offered are those
// already in its observer's VisibleEntities, so the one region carries no visibility bound (they are already seen).
public sealed class EntityTargets : ITargetProvider
{
public void Regions(in TargetSearch search, List<TargetRegion> into)
{
var observer = search.Observer;
if (observer == null || observer.VisibleEntities.Count == 0) return;
var nearest = float.PositiveInfinity;
var farthest = 0f;
foreach (var entity in observer.VisibleEntities)
{
var distance = length(entity.Position.xz - search.Position);
nearest = min(nearest, distance);
farthest = max(farthest, distance);
}
into.Add(new TargetRegion
{
Provider = this,
Nearest = nearest,
Farthest = farthest,
BearingHalfWidth = PI,
MaxVisibility = float.PositiveInfinity
});
}
public void Candidates(in TargetSearch search, in TargetRegion region, List<TargetCandidate> into)
{
foreach (var entity in search.Observer.VisibleEntities)
into.Add(new TargetCandidate(entity, entity.Position.xz));
}
}