public static IMyModelDummy GetDummy(this IMyModel Model, string DummyName) { Dictionary <string, IMyModelDummy> Dummies = new Dictionary <string, IMyModelDummy>(); Model.GetDummies(Dummies); return(Dummies.ContainsKey(DummyName) ? Dummies[DummyName] : null); }
private void CheckFlameDummies() { if (Entity == null) { return; } IMyModel model = Entity.Model; if (model == null) { return; } Dictionary <string, IMyModelDummy> dummies = new Dictionary <string, IMyModelDummy>(); model.GetDummies(dummies); foreach (string dummy in dummies.Keys) { if (dummy.StartsWith("thruster_flame", StringComparison.InvariantCultureIgnoreCase)) { m_hasFlames = true; return; } } m_hasFlames = false; }
private static bool TryGetDummy(string name, IMyModel model, out IMyModelDummy dummy) { Dictionary <string, IMyModelDummy> dummies = new Dictionary <string, IMyModelDummy>(); model.GetDummies(dummies); return(dummies.TryGetValue(name, out dummy)); }
internal void Update() { _cachedModel = Entity.Model; _cachedSubpart = Entity; _cachedSubpartModel = _cachedSubpart?.Model; for (var i = 0; i < _path.Length - 1; i++) { MyEntitySubpart part; if (_cachedSubpart.TryGetSubpart(_path[i], out part)) { _cachedSubpart = part; } else { _tmp2.Clear(); ((IMyModel)_cachedSubpart.Model)?.GetDummies(_tmp2); _failed = true; return; } } _cachedSubpartModel = _cachedSubpart?.Model; _cachedDummyMatrix = null; _tmp1.Clear(); _cachedSubpartModel?.GetDummies(_tmp1); IMyModelDummy dummy; if (_tmp1.TryGetValue(_path[_path.Length - 1], out dummy)) { _cachedDummyMatrix = MatrixD.Normalize(dummy.Matrix); _failed = false; return; } _failed = true; }
private void UpdateParticleEffect() { if (_effectCachedModel != _reactor.Model) { _effectCachedModel = _reactor.Model; var tmp = new Dictionary <string, IMyModelDummy>(); _effectCachedModel?.GetDummies(tmp); _effectMatrix = tmp.GetValueOrDefault("subpart_PlasmaParticle")?.Matrix; // empty for particle } if (_reactor.IsWorking && _effectMatrix.HasValue) { var fractionalOutput = _reactor.CurrentOutput / _reactor.MaxOutput; var dTheta = MAX_RATE * fractionalOutput * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; _effectMatrix = _effectMatrix.Value * MatrixD.CreateRotationY(dTheta); if (_effect == null) { MyParticlesManager.TryCreateParticleEffect("PlasmaSparks", out _effect); // particle subtype } _effect.WorldMatrix = _effectMatrix.Value * _reactor.WorldMatrix; _effect.Velocity = _reactor.CubeGrid.Physics?.GetVelocityAtPoint(_effect.WorldMatrix.Translation) ?? Vector3.Right; // rotation } else { _effect?.Stop(); if (_effect != null) { MyParticlesManager.RemoveParticleEffect(_effect); } _effect = null; } }
internal IMyModelDummy GetPartDummy(string partName, IMyModel model) { Dictionary <string, IMyModelDummy> dummyList = new Dictionary <string, IMyModelDummy>(); model.GetDummies(dummyList); IMyModelDummy dummy; if (dummyList.TryGetValue(partName, out dummy)) { return(dummy); } return(null); }
internal Vector3 GetPartLocation(string partName, IMyModel model) { Dictionary <string, IMyModelDummy> dummyList = new Dictionary <string, IMyModelDummy>(); model.GetDummies(dummyList); IMyModelDummy dummy; if (dummyList.TryGetValue(partName, out dummy)) { return(dummy.Matrix.Translation); } return(Vector3.Zero); }
private void Update() { _cachedModel = _entity.Model; _cachedSubpart = _entity; _cachedSubpartModel = _cachedSubpart?.Model; for (var i = 0; i < _path.Length - 1; i++) { MyEntitySubpart part; if (_cachedSubpart.TryGetSubpart(_path[i], out part)) { _cachedSubpart = part; } else { EnergyWeaponsCore.LoggerStatic?.Warning($"Failed to process {string.Join("/", _path)} for {_entity}"); EnergyWeaponsCore.LoggerStatic?.Warning( $"Couldn't find subpart {_path[i]} in {_cachedSubpart.Model?.AssetName}"); var tmp2 = new Dictionary <string, IMyModelDummy>(); _cachedSubpart.Model?.GetDummies(tmp2); EnergyWeaponsCore.LoggerStatic?.Warning( $"Existing dummies/subparts: {string.Join(", ", tmp2.Keys)}"); _failed = true; return; } } _cachedSubpartModel = _cachedSubpart?.Model; _cachedDummyMatrix = null; var tmp = new Dictionary <string, IMyModelDummy>(); _cachedSubpartModel?.GetDummies(tmp); IMyModelDummy dummy; if (tmp.TryGetValue(_path[_path.Length - 1], out dummy)) { _cachedDummyMatrix = dummy.Matrix; _failed = false; return; } EnergyWeaponsCore.LoggerStatic?.Warning($"Failed to process {string.Join("/", _path)} for {_entity}"); EnergyWeaponsCore.LoggerStatic?.Warning( $"Couldn't find dummy {_path[_path.Length - 1]} in {_cachedSubpart?.Model?.AssetName}"); EnergyWeaponsCore.LoggerStatic?.Warning( $"Existing dummies: {string.Join(", ", tmp.Keys)}"); _failed = true; }
private void UpdateParticleEffect() { if (_effectCachedModel != _reactor.Model) { _effectCachedModel = _reactor.Model; var tmp = new Dictionary <string, IMyModelDummy>(); _effectCachedModel?.GetDummies(tmp); _effectMatrix = tmp.GetValueOrDefault("subpart_PlasmaParticle")?.Matrix; // empty for particle } if (_reactor.IsWorking && _effectMatrix.HasValue) { var fractionalOutput = _reactor.CurrentOutput / _reactor.MaxOutput; var dTheta = 1 * MyEngineConstants.PHYSICS_STEP_SIZE_IN_SECONDS; _effectMatrix = _effectMatrix.Value * MatrixD.CreateRotationY(-dTheta); if (_effect == null) { MyParticlesManager.TryCreateParticleEffect("EMPdamageEffect", out _effect); // particle subtype } _effect.WorldMatrix = _effectMatrix.Value * _reactor.WorldMatrix; _effect.Velocity = _reactor.CubeGrid.Physics?.GetVelocityAtPoint(_effect.WorldMatrix.Translation) ?? Vector3.Right; // rotation if (_effect == null) { return; } // if (Vector3D.DistanceSquared(MyAPIGateway.Session.Camera.WorldMatrix.Translation, _reactor.Position) >= ParticleMaxDistance * ParticleMaxDistance) // return; } else { _effect?.Stop(); if (_effect != null) { MyParticlesManager.RemoveParticleEffect(_effect); } _effect = null; if (_effect == null) { return; } } }
public static bool ProcessBlock(IMySlimBlock block) { if (block == null) { return(false); } if (AllowedBlocks.Contains(block.BlockDefinition.Id)) { return(true); } var grid = block.CubeGrid as MyCubeGrid; if (grid == null) { return(true); } if (RestrictedBlocks.Contains(block.BlockDefinition.Id)) { grid.RazeBlock(block.Min); return(false); } if (block.BlockDefinition.Context?.ModId == null || !block.BlockDefinition.Context.ModId.Contains(".sbm")) { AllowedBlocks.Add(block.BlockDefinition.Id); return(true); } var idString = block.BlockDefinition.Context.ModId.Replace(".sbm", ""); bool badResult = false; if (block.FatBlock == null) { MyCube cube = null; if (!grid.TryGetCube(block.Min, out cube)) { return(true); } foreach (var part in cube.Parts) { IMyModel model = part.Model; if (model == null) { continue; } var dummyDict = new Dictionary <string, IMyModelDummy>(); var count = model.GetDummies(dummyDict); foreach (var dummy in dummyDict.Keys) { if (dummy.Contains("ModEncProtSys_") && !dummy.Contains(idString)) { badResult = true; break; } } if (badResult) { break; } } } else { IMyModel model = block.FatBlock.Model; if (model == null) { return(true); } var dummyDict = new Dictionary <string, IMyModelDummy>(); var count = model.GetDummies(dummyDict); foreach (var dummy in dummyDict.Keys) { if (dummy.Contains("ModEncProtSys_") && !dummy.Contains(idString)) { badResult = true; break; } } } if (badResult) { RestrictedBlocks.Add(block.BlockDefinition.Id); grid.RazeBlock(block.Min); return(false); } else { AllowedBlocks.Add(block.BlockDefinition.Id); return(true); } }