Exemple #1
0
        public override float CalculateSignature()
        {
            float Signature = _ship.Signature;

            for (int i = 0; i < _weapons.Length; i++)
            {
                IGCCorePartWeapon Weapon = _weapons[i];
                IGCCorePartWeapon Turret = _turrets[i];

                if (Weapon != null)
                {
                    if (_fireWeapons == true && (_weaponToFire == i || _weaponToFire == -1))
                    {
                        Signature += Weapon.Signature;
                    }
                }
                if (Turret != null)
                {
                    if (_fireTurrets[i] == true)
                    {
                        Signature += Turret.Signature;
                    }
                }
            }

            if (_missile != null)
            {
                Signature += _missile.Signature;
            }

            if (_shield != null)
            {
                Signature += _shield.Signature;
            }

            if (_fireBooster == true && _booster != null)
            {
                Signature += _booster.Signature;
            }

            Signature /= _factors.ShipSignature;

            if (_cloak != null)
            {
                if (_useCloak == true)
                {
                    Signature -= (_cloak.SignatureReduction * Signature);
                }
            }

            return(Signature);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weapon"></param>
        /// <returns>The amount of damage dealt by the weapon</returns>
        private float FireGun(IGCCorePartWeapon weapon, float interval)
        {
            Ship  ship         = (Ship)_object1;
            float WeaponDamage = 0F;

            // if we can't fire because of ammo or energy, return 0.
            if ((ReloadAmmoTime > 0 || AmmoClip == 0) && weapon.AmmoConsumption > 0)
            {
                return(0F);
            }

            if ((ArmGunsTime > 0 || AmmoClip == 0) && weapon.AmmoConsumption > 0)
            {
                return(0F);
            }

            if (weapon.EnergyConsumption > 0 && Battery <= 0)
            {
                return(0F);
            }

            IGCCoreProjectile Proj      = (IGCCoreProjectile)ship.Core.Projectiles.GetModule((ushort)weapon.ProjectileUID);
            float             ProjRange = Proj.Speed * Proj.Lifespan * Mods.PWRange;

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

            WeaponDamage = CalculateWeaponDamage(Proj, weapon.ShotInterval);
            if (WeaponDamage != 0)
            {
                float AmmoUsed   = weapon.AmmoConsumption * (interval / weapon.ShotInterval);
                float EnergyUsed = weapon.EnergyConsumption * (interval / weapon.ShotInterval);
                if (AmmoUsed <= AmmoClip)
                {                       // Remove the ammo used from the clip
                    AmmoClip  -= AmmoUsed;
                    _ammoUsed += AmmoUsed;
                    if (AmmoClip <= 0F)
                    {
                        ReloadAmmoTime = 4F;
                    }
                }
                else
                {                       // More ammo is needed than is in clip! Start reloading!
                    float PercentageUsed = AmmoClip / AmmoUsed;
                    WeaponDamage   = PercentageUsed * WeaponDamage;
                    _ammoUsed     += PercentageUsed * AmmoUsed;
                    AmmoClip       = 0F;
                    ReloadAmmoTime = 4F;
                    ArmGunsTime    = ReloadAmmoTime * weapon.TimeReady;
                }
                if (EnergyUsed <= Battery)
                {                       // Remove the energy from the battery
                    Battery     -= EnergyUsed;
                    _energyUsed += EnergyUsed;
                }
                else
                {                       // More energy is needed than is in battery!
                    float PercentageUsed = Battery / EnergyUsed;
                    WeaponDamage = PercentageUsed * WeaponDamage;
                    Battery      = 0F;
                }
            }
            return(WeaponDamage);
        }
Exemple #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;
        }