- Entity.Target is one slot of TargetRef, read-only from outside (IReadOnlyReactiveProperty); Entity.SetTarget is its one writer. A chunk is taken only while the entity can see it, so a rock in darkness cannot be picked. Every handler, agent, turret and test writes through SetTarget. - Entity.ChunkInfo (Q14 A): the value the per-tick sensor rule settles at, computed on demand through Sensor.PassiveRate/Sensor.Gain -- sum of the active sensors' passive rates over (sensors x TargetInfoDecay), capped at 1. Stored nowhere; no per-tick loop over chunks. ChunkVisible is the detection threshold through the chunk path. - The lost-track rule reads through the chunk path: Activate's reconciliation and a per-tick check of the one slot drop a chunk target that has gone dark. - Entity.VisibleChunksInReach (Q13 A): visible chunks within the longest range among active weapons -- the one reach rule for cycling and programmatic picks. - Entity-only readers take .Entity: TargetedBy/TargetedByCount, target items, the stance gate (a chunk has no stance), lock (Q12 A: never on a chunk), turrets, Combat, Minion, FireControl (a chunk fires untargeted until Cut 4). TargetRange and the arc gate read a chunk's planar position. - ActionGameManager: the reticle and next/previous offer visible ships and visible chunks in reach; nearest stays enemies-only; the target panel, indicator and fire-control debug take TargetRef. EntityInstance reads .Entity. - MiningCut3Tests pin parity, darkness, monotone brightness, wear and break, reach, the chunk query, target survival and loss, TargetRef equality, lock, and field-kind assignment at generation and first load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
No EOL
3.3 KiB
C#
102 lines
No EOL
3.3 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 System.Linq;
|
|
using MessagePack;
|
|
using Newtonsoft.Json;
|
|
using UniRx;
|
|
using CultMath;
|
|
using static CultMath.math;
|
|
using float3 = CultMath.float3;
|
|
|
|
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
|
public class TurretControllerData : BehaviorData
|
|
{
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
{
|
|
return new TurretController(this, item);
|
|
}
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
|
{
|
|
return new TurretController(this, item);
|
|
}
|
|
}
|
|
|
|
public class TurretController : Behavior, IInitializableBehavior
|
|
{
|
|
private TurretControllerData _data;
|
|
private List<Weapon> _weapons = new List<Weapon>();
|
|
private float _shotSpeed;
|
|
private bool _predictShots;
|
|
|
|
public TurretController(TurretControllerData data, EquippedItem item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
}
|
|
|
|
public TurretController(TurretControllerData data, ConsumableItemEffect item) : base(data, item)
|
|
{
|
|
_data = data;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
foreach (var weapon in Entity.GetBehaviors<Weapon>())
|
|
{
|
|
_weapons.Add(weapon);
|
|
var vel = weapon.Evaluate(weapon.WeaponData.Velocity);
|
|
if (vel > .1f)
|
|
{
|
|
_predictShots = true;
|
|
_shotSpeed = vel;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool Execute(float dt)
|
|
{
|
|
// Mining Cut 3: a turret engages entities only; it never picks a chunk, and reads one as no target.
|
|
var target = Entity.Target.Value.Entity;
|
|
if (target != null)
|
|
{
|
|
var diff = target.Position - Entity.Position;
|
|
if (_predictShots)
|
|
{
|
|
var targetHullData = Entity.ItemManager.GetData(target.Hull) as HullData;
|
|
var targetVelocity = float3(target.Velocity.x, 0, target.Velocity.y);
|
|
var predictedPosition = first_order_intercept(
|
|
Entity.Position, float3.zero, _shotSpeed,
|
|
target.Position, targetVelocity
|
|
);
|
|
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
|
Entity.LookDirection = normalize(predictedPosition - Entity.Position);
|
|
}
|
|
else
|
|
Entity.LookDirection = normalize(diff);
|
|
|
|
foreach (var x in _weapons)
|
|
{
|
|
// The same per-weapon decision Combat.cs makes; the range test is part of it (a shot out of range
|
|
// is not designated and prices at zero).
|
|
if (FireControl.AgentFires(x, Entity, target))
|
|
{
|
|
x.Activate();
|
|
}
|
|
else if (x.Firing)
|
|
x.Deactivate();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var x in _weapons)
|
|
{
|
|
if (x.Firing)
|
|
x.Deactivate();
|
|
}
|
|
Entity.SetTarget(Entity.VisibleEnemies.FirstOrDefault(e => e is Ship));
|
|
}
|
|
return true;
|
|
}
|
|
} |