anchor.diff:  interface
   uses
     Classes, KromUtils, Math, SysUtils,
  +  KM_CommonClasses, KM_Defaults, KM_Points,
     KM_Units, KM_UnitGroups, KM_AISetup,
  -  KM_CommonClasses, KM_Defaults, KM_Points,
  -  KM_ArmyAttack;
  +  KM_HandStats, KM_ArmyAttack, KM_ArmyDefence,
  +  KM_NavMeshFloodPositioning;
   
   type
     TKMArmyManagement = class
     private
       fOwner: TKMHandIndex;
  +    fSetup: TKMHandAISetup;
       fLastEquippedTimeIron, fLastEquippedTimeLeather: Cardinal;
   
  -    fSetup: TKMHandAISetup;
  -
       fAttack: TKMArmyAttack;
  -
  -    //fDefencePositions: TAIDefencePositions;
  +    fDefence: TKMArmyDefence;
   
       fBalanceText: UnicodeString;
  -    {
  -    procedure CheckArmy;
  -    procedure CheckArmyCount;
  -    procedure CheckAttacks;
  -    procedure CheckAutoAttack;
  -    procedure CheckAutoDefend;
  -    }
  -    //procedure OrderAttack(aGroup: TKMUnitGroup; aTarget: TAIAttackTarget; aCustomPos: TKMPoint);
  +
  +    procedure RecruitSoldiers();
  +    procedure CheckGroupsState();
  +    procedure CheckAttack();
     public
       constructor Create(aPlayer: TKMHandIndex; aSetup: TKMHandAISetup);
       destructor Destroy; override;
  -
  -    procedure AfterMissionInit();
  -    procedure OwnerUpdate(aPlayer: TKMHandIndex);
  -    property Attack: TKMArmyAttack read fAttack write fAttack;
  -    //property DefencePositions: TAIDefencePositions read fDefencePositions;
  -    //procedure RetaliateAgainstThreat(aAttacker: TKMUnit);
  -    //procedure WarriorEquipped(aGroup: TKMUnitGroup);
  -
  -    procedure UpdateState(aTick: Cardinal);
       procedure Save(SaveStream: TKMemoryStream);
       procedure Load(LoadStream: TKMemoryStream);
       procedure SyncLoad();
  +
  +    property Attack: TKMArmyAttack read fAttack write fAttack;
  +    property Defence: TKMArmyDefence read fDefence write fDefence;
  +
  +    procedure AfterMissionInit();
  +    procedure UpdateState(aTick: Cardinal);
  +    procedure OwnerUpdate(aPlayer: TKMHandIndex);
  +    procedure WarriorEquipped(aGroup: TKMUnitGroup);
  +    //function GetArmyDemand(): ...;
  +    //procedure RetaliateAgainstThreat(aAttacker: TKMUnit);
   
       procedure LogStatus(var aBalanceText: UnicodeString);
       procedure Paint();
  
positive.code: 
  
  procedure TKMArmyManagement.Paint();
  const
    COLOR_WHITE = $80FFFFFF;
    COLOR_BLACK = $80000000;
    COLOR_GREEN = $6000FF00;
    COLOR_RED = $800000FF;
    COLOR_YELLOW = $8000FFFF;
    COLOR_GREEN_Field = $4400FF00;
    COLOR_GREEN_Wine = $3355FFFF;
    COLOR_BLUE = $60FF0000;
  begin
    gRenderAux.LineOnTerrain(KMPoint(2,2), KMPoint(4,4), $CCFF2222);
    //gRenderAux.CircleOnTerrain(CenterPlatoon.X, CenterPlatoon.Y, 5, $09FFFFFF, $99FFFFFF);
    //gRenderAux.Quad(Loc.X, Loc.Y, Color);
  end;
  
  
  
negative.code: 
  
  procedure TKMArmyManagement.UpdateState(aTick: Cardinal);
  const
    PERF_TIME_LIMIT = MAX_HANDS * 10;
    PERF_TIME_LIMIT_2 = MAX_HANDS * 11;
  begin
    if (aTick mod MAX_HANDS = fOwner) then
    begin
      if (aTick mod PERF_TIME_LIMIT = fOwner) then
        fDefence.UpdateDefences();
      if (aTick mod PERF_TIME_LIMIT_2 = fOwner) then
        CheckAttack();
      RecruitSoldiers();
      CheckGroupsState();
      fAttack.UpdateState(aTick);
      fDefence.UpdateState(aTick);
    end;
  end;
  
  