library InstaTurn; //{$mode delphi}{$H+} uses Classes, Interfaces, Windows, SysUtils { you can add units after this } ,uHCDefines, uHCGCI, uHCGlobals, uHCTypeDefs, uHCEventHelpers, uHCDateTime, uHCAnnexDefs, uHCAnnexHelpers, uHCUtils, uinstaturn; const DLLVERN = 2; DLLVERINTN = 19; {*** Return DLL internal version, i.e. revision 5 of my DLL ***} function DLLVer():word;export;cdecl; begin result := DLLVERN; end; {*** Return DLL interface version, i.e. revision 1 of my HCE interface spec ***} function DLLVerInt():word;export;cdecl; begin result := DLLVERINTN; end; {*** Return DLL description, 255 characters max ***} function DLLDesc():PAnsiChar;export;cdecl; begin result := 'InstaTurn DLL by Tony Eischens'; end; {*** Free DLL ***} procedure DLLFree();export;cdecl; begin // Do any cleanup here, this is the end end; {*** Checks if MessageLogLine is connected and if it is, use it ***} procedure MessageLogLine(pMessage: String); begin if (intVerInterface >= 19) then begin if (HCMessageLogLine <> nil) then begin HCMessageLogLine(PChar(pMessage)); end; end; end; {*** Init DLL ***} procedure DLLInit(hwndHC: HWND; pathHC: PAnsiChar; verHC: PAnsiChar; verSaveGame: LongWord; funcRefs: PHCDLL_FUNC_REF; PGEClosing: Pointer; PDLLBusy: Pointer; verInterface: LongWord);export;cdecl; var funcTmp: PHCDLL_FUNC_REF; begin // here we initialize globals and such for the life of the DLL uInstaTurn.PGEClosing:=PGEClosing; uInstaTurn.PDLLBusy:=PDLLBusy; uInstaTurn.intVerInterface:=verInterface; uInstaTurn.intVerSaveGame:=verSaveGame; // ALE 20171121 consider sending messages to the MessageLog window so we // need to capture that function // ALE 20130908 List the function pointers sent over by the GE // then capture one of them for example usage HCMessageLogLine := nil; funcTmp := funcRefs; while (funcTmp <> nil) do begin if (funcTmp^.funcName = 'MessageLogLine') then begin HCMessageLogLine := THCMessageLogLine(funcTmp^.funcPtr); break; end; funcTmp := funcTmp^.Next; end; end; function Turn(pTurning_group: PHCGroup; pTurning_unit: PHCUnit; pOldCourse: short; pNewCourse: short): CBOOL;export;cdecl; var lGroup: PHCGroup; lUnit: PHCUnit; begin result := CTRUE; // ALE 20170309 we are always handling the turns lGroup := pTurning_group; lUnit := pTurning_unit; if ((lGroup = nil) OR (HCIsValidGroup(lGroup, uinstaturn.PGroupStart) = CFALSE)) then begin if ((lUnit = nil) OR (HCIsValidUnit(lUnit, uinstaturn.PUnitTop) = CFALSE)) then begin exit; end else begin // ALE 20160610 We already assigned lUnit, lUnit = Turning_unit; lGroup := lUnit^.Group; end; end else begin // ALE 20160610 We already assigned both lGroup and lUnit so we don't need to again here // ALE 20160610 But we do need to differentiate between null and bad units if (HCIsValidUnit(lUnit, uinstaturn.PUnitTop) = CFALSE) then begin lUnit := nil; end; end; if (pOldCourse = INVALID_HEADING) then pOldCourse := lGroup^.course; if (pOldCourse = pNewCourse) then exit; if (lUnit <> nil) then begin lUnit^.course := pNewCourse; if (lUnit^.Group^.side = intPlayerSide) then begin MessageLogLine('InstaTurn Unit=' + IntToStr(lUnit^.id) + ' Group=' + lGroup^.id + ' from ' + IntToStr(pOldCourse) + ' to ' + IntToStr(pNewCourse)); end; end else begin HCSetGroupSlivers(lGroup, HCDegToSliver(pNewCourse)); if (lGroup^.side = intPlayerSide) then begin MessageLogLine('InstaTurn Group=' + lGroup^.id + ' from ' + IntToStr(pOldCourse) + ' to ' + IntToStr(pNewCourse)); end; end; end; procedure UnitTop(pUnitTop: PHCUnit);export;cdecl; begin uinstaturn.PUnitTop := pUnitTop; end; procedure StartGroup(pGroupStart: PHCGroup);export;cdecl; begin uinstaturn.PGroupStart:=pGroupStart; end; procedure ScenLoad(strHarpPath: PAnsiChar; intScenNum: SmallInt; strScenFPath: PAnsiChar; intBSNum: ShortInt; strBSFName: PAnsiChar; intSide: byte; intGameTimeIn: Long; intGameTimeLeftIn: Long; dt_scen_start_in: PHCDateTimeRec; AnnexDataIn: PHCAnnexes_disk);export;cdecl; begin uinstaturn.intPlayerSide := intSide; end; exports DLLVer, DLLVerInt, DLLDesc, DLLFree, DLLInit ,Turn // ALE 20170309 Allows overriding of turns ,StartGroup // ALE 20170309 So we can walk the group list ,UnitTop // ALE 20170309 Tells us when Bhead.topUnit changes ,ScenLoad // ALE 20171123 to get player side ; end.