private bool CanBeAlarmSignalized() { // we can launch alarm, when prefab auto charging enabled if (MyFakes.ENABLE_PREFABS_AUTO_CHARGING) { return(true); } // we can launch alarm, when prefab container contains working generator foreach (MyPrefabBase prefabGenerator in GetPrefabs(CategoryTypesEnum.GENERATOR)) { MyPrefabGenerator generator = prefabGenerator as MyPrefabGenerator; if (generator.IsWorking()) { return(true); } } // we can launch alarm, when prefab container contains alarm, which doesn't require energy foreach (MyPrefabBase prefabAlarm in GetPrefabs(CategoryTypesEnum.ALARM)) { MyPrefabAlarm alarm = prefabAlarm as MyPrefabAlarm; if (alarm.RequiresEnergy != null && !alarm.RequiresEnergy.Value) { return(true); } } return(false); }
/// <summary> /// Try find generator for prefab which will supply electricity /// </summary> public void FindGeneratorsFor(MyPrefabBase prefab) { int generatorsCount = 0; foreach (var item in m_prefabs) { MyPrefabGenerator generator = item as MyPrefabGenerator; if (generator != null && generator.IsWorking()) { float distanceSqr = generator.GetRange() + WorldVolume.Radius; distanceSqr *= distanceSqr; if (Vector3.DistanceSquared(prefab.GetPosition(), generator.GetPosition()) <= distanceSqr) { //prefab.Generator = generator; //return; generatorsCount++; } } } //prefab.Generator = null; prefab.GeneratorsCount = generatorsCount; }