Exemple #1
0
 public void SetHealth(int n)
 {
     if (Camera.Target != null)
     {
         ShipObj Ship  = (ShipObj)Camera.Target;
         float   ratio = Ship.ArmorLeft(n);
         NoseHealth.HealthRatio   = ratio;
         CoreHealth.HealthRatio   = ratio;
         EngineHealth.HealthRatio = ratio;
     }
 }
 protected void _receiver_OnReceivedData(ShipObj data)
 {
     lock (_tracksData)
     {
         var target = new HZGPSTarget();
         target.MMSI = data.MMSI;
         target.Update(data.Lon, data.Lat, data.SOG, data.COG, DateTime.Now);
         target.Name         = data.Name;
         target.ReceiverTime = data.Time;
         _tracksData.UpdateDynamicEvent(target);
     }
 }
Exemple #3
0
        public void HandleData(NetIncomingMessage msg)
        {
            NetMsgType datatype = (NetMsgType)msg.ReadByte();

            if (datatype == NetMsgType.Control)
            {
                Soul soul = (Soul)msg.SenderConnection.Tag;
                var  key  = (ControlKey)msg.ReadByte();
                var  edge = msg.ReadBoolean();
                //Console.WriteLine("Received Control Message: " + key + (edge ? "Pressed" : "Released"));
                soul.currentShip.Controls.ReceiveMessage(key, edge);
            }
            else if (datatype == NetMsgType.ControlUpdate)
            {
                Soul soul  = (Soul)msg.SenderConnection.Tag;
                var  Pitch = msg.ReadFloat();
                var  Yaw   = msg.ReadFloat();
                var  Roll  = msg.ReadFloat();
                soul.currentShip.Controls.ReceiveMessage(Pitch, Yaw, Roll);
            }
            else if (datatype == NetMsgType.ShipDataOutput)
            {
                ShipDataOutputMessage data;
                data = new ShipDataOutputMessage(msg);
                Soul soul = new Soul(msg.SenderConnection);
                soul.currentSector       = Sector.Redria;
                msg.SenderConnection.Tag = soul;

                soul.currentSector.Terrain.Load(msg.SenderConnection);
                soul.currentSector.Ships.Load(msg.SenderConnection);
                soul.currentSector.Objects.Load(msg.SenderConnection);
                var idRandomizer = new Random();

                var NewShip = new ShipObj(new Vector3(0, 100, 2), Quaternion.Identity,
                                          data.GeneratedData);
                soul.currentShip = NewShip;
                NewShip.Client   = soul;
                //Console.WriteLine(msg.SenderEndpoint.Address + "'s Ship ID: " + NewShip.ID);
                foreach (NetConnection c in Network.Server.Connections)
                {
                    MessageWriter.ClientEntityCreationMessage(c,
                                                              NewShip.ID, NewShip.Position, NewShip.Orientation,
                                                              data.GeneratedData.NoseID, data.GeneratedData.CoreID, data.GeneratedData.EngineID,
                                                              data.Weapons, msg.SenderConnection.RemoteUniqueIdentifier);
                }
            }
        }
Exemple #4
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse)
        {
            Viewport viewport       = MobileFortressClient.Game.GraphicsDevice.Viewport;
            ShipObj  Ship           = (ShipObj)Camera.Target;
            Vector3  Crosshair      = Ship.Entity.WorldTransform.Forward * 70;
            Vector3  ScreenLocation = viewport.Project(Crosshair, Camera.Projection, Camera.View, Matrix.CreateTranslation(Ship.Entity.WorldTransform.Translation));

            RCrosshairs.Location = new Point((int)ScreenLocation.X - Crosshairs.Width / 2, (int)ScreenLocation.Y - Crosshairs.Height / 2);

            Crosshair             = Ship.Entity.WorldTransform.Forward * 35;
            ScreenLocation        = viewport.Project(Crosshair, Camera.Projection, Camera.View, Matrix.CreateTranslation(Ship.Entity.WorldTransform.Translation));
            RCrosshairs2.Location = new Point((int)ScreenLocation.X - Crosshairs.Width / 4, (int)ScreenLocation.Y - Crosshairs.Height / 4);

            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (LockStatus == LockonStatus.Locking)
            {
                lockTime += dt;
                if (lockTime >= 0.2f)
                {
                    lockTime = 0f;
                    Resources.Sounds.LockingOn.Play();
                }
            }
            if (enemyLock)
            {
                enemyLockTime += dt;
                if (enemyLockTime >= Resources.Sounds.EnemyLockon.Duration.TotalSeconds * 1.2f)
                {
                    enemyLockTime = 0f;
                    Resources.Sounds.EnemyLockon.Play();
                }
            }

            FrameCounter.Update(gameTime);
            Manager.Update(gameTime, mouse);
        }
Exemple #5
0
 public void Remove(ShipObj obj)
 {
     removing.Add(obj);
 }
Exemple #6
0
 public void Add(ShipObj obj)
 {
     adding.Add(obj);
 }
Exemple #7
0
        public override void HandleData(NetIncomingMessage msg)
        {
            NetEntityType Type;
            ushort        ID;
            Vector3       Position;
            Vector3       Velocity;
            Quaternion    Orientation;
            NetMsgType    datatype = (NetMsgType)msg.ReadByte();

            switch (datatype)
            {
            case NetMsgType.Chat:
                Console.WriteLine(msg.ReadString());
                break;

            case NetMsgType.CreateOnClient:
                #region CreateOnClient
                Type        = (NetEntityType)msg.ReadByte();
                ID          = msg.ReadUInt16();
                Position    = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                ushort Resource;
                long   OwnerID;

                //DEBUG
                if (Type == NetEntityType.Ship)
                {
                    int[] shipWeapons  = null;
                    var   shipNose     = msg.ReadInt32();
                    var   shipCore     = msg.ReadInt32();
                    var   shipTail     = msg.ReadInt32();
                    int   weaponLength = msg.ReadInt32();
                    if (weaponLength > 0)
                    {
                        shipWeapons = new int[weaponLength];
                        for (int i = 0; i < weaponLength; i++)
                        {
                            shipWeapons[i] = msg.ReadInt32();
                        }
                    }
                    Resource = 0;
                    OwnerID  = msg.ReadInt64();
                    var shipData = new ShipData(shipNose, shipCore, shipTail);
                    WeaponsFromData(shipData, shipWeapons);
                    var ship = new ShipObj(MobileFortressClient.Game, Position, Orientation, shipData);
                    ship.ID = ID;
                    if (OwnerID == Network.Client.UniqueIdentifier)
                    {
                        Network.JoinedGame = true;
                        Camera.Setup(MobileFortressClient.Game, ship, new Vector3(0, 2f, 6f));
                        var HUD = new ShipHUD();
                        if (shipWeapons != null)
                        {
                            for (int i = 0; i < shipWeapons.Length; i++)
                            {
                                HUD.MakeAmmoIndicator(shipWeapons[i]);
                            }
                        }
                        MenuManager.Menu = HUD;
                    }
                }
                else
                {
                    Resource = msg.ReadUInt16();
                    if (Type == NetEntityType.Building)
                    {
                        new Building(Position, Resource);
                    }
                    else if (Type == NetEntityType.Missile)
                    {
                        var obj = new Rocket(MobileFortressClient.Game, Resource, Position, Orientation);
                        obj.ID = ID;
                    }
                    else
                    {
                        var obj = new PhysicsObj(MobileFortressClient.Game, Position, Orientation, Resource);
                        obj.ID = ID;
                    }
                }
                #endregion
                break;

            case NetMsgType.MapLoading:
                #region MapLoading
                if (msg.ReadByte() == 0)
                {
                    var Seed      = msg.ReadInt32();
                    var Power     = msg.ReadInt32();
                    var Roughness = msg.ReadFloat();
                    Sector.Redria.Terrain.Terrain = new Heightmap(Seed, Power, Roughness);
                }
                else
                {
                    var terrain     = Sector.Redria.Terrain.Terrain;
                    int alterations = msg.ReadInt32();
                    Console.WriteLine(alterations + " Recieved Alterations.");
                    for (int i = 0; i < alterations; i++)
                    {
                        Rectangle flattenedArea = new Rectangle(msg.ReadInt32(),
                                                                msg.ReadInt32(), msg.ReadInt32(), msg.ReadInt32());
                        terrain.FlattenArea(flattenedArea);
                    }
                    terrain.Graphics.ResetVertexBuffer();
                }
                #endregion
                break;

            case NetMsgType.EntityUpdate:
                #region EntityUpdate
                Type        = (NetEntityType)msg.ReadByte();
                ID          = msg.ReadUInt16();
                Position    = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                Velocity    = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                if (Type == NetEntityType.Ship)
                {
                    var ship = Sector.Redria.Ships.Retrieve(ID);
                    if (ship == null)
                    {
                        Console.WriteLine("No such ship ID: " + ID);
                        break;
                    }
                    ship.UpdateFromNet(Position, Orientation, Velocity);
                }
                else if (Type == NetEntityType.Missile)
                {
                    var missile = Sector.Redria.Objects.Retrieve(ID);
                    if (missile == null)
                    {
                        break;
                    }
                    missile.UpdateFromNet(Position, Orientation, Velocity);
                }
                #endregion
                break;

            case NetMsgType.Bullet:
                #region Bullet
                ID          = msg.ReadUInt16();
                Position    = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                Velocity    = new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                Orientation = new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat());
                var Projectile = ProjectileData.ProjectileTable[ID];
                var ping       = Network.Client.ServerConnection.AverageRoundtripTime;
                Projectile.Create(Position + Velocity * (ping / 2), Orientation, Velocity);
                var Audio = new AudioEmitter();
                Audio.Position = Position / Resources.AudioPositionQuotient;
                Audio.Forward  = Vector3.Transform(Vector3.Forward, Orientation);
                Audio.Up       = Vector3.Up;
                Audio.Velocity = Velocity;

                var sound = Resources.Sounds.WeaponSounds[ID].CreateInstance();
                sound.Apply3D(Camera.Audio, Audio);
                sound.Play();
                #endregion
                break;

            case NetMsgType.ShipExplode:
                #region ShipExplode
                ID = msg.ReadUInt16();
                var deadship = Sector.Redria.Ships.Retrieve(ID);
                deadship.Explode();
                #endregion
                break;

            case NetMsgType.Explosion:
                #region Explosion
                ID = msg.ReadUInt16();
                var Radius    = msg.ReadFloat();
                var exploding = Sector.Redria.Objects.Retrieve(ID);
                if (exploding != null)
                {
                    new Explosion(exploding.Position, Radius);
                    exploding.Destroy();
                }
                #endregion
                break;

            case NetMsgType.Lockon:
                #region Lockon
                if (!(MenuManager.Menu is ShipHUD))
                {
                    break;
                }
                ID = msg.ReadUInt16();
                var     LockonStatus = (LockonStatus)msg.ReadByte();
                ShipHUD Menu         = (ShipHUD)MenuManager.Menu;
                if (LockonStatus > LockonStatus.Locked)
                {
                    if (LockonStatus == LockonStatus.EnemyLock)
                    {
                        Menu.enemyLock = true;
                    }
                    else if (LockonStatus == LockonStatus.EnemyMissile)
                    {
                        Menu.enemyLock    = false;
                        Menu.enemyMissile = true;
                    }
                    else
                    {
                        Menu.enemyMissile = false;
                        Menu.enemyLock    = false;
                    }
                }
                else
                {
                    if (ID == ushort.MaxValue)
                    {
                        Menu.Target     = null;
                        Menu.LockStatus = LockonStatus.NotLocked;
                    }
                    else
                    {
                        Menu.Target     = Sector.Redria.Ships.Retrieve(ID);
                        Menu.LockStatus = LockonStatus;
                        if (Menu.LockStatus == LockonStatus.Locking)
                        {
                            Resources.Sounds.LockingOn.Play();
                        }
                        else if (Menu.LockStatus == LockonStatus.Locked)
                        {
                            Resources.Sounds.LockedOn.Play();
                        }
                    }
                }
                #endregion
                break;

            case NetMsgType.ShipUpdate:
                #region ShipUpdate
                var Health    = msg.ReadFloat();
                var Throttle  = msg.ReadFloat();
                var AmmoCount = msg.ReadByte();
                var Ammo      = new ushort[AmmoCount];
                for (byte i = 0; i < AmmoCount; i++)
                {
                    Ammo[i] = msg.ReadUInt16();
                }
                if (MenuManager.Menu is ShipHUD)
                {
                    var HUD = (ShipHUD)MenuManager.Menu;
                    HUD.SetHealth((int)Health);

                    for (int i = 0; i < Ammo.Length; i++)
                    {
                        HUD.SetAmmo(i, Ammo[i]);
                    }
                    ping = msg.SenderConnection.AverageRoundtripTime * 1000;
                    HUD.SetPing(ping);

                    var ship = (ShipObj)Camera.Target;
                    ship.SetThrottle(Throttle);
                }

                #endregion
                break;

            default:
                Console.WriteLine("Unhandled NetMsgType: " + datatype);
                break;
            }
        }
Exemple #8
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            Viewport viewport = spriteBatch.GraphicsDevice.Viewport;
            ShipObj  Ship     = (ShipObj)Camera.Target;

            spriteBatch.Draw(Crosshairs, RCrosshairs2, HUDColor);
            spriteBatch.Draw(Crosshairs, RCrosshairs, HUDColor);
            FrameCounter.Draw(spriteBatch);
            #region Targeting
            foreach (ShipObj ship in nearbyShips)
            {
                if (ship == Camera.Target)
                {
                    continue;
                }
                Rectangle LockonSource   = ArrowSource;
                float     AoA            = AngleOfAttack(ship.Position, Camera.Target.Position, Camera.Target.worldTransform.Forward);
                Vector3   SpriteLocation = viewport.Project(ship.Position, Camera.Projection, Camera.View, Matrix.Identity);
                if (AoA > MathHelper.PiOver2 || AoA < -MathHelper.PiOver2)
                {
                    if (SpriteLocation.X < viewport.Width * 0.25f)
                    {
                        LockonTex = Resources.Menus.HUD.Arrows;
                        if (SpriteLocation.Y < 0)
                        {
                            LockonDest = new Rectangle(0, 0, 16, 16);
                        }
                        else if (SpriteLocation.Y > viewport.Height)
                        {
                            LockonDest = new Rectangle(0, viewport.Height - 16, 16, 16);
                        }
                        else
                        {
                            LockonDest = new Rectangle(0, (int)SpriteLocation.Y - 8, 16, 16);
                        }
                        LockonSource.Y = 16;
                    }
                    else if (SpriteLocation.X > viewport.Width * 0.75f)
                    {
                        LockonTex = Resources.Menus.HUD.Arrows;
                        if (SpriteLocation.Y < 0)
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, 0, 16, 16);
                        }
                        else if (SpriteLocation.Y > viewport.Height)
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, viewport.Height - 16, 16, 16);
                        }
                        else
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, (int)SpriteLocation.Y - 8, 16, 16);
                        }
                        LockonSource.X = 16;
                        LockonSource.Y = 16;
                    }
                    else if (SpriteLocation.Y > viewport.Height / 2)
                    {
                        LockonTex      = Resources.Menus.HUD.Arrows;
                        LockonDest     = new Rectangle((int)SpriteLocation.X - 8, viewport.Height - 16, 16, 16);
                        LockonSource.X = 16;
                    }
                    else
                    {
                        LockonTex  = Resources.Menus.HUD.Arrows;
                        LockonDest = new Rectangle((int)SpriteLocation.X - 8, 0, 16, 16);
                    }
                }
                else
                {
                    if (SpriteLocation.X < 0)
                    {
                        LockonTex = Resources.Menus.HUD.Arrows;
                        if (SpriteLocation.Y < 0)
                        {
                            LockonDest = new Rectangle(0, 0, 16, 16);
                        }
                        else if (SpriteLocation.Y > viewport.Height)
                        {
                            LockonDest = new Rectangle(0, viewport.Height - 16, 16, 16);
                        }
                        else
                        {
                            LockonDest = new Rectangle(0, (int)SpriteLocation.Y - 8, 16, 16);
                        }
                        LockonSource.Y = 16;
                    }
                    else if (SpriteLocation.X > viewport.Width)
                    {
                        LockonTex = Resources.Menus.HUD.Arrows;
                        if (SpriteLocation.Y < 0)
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, 0, 16, 16);
                        }
                        else if (SpriteLocation.Y > viewport.Height)
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, viewport.Height - 16, 16, 16);
                        }
                        else
                        {
                            LockonDest = new Rectangle(viewport.Width - 16, (int)SpriteLocation.Y - 8, 16, 16);
                        }
                        LockonSource.X = 16;
                        LockonSource.Y = 16;
                    }

                    else if (SpriteLocation.Y < 0)
                    {
                        LockonTex  = Resources.Menus.HUD.Arrows;
                        LockonDest = new Rectangle((int)SpriteLocation.X - 8, 0, 16, 16);
                    }
                    else if (SpriteLocation.Y > viewport.Height)
                    {
                        LockonTex      = Resources.Menus.HUD.Arrows;
                        LockonDest     = new Rectangle((int)SpriteLocation.X - 8, viewport.Height - 16, 16, 16);
                        LockonSource.X = 16;
                    }
                    else
                    {
                        LockonTex    = Resources.Menus.HUD.Reticle;
                        LockonDest   = new Rectangle((int)SpriteLocation.X - 16, (int)SpriteLocation.Y - 16, 32, 32);
                        LockonSource = ReticleSource;
                    }
                }
                Color color = HUDColor;
                if (ship == Target)
                {
                    if (LockStatus == LockonStatus.Locking)
                    {
                        color = Color.Gold;
                    }
                    else if (LockStatus == LockonStatus.Locked)
                    {
                        color = Color.Red;
                    }
                }
                spriteBatch.Draw(LockonTex, LockonDest, LockonSource, color);
            }
            #endregion
            Manager.Draw(spriteBatch);
        }
Exemple #9
0
 public PEngine(ShipObj parent, Vector3 position, Vector3 velocity, float size)
     : base(1, parent, position, velocity, size)
 {
 }
Exemple #10
0
 public void Add(ShipObj obj)
 {
     obj.ID = shipCount++;
     adding.Add(obj);
 }