Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff api/Objects/Army.cs @ 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 27 Jun 2009 18:59:49 +0000 |
parents | 3fa4658c50c6 |
children | 89cc29b4c012 |
line wrap: on
line diff
--- a/api/Objects/Army.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/Army.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,52 +2,52 @@ // // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. -using System; +using System; using System.IO; -using System.Collections.Generic; -using System.Text; -using System.Xml; +using System.Collections.Generic; +using System.Text; +using System.Xml; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Factories; using IBBoard.WarFoundry.API.Requirements; -using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for Army. - /// </summary> - public class Army : WarFoundryObject - { - //private GameSystem system; - private Race armyRace; - private int maxPoints; - private double pointsTotal; - private Dictionary<Category, ArmyCategory> categories; - - public event ObjectAddDelegate UnitAdded; - public event ObjectRemoveDelegate UnitRemoved; - public event FailedUnitRequirementDelegate FailedRequirement; - public event DoubleValChangedDelegate PointsValueChanged; +using ICSharpCode.SharpZipLib.Zip; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for Army. + /// </summary> + public class Army : WarFoundryObject + { + //private GameSystem system; + private Race armyRace; + private int maxPoints; + private double pointsTotal; + private Dictionary<Category, ArmyCategory> categories; + + public event ObjectAddDelegate UnitAdded; + public event ObjectRemoveDelegate UnitRemoved; + public event FailedUnitRequirementDelegate FailedRequirement; + public event DoubleValChangedDelegate PointsValueChanged; private DoubleValChangedDelegate PointsValueChangedMethod; public Army(Race race, string armyName, int maxArmyPoints) : this(race, armyName, maxArmyPoints, null) { - } - - public Army(Race race, string armyName, int maxArmyPoints, ZipFile file) : base(armyName) - { - armyRace = race; - Name = armyName; - maxPoints = maxArmyPoints; - PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler); } - - public ArmyCategory GetCategory(Category cat) - { - ArmyCategory armyCat = null; - ArmyCategories.TryGetValue(cat, out armyCat); - return armyCat; + + public Army(Race race, string armyName, int maxArmyPoints, ZipFile file) : base(armyName) + { + armyRace = race; + Name = armyName; + maxPoints = maxArmyPoints; + PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler); + } + + public ArmyCategory GetCategory(Category cat) + { + ArmyCategory armyCat = null; + ArmyCategories.TryGetValue(cat, out armyCat); + return armyCat; } private Dictionary<Category, ArmyCategory> ArmyCategories @@ -74,197 +74,194 @@ return categories; } - } - - public ArmyCategory[] Categories - { - get - { - return DictionaryUtils.ToArray<Category, ArmyCategory>(ArmyCategories); - } - } - - public Race Race - { - get { return armyRace; } - } - - public GameSystem GameSystem - { - get { return (armyRace!=null ? armyRace.GameSystem : null); } - } - - protected void OnUnitAdded(Unit unit) - { - OnUnitAdded(unit, null); - } - - protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) - { - if (UnitAdded!=null) - { - UnitAdded(unit); - } - - if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) - { - FailedRequirement(failedReqs); - } - } - - protected void OnUnitRemoved(Unit unit) - { - OnUnitRemoved(unit, null); - } - - protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs) - { - if (UnitRemoved!=null) - { - UnitRemoved(unit); - } - - if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) - { - FailedRequirement(failedReqs); - } - } - - private void OnPointsValueChanged(double oldValue, double newValue) - { - if (PointsValueChanged!=null) - { - PointsValueChanged(this, oldValue, newValue); - } + } + + public ArmyCategory[] Categories + { + get + { + return DictionaryUtils.ToArray<Category, ArmyCategory>(ArmyCategories); + } + } + + public Race Race + { + get { return armyRace; } + } + + public GameSystem GameSystem + { + get { return (armyRace!=null ? armyRace.GameSystem : null); } + } + + protected void OnUnitAdded(Unit unit) + { + OnUnitAdded(unit, null); + } + + protected void OnUnitAdded(Unit unit, List<FailedUnitRequirement> failedReqs) + { + if (UnitAdded!=null) + { + UnitAdded(unit); + } + + if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) + { + FailedRequirement(failedReqs); + } } - - private double TotalPoints - { - get { return pointsTotal; } - set - { - double oldPoints = pointsTotal; - pointsTotal = value; - - if (oldPoints!=pointsTotal) - { - OnPointsValueChanged(oldPoints, pointsTotal); - } - } - } - - public double PointsTotal - { - get { return TotalPoints; } + + protected void OnUnitRemoved(Unit unit) + { + OnUnitRemoved(unit, null); + } + + protected void OnUnitRemoved(Unit unit, List<FailedUnitRequirement> failedReqs) + { + if (UnitRemoved!=null) + { + UnitRemoved(unit); + } + + if (FailedRequirement!=null && failedReqs!=null && failedReqs.Count > 0) + { + FailedRequirement(failedReqs); + } + } + + private void OnPointsValueChanged(double oldValue, double newValue) + { + if (PointsValueChanged!=null) + { + PointsValueChanged(this, oldValue, newValue); + } + } + + private double TotalPoints + { + get { return pointsTotal; } + set + { + double oldPoints = pointsTotal; + pointsTotal = value; + + if (oldPoints!=pointsTotal) + { + OnPointsValueChanged(oldPoints, pointsTotal); + } + } + } + + public double PointsTotal + { + get { return TotalPoints; } } public void AddUnit(Unit unit) { - List<FailedUnitRequirement> failedReqs = CanAddUnit(unit); unit.Army = this; ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory); armyCat.AddUnit(unit); - OnUnitAdded(unit, failedReqs); } public void RemoveUnit(Unit unit) { List<FailedUnitRequirement> failedReqs = CanRemoveUnit(unit); unit.Army = null; - ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory); - armyCat.RemoveUnit(unit); + unit.Category.RemoveUnit(unit); OnUnitRemoved(unit, failedReqs); - } - - public Unit[] GetUnits(Category cat) - { - return GetUnits(this.GetCategory(cat)); - } - - public Unit[] GetUnits(ArmyCategory cat) - { - return cat.GetUnits(); - } - - public Unit[] GetUnits() - { - List<Unit> fullList = new List<Unit>(); - - foreach(ArmyCategory cat in Categories) + } + + public Unit[] GetUnits(Category cat) + { + return GetUnits(this.GetCategory(cat)); + } + + public Unit[] GetUnits(ArmyCategory cat) + { + return cat.GetUnits(); + } + + public Unit[] GetUnits() + { + List<Unit> fullList = new List<Unit>(); + + foreach(ArmyCategory cat in Categories) + { + fullList.AddRange(cat.GetUnits()); + } + + return fullList.ToArray(); + } + + public int MaxPoints + { + get { return maxPoints; } + set + { + if (value > 0) + { + maxPoints = value; + } + } + } + + private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal) + { + if (obj is ArmyCategory) { - fullList.AddRange(cat.GetUnits()); - } - - return fullList.ToArray(); - } - - public int MaxPoints - { - get { return maxPoints; } - set - { - if (value > 0) - { - maxPoints = value; - } - } - } - - private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal) - { - if (obj is ArmyCategory) - { - double points = 0; - - foreach (ArmyCategory cat in Categories) - { - points+= cat.PointsTotal; - } - - TotalPoints = points; - } - } - - public List<FailedUnitRequirement> CanAddUnit(Unit unit) - { - return CanAddUnitType(unit.UnitType); - } - - public List<FailedUnitRequirement> CanAddUnitType(UnitType unitType) - { - return unitType.CanAddToArmy(this); - } - - public List<FailedUnitRequirement> CanRemoveUnit(Unit unit) - { - return CanRemoveUnitType(unit.UnitType); - } - - public List<FailedUnitRequirement> CanRemoveUnitType(UnitType unitType) - { - return unitType.CanRemoveFromArmy(this); - } - - public int GetUnitTypeCount(UnitType unitType) - { - int count = 0; - - foreach (ArmyCategory cat in Categories) - { - count+= cat.GetUnitTypeCount(unitType); - } - - return count; - } - - private void Army_UnitAdded(object val) - { - OnUnitAdded((Unit)val); - } - - private void Army_UnitRemoved(object val) - { - OnUnitRemoved((Unit)val); - } - } -} + double points = 0; + + foreach (ArmyCategory cat in Categories) + { + points+= cat.PointsTotal; + } + + TotalPoints = points; + } + } + + public List<FailedUnitRequirement> CanAddUnit(Unit unit) + { + return CanAddUnitType(unit.UnitType); + } + + public List<FailedUnitRequirement> CanAddUnitType(UnitType unitType) + { + return unitType.CanAddToArmy(this); + } + + public List<FailedUnitRequirement> CanRemoveUnit(Unit unit) + { + return CanRemoveUnitType(unit.UnitType); + } + + public List<FailedUnitRequirement> CanRemoveUnitType(UnitType unitType) + { + return unitType.CanRemoveFromArmy(this); + } + + public int GetUnitTypeCount(UnitType unitType) + { + int count = 0; + + foreach (ArmyCategory cat in Categories) + { + count+= cat.GetUnitTypeCount(unitType); + } + + return count; + } + + private void Army_UnitAdded(object val) + { + OnUnitAdded((Unit)val); + } + + private void Army_UnitRemoved(object val) + { + OnUnitRemoved((Unit)val); + } + } +}