Merge master into eureka/aetheria-release-scenarios: take the ship-mounts lane
The one conflict is EntityInstance's SoundBank block, which this branch had moved onto item.Hardpoint and ship-mounts deleted: it stays deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
cfd9884a33
13 changed files with 206 additions and 162 deletions
|
|
@ -53,7 +53,7 @@ public static class ShipModPreview
|
|||
var clone = UnityEngine.Object.Instantiate(ship.gameObject).GetComponent<ShipInstance>();
|
||||
try { CheckShip(clone, plan, "clone"); }
|
||||
finally { UnityEngine.Object.DestroyImmediate(clone.gameObject); }
|
||||
Debug.Log($"SHIP_MOD_ASSEMBLY_SMOKE equipment={plan.Equipment.Length} thrusters={plan.Thrusters.Length} " +
|
||||
Debug.Log($"SHIP_MOD_ASSEMBLY_SMOKE thrusters={plan.Thrusters.Length} " +
|
||||
$"weapons={plan.Weapons.Length} radiators={plan.Radiators.Length}");
|
||||
}
|
||||
|
||||
|
|
@ -64,10 +64,10 @@ public static class ShipModPreview
|
|||
Require(ship.HullColliders.Length == 1 && Inside(ship.HullColliders[0]) &&
|
||||
ship.HullColliders[0].GetComponent<MeshCollider>() != null, "one hull collider with a MeshCollider");
|
||||
Require(Inside(ship.MapIcon) && Inside(ship.Shield) && Inside(ship.TractorBeam), "map icon, shield and tractor inside the ship");
|
||||
Require(ship.EquipmentHardpoints.Select(node => node.name).SequenceEqual(plan.Equipment) &&
|
||||
ship.EquipmentHardpoints.All(Inside), "equipment hardpoints named by the plan");
|
||||
Require(ship.ThrusterHardpoints.Select(node => node.name).SequenceEqual(plan.Thrusters) &&
|
||||
ship.ThrusterHardpoints.All(node => Inside(node) && Inside(node.Emitter)), "thruster hardpoints with emitters");
|
||||
ship.ThrusterHardpoints.All(node => Inside(node) && Inside(node.Emitter) &&
|
||||
node.Emitter.sharedMaterials.All(material => material == ship.InvisibleMaterial)),
|
||||
"thruster hardpoints with unrendered emitter meshes");
|
||||
Require(ship.RadiatorHardpoints.Select(node => node.name).SequenceEqual(plan.Radiators) &&
|
||||
ship.RadiatorHardpoints.All(node => Inside(node) && Inside(node.Mesh)), "radiator hardpoints with meshes");
|
||||
Require(ship.WeaponHardpoints.Select(node => node.name).SequenceEqual(plan.Weapons.Select(weapon => weapon.Mount)) &&
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public static class ShipPrefabAuthoring
|
|||
var combatLayer = LayerMask.NameToLayer("Combat");
|
||||
if (minimapLayer < 0 || combatLayer < 0) throw new InvalidOperationException("Minimap or Combat layer is missing");
|
||||
|
||||
var equipment = new List<Transform>();
|
||||
var hardpoints = 0;
|
||||
var thrusters = new List<ThrusterHardpoint>();
|
||||
var weapons = new List<WeaponHardpoint>();
|
||||
var radiators = new List<RadiatorHardpoint>();
|
||||
|
|
@ -106,10 +106,9 @@ public static class ShipPrefabAuthoring
|
|||
var parts = name.Split('.');
|
||||
if (parts.Length != 3 || string.IsNullOrWhiteSpace(parts[2]))
|
||||
throw new InvalidOperationException($"Invalid hardpoint name {name}");
|
||||
equipment.Add(node);
|
||||
hardpoints++;
|
||||
switch (parts[1])
|
||||
{
|
||||
case "Equipment": break;
|
||||
case "Thruster":
|
||||
var emitter = DirectChild(node, "Emitter")?.GetComponent<MeshRenderer>();
|
||||
if (emitter == null) throw new InvalidOperationException($"{name} needs an Emitter mesh child");
|
||||
|
|
@ -155,7 +154,7 @@ public static class ShipPrefabAuthoring
|
|||
name != "SHIP.Shield" && name != "SHIP.TractorBeam")
|
||||
throw new InvalidOperationException($"Unknown ship anchor {name}");
|
||||
}
|
||||
if (equipment.Count == 0) throw new InvalidOperationException("Ship has no HP.* hardpoints");
|
||||
if (hardpoints == 0) throw new InvalidOperationException("Ship has no HP.* hardpoints");
|
||||
|
||||
mapIcon.sharedMaterial = mapMaterial;
|
||||
mapIcon.gameObject.layer = minimapLayer;
|
||||
|
|
@ -182,7 +181,6 @@ public static class ShipPrefabAuthoring
|
|||
ship.InvisibleMaterial = invisible;
|
||||
ship.Shield = shield;
|
||||
ship.HullColliders = new[] { hullSurface };
|
||||
ship.EquipmentHardpoints = equipment.ToArray();
|
||||
ship.ThrusterHardpoints = thrusters.ToArray();
|
||||
ship.WeaponHardpoints = weapons.ToArray();
|
||||
ship.RadiatorHardpoints = radiators.ToArray();
|
||||
|
|
|
|||
|
|
@ -23,13 +23,11 @@ public static class ShipPrefabAuthoringSmoke
|
|||
Child(weapon.gameObject, "Muzzle.0");
|
||||
var radiator = Child(root, "HP.Radiator.Port");
|
||||
Primitive(radiator.gameObject, "RadiatorMesh");
|
||||
Child(root, "HP.Equipment.Reactor");
|
||||
Child(root, "Pivot.2.-90.90.-80.80.60");
|
||||
|
||||
ShipPrefabAuthoring.Configure(root);
|
||||
var ship = root.GetComponent<ShipInstance>();
|
||||
Require(ship != null && ship.EquipmentHardpoints.Length == 4, "equipment references");
|
||||
Require(ship.ThrusterHardpoints.Length == 1 && ship.ThrusterHardpoints[0].Emitter != null, "thruster emitter");
|
||||
Require(ship != null && ship.ThrusterHardpoints.Length == 1 && ship.ThrusterHardpoints[0].Emitter != null, "thruster emitter");
|
||||
Require(ship.WeaponHardpoints.Length == 1 && ship.WeaponHardpoints[0].FiringPoint.Length == 2, "weapon muzzles");
|
||||
Require(ship.WeaponHardpoints[0].FiringPoint[0].name == "Muzzle.0", "numeric muzzle order");
|
||||
Require(ship.RadiatorHardpoints.Length == 1 && ship.RadiatorHardpoints[0].Mesh != null, "radiator mesh");
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ public class EntityInstance : MonoBehaviour
|
|||
public ShieldManager Shield;
|
||||
public HullCollider[] HullColliders;
|
||||
|
||||
public Transform[] EquipmentHardpoints;
|
||||
public RadiatorHardpoint[] RadiatorHardpoints;
|
||||
public ThrusterHardpoint[] ThrusterHardpoints;
|
||||
public WeaponHardpoint[] WeaponHardpoints;
|
||||
|
|
@ -241,16 +240,6 @@ public class EntityInstance : MonoBehaviour
|
|||
_constantWeaponManagers[data].StopFiring(item);
|
||||
}
|
||||
}
|
||||
|
||||
var hp = item.Hardpoint;
|
||||
if (hp != null && item.Data.SoundBank != 0)
|
||||
{
|
||||
var hardpointTransform = EquipmentHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
if (hardpointTransform != null)
|
||||
{
|
||||
var hardpointGameObject = hardpointTransform.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
RadiatorMeshes = new Dictionary<Radiator, MeshRenderer>();
|
||||
Barrels = new Dictionary<HardpointData, Transform[]>();
|
||||
|
|
|
|||
|
|
@ -122,8 +122,12 @@ public static class ShipModShips
|
|||
|
||||
var thrusters = plan.Thrusters.Select(id =>
|
||||
{
|
||||
// The thruster's mesh is its exhaust's emission surface, never drawn (ruling thrusters-radiators-are-meshes).
|
||||
// The invisible material is serialized, so it survives the prototype's clone, and EntityInstance keeps it as
|
||||
// this renderer's visible material; forceRenderingOff would not survive Instantiate.
|
||||
var hardpoint = AddOrGet<ThrusterHardpoint>(Node(id).gameObject);
|
||||
hardpoint.Emitter = Renderer(id);
|
||||
hardpoint.Emitter.sharedMaterials = Enumerable.Repeat(template.Invisible, hardpoint.Emitter.sharedMaterials.Length).ToArray();
|
||||
return hardpoint;
|
||||
}).ToArray();
|
||||
var radiators = plan.Radiators.Select(id =>
|
||||
|
|
@ -149,7 +153,6 @@ public static class ShipModShips
|
|||
instance.InvisibleMaterial = template.Invisible;
|
||||
instance.Shield = shield;
|
||||
instance.HullColliders = new[] { surface };
|
||||
instance.EquipmentHardpoints = plan.Equipment.Select(Node).ToArray();
|
||||
instance.ThrusterHardpoints = thrusters;
|
||||
instance.WeaponHardpoints = weapons;
|
||||
instance.RadiatorHardpoints = radiators;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ public sealed class ShipAnchor
|
|||
{
|
||||
// Stable semantic identity. HullData.Hardpoints[].Transform names this ID for mounts.
|
||||
[Key(0)] public string Id;
|
||||
// One of: map-icon, hull-collider, shield, tractor, thruster-emitter,
|
||||
// weapon-muzzle, radiator-mesh, or articulation.
|
||||
// One of: map-icon, hull-collider, shield, tractor, thruster-emitter, weapon-mount,
|
||||
// weapon-muzzle, radiator-mesh, or articulation (a pivot, never a mount).
|
||||
[Key(1)] public string Role;
|
||||
// Stable node ID in the compiled model, never a Blender display name.
|
||||
[Key(2)] public string ModelNodeId;
|
||||
|
|
@ -53,9 +53,19 @@ public static class ShipAuthoringStore
|
|||
// ShipAnchor.Role's vocabulary.
|
||||
private static readonly HashSet<string> Roles = new HashSet<string>(StringComparer.Ordinal)
|
||||
{
|
||||
"map-icon", "hull-collider", "shield", "tractor", "thruster-emitter", "weapon-muzzle", "radiator-mesh", "articulation"
|
||||
"map-icon", "hull-collider", "shield", "tractor", "thruster-emitter", "weapon-mount", "weapon-muzzle", "radiator-mesh",
|
||||
"articulation"
|
||||
};
|
||||
|
||||
// The anchor role a visible hardpoint's mount plays, or null for an internal hardpoint, which has no anchor.
|
||||
private static string MountRole(HardpointType type) =>
|
||||
type == HardpointType.Thruster ? "thruster-emitter" :
|
||||
type == HardpointType.Radiator ? "radiator-mesh" :
|
||||
IsWeapon(type) ? "weapon-mount" : null;
|
||||
|
||||
public static bool IsWeapon(HardpointType type) =>
|
||||
type == HardpointType.Energy || type == HardpointType.Ballistic || type == HardpointType.Launcher;
|
||||
|
||||
public static CultCache Open(string path, bool writable = false)
|
||||
{
|
||||
var cache = new CultCache();
|
||||
|
|
@ -193,13 +203,13 @@ public static class ShipAuthoringStore
|
|||
if (anchors.Count(anchor => anchor.Role == role) != 1)
|
||||
throw new InvalidOperationException($"{ship.Id}: exactly one {role} anchor is required.");
|
||||
|
||||
var mounts = new HashSet<string>(StringComparer.Ordinal);
|
||||
var mounts = new Dictionary<string, HardpointData>(StringComparer.Ordinal);
|
||||
var occupiedHardpointCells = new HashSet<(int x, int y)>();
|
||||
foreach (var hardpoint in hull.Hardpoints ?? new List<HardpointData>())
|
||||
{
|
||||
if (hardpoint == null || string.IsNullOrWhiteSpace(hardpoint.Transform) ||
|
||||
!mounts.Add(hardpoint.Transform))
|
||||
if (hardpoint == null || string.IsNullOrWhiteSpace(hardpoint.Transform) || mounts.ContainsKey(hardpoint.Transform))
|
||||
throw new InvalidOperationException($"{ship.Id}: hardpoint IDs must be present and unique.");
|
||||
mounts.Add(hardpoint.Transform, hardpoint);
|
||||
if (!Enum.IsDefined(typeof(HardpointType), hardpoint.Type))
|
||||
throw new InvalidOperationException($"{ship.Id}: hardpoint {hardpoint.Transform} has an unknown type {(int)hardpoint.Type}.");
|
||||
if (!Enum.IsDefined(typeof(ItemRotation), hardpoint.Rotation))
|
||||
|
|
@ -219,19 +229,32 @@ public static class ShipAuthoringStore
|
|||
if (!occupiedHardpointCells.Add((x, y)))
|
||||
throw new InvalidOperationException($"{ship.Id}: hardpoint {hardpoint.Transform} overlaps another hardpoint.");
|
||||
}
|
||||
// Only a hardpoint that shows on the model has a mount anchor, and its type fixes the role that anchor plays.
|
||||
var mountAnchor = anchors.FirstOrDefault(anchor => anchor.Id == hardpoint.Transform);
|
||||
if (mountAnchor == null)
|
||||
throw new InvalidOperationException($"{ship.Id}: hardpoint {hardpoint.Transform} has no model anchor.");
|
||||
// A mount's anchor plays the mount, so its role is fixed by the hardpoint type; the structural roles (map-icon,
|
||||
// hull-collider, shield, tractor, weapon-muzzle) name other nodes and never double as a mount.
|
||||
var mountRole = hardpoint.Type == HardpointType.Thruster ? "thruster-emitter" :
|
||||
hardpoint.Type == HardpointType.Radiator ? "radiator-mesh" : "articulation";
|
||||
if (mountAnchor.Role != mountRole)
|
||||
var mountRole = MountRole(hardpoint.Type);
|
||||
if (mountRole == null && mountAnchor != null)
|
||||
throw new InvalidOperationException($"{ship.Id}: {hardpoint.Type} hardpoint {hardpoint.Transform} is internal, so no anchor may take its id.");
|
||||
if (mountRole != null && mountAnchor == null)
|
||||
throw new InvalidOperationException($"{ship.Id}: {hardpoint.Type} hardpoint {hardpoint.Transform} has no model anchor.");
|
||||
if (mountRole != null && mountAnchor.Role != mountRole)
|
||||
throw new InvalidOperationException($"{ship.Id}: {hardpoint.Type} hardpoint {hardpoint.Transform} needs a {mountRole} anchor of that id.");
|
||||
}
|
||||
foreach (var anchor in anchors.Where(anchor => !string.IsNullOrEmpty(anchor.ParentId)))
|
||||
if (!mounts.Contains(anchor.ParentId))
|
||||
foreach (var anchor in anchors)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(anchor.ParentId) && !mounts.ContainsKey(anchor.ParentId))
|
||||
throw new InvalidOperationException($"{ship.Id}: anchor {anchor.Id} has unknown hardpoint parent {anchor.ParentId}.");
|
||||
// A mount-role anchor is the mount of a hardpoint of its type, never a loose node. The hardpoint loop above has
|
||||
// already refused one whose id names a hardpoint of another type, so here it only has to name a hardpoint.
|
||||
if ((anchor.Role == "thruster-emitter" || anchor.Role == "radiator-mesh" || anchor.Role == "weapon-mount") &&
|
||||
!mounts.ContainsKey(anchor.Id))
|
||||
throw new InvalidOperationException($"{ship.Id}: {anchor.Role} anchor {anchor.Id} must be the mount of a hardpoint of its type.");
|
||||
if (anchor.Role == "weapon-muzzle" &&
|
||||
(string.IsNullOrEmpty(anchor.ParentId) || !IsWeapon(mounts[anchor.ParentId].Type)))
|
||||
throw new InvalidOperationException($"{ship.Id}: muzzle {anchor.Id} must be parented to a weapon hardpoint's mount.");
|
||||
}
|
||||
foreach (var hardpoint in mounts.Values.Where(hardpoint => IsWeapon(hardpoint.Type)))
|
||||
if (!anchors.Any(anchor => anchor.Role == "weapon-muzzle" && anchor.ParentId == hardpoint.Transform))
|
||||
throw new InvalidOperationException($"{ship.Id}: weapon hardpoint {hardpoint.Transform} needs at least one muzzle anchor.");
|
||||
|
||||
foreach (var line in ship.SchematicLines ?? new List<ShipPolyline>())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,42 +10,21 @@ public sealed class ShipModPlan
|
|||
public string HullCollider;
|
||||
public string Shield;
|
||||
public string Tractor;
|
||||
// Every hull hardpoint's mount id, in hardpoint order: the anchor node each one is matched to by name.
|
||||
public string[] Equipment;
|
||||
// Mount ids whose anchor (role thruster-emitter / radiator-mesh) is the emitter / mesh node itself.
|
||||
public string[] Thrusters;
|
||||
public string[] Radiators;
|
||||
// A weapon mount's muzzle anchors, by Order then id.
|
||||
// Each weapon mount (role weapon-mount) and its muzzle anchors, by Order then id.
|
||||
public (string Mount, string[] Muzzles)[] Weapons;
|
||||
|
||||
// Anchors with role "articulation" become ordinary mount nodes: ArticulationPoint's limits are not authorable until
|
||||
// pivots move onto HullData, so no ArticulationPoint is planned.
|
||||
// Maps a pair Validate accepts; every rule about which anchor may play which part is Validate's, so this refuses nothing.
|
||||
public static ShipModPlan Build(HullData hull, ShipAuthoring visual)
|
||||
{
|
||||
ShipAuthoringStore.Validate(hull, visual);
|
||||
var hardpoints = hull.Hardpoints ?? new List<HardpointData>();
|
||||
var byMount = hardpoints.ToDictionary(hardpoint => hardpoint.Transform, StringComparer.Ordinal);
|
||||
string Only(string wanted) => visual.Anchors.Single(anchor => anchor.Role == wanted).Id;
|
||||
|
||||
foreach (var anchor in visual.Anchors.Where(anchor => anchor.Role == "thruster-emitter" || anchor.Role == "radiator-mesh"))
|
||||
{
|
||||
var wanted = anchor.Role == "thruster-emitter" ? HardpointType.Thruster : HardpointType.Radiator;
|
||||
if (!byMount.ContainsKey(anchor.Id))
|
||||
throw new InvalidOperationException($"{visual.Id}: {anchor.Role} anchor {anchor.Id} must be a {wanted} hardpoint's mount.");
|
||||
}
|
||||
string[] Mounts(HardpointType type) => hardpoints.Where(hardpoint => hardpoint.Type == type).Select(hardpoint => hardpoint.Transform).ToArray();
|
||||
|
||||
var muzzles = visual.Anchors.Where(anchor => anchor.Role == "weapon-muzzle")
|
||||
.OrderBy(anchor => anchor.Order).ThenBy(anchor => anchor.Id, StringComparer.Ordinal).ToArray();
|
||||
foreach (var muzzle in muzzles)
|
||||
if (string.IsNullOrEmpty(muzzle.ParentId) || !IsWeapon(byMount[muzzle.ParentId].Type))
|
||||
throw new InvalidOperationException($"{visual.Id}: muzzle {muzzle.Id} must be parented to a weapon hardpoint's mount.");
|
||||
var weapons = hardpoints.Where(hardpoint => IsWeapon(hardpoint.Type)).Select(hardpoint => (
|
||||
hardpoint.Transform,
|
||||
muzzles.Where(muzzle => muzzle.ParentId == hardpoint.Transform).Select(muzzle => muzzle.Id).ToArray())).ToArray();
|
||||
foreach (var (mount, ids) in weapons)
|
||||
if (ids.Length == 0)
|
||||
throw new InvalidOperationException($"{visual.Id}: weapon hardpoint {mount} needs at least one muzzle anchor.");
|
||||
|
||||
return new ShipModPlan
|
||||
{
|
||||
|
|
@ -53,13 +32,11 @@ public sealed class ShipModPlan
|
|||
HullCollider = Only("hull-collider"),
|
||||
Shield = Only("shield"),
|
||||
Tractor = Only("tractor"),
|
||||
Equipment = hardpoints.Select(hardpoint => hardpoint.Transform).ToArray(),
|
||||
Thrusters = Mounts(HardpointType.Thruster),
|
||||
Radiators = Mounts(HardpointType.Radiator),
|
||||
Weapons = weapons
|
||||
Weapons = hardpoints.Where(hardpoint => ShipAuthoringStore.IsWeapon(hardpoint.Type)).Select(hardpoint => (
|
||||
hardpoint.Transform,
|
||||
muzzles.Where(muzzle => muzzle.ParentId == hardpoint.Transform).Select(muzzle => muzzle.Id).ToArray())).ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
private static bool IsWeapon(HardpointType type) =>
|
||||
type == HardpointType.Energy || type == HardpointType.Ballistic || type == HardpointType.Launcher;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue