anchor.diff:    UpdateBasicHouses(GA_PLANNER);
     UpdateWareBalance();
   
  -  if (fCornDelay = 0) AND (gHands[fOwner].Stats.GetHouseTotal(ht_Farm) > 0) then // Dont use fCityStats because it consider planned houses
  -  begin
  -    fCornDelay := gGame.GameTickCount + 6000; // 10 ticks = 1 sec (farm requires 10 min to produce corn)
  -  end;
  -  // Corn delay (should not wait till is first corn produced because it have huge impact)
  -  if (gGame.GameTickCount < fCornDelay) AND not gHands[fOwner].Locks.HouseBlocked[ht_Farm] then // Consider corn delay (~10 minutes) -> time saved by construction
  +  // Consideration of corn delay - only remove all required houses, builder will find the right one if they are not removed
  +  if UpdateFarmHistory() AND not gHands[fOwner].Locks.HouseBlocked[ht_Farm] then
     begin
       RequiredHouses[ht_Mill] := 0;
  -    RequiredHouses[ht_Bakery] := 0;
       RequiredHouses[ht_Swine] := 0;
  -    RequiredHouses[ht_Tannery] := 0;
  -    RequiredHouses[ht_ArmorWorkshop] := 0;
  -  end;
  -  // Pig delay
  -  //RequiredHouses[ht_Butchers] := RequiredHouses[ht_Butchers] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Pig) > 0);
  -  RequiredHouses[ht_Butchers] := RequiredHouses[ht_Butchers] * Byte(gHands[fOwner].Stats.GetHouseQty(ht_Swine) > 0);
  -  //if (gHands[fOwner].Stats.GetWareBalance(wt_Skin) = 0) then
  -  //begin
  -  //  RequiredHouses[ht_Tannery] := 0;
  -  //  RequiredHouses[ht_ArmorWorkshop] := 0;
  -  //end;
  -
  -  if (gGame.GameTickCount < 22000) then
  +    RequiredHouses[ht_Stables] := 0;
  +  end;
  +  // Houses in dependence on corn delay
  +  RequiredHouses[ht_Bakery] := Min(RequiredHouses[ht_Bakery], Stats.GetHouseQty(ht_Mill) - fCityStats.Houses[ht_Bakery]);
  +  RequiredHouses[ht_Butchers] := Min(RequiredHouses[ht_Butchers], Ceil(Stats.GetHouseQty(ht_Swine)/3 - fCityStats.Houses[ht_Butchers]));
  +  RequiredHouses[ht_Tannery] := Min(RequiredHouses[ht_Tannery], Ceil(Stats.GetHouseQty(ht_Swine)/2 - fCityStats.Houses[ht_Tannery]));
  +  RequiredHouses[ht_ArmorWorkshop] := Min(RequiredHouses[ht_ArmorWorkshop], Stats.GetHouseTotal(ht_Tannery)*2 - fCityStats.Houses[ht_ArmorWorkshop]);
  +
  +  RequiredHouses[ht_WeaponWorkshop] := RequiredHouses[ht_WeaponWorkshop] * Byte( (RequiredHouses[ht_Tannery] > 0) OR (WEAP_WORKSHOP_DELAY < aTick) OR (aTick > (gGame.GameOptions.Peacetime-20) * 10 * 60) );
  +
  +  if (gGame.GameTickCount < WINEYARD_DELAY) then
       RequiredHouses[ht_Wineyard] := 0;
   
  -  RequiredHouses[ht_WeaponWorkshop] := RequiredHouses[ht_WeaponWorkshop] * Byte( (RequiredHouses[ht_Tannery] > 0) OR (WEAP_WORKSHOP_DELAY < aTick) OR (aTick > (gGame.GameOptions.Peacetime-20) * 10 * 60) );
   
     // Loghical house requirements (delay takes too long so it is not used)
     {
  -  RequiredHouses[ht_Swine] := RequiredHouses[ht_Swine] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Corn) > 0);
  -  RequiredHouses[ht_Butchers] := RequiredHouses[ht_Butchers] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Pig) > 0);
  -  RequiredHouses[ht_Tannery] := RequiredHouses[ht_Tannery] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Leather) > 0);
  -  RequiredHouses[ht_ArmorWorkshop] := RequiredHouses[ht_ArmorWorkshop] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Skin) > 0);
  -  RequiredHouses[ht_Mill] := RequiredHouses[ht_Mill] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Flour) > 0);
  -  RequiredHouses[ht_Bakery] := RequiredHouses[ht_Bakery] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Corn) > 0);
  +  RequiredHouses[ht_Swine] := RequiredHouses[ht_Swine] * Byte(Stats.GetWareBalance(wt_Corn) > 0);
  +  RequiredHouses[ht_Butchers] := RequiredHouses[ht_Butchers] * Byte(Stats.GetWareBalance(wt_Pig) > 0);
  +  RequiredHouses[ht_Tannery] := RequiredHouses[ht_Tannery] * Byte(Stats.GetWareBalance(wt_Leather) > 0);
  +  RequiredHouses[ht_ArmorWorkshop] := RequiredHouses[ht_ArmorWorkshop] * Byte(Stats.GetWareBalance(wt_Skin) > 0);
  +  RequiredHouses[ht_Mill] := RequiredHouses[ht_Mill] * Byte(Stats.GetWareBalance(wt_Flour) > 0);
  +  RequiredHouses[ht_Bakery] := RequiredHouses[ht_Bakery] * Byte(Stats.GetWareBalance(wt_Corn) > 0);
     //}
     // Iron production (it will give time to build more mines)
     {
  -  RequiredHouses[ht_IronSmithy] := RequiredHouses[ht_IronSmithy] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_IronOre) > 0);
  -  RequiredHouses[ht_WeaponSmithy] := RequiredHouses[ht_WeaponSmithy] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Steel) > 0);
  -  RequiredHouses[ht_ArmorSmithy] := RequiredHouses[ht_ArmorSmithy] * Byte(gHands[fOwner].Stats.GetWareBalance(wt_Steel) > 0);
  +  RequiredHouses[ht_IronSmithy] := RequiredHouses[ht_IronSmithy] * Byte(Stats.GetWareBalance(wt_IronOre) > 0);
  +  RequiredHouses[ht_WeaponSmithy] := RequiredHouses[ht_WeaponSmithy] * Byte(Stats.GetWareBalance(wt_Steel) > 0);
  +  RequiredHouses[ht_ArmorSmithy] := RequiredHouses[ht_ArmorSmithy] * Byte(Stats.GetWareBalance(wt_Steel) > 0);
     //}
   end;
   
  
positive.code:   TKMCityPredictor = class
    private
      fOwner: TKMHandIndex;
      fCornDelay: Cardinal;
      fMaxSoldiersInMin: Single;
      fCityStats: TCityStats;
      fWareBalance: TWareBalanceArray;
      fSetup: TKMHandAISetup;
  
      procedure UpdateWareProduction(aWT: TKMWareType);
  
negative.code: begin
    SaveStream.WriteA('CityPredictor');
    SaveStream.Write(fOwner);
    SaveStream.Write(fMaxSoldiersInMin);
    SaveStream.Write(fFarmBuildHistory.Count);
    if (fFarmBuildHistory.Count > 0) then
    begin
      SaveStream.Write(fFarmBuildHistory.Quantity[0], SizeOf(fFarmBuildHistory.Quantity[0]) * fFarmBuildHistory.Count);
      SaveStream.Write(fFarmBuildHistory.Tick[0], SizeOf(fFarmBuildHistory.Tick[0]) * fFarmBuildHistory.Count);
    end;
  
    // Requred houses should be saved because of public variable
    SaveStream.Write(RequiredHouses, SizeOf(TRequiredHousesArray));
  