public void OnComponentInstalation(Entity parentEntity, Entity componentInstance) { if (!parentEntity.HasDataBlob <PropulsionAbilityDB>()) { parentEntity.SetDataBlob(new PropulsionAbilityDB()); } ShipMovementProcessor.CalcMaxSpeedAndFuelUsage(parentEntity); }
public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity) { ShipInfoDB shipInfo = shipEntity.GetDataBlob <ShipInfoDB>(); ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>(); float totalTonnage = 0; int totalHTK = 0; double totalVolume = 0; foreach (var componentDesign in componentInstances.GetComponentsByDesigns()) { var componentVolume = componentInstances.AllDesigns[componentDesign.Key].GetDataBlob <MassVolumeDB>().Volume; var componentTonnage = componentInstances.AllDesigns[componentDesign.Key].GetDataBlob <ComponentInfoDB>().SizeInTons; foreach (var componentInstance in componentDesign.Value) { totalHTK += componentInstance.GetDataBlob <ComponentInstanceInfoDB>().HTKRemaining; totalVolume += componentVolume; totalTonnage += componentTonnage; if (!componentInstances.ComponentDictionary.ContainsKey(componentInstance)) { componentInstances.ComponentDictionary.Add(componentInstance, totalVolume); } } } if (shipInfo.Tonnage != totalTonnage) { shipInfo.Tonnage = totalTonnage; ShipMovementProcessor.CalcMaxSpeedAndFuelUsage(shipEntity); } shipInfo.InternalHTK = totalHTK; MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>(); mvDB.Mass = totalTonnage; mvDB.Volume = totalVolume; mvDB.Density = MassVolumeDB.CalculateDensity(totalTonnage, totalVolume); mvDB.Radius = MassVolumeDB.CalculateRadius(totalTonnage, mvDB.Density); }