Пример #1
0
            public void OnGridsCreated(ParallelTasks.WorkData workData)
            {
                foreach (var entity in m_resultIDs)
                {
                    VRage.ModAPI.IMyEntity foundEntity;
                    MyEntityIdentifier.TryGetEntity(entity.EntityId, out foundEntity);
                    if (foundEntity == null)
                    {
                        MyEntityIdentifier.AddEntityWithId(entity);
                    }
                    else
                    {
                        Debug.Fail("Two threads added the same entity");
                    }
                }
                foreach (var grid in m_results)
                {
                    MyEntities.Add(grid);
                    grid.IsReadyForReplication = true;
                }

                while (m_callbacks.Count > 0)
                {
                    var callback = m_callbacks.Pop();
                    if (callback != null)
                    {
                        callback();
                    }
                }
            }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
0
        public override void Start(Vector3 position, Vector3 initialVelocity, Vector3 direction, float impulseMultiplier, MyEntity owner)
        {
            base.Start(position, initialVelocity, direction, impulseMultiplier, owner, MyTextsWrapper.Get(MyTextsWrapperEnum.MineSmartHud));

            EntityId = MyEntityIdentifier.AllocateId();
            MyEntityIdentifier.AddEntityWithId(this);

            m_currentTarget             = null;
            m_movingCue                 = null;
            m_lastTimeSearchedForTarget = MyConstants.FAREST_TIME_IN_PAST;
            Faction             = owner.Faction;
            GuidedInMultiplayer = true;
        }
Пример #4
0
 private void OnWorkCompleted()
 {
     if (MySession.Static.Ready)
     {
         MyEntityIdentifier.InEntityCreationBlock = true;
         foreach (DebrisData data in this.m_pieces)
         {
             MyEntityIdentifier.AddEntityWithId(data.Object);
             data.Object.Debris.Start(data.StartPos, data.InitialVelocity);
         }
         MyEntityIdentifier.InEntityCreationBlock = false;
         this.Release();
     }
 }
Пример #5
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;
        }
Пример #6
0
        //  Every child of this base class must implement Shot() method, which shots projectile or missile.
        //  Method returns true if something was shot. False if not (because interval between two shots didn't pass)
        public override bool Shot(MyMwcObjectBuilder_SmallShip_Ammo usedAmmo)
        {
            LastShotId = null;
            float missileLauncherShotInterval = float.MaxValue;

            switch (usedAmmo.AmmoType)
            {
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_EMP:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection:
                missileLauncherShotInterval = MyGuidedMissileConstants.MISSILE_LAUNCHER_SHOT_INTERVAL_IN_MILISECONDS;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileLauncherShotInterval && !IsDummy)
            {
                return(false);
            }

            //  Throw ship backward (by deviated vector)
            this.Parent.Physics.AddForce(MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE,
                                         MyUtilRandomVector3ByDeviatingVector.GetRandom(Vector3.Backward, MathHelper.ToRadians(5)) * MyMwcUtils.GetRandomFloat(40000, 50000), null, null);

            //  Play missile launch cue (one-time)
            AddWeaponCue(MySoundCuesEnum.WepMissileLaunch3d);

            Vector3 forwardVelocity = MyMath.ForwardVectorProjection(this.WorldMatrix.Forward, GetParentMinerShip().Physics.LinearVelocity);


            //  Create and fire missile - but deviate missile direction be random angle
            Vector3 deviatedVector = GetDeviatedVector(MinerWars.AppCode.Game.Gameplay.MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType));

            // correct missile start position if it would intersect some entity
            Vector3 missileStartPosition = m_positionMuzzleInWorldSpace;

            missileStartPosition = CorrectPosition(missileStartPosition, deviatedVector, Parent);

            if (MinerWars.AppCode.Game.Managers.Session.MySession.Static.Is2DSector)
            {
                forwardVelocity.Y = 0;
                deviatedVector.Y  = 0;
            }

            var missile = MyMissiles.Add(usedAmmo.AmmoType, missileStartPosition, forwardVelocity, deviatedVector, LocalMatrix.Translation, Parent, ((MySmallShip)Parent).TargetEntity, isDummy: this.IsDummy);

            if (missile != null)
            {
                missile.EntityId = MyEntityIdentifier.AllocateId();
                MyEntityIdentifier.AddEntityWithId(missile);
                LastShotId = missile.EntityId;
                GetParentMinerShip().LastMissileFired = missile;
            }
            //MyUtilRandomVector3ByDeviatingVector.GetRandom(WorldMatrix.Forward

            m_lastTimeShoot     = MyMinerGame.TotalGamePlayTimeInMilliseconds;
            m_lastSmokePosition = GetSmokePosition();

            if (SysUtils.MyMwcFinalBuildConstants.ENABLE_TRAILER_SAVE)
            {
                MinerWars.AppCode.Game.Trailer.MyTrailerSave.UpdateGunShot(this.Parent, Trailer.MyTrailerGunsShotTypeEnum.MISSILE);
            }

            //  We shot one missile
            return(true);
        }
Пример #7
0
        public override bool StartShooting()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyLargeShipMissileLauncherBarrel::StartShooting");

            LastShotId = null;

            int missileShotInterval = 0;

            MyLargeShipGunBase.GetMissileAmmoParams(GetAmmoType(), ref missileShotInterval);
            if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_lastTimeShoot) < missileShotInterval)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                return(false);
            }

            m_burstFinish = false;
            while (!m_burstFinish)
            {
                if (!base.StartShooting())
                {
                    MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
                    return(false);
                }

                if (m_groupMask == null)
                {
                    MyPhysics.physicsSystem.GetRigidBodyModule().GetGroupMaskManager().GetGroupMask(ref m_groupMask);
                }

                MyEntity target = ((MyLargeShipGunBase)Parent).GetTarget();

                List <MyModelDummy> muzzles = GetMuzzleFlashMatrix();
                m_activeMuzzle = --m_burstToFire;

                Matrix  worldMatrix         = WorldMatrix;
                Vector3 muzzleFlashPosition = MyUtils.GetTransform(muzzles[m_activeMuzzle].Matrix.Translation, ref worldMatrix);


                if (IsControlledByPlayer())
                {
                    //target = MySession.PlayerShip.TargetEntity as MySmallShip;
                    target = MyEnemyTargeting.SwitchNextTarget(true);
                }

                if (target != null || IsControlledByPlayer())
                {
                    MySoundCue?shootingSound = GetWeaponBase().UnifiedWeaponCueGet(MySoundCuesEnum.WepMissileLaunch3d);
                    if (shootingSound == null || !shootingSound.Value.IsPlaying)
                    {
                        GetWeaponBase().UnifiedWeaponCueSet(Audio.MySoundCuesEnum.WepMissileLaunch3d,
                                                            MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero));
                        //MyAudio.AddCue2dOr3d(this.GetWeaponBase().PrefabParent, Audio.MySoundCuesEnum.WepMissileLaunch3d, muzzleFlashPosition, WorldMatrix.Forward, WorldMatrix.Up, Vector3.Zero);
                    }

                    Vector3 deviateVector = GetDeviatedVector(MyAmmoConstants.GetAmmoProperties(GetAmmoType()));

                    var missile = MyMissiles.Add(GetAmmoType(), muzzleFlashPosition + 2 * WorldMatrix.Forward, WorldMatrix.Forward * 2.0f, deviateVector, Vector3.Zero, this, target, SearchingDistance, isLightWeight: true);
                    if (missile.GuidedInMultiplayer)
                    {
                        missile.EntityId = MyEntityIdentifier.AllocateId();
                        MyEntityIdentifier.AddEntityWithId(missile);
                        LastShotId = missile.EntityId;
                    }
                }


                if (m_burstToFire <= 0)
                {
                    m_burstFireTime_ms = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    m_burstToFire      = m_burstFireCount;
                    m_burstFinish      = true;
                }
                if ((MyMinerGame.TotalGamePlayTimeInMilliseconds - m_burstFireTime_ms) > m_burstFireTimeLoadingIntervalConst_ms)
                {
                    m_burstFinish = false;
                }

                if (!IsControlledByPlayer())
                {
                    m_burstFinish = true;
                }
            }

            m_lastTimeShoot = MyMinerGame.TotalGamePlayTimeInMilliseconds;

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

            return(true);
        }
Пример #8
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();
        }