Exemplo n.º 1
0
 /// <summary>
 ///  this is really only used for initialization. Use Entity.Mass for the ship's mass as it pertains to the physics model
 /// </summary>
 /// <returns>the mass of all combined shipParts</returns>
 private float getTotalMass()
 {
     return(Reactors.Select(x => x.GetMass()).Sum() +
            Shields.Select(x => x.GetMass()).Sum() +
            Weapons.Select(x => x.GetMass()).Sum() +
            Engines.Select(x => x.GetMass()).Sum() +
            CrewDecks.Select(x => x.GetMass()).Sum());
 }
Exemplo n.º 2
0
 private List <IShipPart> getDamageableParts()
 {
     return(new List <IShipPart>()
            .Concat(Reactors.Where(x => !x.IsDestroyed()))
            .Concat(Engines.Where(x => !x.IsDestroyed()))
            .Concat(Shields.Where(x => !x.IsDestroyed()))
            .Concat(Weapons.Where(x => !x.IsDestroyed()))
            .Concat(CrewDecks.Where(x => !x.IsDestroyed())).ToList());
 }
Exemplo n.º 3
0
        /// <summary>
        /// repairs some part that is damaged.
        /// </summary>
        /// <param name="crewDeck">Use this crewdeck's repair rate.</param>
        private void repairARandomPartThatNeedsIt(CrewDeck crewDeck)
        {
            List <IShipPart> damagedParts = new List <IShipPart>();

            damagedParts.AddRange(Reactors.Where(x => x.Health.Item1 < x.Health.Item2));
            damagedParts.AddRange(Engines.Where(x => x.Health.Item1 < x.Health.Item2));
            damagedParts.AddRange(Weapons.Where(x => x.Health.Item1 < x.Health.Item2));
            damagedParts.AddRange(Shields.Where(x => x.Health.Item1 < x.Health.Item2));
            damagedParts.AddRange(CrewDecks.Where(x => x.Health.Item1 < x.Health.Item2));

            if (damagedParts.Count() == 0)
            {
                return;
            }

            crewDeck.PerformRepair(damagedParts[GameEngine.Random(damagedParts.Count)]);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Clears all higher and lower object pools.
 /// Field will be ready for disposal and can not be used after this is called.
 /// </summary>
 public void Dispose()
 {
     Users.Dispose();
     Npcs.Dispose();
     Footholds.Dispose();
     Portals.Dispose();
     Mobs.Dispose();
     Reactors.Dispose();
     Drops.Dispose();
     AffectedAreas.Dispose();
     MiniRooms.Dispose();
     Kites.Dispose();
     TownPortals.Dispose();
     OpenGates1.Dispose();
     OpenGates2.Dispose();
     CurrentWeather.Dispose();
 }
Exemplo n.º 5
0
 private void spendPower()
 {
     // currently the only thing that this does is regen the shields or not.
     // change to for loop so we have more control owver what gets power when and what happens if there isn't enough power.
     Power -= (Reactors.Select(x => x.GetUpkeepCost()).Sum() +
               Shields.Select(x => x.GetUpkeepCost()).Sum() +
               Weapons.Select(x => x.GetUpkeepCost()).Sum() +
               Engines.Select(x => x.GetUpkeepCost()).Sum() +
               CrewDecks.Select(x => x.GetUpkeepCost()).Sum());
     if (Power < 0)
     {
         Power = 0;
     }
     foreach (var shield in Shields)
     {
         Power = shield.Regen(Power);
     }
 }
Exemplo n.º 6
0
        public override string ToString()
        {
            var result = "Ship:" + Name +
                         " Crew:" + CrewDecks.Select(x => (int)x.GetCrew()).Sum() +
                         " Mass: " + Mass +
                         " Power:" + Power +
                         " Position:[X:" + Position.X + " Y:" + Position.Y + " Heading:" + Orientation + "° Velocity: X:" + Velocity.X + " Y:" + Velocity.Y + " Mag:" + Velocity.Magnitude + "]\n";

            result += string.Join(" ", Reactors.Select(x => x.ToString())) + "\n";
            result += string.Join(" ", Shields.Select(x => x.ToString())) + "\n";
            result += string.Join(" ", Weapons.Select(x => x.ToString())) + "\n";
            result += string.Join(" ", Engines.Select(x => x.ToString())) + "Max :" + GetMaxAcceleration() + "\n";
            result += string.Join(" ", CrewDecks.Select(x => x.ToString())) + "\n";
            if (IsDestroyed())
            {
                result += "(Destroyed)\n";
            }
            return(result);
        }
Exemplo n.º 7
0
        public override void Update(uint roundNumber)
        {
            if (IsDestroyed())
            {
                return;
            }
            // this would be where we would do repairs, regen shields, move the ship etc.

            Power = Reactors.Select(x => x.Produce()).Sum();

            moveShip();

            foreach (var crewDeck in CrewDecks)
            {
                repairARandomPartThatNeedsIt(crewDeck);
            }

            // update parts
            foreach (var part in CrewDecks)
            {
                part.Update(roundNumber);
            }
            foreach (var part in Reactors)
            {
                part.Update(roundNumber);
            }
            foreach (var part in Engines)
            {
                part.Update(roundNumber);
            }
            foreach (var part in Shields)
            {
                part.Update(roundNumber);
            }
            foreach (var part in Weapons)
            {
                part.Update(roundNumber);
            }
            foreach (var shield in Shields)
            {
                Power = shield.Regen(Power);
            }
        }
Exemplo n.º 8
0
        protected override void Init()
        {
            aTeams       = new Dictionary <int, BattlefieldData.BattlefieldTeams>();
            aSheepPoints = new Dictionary <int, int>();
            WolfScore    = 0;
            SheepScore   = 0;
            Mobs.Reset();
            Reactors.Reset();

            foreach (var reactor in Reactors)
            {
                if (reactor.tReactorTime == 0)
                {
                    reactor.tReactorTime = 10;                     // TODO figure out how reactor events work with this
                }
            }

            tGameOverTime = DateTime.MinValue;

            CreateFieldClock(DURATION_SEC);
        }
Exemplo n.º 9
0
        public void Insert(VisibleObject obj, byte x, byte y, bool updateClient = true)
        {
            lock (_lock)
            {
                if (Objects.Add(obj))
                {
                    obj.Map = this;
                    obj.X   = x;
                    obj.Y   = y;

                    EntityTree.Add(obj);

                    var user = obj as User;
                    if (user != null)
                    {
                        if (updateClient)
                        {
                            obj.SendMapInfo();
                            obj.SendLocation();
                        }
                        Users.Add(user.Name, user);
                    }

                    var value = obj as Objects.Reactor;
                    if (value != null)
                    {
                        Reactors.Add(new Tuple <byte, byte>((byte)x, (byte)y), value);
                    }

                    var affectedObjects = EntityTree.GetObjects(obj.GetViewport());

                    foreach (var target in affectedObjects)
                    {
                        target.AoiEntry(obj);
                        obj.AoiEntry(target);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void Load()
 {
     if (!Loading)
     {
         Loading = true;
         StatusMessageService.Message = String.Format("Loading {0} schedule.", ScheduleCodeName);
         _schedule = Repository.LoadSchedule(this.ScheduleCode);
         if (_schedule == null)
         {
             _schedule = Repository.CreateSchedule(this.ScheduleCode);
         }
         ID = _schedule.ScheduleID;
         StatusMessageService.Message = "Getting Reactor Statuses...";
         var reactorStatus = Repository.GetStatuses();
         StatusMessageService.Message = "Loading Schedules...";
         BookedOrders.Load();
         var reactors = new List <ReactorViewModel>(16);
         foreach (var rs in _schedule.ReactorSchedules.OrderBy(r => r.Reactor.ReactorNumber))
         {
             ReactorStatus status  = reactorStatus.Find(r => r.ReactorID == rs.ReactorID);
             var           reactor = _factory.Create(rs);
             StatusMessageService.Message = "Loading " + reactor.Caption;
             reactors.Add(reactor);
             reactor.Start         = Start;
             reactor.End           = End;
             reactor.Status        = status;
             reactor.TaskSelected += ReactorTaskSelected;
             reactor.Load(rs.Tasks.OrderBy(t => t.TaskIndex).ToList());
             reactor.RemoveProcessedTasks();
             reactor.RefreshLayout();
         }
         Reactors.Clear();
         Reactors.AddRange(reactors);
         Loading = false;
         StatusMessageService.Message = "Loading Complete.";
         BookedOrders.Orders.View.Refresh();
     }
 }
Exemplo n.º 11
0
        //--------------------------------------------------

        /// <summary>
        /// Updates all field objects.
        /// </summary>
        public virtual void Update()
        {
            Mobs.Update();

            Reactors.RedistributeLife();

            Drops.Update();

            if (tFieldTimerExpiration != DateTime.MinValue && tFieldTimerExpiration.SecondsUntilEnd() <= 0)
            {
                OnClockEnd();
            }

            foreach (var user in Users)
            {
                user.Update(this);
            }

            // less taxing to check item id cuz it gets reset when the effect is over
            if (CurrentWeather.nItemID > 0 && CurrentWeather.StartTime.AddedSecondsExpired(CurrentWeather.Duration))
            {
                CurrentWeather.Clear();
            }

            MiniRooms.Update();
            Kites.Update();
            TownPortals.Update();
            OpenGates1.Update();
            OpenGates2.Update();
            AffectedAreas.Update();
            Summons.Update();

            if (Template.DecHP > 0 || Template.DecMP > 0)
            {
                // TODO
                // CUserLocal::OnNotifyHPDecByField(this, iPacket);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Clears all lower object pools and resets all higher object pools.
        /// Map can still be used after this is called.
        /// DO NOT CALL DISPOSE FROM INSIDE THIS FUNCTION
        /// </summary>
        protected virtual void Reset(bool bFromDispose = false)
        {
            if (Users.Count > 0)             // not good
            {
                throw new InvalidOperationException("Trying to reset map that still has users in it.");
            }

            QR = "";
            nFieldDeathCount      = -1;
            tFieldTimerExpiration = DateTime.MinValue;

            Mobs.Reset();
            Reactors.Reset();

            Drops.Clear();
            AffectedAreas.Clear();
            MiniRooms.Clear();
            Kites.Clear();
            TownPortals.Clear();
            OpenGates1.Clear();
            OpenGates2.Clear();
            CurrentWeather.Clear();
        }
Exemplo n.º 13
0
        //---------------------------------------------------------------------
        // READING
        //---------------------------------------------------------------------

        /// <summary>
        /// Converts all the base file's data classes into the editor class for that type.
        /// </summary>
        public void CreateLocalLists()
        {
            //TODO: This is just passthrough for now, need "editor" classes
            foreach (ushort texture in BaseFile.Textures)
            {
                Textures.Add(texture);
            }
            foreach (TMAPInfo tmapInfo in BaseFile.TMapInfo)
            {
                TMapInfo.Add(tmapInfo);
            }

            Array.Copy(BaseFile.Sounds, Sounds, 254);
            Array.Copy(BaseFile.AltSounds, AltSounds, 254);

            foreach (VClip clip in BaseFile.VClips)
            {
                VClips.Add(clip);
            }
            foreach (EClip clip in BaseFile.EClips)
            {
                EClips.Add(clip);
            }
            foreach (WClip clip in BaseFile.WClips)
            {
                WClips.Add(clip);
            }
            foreach (Robot robot in BaseFile.Robots)
            {
                Robots.Add(robot);
            }
            foreach (JointPos joint in BaseFile.Joints)
            {
                Joints.Add(joint);
            }
            foreach (Weapon weapon in BaseFile.Weapons)
            {
                Weapons.Add(weapon);
            }
            foreach (Polymodel model in BaseFile.Models)
            {
                Models.Add(model);
            }
            foreach (ushort gauge in BaseFile.Gauges)
            {
                Gauges.Add(gauge);
            }
            foreach (ushort gauge in BaseFile.GaugesHires)
            {
                GaugesHires.Add(gauge);
            }
            PlayerShip = BaseFile.PlayerShip;
            foreach (ushort cockpit in BaseFile.Cockpits)
            {
                Cockpits.Add(cockpit);
            }
            foreach (Reactor reactor in BaseFile.Reactors)
            {
                Reactors.Add(reactor);
            }
            foreach (Powerup powerup in BaseFile.Powerups)
            {
                Powerups.Add(powerup);
            }
            FirstMultiBitmapNum = BaseFile.FirstMultiBitmapNum;
            for (int i = 0; i < 2620; i++)
            {
                BitmapXLATData[i] = BaseFile.BitmapXLATData[i];
            }
            foreach (ushort bm in BaseFile.ObjBitmaps)
            {
                ObjBitmaps.Add(bm);
            }
            foreach (ushort bm in BaseFile.ObjBitmapPointers)
            {
                ObjBitmapPointers.Add(bm);
            }
        }
Exemplo n.º 14
0
        public void Read(Stream stream)
        {
            BinaryReader br;

            br = new BinaryReader(stream);
            HAMDataReader bm = new HAMDataReader();

            int sig = br.ReadInt32();

            if (sig != 0x214D4148)
            {
                br.Dispose();
                throw new InvalidDataException("HAMFile::Read: HAM file has bad header.");
            }
            Version = br.ReadInt32();
            if (Version < 2 || Version > 3)
            {
                br.Dispose();
                throw new InvalidDataException(string.Format("HAMFile::Read: HAM file has bad version. Got {0}, but expected \"2\" or \"3\"", Version));
            }
            int sndptr = 0;

            if (Version == 2)
            {
                sndptr = br.ReadInt32();
            }

            int NumBitmaps = br.ReadInt32();

            for (int x = 0; x < NumBitmaps; x++)
            {
                Textures.Add(br.ReadUInt16());
            }
            for (int x = 0; x < NumBitmaps; x++)
            {
                TMapInfo.Add(bm.ReadTMAPInfo(br));
                TMapInfo[x].ID = x;
            }

            int NumSounds = br.ReadInt32();

            if (NumSounds > 254)
            {
                throw new InvalidDataException("HAM file specifies more than 254 sounds.");
            }

            for (int x = 0; x < NumSounds; x++)
            {
                Sounds[x] = br.ReadByte();
            }
            for (int x = 0; x < NumSounds; x++)
            {
                AltSounds[x] = br.ReadByte();
            }

            int NumVClips = br.ReadInt32();

            for (int x = 0; x < NumVClips; x++)
            {
                VClips.Add(bm.ReadVClip(br));
                VClips[x].ID = x;
            }

            int NumEClips = br.ReadInt32();

            for (int x = 0; x < NumEClips; x++)
            {
                EClips.Add(bm.ReadEClip(br));
                EClips[x].ID = x;
            }

            int NumWallAnims = br.ReadInt32();

            for (int x = 0; x < NumWallAnims; x++)
            {
                WClips.Add(bm.ReadWClip(br));
            }

            int NumRobots = br.ReadInt32();

            for (int x = 0; x < NumRobots; x++)
            {
                Robots.Add(bm.ReadRobot(br));
                Robots[x].ID = x;
            }

            int NumLoadJoints = br.ReadInt32();

            for (int x = 0; x < NumLoadJoints; x++)
            {
                JointPos joint = new JointPos();
                joint.JointNum = br.ReadInt16();
                joint.Angles.P = br.ReadInt16();
                joint.Angles.B = br.ReadInt16();
                joint.Angles.H = br.ReadInt16();
                Joints.Add(joint);
            }

            int NumWeaponTypes = br.ReadInt32();

            for (int x = 0; x < NumWeaponTypes; x++)
            {
                if (Version >= 3)
                {
                    Weapons.Add(bm.ReadWeapon(br));
                }
                else
                {
                    Weapons.Add(bm.ReadWeaponInfoVersion2(br));
                }
                Weapons[x].ID = x;
            }

            int NumPowerups = br.ReadInt32();

            for (int x = 0; x < NumPowerups; x++)
            {
                Powerup powerup = new Powerup();
                powerup.VClipNum = br.ReadInt32();
                powerup.HitSound = br.ReadInt32();
                powerup.Size     = new Fix(br.ReadInt32());
                powerup.Light    = new Fix(br.ReadInt32());
                powerup.ID       = x;
                Powerups.Add(powerup);
            }

            int NumPolygonModels = br.ReadInt32();

            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models.Add(bm.ReadPolymodelInfo(br));
                Models[x].ID = x;
            }

            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].InterpreterData = br.ReadBytes(Models[x].ModelIDTASize);
                //PolymodelData.Add(modeldata);
            }
            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].DyingModelnum = br.ReadInt32();
            }
            for (int x = 0; x < NumPolygonModels; x++)
            {
                Models[x].DeadModelnum = br.ReadInt32();
            }
            int gagueCount = br.ReadInt32();

            for (int x = 0; x < gagueCount; x++)
            {
                Gauges.Add(br.ReadUInt16());
            }
            for (int x = 0; x < gagueCount; x++)
            {
                GaugesHires.Add(br.ReadUInt16());
            }

            int bitmapCount = br.ReadInt32();

            for (int x = 0; x < bitmapCount; x++)
            {
                ObjBitmaps.Add(br.ReadUInt16());
            }
            ushort value;

            for (int x = 0; x < bitmapCount; x++)
            {
                value = br.ReadUInt16();
                if ((value + 1) > NumObjBitmaps)
                {
                    NumObjBitmaps = (value + 1);
                }
                ObjBitmapPointers.Add(value);
            }

            PlayerShip                   = new Ship();
            PlayerShip.ModelNum          = br.ReadInt32();
            PlayerShip.DeathVClipNum     = br.ReadInt32();
            PlayerShip.Mass              = new Fix(br.ReadInt32());
            PlayerShip.Drag              = new Fix(br.ReadInt32());
            PlayerShip.MaxThrust         = new Fix(br.ReadInt32());
            PlayerShip.ReverseThrust     = new Fix(br.ReadInt32());
            PlayerShip.Brakes            = new Fix(br.ReadInt32());
            PlayerShip.Wiggle            = new Fix(br.ReadInt32());
            PlayerShip.MaxRotationThrust = new Fix(br.ReadInt32());
            for (int x = 0; x < 8; x++)
            {
                PlayerShip.GunPoints[x] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }

            int NumCockpits = br.ReadInt32();

            for (int x = 0; x < NumCockpits; x++)
            {
                Cockpits.Add(br.ReadUInt16());
            }
            //Build a table of all multiplayer bitmaps, to inject into the object bitmap table
            FirstMultiBitmapNum = br.ReadInt32();

            int NumReactors = br.ReadInt32();

            for (int x = 0; x < NumReactors; x++)
            {
                Reactor reactor = new Reactor();
                reactor.ModelNum = br.ReadInt32();
                reactor.NumGuns  = br.ReadInt32();
                for (int y = 0; y < 8; y++)
                {
                    reactor.GunPoints[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                for (int y = 0; y < 8; y++)
                {
                    reactor.GunDirs[y] = FixVector.FromRawValues(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
                }
                Reactors.Add(reactor);
            }
            PlayerShip.MarkerModel = br.ReadInt32();
            //2620
            if (Version < 3)
            {
                ExitModelnum          = br.ReadInt32();
                DestroyedExitModelnum = br.ReadInt32();
            }
            for (int x = 0; x < 2620; x++)
            {
                try
                {
                    BitmapXLATData[x] = br.ReadUInt16();
                }
                catch (EndOfStreamException) //Descent 2's official HAM files have only 2600 XLAT entries, but later versions of the game attempt to read 2620.
                {
                    break;
                }
            }

            if (Version < 3)
            {
                br.BaseStream.Seek(sndptr, SeekOrigin.Begin);
                int dataToRead = (int)(br.BaseStream.Length - br.BaseStream.Position);
                sounddata = br.ReadBytes(dataToRead);
            }

            hasRead = true;
            //br.Dispose();
        }