anchor.diff:    // If we cannot walk there choose first group instead
     if not gTerrain.CheckPassability(Output, tpWalk) then
       for G := Low(TGroupType) to High(TGroupType) do
  -      if fSquads[G].Count > 0 then
  +      if (fSquads[G].Count > 0) then
         begin
           Squad := fSquads[G][0];
           Output := Squad.Group.Position;
           break;
         end;
  +  if not gTerrain.TileInMapCoords(Output.X, Output.Y) then
  +    POM(Output);
     Result := Output;
   end;
  +
  +
  +function TAICompany.ActualizeTarget(aInitPosition: TKMPoint; var aTargetHouse: TKMHouse; var aTargetUnit: TKMUnit; aAimCivilians: Boolean = True): Boolean;
  +var
  +  TargetGroup: TKMUnitGroup;
  +begin
  +  Result := False;
  +  aTargetHouse := gHands.GetClosestHouse(aInitPosition, fOwner, at_Enemy, TARGET_HOUSES, false);
  +  if (aTargetHouse = nil) then
  +  begin
  +    TargetGroup := gHands.GetClosestGroup(aInitPosition, fOwner, at_Enemy);
  +    if (TargetGroup = nil) then
  +    begin
  +      if not aAimCivilians then
  +        Exit;
  +      aTargetUnit := gHands.GetClosestUnit(aInitPosition, fOwner, at_Enemy);
  +      if (aTargetUnit = nil) then
  +        Exit;
  +    end
  +    else
  +      aTargetUnit := TargetGroup.GetAliveMember;
  +  end;
  +  Result := True;
  +end;
  +
  +
  +{
  +function TAICompany.FindPath(aStart,aEnd: TKMPoint; aPolygonPath: TKMWordArray; aPointPath: TKMPointArray): Boolean;
  +begin
  +  Result := fPathfinding.Route_Make(aStart, aEnd, aPolygonPath, aPointPath);
  +end;
  +}
  +
  +function TAICompany.IsGroupInCompany(aGroup: TKMUnitGroup): Boolean;
  +var
  +  I: Integer;
  +  G: TGroupType;
  +  Squad: TAISquad;
  +begin
  +  Result := True;
  +  for G := Low(TGroupType) to High(TGroupType) do
  +    for I := 0 to fSquads[G].Count-1 do
  +    begin
  +      Squad := fSquads[G][I];
  +      if (Squad.Group = aGroup) then
  +        Exit;
  +    end;
  +  Result := False;
  +end;
  +
  +
  +
  +
   
   
   
  
positive.code: begin
    inherited Create;
    fGroup := aGroup.GetGroupPointer();
  end;
  
  
  destructor TAISquad.Destroy();
  begin
    fGroup.ReleaseGroupPointer();
    inherited;
  end;
  
  
  procedure TAISquad.Save(SaveStream: TKMemoryStream);
  begin
    //SaveStream.Write(fOwner);
  end;
  
  
  procedure TAISquad.Load(LoadStream: TKMemoryStream);
  begin
    //LoadStream.Read(fOwner);
  end;
  
  
  
negative.code:   COLOR_RED = $800000FF;
    COLOR_YELLOW = $8000FFFF;
    COLOR_GREEN_Field = $4400FF00;
    COLOR_GREEN_1 = $3355FFFF;
    COLOR_BLUE = $60FF0000;
  var
    I,K,J: Integer;
    Position: TKMPoint;
    GT: TGroupType;
    Company: TAICompany;
    Squad: TAISquad;
  begin
    if (fOwner <> gMySpectator.HandIndex) then // Show just 1 player (it prevents notification to be mess)
      Exit;
    for I := 0 to Count - 1 do
    begin
      Company := fCompanies.Items[I];
      Position := Company.Position;
      gRenderAux.CircleOnTerrain(Position.X, Position.Y, COMPANY_SCAN_RAD, $09FFFFFF, $99FFFFFF);
      if (Length(Company.PointPath) > 0) then
        for K := Length(Company.PointPath)-2 downto 0 do
          gRenderAux.LineOnTerrain(Company.PointPath[K+1], Company.PointPath[K], COLOR_RED);
      for GT := Low(TGroupType) to High(TGroupType) do
        for K := Company.Squads[GT].Count - 1 downto 0 do
        begin
          Squad := Company.Squads[GT].Items[K];
          Position := Squad.Position;
          gRenderAux.CircleOnTerrain(Position.X, Position.Y, 1, $0500FF00, $6600FF00);
          if (Squad.TargetHouse <> nil) then
            gRenderAux.LineOnTerrain(Position, Squad.TargetHouse.GetPosition, $AA6666FF)
          else if (Squad.TargetUnit <> nil) then
            gRenderAux.LineOnTerrain(Position, Squad.TargetUnit.GetPosition, $AA6666FF)
          else if not KMSamePoint(Squad.FinalPosition.Loc,KMPOINT_ZERO) then
          begin
            //gRenderAux.LineOnTerrain(Position, Squad.FinalPosition.Loc, $AAFF5555);
            gRenderAux.CircleOnTerrain(Squad.FinalPosition.Loc.X, Squad.FinalPosition.Loc.Y, 1, $05FF0000, $66FF0000);
            if (Length(Squad.PointPath) > 0) then
              for J := Length(Squad.PointPath)-2 downto 0 do
                gRenderAux.LineOnTerrain(Squad.PointPath[J+1], Squad.PointPath[J], COLOR_BLUE);
          end;
        end;
    end;
    //gRenderAux.LineOnTerrain(P1, P2, $CCFF2222);
    //gRenderAux.CircleOnTerrain(CenterPlatoon.X, CenterPlatoon.Y, 5, $09FFFFFF, $99FFFFFF);
    //gRenderAux.Quad(Loc.X, Loc.Y, Color);
  