public static void AddShipSounds(MyShipSoundsDefinition shipSoundGroup) { if (m_categories.ContainsKey(shipSoundGroup.Id)) { m_categories.Remove(shipSoundGroup.Id); } m_categories.Add(shipSoundGroup.Id, shipSoundGroup); }
private void CalculateShipCategory() { bool originalDebris = m_isDebris; MyDefinitionId originalType = m_shipCategory; if (m_shipThrusters == null && (m_shipWheels == null || m_shipWheels.WheelCount <= 0)) { m_isDebris = true; } else if (m_shipGrid.GridSystems.GyroSystem.GyroCount == 0) { m_isDebris = true; } else { bool hasController = false; foreach (var block in m_shipGrid.GetFatBlocks()) { if (block is MyShipController) { if (m_shipGrid.MainCockpit == null && m_shipGrid.GridSizeEnum == MyCubeSize.Small) { m_shipSoundSource = block as MyEntity; } hasController = true; break; } } if (hasController) { int shipMass = m_shipGrid.GetCurrentMass(); float bestWeight = float.MinValue; foreach (var group in m_categories.Values) { if (group.MinWeight < shipMass && ((group.AllowSmallGrid && m_shipGrid.GridSizeEnum == MyCubeSize.Small) || (group.AllowLargeGrid && m_shipGrid.GridSizeEnum == MyCubeSize.Large))) { if (bestWeight == float.MinValue || group.MinWeight > bestWeight) { bestWeight = group.MinWeight; m_shipCategory = group.Id; m_groupData = group; } } } if (bestWeight == float.MinValue) { m_isDebris = true; } else { m_isDebris = false; } } else { m_isDebris = true; } } if (m_groupData == null) { m_isDebris = true; } if (originalType != m_shipCategory || m_isDebris != originalDebris) { m_categoryChange = true; if (m_isDebris) { for (int i = 0; i < m_emitters.Length; i++) { if (m_emitters[i].IsPlaying && m_emitters[i].Loop) { if (i == (int)ShipEmitters.WheelsMain || i == (int)ShipEmitters.WheelsSecondary) { m_emitters[i].StopSound(m_shipWheels == null); } else { m_emitters[i].StopSound(m_shipThrusters == null); } } } } else { for (int i = 0; i < m_emitters.Length; i++) { if (m_emitters[i].IsPlaying && m_emitters[i].Loop) { m_emitters[i].StopSound(true); } } } } if (m_isDebris) { SetGridSounds(false); } else { SetGridSounds(true); } }