public override void UpdateGeneralFromEntityBase()
{
double scaleMultiplyer = CubeGrid.GridSizeEnum.ToLength();
if (IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Large)
{
ClassType = ClassType.Station;
}
else if (!IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Large)
{
ClassType = ClassType.LargeShip;
}
else if (!IsStatic && CubeGrid.GridSizeEnum == MyCubeSize.Small)
{
ClassType = ClassType.SmallShip;
}
var min = new Point3D(int.MaxValue, int.MaxValue, int.MaxValue);
var max = new Point3D(int.MinValue, int.MinValue, int.MinValue);
float totalMass = 0;
foreach (var block in CubeGrid.CubeBlocks)
{
min.X = Math.Min(min.X, block.Min.X);
min.Y = Math.Min(min.Y, block.Min.Y);
min.Z = Math.Min(min.Z, block.Min.Z);
var cubeDefinition = SpaceEngineersApi.GetCubeDefinition(block.TypeId, CubeGrid.GridSizeEnum, block.SubtypeName);
// definition is null when the block no longer exists in the Cube definitions. Ie, Ladder, or a Mod that was removed.
if (cubeDefinition == null || (cubeDefinition.Size.X == 1 && cubeDefinition.Size.Y == 1 && cubeDefinition.Size.Z == 1))
{
max.X = Math.Max(max.X, block.Min.X);
max.Y = Math.Max(max.Y, block.Min.Y);
max.Z = Math.Max(max.Z, block.Min.Z);
}
else
{
// resolve the cube size acording to the cube's orientation.
var orientSize = cubeDefinition.Size.Add(-1).Transform(block.BlockOrientation).Abs();
max.X = Math.Max(max.X, block.Min.X + orientSize.X);
max.Y = Math.Max(max.Y, block.Min.Y + orientSize.Y);
max.Z = Math.Max(max.Z, block.Min.Z + orientSize.Z);
}
var cubeBlockDefinition = SpaceEngineersApi.GetCubeDefinition(block.TypeId, CubeGrid.GridSizeEnum, block.SubtypeName);
float cubeMass = 0;
if (cubeBlockDefinition != null)
{
foreach (var component in cubeBlockDefinition.Components)
{
float componentMass = component.Definition.Mass * component.Count;
cubeMass += componentMass;
}
}
totalMass += cubeMass;
}
var cockpitOrientation = "None";
var cockpits = CubeGrid.CubeBlocks.Where(b => b is MyObjectBuilder_Cockpit).ToArray();
if (cockpits.Length > 0)
{
var count = cockpits.Count(b => b.BlockOrientation.Forward == cockpits[0].BlockOrientation.Forward && b.BlockOrientation.Up == cockpits[0].BlockOrientation.Up);
if (cockpits.Length == count)
{
// All cockpits share the same orientation.
cockpitOrientation = string.Format("Forward={0} ({1}), Up={2} ({3})", cockpits[0].BlockOrientation.Forward, GetAxisIndicator(cockpits[0].BlockOrientation.Forward), cockpits[0].BlockOrientation.Up, GetAxisIndicator(cockpits[0].BlockOrientation.Up));
}
else
{
// multiple cockpits are present, and do not share a common orientation.
cockpitOrientation = "Mixed";
}
}
CockpitOrientation = cockpitOrientation;
var scale = max - min;
scale.X++;
scale.Y++;
scale.Z++;
if (CubeGrid.CubeBlocks.Count == 0)
scale = new System.Windows.Media.Media3D.Vector3D();
Min = min;
Max = max;
Scale = scale;
Size = new Size3D(scale.X * scaleMultiplyer, scale.Y * scaleMultiplyer, scale.Z * scaleMultiplyer);
Mass = totalMass;
var quaternion = CubeGrid.PositionAndOrientation.Value.ToQuaternionD();
var p1 = (min.ToVector3D() * CubeGrid.GridSizeEnum.ToLength()).Transform(quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
var p2 = ((min.ToVector3D() + Scale.ToVector3D()) * CubeGrid.GridSizeEnum.ToLength()).Transform(quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
//var p1 = VRageMath.Vector3D.Transform(min.ToVector3D() * CubeGrid.GridSizeEnum.ToLength(), quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
//var p2 = VRageMath.Vector3D.Transform((min.ToVector3D() + Scale.ToVector3D()) * CubeGrid.GridSizeEnum.ToLength(), quaternion) + CubeGrid.PositionAndOrientation.Value.Position - (CubeGrid.GridSizeEnum.ToLength() / 2);
WorldAABB = new BoundingBoxD(VRageMath.Vector3D.Min(p1, p2), VRageMath.Vector3D.Max(p1, p2));
Center = WorldAABB.Center;
DisplayName = CubeGrid.DisplayName;
// Add Beacon or Antenna detail for the Description.
var broadcasters = CubeGrid.CubeBlocks.Where(b => b.SubtypeName == SubtypeId.LargeBlockBeacon.ToString()
|| b.SubtypeName == SubtypeId.SmallBlockBeacon.ToString()
|| b.SubtypeName == SubtypeId.LargeBlockRadioAntenna.ToString()
|| b.SubtypeName == SubtypeId.SmallBlockRadioAntenna.ToString()).ToArray();
var broadcastNames = string.Empty;
if (broadcasters.Length > 0)
{
var beaconNames = broadcasters.Where(b => b is MyObjectBuilder_Beacon).Select(b => ((MyObjectBuilder_Beacon)b).CustomName ?? "Beacon").ToArray();
var antennaNames = broadcasters.Where(b => b is MyObjectBuilder_RadioAntenna).Select(b => ((MyObjectBuilder_RadioAntenna)b).CustomName ?? "Antenna").ToArray();
broadcastNames = String.Join("|", beaconNames.Concat(antennaNames).OrderBy(s => s));
}
if (string.IsNullOrEmpty(broadcastNames))
Description = string.Format("{0}×{1}×{2}", Scale.X, Scale.Y, Scale.Z);
else
Description = string.Format("{3} {0}×{1}×{2}", Scale.X, Scale.Y, Scale.Z, broadcastNames);
// TODO:
// Report:
// Reflectors On
// Mass: 9,999,999 Kg
// Speed: 0.0 m/s
// Power Usage: 0.05%
// Reactors: 12,999 GW
// Thrusts: 999
// Gyros: 999
// Fuel Time: 0 sec
}