Use typed hull facets in motion consumers

This commit is contained in:
Meta Vens 2026-06-14 05:15:18 +01:00
commit 64214c5dd8
7 changed files with 34 additions and 14 deletions

View file

@ -83,7 +83,7 @@ public class CombatState : BaseState
var testWeapon = _agent.Ship.WeaponGroups[selectedGroup].weapons.First();
if(testWeapon.Velocity > 1)
{
var targetHullData = _agent.ItemManager.GetData(target.Hull) as HullData;
var targetHull = _agent.ItemManager.GetRuntimeItem(target.Hull);
var targetVelocity = float3(target.Velocity.x, 0, target.Velocity.y);
var shipVelocity = float3(_agent.Ship.Velocity.x, 0, _agent.Ship.Velocity.y);
var predictedPosition = AetheriaMath.FirstOrderIntercept(
@ -93,7 +93,7 @@ public class CombatState : BaseState
target.Position,
targetVelocity
);
predictedPosition.y = _agent.Ship.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
predictedPosition.y = _agent.Ship.Zone.GetHeight(predictedPosition.xz) + (float)(targetHull?.HullGridOffset ?? 0);
toTarget = normalize(predictedPosition - _agent.Ship.Position);
}
@ -148,4 +148,4 @@ public class CombatState : BaseState
}
}
}
}
}

View file

@ -52,10 +52,10 @@ public class Thruster : Behavior, IAnalogBehavior
public Thruster(ThrusterData data, EquippedItem item) : base(data, item)
{
_data = data;
var hullData = ItemManager.GetData(Entity.Hull) as HullData;
var hullCenter = hullData.Shape.CenterOfMass;
var itemData = ItemManager.GetData(item.EquippableItem);
var itemCenter = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
var hullShape = ItemManager.GetRuntimeShape(Entity.Hull);
var itemShape = ItemManager.GetRuntimeShape(item.EquippableItem);
var hullCenter = hullShape.CenterOfMass;
var itemCenter = hullShape.Inset(itemShape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
var toCenter = hullCenter - itemCenter;
Torque = -dot(normalize(toCenter), float2(1, 0).Rotate(item.EquippableItem.Rotation));
Thrust = Evaluate(_data.Thrust);

View file

@ -60,13 +60,13 @@ public class TurretController : Behavior, IInitializableBehavior
var diff = Entity.Target.Value.Position - Entity.Position;
if (_predictShots)
{
var targetHullData = Entity.ItemManager.GetData(Entity.Target.Value.Hull) as HullData;
var targetHull = Entity.ItemManager.GetRuntimeItem(Entity.Target.Value.Hull);
var targetVelocity = float3(Entity.Target.Value.Velocity.x, 0, Entity.Target.Value.Velocity.y);
var predictedPosition = AetheriaMath.FirstOrderIntercept(
Entity.Position, float3.zero, _shotSpeed,
Entity.Target.Value.Position, targetVelocity
);
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
predictedPosition.y = Entity.Zone.GetHeight(predictedPosition.xz) + (float)(targetHull?.HullGridOffset ?? 0);
Entity.LookDirection = normalize(predictedPosition - Entity.Position);
}
else
@ -98,4 +98,4 @@ public class TurretController : Behavior, IInitializableBehavior
}
return true;
}
}
}

View file

@ -64,6 +64,23 @@ public class ItemManager
return itemId == Guid.Empty ? null : _itemProjections.GetRuntimeItem(itemId);
}
public Shape GetRuntimeShape(ItemInstance item)
{
var typedItem = GetRuntimeItem(item);
return ToShape(typedItem?.ShapeWidth ?? 1, typedItem?.ShapeHeight ?? 1, typedItem?.ShapeCells);
}
private static Shape ToShape(int width, int height, IReadOnlyList<AetheriaRuntimeShapeCell> cells)
{
var shape = new Shape(Math.Max(width, 1), Math.Max(height, 1));
if (cells == null) return shape;
foreach (var cell in cells)
shape[new int2(cell.X, cell.Y)] = true;
return shape;
}
public RuntimeItemReference CreateReference(ItemData item)
{
return new RuntimeItemReference(item);

View file

@ -284,7 +284,7 @@ public class Ship : Entity
var velocityMagnitude = length(Velocity);
if(velocityMagnitude > .01f)
Velocity = normalize(Velocity) * AetheriaMath.Decay(velocityMagnitude, HullData.Drag, delta);
Velocity = normalize(Velocity) * AetheriaMath.Decay(velocityMagnitude, (float)(ItemManager.GetRuntimeItem(Hull)?.HullDrag ?? 0), delta);
Position.xz += Velocity * delta;