Show
Ignore:
Timestamp:
06/27/09 14:39:04 (14 months ago)
Author:
ibboard
Message:

Re #90: Stop new units showing up twice

  • Hand all of unit adding/removing down to category
  • Refactor out OnFailedRequirement method in Army
  • Make Army listen to and propogate FailedRequirement events from Units
  • Add OnUnitAdded/Removed method to ArmyCategory that takes list of failures
  • Remove direct reference to Army from Unit and go via ArmyCategory instead
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • IBBoard.WarFoundry.API/trunk/api/Objects/Unit.cs

    r143 r146  
    1818        private UnitType type; 
    1919        private int size; 
    20         private Army army; 
    2120        private Unit parentUnit; 
    2221        private double points; 
     
    2827        public event DoubleValChangedDelegate UnitEquipmentAmountChanged; 
    2928 
    30         public Unit(UnitType unitType, Army parentArmy) : this(unitType, unitType.MinSize, parentArmy){} 
    31  
    32         public Unit(UnitType unitType, int startSize, Army parentArmy) 
    33         { 
    34             Army = parentArmy; 
     29        public Unit(UnitType unitType, ArmyCategory parentArmyCat) : this(unitType, unitType.MinSize, parentArmyCat) { } 
     30 
     31        public Unit(UnitType unitType, int startSize, ArmyCategory parentArmyCat) 
     32        { 
     33            Category = parentArmyCat; 
    3534            type = unitType; 
    3635            Size = startSize; 
     
    144143        public Army Army 
    145144        { 
    146             get { return army; } 
    147             set  
    148             { 
    149                 army = value; 
    150  
    151                 if (army == null) 
    152                 { 
    153                     Category = null; 
    154                 } 
    155             } 
     145            get { return (Category == null ? null : Category.ParentArmy); } 
    156146        } 
    157147 
     
    163153        public ArmyCategory Category 
    164154        { 
    165             get  
    166             {  
    167                 if (cat==null) 
    168                 { 
    169                     if (Army!=null) 
    170                     { 
    171                         return Army.GetCategory(UnitType.MainCategory); 
    172                     } 
    173                     else 
    174                     { 
    175                         return null; 
    176                     } 
    177                 } 
    178                 else 
    179                 { 
    180                     return cat;  
    181                 } 
     155            get 
     156            { 
     157                return cat; 
    182158            } 
    183159            set { cat = value; }