anchor.diff:          begin
             MaxPlans := 0; // This house is critical so dont plan anything else
             Exit;
  -          //MaxPlans := MaxPlans - 1;
  -        end;
  -      end;
  -      //if (MaxPlans <= 0) then
  -      //  Break;
  +        end;
  +      end;
       end;
     end;
   
     procedure CheckHouseReservation();
  -  const // Reservation sets must be able to unlock specific houses!!!
  -    RESERVATION_StoneShortage: TSetOfHouseType = [htSchool, htStore, htQuary, htMarketplace];
  -    RESERVATION_WoodShortage: TSetOfHouseType = [htSchool, htMarketplace, htStore, htQuary, htWoodcutters, htSawmill];
  -    RESERVATION_TrunkShortage: TSetOfHouseType = [htSchool, htStore, htQuary, htGoldMine, htCoalMine, htMetallurgists, htWoodcutters];
  -    RESERVATION_GoldShortage: TSetOfHouseType = [htSchool, htMarketplace, htStore, htQuary, htGoldMine, htCoalMine, htMetallurgists, htWoodcutters, htSawmill];
  -    RESERVATION_FullSet: TSetOfHouseType = [htArmorSmithy, htArmorWorkshop, htBakery, htBarracks, htButchers, htCoalMine, htFarm, htFisherHut, htGoldMine, htInn, htIronMine, htIronSmithy, htMarketplace, htMetallurgists, htMill, htQuary, htSawmill, htSchool, htSiegeWorkshop, htStables, htStore, htSwine, htTannery, htTownHall, htWatchTower, htWeaponSmithy, htWeaponWorkshop, htWineyard, htWoodcutters];
  -  var
  -    I: Integer;
  +  const
  +    // Reservation sets must be able to unlock specific houses!!!
  +    RESERVATION_FullSet: array[0..28] of TKMHouseType = (
  +      htSchool, htQuary, htMarketplace, htWoodcutters, htSawmill,
  +      htGoldMine, htCoalMine, htMetallurgists, htBarracks, htInn,
  +      htFarm, htMill, htBakery, htSwine, htButchers, htStables, htFisherHut,
  +      htIronMine, htIronSmithy, htArmorSmithy, htWeaponSmithy,
  +      htTannery, htArmorWorkshop, htWeaponWorkshop,
  +      htSiegeWorkshop, htTownHall, htWineyard, htStore, htWatchTower
  +    );
  +    STONE_SHORTAGE_IDX = 2;
  +    TRUNK_SHORTAGE_IDX = 3;
  +    WOOD_SHORTAGE_IDX = 4;
  +    GOLD_SHORTAGE_IDX = 7;
  +    FULL_SET = 28;
  +  var
  +    I,K, MaxIdx: Integer;
       HT: TKMHouseType;
  -    ActualHouseSet: TSetOfHouseType;
     begin
       if fStoneShortage then
  -      ActualHouseSet := RESERVATION_StoneShortage
  +      MaxIdx := STONE_SHORTAGE_IDX
  +    else if fTrunkShortage then
  +      MaxIdx := TRUNK_SHORTAGE_IDX
  +    else if fWoodShortage then
  +      MaxIdx := WOOD_SHORTAGE_IDX
       else if fGoldShortage then
  -      ActualHouseSet := RESERVATION_GoldShortage
  -    else if fTrunkShortage then
  -      ActualHouseSet := RESERVATION_TrunkShortage
  -    else if fWoodShortage then
  -      ActualHouseSet := RESERVATION_WoodShortage
  +      MaxIdx := GOLD_SHORTAGE_IDX
       else
  -      ActualHouseSet := RESERVATION_FullSet;
  -    for HT in ActualHouseSet do
  -      for I := 0 to fPlanner.PlannedHouses[HT].Count - 1 do
  -        with fPlanner.PlannedHouses[HT].Plans[I] do
  +      MaxIdx := FULL_SET;
  +    for I := 0 to MaxIdx do
  +    begin
  +      HT := RESERVATION_FullSet[I];
  +      for K := 0 to fPlanner.PlannedHouses[HT].Count - 1 do
  +        with fPlanner.PlannedHouses[HT].Plans[K] do
             if not Placed
                AND (HouseReservation OR RemoveTreeInPlanProcedure)
                AND (cs_HousePlaced = AddToConstruction(HT,False,True)) then
             begin
  -            MaxPlans := MaxPlans - 1;
  +            MaxPlace := MaxPlace - 1;
               RequiredHouses[HT] := 0;
  +            if (MaxPlace <= 0) then
  +              Exit;
             end;
  +    end;
     end;
   
     function GetChopOnlyCnt(): Word;
  
positive.code: 
  
  var
    GA_BUILDER_BuildHouse_FieldMaxWork    : Single = 1;
    GA_BUILDER_BuildHouse_RTPMaxWork      : Single = 10;
    GA_BUILDER_BuildHouse_RoadMaxWork     : Single = 10.94186592;
    GA_BUILDER_CreateShortcuts_MaxWork    : Single = 10.81381607;
    //GA_BUILDER_ChHTB_FractionCoef         : Single = 20.06742477;
    GA_BUILDER_ChHTB_FractionCoef         : Single = 40;//11.58820248;
    //GA_BUILDER_ChHTB_TrunkFactor          : Single = 8.568861008;
    //GA_BUILDER_ChHTB_TrunkBalance         : Single = 5.72991991;
    GA_BUILDER_ChHTB_TrunkFactor          : Single = 5.920251846;
    GA_BUILDER_ChHTB_TrunkBalance         : Single = 3.946866512;
    GA_BUILDER_ChHTB_AllWorkerCoef        : Single = 9.645618439;
    GA_BUILDER_ChHTB_FreeWorkerCoef       : Single = 1;
    GA_BUILDER_TRUNK_SHORTAGE             : Single = 0;
    GA_BUILDER_STONE_SHORTAGE             : Single = 10.40034485;
    GA_BUILDER_WOOD_SHORTAGE              : Single = 10.05567646;
    GA_BUILDER_GOLD_SHORTAGE              : Single = 23.72795486;
  
  
  type
  
negative.code:   // Woodcutters have huge delay (8 min) + trunk is used only to produce wood -> decide shortage based on actual consumption and reserves
    TrunkBalance := (gHands[fOwner].Stats.GetWareBalance(wt_Trunk) + gHands[fOwner].Stats.GetWareBalance(wt_Wood) / 2) / Max(0.1,WareBalance[wt_Trunk].ActualConsumption);
    if (TrunkBalance < GA_BUILDER_TRUNK_SHORTAGE) then
    begin
      RequiredHouses[htWineyard] := 0; // Dont try to place wine
      fTrunkShortage := True;
    end;
  
    // Find place for chop-only woodcutters when we start to be out of wood
    if ((GA_BUILDER_ChHTB_TrunkBalance - TrunkBalance) / GA_BUILDER_ChHTB_TrunkFactor - GetChopOnlyCnt() > 0) then // Max 2 chop-only woodcutters
  