unit MainForm;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ComCtrls, Spin, ExtCtrls, uHCTypeDefs, uHCAnnexDefs, uHCAnnexHelpers, uActUnitReportGlobals;

type

  { TfrmMain }

  TfrmMain = class(TForm)
    lblAUMGroupId: TLabel;
    lblAUMHeading: TLabel;
    lblAUMAltitude: TLabel;
    lblAUMUnitId: TLabel;
    lblAUMName: TLabel;
    SGbtnRefresh: TButton;
    GlblDesc: TLabel;
    tshActUnitMain: TTabSheet;
    tshActGroupUnit: TTabSheet;
    AGckbEnabled: TCheckBox;
    AGedtLines: TSpinEdit;
    AGlblLines: TLabel;
    AGmemMsgLog: TMemo;
    SGlblDesc: TLabel;
    memDLLInit: TMemo;
    SGckbEnabled: TCheckBox;
    HHckbEnabled: TCheckBox;
    SGedtLines: TSpinEdit;
    HHedtLines: TSpinEdit;
    SGlblLines: TLabel;
    HHlblLines: TLabel;
    SGmemMsgLog: TMemo;
    HHmemMsgLog: TMemo;
    tshStartGroup: TTabSheet;
    tshDLLInit: TTabSheet;
    PageControl1: TPageControl;
    tshHH: TTabSheet;
  private
    { private declarations }
  public
    { public declarations }
    // ALE 20130812 Big bad pointers that hold most of the game data
    PStartGroup: PHCGroup;
    PHarpEventHead: PHCHarpoonEvent;
    PSonobuoyRegionHead: PHCSonobuoyRegion;
    PAllDeadUnitsPtr: PHCDeadListItem;
    PWeatherGroups: PHCGroup;
    PVictoryConditionsList: PHCVictoryConditions;
    // ALE 20130812 transient pointers
    PSelectedUnit: PHCUnit;
    // ALE 20130812 misc globals
    //blnInvestigatingStructs: Boolean;
    // ALE 20130908 pointers to functions exported by the GE
    HCdllCheckLatLonDepth: THCdllCheckLatLonDepth;

    procedure UpdateActUnitReport();
  end;

var
  frmMain: TfrmMain;

implementation

uses uHCDefines, uHCEventHelpers;

{$R *.lfm}

{ TfrmMain }

procedure TfrmMain.UpdateActUnitReport;
var
  PHarpEvent: PHCHarpoonEvent;
  cEventCourse: NativeInt;
  cEventAltitude: NativeInt;
begin
  //Byte(PDLLBusy^) := CTRUE; // ALE 20130816 don't process other events in GE

  if (PActUnit <> nil) then
  begin
    if (PHarpEventHead <> nil) then
    begin
      // ALE 20160408 Count up course events
      // ALE 20160408 Count up altitude events
      cEventCourse := 0;
      cEventAltitude := 0;
      PHarpEvent := PHarpEventHead;
      while (PHarpEvent <> nil) do
      begin
        if ((PHarpEvent^.flag AND CommandMask) = ALT_COURSE_EVENT) then
        begin
          if (PHCGroup(PHarpEvent^.ourGroup)^.id = PActUnit^.Group^.id) then
            Inc(cEventCourse);
        end;
        if ((PHarpEvent^.flag AND CommandMask) = ALT_SPEED_EVENT) then
        begin
          if (PHCGroup(PHarpEvent^.ourGroup)^.id = PActUnit^.Group^.id) then
             Inc(cEventAltitude);
        end;

        PHarpEvent := PHarpEvent^.next;
      end;
    end;
    lblAUMGroupId.Caption:='Group: ' + PActUnit^.Group^.id;
    lblAUMUnitId.Caption:='Unit: ' + IntToStr(PActUnit^.id);
    lblAUMName.Caption:='Name: ' + PActUnit^.name;
    lblAUMHeading.Caption:='Heading (deg): ' + IntToStr(PActUnit^.course)
     + ' (' + IntToStr(cEventCourse) + ' ALT_COURSE events)';
    lblAUMAltitude.Caption:='Altitude (m): '
     + Format('%0.0N', [PActUnit^.Altitude/1.0])
     + ' (' + IntToStr(cEventAltitude) + 'ALT_SPEED events)';

  end
  else
  begin
    lblAUMGroupId.Caption:='';
    lblAUMGroupId.Caption:='';
    lblAUMName.Caption:='';
    lblAUMHeading.Caption:='';
    lblAUMAltitude.Caption:='';
  end;

  //Byte(PDLLBusy^) := CFALSE;
end;

{ TfrmMain }


end.
