Example #1
0
        /// <summary>
        /// Will remove the armies only if both this object and the passed Armies are not fogged
        /// Will never allow armies to be negative.
        /// </summary>
        /// <param name="armies"></param>
        public Armies Subtract(Armies armies)
        {
            if (this.Fogged || armies.Fogged)
            {
                return(this);
            }

            SpecialUnit[] specials;

            if (SpecialUnits.Length == 0)
            {
                specials = SpecialUnits; //we have none, so there's nothing to subtract.  This is by far the most common case, so check for it first.
            }
            else if (armies.SpecialUnits.Length == 0)
            {
                specials = SpecialUnits; //not subtracting any special units, carry ours forward
            }
            else
            {
                //It's OK to do a N^2 algorithm here since our array length is usually 1, and never higher than 3. It's likely slower to allocate a dictionary.
                var list = new List <SpecialUnit>(SpecialUnits.Length);

                foreach (var spec in SpecialUnits)
                {
                    if (armies.SpecialUnits.None(o => o.ID == spec.ID))
                    {
                        list.Add(spec);
                    }
                }
                specials = list.ToArray();
            }

            return(new Armies(Math.Max(0, this._numArmies - armies._numArmies), specials));
        }
Example #2
0
        public Armies Add(Armies armies)
        {
            if (this.Fogged || armies.Fogged)
            {
                return(this);
            }

            SpecialUnit[] specials;

            if (armies.SpecialUnits.Length == 0)
            {
                specials = SpecialUnits; //we're adding none, so just keep what we have
            }
            else
            {
                //It's OK to do a N^2 algorithm here since our array length is usually 1, and never higher than 3. It's likely slower to allocate a dictionary.
                var ourSpecialCount = SpecialUnits.Length;
                specials = new SpecialUnit[ourSpecialCount + armies.SpecialUnits.Length];

                for (int i = 0; i < SpecialUnits.Length; i++)
                {
                    specials[i] = SpecialUnits[i].Clone();
                }

                for (int i = 0; i < armies.SpecialUnits.Length; i++)
                {
                    specials[i + ourSpecialCount] = armies.SpecialUnits[i].Clone();
                }
            }


            return(new Armies(this._numArmies + armies._numArmies, specials));
        }
Example #3
0
 public static Armies ToArmies(string str)
 {
     if (str == "Fogged")
     {
         return(new Armies(fogged: true));
     }
     else
     {
         return(Armies.DeserializeFromString(str));
     }
 }
        public static GameOrderAttackTransfer Create(PlayerIDType playerID, TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, bool byPercent, Armies armies, bool attackTeammates)
        {
            var r = new GameOrderAttackTransfer();

            r.PlayerID        = playerID;
            r.From            = from;
            r.To              = to;
            r.AttackTransfer  = attackTransfer;
            r.ByPercent       = byPercent;
            r.NumArmies       = armies;
            r.AttackTeammates = attackTeammates;
            return(r);
        }
        public static GameOrderAttackTransfer Create(PlayerIDType playerID, TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, Armies armies, String reason)
        {
            var r = new GameOrderAttackTransfer();

            r.PlayerID        = playerID;
            r.From            = from;
            r.To              = to;
            r.AttackTransfer  = attackTransfer;
            r.ByPercent       = false;
            r.NumArmies       = armies;
            r.AttackTeammates = true;
            r.Reason          = reason;
            return(r);
        }
Example #6
0
        public static GameOrderPlayCardAirlift Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType fromTerritoryID, TerritoryIDType toTerritoryID, Armies numArmies)
        {
            var o = new GameOrderPlayCardAirlift();

            o.CardInstanceID  = cardInstanceID;
            o.PlayerID        = playerID;
            o.FromTerritoryID = fromTerritoryID;
            o.ToTerritoryID   = toTerritoryID;
            o.NumArmies       = numArmies;
            return(o);
        }
        public static TerritoryStanding Create(TerritoryIDType territoryID, PlayerIDType owner, Armies armies)
        {
            TerritoryStanding cs = new TerritoryStanding();

            cs.ID                      = territoryID;
            cs.OwnerPlayerID           = owner;
            cs.NumArmies               = armies;
            cs.ArmiesMarkedAsUsed      = new Armies();
            cs.TerritoriesMarkedAsUsed = new List <TerritoryIDType>();
            return(cs);
        }
        public static TerritoryStanding Create(TerritoryIDType territoryID, PlayerIDType owner, Armies armies)
        {
            TerritoryStanding cs = new TerritoryStanding();

            cs.ID            = territoryID;
            cs.OwnerPlayerID = owner;
            cs.NumArmies     = armies;
            return(cs);
        }