コード例 #1
0
        private void CalculateShield(InternalModel shieldgenerator, double basemass) {
            double baseshield = this.Data.SelectedShip.BaseShield;
            double shield = 0.0;
            double multiplier = 1.0;

            // get the shield boosters
            foreach (var u in _shipout.UtilityMounts)
                foreach (var j in u.Values) if (j.First == "SHIELD_MULT") 
                    multiplier += Double.Parse(j.Second); 

            if (shieldgenerator != null) {
                double minmass = 0, optmass = 0, maxmass = 0;
                double minmult = 0, optmult = 0, maxmult = 0;
                foreach (var value in shieldgenerator.Values) {
                    if (value.First == "Minmass") { minmass = Double.Parse(value.Second); }
                    else if (value.First == "Optmass") { optmass = Double.Parse(value.Second); }
                    else if (value.First == "Maxmass") { maxmass = Double.Parse(value.Second); }
                    else if (value.First == "Minmult") { minmult = Double.Parse(value.Second); }
                    else if (value.First == "Optmult") { optmult = Double.Parse(value.Second); }
                    else if (value.First == "Maxmult") { maxmult = Double.Parse(value.Second); }
                }
                // calcualte shield: formula based on "http://coriolis.io/" by Colin McLeod
                if (basemass < minmass) { shield = (baseshield * multiplier) * minmult; }
                else if (basemass > maxmass) { shield = (baseshield * multiplier) * maxmult; }
                else if (basemass < optmass) {
                    double opt = (optmass - basemass) / (optmass - minmass);
                    opt = 1 - Math.Pow(1 - opt, 0.87);
                    shield = (baseshield * multiplier) * ((opt * minmult) + ((1 - opt) * optmult));
                }
                else {
                    double opt = (optmass - basemass) / (maxmass - optmass);
                    opt = -1 + Math.Pow(1 + opt, 2.425);
                    shield = (baseshield * multiplier) * ((-1 * opt * maxmult) + ((1 + opt) * optmult));
                }
            }
            this.Data.Shield = Convert.ToInt32(shield);
        }
コード例 #2
0
        // ---------------------------------------------------------------------------------
        // --------------------------- ITEM SELECTION FUNCTIONS ----------------------------
        // ---------------------------------------------------------------------------------

        // Load new Item form DB, depending on the "ItemType" and
        // the Item-DatabaseID, returned from the "SelectionDialogView"
        private void LoadNewItem(SelectedIDEventArgs e) {
            if (this._updateItem.Second == ItemType.HARDPOINT) {
                int maxclass = this.Data.Hardpoints[_updateItem.First].MaxClass;
                HardpointModel tmp = new HardpointModel(this._loader.ItemID, maxclass);
                if(e.Addition != "empty") tmp = this._loader.loadHardpoint(e.ItemID, maxclass);
                List<HardpointModel> hps = this.Data.Hardpoints;
                hps[this._updateItem.First] = tmp;
                this.Data.Hardpoints = new List<HardpointModel>();
                this.Data.Hardpoints = hps;
            } else if (this._updateItem.Second == ItemType.BULKHEADS) {
                var tmp = this._loader.loadBasic<BulkheadModel>(e.ItemID, Data.SelectedBulkhead.MaxClass);
                List<BulkheadModel> bhm = new List<BulkheadModel>() { tmp };
                this.Data.Bulkheads = new List<BulkheadModel>();
                this.Data.Bulkheads = bhm;
            } else if (this._updateItem.Second == ItemType.POWERPLANT) {
                var tmp = this._loader.loadBasic<PowerPlantModel>(e.ItemID, Data.SelectedPowerPlant.MaxClass);
                List<PowerPlantModel> ppm = new List<PowerPlantModel>() { tmp };
                this.Data.PowerPlants = new List<PowerPlantModel>();
                this.Data.PowerPlants = ppm;
            } else if (this._updateItem.Second == ItemType.THURSTER) {
                var tmp = this._loader.loadBasic<ThrusterModel>(e.ItemID, Data.SelectedThruster.MaxClass);
                List<ThrusterModel> tm = new List<ThrusterModel>() { tmp };
                this.Data.Thrusters = new List<ThrusterModel>();
                this.Data.Thrusters = tm;
            } else if (this._updateItem.Second == ItemType.FSD) {
                var tmp = this._loader.loadBasic<FSDModel>(e.ItemID, Data.SelectedFSD.MaxClass);
                List<FSDModel> fsdm = new List<FSDModel>() { tmp };
                this.Data.FSDs = new List<FSDModel>();
                this.Data.FSDs = fsdm;
            } else if (this._updateItem.Second == ItemType.LIFESUPPORT) {
                var tmp = this._loader.loadBasic<LifeSupportModel>(e.ItemID, Data.SelectedLifeSupport.MaxClass);
                List<LifeSupportModel> lsms = new List<LifeSupportModel>() { tmp };
                this.Data.LifeSupports = new List<LifeSupportModel>();
                this.Data.LifeSupports = lsms;
            } else if (this._updateItem.Second == ItemType.POWERDISTRIB) {
                var tmp = this._loader.loadBasic<PowerDistributorModel>(e.ItemID, Data.SelectedPowerDistrib.MaxClass);
                List<PowerDistributorModel> pdms = new List<PowerDistributorModel>() { tmp };
                this.Data.PowerDistributors = new List<PowerDistributorModel>();
                this.Data.PowerDistributors = pdms;
            } else if (this._updateItem.Second == ItemType.SENSORES) {
                var tmp = this._loader.loadBasic<SensorsModel>(e.ItemID, Data.SelectedSensor.MaxClass);
                List<SensorsModel> sms = new List<SensorsModel>() { tmp };
                this.Data.Sensors = new List<SensorsModel>();
                this.Data.Sensors = sms;
            } else if (this._updateItem.Second == ItemType.FUELTANK) {
                var tmp = this._loader.loadBasic<FuelTankModel>(e.ItemID, Data.SelectedFuelTank.MaxClass);
                List<FuelTankModel> ftms = new List<FuelTankModel>() { tmp };
                this.Data.FuelTanks = new List<FuelTankModel>();
                this.Data.FuelTanks = ftms;
            } else if (this._updateItem.Second == ItemType.UTILITY) {
                UtilityModel tmp = new UtilityModel(this._loader.ItemID);
                if (e.Addition != "empty") tmp = this._loader.loadUtility(e.ItemID, e.Addition);
                List<UtilityModel> ums = this.Data.UtilityMounts;
                ums[this._updateItem.First] = tmp;
                this.Data.UtilityMounts = new List<UtilityModel>();
                this.Data.UtilityMounts = ums;
            } else if (this._updateItem.Second == ItemType.INTERNAL) {
                int maxclass = this.Data.InternalComps1[_updateItem.First].MaxClass;
                InternalModel tmp = new InternalModel(this._loader.ItemID, maxclass);
                if (e.Addition != "empty") tmp = this._loader.loadInternal(e.ItemID, e.Addition, maxclass);
                List<InternalModel> ints = this.Data.InternalComps1;
                ints[this._updateItem.First] = tmp;
                this.Data.InternalComps1 = new List<InternalModel>();
                this.Data.InternalComps1 = ints;
            } else if (this._updateItem.Second == ItemType.INTERNALX) {
                int maxclass = this.Data.InternalComps2[_updateItem.First].MaxClass;
                InternalModel tmp = new InternalModel(this._loader.ItemID, maxclass);
                if (e.Addition != "empty") tmp = this._loader.loadInternal(e.ItemID, e.Addition, maxclass);
                List<InternalModel> ints = this.Data.InternalComps2;
                ints[this._updateItem.First] = tmp;
                this.Data.InternalComps2 = new List<InternalModel>();
                this.Data.InternalComps2 = ints;
            }
            // Fire Event, when the Outfitting Item was changed
            OutfittingChangedEventArgs eventargs = new OutfittingChangedEventArgs(this.Data, false);
            this._eventAggregator.GetEvent<OutfittingChangedEvent>().Publish(eventargs);
        }
コード例 #3
0
        // ---------------------------------------------------------------------------------
        // --------------------------- STAT CALCULATION FUNCTIONS --------------------------
        // ---------------------------------------------------------------------------------

        private void CalculateAttributes() {
            // Important Variables : "cost", "powers" and "masses"
            double mass = this.Data.SelectedShip.HullMass, massladen = 0.0;
            double power = _shipout.PowerPlants[0].Power, powerret = 0, powerdep = 0;
            int cost = Int32.Parse(this.Data.SelectedShip.Cost.Replace(".", ""));
            int dps = 0, cargo = 0, fuel = 0; 
            InternalModel shieldgenerator = new InternalModel(0, 0);

            // Main Calculations : cost, powers, masses, cargo, fuel and dps
            // hardpoints and utility
            foreach (var h in _shipout.Hardpoints) { mass += h.Mass; cost += h.Cost; dps += h.DPS; powerdep += h.PowerDraw; }
            foreach (var u in _shipout.UtilityMounts) { 
                mass += u.Mass; cost += u.Cost;
                if (u.Name != null) {
                    if (u.Name.Contains("Scanner")) { powerdep += u.Power; }
                    else if (u.Name.Contains("Countermeasure")) { powerdep += u.Power; }
                    else { powerret += u.Power; }
                }
            }
            // add the basics
            mass += CalculateBasicsMass();
            cost += CalculateBasicsCost();
            powerret += CalculateBasicsPower();
            massladen += _shipout.FuelTanks[0].Capacity;
            fuel += _shipout.FuelTanks[0].Capacity;
            // internal compartments
            foreach (var intern in _combinedInternals) {
                cost += intern.Cost;
                if (intern.Name == "Shield Generator") { shieldgenerator = intern; }
                else if (intern.Name == "Pristmatic Shield Generator") { shieldgenerator = intern; }
                else if (intern.Name == "Bi-Weave Shield Generator") { shieldgenerator = intern; }
                else if (intern.Name == "Cargo Rack") { cargo += Int32.Parse(intern.Values[0].Second); }
                else if (intern.Name == "Internal Fuel Tank") { fuel += Int32.Parse(intern.Values[0].Second); }
                foreach (var value in intern.Values) {
                    if (value.First == "Mass") { mass += Double.Parse(value.Second); }
                    else if (value.First == "Capacity") { massladen += Double.Parse(value.Second); }
                    else if (value.First == "Power") powerret += Double.Parse(value.Second); 
                }
            }
            massladen += mass;
            powerret += 0.6; // Cargo Hatch
            powerdep += powerret;
            
            // set the calculated values
            this.Data.Hullunladen = mass.ToString("0.#");
            this.Data.Hullladen = massladen.ToString("0.#");
            this.Data.Price = cost.ToString("N0");
            this.Data.TmpPrice = this.Data.Price;
            this.Data.Insurance = ((cost / 100) * 5).ToString("N0");
            this.Data.Dps = dps;
            this.Data.Cargo = cargo.ToString() + ".0 T";
            this.Data.Fuel = fuel.ToString() + ".0 T";
            this.Data.Poweravail = power.ToString() + "   ( 100% )";
            this.Data.Powerretr = powerret.ToString() + "   ( " + ((powerret / power) * 100).ToString("0.#") + "% )";
            this.Data.Powerdepl = powerdep.ToString() + "   ( " + ((powerdep / power) * 100).ToString("0.#") + "% )";

            // calculate the rest
            CalculateArmour();
            CalculateShield(shieldgenerator, this.Data.SelectedShip.HullMass);
            CalcualteSpeedBoost(mass);
            CalculateJumprange(mass, massladen, fuel);
        }