2026-08-10 14:57:50 +01:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-01-06 14:56:39 +00:00
|
|
|
|
* 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;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2021-01-06 14:56:39 +00:00
|
|
|
|
using UniRx;
|
2026-09-14 17:39:12 +02:00
|
|
|
|
using CultMath;
|
|
|
|
|
|
using static CultMath.math;
|
|
|
|
|
|
using float3 = CultMath.float3;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
|
|
|
|
|
[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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-21 09:37:54 +01:00
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public class TurretController : Behavior, IInitializableBehavior
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
private TurretControllerData _data;
|
2021-01-25 05:53:36 +00:00
|
|
|
|
private List<Weapon> _weapons = new List<Weapon>();
|
2021-01-27 16:14:41 +00:00
|
|
|
|
private float _shotSpeed;
|
|
|
|
|
|
private bool _predictShots;
|
2021-01-06 14:56:39 +00:00
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public TurretController(TurretControllerData data, EquippedItem item) : base(data, item)
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
_data = data;
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
2021-01-06 14:56:39 +00:00
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public TurretController(TurretControllerData data, ConsumableItemEffect item) : base(data, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
_data = data;
|
2021-01-06 14:56:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public void Initialize()
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
|
foreach (var weapon in Entity.GetBehaviors<Weapon>())
|
|
|
|
|
|
{
|
|
|
|
|
|
_weapons.Add(weapon);
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var vel = weapon.Evaluate(weapon.WeaponData.Velocity);
|
2021-04-18 05:13:20 +01:00
|
|
|
|
if (vel > .1f)
|
2021-01-27 16:14:41 +00:00
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
|
_predictShots = true;
|
|
|
|
|
|
_shotSpeed = vel;
|
2021-01-27 16:14:41 +00:00
|
|
|
|
}
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
2021-01-06 14:56:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public override bool Execute(float dt)
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
|
if (Entity.Target.Value != null)
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var diff = Entity.Target.Value.Position - Entity.Position;
|
2021-01-27 16:14:41 +00:00
|
|
|
|
if (_predictShots)
|
|
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var targetHullData = Entity.ItemManager.GetData(Entity.Target.Value.Hull) as HullData;
|
|
|
|
|
|
var targetVelocity = float3(Entity.Target.Value.Velocity.x, 0, Entity.Target.Value.Velocity.y);
|
Delete AetheriaMath in favour of CultMath
AetheriaMath predates the CultMath swap and re-implemented helpers CultMath
now owns. Callers use CultMath directly: decay (Ship, AetherDrive, Entity),
damp (VelocityConversion, FieldTester, FieldDriver), first_order_intercept
(TurretController, Combat, GuidedProjectile), quadratic_bezier (FieldDriver)
and smootherstep (Ship). Parameter order matches in every case, and those
formulas have the same float evaluation order, so behaviour is unchanged.
Galaxy's commented-out segment check names distance_to_segment.
The other overloads had no callers and are dropped without a CultMath
counterpart being needed: the double Damp overloads, FindDistanceToSegment,
GetCatmullRomPosition, GetCubicSplinePosition, Smoothstep(x), and the
Deg2Rad/Rad2Deg constants.
AetherDb census, factions and hardpoint-fit are byte-identical to the
pre-cut captures.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 18:02:41 +02:00
|
|
|
|
var predictedPosition = first_order_intercept(
|
2026-08-10 14:57:50 +01:00
|
|
|
|
Entity.Position, float3.zero, _shotSpeed,
|
|
|
|
|
|
Entity.Target.Value.Position, targetVelocity
|
2021-01-27 16:14:41 +00:00
|
|
|
|
);
|
2026-08-10 14:57:50 +01:00
|
|
|
|
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
|
|
|
|
|
Entity.LookDirection = normalize(predictedPosition - Entity.Position);
|
2021-01-27 16:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2026-08-10 14:57:50 +01:00
|
|
|
|
Entity.LookDirection = normalize(diff);
|
2021-01-06 14:56:39 +00:00
|
|
|
|
var dist = length(diff);
|
|
|
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
|
foreach (var x in _weapons)
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
var data = x.Data as WeaponData;
|
Delete HardpointTransforms; mount direction and arc become sim data
Entity.HardpointTransforms was written only by Unity (EntityInstance.cs),
so the simulation's notion of where a gun points was a readback from a
renderer that never runs headless -- Combat.cs threw KeyNotFoundException
on the first combat tick outside Unity. Deletes the field, its writer, and
the readback branch in Behavior.Direction, leaving the item-rotation path
(the same convention reaction thrusters use, R6) as the only source of
mount direction.
Adds FireControl (ServerShared), a static class owning whether a weapon
bears on a point: MountDirection (planar, from ItemRotation), ArcFor (the
per-hardpoint HardpointData.FiringArc override, falling back to the new
GameplaySettings.FiringArc default of 120), and InArc (the planar dot-cone
test, R7 -- target height never enters it, and an arc of 360+ passes
unconditionally so a turret hardpoint needs no new type, just a number).
Combat.cs and TurretController.cs now gate AI fire through InArc instead
of the old hardcoded 0.99 dot-product test against a live Unity transform.
Settings.cs drops AgentFiringMinDot, which was declared and read by
nothing.
docs/fire-control-cut.md, Cut 1.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 07:37:52 +02:00
|
|
|
|
var fire = FireControl.InArc(x.Item, Entity.LookDirection);
|
2026-08-10 14:57:50 +01:00
|
|
|
|
if (x.Evaluate(data.Range) > dist && fire)
|
2021-01-06 14:56:39 +00:00
|
|
|
|
{
|
2021-01-25 05:53:36 +00:00
|
|
|
|
x.Activate();
|
2021-01-06 14:56:39 +00:00
|
|
|
|
}
|
2021-01-25 05:53:36 +00:00
|
|
|
|
else if (x.Firing)
|
|
|
|
|
|
x.Deactivate();
|
2021-01-06 14:56:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-02-27 20:53:36 +00:00
|
|
|
|
foreach (var x in _weapons)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (x.Firing)
|
|
|
|
|
|
x.Deactivate();
|
|
|
|
|
|
}
|
2021-05-11 04:45:42 +01:00
|
|
|
|
Entity.Target.Value = Entity.VisibleEnemies.FirstOrDefault(e => e is Ship);
|
2021-01-06 14:56:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|