Mercurial > repos > snowblizz-super-API-ideas
changeset 82:3ea0ab04352b
* Fix line terminators
no-open-ticket
line wrap: on
line diff
--- a/AssemblyInfo.cs Wed May 27 19:43:09 2009 +0000 +++ b/AssemblyInfo.cs Sat Jun 27 18:59:49 2009 +0000 @@ -1,58 +1,58 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly: AssemblyTitle("WarFoundry API")] -[assembly: AssemblyDescription("The API for the WarFoundry army builder")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("IBBoard.WarFoundry.API")] -[assembly: AssemblyCopyright("IBBoard 2009")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("1.0.0.*")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\<configuration>. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] +using System.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("WarFoundry API")] +[assembly: AssemblyDescription("The API for the WarFoundry army builder")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IBBoard.WarFoundry.API")] +[assembly: AssemblyCopyright("IBBoard 2009")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\<configuration>. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")]
--- a/api/Commands/CreateAndAddUnitCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/CreateAndAddUnitCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -1,72 +1,72 @@ // This file (CreateAndAddUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. // -// 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; +// 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 IBBoard.Commands; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - public class CreateAndAddUnitCommand : Command - { - private UnitType addedUnitType; - private Army army; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + public class CreateAndAddUnitCommand : Command + { + private UnitType addedUnitType; + private Army army; private Unit addedUnit; public CreateAndAddUnitCommand(UnitType toAdd, Army armyTo) { addedUnitType = toAdd; army = armyTo; - } + } + + [Obsolete("Use two parameter constructor instead")] + public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, armyTo) + { + } - [Obsolete("Use two parameter constructor instead")] - public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, armyTo) - { - } + [Obsolete("Use two parameter constructor instead")] + public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) + { + } + + public override bool CanExecute() + { + return (addedUnitType!=null && army!=null); + } + + public override string Description + { + get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } + } - [Obsolete("Use two parameter constructor instead")] - public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) - { - } - - public override bool CanExecute() - { - return (addedUnitType!=null && army!=null); - } - - public override string Description - { - get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } - } - - public override string UndoDescription - { - get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } - } - - public override bool Execute() - { - addedUnit = new Unit(addedUnitType, army); - this.Redo(); - return true; - } - - public override void Redo() - { - army.AddUnit(addedUnit); - } - - public override void Undo() - { - army.RemoveUnit(addedUnit); - } - - - public override string Name - { - get { return "Add new unit"; } - } - } -} + public override string UndoDescription + { + get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } + } + + public override bool Execute() + { + addedUnit = new Unit(addedUnitType, army); + this.Redo(); + return true; + } + + public override void Redo() + { + army.AddUnit(addedUnit); + } + + public override void Undo() + { + army.RemoveUnit(addedUnit); + } + + + public override string Name + { + get { return "Add new unit"; } + } + } +}
--- a/api/Commands/RemoveUnitCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/RemoveUnitCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -1,61 +1,61 @@ // This file (RemoveUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. // -// 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; +// 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 IBBoard.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - /// <summary> - /// Summary description for RemoveUnitCommand. - /// </summary> - public class RemoveUnitCommand : Command - { - private Unit unit; - private ArmyCategory cat; - - public RemoveUnitCommand(Unit toRemove) - { - unit = toRemove; - cat = unit.Category; - } - - public override bool CanExecute() - { - return (unit!=null); - } - - public override string Description - { - get { return "Remove an existing unit from the army"; } - } - - public override string UndoDescription - { - get { return "Replace a removed unit"; } - } - - public override bool Execute() - { - this.Redo(); - return true; - } - - public override void Redo() - { - cat.RemoveUnit(unit); - } - - public override void Undo() - { - cat.AddUnit(unit); - } - - public override string Name - { - get { return "Remove unit"; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for RemoveUnitCommand. + /// </summary> + public class RemoveUnitCommand : Command + { + private Unit unit; + private ArmyCategory cat; + + public RemoveUnitCommand(Unit toRemove) + { + unit = toRemove; + cat = unit.Category; + } + + public override bool CanExecute() + { + return (unit!=null); + } + + public override string Description + { + get { return "Remove an existing unit from the army"; } + } + + public override string UndoDescription + { + get { return "Replace a removed unit"; } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() + { + cat.RemoveUnit(unit); + } + + public override void Undo() + { + cat.AddUnit(unit); + } + + public override string Name + { + get { return "Remove unit"; } + } + } +}
--- a/api/Commands/ReplaceUnitEquipmentCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/ReplaceUnitEquipmentCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,63 +2,63 @@ // // 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 IBBoard.Commands; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - /// <summary> - /// Summary description for ReplaceUnitEquipmentCommand. - /// </summary> - public class ReplaceUnitEquipmentCommand : Command - { - private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand; - - public ReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, UnitEquipmentItem newItem, double amount) - { - removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0); - addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount); - } - - public override bool CanExecute() - { - return removeOldCommand.CanExecute() && addNewCommand.CanExecute(); - } - - public override string Description - { - get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } - } - - public override string UndoDescription - { - get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } - } - - public override bool Execute() - { - this.Redo(); - return true; - } - - public override void Redo() - { - removeOldCommand.Redo(); - addNewCommand.Redo(); - } - - public override void Undo() - { - addNewCommand.Undo(); - removeOldCommand.Undo(); - } - - - public override string Name - { - get { return "Replace required equipment"; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for ReplaceUnitEquipmentCommand. + /// </summary> + public class ReplaceUnitEquipmentCommand : Command + { + private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand; + + public ReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, UnitEquipmentItem newItem, double amount) + { + removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0); + addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount); + } + + public override bool CanExecute() + { + return removeOldCommand.CanExecute() && addNewCommand.CanExecute(); + } + + public override string Description + { + get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + } + + public override string UndoDescription + { + get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() + { + removeOldCommand.Redo(); + addNewCommand.Redo(); + } + + public override void Undo() + { + addNewCommand.Undo(); + removeOldCommand.Undo(); + } + + + public override string Name + { + get { return "Replace required equipment"; } + } + } +}
--- a/api/Commands/SetNameCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/SetNameCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,61 +2,61 @@ // // 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 IBBoard.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - /// <summary> - /// Summary description for SetNameCommand. - /// </summary> - public class SetNameCommand : Command - { - private WarFoundryObject obj; - private string newName, oldName; - - public SetNameCommand(WarFoundryObject toRename, string name) - { - obj = toRename; - newName = name; - oldName = obj.Name; - } - - public override bool CanExecute() - { - return (obj!=null && newName!=null && newName!=""); - } - - public override string Description - { - get { return "Rename "+oldName; } - } - - public override string UndoDescription - { - get { return "Revert name of "+newName; } - } - - public override bool Execute() - { - this.Redo(); - return true; - } - - public override void Redo() - { - obj.Name = newName; - } - - public override void Undo() - { - obj.Name = oldName; - } - - public override string Name - { - get { return "Rename item"; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for SetNameCommand. + /// </summary> + public class SetNameCommand : Command + { + private WarFoundryObject obj; + private string newName, oldName; + + public SetNameCommand(WarFoundryObject toRename, string name) + { + obj = toRename; + newName = name; + oldName = obj.Name; + } + + public override bool CanExecute() + { + return (obj!=null && newName!=null && newName!=""); + } + + public override string Description + { + get { return "Rename "+oldName; } + } + + public override string UndoDescription + { + get { return "Revert name of "+newName; } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() + { + obj.Name = newName; + } + + public override void Undo() + { + obj.Name = oldName; + } + + public override string Name + { + get { return "Rename item"; } + } + } +}
--- a/api/Commands/SetUnitEquipmentAmountCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/SetUnitEquipmentAmountCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,65 +2,65 @@ // // 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 IBBoard.Commands; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - /// <summary> - /// Summary description for SetUnitEquipmentAmountCommand. - /// </summary> - public class SetUnitEquipmentAmountCommand : Command - { - private Unit unit; - private UnitEquipmentItem equip; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for SetUnitEquipmentAmountCommand. + /// </summary> + public class SetUnitEquipmentAmountCommand : Command + { + private Unit unit; + private UnitEquipmentItem equip; private double newAmount; - private double oldAmount; - - public SetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item, double amount) - { - this.unit = unit; - equip = item; - newAmount = amount; - oldAmount = unit.GetEquipmentAmount(equip.ID); - } - - public override bool CanExecute() - { - return (unit!=null && equip!=null); - } - - public override string Description - { - get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, newAmount); } - } - - public override string UndoDescription - { - get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, oldAmount); } - } - - public override bool Execute() - { - this.Redo(); - return true; - } - - public override void Redo() + private double oldAmount; + + public SetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item, double amount) + { + this.unit = unit; + equip = item; + newAmount = amount; + oldAmount = unit.GetEquipmentAmount(equip.ID); + } + + public override bool CanExecute() + { + return (unit!=null && equip!=null); + } + + public override string Description + { + get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, newAmount); } + } + + public override string UndoDescription + { + get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItem.FormatEquipmentAmount(equip, oldAmount); } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() { if (equip.IsRatioLimit) - { + { unit.SetEquipmentRatio(equip, newAmount); } else { unit.SetEquipmentAmount(equip, (int)newAmount); - } - } - - public override void Undo() + } + } + + public override void Undo() { if (equip.IsRatioLimit) { @@ -69,22 +69,22 @@ else { unit.SetEquipmentAmount(equip, (int)oldAmount); - } - } - - public override string Name - { - get { return "Set equipment amount"; } - } - - public UnitEquipmentItem EquipItem - { - get { return equip; } - } - - public Unit Unit - { - get { return unit; } - } - } -} + } + } + + public override string Name + { + get { return "Set equipment amount"; } + } + + public UnitEquipmentItem EquipItem + { + get { return equip; } + } + + public Unit Unit + { + get { return unit; } + } + } +}
--- a/api/Commands/SetUnitSizeCommand.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Commands/SetUnitSizeCommand.cs Sat Jun 27 18:59:49 2009 +0000 @@ -1,62 +1,62 @@ // This file (SetUnitSizeCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. // -// 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; +// 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 IBBoard.Commands; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Commands -{ - /// <summary> - /// Summary description for SetNameCommand. - /// </summary> - public class SetUnitSizeCommand : Command - { - private Unit unit; - private int newSize, oldSize; - - public SetUnitSizeCommand(Unit toResize, int size) - { - unit = toResize; - newSize = size; - oldSize = unit.Size; - } - - public override bool CanExecute() - { - return (unit!=null && newSize >0 && oldSize > 0); - } - - public override string Description - { - get { return "Change size of "+unit.Name; } - } - - public override string UndoDescription - { - get { return "Revert size of "+unit.Name; } - } - - public override bool Execute() - { - this.Redo(); - return true; - } - - public override void Redo() - { - unit.Size = newSize; - } - - public override void Undo() - { - unit.Size = oldSize; - } - - public override string Name - { - get { return "Change unit size"; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for SetNameCommand. + /// </summary> + public class SetUnitSizeCommand : Command + { + private Unit unit; + private int newSize, oldSize; + + public SetUnitSizeCommand(Unit toResize, int size) + { + unit = toResize; + newSize = size; + oldSize = unit.Size; + } + + public override bool CanExecute() + { + return (unit!=null && newSize >0 && oldSize > 0); + } + + public override string Description + { + get { return "Change size of "+unit.Name; } + } + + public override string UndoDescription + { + get { return "Revert size of "+unit.Name; } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() + { + unit.Size = newSize; + } + + public override void Undo() + { + unit.Size = oldSize; + } + + public override string Name + { + get { return "Change unit size"; } + } + } +}
--- a/api/Delegates.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Delegates.cs Sat Jun 27 18:59:49 2009 +0000 @@ -4,20 +4,20 @@ using System; using System.Collections.Generic; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API -{ +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API +{ public delegate void ObjectChangedDelegate(WarFoundryObject oldValue, WarFoundryObject newValue); public delegate void ArmyChangedDelegate(Army oldValue, Army newValue); - public delegate void GameSystemChangedDelegate(GameSystem oldValue, GameSystem newValue); + public delegate void GameSystemChangedDelegate(GameSystem oldValue, GameSystem newValue); public delegate void ObjectAddDelegate(WarFoundryObject val); - public delegate void ObjectRemoveDelegate(WarFoundryObject val); + public delegate void ObjectRemoveDelegate(WarFoundryObject val); public delegate void UnitAddDelegate(Unit val); - public delegate void UnitRemoveDelegate(Unit val); - public delegate void ObjectUpdatedDelegate(WarFoundryObject val, string updatedValName); - public delegate void DoubleValChangedDelegate(WarFoundryObject obj, double oldValue, double newValue); - public delegate void FloatValChangedDelegate(WarFoundryObject obj, float oldValue, float newValue); - public delegate void StringValChangedDelegate(WarFoundryObject obj, string oldValue, string newValue); - public delegate void IntValChangedDelegate(WarFoundryObject obj, int oldValue, int newValue); -} + public delegate void UnitRemoveDelegate(Unit val); + public delegate void ObjectUpdatedDelegate(WarFoundryObject val, string updatedValName); + public delegate void DoubleValChangedDelegate(WarFoundryObject obj, double oldValue, double newValue); + public delegate void FloatValChangedDelegate(WarFoundryObject obj, float oldValue, float newValue); + public delegate void StringValChangedDelegate(WarFoundryObject obj, string oldValue, string newValue); + public delegate void IntValChangedDelegate(WarFoundryObject obj, int oldValue, int newValue); +}
--- a/api/Factories/AbstractNativeWarFoundryFactory.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Factories/AbstractNativeWarFoundryFactory.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,7 +3,7 @@ // 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.IO; +using System.IO; using System.Xml; using System.Xml.Schema; using System.Collections.Generic; @@ -14,22 +14,22 @@ using IBBoard.Logging; using IBBoard.Xml; using IBBoard.WarFoundry.API.Objects; -using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Factories -{ - /// <summary> - /// Base abstract class for all factories that load native WarFoundry data. - /// </summary> - public abstract class AbstractNativeWarFoundryFactory : AbstractWarFoundryFactory<ZipFile>, INativeWarFoundryFactory +using ICSharpCode.SharpZipLib.Zip; + +namespace IBBoard.WarFoundry.API.Factories +{ + /// <summary> + /// Base abstract class for all factories that load native WarFoundry data. + /// </summary> + public abstract class AbstractNativeWarFoundryFactory : AbstractWarFoundryFactory<ZipFile>, INativeWarFoundryFactory { protected static readonly string SYSTEM_ZIP_IDENTIFIER = "WarFoundry_System"; protected static readonly string RACE_ZIP_IDENTIFIER = "WarFoundry_Race"; protected static readonly string ARMY_ZIP_IDENTIFIER = "WarFoundry_Army"; - protected AbstractNativeWarFoundryFactory() + protected AbstractNativeWarFoundryFactory() { - //Do nothing - just make the constructor non-public + //Do nothing - just make the constructor non-public } protected override ZipFile GetFileAsSupportedType (FileInfo file) @@ -135,7 +135,7 @@ } protected abstract Stream GetGameSystemDataStream(ZipFile file); - protected abstract GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream); + protected abstract GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream); public override bool Equals (object o) { @@ -154,6 +154,6 @@ public override int GetHashCode () { return GetType().FullName.GetHashCode(); - } - } -} + } + } +}
--- a/api/Factories/Xml/WarFoundryXmlFactory.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,7 +3,7 @@ // 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.IO; +using System.IO; using System.Xml; using System.Xml.Schema; using System.Xml.XPath; @@ -16,14 +16,14 @@ using IBBoard.Xml; using IBBoard.WarFoundry.API.Requirements; using IBBoard.WarFoundry.API.Objects; -using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Factories.Xml -{ - /// <summary> - /// The WarFoundryXmlFactory loads WarFoundry classes from the native "XML in a zip" file format. Files are validated using the schema for the file type, so structurally invalid files should be identified at initial load. - /// </summary> - public class WarFoundryXmlFactory : AbstractNativeWarFoundryFactory +using ICSharpCode.SharpZipLib.Zip; + +namespace IBBoard.WarFoundry.API.Factories.Xml +{ + /// <summary> + /// The WarFoundryXmlFactory loads WarFoundry classes from the native "XML in a zip" file format. Files are validated using the schema for the file type, so structurally invalid files should be identified at initial load. + /// </summary> + public class WarFoundryXmlFactory : AbstractNativeWarFoundryFactory { private static WarFoundryXmlFactory factory; private WarFoundryXmlGameSystemFactory gameSystemFactory; @@ -40,11 +40,11 @@ return factory; } - private WarFoundryXmlFactory() : base() + private WarFoundryXmlFactory() : base() { gameSystemFactory = new WarFoundryXmlGameSystemFactory(this); raceFactory = new WarFoundryXmlRaceFactory(this); - armyFactory = new WarFoundryXmlArmyFactory(); + armyFactory = new WarFoundryXmlArmyFactory(); } protected override bool CheckCanFindArmyFileContent(ZipFile file) @@ -123,5 +123,5 @@ raceFactory.CompleteLoading((Race)obj); } } - } + } } \ No newline at end of file
--- a/api/Factories/Xml/WarFoundryXmlSaver.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlSaver.cs Sat Jun 27 18:59:49 2009 +0000 @@ -29,7 +29,7 @@ return saver; } - public bool SaveAs(WarFoundryObject toSave, string saveAsPath) + public bool SaveAs(WarFoundryObject toSave, string saveAsPath) { if (CanSaveType(toSave)) { @@ -37,12 +37,12 @@ bool success = false; try - { - fs = new FileStream(saveAsPath, FileMode.Create, FileAccess.Write); - byte[] bytes = StringManipulation.StringToBytes(CreateXmlString(toSave)); - fs.Write(bytes, 0, bytes.Length); + { + fs = new FileStream(saveAsPath, FileMode.Create, FileAccess.Write); + byte[] bytes = StringManipulation.StringToBytes(CreateXmlString(toSave)); + fs.Write(bytes, 0, bytes.Length); fs.Flush(); - savePaths.Add(toSave, saveAsPath); + savePaths.Add(toSave, saveAsPath); success = true; } finally @@ -58,7 +58,7 @@ else { throw new ArgumentException("Cannot directly save objects of type "+toSave.GetType()); - } + } } public bool Save(WarFoundryObject toSave)
--- 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); + } + } +}
--- a/api/Objects/ArmyCategory.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/ArmyCategory.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,160 +2,161 @@ // // 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.Collections.Generic; -using IBBoard.WarFoundry.API.Requirements; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for ArmyCategory. - /// </summary> - public class ArmyCategory : WarFoundryObject - { - private Category category; - private Army parentArmy; - private double pointsTotal; - private List<Unit> units; - private Dictionary<string, int> unitTypes; - private DoubleValChangedDelegate PointsValueChangedMethod; - public event DoubleValChangedDelegate PointsValueChanged; - public event ObjectAddDelegate UnitAdded; - public event ObjectRemoveDelegate UnitRemoved; - - public ArmyCategory(Army army, Category cat) : base() - { - parentArmy = army; - category = cat; - cat.NameChanged+=new StringValChangedDelegate(cat_NameChanged); - PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler); - units = new List<Unit>(); - unitTypes = new Dictionary<string,int>(); - } - - public Category Category - { - get { return category; } - } - - public Army ParentArmy - { - get { return parentArmy; } - } - - public override string ID - { - get - { - return Category.ID; - } - set - { - Category.ID = value; - } - } - - public override string Name - { - get { return category.Name; } - set - { - category.Name = value; - } - } - - internal void AddUnit(Unit unit) - { - units.Add(unit); - unit.Category = this; +using IBBoard.WarFoundry.API.Requirements; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for ArmyCategory. + /// </summary> + public class ArmyCategory : WarFoundryObject + { + private Category category; + private Army parentArmy; + private double pointsTotal; + private List<Unit> units; + private Dictionary<string, int> unitTypes; + private DoubleValChangedDelegate PointsValueChangedMethod; + public event DoubleValChangedDelegate PointsValueChanged; + public event ObjectAddDelegate UnitAdded; + public event ObjectRemoveDelegate UnitRemoved; + + public ArmyCategory(Army army, Category cat) : base() + { + parentArmy = army; + category = cat; + cat.NameChanged+=new StringValChangedDelegate(cat_NameChanged); + PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler); + units = new List<Unit>(); + unitTypes = new Dictionary<string,int>(); + } + + public Category Category + { + get { return category; } + } + + public Army ParentArmy + { + get { return parentArmy; } + } + + public override string ID + { + get + { + return Category.ID; + } + set + { + Category.ID = value; + } + } + + public override string Name + { + get { return category.Name; } + set + { + category.Name = value; + } + } + + internal void AddUnit(Unit unit) + { + List<FailedUnitRequirement> failedReqs = ParentArmy.CanAddUnit(unit); + units.Add(unit); + unit.Category = this; unit.PointsValueChanged+= PointsValueChangedMethod; - int unitTypeCount; - unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount); - unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; + int unitTypeCount; + unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount); + unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; TotalPoints+= unit.PointsValue; - OnUnitAdded(unit); - } - - internal void RemoveUnit(Unit unit) - { - units.Remove(unit); - unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; - TotalPoints-= unit.PointsValue; + OnUnitAdded(unit); + } + + internal void RemoveUnit(Unit unit) + { + units.Remove(unit); + unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; + TotalPoints-= unit.PointsValue; unit.PointsValueChanged-= PointsValueChangedMethod; - OnUnitRemoved(unit); - } - - public int GetUnitTypeCount(UnitType unitType) - { - return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0; - } - - public Unit[] GetUnits() - { - return units.ToArray(); - } - - private double TotalPoints - { - get { return pointsTotal; } - set - { - double oldVal = pointsTotal; - pointsTotal = value; - - if (oldVal!=pointsTotal) - { - OnPointsValueChanged(oldVal, pointsTotal); - } - } - } - - public double PointsTotal - { - get { return TotalPoints; } - } - - private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal) - { - if (obj is Unit) - { - double diff = newVal - oldVal; - TotalPoints+= diff; - } - } - - private void OnUnitAdded(Unit unit) - { - if (UnitAdded!=null) - { - UnitAdded(unit); - } - } - - private void OnUnitRemoved(Unit unit) - { - if (UnitRemoved!=null) - { - UnitRemoved(unit); - } - } - - protected virtual void OnPointsValueChanged(double oldValue, double newValue) - { - if (PointsValueChanged!=null) - { - PointsValueChanged(this, oldValue, newValue); - } - } - - protected void cat_NameChanged(WarFoundryObject obj, string oldValue, string newValue) - { - OnNameChanged(oldValue, newValue); - } - - public int GetPointsPercentage() - { - return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0); - } - } -} + OnUnitRemoved(unit); + } + + public int GetUnitTypeCount(UnitType unitType) + { + return unitTypes.ContainsKey(unitType.ID) ? (int)unitTypes[unitType.ID] : 0; + } + + public Unit[] GetUnits() + { + return units.ToArray(); + } + + private double TotalPoints + { + get { return pointsTotal; } + set + { + double oldVal = pointsTotal; + pointsTotal = value; + + if (oldVal!=pointsTotal) + { + OnPointsValueChanged(oldVal, pointsTotal); + } + } + } + + public double PointsTotal + { + get { return TotalPoints; } + } + + private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal) + { + if (obj is Unit) + { + double diff = newVal - oldVal; + TotalPoints+= diff; + } + } + + private void OnUnitAdded(Unit unit) + { + if (UnitAdded!=null) + { + UnitAdded(unit); + } + } + + private void OnUnitRemoved(Unit unit) + { + if (UnitRemoved!=null) + { + UnitRemoved(unit); + } + } + + protected virtual void OnPointsValueChanged(double oldValue, double newValue) + { + if (PointsValueChanged!=null) + { + PointsValueChanged(this, oldValue, newValue); + } + } + + protected void cat_NameChanged(WarFoundryObject obj, string oldValue, string newValue) + { + OnNameChanged(oldValue, newValue); + } + + public int GetPointsPercentage() + { + return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0); + } + } +}
--- a/api/Objects/Category.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/Category.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,27 +2,27 @@ // // 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.Xml; -using IBBoard.Logging; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// A Category is a definition at the <see cref=" GameSystem"/> or <see cref=" Race"/> level of a group that <see cref=" UnitType"/>s belong to. Each category has a name and a min/max limit on points or percentage of a total army cost that units in the category can total. - /// </summary> - public class Category : WarFoundryObject - { - private int minPts = 0; - private int maxPts = WarFoundryCore.INFINITY; - private int minPc = 0; - private int maxPc = 100; - - - public Category(string id, string name) : base(id, name) - { +using System; +using System.Xml; +using IBBoard.Logging; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// A Category is a definition at the <see cref=" GameSystem"/> or <see cref=" Race"/> level of a group that <see cref=" UnitType"/>s belong to. Each category has a name and a min/max limit on points or percentage of a total army cost that units in the category can total. + /// </summary> + public class Category : WarFoundryObject + { + private int minPts = 0; + private int maxPts = WarFoundryCore.INFINITY; + private int minPc = 0; + private int maxPc = 100; + + + public Category(string id, string name) : base(id, name) + { } - + [Obsolete("Use the two argument constructor and the appropriate 'set' methods")] public Category(string id, string name, int minPoints, int maxPoints, int minPercent, int maxPercent, int minChoices, int maxChoices, int baseValue, int incrementValue, int incrementAmount) : base(id, name) { @@ -30,99 +30,99 @@ MaximumPoints = maxPoints; MinimumPercentage = minPercent; MaximumPercentage = maxPercent; - } - - protected override string DefaultName() - { - return ""; + } + + protected override string DefaultName() + { + return ""; } /// <value> /// Gets or sets the minimum number of points that the units of this category can cost. Note: This should be set AFTER MaximumPoints, otherwise an unintended default value may be set for the minimum - /// </value> - public int MinimumPoints - { - get { return minPts; } - set - { - minPts = (value >= 0 ? value : 0); - CheckMinimumPoints(); - } - } + /// </value> + public int MinimumPoints + { + get { return minPts; } + set + { + minPts = (value >= 0 ? value : 0); + CheckMinimumPoints(); + } + } /// <value> /// Gets or sets the maximum number of points that the units of this category can cost. Note: This should be set BEFORE MinimumPoints, otherwise an unintended default value may be set for the minimum - /// </value> - public int MaximumPoints - { - get { return maxPts; } - set - { - maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); - CheckMinimumPoints(); - } + /// </value> + public int MaximumPoints + { + get { return maxPts; } + set + { + maxPts = (value >= 0 ? value : WarFoundryCore.INFINITY); + CheckMinimumPoints(); + } } /// <summary> /// Makes sure that the minimum points value isn't more than the maximum points value, hence the warning on the properties - /// </summary> - private void CheckMinimumPoints() - { + /// </summary> + private void CheckMinimumPoints() + { 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); - } + } } /// <value> /// Gets or sets the minimum percentage of the total army points value that the units of this category can cost. Note: This should be set AFTER MaximumPercentage, otherwise an unintended default value may be set for the minimum /// </value> - public int MinimumPercentage - { - get { return minPc; } - set - { - minPc = (value >= 0 ? value : 0); - CheckMinimumPercentage(); - } + public int MinimumPercentage + { + get { return minPc; } + set + { + minPc = (value >= 0 ? value : 0); + CheckMinimumPercentage(); + } } /// <value> /// Gets or sets the maximum percentage of the total army points value that the units of this category can cost. Note: This should be set BEFORE MinimumPercentage, otherwise an unintended default value may be set for the minimum - /// </value> - public int MaximumPercentage - { - get { return maxPc; } - set - { - if (value < 0) - { - maxPc = 0; - } - else if (value > 100) - { - maxPc = 100; - } - else - { - maxPc = value; - } - - CheckMinimumPercentage(); - } + /// </value> + public int MaximumPercentage + { + get { return maxPc; } + set + { + if (value < 0) + { + maxPc = 0; + } + else if (value > 100) + { + maxPc = 100; + } + else + { + maxPc = value; + } + + CheckMinimumPercentage(); + } } /// <summary> /// Makes sure that the minimum percentage value isn't more than the maximum points value, hence the warning on the properties - /// </summary> - private void CheckMinimumPercentage() - { + /// </summary> + private void CheckMinimumPercentage() + { if (MinimumPercentage > MaximumPercentage) { MinimumPercentage = MaximumPercentage; LogNotifier.WarnFormat(GetType(), "Category {0} ({1}) had a minimum percentage limit greater than its maximum percentage limit.", Name, ID); - } - } - } -} + } + } + } +}
--- a/api/Objects/EquipmentItem.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/EquipmentItem.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,18 +2,18 @@ // // 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.Xml; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for EquipmentItem. - /// </summary> - public class EquipmentItem : WarFoundryObject - { +using System; +using System.Xml; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for EquipmentItem. + /// </summary> + public class EquipmentItem : WarFoundryObject + { private double cost; - private string description; + private string description; private ArmourType armourType; private Race equipForRace; @@ -22,30 +22,30 @@ equipForRace = race; description = ""; armourType = ArmourType.None; - } + } [Obsolete("Use the three argument constructor and the appropriate 'set' methods")] public EquipmentItem(string id, string name, double itemCost, double minimum, double maximum, ArmourType itemArmourType, Race race) : this(id, name, race) { ItemArmourType = itemArmourType; - } - - public ArmourType ItemArmourType - { - get { return armourType; } - set { armourType = value; } - } - - public double Cost - { - get { return cost; } + } + + public ArmourType ItemArmourType + { + get { return armourType; } + set { armourType = value; } + } + + public double Cost + { + get { return cost; } set { if (value >= 0) { cost = value; } - } + } } public string Description @@ -57,16 +57,16 @@ public Race EquipmentForRace { get { return equipForRace; } - } - - public bool CanBeUsedWithItem(EquipmentItem item) - { - return CanBeUsedWithArmourType(item.ItemArmourType); - } - - public bool CanBeUsedWithArmourType(ArmourType otherItemType) - { - return (this.ItemArmourType & otherItemType) == 0; - } - } -} + } + + public bool CanBeUsedWithItem(EquipmentItem item) + { + return CanBeUsedWithArmourType(item.ItemArmourType); + } + + public bool CanBeUsedWithArmourType(ArmourType otherItemType) + { + return (this.ItemArmourType & otherItemType) == 0; + } + } +}
--- a/api/Objects/GameSystem.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/GameSystem.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,26 +2,26 @@ // // 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.Collections.Generic; -using System.Xml; -using System.IO; +using System; +using System.Collections.Generic; +using System.Xml; +using System.IO; using IBBoard.Logging; -using IBBoard.WarFoundry.API.Factories; +using IBBoard.WarFoundry.API.Factories; using ICSharpCode.SharpZipLib.Zip; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for GameSystem. - /// </summary> - public class GameSystem : WarFoundryStagedLoadingObject - { + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for GameSystem. + /// </summary> + public class GameSystem : WarFoundryStagedLoadingObject + { private bool warnOnError; - private bool allowAllies; - private Dictionary<string, Category> categories = new Dictionary<string,Category>(); + private bool allowAllies; + private Dictionary<string, Category> categories = new Dictionary<string,Category>(); private Dictionary<string, SystemStats> stats = new Dictionary<string,SystemStats>(); - private string defaultStats; + private string defaultStats; public GameSystem(string systemID, string systemName, IWarFoundryFactory creatingFactory) : base(systemID, systemName, creatingFactory) { @@ -37,37 +37,37 @@ public void AddCategory(Category cat) { RawCategories[cat.ID] = cat; - } - - public Category GetCategory(string id) + } + + public Category GetCategory(string id) { EnsureFullyLoaded(); Category cat = null; RawCategories.TryGetValue(id, out cat); - return cat; - } - - public Category[] Categories - { - get + return cat; + } + + public Category[] Categories + { + get { - EnsureFullyLoaded(); - return DictionaryUtils.ToArray<string, Category>(RawCategories); - } + EnsureFullyLoaded(); + return DictionaryUtils.ToArray<string, Category>(RawCategories); + } } protected Dictionary<string, Category> RawCategories { get { return categories; } - } - - public bool WarnOnError - { + } + + public bool WarnOnError + { get { return warnOnError; - } - set { warnOnError = value; } + } + set { warnOnError = value; } } public void AddSystemStats(SystemStats sysStats) @@ -98,17 +98,17 @@ defaultStats = value; } } - } - - public SystemStats[] SystemStats - { - get + } + + public SystemStats[] SystemStats + { + get { EnsureFullyLoaded(); SystemStats[] statsArray = new SystemStats[stats.Count]; - stats.Values.CopyTo(statsArray, 0); - return statsArray; - } + stats.Values.CopyTo(statsArray, 0); + return statsArray; + } } public SystemStats GetSystemStatsForID(string id) @@ -122,50 +122,50 @@ public Race SystemDefaultRace { get { return WarFoundryLoader.GetDefault().GetRace(this, Race.SYSTEM_DEFAULT_RACE_ID); } - } - - public bool Matches(GameSystem otherSystem) - { - if (otherSystem==null) - { - return false; - } - - return this.ID == otherSystem.ID; - } - - public override bool Equals(object obj) + } + + public bool Matches(GameSystem otherSystem) + { + if (otherSystem==null) + { + return false; + } + + return this.ID == otherSystem.ID; + } + + public override bool Equals(object obj) { if (obj == null) { return false; } - - if (obj.GetType().Equals(this.GetType())) - { - GameSystem otherSystem = (GameSystem)obj; - - return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); - } - else - { - return false; - } - } - - public override int GetHashCode() - { - return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); - } - - public bool UnitTypeMaxed(UnitType unitType, Army army) - { - return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; - } - - public bool UnitTypeMinned(UnitType unitType, Army army) - { - return army.GetUnitTypeCount(unitType) <= unitType.MinNumber; + + if (obj.GetType().Equals(this.GetType())) + { + GameSystem otherSystem = (GameSystem)obj; + + return this.ID == otherSystem.ID && this.Name == otherSystem.Name && ((this.RawCategories == null && otherSystem.RawCategories == null) || this.RawCategories.Equals(otherSystem.RawCategories)); + } + else + { + return false; + } + } + + public override int GetHashCode() + { + return ID.GetHashCode() + Name.GetHashCode() + (RawCategories!=null ? RawCategories.GetHashCode() : 0) + warnOnError.GetHashCode(); + } + + public bool UnitTypeMaxed(UnitType unitType, Army army) + { + return unitType.MaxNumber!=WarFoundryCore.INFINITY && army.GetUnitTypeCount(unitType) >= unitType.MaxNumber; + } + + public bool UnitTypeMinned(UnitType unitType, Army army) + { + return army.GetUnitTypeCount(unitType) <= unitType.MinNumber; } public List<EquipmentItem> GetSystemEquipmentList() @@ -244,6 +244,6 @@ } return ability; - } - } -} + } + } +}
--- a/api/Objects/IWarFoundryObject.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/IWarFoundryObject.cs Sat Jun 27 18:59:49 2009 +0000 @@ -12,11 +12,11 @@ /// <value> /// The unique identifier for the object /// </value> - string ID { get; set; } + string ID { get; set; } /// <value> /// The display name of the WarFoundry object - /// </value> + /// </value> string Name { get; set; } } }
--- a/api/Objects/Race.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/Race.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,9 +2,9 @@ // // 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.Collections.Generic; -using System.IO; +using System; +using System.Collections.Generic; +using System.IO; using System.Xml; using IBBoard.IO; using IBBoard.WarFoundry.API.Factories; @@ -14,13 +14,13 @@ public class Race : WarFoundryStagedLoadingObject { public static string SYSTEM_DEFAULT_RACE_ID = "GameDefault"; - + private string subID; - private GameSystem system; - private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat; - private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>(); + private GameSystem system; + private Dictionary<Category, Dictionary<string, UnitType>> unitTypesByCat; + private Dictionary<string, UnitType> unitTypes = new Dictionary<string,UnitType>(); private Dictionary<string, EquipmentItem> equipment = new Dictionary<string,EquipmentItem>(); - private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>(); + private Dictionary<string, Ability> abilities = new Dictionary<string,Ability>(); private Dictionary<string, Category> categories = new Dictionary<string,Category>(); public Race(string raceID, string raceName, GameSystem gameSystem, IWarFoundryFactory creatingFactory) : this(raceID, "", raceName, gameSystem, creatingFactory) @@ -41,17 +41,17 @@ [Obsolete("Use constructor with GameSystem argument instead")] public Race(string raceID, string raceSubID, string raceName, string gameSystemID, IWarFoundryFactory creatingFactory) : this(raceID, raceSubID, raceName, WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID), creatingFactory) { - } - - public string SubID - { - get { return subID; } - set { subID = (value == null ? "" : value.Trim()); } - } - - public GameSystem GameSystem - { - get { return system; } + } + + public string SubID + { + get { return subID; } + set { subID = (value == null ? "" : value.Trim()); } + } + + public GameSystem GameSystem + { + get { return system; } set { if (value == null) @@ -60,13 +60,13 @@ } system = value; - } + } } public void AddCategory(Category cat) { categories[cat.ID] = cat; - } + } /// <summary> /// Gets a category from its ID. Attempts to get the category from the race's overrides, or else it falls back to getting the Game System's category with that ID. @@ -76,8 +76,8 @@ /// </param> /// <returns> /// The <code>Category</code> with the specified ID, or null if one doesn't exist. - /// </returns> - public Category GetCategory(string id) + /// </returns> + public Category GetCategory(string id) { EnsureFullyLoaded(); Category cat = null; @@ -88,12 +88,12 @@ cat = GameSystem.GetCategory(id); } - return cat; - } + return cat; + } - public Category[] Categories - { - get + public Category[] Categories + { + get { EnsureFullyLoaded(); Category[] cats; @@ -106,14 +106,14 @@ { cats = DictionaryUtils.ToArray<string, Category>(categories); } - - return cats; - } - } - - public bool HasCategoryOverrides() - { - return categories.Count > 0; + + return cats; + } + } + + public bool HasCategoryOverrides() + { + return categories.Count > 0; } public void AddEquipmentItem(EquipmentItem item) @@ -129,12 +129,12 @@ { AddEquipmentItem(item); } - } - - public EquipmentItem GetEquipmentItem(string id) + } + + public EquipmentItem GetEquipmentItem(string id) { - EnsureFullyLoaded(); - return (EquipmentItem)equipment[id]; + EnsureFullyLoaded(); + return (EquipmentItem)equipment[id]; } public List<EquipmentItem> GetEquipmentList() @@ -162,9 +162,9 @@ { AddUnitType(type); } - } - - public UnitType[] GetUnitTypes(Category cat) + } + + public UnitType[] GetUnitTypes(Category cat) { BuildUnitTypesByCategoryCache(); Dictionary<string, UnitType> unitTypesDictionary; @@ -179,21 +179,21 @@ { unitTypesArray = DictionaryUtils.ToArray<string, UnitType>(unitTypesDictionary); } - - return unitTypesArray; + + return unitTypesArray; } private void CacheUnitType(UnitType unit) { BuildUnitTypesByCategoryCache(); - Dictionary<string,UnitType> catUnitTypes; - unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes); - - if (catUnitTypes == null) - { - throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name)); - } - + Dictionary<string,UnitType> catUnitTypes; + unitTypesByCat.TryGetValue(unit.MainCategory, out catUnitTypes); + + if (catUnitTypes == null) + { + throw new InvalidFileException(String.Format("Unit type {0} with name {1} is a unit of an undefined category", unit.ID, unit.Name)); + } + catUnitTypes.Add(unit.ID, unit); } @@ -209,22 +209,22 @@ { unitTypesByCat = new Dictionary<Category,Dictionary<string,UnitType>>(); - foreach (Category category in Categories) - { - unitTypesByCat.Add(category, new Dictionary<string, UnitType>()); + foreach (Category category in Categories) + { + unitTypesByCat.Add(category, new Dictionary<string, UnitType>()); } foreach (UnitType unit in unitTypes.Values) { CacheUnitType(unit); } - } - - public UnitType GetUnitType(string id) + } + + public UnitType GetUnitType(string id) { UnitType type = null; - unitTypes.TryGetValue(id, out type); - return type; + unitTypes.TryGetValue(id, out type); + return type; } public List<Ability> GetAbilityList() @@ -255,13 +255,13 @@ abilities.TryGetValue(id, out ability); return ability; } - + protected virtual Dictionary<string, UnitType> RaceUnitTypes { get { return RaceRawUnitTypes; } set { RaceRawUnitTypes = value; } } - + protected virtual Dictionary<string, EquipmentItem> RaceEquipment { get { return RaceRawEquipment; } @@ -273,13 +273,13 @@ get { return RaceRawAbilities; } set { RaceRawAbilities = value; } } - + protected Dictionary<string, UnitType> RaceRawUnitTypes { get { return unitTypes; } set { unitTypes = value; } } - + protected Dictionary<string, EquipmentItem> RaceRawEquipment { get { return equipment; }
--- a/api/Objects/Stat.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/Stat.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,34 +2,39 @@ // // 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; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for Stat. - /// </summary> - public class Stat - { - private StatSlot parentStatSlot; - private string statString; - - public Stat(StatSlot parentSlot, string statValue) - { - parentStatSlot = parentSlot; - statString = statValue; - } - - public StatSlot ParentSlot - { - get { return parentStatSlot; } - set { parentStatSlot = value; } - } - - public string SlotValueString - { - get { return statString; } - set { statString = (value == null ? "" : value); } - } - } -} +using System; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for Stat. + /// </summary> + public class Stat + { + private StatSlot parentStatSlot; + private string statString; + + public Stat(StatSlot parentSlot, string statValue) + { + parentStatSlot = parentSlot; + statString = statValue; + } + + public StatSlot ParentSlot + { + get { return parentStatSlot; } + set { parentStatSlot = value; } + } + + public string ParentSlotName + { + get { return ParentSlot.Name; } + } + + public string SlotValueString + { + get { return statString; } + set { statString = (value == null ? "" : value); } + } + } +}
--- a/api/Objects/StatSlot.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/StatSlot.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,36 +2,36 @@ // // 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.Text.RegularExpressions; -using System.Xml; -using IBBoard; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for StatSlot. - /// </summary> - public class StatSlot - { +using System; +using System.Text.RegularExpressions; +using System.Xml; +using IBBoard; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for StatSlot. + /// </summary> + public class StatSlot + { private string name; - private SystemStats sysStats; - - public StatSlot(String statName) + private SystemStats sysStats; + + public StatSlot(String statName) { - name = statName; - } - - public string Name - { - get { return name; } - set { value = name; } + name = statName; + } + + public string Name + { + get { return name; } + set { value = name; } } public SystemStats SystemStats { get { return sysStats; } set { sysStats = value; } - } - } -} + } + } +}
--- a/api/Objects/SystemStats.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/SystemStats.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,24 +3,24 @@ // 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.Collections.Generic; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// SystemStats defines the available statistics/attributes that entity types can use (either a unit or an equipment item that has a stats line). Statistic/attribute values will be defined by a <see cref="Stats"/> object. - /// </summary> - public class SystemStats - { +using System.Collections.Generic; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// SystemStats defines the available statistics/attributes that entity types can use (either a unit or an equipment item that has a stats line). Statistic/attribute values will be defined by a <see cref="Stats"/> object. + /// </summary> + public class SystemStats + { private Dictionary<string, StatSlot> statsByName; private List<StatSlot> stats; - private string id; - - public SystemStats(string statsID) + private string id; + + public SystemStats(string statsID) { - id = statsID; + id = statsID; statsByName = new Dictionary<string, StatSlot>(); - stats = new List<StatSlot>(); + stats = new List<StatSlot>(); } public void AddStatSlot(string slotName) @@ -29,14 +29,14 @@ slot.SystemStats = this; statsByName[slot.Name] = slot; stats.Add(slot); - } - - public StatSlot[] StatSlots - { + } + + public StatSlot[] StatSlots + { get { return stats.ToArray(); - } + } } public StatSlot this[string statName] @@ -51,15 +51,15 @@ { return stats.IndexOf(slot); } - - public int SlotCount - { - get { return stats.Count; } + + public int SlotCount + { + get { return stats.Count; } } public string ID { get { return id; } - } - } -} + } + } +}
--- a/api/Objects/Unit.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/Unit.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,198 +2,198 @@ // // 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.Collections.Generic; -using System.Text; +using System; +using System.Collections.Generic; +using System.Text; using System.Xml; -using IBBoard.Lang; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for UnitInstance. - /// </summary> - public class Unit : WarFoundryObject - { - private UnitType type; - private int size; +using IBBoard.Lang; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for UnitInstance. + /// </summary> + public class Unit : WarFoundryObject + { + private UnitType type; + private int size; private Army army; - private Unit parentUnit; - private double points; - private ArmyCategory cat; + private Unit parentUnit; + private double points; + private ArmyCategory cat; private Dictionary<UnitEquipmentItem, double> equipment = new Dictionary<UnitEquipmentItem, double>(); - private List<Unit> containedUnits = new List<Unit>(); - public event DoubleValChangedDelegate PointsValueChanged; - public event IntValChangedDelegate UnitSizeChanged; - public event DoubleValChangedDelegate UnitEquipmentAmountChanged; - - public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){} - - public Unit(UnitType unitType, int startSize, Army parentArmy) - { - Army = parentArmy; - type = unitType; - Size = startSize; - SetInitialEquipment(); - CalcCost(); - } - - protected override string DefaultName() - { - if (type != null) - { - if (size == 1) - { - return type.Name; - } - else - { - return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); - } - } - else - { - return "Unknown Unit"; - } - } - - private void SetInitialEquipment() - { - foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) - { - if (unitEquip.IsRequired) - { - if (CanEquipWithItem(unitEquip)) - { - equipment[unitEquip] = unitEquip.MinNumber; - } - } - } - } - - private void CalcCost() - { - String oldName = HasDefaultName() ? Name : null; - double oldpoints = points; - points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; - - foreach (UnitEquipmentItem unitEquipItem in equipment.Keys) - { - double count = equipment[unitEquipItem]; - - if (unitEquipItem.IsRatioLimit) - { - if (unitEquipItem.RoundNumberUp) - { - points += Math.Ceiling(size * count) * unitEquipItem.Cost; - } - else - { - points += Math.Floor(size * count) * unitEquipItem.Cost; - } - } - else - { - if (count == WarFoundryCore.INFINITY) - { - points += size * unitEquipItem.Cost; - } - else - { - points += count * unitEquipItem.Cost; - } - } - } - - if (oldpoints!=points) - { - OnPointsValueChanged(oldpoints, points); - } - - if (oldName!=null) - { - OnNameChanged(oldName, Name); - } + private List<Unit> containedUnits = new List<Unit>(); + public event DoubleValChangedDelegate PointsValueChanged; + public event IntValChangedDelegate UnitSizeChanged; + public event DoubleValChangedDelegate UnitEquipmentAmountChanged; + + public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){} + + public Unit(UnitType unitType, int startSize, Army parentArmy) + { + Army = parentArmy; + type = unitType; + Size = startSize; + SetInitialEquipment(); + CalcCost(); + } + + protected override string DefaultName() + { + if (type != null) + { + if (size == 1) + { + return type.Name; + } + else + { + return String.Format(Translation.GetTranslation("defaultUnitName"), size, type.Name); + } + } + else + { + return "Unknown Unit"; + } + } + + private void SetInitialEquipment() + { + foreach (UnitEquipmentItem unitEquip in UnitType.GetEquipmentItems()) + { + if (unitEquip.IsRequired) + { + if (CanEquipWithItem(unitEquip)) + { + equipment[unitEquip] = unitEquip.MinNumber; + } + } + } + } + + private void CalcCost() + { + String oldName = HasDefaultName() ? Name : null; + double oldpoints = points; + points = type.CostPerTrooper * AdditionalTroopers + type.BaseUnitCost; + + foreach (UnitEquipmentItem unitEquipItem in equipment.Keys) + { + double count = equipment[unitEquipItem]; + + if (unitEquipItem.IsRatioLimit) + { + if (unitEquipItem.RoundNumberUp) + { + points += Math.Ceiling(size * count) * unitEquipItem.Cost; + } + else + { + points += Math.Floor(size * count) * unitEquipItem.Cost; + } + } + else + { + if (count == WarFoundryCore.INFINITY) + { + points += size * unitEquipItem.Cost; + } + else + { + points += count * unitEquipItem.Cost; + } + } + } + + if (oldpoints!=points) + { + OnPointsValueChanged(oldpoints, points); + } + + if (oldName!=null) + { + OnNameChanged(oldName, Name); + } } public int AdditionalTroopers { get { return Math.Max(Size - type.BaseSize, 0); } - } - - public int Size - { - get { return size; } - set - { - if (value!=size) - { - int oldValue = size; - size = (value>0 ? value : 1); - CalcCost(); - OnUnitSizeChanged(oldValue, size); - } - } - } - - public UnitType UnitType - { - get { return type; } - } - - public Army Army - { - get { return army; } - set - { - army = value; - - if (army == null) - { - Category = null; - } - } - } - - public Race Race + } + + public int Size + { + get { return size; } + set + { + if (value!=size) + { + int oldValue = size; + size = (value>0 ? value : 1); + CalcCost(); + OnUnitSizeChanged(oldValue, size); + } + } + } + + public UnitType UnitType { - get { return UnitType.Race; } - } - - public ArmyCategory Category - { - get - { - if (cat==null) + get { return type; } + } + + public Army Army + { + get { return army; } + set + { + army = value; + + if (army == null) + { + Category = null; + } + } + } + + public Race Race + { + get { return UnitType.Race; } + } + + public ArmyCategory Category + { + get + { + if (cat==null) { if (Army!=null) - { + { return Army.GetCategory(UnitType.MainCategory); } else { return null; - } - } - else - { - return cat; - } - } - set { cat = value; } - } - - public double PointsValue - { - get - { - if (points == 0) - { - CalcCost(); - } - - return points; - } + } + } + else + { + return cat; + } + } + set { cat = value; } + } + + public double PointsValue + { + get + { + if (points == 0) + { + CalcCost(); + } + + return points; + } } public Unit[] ContainedUnits @@ -238,63 +238,63 @@ } } } - } - - public UnitEquipmentItem[] GetAllowedOptionalEquipment() - { - List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); - - foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems()) - { - if (!item.IsRequired) - { - list.Add(item); - } - } - - return list.ToArray(); - } - - public UnitEquipmentItem[] GetEquipment() - { - return DictionaryUtils.ToKeyArray(equipment); - } - - public EquipmentItem[] GetRequiredEquipment() - { - List<EquipmentItem> list = new List<EquipmentItem>(); - - foreach(UnitEquipmentItem item in GetEquipment()) - { - if (item.IsRequired) - { - list.Add(item.EquipmentItem); - } - } - - return list.ToArray(); - } + } + + public UnitEquipmentItem[] GetAllowedOptionalEquipment() + { + List<UnitEquipmentItem> list = new List<UnitEquipmentItem>(); + + foreach (UnitEquipmentItem item in UnitType.GetEquipmentItems()) + { + if (!item.IsRequired) + { + list.Add(item); + } + } + + return list.ToArray(); + } + + public UnitEquipmentItem[] GetEquipment() + { + return DictionaryUtils.ToKeyArray(equipment); + } + + public EquipmentItem[] GetRequiredEquipment() + { + List<EquipmentItem> list = new List<EquipmentItem>(); + + foreach(UnitEquipmentItem item in GetEquipment()) + { + if (item.IsRequired) + { + list.Add(item.EquipmentItem); + } + } + + return list.ToArray(); + } public double GetEquipmentAmount(UnitEquipmentItem item) { return GetEquipmentAmount(item.ID); - } - - public double GetEquipmentAmount(string equipID) + } + + public double GetEquipmentAmount(string equipID) { - return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID)); + return GetEquipmentAmount(UnitType.GetEquipmentItem(equipID)); } public void SetEquipmentAmount(UnitEquipmentItem equip, int amount) { - if (equip.IsRatioLimit) - { - throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has a ratio limit, not an absolute limit"); - } - - if (amount <1 && amount != WarFoundryCore.INFINITY) - { - amount = 0; + if (equip.IsRatioLimit) + { + throw new InvalidOperationException("Equipment with ID "+equip.ID+" for unit of type "+UnitType.ID+" has a ratio limit, not an absolute limit"); + } + + if (amount <1 && amount != WarFoundryCore.INFINITY) + { + amount = 0; } SetEquipmentAmount(equip, amount); @@ -320,28 +320,28 @@ } private void SetEquipmentAmount(UnitEquipmentItem equip, double amount) - { - double oldAmount = 0; - - if (equipment.ContainsKey(equip)) - { - oldAmount = equipment[equip]; - } - - if (amount!=oldAmount) - { - if (amount != 0) - { - equipment[equip] = amount; - } - else - { - equipment.Remove(equip); - } - - OnUnitEquipmentAmountChanged(equip, oldAmount, amount); - CalcCost(); - } + { + double oldAmount = 0; + + if (equipment.ContainsKey(equip)) + { + oldAmount = equipment[equip]; + } + + if (amount!=oldAmount) + { + if (amount != 0) + { + equipment[equip] = amount; + } + else + { + equipment.Remove(equip); + } + + OnUnitEquipmentAmountChanged(equip, oldAmount, amount); + CalcCost(); + } } public bool CanEquipWithItem(UnitEquipmentItem item) @@ -362,40 +362,40 @@ } return true; - } - - public bool CanEquipWithItem(string equipID) - { - return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); - } - - private void OnPointsValueChanged(double oldValue, double newValue) - { - if (PointsValueChanged!=null) - { - PointsValueChanged(this, oldValue, newValue); - } - } - - private void OnUnitSizeChanged(int oldValue, int newValue) - { - if (UnitSizeChanged!=null) - { - UnitSizeChanged(this, oldValue, newValue); - } - } - - private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) - { - if (UnitEquipmentAmountChanged!=null) - { - UnitEquipmentAmountChanged(equip, oldValue, newValue); - } - } - - public Stat[] UnitStatsArray - { - get { return UnitType.UnitStatsArray; } + } + + public bool CanEquipWithItem(string equipID) + { + return CanEquipWithItem(UnitType.GetEquipmentItem(equipID)); + } + + private void OnPointsValueChanged(double oldValue, double newValue) + { + if (PointsValueChanged!=null) + { + PointsValueChanged(this, oldValue, newValue); + } + } + + private void OnUnitSizeChanged(int oldValue, int newValue) + { + if (UnitSizeChanged!=null) + { + UnitSizeChanged(this, oldValue, newValue); + } + } + + private void OnUnitEquipmentAmountChanged(UnitEquipmentItem equip, double oldValue, double newValue) + { + if (UnitEquipmentAmountChanged!=null) + { + UnitEquipmentAmountChanged(equip, oldValue, newValue); + } + } + + public Stat[] UnitStatsArray + { + get { return UnitType.UnitStatsArray; } } public Stat[] UnitStatsArrayWithName @@ -406,6 +406,6 @@ public string GetStatValue(string statName) { return UnitType.GetStatValue(statName); - } - } -} + } + } +}
--- a/api/Objects/UnitEquipmentItem.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/UnitEquipmentItem.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,18 +2,18 @@ // // 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.Xml; -using IBBoard.Lang; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for UnitEquipmentItem. - /// </summary> - public class UnitEquipmentItem : WarFoundryObject +using IBBoard.Lang; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for UnitEquipmentItem. + /// </summary> + public class UnitEquipmentItem : WarFoundryObject { - private EquipmentItem item; + private EquipmentItem item; private bool required; private bool roundUp; private int minNum; @@ -21,9 +21,9 @@ private double minPercentage; private double maxPercentage; private double costMultiplier; - private RoundType roundType; - private string mutexGroup; - private UnitType unitType; + private RoundType roundType; + private string mutexGroup; + private UnitType unitType; protected UnitEquipmentItem(EquipmentItem equipmentItem, UnitType equipForType) { @@ -44,14 +44,14 @@ public string EquipmentItemID { get { return item.ID; } - } - - public double Cost - { + } + + public double Cost + { get { return IBBMath.Round(EquipmentItem.Cost * CostMultiplier, CostRoundType); - } + } } public double CostMultiplier @@ -70,36 +70,36 @@ { roundType = value; } - } - - public bool IsRequired - { - get { return required; } - set { required = value; } - } - - public bool RoundNumberUp - { - get { return roundUp; } - set { roundUp = value; } - } - - public string MutexGroup - { - get { return mutexGroup; } - set { mutexGroup = (value == null ? "" : value.Trim()); } - } - - public UnitType EquipmentForUnit - { - get { return unitType; } - set - { - if (value != null) - { - unitType = value; - } - } + } + + public bool IsRequired + { + get { return required; } + set { required = value; } + } + + public bool RoundNumberUp + { + get { return roundUp; } + set { roundUp = value; } + } + + public string MutexGroup + { + get { return mutexGroup; } + set { mutexGroup = (value == null ? "" : value.Trim()); } + } + + public UnitType EquipmentForUnit + { + get { return unitType; } + set + { + if (value != null) + { + unitType = value; + } + } } public bool IsRatioLimit @@ -157,29 +157,29 @@ } //TODO: Check Min<Max } - } - - public EquipmentItem EquipmentItem - { - get { return item; } - } - - public override string ToString() - { - return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; - } - - public bool HasAlternatives() - { - if (MutexGroup=="") - { - return false; - } - else - { - //If the number of items in the MutEx group is greater than one then it must be this item plus another - return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; - } + } + + public EquipmentItem EquipmentItem + { + get { return item; } + } + + public override string ToString() + { + return EquipmentItem.Name+ " ("+EquipmentItem.Cost+"pts each)"; + } + + public bool HasAlternatives() + { + if (MutexGroup=="") + { + return false; + } + else + { + //If the number of items in the MutEx group is greater than one then it must be this item plus another + return EquipmentForUnit.GetEquipmentItemsByExclusionGroup(MutexGroup).Length > 1; + } } public ArmourType ItemArmourType @@ -224,6 +224,6 @@ return amount.ToString(); } } - } - } -} + } + } +}
--- a/api/Objects/UnitType.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/UnitType.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,41 +3,41 @@ // 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.Collections.Generic; +using System.Collections.Generic; using System.Xml; using IBBoard.Logging; -using IBBoard.WarFoundry.API.Requirements; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// A UnitType is a type for a <see cref=" Unit"/>, normally relating to an entry in an army list. The UnitType defines the name, cost, minimum and maximum limits of a unit, and the equipment units of the type can take. - /// </summary> - public class UnitType : WarFoundryObject +using IBBoard.WarFoundry.API.Requirements; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// A UnitType is a type for a <see cref=" Unit"/>, normally relating to an entry in an army list. The UnitType defines the name, cost, minimum and maximum limits of a unit, and the equipment units of the type can take. + /// </summary> + public class UnitType : WarFoundryObject { private Category mainCat; - private Race race; - private int min, max, baseSize = 0; + private Race race; + private int min, max, baseSize = 0; private int minSize, maxSize; - private double baseUnitCost; - private double costPerTrooper; - private Stats stats; - private List<UnitRequirement> requirements = new List<UnitRequirement>(); - private Dictionary<string, UnitEquipmentItem> equipment = new Dictionary<string, UnitEquipmentItem>(); - private Dictionary<string, List<UnitEquipmentItem>> equipmentExclusionGroups = new Dictionary<string, List<UnitEquipmentItem>>(); + private double baseUnitCost; + private double costPerTrooper; + private Stats stats; + private List<UnitRequirement> requirements = new List<UnitRequirement>(); + private Dictionary<string, UnitEquipmentItem> equipment = new Dictionary<string, UnitEquipmentItem>(); + private Dictionary<string, List<UnitEquipmentItem>> equipmentExclusionGroups = new Dictionary<string, List<UnitEquipmentItem>>(); private List<string> equipmentKeyOrder = new List<string>(); private Dictionary<string, Ability> requiredAbilities = new Dictionary<string, Ability>(); private Dictionary<string, Ability> optionalAbilities = new Dictionary<string, Ability>(); private String notes = ""; private List<UnitType> containedTypes = new List<UnitType>(); - private Dictionary<string, string> extraData = new Dictionary<string, string>(); - - - public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) - { - race = parentRace; - } - + private Dictionary<string, string> extraData = new Dictionary<string, string>(); + + + public UnitType(string id, string typeName, Race parentRace) : base(id, typeName) + { + race = parentRace; + } + [Obsolete("Use three parameter constructor and setters")] public UnitType(string id, string typeName, string mainCategoryID, string[] allCategoryIDs, int minNum, int maxNum, int minimumSize, int maximumSize, double unitCost, double trooperCost, Stats unitStats, UnitRequirement[] unitRequirements, Race parentRace) : this (id, typeName, parentRace) { @@ -48,13 +48,13 @@ MaxSize = maximumSize; BaseUnitCost = unitCost; CostPerTrooper = trooperCost; - SetUnitStats(unitStats); - - foreach (UnitRequirement requirement in requirements) - { - AddRequirement(requirement); + SetUnitStats(unitStats); + + foreach (UnitRequirement requirement in requirements) + { + AddRequirement(requirement); } - } + } public GameSystem GameSystem { @@ -63,101 +63,101 @@ /// <value> /// Gets the <see cref=" Race"/> that this unit belongs to. - /// </value> - public Race Race - { - get { return race; } - } + /// </value> + public Race Race + { + get { return race; } + } /// <value> /// Gets or sets the <see cref=" Category"/> that this unit type is a member of. - /// </value> - public virtual Category MainCategory - { + /// </value> + public virtual Category MainCategory + { get { return mainCat; - } - set - { - mainCat = value; - } - } + } + set + { + mainCat = value; + } + } /// <value> /// Gets or sets the minimum size of each unit of this type. Note: This should be set AFTER MaxSize, otherwise an unintended default value may be set for the minimum - /// </value> - public int MinSize - { - get { return minSize; } - set + /// </value> + public int MinSize + { + get { return minSize; } + set { - minSize = (value >= 0 ? value : 0); - CheckMinimumSize(); - } - } + minSize = (value >= 0 ? value : 0); + CheckMinimumSize(); + } + } /// <value> /// Gets or sets the maximum size of each unit of this type. Note: This should be set BEFORE MinSize, otherwise an unintended default value may be set for the minimum - /// </value> - public int MaxSize - { - get { return maxSize; } - set - { - maxSize = (value >= 0 ? value : WarFoundryCore.INFINITY); - CheckMinimumSize(); - } + /// </value> + public int MaxSize + { + get { return maxSize; } + set + { + maxSize = (value >= 0 ? value : WarFoundryCore.INFINITY); + CheckMinimumSize(); + } } - + /// <value> /// Gets or sets the minimum number of units of this type that must be taken in an army. Note: This should be set AFTER MaxNumber, otherwise an unintended default value may be set for the minimum - /// </value> - public int MinNumber - { - get { return min; } - set + /// </value> + public int MinNumber + { + get { return min; } + set { - min = (value >= 0 ? value : 0); - CheckMinimumNumber(); - } - } + min = (value >= 0 ? value : 0); + CheckMinimumNumber(); + } + } /// <value> /// Gets or sets the maximum number of units of this type that can be taken in an army. Note: This should be set BEFORE MinNumber, otherwise an unintended default value may be set for the minimum - /// </value> - public int MaxNumber - { - get { return max; } - set - { - max = (value >= 0 ? value : WarFoundryCore.INFINITY); - CheckMinimumNumber(); - } - } + /// </value> + public int MaxNumber + { + get { return max; } + set + { + max = (value >= 0 ? value : WarFoundryCore.INFINITY); + CheckMinimumNumber(); + } + } /// <summary> /// Makes sure that the minimum number isn't more than the maximum number, hence the warning on the properties - /// </summary> - private void CheckMinimumNumber() - { + /// </summary> + private void CheckMinimumNumber() + { 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); - } - } + } + } /// <summary> /// Makes sure that the minimum unit size isn't more than the maximum unit size, hence the warning on the properties - /// </summary> - private void CheckMinimumSize() - { + /// </summary> + private void CheckMinimumSize() + { 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); - } + } } //// <value> @@ -174,33 +174,33 @@ /// </value> public double BaseUnitCost { - get { return baseUnitCost; } + get { return baseUnitCost; } set { baseUnitCost = (value >= 0 ? value : 0); } - } + } //// <value> /// The cost of an individual trooper. This value is the cost for a basic trooper without weapons, which are added on top of the cost before calculating a unit cost. - /// </value> - public double CostPerTrooper - { - get { return costPerTrooper; } - set { costPerTrooper = (value >= 0 ? value : 0); } - } - - protected override string DefaultName() - { - throw new InvalidOperationException("Unit type with id "+id+" did not have a name specified"); - } + /// </value> + public double CostPerTrooper + { + get { return costPerTrooper; } + set { costPerTrooper = (value >= 0 ? value : 0); } + } + + protected override string DefaultName() + { + throw new InvalidOperationException("Unit type with id "+id+" did not have a name specified"); + } /// <value> /// The set of <see cref="Stat"/>s for the unit in a format that is valid for the game system. - /// </value> - public Stat[] UnitStatsArray - { - get - { - return stats.StatsArray; - } + /// </value> + public Stat[] UnitStatsArray + { + get + { + return stats.StatsArray; + } } //// <value> @@ -250,7 +250,7 @@ items.Add(item); } - } + } /// <summary> /// Gets a <see cref="UnitEquipmentItem"/> for the given ID string, or <code>null</code> if nothing exists for that ID @@ -260,10 +260,10 @@ /// </param> /// <returns> /// The <see cref="UnitEquipmentItem"/> for the given ID string, or <code>null</code> if nothing exists for that ID - /// </returns> - public UnitEquipmentItem GetEquipmentItem(string id) + /// </returns> + public UnitEquipmentItem GetEquipmentItem(string id) { - return DictionaryUtils.GetValue(equipment, id); + return DictionaryUtils.GetValue(equipment, id); } /// <summary> @@ -278,17 +278,17 @@ public UnitEquipmentItem GetEquipmentItem(EquipmentItem item) { return GetEquipmentItem(item.ID); - } + } /// <summary> /// Gets an array of all available <see cref="UnitEquipmentItem"/>s for this UnitType /// </summary> /// <returns> /// An array of all available <see cref="UnitEquipmentItem"/>s for this UnitType - /// </returns> - public UnitEquipmentItem[] GetEquipmentItems() - { - return DictionaryUtils.ToArray<string, UnitEquipmentItem>(equipment); + /// </returns> + public UnitEquipmentItem[] GetEquipmentItems() + { + return DictionaryUtils.ToArray<string, UnitEquipmentItem>(equipment); } public UnitEquipmentItem[] GetEquipmentItemsByExclusionGroup(string group) @@ -342,23 +342,23 @@ optionalAbilities[id] = ability; } } - } - - public void AddRequirement(UnitRequirement requirement) - { - requirements.Add(requirement); + } + + public void AddRequirement(UnitRequirement requirement) + { + requirements.Add(requirement); } public UnitRequirement[] Requirements { get { return requirements.ToArray(); } - } + } public List<FailedUnitRequirement> CanAddToArmy(Army army) { List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>(); - if (requirements!=null && requirements.Count > 0) + if (requirements!=null && requirements.Count > 0) { foreach (UnitRequirement requirement in requirements) { @@ -378,7 +378,7 @@ { List<FailedUnitRequirement> failures = new List<FailedUnitRequirement>(); - if (requirements!=null && requirements.Count > 0) + if (requirements!=null && requirements.Count > 0) { foreach (UnitRequirement requirement in requirements) { @@ -428,6 +428,6 @@ public string GetExtraData(string id) { return DictionaryUtils.GetValue(extraData, id); - } - } + } + } } \ No newline at end of file
--- a/api/Objects/WarFoundryObject.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Objects/WarFoundryObject.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,17 +3,17 @@ // 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 IBBoard.WarFoundry.API.Factories; - -namespace IBBoard.WarFoundry.API.Objects -{ - /// <summary> - /// Summary description for WarFoundryObject. - /// </summary> - public abstract class WarFoundryObject : IWarFoundryObject +using IBBoard.WarFoundry.API.Factories; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// Summary description for WarFoundryObject. + /// </summary> + public abstract class WarFoundryObject : IWarFoundryObject { - protected string id; - protected string name; + protected string id; + protected string name; public event StringValChangedDelegate NameChanged; protected WarFoundryObject() @@ -28,10 +28,10 @@ protected WarFoundryObject(string objId, string objName) : this(objName) { ID = objId; - } - - public virtual string ID - { + } + + public virtual string ID + { get { if (id == null) @@ -41,56 +41,56 @@ return id; } - - set { id = (value == null ? GenerateID() : value.Trim()); } - } - - public virtual string Name - { - get - { - if (HasDefaultName()) - { - return DefaultName(); - } - else - { - return name; - } - } - set - { - string oldValue = name; - name = value; - - if (name!=oldValue) - { - OnNameChanged(oldValue, name); - } - } - } - - protected bool HasDefaultName() - { - return (name == null || name == ""); - } - - protected void OnNameChanged(string oldValue, string newValue) - { - if (NameChanged!=null) - { - NameChanged(this, oldValue, newValue); - } - } - - protected virtual string DefaultName() - { - return "-"; - } - - protected string GenerateID() - { - return "ID" + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond; - } - } -} + + set { id = (value == null ? GenerateID() : value.Trim()); } + } + + public virtual string Name + { + get + { + if (HasDefaultName()) + { + return DefaultName(); + } + else + { + return name; + } + } + set + { + string oldValue = name; + name = value; + + if (name!=oldValue) + { + OnNameChanged(oldValue, name); + } + } + } + + protected bool HasDefaultName() + { + return (name == null || name == ""); + } + + protected void OnNameChanged(string oldValue, string newValue) + { + if (NameChanged!=null) + { + NameChanged(this, oldValue, newValue); + } + } + + protected virtual string DefaultName() + { + return "-"; + } + + protected string GenerateID() + { + return "ID" + UnixTimestamp.GetTimestamp(DateTime.Now) + "." + DateTime.Now.Millisecond; + } + } +}
--- a/api/Requirements/AbstractFailedRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/AbstractFailedRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -14,7 +14,7 @@ { failedReq = req; } - + public abstract string Description { get; } } }
--- a/api/Requirements/AbstractRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/AbstractRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -11,7 +11,7 @@ /// The base class for Requirements. Specific types of abstract requirement should extend this class. /// </summary> public abstract class AbstractRequirement - { + { public abstract string Description { get; } public abstract AbstractFailedRequirement CanAddToWarFoundryObject(WarFoundryObject obj); public abstract AbstractFailedRequirement CanRemoveFromWarFoundryObject(WarFoundryObject obj);
--- a/api/Requirements/Delegates.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/Delegates.cs Sat Jun 27 18:59:49 2009 +0000 @@ -6,6 +6,6 @@ using System.Collections.Generic; namespace IBBoard.WarFoundry.API.Requirements -{ +{ public delegate void FailedUnitRequirementDelegate(List<FailedUnitRequirement> failedRequirements); }
--- a/api/Requirements/FailedUnitRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/FailedUnitRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,14 +2,14 @@ // // 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; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequirement. - /// </summary> - public class FailedUnitRequirement : AbstractFailedRequirement +using System; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequirement. + /// </summary> + public class FailedUnitRequirement : AbstractFailedRequirement { public FailedUnitRequirement(UnitRequirement requirement) : base(requirement) { @@ -19,6 +19,6 @@ { get { return failedReq.Description; } } - - } -} + + } +}
--- a/api/Requirements/RequirementAND.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/RequirementAND.cs Sat Jun 27 18:59:49 2009 +0000 @@ -5,62 +5,62 @@ using System; using System.Collections.Generic; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for RequirementAND. - /// </summary> - public class RequirementAND : AbstractRequirement - { - private static string and; - - static RequirementAND() - { - and = Translation.GetTranslation("requirement_and", true); - - if (and == null) - { - and = "{0}; and {1}"; - } - } - - private AbstractRequirement reqA, reqB; - - public RequirementAND(AbstractRequirement requirementA, AbstractRequirement requirementB) - { - reqA = requirementA; - reqB = requirementB; - } - - public override AbstractFailedRequirement CanAddToWarFoundryObject(WarFoundryObject obj) +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for RequirementAND. + /// </summary> + public class RequirementAND : AbstractRequirement + { + private static string and; + + static RequirementAND() + { + and = Translation.GetTranslation("requirement_and", true); + + if (and == null) + { + and = "{0}; and {1}"; + } + } + + private AbstractRequirement reqA, reqB; + + public RequirementAND(AbstractRequirement requirementA, AbstractRequirement requirementB) + { + reqA = requirementA; + reqB = requirementB; + } + + public override AbstractFailedRequirement CanAddToWarFoundryObject(WarFoundryObject obj) { FailedRequirement failed = null; - + if (reqA.CanAddToWarFoundryObject(obj) !=null || reqB.CanAddToWarFoundryObject(obj)!=null) { failed = new FailedRequirement(this); } - return failed; - } - - public override AbstractFailedRequirement CanRemoveFromWarFoundryObject(WarFoundryObject obj) + return failed; + } + + public override AbstractFailedRequirement CanRemoveFromWarFoundryObject(WarFoundryObject obj) { FailedRequirement failed = null; - + if (reqA.CanRemoveFromWarFoundryObject(obj) !=null || reqB.CanRemoveFromWarFoundryObject(obj)!=null) { failed = new FailedRequirement(this); } - return failed; - } - - public override string Description - { - get { return String.Format(and, reqA.Description, reqB.Description); } - } - } -} + return failed; + } + + public override string Description + { + get { return String.Format(and, reqA.Description, reqB.Description); } + } + } +}
--- a/api/Requirements/RequirementOR.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/RequirementOR.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,65 +2,65 @@ // // 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.Collections.Generic; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequirementOR. - /// </summary> - public class RequirementOR : AbstractRequirement - { - private static string or; - - static RequirementOR() - { - or = Translation.GetTranslation("requirement_or", true); - - if (or == null) - { - or = "{0} or {1}"; - } - } - - private AbstractRequirement reqA, reqB; - - public RequirementOR(AbstractRequirement requirementA, AbstractRequirement requirementB) - { - reqA = requirementA; - reqB = requirementB; - } - - public override AbstractFailedRequirement CanAddToWarFoundryObject(WarFoundryObject obj) +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequirementOR. + /// </summary> + public class RequirementOR : AbstractRequirement + { + private static string or; + + static RequirementOR() + { + or = Translation.GetTranslation("requirement_or", true); + + if (or == null) + { + or = "{0} or {1}"; + } + } + + private AbstractRequirement reqA, reqB; + + public RequirementOR(AbstractRequirement requirementA, AbstractRequirement requirementB) + { + reqA = requirementA; + reqB = requirementB; + } + + public override AbstractFailedRequirement CanAddToWarFoundryObject(WarFoundryObject obj) { FailedRequirement failed = null; - + if (reqA.CanAddToWarFoundryObject(obj) !=null && reqB.CanAddToWarFoundryObject(obj)!=null) { failed = new FailedRequirement(this); } - return failed; - } - - public override AbstractFailedRequirement CanRemoveFromWarFoundryObject(WarFoundryObject obj) + return failed; + } + + public override AbstractFailedRequirement CanRemoveFromWarFoundryObject(WarFoundryObject obj) { FailedRequirement failed = null; - + if (reqA.CanRemoveFromWarFoundryObject(obj)!=null && reqB.CanRemoveFromWarFoundryObject(obj)!=null) { failed = new FailedRequirement(this); } - return failed; - } - - public override string Description - { - get { return String.Format(or, reqA.Description, reqB.Description); } - } - } -} + return failed; + } + + public override string Description + { + get { return String.Format(or, reqA.Description, reqB.Description); } + } + } +}
--- a/api/Requirements/UnitExcludesRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitExcludesRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -4,50 +4,50 @@ using System; using System.Collections.Generic; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitExcludesRequirement. - /// </summary> - public class UnitExcludesRequirement : UnitRequirement - { - private UnitRequirementItem[] excludingTypes; - - public UnitExcludesRequirement(UnitType type, UnitRequirementItem[] excludingUnitTypes) : base(type) - { - excludingTypes = excludingUnitTypes; - } - - public override string Description - { - get - { - return "Some units are already included that excluded this unit"; - } - } - - protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitExcludesRequirement. + /// </summary> + public class UnitExcludesRequirement : UnitRequirement + { + private UnitRequirementItem[] excludingTypes; + + public UnitExcludesRequirement(UnitType type, UnitRequirementItem[] excludingUnitTypes) : base(type) + { + excludingTypes = excludingUnitTypes; + } + + public override string Description + { + get + { + return "Some units are already included that excluded this unit"; + } + } + + protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) { - FailedUnitRequirement failed = null; - - for (int i = 0; i<excludingTypes.Length; i++) - { - if (army.GetUnitTypeCount(excludingTypes[i].UnitType) > 0) - { + FailedUnitRequirement failed = null; + + for (int i = 0; i<excludingTypes.Length; i++) + { + if (army.GetUnitTypeCount(excludingTypes[i].UnitType) > 0) + { failed = new FailedUnitRequirement(this); - break; - } + break; + } } - return failed; - } - - protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) - { - return null; - } - - } -} + return failed; + } + + protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) + { + return null; + } + + } +}
--- a/api/Requirements/UnitExclusion.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitExclusion.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,44 +2,44 @@ // // 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.Text; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitMaxNumberRequirement. - /// </summary> - public class UnitExclusion : FailedUnitRequirement - { - private string unitList; - private UnitType type; - - public UnitExclusion(UnitRequirement req, UnitType unitType, UnitType[] excludingTypes) : base(req) - { - type = unitType; - - if (excludingTypes.Length > 1) - { - StringBuilder sb = new StringBuilder(excludingTypes[0].Name); - - for (int i = 1; i<excludingTypes.Length; i++) - { - sb.Append(", "+excludingTypes[i].Name); - } - - unitList = sb.ToString(); - } - else - { - unitList = excludingTypes[0].Name; - } - } - - public override string Description - { - get { return "The army cannot have any of the following units to include a unit of type "+type.Name+": "+unitList; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitMaxNumberRequirement. + /// </summary> + public class UnitExclusion : FailedUnitRequirement + { + private string unitList; + private UnitType type; + + public UnitExclusion(UnitRequirement req, UnitType unitType, UnitType[] excludingTypes) : base(req) + { + type = unitType; + + if (excludingTypes.Length > 1) + { + StringBuilder sb = new StringBuilder(excludingTypes[0].Name); + + for (int i = 1; i<excludingTypes.Length; i++) + { + sb.Append(", "+excludingTypes[i].Name); + } + + unitList = sb.ToString(); + } + else + { + unitList = excludingTypes[0].Name; + } + } + + public override string Description + { + get { return "The army cannot have any of the following units to include a unit of type "+type.Name+": "+unitList; } + } + } +}
--- a/api/Requirements/UnitMaxNumberReached.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitMaxNumberReached.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,28 +2,28 @@ // // 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 IBBoard; using IBBoard.Lang; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitMaxNumberRequirement. - /// </summary> - public class UnitMaxNumberReached : FailedUnitRequirement - { - private UnitType type; - - public UnitMaxNumberReached(UnitType unitType, UnitRequirementMaxNumber requirement) : base(requirement) - { - type = unitType; - } - - public override string Description - { - get { return String.Format(Translation.GetTranslation("ErrorUnitMaxNumberReached", "The maximum number of units of type \"{0}\" has already been reached or exceeded."), type.Name); } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitMaxNumberRequirement. + /// </summary> + public class UnitMaxNumberReached : FailedUnitRequirement + { + private UnitType type; + + public UnitMaxNumberReached(UnitType unitType, UnitRequirementMaxNumber requirement) : base(requirement) + { + type = unitType; + } + + public override string Description + { + get { return String.Format(Translation.GetTranslation("ErrorUnitMaxNumberReached", "The maximum number of units of type \"{0}\" has already been reached or exceeded."), type.Name); } + } + } +}
--- a/api/Requirements/UnitMinNumberReached.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitMinNumberReached.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,25 +3,25 @@ // 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 IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitMaxNumberRequirement. - /// </summary> - public class UnitMinNumberReached : FailedUnitRequirement - { - private UnitType type; - - public UnitMinNumberReached(UnitType unitType, UnitRequirementMinNumber requirement) : base(requirement) - { - type = unitType; - } - - public override string Description - { - get { return "The minimum number of units of type "+type.Name+" is not currently met"; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitMaxNumberRequirement. + /// </summary> + public class UnitMinNumberReached : FailedUnitRequirement + { + private UnitType type; + + public UnitMinNumberReached(UnitType unitType, UnitRequirementMinNumber requirement) : base(requirement) + { + type = unitType; + } + + public override string Description + { + get { return "The minimum number of units of type "+type.Name+" is not currently met"; } + } + } +}
--- a/api/Requirements/UnitRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,17 +2,17 @@ // // 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.Collections.Generic; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequirement. - /// </summary> - public abstract class UnitRequirement : AbstractArmyRequirement + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequirement. + /// </summary> + public abstract class UnitRequirement : AbstractArmyRequirement { protected UnitType unitType; @@ -82,15 +82,15 @@ { return CanRemoveFromArmy(army, unit.UnitType); } - + protected override AbstractFailedRequirement CanAddToArmy(Army army) { return CanAddToArmy(army, unitType); } - + protected override AbstractFailedRequirement CanRemoveFromArmy(Army army) { return CanRemoveFromArmy(army, unitType); - } - } -} + } + } +}
--- a/api/Requirements/UnitRequirementItem.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitRequirementItem.cs Sat Jun 27 18:59:49 2009 +0000 @@ -3,34 +3,34 @@ // 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 IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequirementItem. - /// </summary> - public class UnitRequirementItem - { - private UnitType type; - private int requiredNum; - - public UnitRequirementItem(UnitType unitType, int reqNumber) - { - type = unitType; - requiredNum = reqNumber; - } - - public UnitRequirementItem(UnitType type) : this(type, 1) { } - - public UnitType UnitType - { - get { return type; } - } - - public int Amount - { - get { return requiredNum; } - } - } -} +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequirementItem. + /// </summary> + public class UnitRequirementItem + { + private UnitType type; + private int requiredNum; + + public UnitRequirementItem(UnitType unitType, int reqNumber) + { + type = unitType; + requiredNum = reqNumber; + } + + public UnitRequirementItem(UnitType type) : this(type, 1) { } + + public UnitType UnitType + { + get { return type; } + } + + public int Amount + { + get { return requiredNum; } + } + } +}
--- a/api/Requirements/UnitRequiresAtLeastRequirement.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/Requirements/UnitRequiresAtLeastRequirement.cs Sat Jun 27 18:59:49 2009 +0000 @@ -2,28 +2,28 @@ // // 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.Collections.Generic; using System.Text; using IBBoard.WarFoundry.API; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Requirements -{ - /// <summary> - /// Summary description for UnitRequiresRequirement. - /// </summary> - public class UnitRequiresAtLeastRequirement : UnitRequirement - { +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Requirements +{ + /// <summary> + /// Summary description for UnitRequiresRequirement. + /// </summary> + public class UnitRequiresAtLeastRequirement : UnitRequirement + { private UnitType[] requiredTypes; private int[] requiredCounts; - private String unitList; - - public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1}) - { + private String unitList; + + public UnitRequiresAtLeastRequirement(UnitType type, UnitType requiredUnitType) : this(type, new UnitType[]{requiredUnitType}, new int[]{1}) + { } - public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type) + public UnitRequiresAtLeastRequirement(UnitType type, UnitType[] requiredUnitTypes, int[] minNumsRequired) : base(type) { if (requiredUnitTypes.Length != minNumsRequired.Length) { @@ -33,52 +33,52 @@ { throw new ArgumentException("List of required unit types must not be empty"); } - + requiredTypes = requiredUnitTypes; - requiredCounts = minNumsRequired; - - if (requiredTypes.Length > 1) - { - StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name); - - for (int i = 1; i<requiredTypes.Length; i++) - { - sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name); - } - - unitList = sb.ToString(); - } - else - { - unitList = requiredTypes[0].Name; - } - } - - public override string Description - { - get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; } - } - - protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) - { - return null; - } - - protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) + requiredCounts = minNumsRequired; + + if (requiredTypes.Length > 1) + { + StringBuilder sb = new StringBuilder(requiredCounts[0]+" x "+requiredTypes[0].Name); + + for (int i = 1; i<requiredTypes.Length; i++) + { + sb.Append(", "+requiredCounts[i]+" x "+requiredTypes[i].Name); + } + + unitList = sb.ToString(); + } + else + { + unitList = requiredTypes[0].Name; + } + } + + public override string Description + { + get { return "The army must include at least the following units to include a unit of type "+unitType.Name+": "+unitList; } + } + + protected override AbstractFailedRequirement CanRemoveFromArmy(Army army, UnitType type) + { + return null; + } + + protected override AbstractFailedRequirement CanAddToArmy(Army army, UnitType type) { FailedRequirement failure = null; int count = requiredTypes.Length; for (int i = 0; i < count; i++) - { - if (army.GetUnitTypeCount(requiredTypes[i]) < requiredCounts[i]) - { + { + if (army.GetUnitTypeCount(requiredTypes[i]) < requiredCounts[i]) + { failure = new FailedRequirement(this); - break; + break; } } - return failure; - } - } -} + return failure; + } + } +}
--- a/api/WarFoundryCore.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/WarFoundryCore.cs Sat Jun 27 18:59:49 2009 +0000 @@ -11,20 +11,20 @@ public class WarFoundryCore { public static readonly int INFINITY = -1; - public static event GameSystemChangedDelegate GameSystemChanged; + public static event GameSystemChangedDelegate GameSystemChanged; public static event ArmyChangedDelegate ArmyChanged; private static GameSystem system; private static Army currentArmy; - public static GameSystem CurrentGameSystem - { - get { return system; } - set - { - if (system==null || !system.Equals(value)) + public static GameSystem CurrentGameSystem + { + get { return system; } + set + { + if (system==null || !system.Equals(value)) { - GameSystem oldSystem = system; + GameSystem oldSystem = system; system = value; if (system==null) @@ -34,55 +34,55 @@ else { LogNotifier.DebugFormat(typeof(WarFoundryCore), "Game system set to {0} with ID {1}", system.Name, system.ID); - } - - if (GameSystemChanged!=null) - { - GameSystemChanged(oldSystem, system); + } + + if (GameSystemChanged!=null) + { + GameSystemChanged(oldSystem, system); } //If we've changed the game system then we can't keep the current army - CurrentArmy = null; - } - } + CurrentArmy = null; + } + } } - public static Army CurrentArmy - { - get { return currentArmy; } - set - { - if (currentArmy==null || !currentArmy.Equals(value)) - { - /*if (currentArmy!=null) - { - currentArmy.UnitAdded-= UnitAddedMethod; - currentArmy.UnitRemoved-= UnitRemovedMethod; - currentArmy.PointsValueChanged-= PointsValueChangedMethod; - currentArmy.FailedRequirement-=FailedUnitRequirementMethod; - }*/ - Army oldArmy = currentArmy; + public static Army CurrentArmy + { + get { return currentArmy; } + set + { + if (currentArmy==null || !currentArmy.Equals(value)) + { + /*if (currentArmy!=null) + { + currentArmy.UnitAdded-= UnitAddedMethod; + currentArmy.UnitRemoved-= UnitRemovedMethod; + currentArmy.PointsValueChanged-= PointsValueChangedMethod; + currentArmy.FailedRequirement-=FailedUnitRequirementMethod; + }*/ + Army oldArmy = currentArmy; currentArmy = value; if (currentArmy!=null) { CurrentGameSystem = currentArmy.GameSystem; //Set the game system in case the new army is from a different system - } - - /*if (currentArmy!=null) - { - currentArmy.UnitAdded+= UnitAddedMethod; - currentArmy.UnitRemoved+= UnitRemovedMethod; - currentArmy.PointsValueChanged+= PointsValueChangedMethod; - currentArmy.FailedRequirement+=FailedUnitRequirementMethod; - }*/ - - if (ArmyChanged!=null) - { - ArmyChanged(oldArmy, currentArmy); - } - } - } + } + + /*if (currentArmy!=null) + { + currentArmy.UnitAdded+= UnitAddedMethod; + currentArmy.UnitRemoved+= UnitRemovedMethod; + currentArmy.PointsValueChanged+= PointsValueChangedMethod; + currentArmy.FailedRequirement+=FailedUnitRequirementMethod; + }*/ + + if (ArmyChanged!=null) + { + ArmyChanged(oldArmy, currentArmy); + } + } + } } } }
--- a/api/WarFoundryLoader.cs Wed May 27 19:43:09 2009 +0000 +++ b/api/WarFoundryLoader.cs Sat Jun 27 18:59:49 2009 +0000 @@ -482,14 +482,14 @@ protected void StoreGameSystem(GameSystem system) { string sysid = system.ID.ToLower(); - - if (systemsTable.ContainsKey(sysid)) - { - LogNotifier.WarnFormat(GetType(), "System {0} ({1}) has already been loaded. Duplicate file ({3}) discarded", system.Name, system.ID, system.SourceFile.FullName); - } - else + + if (systemsTable.ContainsKey(sysid)) { - systemsTable.Add(sysid, (GameSystem)system); + LogNotifier.WarnFormat(GetType(), "System {0} ({1}) has already been loaded. Duplicate file ({3}) discarded", system.Name, system.ID, system.SourceFile.FullName); + } + else + { + systemsTable.Add(sysid, (GameSystem)system); } } @@ -538,14 +538,14 @@ /// An array of <see cref="GameSystem"/>s that are currently available. /// </returns> public GameSystem[] GetGameSystems() - { - if (systemsTable==null) - { - LoadFiles(); + { + if (systemsTable==null) + { + LoadFiles(); } return DictionaryUtils.ToArray<string, GameSystem>(systemsTable); - } + } /// <summary> /// Gets a single <see cref="GameSystem"/> with a given ID. @@ -555,18 +555,18 @@ /// </param> /// <returns> /// The <see cref="GameSystem"/> with the given ID, or <code>null</code> if one doesn't exist. - /// </returns> - public GameSystem GetGameSystem(string systemID) - { - if (systemsTable==null) - { - LoadFiles(); + /// </returns> + public GameSystem GetGameSystem(string systemID) + { + if (systemsTable==null) + { + LoadFiles(); } GameSystem system; - systemsTable.TryGetValue(systemID.ToLower(), out system); - return system; - } + systemsTable.TryGetValue(systemID.ToLower(), out system); + return system; + } /// <summary> /// Gets an array of the races for the specified <see cref="GameSystem"/>. @@ -576,11 +576,11 @@ /// </param> /// <returns> /// An array of <see cref="Race"/>s for the <see cref="GameSystem"/> - /// </returns> - public Race[] GetRaces(GameSystem system) - { - return GetRaces(system.ID); - } + /// </returns> + public Race[] GetRaces(GameSystem system) + { + return GetRaces(system.ID); + } /// <summary> /// Gets an array of the races for a game system by ID. @@ -590,43 +590,43 @@ /// </param> /// <returns> /// An array of <see cref="Race"/>s for the specified game system - /// </returns> - public Race[] GetRaces(string systemID) - { - if (racesTable==null) - { - LoadFiles(); + /// </returns> + public Race[] GetRaces(string systemID) + { + if (racesTable==null) + { + LoadFiles(); } - systemID = systemID.ToLower(); + systemID = systemID.ToLower(); Dictionary<string, Dictionary<string, Race>> system; - racesTable.TryGetValue(systemID, out system); - - if (system==null) - { - return new Race[0]; - } - - int count = 0; - - foreach (Dictionary<string, Race> racesDict in system.Values) - { - count+= racesDict.Count; - } - - Race[] races = new Race[count]; - int i = 0; - - foreach (string raceID in system.Keys) - { - foreach (string raceSubId in system[raceID].Keys) - { - races[i++] = GetRace(systemID, raceID, raceSubId); - } - } - - return races; - } + racesTable.TryGetValue(systemID, out system); + + if (system==null) + { + return new Race[0]; + } + + int count = 0; + + foreach (Dictionary<string, Race> racesDict in system.Values) + { + count+= racesDict.Count; + } + + Race[] races = new Race[count]; + int i = 0; + + foreach (string raceID in system.Keys) + { + foreach (string raceSubId in system[raceID].Keys) + { + races[i++] = GetRace(systemID, raceID, raceSubId); + } + } + + return races; + } /// <summary> /// Gets a single race for a given <see cref="GameSystem"/> by ID of the race. @@ -639,11 +639,11 @@ /// </param> /// <returns> /// A <see cref="Race"/> with the specified ID from the <see cref="GameSystem"/>, or <code>null</code> if one doesn't exist. - /// </returns> - public Race GetRace(GameSystem system, string raceID) - { - return GetRace(system.ID, raceID); - } + /// </returns> + public Race GetRace(GameSystem system, string raceID) + { + return GetRace(system.ID, raceID); + } /// <summary> /// Gets a single race for a given game system by ID of the game system and race. @@ -656,11 +656,11 @@ /// </param> /// <returns> /// A <see cref="Race"/> with the specified ID from the game system with the specified ID, or <code>null</code> if there is no race or game system with those IDs. - /// </returns> - public Race GetRace(string systemID, string raceID) - { - return GetRace(systemID, raceID, ""); - } + /// </returns> + public Race GetRace(string systemID, string raceID) + { + return GetRace(systemID, raceID, ""); + } /// <summary> /// Gets a single race for a given <see cref="GameSystem"/> by the race's ID and sub-race ID. @@ -676,11 +676,11 @@ /// </param> /// <returns> /// A <see cref="Race"/> - /// </returns> - public Race GetRace(GameSystem system, string raceID, string raceSubID) - { - return GetRace(system.ID, raceID, raceSubID); - } + /// </returns> + public Race GetRace(GameSystem system, string raceID, string raceSubID) + { + return GetRace(system.ID, raceID, raceSubID); + } /// <summary> /// Gets a single race for a given game system by the game system's ID and the race's ID and sub-race ID. @@ -696,57 +696,57 @@ /// </param> /// <returns> /// A <see cref="Race"/> - /// </returns> - public Race GetRace(string systemID, string raceID, string raceSubID) - { - if (racesTable==null) - { - LoadFiles(); + /// </returns> + public Race GetRace(string systemID, string raceID, string raceSubID) + { + if (racesTable==null) + { + LoadFiles(); } Race race = null; - systemID = systemID.ToLower(); - + systemID = systemID.ToLower(); + Dictionary<string, Dictionary<string, Race>> races; - racesTable.TryGetValue(systemID, out races); - - if (races!=null) - { + racesTable.TryGetValue(systemID, out races); + + if (races!=null) + { Dictionary<string, Race> subraces; - races.TryGetValue(raceID, out subraces); - - if (subraces!=null) + races.TryGetValue(raceID, out subraces); + + if (subraces!=null) { - subraces.TryGetValue(raceSubID, out race); - } + subraces.TryGetValue(raceSubID, out race); + } } - return race; - } + return race; + } /// <summary> /// Gets the IDs of all of the game systems currently available. /// </summary> /// <returns> /// An array of <see cref="System.String"/>s representing the IDs of the game systems. - /// </returns> - public string[] GetGameSystemIDs() - { - if (systemsTable==null) - { - LoadFiles(); - } - - string[] keys = new string[systemsTable.Keys.Count]; - int i = 0; - - foreach (string key in systemsTable.Keys) - { - keys[i++] = key; - } - - return keys; + /// </returns> + public string[] GetGameSystemIDs() + { + if (systemsTable==null) + { + LoadFiles(); + } + + string[] keys = new string[systemsTable.Keys.Count]; + int i = 0; + + foreach (string key in systemsTable.Keys) + { + keys[i++] = key; + } + + return keys; } /// <summary> @@ -761,7 +761,7 @@ public string[] GetSystemRaceIDs(GameSystem system) { return GetSystemRaceIDs(system.ID); - } + } /// <summary> /// Gets the IDs of all of the races of a specified game system. @@ -771,32 +771,32 @@ /// </param> /// <returns> /// An array of <see cref="System.String"/>s representing the IDs of the races of the specified game system. - /// </returns> - public string[] GetSystemRaceIDs(string systemID) - { - if (racesTable == null) - { - LoadFiles(); - } - - Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()]; - - if (races==null) - { - return new string[0]; - } - else - { - string[] keys = new string[races.Keys.Count]; - int i = 0; - - foreach (string key in races.Keys) - { - keys[i++] = key; - } - - return keys; - } + /// </returns> + public string[] GetSystemRaceIDs(string systemID) + { + if (racesTable == null) + { + LoadFiles(); + } + + Dictionary<string, Dictionary<string, Race>> races = racesTable[systemID.ToLower()]; + + if (races==null) + { + return new string[0]; + } + else + { + string[] keys = new string[races.Keys.Count]; + int i = 0; + + foreach (string key in races.Keys) + { + keys[i++] = key; + } + + return keys; + } } } }