Beispiel #1
0
        /// <summary>
        /// ReadDummies
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static Dictionary <string, MyModelDummy> ReadDummies(BinaryReader reader)
        {
            var dummies = new Dictionary <string, MyModelDummy>();

            var nCount = reader.ReadInt32();

            for (var i = 0; i < nCount; ++i)
            {
                var str = reader.ReadString();
                var mat = ReadMatrix(reader);

                var dummy = new MyModelDummy {
                    Matrix = mat, CustomData = new Dictionary <string, object>()
                };

                var customDataCount = reader.ReadInt32();
                for (var j = 0; j < customDataCount; ++j)
                {
                    var name  = reader.ReadString();
                    var value = reader.ReadString();
                    dummy.CustomData.Add(name, value);
                }

                dummies.Add(str, dummy);
            }

            return(dummies);
        }
Beispiel #2
0
 public WeaponEffect(MyModelDummy dummy, int effectId, MyWeaponDefinition.WeaponEffectAction action, MyParticleEffect effect)
 {
     this.Dummy    = dummy;
     this.EffectId = effectId;
     this.Effect   = effect;
     this.Action   = action;
 }
        public MyUseObjectCryoChamberDoor(MyCubeBlock owner, string dummyName, MyModelDummy dummyData, int key)
        {
            CryoChamber = owner as MyCryoChamber;
            Debug.Assert(CryoChamber != null, "MyUseObjectCryoChamberDoor should only be used with MyCryoChamber blocks!");

            LocalMatrix = dummyData.Matrix;
        }
Beispiel #4
0
        protected static void HandleInteractiveObject(IMyUseObject interactive)
        {
            if (!MyFakes.ENABLE_USE_NEW_OBJECT_HIGHLIGHT)
            {
                MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.DummyHighlight;
            }
            else
            {
                MyHud.SelectedObjectHighlight.Color = MySector.EnvironmentDefinition.ContourHighlightColor;
                if (((interactive.InstanceID != -1) || (interactive is MyFloatingObject)) || (interactive.Owner is MyInventoryBagEntity))
                {
                    MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                    MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.OutlineHighlight;
                }
                else
                {
                    MyCharacter character = interactive as MyCharacter;
                    if ((character != null) && character.IsDead)
                    {
                        MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                        MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.OutlineHighlight;
                    }
                    else
                    {
                        bool         flag  = false;
                        MyModelDummy dummy = interactive.Dummy;
                        if ((dummy != null) && (dummy.CustomData != null))
                        {
                            object obj2;
                            flag = dummy.CustomData.TryGetValue("highlight", out obj2);
                            string str = obj2 as string;
                            if (flag && (str != null))
                            {
                                MyHud.SelectedObjectHighlight.HighlightAttribute = str;
                                MyHud.SelectedObjectHighlight.HighlightStyle     = !(interactive.Owner is MyTextPanel) ? MyHudObjectHighlightStyle.OutlineHighlight : MyHudObjectHighlightStyle.EdgeHighlight;
                            }
                            bool   flag1 = dummy.CustomData.TryGetValue("highlighttype", out obj2);
                            string str2  = obj2 as string;
                            if (flag1 && (str2 != null))
                            {
                                MyHud.SelectedObjectHighlight.HighlightStyle = (str2 != "edge") ? MyHudObjectHighlightStyle.OutlineHighlight : MyHudObjectHighlightStyle.EdgeHighlight;
                            }
                        }
                        if (!flag)
                        {
                            MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                            MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.DummyHighlight;
                        }
                    }
                }
            }
            MyCubeBlock owner = interactive.Owner as MyCubeBlock;

            if ((owner != null) && (owner.GetPlayerRelationToOwner() == MyRelationsBetweenPlayerAndBlock.Enemies))
            {
                MyHud.SelectedObjectHighlight.Color = MySector.EnvironmentDefinition.ContourHighlightColorAccessDenied;
            }
            MyHud.SelectedObjectHighlight.Highlight(interactive);
        }
        protected void DebugDrawDummies(MyModel model)
        {
            if (model == null)
            {
                return;
            }

            var distanceSquared = 0f;
            var cameraPos       = Vector3D.Zero;

            if (MySector.MainCamera != null)
            {
                distanceSquared = MyDebugDrawSettings.DEBUG_DRAW_MODEL_DUMMIES_DISTANCE * MyDebugDrawSettings.DEBUG_DRAW_MODEL_DUMMIES_DISTANCE;
                cameraPos       = MySector.MainCamera.WorldMatrix.Translation;
            }

            foreach (var dummy in model.Dummies)
            {
                MyModelDummy modelDummy = dummy.Value;

                MatrixD worldMatrix = (MatrixD)modelDummy.Matrix * m_entity.PositionComp.WorldMatrix;
                if (distanceSquared != 0f && Vector3D.DistanceSquared(cameraPos, worldMatrix.Translation) > distanceSquared)
                {
                    continue;
                }

                VRageRender.MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, dummy.Key, Color.White, 0.7f, false);
                VRageRender.MyRenderProxy.DebugDrawAxis(MatrixD.Normalize(worldMatrix), 0.1f, false);
                VRageRender.MyRenderProxy.DebugDrawOBB(worldMatrix, Vector3.One, 0.1f, false, false);
            }
        }
Beispiel #6
0
 public WeaponEffect(MyModelDummy dummy, int effectId, MyWeaponDefinition.WeaponEffectAction action, MyParticleEffect effect)
 {
     this.Dummy = dummy;
     this.EffectId = effectId;
     this.Effect = effect;
     this.Action = action;
 }
Beispiel #7
0
        private uint AddDetector(string detectorName, string dummyName, MyModelDummy dummyData)
        {
            List <Matrix> matrices;

            if (!m_detectors.TryGetValue(detectorName, out matrices))
            {
                matrices = new List <Matrix>();
                m_detectors[detectorName] = matrices;
            }

            var dummyMatrix = dummyData.Matrix;

            if (Entity is MyCubeBlock)
            {
                float scale = (Entity as MyCubeBlock).CubeGrid.GridScale;
                dummyMatrix.Translation *= scale;
                Matrix.Rescale(ref dummyMatrix, scale);
            }

            matrices.Add(Matrix.Invert(dummyMatrix));

            var shapeKey          = (uint)m_detectorInteractiveObjects.Count;
            var interactiveObject = CreateInteractiveObject(detectorName, dummyName, dummyData, shapeKey);

            if (interactiveObject != null)
            {
                m_detectorInteractiveObjects.Add(shapeKey, new DetectorData(interactiveObject, dummyMatrix, detectorName));
                m_detectorShapeKeys[detectorName] = shapeKey;
            }

            return(shapeKey);
        }
Beispiel #8
0
        private static Dictionary <string, MyModelDummy> ReadDummies(
            BinaryReader reader)
        {
            var dictionary = new Dictionary <string, MyModelDummy>();
            var num1       = reader.ReadInt32();

            for (var index1 = 0; index1 < num1; ++index1)
            {
                var key1         = reader.BaseStream.ReadString(Encoding.ASCII);
                var matrix       = ReadMatrix(reader);
                var myModelDummy = new MyModelDummy();
                myModelDummy.Name       = key1;
                myModelDummy.Matrix     = matrix;
                myModelDummy.CustomData = new Dictionary <string, object>();
                var num2 = reader.ReadInt32();
                for (var index2 = 0; index2 < num2; ++index2)
                {
                    var key2 = reader.BaseStream.ReadString(Encoding.ASCII);
                    var str  = reader.BaseStream.ReadString(Encoding.ASCII);
                    myModelDummy.CustomData.Add(key2, str);
                }

                dictionary.Add(key1, myModelDummy);
            }

            return(dictionary);
        }
Beispiel #9
0
        private unsafe uint AddDetector(string detectorName, string dummyName, MyModelDummy dummyData)
        {
            List <Matrix> list;

            if (!base.m_detectors.TryGetValue(detectorName, out list))
            {
                list = new List <Matrix>();
                base.m_detectors[detectorName] = list;
            }
            Matrix matrix = dummyData.Matrix;

            if (base.Entity is MyCubeBlock)
            {
                float   gridScale  = (base.Entity as MyCubeBlock).CubeGrid.GridScale;
                Matrix *matrixPtr1 = (Matrix *)ref matrix;
                matrixPtr1.Translation *= gridScale;
                Matrix.Rescale(ref matrix, gridScale);
            }
            list.Add(Matrix.Invert(matrix));
            uint         count     = (uint)this.m_detectorInteractiveObjects.Count;
            IMyUseObject useObject = this.CreateInteractiveObject(detectorName, dummyName, dummyData, count);

            if (useObject != null)
            {
                this.m_detectorInteractiveObjects.Add(count, new DetectorData(useObject, matrix, detectorName));
                this.m_detectorShapeKeys[detectorName] = count;
            }
            return(count);
        }
 public MyUseObjectCryoChamberDoor(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     CryoChamber = owner as MyCryoChamber;
     Debug.Assert(CryoChamber != null, "MyUseObjectCryoChamberDoor should only be used with MyCryoChamber blocks!");
     
     LocalMatrix = dummyData.Matrix;
 }
Beispiel #11
0
        private static bool CompoundDummiesIntersect(ref Matrix thisRotation, ref Matrix otherRotation, List <MyModelDummy> thisDummies, List <MyModelDummy> otherDummies)
        {
            using (List <MyModelDummy> .Enumerator enumerator = thisDummies.GetEnumerator())
            {
                bool flag;
                while (true)
                {
                    if (enumerator.MoveNext())
                    {
                        Matrix       matrix2;
                        MyModelDummy current = enumerator.Current;
                        Vector3      forward = current.Matrix.Forward;
                        Vector3      max     = new Vector3(current.Matrix.Right.Length(), current.Matrix.Up.Length(), forward.Length()) * 0.5f;
                        BoundingBox  box     = new BoundingBox(-max, max);
                        Matrix       matrix  = Matrix.Normalize(current.Matrix);
                        Matrix.Multiply(ref matrix, ref thisRotation, out matrix2);
                        Matrix.Invert(ref matrix2, out matrix);
                        List <MyModelDummy> .Enumerator enumerator2 = otherDummies.GetEnumerator();
                        try
                        {
                            while (true)
                            {
                                Matrix matrix4;
                                if (!enumerator2.MoveNext())
                                {
                                    break;
                                }
                                MyModelDummy dummy2 = enumerator2.Current;
                                forward = dummy2.Matrix.Forward;
                                Vector3 vector3 = new Vector3(dummy2.Matrix.Right.Length(), dummy2.Matrix.Up.Length(), forward.Length()) * 0.5f;
                                Matrix  matrix3 = Matrix.Normalize(dummy2.Matrix);
                                Matrix.Multiply(ref matrix3, ref otherRotation, out matrix4);
                                Matrix.Multiply(ref matrix4, ref matrix, out matrix3);
                                MyOrientedBoundingBox box2 = MyOrientedBoundingBox.Create(new BoundingBox(-vector3, vector3), matrix3);
                                if (box2.Intersects(ref box))
                                {
                                    return(true);
                                }
                            }
                            continue;
                        }
                        finally
                        {
                            enumerator2.Dispose();
                            continue;
                        }
                    }
                    else
                    {
                        goto TR_0000;
                    }
                    break;
                }
                return(flag);
            }
TR_0000:
            return(false);
        }
        public override int AddDetector(string name, Matrix dummyMatrix)
        {
            var          detectorName = name.ToLower();
            var          dummyName    = "detector_" + detectorName;
            MyModelDummy modelDummy   = new MyModelDummy()
            {
                CustomData = null, Matrix = dummyMatrix
            };

            return(AddDetector(detectorName, dummyName, modelDummy));
        }
        protected static void HandleInteractiveObject(IMyUseObject interactive)
        {
            if (MyFakes.ENABLE_ME_HIGHLIGHT_TEMPORARY_HACK)
            {
                if (interactive is MyFloatingObject)
                {
                    MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                    MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle2;
                }
                else
                {
                    MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                    MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle1;
                }
            }
            else if (MyFakes.ENABLE_USE_NEW_OBJECT_HIGHLIGHT)
            {
                if (!(interactive is MyFloatingObject))
                {
                    bool         found = false;
                    MyModelDummy dummy = interactive.Dummy;
                    if (dummy != null && dummy.CustomData != null)
                    {
                        object data;
                        found = dummy.CustomData.TryGetValue(MyModelDummy.ATTRIBUTE_HIGHLIGHT, out data);
                        string highlightAttribute = data as string;
                        if (found && highlightAttribute != null)
                        {
                            MyHud.SelectedObjectHighlight.HighlightAttribute = highlightAttribute;
                            MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle2;
                        }
                    }

                    if (!found)
                    {
                        MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                        MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle1;
                    }
                }
                else
                {
                    MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                    MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle2;
                }
            }
            else
            {
                MyHud.SelectedObjectHighlight.HighlightAttribute = null;
                MyHud.SelectedObjectHighlight.HighlightStyle     = MyHudObjectHighlightStyle.HighlightStyle1;
            }

            MyHud.SelectedObjectHighlight.Highlight(interactive);
        }
Beispiel #14
0
        public override uint AddDetector(string name, Matrix dummyMatrix)
        {
            var          detectorName = name.ToLower();
            var          dummyName    = "detector_" + detectorName;
            MyModelDummy modelDummy   = new MyModelDummy()
            {
                Name = dummyName, CustomData = null, Matrix = dummyMatrix
            };
            var detector = AddDetector(detectorName, dummyName, modelDummy);

            m_customAddedDetectors.Add(detector);
            return(detector);
        }
Beispiel #15
0
        public override void Init(string displayName, Microsoft.Xna.Framework.Vector3 relativePosition, Microsoft.Xna.Framework.Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {
            m_config = prefabConfig;
            MyPrefabConfigurationKinematicRotating config = (MyPrefabConfigurationKinematicRotating)prefabConfig;

            base.Init(displayName, relativePosition, localOrientation, objectBuilder, prefabConfig);
            Physics.RemoveAllElements();

            // create the box
            MyPhysicsObjects            physobj          = MyPhysics.physicsSystem.GetPhysicsObjects();
            MyRBTriangleMeshElementDesc trianglemeshDesc = physobj.GetRBTriangleMeshElementDesc();

            trianglemeshDesc.SetToDefault();
            trianglemeshDesc.m_Model      = ModelLod0;
            trianglemeshDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(config.MaterialType).PhysicsMaterial;;


            MyRBTriangleMeshElement trEl = (MyRBTriangleMeshElement)physobj.CreateRBElement(trianglemeshDesc);

            this.Physics = new MyPhysicsBody(this, 1.0f, RigidBodyFlag.RBF_RBO_STATIC)
            {
                MaterialType = config.MaterialType
            };
            this.Physics.Enabled        = true;
            this.Physics.CollisionLayer = MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC;
            this.Physics.AddElement(trEl, true);

            MyModel model = MyModels.GetModelOnlyDummies(m_config.ModelLod0Enum);

            foreach (var dummyKVP in model.Dummies)
            {
                if (dummyKVP.Key.StartsWith("Dummy"))
                {
                    MyModelDummy dummy                         = dummyKVP.Value;
                    MyModelsEnum rotatingPartModel             = MyModels.GetModelEnumByAssetName(dummy.CustomData["LINKEDMODEL"].ToString());
                    MyPrefabKinematicRotatingPart rotatingPart = new MyPrefabKinematicRotatingPart(this.GetOwner());
                    rotatingPart.Init(this, rotatingPartModel, config.MaterialType, dummy.Matrix, config.RotatingVelocity, true, config.SoundLooping, config.SoundOpening, config.SoundClosing);
                    m_parts.Add(rotatingPart);
                }
            }

            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_MISSILE, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_ALL, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_MODEL_DEBRIS, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_VOXEL_DEBRIS, true);
            AppCode.Physics.MyPhysics.physicsSystem.GetRigidBodyModule().EnableCollisionInLayers(MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC, MyConstants.COLLISION_LAYER_PREFAB_KINEMATIC_PART, false);

            NeedsUpdate = false;
            EnabledChanged();
            //Enabled = true;
        }
        public MyUseObjectPanelButton(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
        {
            m_buttonPanel = owner as MyButtonPanel;
            m_localMatrix = dummyData.Matrix;

            int orderNumber = 0;
            var parts       = dummyName.Split('_');

            int.TryParse(parts[parts.Length - 1], out orderNumber);
            m_index = orderNumber - 1;
            if (m_index >= m_buttonPanel.BlockDefinition.ButtonCount)
            {
                MyLog.Default.WriteLine(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName));
                Debug.Fail(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName));
                m_index = m_buttonPanel.BlockDefinition.ButtonCount - 1;
            }
        }
        protected void DebugDrawDummies(MyModel model)
        {
            if (model == null)
            {
                return;
            }

            foreach (var dummy in model.Dummies)
            {
                MyModelDummy modelDummy = dummy.Value;

                MatrixD worldMatrix = (MatrixD)modelDummy.Matrix * m_entity.PositionComp.WorldMatrix;
                VRageRender.MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, dummy.Key, Color.White, 0.7f, false);
                VRageRender.MyRenderProxy.DebugDrawAxis(MatrixD.Normalize(worldMatrix), 0.1f, false);
                VRageRender.MyRenderProxy.DebugDrawOBB(worldMatrix, Vector3.One, 1, false, false);
            }
        }
        public MyUseObjectPanelButton(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
            : base(owner, dummyData)
        {
            m_buttonPanel = owner as MyButtonPanel;
            m_localMatrix = dummyData.Matrix;

            int orderNumber = 0;
            var parts =  dummyName.Split('_');
            int.TryParse(parts[parts.Length - 1], out orderNumber);
            m_index = orderNumber - 1;
            if (m_index >= m_buttonPanel.BlockDefinition.ButtonCount)
            {
                MyLog.Default.WriteLine(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName));
                Debug.Fail(string.Format("{0} Button index higher than defined count.", m_buttonPanel.BlockDefinition.Id.SubtypeName));
                m_index = m_buttonPanel.BlockDefinition.ButtonCount - 1;
            }
        }
        public static bool GetSubpartFromDummy(string modelPath, string dummyName, MyModelDummy dummy, ref Data outData)
        {
            if (!dummyName.Contains(MyModelDummy.SUBPART_PREFIX))
                return false;

            Debug.Assert(dummyName.Substring(0, MyModelDummy.SUBPART_PREFIX.Length).Equals(MyModelDummy.SUBPART_PREFIX), string.Format("Subpart name should start with prefix '{0}'", MyModelDummy.SUBPART_PREFIX));
            Debug.Assert(dummy.CustomData.ContainsKey(MyModelDummy.ATTRIBUTE_FILE), "Subpart dummy must have 'file' attribute specified.");

            string subpartPath = Path.Combine(Path.GetDirectoryName(modelPath), (string)dummy.CustomData[MyModelDummy.ATTRIBUTE_FILE]);
            subpartPath += ".mwm"; // Temporary fix
            outData = new Data()
            {
                Name = dummyName.Substring(MyModelDummy.SUBPART_PREFIX.Length),
                File = subpartPath,
                InitialTransform = Matrix.Normalize(dummy.Matrix)
            };
            return true;
        }
        private int AddDetector(string detectorName, string dummyName, MyModelDummy dummyData)
        {
            List <Matrix> matrices;

            if (!m_detectors.TryGetValue(detectorName, out matrices))
            {
                matrices = new List <Matrix>();
                m_detectors[detectorName] = matrices;
            }
            matrices.Add(Matrix.Invert(dummyData.Matrix));

            var shapeKey          = m_detectorInteractiveObjects.Count;
            var interactiveObject = CreateInteractiveObject(detectorName, dummyName, dummyData, shapeKey);

            if (interactiveObject != null)
            {
                m_detectorInteractiveObjects.Add(shapeKey, new DetectorData(interactiveObject, dummyData.Matrix));
            }

            return(shapeKey);
        }
Beispiel #21
0
        public static bool GetSubpartFromDummy(string modelPath, string dummyName, MyModelDummy dummy, ref Data outData)
        {
            if (!dummyName.Contains(MyModelDummy.SUBPART_PREFIX))
            {
                return(false);
            }

            Debug.Assert(dummyName.Substring(0, MyModelDummy.SUBPART_PREFIX.Length).Equals(MyModelDummy.SUBPART_PREFIX), string.Format("Subpart name should start with prefix '{0}'", MyModelDummy.SUBPART_PREFIX));
            Debug.Assert(dummy.CustomData.ContainsKey(MyModelDummy.ATTRIBUTE_FILE), "Subpart dummy must have 'file' attribute specified.");

            string subpartPath = Path.Combine(Path.GetDirectoryName(modelPath), (string)dummy.CustomData[MyModelDummy.ATTRIBUTE_FILE]);

            subpartPath += ".mwm"; // Temporary fix
            outData      = new Data()
            {
                Name             = dummyName.Substring(MyModelDummy.SUBPART_PREFIX.Length),
                File             = subpartPath,
                InitialTransform = Matrix.Normalize(dummy.Matrix)
            };
            return(true);
        }
Beispiel #22
0
        public override uint AddDetector(string name, Matrix dummyMatrix)
        {
            MyModelDummy dummy;
            string       detectorName = name.ToLower();
            string       key          = "detector_" + detectorName;
            MyModel      model        = base.Container.Entity.Render.GetModel();
            Dictionary <string, object> customData = null;

            if ((model != null) && model.Dummies.TryGetValue(key, out dummy))
            {
                customData = dummy.CustomData;
            }
            MyModelDummy dummyData = new MyModelDummy();

            dummyData.Name       = key;
            dummyData.CustomData = customData;
            dummyData.Matrix     = dummyMatrix;
            uint item = this.AddDetector(detectorName, key, dummyData);

            this.m_customAddedDetectors.Add(item);
            return(item);
        }
 public MyCubeBlockParticleEffect(CubeBlockEffect effectData, MyEntity entity)
 {
     MyParticlesLibrary.GetParticleEffectsID(effectData.Name, out m_particleId);
     if (m_particleId == -1)
     {
         m_canBeDeleted = true;
     }
     else
     {
         m_loop         = effectData.Loop;
         m_delay        = effectData.Delay;
         m_spawnTimeMin = Math.Max(0f, effectData.SpawnTimeMin);
         m_spawnTimeMax = Math.Max(m_spawnTimeMin, effectData.SpawnTimeMax);
         m_timer        = m_delay;
         m_entity       = entity;
         m_originPoint  = GetEffectOrigin(effectData.Origin);
         m_duration     = effectData.Duration;
         if (m_spawnTimeMax > 0f)
         {
             m_timer += MyUtils.GetRandomFloat(m_spawnTimeMin, m_spawnTimeMax);
         }
     }
 }
Beispiel #24
0
        public override uint AddDetector(string name, Matrix dummyMatrix)
        {
            var detectorName = name.ToLower();
            var dummyName    = "detector_" + detectorName;

            // Try to assign CustomData from existing same name model dummy
            MyModel      model = Container.Entity.Render.GetModel();
            MyModelDummy dummy;
            Dictionary <string, object> customData = null;

            if (model != null && model.Dummies.TryGetValue(dummyName, out dummy))
            {
                customData = dummy.CustomData;
            }

            MyModelDummy modelDummy = new MyModelDummy()
            {
                Name = dummyName, CustomData = customData, Matrix = dummyMatrix
            };
            var detector = AddDetector(detectorName, dummyName, modelDummy);

            m_customAddedDetectors.Add(detector);
            return(detector);
        }
 public MyUseObjectDoorTerminal(IMyEntity owner, string dummyName, MyModelDummy dummyData, int key)
 {
     Door        = (MyDoor)owner;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectTerminal(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Block = owner as MyCubeBlock;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectAdvancedDoorTerminal(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Door = (MyAdvancedDoor)owner;
     LocalMatrix = dummyData.Matrix;
 }
Beispiel #28
0
 public MyUseObjectAirtightDoors(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Door        = (MyAirtightDoorGeneric)owner;
     LocalMatrix = dummyData.Matrix;
 }
 public MyCubeBlockParticleEffect(CubeBlockEffect effectData, MyEntity entity)
 {
     MyParticlesLibrary.GetParticleEffectsID(effectData.Name, out m_particleId);
     if (m_particleId == -1)
         m_canBeDeleted = true;
     else
     {
         m_loop = effectData.Loop;
         m_delay = effectData.Delay;
         m_spawnTimeMin = Math.Max(0f, effectData.SpawnTimeMin);
         m_spawnTimeMax = Math.Max(m_spawnTimeMin, effectData.SpawnTimeMax);
         m_timer = m_delay;
         m_entity = entity;
         m_originPoint = GetEffectOrigin(effectData.Origin);
         m_duration = effectData.Duration;
         if (m_spawnTimeMax > 0f)
             m_timer += MyUtils.GetRandomFloat(m_spawnTimeMin, m_spawnTimeMax);
     }
 }
Beispiel #30
0
        /// <summary>
        /// ReadDummies
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static Dictionary<string, MyModelDummy> ReadDummies(BinaryReader reader)
        {
            var dummies = new Dictionary<string, MyModelDummy>();

            var nCount = reader.ReadInt32();
            for (var i = 0; i < nCount; ++i)
            {
                var str = reader.ReadString();
                var mat = ReadMatrix(reader);

                var dummy = new MyModelDummy { Matrix = mat, CustomData = new Dictionary<string, object>() };

                var customDataCount = reader.ReadInt32();
                for (var j = 0; j < customDataCount; ++j)
                {
                    var name = reader.ReadString();
                    var value = reader.ReadString();
                    dummy.CustomData.Add(name, value);
                }

                dummies.Add(str, dummy);
            }

            return dummies;
        }
Beispiel #31
0
        /// <summary>
        /// Returns subblock data from dummy, subblock matrix can be offset (according to useOffset parameter) so the dummy position output is also provided.
        /// </summary>
        /// <returns>true when dummy is subblock otherwise false</returns>
        public static bool GetSubBlockDataFromDummy(MyCubeBlockDefinition ownerBlockDefinition, string dummyName, MyModelDummy dummy, bool useOffset, out MyCubeBlockDefinition subBlockDefinition,
                                                    out MatrixD subBlockMatrix, out Vector3 dummyPosition)
        {
            subBlockDefinition = null;
            subBlockMatrix     = MatrixD.Identity;
            dummyPosition      = Vector3.Zero;

            if (!dummyName.ToLower().StartsWith(MyCubeBlock.DUMMY_SUBBLOCK_ID))
            {
                return(false);
            }

            if (ownerBlockDefinition.SubBlockDefinitions == null)
            {
                return(false);
            }

            string dummyNameShort = dummyName.Substring(MyCubeBlock.DUMMY_SUBBLOCK_ID.Length);

            MyDefinitionId definitiondId;

            if (!ownerBlockDefinition.SubBlockDefinitions.TryGetValue(dummyNameShort, out definitiondId))
            {
                Debug.Assert(false, "SubBlock definition not found!");
                return(false);
            }

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(definitiondId, out subBlockDefinition);
            if (subBlockDefinition == null)
            {
                Debug.Assert(false, "SubBlock definition not found!");
                return(false);
            }

            const double dotEpsilon = 0.00000001;

            subBlockMatrix = MatrixD.Normalize(dummy.Matrix);
            Vector3I forward    = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Forward));
            double   forwardDot = Vector3D.Dot(subBlockMatrix.Forward, (Vector3D)forward);

            if (Math.Abs(1 - forwardDot) <= dotEpsilon)
            {
                subBlockMatrix.Forward = forward;
            }

            Vector3I right    = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Right));
            double   rightDot = Vector3D.Dot(subBlockMatrix.Right, (Vector3D)right);

            if (Math.Abs(1 - rightDot) <= dotEpsilon)
            {
                subBlockMatrix.Right = right;
            }

            Vector3I up    = Base6Directions.GetIntVector(Base6Directions.GetClosestDirection(subBlockMatrix.Up));
            double   upDot = Vector3D.Dot(subBlockMatrix.Up, (Vector3D)up);

            if (Math.Abs(1 - upDot) <= dotEpsilon)
            {
                subBlockMatrix.Up = up;
            }

            dummyPosition = subBlockMatrix.Translation;
            if (useOffset)
            {
                Vector3 offset = MyCubeBlock.GetBlockGridOffset(subBlockDefinition);
                subBlockMatrix.Translation -= Vector3D.TransformNormal(offset, subBlockMatrix);
            }

            return(true);
        }
        public static IMyUseObject CreateUseObject(string detectorName, IMyEntity owner, string dummyName, MyModelDummy dummyData, uint shapeKey)
        {
            Type type;
            if (!m_useObjectTypesByDummyName.TryGetValue(detectorName, out type) || type == null)
                return null;

            return (IMyUseObject)Activator.CreateInstance(type, owner, dummyName, dummyData, shapeKey);
        }
Beispiel #33
0
        public static IMyUseObject CreateUseObject(string detectorName, IMyEntity owner, string dummyName, MyModelDummy dummyData, uint shapeKey)
        {
            Type type;

            if (!m_useObjectTypesByDummyName.TryGetValue(detectorName, out type) || type == null)
            {
                return(null);
            }

            return((IMyUseObject)Activator.CreateInstance(type, owner, dummyName, dummyData, shapeKey));
        }
 public MyUseObjectCockpitDoor(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Cockpit     = owner;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectTextPanel(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     m_textPanel = (MyTextPanel)owner;
     m_localMatrix = dummyData.Matrix;
 }
Beispiel #36
0
 private IMyUseObject CreateInteractiveObject(string detectorName, string dummyName, MyModelDummy dummyData, uint shapeKey)
 {
     if (!(base.Container.Entity is MyDoor) || (detectorName != "terminal"))
     {
         return(MyUseObjectFactory.CreateUseObject(detectorName, base.Container.Entity, dummyName, dummyData, shapeKey));
     }
     return(new MyUseObjectDoorTerminal(base.Container.Entity, dummyName, dummyData, shapeKey));
 }
Beispiel #37
0
 public MyUseObjectInventory(IMyEntity owner, string dummyName, MyModelDummy dummyData, int key)
 {
     Block       = owner as MyCubeBlock;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectInventory(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Entity      = owner as MyEntity;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectBase(IMyEntity owner, MyModelDummy dummy)
 {
     Owner = owner;
     Dummy = dummy;
 }
Beispiel #40
0
 public MyUseObjectTextPanel(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     m_textPanel   = (MyTextPanel)owner;
     m_localMatrix = dummyData.Matrix;
 }
 public MyUseObjectInventory(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Entity = owner as MyEntity;
     LocalMatrix = dummyData.Matrix;
 }
Beispiel #42
0
        private IMyUseObject CreateInteractiveObject(string detectorName, string dummyName, MyModelDummy dummyData, uint shapeKey)
        {
            // temporary hack until dummy for door terminal is renamed
            if (Container.Entity is MyDoor && detectorName == "terminal")
            {
                return(new MyUseObjectDoorTerminal(Container.Entity, dummyName, dummyData, shapeKey));
            }

            return(MyUseObjectFactory.CreateUseObject(detectorName, Container.Entity, dummyName, dummyData, shapeKey));
        }
 public MyUseObjectMedicalRoom(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     m_medicalRoom = (MyMedicalRoom)owner;
     m_localMatrix = dummyData.Matrix;
 }
 public MyUseObjectAirtightDoors(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Door = (MyAirtightDoorGeneric)owner;
     LocalMatrix = dummyData.Matrix;
 }
 public MyUseObjectCockpitDoor(IMyEntity owner, string dummyName, MyModelDummy dummyData, uint key)
     : base(owner, dummyData)
 {
     Cockpit = owner;
     LocalMatrix = dummyData.Matrix;
 }