예제 #1
0
        public virtual void OnOkClick(MyGuiControlButton sender)
        {
            if (HasEntity())
            {
                if (m_idTextbox != null)
                {
                    if (m_entity.EntityId != null)
                    {
                        var newId = new MyEntityIdentifier(Convert.ToUInt32(m_idTextbox.Text));

                        if (newId.NumericValue != m_entity.EntityId.Value.NumericValue && !MyEntityIdentifier.ExistsById(newId))
                        {
                            MyEntityIdentifier.RemoveEntity(m_entity.EntityId.Value);
                            m_entity.EntityId = newId;
                            MyEntityIdentifier.AddEntityWithId(m_entity);
                        }
                    }
                }

                if (IsPositionInput())
                {
                    Vector3 position = GetNewPosition();
                    if (IsValidPositionInput(position))
                    {
                        MyEditorGizmo.MoveAndRotateObject(position, m_entity.GetWorldRotation(), m_entity);
                    }
                }
            }
        }
예제 #2
0
        public override void Close()
        {
            ((IMyGameLogicComponent)this.GameLogic).Close();
            MyHierarchyComponent <MyEntity> hierarchy = this.m_entity.Hierarchy;

            while (true)
            {
                if (hierarchy != null)
                {
                    ListReader <MyHierarchyComponentBase> children = hierarchy.Children;
                    if (children.Count > 0)
                    {
                        MyHierarchyComponentBase childHierarchy = hierarchy.Children[hierarchy.Children.Count - 1];
                        childHierarchy.Container.Entity.Close();
                        hierarchy.RemoveByJN(childHierarchy);
                        continue;
                    }
                }
                this.CallAndClearOnClosing();
                MyEntities.RemoveName(this.m_entity);
                MyEntities.RemoveFromClosedEntities(this.m_entity);
                if (this.m_entity.Physics != null)
                {
                    this.m_entity.Physics.Close();
                    this.m_entity.Physics = null;
                    this.m_entity.RaisePhysicsChanged();
                }
                MyEntities.UnregisterForUpdate(this.m_entity, true);
                MyEntities.UnregisterForDraw(this.m_entity);
                if ((hierarchy == null) || (hierarchy.Parent == null))
                {
                    MyEntities.Remove(this.m_entity);
                }
                else
                {
                    this.m_entity.Parent.Hierarchy.RemoveByJN(hierarchy);
                    if (this.m_entity.Parent.InScene)
                    {
                        this.m_entity.OnRemovedFromScene(this.m_entity);
                    }
                    MyEntities.RaiseEntityRemove(this.m_entity);
                }
                if (this.m_entity.EntityId != 0)
                {
                    MyEntityIdentifier.RemoveEntity(this.m_entity.EntityId);
                }
                this.CallAndClearOnClose();
                base.Closed = true;
                return;
            }
        }
예제 #3
0
        public override void Close()
        {
            GameLogic.Close();
            //doesnt work in parallel update
            //Debug.Assert(MySandboxGame.IsMainThread(), "Entity.Close() called not from Main Thread!");
            Debug.Assert(MyEntities.UpdateInProgress == false, "Do not close entities directly in Update*, use MarkForClose() instead");
            Debug.Assert(MyEntities.CloseAllowed == true, "Use MarkForClose()");
            //Debug.Assert(!Closed, "Close() called twice!");

            //Children has to be cleared after close notification is send
            while (m_entity.Hierarchy.Children.Count > 0)
            {
                MyHierarchyComponentBase compToRemove = m_entity.Hierarchy.Children[m_entity.Hierarchy.Children.Count - 1];
                Debug.Assert(compToRemove.Parent != null, "Entity has no parent but is part of children collection");

                compToRemove.Container.Entity.Close();

                m_entity.Hierarchy.Children.Remove(compToRemove);
            }

            //OnPositionChanged = null;

            CallAndClearOnClosing();

            MyEntities.RemoveName(m_entity);
            MyEntities.RemoveFromClosedEntities(m_entity);

            if (m_entity.Physics != null)
            {
                m_entity.Physics.Close();
                m_entity.Physics = null;

                m_entity.RaisePhysicsChanged();
            }

            MyEntities.UnregisterForUpdate(m_entity, true);


            if (m_entity.Hierarchy.Parent == null) //only root objects are in entities list
            {
                MyEntities.Remove(m_entity);
            }
            else
            {
                m_entity.Parent.Hierarchy.Children.Remove(m_entity.Hierarchy);

                //remove children first
                if (m_entity.Parent.InScene)
                {
                    m_entity.OnRemovedFromScene(m_entity);
                }

                MyEntities.RaiseEntityRemove(m_entity);
            }

            if (m_entity.EntityId != 0)
            {
                MyEntityIdentifier.RemoveEntity(m_entity.EntityId);
            }

            //this.EntityId = 0;
            Debug.Assert(m_entity.Hierarchy.Children.Count == 0);

            CallAndClearOnClose();

            Closed = true;
        }
예제 #4
0
        public virtual void Start(Vector3 position, Vector3 initialVelocity, Vector3 direction, float impulseMultiplier, MyEntity owner, StringBuilder displayName = null)
        {
            System.Diagnostics.Debug.Assert(Closed);
            Closed = false;
            GuidedInMultiplayer = false;

            if (this.EntityId.HasValue)
            {
                MyEntityIdentifier.RemoveEntity(this.EntityId.Value);
                this.EntityId = null;
            }

            if (this.NeedsId)
            {
                //if(owner.EntityId.HasValue) this.EntityId = MyEntityIdentifier.AllocateId(owner.EntityId.Value.PlayerId);
                //else this.EntityId = MyEntityIdentifier.AllocateId();
                this.EntityId = MyEntityIdentifier.AllocateId();
                MyEntityIdentifier.AddEntityWithId(this);
            }

            if (displayName != null && owner == MySession.PlayerShip)
            {
                DisplayName = displayName.ToString();
                MyHud.AddText(this, displayName, maxDistance: 1000);
            }

            m_isExploded            = false;
            m_cascadeExplosionLevel = 0;
            m_origin           = position;
            m_previousPosition = position;
            m_initialVelocity  = initialVelocity;

            System.Diagnostics.Debug.Assert(owner.EntityId.HasValue, "Shooting entity must have ID");

            m_ownerEntityID      = owner.EntityId.Value;
            m_elapsedMiliseconds = 0;



            Matrix ammoWorld = Matrix.CreateWorld(position, direction, owner.WorldMatrix.Up);

            SetWorldMatrix(ammoWorld);

            this.Physics.Clear();
            this.Physics.Enabled        = true;
            this.Physics.LinearVelocity = initialVelocity;

            if (owner.Physics != null)
            {
                this.Physics.GroupMask = owner.Physics.GroupMask;
            }
            else
            {
                this.Physics.GroupMask = MyGroupMask.Empty;
            }

            //this.Physics.Enabled = true;

            this.Physics.ApplyImpulse(direction * this.Physics.Mass * impulseMultiplier, position);

            MyEntities.Add(this);
            NeedsUpdate = true;
        }
예제 #5
0
        // Player is in sector, everything loaded, can process messages
        public void Start()
        {
            if (MyFakes.MULTIPLAYER_DISABLED)
            {
                return;
            }

            Debug.Assert(MyGuiScreenGamePlay.Static != null);
            Debug.Assert(!IsRunning);

            if (IsEditor())
            {
                return;
            }

            MyMwcLog.WriteLine("MyMultiplayerGameplay.Start - START");
            MyMwcLog.IncreaseIndent();

            m_lastPlayerId = 0;

            m_lastConfig         = null;
            m_lastAmmoAssignment = null;
            m_lastCamera         = MyCameraAttachedToEnum.PlayerMinerShip;

            IsRunning = true;


            if (IsSandBox())
            {
                // Everybody is enemy to every other faction
                var values = Enum.GetValues(typeof(MyMwcObjectBuilder_FactionEnum));
                foreach (MyMwcObjectBuilder_FactionEnum f1 in values)
                {
                    foreach (MyMwcObjectBuilder_FactionEnum f2 in values)
                    {
                        // Traders are neutral to all
                        if (f1 == MyMwcObjectBuilder_FactionEnum.Traders || f2 == MyMwcObjectBuilder_FactionEnum.Traders)
                        {
                            MyFactions.SetFactionStatus(f1, f2, MyFactions.RELATION_NEUTRAL, false);
                        }
                        else if (f1 != f2 && f1 != MyMwcObjectBuilder_FactionEnum.None)
                        {
                            MyFactions.SetFactionStatus(f1, f2, MyFactions.RELATION_WORST, false);
                        }
                    }
                }

                // Freelancers are enemies to self, it allows classic deathmatch
                MyFactions.SetFactionStatus(MyMwcObjectBuilder_FactionEnum.Freelancers, MyMwcObjectBuilder_FactionEnum.Freelancers, MyFactions.RELATION_WORST, false);
            }

            if (IsHost)
            {
                MyEntityIdentifier.CurrentPlayerId = GeneratePlayerId();

                // Make playership proper id
                MyEntityIdentifier.RemoveEntity(MySession.PlayerShip.EntityId.Value);
                MySession.PlayerShip.EntityId = MyEntityIdentifier.AllocatePlayershipId();
                MyEntityIdentifier.AddEntityWithId(MySession.PlayerShip);

                NewPlayer += MyMultiplayerGameplay_NewPlayer;
            }


            MyClientServer.LoggedPlayer.Statistics = new MyPlayerStatistics();
            Peers.PlayerDisconnected += Peers_PlayerDisconnected;

            Resume();


            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMultiplayerGameplay.Start - END");
        }
        void OnShoot(ref MyEventShoot msg)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Shoot");
            MyEntity parent;

            if (MyEntities.TryGetEntityById(new MyEntityIdentifier(msg.ShooterEntityId), out parent))
            {
                if (parent is MySmallShip)
                {
                    var ship = (MySmallShip)parent;
                    ship.InitGroupMaskIfNeeded();
                    ship.WorldMatrix = msg.Position.GetMatrix();
                    if (msg.TargetEntityId.HasValue)
                    {
                        ship.TargetEntity = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                    }
                    var msgWeapon = msg.Weapon;
                    var weapon    = GetWeapon(ship, msgWeapon);
                    if (weapon == null)
                    {
                        weapon = ship.Weapons.AddWeapon(new MyMwcObjectBuilder_SmallShip_Weapon(msg.Weapon));
                    }
                    Debug.Assert(weapon.Parent != null, "Weapon parent is null, something is wrong");
                    weapon.IsDummy = true;
                    weapon.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && weapon.LastShotId.HasValue && MyEntities.TryGetEntityById(weapon.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(weapon.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
                else if (parent is MyPrefabLargeWeapon)
                {
                    var gun = ((MyPrefabLargeWeapon)parent).GetGun();
                    if (msg.TargetEntityId.HasValue)
                    {
                        var target = MyEntityIdentifier.GetEntityByIdOrNull(new MyEntityIdentifier(msg.TargetEntityId.Value));
                        gun.SetTarget(target);
                    }

                    gun.GetBarell().IsDummy = true;
                    gun.RotateImmediately(gun.GetPosition() + msg.Position.GetMatrix().Forward * 5000);
                    gun.IsDummy = true;
                    gun.Shot(new MyMwcObjectBuilder_SmallShip_Ammo(msg.Ammo));
                    MyEntity projectile;
                    if (msg.ProjectileEntityId.HasValue && gun.LastShotId.HasValue && MyEntities.TryGetEntityById(gun.LastShotId.Value, out projectile))
                    {
                        MyEntityIdentifier.RemoveEntity(gun.LastShotId.Value);
                        projectile.EntityId = new MyEntityIdentifier(msg.ProjectileEntityId.Value);
                        if (!MyEntityIdentifier.ExistsById(projectile.EntityId.Value))
                        {
                            MyEntityIdentifier.AddEntityWithId(projectile);
                        }
                    }
                }
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }