Exemplo n.º 1
0
        public Game(string corePath, int numTeams, int myTeam, bool allowDevelopment, bool allowShipyards, bool deathMatch, bool captureTheFlag, bool allowArtifacts, bool prosperity)
        {
            _core        = new Core(corePath);
            _teams       = new ArrayList(numTeams);
            _comparisons = new ArrayList(3);

            _gameDefs = new BitArray(400, false);
            _gameDefs[ALLOWDEVELOPMENT] = allowDevelopment;
            _gameDefs[ALLOWSUPREMACY]   = allowDevelopment;
            _gameDefs[ALLOWTACTICAL]    = allowDevelopment;
            _gameDefs[ALLOWEXPANSION]   = allowDevelopment;
            _gameDefs[ALLOWSHIPYARDS]   = allowShipyards;
            _gameDefs[DEATHMATCH]       = deathMatch;
            _gameDefs[CAPTURETHEFLAG]   = captureTheFlag;
            //_gameDefs[ALLOWARTIFACTS] = allowArtifacts;
            //_gameDefs[PROSPERITY] = prosperity;

            for (int i = 0; i < numTeams; i++)
            {
                _teams.Add(new Team(this, i));
            }

            _myTeam = (Team)_teams[myTeam - 1];

            // Get references to the ammo and fuel packs
            foreach (IGCCorePart Part in _core.Parts)
            {
                if (Part is IGCCorePartPack)
                {
                    IGCCorePartPack Pack = (IGCCorePartPack)Part;
                    if (Pack.PackType == PackType.Ammo)
                    {
                        Ship.AmmoPack = Pack;
                    }

                    if (Pack.PackType == PackType.Fuel)
                    {
                        Ship.FuelPack = Pack;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Calculate()
        {
            if (_object1 is Station)
            {
                _timeToKill = float.PositiveInfinity;
                return;
            }

            float Interval = _object1.Core.Constants.DownedShield;

            if (_object1 is Ship)
            {
                Ship ship = (Ship)_object1;
                if (ship.FireMissile && firingMissile != null)
                {
                    MissilePack = ship.IGCShip.MissileCapacity / firingMissile.CargoPayload;
                }
            }

            float WeaponDamage = 0F;

            bool DownedShield = false;
            bool TakingDamage = false;

            while (true)
            {
                _timeToKill += Interval;
                if (_timeToKill > 3600F)
                {
                    _timeToKill = float.NaN;
                    break;
                }

                TakingDamage = false;

                if (_object1 is Probe)
                {
                    Probe             probe      = (Probe)_object1;
                    IGCCoreProjectile Projectile = (IGCCoreProjectile)probe.Core.Projectiles.GetModule((ushort)probe.IGCProbe.Projectile);
                    if (Projectile == null)
                    {
                        _timeToKill = float.PositiveInfinity;
                        break;
                    }
                    float ProjRange = Projectile.Speed * Projectile.Lifespan * Mods.PWRange;
                    if (ProjRange > _range)
                    {
                        _range = ProjRange;
                    }

                    WeaponDamage  = CalculateWeaponDamage(Projectile, probe.IGCProbe.ShotInterval);
                    WeaponDamage *= Interval * probe.IGCProbe.Accuracy;
                    if (WeaponDamage == 0)
                    {
                        TakingDamage = true;
                        _timeToKill  = float.PositiveInfinity;
                        break;
                    }
                    _ammoUsed += Interval / probe.IGCProbe.ShotInterval;
                    if (_ammoUsed > probe.IGCProbe.AmmoCapacity)
                    {
                        break;
                    }

                    if (ApplyDamage(WeaponDamage) == false)
                    {
                        continue;
                    }
                    else
                    {
                        break;                          // Target Destroyed!
                    }
                }

                if (_object1 is Ship)
                {
                    Ship ship = (Ship)_object1;
                    IGCCorePartWeapon Weapon;
                    if (ship.FireWeapons == true)
                    {
                        Weapon = ship.Weapons[0];
                        if ((ship.WeaponToFire == -1 || ship.WeaponToFire == 0) && Weapon != null)
                        {
                            // If we're not reloading, not rearming, and not recharging energy (if we need them)
                            if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                                (Weapon.EnergyConsumption > 0 && Battery > 0))
                            {
                                WeaponDamage = FireGun(Weapon, Interval);
                                if (WeaponDamage != 0)
                                {
                                    TakingDamage = true;
                                    if (ApplyDamage(WeaponDamage) == true)
                                    {
                                        break;                                          // Target Destroyed!
                                    }
                                }
                            }
                        }

                        Weapon = ship.Weapons[1];
                        if ((ship.WeaponToFire == -1 || ship.WeaponToFire == 1) && Weapon != null)
                        {
                            if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                                (Weapon.EnergyConsumption > 0 && Battery > 0))
                            {
                                WeaponDamage = FireGun(Weapon, Interval);
                                if (WeaponDamage != 0)
                                {
                                    TakingDamage = true;
                                    if (ApplyDamage(WeaponDamage) == true)
                                    {
                                        break;                                          // Target Destroyed!
                                    }
                                }
                            }
                        }

                        Weapon = ship.Weapons[2];
                        if ((ship.WeaponToFire == -1 || ship.WeaponToFire == 2) && Weapon != null)
                        {
                            if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                                (Weapon.EnergyConsumption > 0 && Battery > 0))
                            {
                                WeaponDamage = FireGun(Weapon, Interval);
                                if (WeaponDamage != 0)
                                {
                                    TakingDamage = true;
                                    if (ApplyDamage(WeaponDamage) == true)
                                    {
                                        break;                                          // Target Destroyed!
                                    }
                                }
                            }
                        }

                        Weapon = ship.Weapons[3];
                        if ((ship.WeaponToFire == -1 || ship.WeaponToFire == 3) && Weapon != null)
                        {
                            if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                                (Weapon.EnergyConsumption > 0 && Battery > 0))
                            {
                                WeaponDamage = FireGun(Weapon, Interval);
                                if (WeaponDamage != 0)
                                {
                                    TakingDamage = true;
                                    if (ApplyDamage(WeaponDamage) == true)
                                    {
                                        break;                                          // Target Destroyed!
                                    }
                                }
                            }
                        }
                    }

                    Weapon = ship.Turrets[0];
                    if (ship.FireTurrets[0] == true)
                    {
                        if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                            (Weapon.EnergyConsumption > 0 && Battery > 0))
                        {
                            WeaponDamage = FireGun(Weapon, Interval);
                            if (WeaponDamage != 0)
                            {
                                TakingDamage = true;
                                if (ApplyDamage(WeaponDamage) == true)
                                {
                                    break;                                      // Target Destroyed!
                                }
                            }
                        }
                    }

                    Weapon = ship.Turrets[1];
                    if (ship.FireTurrets[1] == true)
                    {
                        if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                            (Weapon.EnergyConsumption > 0 && Battery > 0))
                        {
                            WeaponDamage = FireGun(Weapon, Interval);
                            if (WeaponDamage != 0)
                            {
                                TakingDamage = true;
                                if (ApplyDamage(WeaponDamage) == true)
                                {
                                    break;                                      // Target Destroyed!
                                }
                            }
                        }
                    }

                    Weapon = ship.Turrets[2];
                    if (ship.FireTurrets[2] == true)
                    {
                        if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                            (Weapon.EnergyConsumption > 0 && Battery > 0))
                        {
                            WeaponDamage = FireGun(Weapon, Interval);
                            if (WeaponDamage != 0)
                            {
                                TakingDamage = true;
                                if (ApplyDamage(WeaponDamage) == true)
                                {
                                    break;                                      // Target Destroyed!
                                }
                            }
                        }
                    }

                    Weapon = ship.Turrets[3];
                    if (ship.FireTurrets[3] == true)
                    {
                        if (((ReloadAmmoTime == 0 && ArmGunsTime == 0) && Weapon.AmmoConsumption > 0) ||
                            (Weapon.EnergyConsumption > 0 && Battery > 0))
                        {
                            WeaponDamage = FireGun(Weapon, Interval);
                            if (WeaponDamage != 0)
                            {
                                TakingDamage = true;
                                if (ApplyDamage(WeaponDamage) == true)
                                {
                                    break;                                      // Target Destroyed!
                                }
                            }
                        }
                    }

                    if (ship.FireMissile == true)
                    {
                        if (firingMissile != null)
                        {
                            if (firingMissile.SpecialEffect == MissileSpecialEffect.NerveGas)
                            {
                                _timeToKill = float.PositiveInfinity;
                                break;
                            }
                            if (ReloadMissileTime == 0 && ArmMissileTime == 0 && firingMissile.SpecialEffect != MissileSpecialEffect.Resonator)
                            {                                   // Not reloading or rearming missiles, fire it!
                                float MissileDamage = CalculateMissileDamage(firingMissile);

                                float WorkingRange = firingMissile.LifeSpan * firingMissile.Acceleration;
                                WorkingRange = WorkingRange / 2F;
                                WorkingRange = WorkingRange + firingMissile.LaunchVelocity + _launchSpeed;
                                WorkingRange = WorkingRange * firingMissile.LifeSpan;

                                if (WorkingRange > _range)
                                {
                                    _range = WorkingRange;
                                }

                                if (MissileDamage > 0)
                                {
                                    _missilesUsed += firingMissile.LaunchCount;
                                    MissilePack   -= firingMissile.LaunchCount;

                                    ArmMissileTime = firingMissile.ReloadTime;
                                    if (MissilePack == 0)
                                    {
                                        ReloadMissileTime = (1F / _object1.Core.Constants.MountRate);
                                    }

                                    TakingDamage = true;
                                    if (ApplyDamage(MissileDamage) == true)
                                    {
                                        break;                                          // Target Destroyed!
                                    }
                                }
                            }
                        }
                    }

                    // See if the target's shields started recharging
                    if (TakingDamage == true)
                    {
                        DownedShield = false;
                    }
                    else
                    {
                        // We're not damaging, and not reloading... so stop!
                        if (ReloadAmmoTime == 0 && ArmGunsTime == 0 &&
                            ArmTurret1Time == 0 && ArmTurret2Time == 0 &&
                            ArmTurret3Time == 0 && ArmTurret4Time == 0 &&
                            ReloadMissileTime == 0 && ArmMissileTime == 0)
                        {
                            _timeToKill = float.PositiveInfinity;
                            break;
                        }

                        if (DownedShield == false)
                        {
                            DownedShield = true;
                        }
                        else
                        {
                            if (ShieldHitpoints <= _object2.CalculateShieldHitpoints())
                            {
                                ShieldHitpoints += Interval * ShieldRecharge;
                            }
                        }
                    }

                    // All damage that could be done has been applied.
                    // reload, rearm, and recharge if needed
                    if (ReloadAmmoTime > 0)
                    {
                        ReloadAmmoTime = (float)Math.Round(ReloadAmmoTime - Interval, 1);
                        if (ReloadAmmoTime == 0)
                        {
                            if (HullHitpoints >= _object2.CalculateHullHitpoints() ||
                                (ShieldHitpoints >= _object2.CalculateShieldHitpoints() && _object2.CalculateShieldHitpoints() != 0))
                            {                                   // We just finished reloading, and it's full again. Stop now.
                                _timeToKill = float.PositiveInfinity;
                                break;
                            }
                            for (int i = 0; i < shipCargo.Length; i++)
                            {
                                if (shipCargo[i] != null)
                                {
                                    if (shipCargo[i] is IGCCorePartPack)
                                    {
                                        IGCCorePartPack Pack = (IGCCorePartPack)shipCargo[i];
                                        if (Pack.PackType == PackType.Ammo)
                                        {
                                            AmmoClip     = ship.IGCShip.AmmoCapacity;
                                            shipCargo[i] = null;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (ArmGunsTime > 0)
                    {
                        ArmGunsTime = (float)Math.Round(ArmGunsTime - Interval, 1);
                    }

                    if (Battery <= 0 && ship.CalculateEnergy() > 0)
                    {
                        if (_object2 != null)
                        {
                            if (HullHitpoints >= _object2.CalculateHullHitpoints())
                            {
                                _timeToKill = float.PositiveInfinity;
                                break;
                            }
                        }
                    }

                    if (Battery < ship.CalculateEnergy())
                    {
                        Battery += Interval * ship.CalculateEnergyRecharge();
                    }

                    if (ReloadMissileTime > 0)
                    {
                        ReloadMissileTime = (float)Math.Round(ReloadMissileTime - Interval, 1);
                        if (ReloadMissileTime == 0)
                        {
                            if (HullHitpoints >= _object2.CalculateHullHitpoints())
                            {                                   // We just finished reloading
                                if (ShieldHitpoints >= _object2.CalculateShieldHitpoints())
                                {                               //Shields have recharged during the reloading time - we'll never kill this. Stop now.
                                    _timeToKill = float.PositiveInfinity;
                                    break;
                                }
                            }
                            firingMissile = null;
                            for (int i = 0; i < shipCargo.Length; i++)
                            {
                                if (shipCargo[i] != null)
                                {
                                    if (shipCargo[i] is IGCCoreMissile)
                                    {
                                        IGCCoreMissile Missile = (IGCCoreMissile)shipCargo[i];
                                        if (ship.CanMountPart(Missile, ShipSlots.Missile))
                                        {
                                            firingMissile = Missile;
                                            MissilePack   = ship.IGCShip.MissileCapacity / Missile.CargoPayload;
                                            shipCargo[i]  = null;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (ArmMissileTime > 0)
                        {
                            ArmMissileTime = (float)Math.Round(ArmMissileTime - Interval, 1);
                        }
                    }
                }
                if (_object2 == null && _timeToKill >= 1F)                      // Stops calculating after 1 second for single-object Damage calcs
                {
                    _timeToKill = float.PositiveInfinity;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        private void ReadFromFile(string fileName)
        {
//			try
//			{
            FileStream CoreFS = File.OpenRead(fileName);
            DataReader Reader = new DataReader(CoreFS);

            int Size;
            int CoreSize;

            short Tag;

            _coreHeader = Reader.ReadUInt();
            CoreSize    = Reader.ReadInt();

            while (CoreFS.Position < (CoreSize + 8))
            {
                Tag  = Reader.ReadShort();
                Size = Reader.ReadInt();

                long Pos = CoreFS.Position;
                switch ((AGCObjectType)Tag)
                {
                case AGCObjectType.AGC_Constants:                                       // 21
                    _coreConstants = new IGCCoreConstants(Reader);
                    break;

                case AGCObjectType.AGC_StationType:                                     // 31;
                    _stationTypes.Add(new IGCCoreStationType(Reader));
                    break;

                case AGCObjectType.AGC_Civilization:                                    // 27
                    _civs.Add(new IGCCoreCiv(Reader));
                    break;

                case AGCObjectType.AGC_Development:                                     // 32
                    _devs.Add(new IGCCoreDevel(Reader));
                    break;

                case AGCObjectType.AGC_BucketStart:                                     //29
                    _ships.Add(new IGCCoreShip(Reader));
                    break;

                case AGCObjectType.AGC_PartType:                                        //30
                    IGCCorePart Part = null;
                    if (Size == 24)
                    {                                           // It's a spec part. Look up the real part and add it instead
                        IGCCorePartSpec Spec   = new IGCCorePartSpec(Reader);
                        ushort          PartID = Spec.UID;
                        ushort          RealID = (ushort)Spec.Group;

                        IGCCorePart Obj = null;
                        switch (Spec.Slot)
                        {
                        case "invchaff":
                            Obj = (IGCCorePart)_chaffs.GetObject(RealID);
                            IGCCoreCounter Counter = (IGCCoreCounter)Obj;
                            Counter.OverridingUID = Spec.OverridingUID;
                            break;

                        case "invsmissile":
                            Obj = (IGCCorePart)_missiles.GetObject(RealID);
                            IGCCoreMissile Missile = (IGCCoreMissile)Obj;
                            Missile.OverridingUID = Spec.OverridingUID;
                            Missile.LaunchCount   = (short)Spec.PartType;
                            Missile.QtyPerPack    = (short)Spec.Amount;
                            break;

                        case "invsmine":
                            Obj = (IGCCorePart)_mines.GetObject(RealID);
                            if (Obj == null)
                            {
                                Obj = (IGCCorePart)_probes.GetObject(RealID);
                                IGCCoreProbe Probe = (IGCCoreProbe)Obj;
                                Probe.OverridingUID = Spec.OverridingUID;
                            }
                            else
                            {
                                IGCCoreMine Mine = (IGCCoreMine)Obj;
                                Mine.OverridingUID = Spec.OverridingUID;
                            }
                            break;
                        }
                        if (Obj != null)
                        {
                            Obj.SpecUID = PartID;
                            _parts.Add(Obj);
                        }

                        break;
                    }

                    Reader.Seek(376);
                    short Type = Reader.ReadShort();
                    Reader.Seek(-378);
                    // 1 = weapon, 2 = shield, 5 = cloak, 7 = after, 6 = default
                    switch (Type)
                    {
                    case 1:
                        Part = new IGCCorePartWeapon(Reader);
                        break;

                    case 2:
                        //Part = new IGCCorePartShield(Reader);
                        break;

                    case 4:
                        Part = new IGCCorePartShield(Reader);
                        break;

                    case 5:
                        Part = new IGCCorePartCloak(Reader);
                        break;

                    case 7:
                        Part = new IGCCorePartAfterburner(Reader);
                        break;

                    case 6:
                        Part = new IGCCorePartPack(Reader);
                        break;

                    default:
                        break;
                    }
                    if (Part != null)
                    {
                        _parts.Add(Part);
                    }

                    break;

                case AGCObjectType.AGC_ChaffType:                                 // 26
                    _chaffs.Add(new IGCCoreCounter(Reader));
                    break;

                case AGCObjectType.AGC_MissileType:                                 // 23
                    _missiles.Add(new IGCCoreMissile(Reader));
                    break;

                case AGCObjectType.AGC_MineType:                                 // 24
                    _mines.Add(new IGCCoreMine(Reader));
                    break;

                case AGCObjectType.AGC_DroneType:
                    _drones.Add(new IGCCoreDrone(Reader));
                    break;

                case AGCObjectType.AGC_ProbeType:
                    _probes.Add(new IGCCoreProbe(Reader));
                    break;

                case AGCObjectType.AGC_ProjectileType:                                  //22
                    _projectiles.Add(new IGCCoreProjectile(Reader));
                    break;

                case AGCObjectType.AGC_TreasureSet:
                    _treasureSets.Add(new IGCCoreTreasureSet(Reader));
                    break;

                default:
                    break;
                }
                if (CoreFS.Position != Pos + Size)
                {
                    throw new Exception("Error occured while reading core file");
                }
            }
            CoreFS.Close();
            Reader = null;

//			}
//			catch (Exception e)
//			{
//				return;
//			}
            return;
        }