Esempio n. 1
0
        bool IsCurrentSettingCloserToMinimumValue(Weapon weapon)
        {
            Setting setting = weapon.Access(WeaponSetting);
            int     differenceBetweenMin = setting.Value - _minimumSettingValue.Value;
            int     differenceBetweenMax = _maximumSettingValue.Value - setting.Value;

            Debug.Assert(differenceBetweenMin >= 0 && differenceBetweenMax >= 0);
            return(differenceBetweenMax > differenceBetweenMin);
        }
Esempio n. 2
0
        public Scheme GenerateScheme(Random rng, SchemeVersion version)
        {
            Scheme scheme = new Scheme(version, ExtendedOptionsDataVersion);

            //Generate values for every setting.
            int settingsCount = Math.Min(scheme.Settings.Length, _settingGenerators.Length);

            for (int i = 0; i < settingsCount; ++i)
            {
                ValueGenerator valueGenerator = _settingGenerators[i];

                if (valueGenerator != null)
                {
                    SettingTypes settingType = (SettingTypes)i;
                    Setting      setting     = scheme.Access(settingType);
                    Debug.Assert(setting != null);

                    setting.SetValue(valueGenerator.GenerateValue(rng), valueGenerator);
                }
            }

            //Generate values for every weapon.
            int weaponsCount = Math.Min(scheme.Weapons.Length, _weaponGenerators.Length);

            for (int i = 0; i < weaponsCount; ++i)
            {
                WeaponGenerator weaponGenerator = _weaponGenerators[i];

                for (int j = 0; j < (int)WeaponSettings.Count; ++j)
                {
                    WeaponSettings weaponSetting  = (WeaponSettings)j;
                    ValueGenerator valueGenerator = weaponGenerator.Get(weaponSetting);

                    if (valueGenerator != null)
                    {
                        WeaponTypes weaponType = (WeaponTypes)i;
                        Weapon      weapon     = scheme.Access(weaponType);
                        Debug.Assert(weapon != null);

                        Setting setting = weapon.Access(weaponSetting);
                        Debug.Assert(setting != null);

                        //Check value generator range (range check is not done at XML parsing-time for default values).
                        if (!valueGenerator.IsValueRangeWithinLimits(setting.Limits))
                        {
                            throw new Exception(String.Format("Generatable values for setting '{0}' must be within the range(s): {1}.",
                                                              setting.Name, setting.Limits.ToString()));
                        }

                        setting.SetValue(valueGenerator.GenerateValue(rng), valueGenerator);
                    }
                }
            }

            //Generate values for every extended option.
            if (version >= SchemeVersion.Armageddon3)
            {
                int optionsCount = Math.Min(scheme.ExtendedOptions.Length, _extendedOptionGenerators.Length);
                for (int i = 0; i < optionsCount; ++i)
                {
                    ValueGenerator valueGenerator = _extendedOptionGenerators[i];
                    if (valueGenerator != null)
                    {
                        ExtendedOptionTypes extendedOption = (ExtendedOptionTypes)i;
                        Setting             setting        = scheme.Access(extendedOption);
                        Debug.Assert(setting != null);

                        setting.SetValue(valueGenerator.GenerateValue(rng), valueGenerator);
                    }
                }
            }

            //Handle guarantees.
            foreach (Guarantee guarantee in _guarantees)
            {
                guarantee.ApplyGuarantee(scheme, rng);
            }

            return(scheme);
        }