anchor.diff:    inherited Create;
     fOwner := aPlayer;
     fSetup := aSetup;
  +  with fFarmBuildHistory do
  +  begin
  +    Count := 1;
  +    SetLength(Quantity,1);
  +    SetLength(Tick,1);
  +    Quantity[0] := 0;
  +    Tick[0] := 10 * 60 * 10; // Init delay 10 min
  +  end;
   end;
   
   destructor TKMCityPredictor.Destroy();
  
positive.code: begin
    SaveStream.WriteA('CityPredictor');
    SaveStream.Write(fOwner);
    SaveStream.Write(fCornDelay);
    SaveStream.Write(fMaxSoldiersInMin);
  
    // Requred houses should be saved because of public variable
    SaveStream.Write(RequiredHouses, SizeOf(TRequiredHousesArray));
  
negative.code:   UpdateBasicHouses(GA_PLANNER);
    UpdateWareBalance();
  
    // 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_Swine] := 0;
      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;
  
  
    // Loghical house requirements (delay takes too long so it is not used)
    {
    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(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;
  
  