Beispiel #1
0
        /// <summary>
        /// Sets the percent of a party in the population group equal to the desired value.
        /// It will take shares from all others proportionally.
        /// </summary>
        /// <param name="pol">The political group we are setting.</param>
        /// <param name="percent">The percent we are setting it to.</param>
        public void SetPartyPercent(PoliticalGroup pol, double percent)
        {
            if (percent <= 0 || percent > 1)
            {
                throw new ArgumentOutOfRangeException("Percent must be greater than 0 or less than or equal to 1.");
            }

            if (!PoliticalBreakdown.Any(x => x.PoliticalGroup.Id == pol.Id))
            {
                PoliticalBreakdown.Add(new PoliticalBreakdown
                {
                    ParentId         = Id,
                    Percent          = 0,
                    PoliticalGroupId = pol.Id
                });
            }

            double oldPercent = PoliticalBreakdown
                                .Single(x => x.PoliticalGroupId == pol.Id)
                                .Percent;

            double add = (oldPercent - percent) / (percent - 1);

            PoliticalBreakdown
            .Single(x => x.PoliticalGroupId == pol.Id)
            .Percent += add;

            var newSum = PolPercent();

            foreach (var group in PoliticalBreakdown)
            {
                group.Percent = group.Percent / newSum;
            }
        }
Beispiel #2
0
        public void RemoveEnemy(PoliticalGroup other)
        {
            if (!Enemies.Contains(other))
            {
                return;
            }

            Enemies.Remove(other);
            EnemiesRev.Remove(other);

            other.RemoveEnemy(this);
        }
Beispiel #3
0
        public void AddEnemy(PoliticalGroup other)
        {
            if (Enemies.Contains(other))
            {
                return;
            }

            Enemies.Add(other);
            EnemiesRev.Add(other);

            other.AddEnemy(this);
        }
Beispiel #4
0
        public void RemoveAlly(PoliticalGroup other)
        {
            if (!Allies.Contains(other))
            {
                return;
            }

            Allies.Remove(other);
            AlliesRev.Remove(other);

            other.RemoveAlly(this);
        }
Beispiel #5
0
        public void AddAlly(PoliticalGroup other)
        {
            if (Allies.Contains(other))
            {
                return;
            }

            Allies.Add(other);
            AlliesRev.Add(other);

            other.AddAlly(this);
        }
Beispiel #6
0
        public void ShiftPartyPercent(PoliticalGroup pol, double percent)
        {
            if (!PoliticalBreakdown.Any(x => x.PoliticalGroup == pol))
            {
                PoliticalBreakdown.Add(new PoliticalBreakdown
                {
                    ParentId         = Id,
                    Percent          = 0,
                    PoliticalGroupId = pol.Id
                });
            }

            PoliticalBreakdown.Single(x => x.PoliticalGroupId == pol.Id)
            .Percent += percent;

            var newSum = PolPercent();

            foreach (var group in PoliticalBreakdown)
            {
                group.Percent = group.Percent / newSum;
            }
        }