Ejemplo n.º 1
0
 public TerritoryDetails(MapDetails parent, TerritoryIDType id)
 {
     this.Parent        = parent;
     this.ID            = id;
     this.PartOfBonuses = new HashSet <BonusIDType>();
     this.ConnectedTo   = new HashSet <TerritoryIDType>();
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        /// <param name="numArmies">Can be negative to indicate we're freeing armies we previously used.</param>
        /// <returns>
        /// True if the change was successful. False if we couldn't do it.
        /// </returns>
        public bool TryRecordUsedArmies(TerritoryIDType territoryID, int numArmies)
        {
            Assert.Fatal(_income != null, "_income is null");
            if (numArmies == 0)
            {
                return(true); //no-op
            }
            else if (numArmies < 0)
            {
                return(TryRemoveUsedArmies(territoryID, -numArmies));
            }


            if (_income.BonusRestrictions.Count > 0)
            {
                var td = _map.Territories[territoryID];

                foreach (var bonusID in td.PartOfBonuses)
                {
                    if (_income.BonusRestrictions.ContainsKey(bonusID))
                    {
                        var used  = _armiesUsedOnBonuses.ValueOrZero(bonusID);
                        var avail = _income.BonusRestrictions[bonusID];
                        if (avail > used)
                        {
                            var toUse = SharedUtility.MathMin(numArmies, avail - used); //can't name a variable "use" in actionscript

                            if (_income.FreeArmies - _freeArmiesUsedOn.Values.Sum() < numArmies - toUse)
                            {
                                return(false); //We have some armies we could award from this bonus, but we wouldn't have enough free armies to award the rest of what's requested.  Therefore, abort now before recording bonus armies, so that the function doesn't change something and also return false.
                            }
                            _armiesUsedOnBonuses.AddTo(bonusID, toUse);
                            _freeArmiesUsedOn.AddTo(territoryID, numArmies - toUse);

                            return(true);
                        }
                    }
                }
            }

            //Take free armies.
            int freeAvail = _income.FreeArmies - _freeArmiesUsedOn.Values.Sum();

            if (freeAvail < numArmies)
            {
                return(false);
            }

            _freeArmiesUsedOn.AddTo(territoryID, numArmies);
            return(true);
        }
Ejemplo n.º 4
0
        public bool TryRemoveUsedArmies(TerritoryIDType territoryID, int armiesToRemove)
        {
            Assert.Fatal(_income != null, "_income is null");

            //First try to remove free income since those are the most important
            var freeUsedHere = _freeArmiesUsedOn.ValueOrZero(territoryID);

            if (freeUsedHere >= armiesToRemove)
            {
                _freeArmiesUsedOn.AddTo(territoryID, -armiesToRemove);
                return(true);
            }

            //Try to free bonus income if we can't satisfy it with free income
            if (_income.BonusRestrictions.Count > 0)
            {
                var needToRemoveFromBonus = armiesToRemove - freeUsedHere;

                var td = _map.Territories[territoryID];

                foreach (var bonusID in td.PartOfBonuses)
                {
                    if (_income.BonusRestrictions.ContainsKey(bonusID))
                    {
                        var used = _armiesUsedOnBonuses.ValueOrZero(bonusID);

                        if (used < needToRemoveFromBonus)
                        {
                            return(false); //can't remove enough from the bonus and free armies combined
                        }
                        _armiesUsedOnBonuses.AddTo(bonusID, -needToRemoveFromBonus);
                        _freeArmiesUsedOn.Remove(territoryID);

                        //Anytime we take bonus armies away, we could be in a situation where we could move free armies into bonus armies.  Check for this
                        CheckFreeMovingToBonus(bonusID);
                        return(true);
                    }
                }
            }

            return(false); //couldn't remove from bonuses and free armies combined
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the maximum number of armies that can be deployed on this territory beyond what's already deployed.  For example, if your income is 5, and you've already deployed 3 elsewhere, this will return 2.
        /// </summary>
        /// <param name="terrID"></param>
        /// <returns></returns>
        public int MaxAdditionalCanDeployOn(TerritoryIDType territoryID)
        {
            Assert.Fatal(_income != null, "_income is null");
            int freeAvail = this.FreeArmiesUndeployed;

            if (_income.BonusRestrictions.Count == 0)
            {
                return(freeAvail);
            }

            var td = _map.Territories[territoryID];

            foreach (var bonusID in td.PartOfBonuses)
            {
                if (_income.BonusRestrictions.ContainsKey(bonusID))
                {
                    return(freeAvail + _income.BonusRestrictions[bonusID] - _armiesUsedOnBonuses.ValueOrZero(bonusID));
                }
            }

            //No bonuses were restricted, just free can go here
            return(freeAvail);
        }
Ejemplo n.º 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.ArmiesToAirlift = numArmies;
            return(o);
        }
Ejemplo n.º 7
0
        public static GameOrderPlayCardAbandon Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType targetTerritoryID)
        {
            var o = new GameOrderPlayCardAbandon();

            o.CardInstanceID    = cardInstanceID;
            o.PlayerID          = (PlayerIDType)playerID;
            o.TargetTerritoryID = targetTerritoryID;
            return(o);
        }
Ejemplo n.º 8
0
        public static GameOrderPlayCardReconnaissance Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType targetTerritory)
        {
            var o = new GameOrderPlayCardReconnaissance();

            o.CardInstanceID  = cardInstanceID;
            o.PlayerID        = playerID;
            o.TargetTerritory = targetTerritory;
            return(o);
        }
Ejemplo n.º 9
0
        public static GameOrderPlayCardGift Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType terrID, PlayerIDType giftTo)
        {
            var o = new GameOrderPlayCardGift();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            o.TerritoryID    = terrID;
            o.GiftTo         = giftTo;
            return(o);
        }
Ejemplo n.º 10
0
 public TerritoryStanding(TerritoryIDType terrID, PlayerIDType playerID, Armies armies)
 {
     this.ID            = terrID;
     this.OwnerPlayerID = playerID;
     this.NumArmies     = armies;
 }