# HG changeset patch # User IBBoard # Date 1237493467 0 # Node ID 548cfc776f54aef817655608d3da33fc68708635 # Parent 465a215a21a27490062750473b8a1f188adddd9f Fixes #34 - Remove "Choices" and "Base/Increment" from Category * Remove Choices and Base/Increment from code Re #47: Remove magic numbers * Replace "-1" magic number with WarFoundryCore.INFINITY * Use INFINITY instead of -1 in code * Use INF in schemas instead of -1 * Handle and parse INF as a special value in XML Factory diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/Category.cs --- a/api/Objects/Category.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/Category.cs Thu Mar 19 20:11:07 2009 +0000 @@ -14,14 +14,9 @@ public class Category : WarFoundryObject { private int minPts = 0; - private int maxPts = -1; + private int maxPts = WarFoundryCore.INFINITY; private int minPc = 0; private int maxPc = 100; - private int minChoice = 0; - private int maxChoice = -1; - private int baseVal = 0; - private int incVal = 0; - private int incAmount = 0; public Category(string id, string name) : base(id, name) @@ -35,9 +30,6 @@ MaximumPoints = maxPoints; MinimumPercentage = minPercent; MaximumPercentage = maxPercent; - BaseValue = baseValue; - IncrementValue = incrementValue; - IncrementAmount = incrementAmount; } protected override string DefaultName() @@ -60,14 +52,14 @@ get { return maxPts; } set { - maxPts = (value >= -1 ? value : -1); + maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumPoints(); } } private void CheckMinimumPoints() { - if (MinimumPoints > MaximumPoints && MaximumPoints!=-1) + if (MinimumPoints > MaximumPoints && MaximumPoints!=WarFoundryCore.INFINITY) { MinimumPoints = MaximumPoints; LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum points limit greater than its maximum points limit.", Name, ID); @@ -114,52 +106,5 @@ LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); } } - - public int MinimumChoices - { - get { return minChoice; } - set - { - minChoice = (value >= 0 ? value : 0); - CheckMinimumChoices(); - } - } - - public int MaximumChoices - { - get { return maxChoice; } - set - { - maxChoice = (value >= -1 ? value : -1); - CheckMinimumChoices(); - } - } - - private void CheckMinimumChoices() - { - if (MinimumPercentage > MaximumPercentage && MaximumPercentage!=-1) - { - MinimumPercentage = MaximumPercentage; - LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum number of choices greater than its maximum number of choices.", Name, ID); - } - } - - public int BaseValue - { - get { return baseVal; } - set { baseVal = (value >= 0 ? value : 0); } - } - - public int IncrementValue - { - get { return incVal; } - set { incVal = (value >= 0 ? value : 0); } - } - - public int IncrementAmount - { - get { return incAmount; } - set { incAmount = (value >= 0 ? value : 0); } - } } } diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/EquipmentItem.cs --- a/api/Objects/EquipmentItem.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/EquipmentItem.cs Thu Mar 19 20:11:07 2009 +0000 @@ -35,9 +35,9 @@ get { return min; } set { - min = (value >= 0 || value == -1) ? value : 0; + min = (value >= 0 || value == WarFoundryCore.INFINITY) ? value : 0; - if (MaxNumber != -1 && min > MaxNumber) + if (MaxNumber != WarFoundryCore.INFINITY && min > MaxNumber) { MaxNumber = min; } @@ -49,9 +49,9 @@ get { return max; } set { - max = (value > 0 || value == -1) ? value : -1; + max = (value > 0 || value == WarFoundryCore.INFINITY) ? value : WarFoundryCore.INFINITY; - if (max != -1 && MinNumber > max) + if (max != WarFoundryCore.INFINITY && MinNumber > max) { MinNumber = max; } diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/GameSystem.cs --- a/api/Objects/GameSystem.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/GameSystem.cs Thu Mar 19 20:11:07 2009 +0000 @@ -160,7 +160,7 @@ public bool UnitTypeMaxed(UnitType unitType, Army army) { - return unitType.MaxNumber!=-1 && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; + return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; } public bool UnitTypeMinned(UnitType unitType, Army army) diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/Unit.cs --- a/api/Objects/Unit.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/Unit.cs Thu Mar 19 20:11:07 2009 +0000 @@ -99,7 +99,7 @@ } else { - if (count == -1) + if (count == WarFoundryCore.INFINITY) { points+= size * equipItem.Cost; } @@ -288,7 +288,7 @@ } else { - if (amount >=1 || amount == -1) + if (amount >=1 || amount == WarFoundryCore.INFINITY) { amount = (float)Math.Round(amount); } @@ -307,7 +307,7 @@ if (amount!=oldAmount) { - if (amount > 0 || amount == -1) + if (amount > 0 || amount == WarFoundryCore.INFINITY) { equipment[equipID] = amount; } @@ -369,41 +369,5 @@ { get { return UnitType.UnitStats; } } - - /*public override string ToXmlString() - { - StringBuilder sb = new StringBuilder(); - float amount; - - foreach(string key in equipment.Keys) - { - amount = (float)equipment[key]; - - if (amount > 0 || amount == -1) - { - sb.Append(""); - } - } - - string equipmentString; - - if (sb.Length > 0) - { - equipmentString = ""+sb.ToString()+""; - } - else - { - equipmentString = ""; - } - - if (equipmentString == "") - { - return ""; - } - else - { - return ""+equipmentString+""; - } - }*/ } } diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/UnitEquipmentItemObj.cs --- a/api/Objects/UnitEquipmentItemObj.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/UnitEquipmentItemObj.cs Thu Mar 19 20:11:07 2009 +0000 @@ -58,7 +58,7 @@ } else { - if (amount == -1) + if (amount == WarFoundryCore.INFINITY) { return "all"; } diff -r 465a215a21a2 -r 548cfc776f54 api/Objects/UnitType.cs --- a/api/Objects/UnitType.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/Objects/UnitType.cs Thu Mar 19 20:11:07 2009 +0000 @@ -85,7 +85,7 @@ get { return maxSize; } set { - maxSize = (value >= -1 ? value : -1); + maxSize = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumSize(); } } @@ -110,14 +110,14 @@ get { return max; } set { - max = (value >= -1 ? value : -1); + max = (value >= 0 ? value : WarFoundryCore.INFINITY); CheckMinimumNumber(); } } private void CheckMinimumNumber() { - if (MinNumber > MaxNumber && MaxNumber!=-1) + if (MinNumber > MaxNumber && MaxNumber!=WarFoundryCore.INFINITY) { MinNumber = MaxNumber; LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum number greater than their maximum number.", Name, ID); @@ -126,7 +126,7 @@ private void CheckMinimumSize() { - if (MinSize > MaxSize && MaxSize!=-1) + if (MinSize > MaxSize && MaxSize!=WarFoundryCore.INFINITY) { MinSize = MaxSize; LogNotifier.WarnFormat(GetType(), "Unit type {0} ({1}) had a minimum size greater than their maximum size.", Name, ID); diff -r 465a215a21a2 -r 548cfc776f54 api/WarFoundryCore.cs --- a/api/WarFoundryCore.cs Mon Mar 16 20:53:22 2009 +0000 +++ b/api/WarFoundryCore.cs Thu Mar 19 20:11:07 2009 +0000 @@ -10,6 +10,7 @@ { public class WarFoundryCore { + public static readonly int INFINITY = -1; public static event GameSystemChangedDelegate GameSystemChanged; public static event ArmyChangedDelegate ArmyChanged; diff -r 465a215a21a2 -r 548cfc776f54 dtds/race.xsd --- a/dtds/race.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/race.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -33,12 +33,12 @@ - - + + - + - + @@ -62,8 +62,8 @@ - - + + @@ -126,7 +126,7 @@ - + diff -r 465a215a21a2 -r 548cfc776f54 dtds/warfoundry-cats.xsd --- a/dtds/warfoundry-cats.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/warfoundry-cats.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -7,8 +7,8 @@ - - + + diff -r 465a215a21a2 -r 548cfc776f54 dtds/warfoundry-core.xsd --- a/dtds/warfoundry-core.xsd Mon Mar 16 20:53:22 2009 +0000 +++ b/dtds/warfoundry-core.xsd Thu Mar 19 20:11:07 2009 +0000 @@ -1,19 +1,20 @@ - + - + - + - + +