{$mode objfpc}{$H+}
unit uGroupTypes;

// CC 20260313 shared group tracking record and pure helper functions

interface

uses
  Graphics,
  uHCTypeDefs, uHCDefines,
  uGroupSnapshot;

type
  PGroupMapEntry = ^TGroupMapEntry;
  TGroupMapEntry = record
    UUID: string;
    IconPresenterID: Integer;
    IconObjectID: Integer;
    ArrowPresenterID: Integer;  // -1 if no arrow
    ArrowObjectID: Integer;     // -1 if no arrow
    RangePresenterIDs: array[0..5] of Integer;  // -1 if ring not shown; indices per RING_* constants
    RangeObjectIDs: array[0..5] of Integer;     // -1 if ring not shown; indices per RING_* constants
    TrackLinePresenterID: Integer;  // -1 if no track
    TrackLineObjectID:    Integer;
    TrackDotPresenterID:  Integer;  // -1 if no waypoint dots
    TrackDotObjectID:     Integer;
    Visited: Boolean;             // mark flag for sweep phase
    DispSide: uchar;              // CC 20260322 cached display side for current tick
    UncertPresenterID: Integer;   // CC 20260322 -1 if no uncertainty diamond
    UncertObjectID:    Integer;   // CC 20260322 -1 if no uncertainty diamond
    ActualSide: uchar;            // CC 20260323 real side for own-side checks
    GType: HCMT;                  // CC 20260924 group marker type, for the Edit Formation menu rule
    HasTrack: Boolean;            // CC 20260323 whether group had waypoints in last snapshot
    GroupSLon, GroupSLat: LongInt; // CC 20260323 group position in slivers for track chain building
    SnapTrackNodes: array of TTrackNodeSnapshot; // CC 20260323 cached track nodes for drag preview
    // CC 20260921 -1 if zone ring not shown; indices per HC MainBodyZone..PicketRing3Zone
    // CC 20260924 all 64 HC zone slots (decision 7: extended rings)
    ZonePresenterIDs: array[0..MAX_FORMATION_ZONES-1] of Integer;
    ZoneObjectIDs:    array[0..MAX_FORMATION_ZONES-1] of Integer;
    SectorPresenterID: Integer;  // CC 20260924 -1 when formation sector spokes not shown
    SectorObjectID:    Integer;
    // CC 20260924 -1 if zone range label not shown; same indices as ZonePresenterIDs
    ZoneLabelPresenterIDs: array[0..MAX_FORMATION_ZONES-1] of Integer;
    ZoneLabelObjectIDs:    array[0..MAX_FORMATION_ZONES-1] of Integer;
    JamPresenterID: Integer;  // CC 20260921 -1 when the group is not jammed
    JamObjectID:    Integer;
  end;

function SideColor(const ASide: uchar): TColor;
function HCGroupShowing(const pPSide: uchar; const pGroup: PHCGroup): uchar;
function DisplaySide(const pShowing: uchar; const pActualSide: uchar): uchar; // CC 20260322

implementation

function SideColor(const ASide: uchar): TColor;
begin
  case ASide of
    BLUESIDE:    Result := clBlue;
    REDSIDE:     Result := clRed;
    GREENSIDE:   Result := clGreen;
    UNKNOWNSIDE: Result := clYellow;
  else
    Result := clWhite;
  end;
end;

function HCGroupShowing(const pPSide: uchar; const pGroup: PHCGroup): uchar;
begin
  result := NotShowing;
  if pGroup^.side = pPSide then
  begin
    result := ShowExact or SideKnown; // CC 20260322 own-side always knows side
  end
  else
  begin
    result := pGroup^.showing;
  end;
end;

// CC 20260322 return actual side if SideKnown is set, otherwise UNKNOWNSIDE
function DisplaySide(const pShowing: uchar; const pActualSide: uchar): uchar;
begin
  if (pShowing and SideKnown) <> 0 then
    Result := pActualSide
  else
    Result := UNKNOWNSIDE;
end;

end.
