anchor.diff:          begin
             Active := True;
             RemoveTreesMode := True;
  +          ShortcutMode := False;
             MaxReqWorkers := 5;
             RequiredWorkers := Min(MaxReqWorkers, FieldList.Count); // Real count will be updated during building process
             CenterPoint := Loc;
  -          ResponsibleHouseIdx := HouseIdx;
  -          ResponsibleHouseType := aHT;
           end;
           LockHouseLoc(aHT, Loc);
  -      end
  +      end;
         // There is another problem...
  -      else
  -      begin
  -        //RemovePlan(aHT, Loc);
  -        // Remove house plan from city planner
  -      end;
  -    end;
  +      //else
  +      //  Planner.RemovePlan(aHT, Loc);
  +    end;
  +    //else
  +    //  Planner.RemovePlan(aHT, Loc);
     end
     else
     begin
       // new house cannot be added
     end;
     Result := Output
  -end;
  -
  -
  -function TKMCityBuilder.BuildHouse_GA_MODE(aHT: THouseType): Boolean;
  -var
  -  FieldType: TFieldType;
  -  FieldList: TKMPointList;
  -
  -  procedure AddField();
  -  var
  -    I: Integer;
  -  begin
  -    for I := FieldList.Count - 1 downto 0 do
  -      case FieldType of
  -        ft_Road:
  -          begin
  -            gTerrain.SetRoad(FieldList.Items[I], fOwner);
  -            gTerrain.FlattenTerrain(FieldList.Items[I]);
  -            if gMapElements[  gTerrain.Land[ FieldList.Items[I].Y,FieldList.Items[I].X ].Obj  ].WineOrCorn then
  -              gTerrain.RemoveObject(FieldList.Items[I]);
  -          end;
  -        ft_Corn,ft_Wine:
  -        begin
  -          gTerrain.SetField(FieldList.Items[I], fOwner, FieldType);
  -          gAIFields.Influences.AvoidBuilding[FieldList.Items[I].Y, FieldList.Items[I].X] := AVOID_BUILDING_NODE_LOCK_FIELD;
  -        end;
  -      end;
  -  end;
  -
  -var
  -  Output: Boolean;
  -  HouseIdx: Integer;
  -  Loc: TKMPoint;
  -  HPlan: TKMHousePlan;
  -begin
  -  Output := False;
  -  FieldList := TKMPointList.Create;
  -  try
  -    if fPlanner.GetHousePlan(False, aHT, Loc, HouseIdx) then
  -    begin
  -      Output := True;
  -      gHands[fOwner].AddHousePlan(aHT, Loc); // Place house plan
  -      if fPlanner.GetRoadToHouse(aHT, HouseIdx, FieldList, FieldType) then // Place roads
  -        AddField();
  -      if fPlanner.GetFieldToHouse(aHT, HouseIdx, FieldList, FieldType) then // Place fields
  -        AddField();
  -      if gHands[fOwner].BuildList.HousePlanList.TryGetPlan(Loc, HPlan) then // Remove house plan (it must be done because of road planning)
  -      begin
  -        gHands[fOwner].BuildList.HousePlanList.RemPlan(Loc);
  -        gHands[fOwner].Stats.HousePlanRemoved(aHT);
  -      end;
  -      gHands[fOwner].AddHouse(aHT, Loc.X, Loc.Y, True); // Place house
  -    end;
  -  finally
  -    FieldList.Free;
  -  end;
  -  //fPlanner.UpdateState(0);// DELETE (ADD SOMEWHERE ELSE)
  -  Result := Output;
  -end;
  -
  -
  -procedure TKMCityBuilder.LockHouseLoc(aHT: THouseType; aLoc: TKMPoint);
  -var
  -  I,Dist: Integer;
  -  Point: TKMPoint;
  -  Dir: TDirection;
  -  HMA: THouseMappingArray;
  -begin
  -  HMA := gAIFields.Eye.HousesMapping;
  -  // Reserve all tiles inside house plan
  -  for I := Low(HMA[aHT].Tiles) to High(HMA[aHT].Tiles) do
  -    gAIFields.Influences.AvoidBuilding[aLoc.Y + HMA[aHT].Tiles[I].Y, aLoc.X + HMA[aHT].Tiles[I].X] := AVOID_BUILDING_HOUSE_INSIDE_LOCK;
  -  // Reserve all tiles in distance 1 from house plan
  -  Dist := 1;
  -  for Dir := Low(HMA[aHT].Surroundings[Dist]) to High(HMA[aHT].Surroundings[Dist]) do
  -    for I := Low(HMA[aHT].Surroundings[Dist,Dir]) to High(HMA[aHT].Surroundings[Dist,Dir]) do
  -    begin
  -      Point := KMPointAdd(aLoc, HMA[aHT].Surroundings[Dist,Dir,I]);
  -      if (gAIFields.Influences.AvoidBuilding[Point.Y, Point.X] < AVOID_BUILDING_HOUSE_INSIDE_LOCK) then
  -        gAIFields.Influences.AvoidBuilding[Point.Y, Point.X] := AVOID_BUILDING_HOUSE_OUTSIDE_LOCK;
  -    end;
  -end;
  -
  -
  -procedure TKMCityBuilder.UnlockHouseLoc(aHT: THouseType; aLoc: TKMPoint);
  -var
  -  I,Dist: Integer;
  -  Point: TKMPoint;
  -  Dir: TDirection;
  -  HMA: THouseMappingArray;
  -begin
  -  HMA := gAIFields.Eye.HousesMapping;
  -  // Free all tiles inside house plan
  -  for I := Low(HMA[aHT].Tiles) to High(HMA[aHT].Tiles) do
  -    gAIFields.Influences.AvoidBuilding[aLoc.Y + HMA[aHT].Tiles[I].Y, aLoc.X + HMA[aHT].Tiles[I].X] := AVOID_BUILDING_UNLOCK;
  -  // Free all tiles in distance 1 from house plan
  -  Dist := 1;
  -  for Dir := Low(HMA[aHT].Surroundings[Dist]) to High(HMA[aHT].Surroundings[Dist]) do
  -    for I := Low(HMA[aHT].Surroundings[Dist,Dir]) to High(HMA[aHT].Surroundings[Dist,Dir]) do
  -    begin
  -      Point := KMPointAdd(aLoc, HMA[aHT].Surroundings[Dist,Dir,I]);
  -      if (gAIFields.Influences.AvoidBuilding[Point.Y, Point.X] = AVOID_BUILDING_HOUSE_OUTSIDE_LOCK) then
  -        gAIFields.Influences.AvoidBuilding[Point.Y, Point.X] := AVOID_BUILDING_UNLOCK;
  -    end;
  -end;
  -
  -
  -procedure TKMCityBuilder.LockNode(var aNode: TBuildNode);
  -var
  -  NODE_TYPE: Byte;
  -  I: Integer;
  -begin
  -  case aNode.FieldType of
  -    ft_Road: NODE_TYPE := AVOID_BUILDING_NODE_LOCK_ROAD;
  -    else     NODE_TYPE := AVOID_BUILDING_NODE_LOCK_FIELD;
  -  end;
  -  with aNode.FieldList do
  -    for I := 0 to Count-1 do
  -      if (gAIFields.Influences.AvoidBuilding[Items[I].Y, Items[I].X] < NODE_TYPE) then
  -        gAIFields.Influences.AvoidBuilding[Items[I].Y, Items[I].X] := NODE_TYPE;
  -end;
  -
  -
  -procedure TKMCityBuilder.UnlockPointOfNode(aPoint: TKMPoint);
  -begin
  -  if (gAIFields.Influences.AvoidBuilding[aPoint.Y, aPoint.X] = AVOID_BUILDING_NODE_LOCK_ROAD) then // Only roads are unlocked
  -    gAIFields.Influences.AvoidBuilding[aPoint.Y, aPoint.X] := AVOID_BUILDING_UNLOCK;
   end;
   
   
  
positive.code: 
    aRequiredHouses[ht_CoalMine] := POMCoal;
    if not Output then
      Output := SelectHouse(FOOD_WARE) OR SelectHouse(WEAPON_WARE);
  
    Result := Output;
    //}
  end;
  
  
  // Old test version
  procedure TKMCityBuilder.ChooseHousesToBuildPOM(aMaxCnt: Integer; var aRequiredHouses: TRequiredHousesArray; aWareBalance: TWareBalanceArray);
    function GetHouseToUnlock(var aUnlockProcedure: Boolean; var aHT: THouseType): Boolean;
    var
      Output: Boolean;
      POM_HT: THouseType;
    begin
      Output := True;
      aUnlockProcedure := False;
      // Repeat until is avaiable house finded (to unlock target house)
      POM_HT := aHT;
      while Output AND not gHands[fOwner].Locks.HouseCanBuild(aHT) do
      begin
        aUnlockProcedure := True;
        if gHands[fOwner].Locks.HouseBlocked[aHT] then // House is blocked -> unlock impossible
          Output := False
        else
          aHT := gRes.Houses[aHT].ReleasedBy; // House have to be unlocked by this house
      end;
      // Output = false only in case that house is already under construction OR is blocked by script / settings from the map editor
      Result := Output AND ( (POM_HT = aHT) OR (gHands[fOwner].Stats.GetHouseTotal(aHT) = 0));
    end;
    //gHands[fOwner].Locks.HouseCanBuild(aHouse)
    //gHands[fOwner].Locks.HouseBlocked[ht_Quary]
    function AddToConstruction(aHT: THouseType): Boolean;
    var
      UnlockProcedure: Boolean;
    begin
      // Check if AI can build house (if is house blocked [by script] ignore it)
      if GetHouseToUnlock(UnlockProcedure, aHT) then
      begin
        BuildHouse(UnlockProcedure, false, aHT);
        //BuildHouse_DEBUG_MODE(aHT);
        aRequiredHouses[aHT] := aRequiredHouses[aHT] - 1;
        aMaxCnt := aMaxCnt - 1;
      end;
      aRequiredHouses[aHT] := 0; // Make sure that next node will not scan this house in this tick
      Result := (aMaxCnt > 0);
    end;
  
  var
    I: Integer;
    BestDerivation: Single;
    WT, BestWT: TWareType;
  const
    BASIC_HOUSES: array[0..4] of THouseType = (ht_School, ht_Barracks, ht_Inn, ht_Store, ht_MarketPlace);
    BASIC_WARE: array[0..5] of TWareType = (wt_Gold, wt_GoldOre, wt_Coal, wt_Stone, wt_Trunk, wt_Wood); //,
    //IRON_WEAPONS: array[..] of TWareType = ();
    //FOOD:
    //WEAPONS
    {
      wt_Trunk,          wt_Stone,         wt_Wood,           wt_IronOre,      wt_GoldOre,
      wt_Coal,           wt_Steel,         wt_Gold,           wt_Wine,         wt_Corn,
      wt_Bread,          wt_Flour,         wt_Leather,        wt_Sausages,     wt_Pig,
      wt_Skin,
    }
  begin
    for I := Low(BASIC_HOUSES) to High(BASIC_HOUSES) do
      if (aRequiredHouses[ BASIC_HOUSES[I] ] > 0) then
      begin
        AddToConstruction(BASIC_HOUSES[I]);
        if aMaxCnt <= 0 then
          Exit;
      end;
  
    BestDerivation := 0;
    for I := Low(BASIC_WARE) to High(BASIC_WARE) do
      if (aRequiredHouses[  PRODUCTION[ BASIC_WARE[I] ]  ] > 0) then
      begin
        AddToConstruction(PRODUCTION[ BASIC_WARE[I] ]);
        {
        if (BASIC_WARE[I] = wt_Gold) AND (aWareBalance[wt_GoldOre].Derivation > aWareBalance[wt_Coal].Derivation) then
        begin
          aRequiredHouses[ht_CoalMine] := Max(0, gHands[fOwner].Stats.GetHouseTotal(ht_GoldMine) - gHands[fOwner].Stats.GetHouseTotal(ht_CoalMine));
          if (aRequiredHouses[ht_CoalMine] > 0) then
            AddToConstruction(ht_CoalMine);
        end;
        //}
        if aMaxCnt <= 0 then
          Exit;
      end;
    {
        if (aWareBalance[BASIC_WARE[I]].Derivation < BestDerivation) then
        begin
          BestWT := BASIC_WARE[I];
          BestDerivation := aWareBalance[BASIC_WARE[I]].Derivation;
        end;
    if (BestDerivation < 0) then
      if not AddToConstruction(PRODUCTION[BestWT]) then
        Exit;
    //}
    {
    while (aMaxCnt > 0) do
    begin
      BestDerivation := 0;
      for WT := Low(aWareBalance) to High(aWareBalance) do
      begin
        if WT in [wt_Shield,  wt_MetalShield, wt_Armor,     wt_MetalArmor,
                  wt_Axe,     wt_Sword,   wt_Pike,        wt_Hallebard, wt_Bow,
                  wt_Arbalet, wt_Horse,   wt_Fish] then
          continue;
        if (aWareBalance[WT].Derivation < BestDerivation) then
        begin
          BestWT := WT;
          BestDerivation := aWareBalance[WT].Derivation;
        end;
      end;
      if (BestDerivation < 0) then
      begin
        aWareBalance[BestWT].Derivation := 0;
        if not AddToConstruction(PRODUCTION[BestWT]) then
          Exit;
      end
      else
        break;
    end;
    //}
  end;
  
  
  
negative.code: //    6,7: receive wood, build wine
  //    8: wine is finished
  var
    I, ClosestIdx, ClosestDist, Dist: Integer;
    WorkersPos: TKMPointArray;
  begin
    // Reset count of free workers in each node
  