anchor.diff:  
       procedure GetVerticeTerKinds(const aLoc: TKMPoint; out aVerticeTerKinds: TKMTerrainKindCorners);
   
  -    function TileHasRoad(const Loc: TKMPoint): Boolean; overload; inline;
  +    function TileHasRoad(const aLoc: TKMPoint): Boolean; overload; inline;
       function TileHasRoad(X,Y: Integer): Boolean; overload; inline;
   
       function UnitsHitTest(X, Y: Word): Pointer;
       function UnitsHitTestF(const aLoc: TKMPointF): Pointer;
  -    function UnitsHitTestWithinRad(const aLoc: TKMPoint; MinRad, MaxRad: Single; aPlayer: TKMHandID; aAlliance: TKMAllianceType;
  -                                   Dir: TKMDirection; const aClosest: Boolean): Pointer;
  +    function UnitsHitTestWithinRad(const aLoc: TKMPoint; aMinRad, aMaxRad: Single; aPlayer: TKMHandID; aAlliance: TKMAllianceType;
  +                                   aDir: TKMDirection; const aClosest: Boolean): Pointer;
   
       function ScriptTrySetTile(X, Y, aType, aRot: Integer): Boolean;
       function ScriptTrySetTileHeight(X, Y, aHeight: Integer): Boolean;
       function ScriptTrySetTileObject(X, Y, aObject: Integer): Boolean;
       function ScriptTrySetTilesArray(var aTiles: array of TKMTerrainTileBrief; aRevertOnFail: Boolean; var aErrors: TKMTerrainTileChangeErrorArray): Boolean;
   
  -    function ObjectIsCorn(const Loc: TKMPoint): Boolean; overload; inline;
  +    function ObjectIsCorn(const aLoc: TKMPoint): Boolean; overload; inline;
       function ObjectIsCorn(X,Y: Word): Boolean; overload; inline;
   
  -    function ObjectIsWine(const Loc: TKMPoint): Boolean; overload; inline;
  +    function ObjectIsWine(const aLoc: TKMPoint): Boolean; overload; inline;
       function ObjectIsWine(X,Y: Word): Boolean; overload; inline;
   
       function ObjectIsChopableTree(X,Y: Word): Boolean; overload; inline;
  -    function ObjectIsChopableTree(const Loc: TKMPoint; aStage: TKMChopableAge): Boolean; overload; inline;
  -    function ObjectIsChopableTree(const Loc: TKMPoint; aStages: TKMChopableAgeSet): Boolean; overload; inline;
  -    function CanWalkDiagonaly(const aFrom: TKMPoint; bX, bY: SmallInt): Boolean;
  -
  -    function GetFieldStage(const Loc: TKMPoint): Byte;
  -    function GetCornStage(const Loc: TKMPoint): Byte;
  -    function GetWineStage(const Loc: TKMPoint): Byte;
  +    function ObjectIsChopableTree(const aLoc: TKMPoint; aStage: TKMChopableAge): Boolean; overload; inline;
  +    function ObjectIsChopableTree(const aLoc: TKMPoint; aStages: TKMChopableAgeSet): Boolean; overload; inline;
  +    function CanWalkDiagonaly(const aFrom: TKMPoint; aX, aY: SmallInt): Boolean;
  +
  +    function GetFieldStage(const aLoc: TKMPoint): Byte;
  +    function GetCornStage(const aLoc: TKMPoint): Byte;
  +    function GetWineStage(const aLoc: TKMPoint): Byte;
   
       function TopHill: Byte;
       procedure FlattenTerrain(const Loc: TKMPoint; aUpdateWalkConnects: Boolean = True; aIgnoreCanElevate: Boolean = False); overload;
       procedure FlattenTerrain(LocList: TKMPointList); overload;
   
  -    function ConvertCursorToMapCoord(inX,inY:single): Single;
  +    function ConvertCursorToMapCoord(inX, inY:single): Single;
       function FlatToHeight(inX, inY: Single): Single; overload;
       function FlatToHeight(const aPoint: TKMPointF): TKMPointF; overload;
       function RenderFlatToHeight(inX, inY: Single): Single; overload;
  
positive.code: end;
  
  
  function TKMTerrain.CatchFish(aLoc: TKMPointDir; TestOnly: Boolean = False): Boolean;
  var
    myFish: TKMUnitAnimal;
  begin
    //Here we are catching fish in the tile 1 in the direction
    aLoc.Loc := KMGetPointInDir(aLoc.Loc, aLoc.Dir);
    myFish := gHands.PlayerAnimals.GetFishInWaterBody(Land^[aLoc.Loc.Y, aLoc.Loc.X].WalkConnect[wcFish], not TestOnly);
    Result := (myFish <> nil);
    if (not TestOnly) and (myFish <> nil) then myFish.ReduceFish; //This will reduce the count or kill it (if they're all gone)
  end;
  
  
  procedure TKMTerrain.SetObject(const Loc: TKMPoint; ID: Integer);
  var
    isObjectSet: Boolean;
  begin
    isObjectSet := False;
    case ID of
      // Special cases for corn fields 
      58: if TileIsCornField(Loc) and (GetCornStage(Loc) <> 4) then
          begin
            SetField(Loc, Land^[Loc.Y,Loc.X].TileOwner, ftCorn, 4, False);
            isObjectSet := True;
          end;
      59: if TileIsCornField(Loc) and (GetCornStage(Loc) <> 4) then
          begin
            SetField(Loc, Land^[Loc.Y,Loc.X].TileOwner, ftCorn, 5, False);
            isObjectSet := True;
          end
    end;
  
    if not isObjectSet then
    begin
      Land^[Loc.Y,Loc.X].Obj := ID;
      Land^[Loc.Y,Loc.X].TreeAge := 1;
  
      //Add 1 tile on sides because surrounding tiles will be affected (CanPlantTrees)
      UpdatePassability(KMRectGrow(KMRect(Loc), 1));
  
      //Tree could have blocked the only diagonal passage
      UpdateWalkConnect([wcWalk, wcRoad, wcWork], KMRectGrowTopLeft(KMRect(Loc)), True); //Trees block diagonal
    end;
  end;
  
  
  // Set Tile Overlay
  //todo: Do not update walkConnect and passability multiple times here
  procedure TKMTerrain.SetOverlay(const Loc: TKMPoint; aOverlay: TKMTileOverlay; aOverwrite: Boolean);
  var
    changed: Boolean;
  begin
    if not TileInMapCoords(Loc.X, Loc.Y) then Exit;
  
    if aOverlay = toRoad then
    begin
      SetRoad(Loc, HAND_NONE);
      Exit;
    end;
  
  
negative.code: 
    //Walkable way between A and B is proved by FloodFill
    testRadius := False;
    for I := Max(Round(aLocB.Y - aDistance), 1) to Min(Round(aLocB.Y + aDistance), fMapY-1) do
      for K := Max(Round(aLocB.X - aDistance), 1) to Min(Round(aLocB.X + aDistance), fMapX-1) do
        if KMLengthSqr(aLocB,KMPoint(K, I)) <= distanceSqr then
          testRadius := testRadius or (Land[aLocA.Y,aLocA.X].WalkConnect[WC] = Land^[i,k].WalkConnect[WC]);
  
    Result := Result and testRadius;
  end;
  
  
  //Check if a route can be made to this vertex, from any direction (used for woodcutter cutting trees)
  function TKMTerrain.Route_CanBeMadeToVertex(const aLocA, aLocB: TKMPoint; aPass: TKMTerrainPassability): Boolean;
  var
    I, K: Integer;
  begin
    Result := false;
    //Check from top-left of vertex to vertex tile itself
    for I := Max(aLocB.Y - 1, 1) to aLocB.Y do
      for K := Max(aLocB.X - 1, 1) to aLocB.X do
        Result := Result or Route_CanBeMade(aLocA, KMPoint(K, I), aPass, 0);
  end;
  
  
  //Returns the closest tile to TargetLoc with aPass and walk connect to OriginLoc
  //If no tile found - return Origin location
  function TKMTerrain.GetClosestTile(const aTargetLoc, aOriginLoc: TKMPoint; aPass: TKMTerrainPassability; aAcceptTargetLoc: Boolean): TKMPoint;
  const
    testDepth = 255;
  var
  