/// <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), false, specials)); }
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, false, specials)); }
public static Armies ToArmies(string str) { if (str == "Fogged") { return(new Armies(fogged: true)); } else { return(Armies.DeserializeFromString(str)); } }
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); }
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 TerritoryStanding(TerritoryIDType terrID, PlayerIDType playerID, Armies armies) { this.ID = terrID; this.OwnerPlayerID = playerID; this.NumArmies = armies; }