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; }
/// <summary> /// CreatePrefab /// </summary> /// <param name="hudLabelText"></param> /// <param name="objBuilder"></param> /// <returns></returns> public MyPrefabBase CreatePrefab(string hudLabelText, MyPrefabContainer prefabContainer, MyMwcObjectBuilder_PrefabBase prefabBuilder) { Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyPrefabFactory.CreatePrefab"); MyPrefabConfiguration config = MyPrefabConstants.GetPrefabConfiguration(prefabBuilder.GetObjectBuilderType(), prefabBuilder.GetObjectBuilderId().Value); Vector3 relativePosition = MyPrefabContainer.GetRelativePositionInAbsoluteCoords(prefabBuilder.PositionInContainer); Matrix prefabLocalOrientation = Matrix.CreateFromYawPitchRoll(prefabBuilder.AnglesInContainer.X, prefabBuilder.AnglesInContainer.Y, prefabBuilder.AnglesInContainer.Z); MyPrefabBase prefab = null; if (config is MyPrefabConfigurationKinematic) { prefab = new MyPrefabKinematic(prefabContainer); } else if (config is MyPrefabConfigurationLight) { prefab = new MyPrefabLight(prefabContainer); } else if (config is MyPrefabConfigurationLargeWeapon) { prefab = new MyPrefabLargeWeapon(prefabContainer); } else if (config is MyPrefabConfigurationSound) { prefab = new MyPrefabSound(prefabContainer); } else if (config is MyPrefabConfigurationParticles) { prefab = new MyPrefabParticles(prefabContainer); } else if (config is MyPrefabConfigurationLargeShip) { prefab = new MyPrefabLargeShip(prefabContainer); } else if (config is MyPrefabConfigurationHangar) { prefab = new MyPrefabHangar(prefabContainer); } else if (config is MyPrefabConfigurationFoundationFactory) { prefab = new MyPrefabFoundationFactory(prefabContainer); } else if (config is MyPrefabConfigurationSecurityControlHUB) { prefab = new MyPrefabSecurityControlHUB(prefabContainer); } else if (config is MyPrefabConfigurationBankNode) { prefab = new MyPrefabBankNode(prefabContainer); } else if (config is MyPrefabConfigurationGenerator) { prefab = new MyPrefabGenerator(prefabContainer); } else if (config is MyPrefabConfigurationScanner) { prefab = new MyPrefabScanner(prefabContainer); } else if (config is MyPrefabConfigurationCamera) { prefab = new MyPrefabCamera(prefabContainer); } else if (config is MyPrefabConfigurationAlarm) { prefab = new MyPrefabAlarm(prefabContainer); } else { prefab = new MyPrefab(prefabContainer); //prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); } prefab.Init(hudLabelText, relativePosition, prefabLocalOrientation, prefabBuilder, config); Render.MyRender.GetRenderProfiler().EndProfilingBlock(); return(prefab); }