DEADSOFTWARE

cleanup: move monster-specific code from g_basic
[d2df-sdl.git] / src / game / g_basic.pas
index 1ed87abd9145fba8dbf04b0875b590d38dbb7d2f..d119742bcec3881673e4e8acb7a922810da417ae 100644 (file)
@@ -38,6 +38,9 @@ type
   DWArray = array of DWORD;
   String20 = String[20];
 
+function g_GetBuilderName (): AnsiString;
+function g_GetBuildHash (full: Boolean = True): AnsiString;
+
 function g_CreateUID(UIDType: Byte): Word;
 function g_GetUIDType(UID: Word): Byte;
 function g_Collide(X1, Y1: Integer; Width1, Height1: Word;
@@ -51,7 +54,6 @@ function g_CollidePlayer(X, Y: Integer; Width, Height: Word): Boolean; inline;
 function g_PatchLength(X1, Y1, X2, Y2: Integer): Word;
 function g_TraceVector(X1, Y1, X2, Y2: Integer): Boolean; // `true`: no wall hit
 function g_GetAcidHit(X, Y: Integer; Width, Height: Word): Byte;
-function g_Look(a, b: PObj; d: TDirection): Boolean;
 procedure IncMax(var A: Integer; B, Max: Integer); overload;
 procedure IncMax(var A: Single; B, Max: Single); overload;
 procedure IncMax(var A: Integer; Max: Integer); overload;
@@ -73,8 +75,6 @@ function Sign(A: Single): ShortInt; overload;
 function PointToRect(X, Y, X1, Y1: Integer; Width, Height: Word): Integer;
 function GetAngle(baseX, baseY, pointX, PointY: Integer): SmallInt;
 function GetAngle2(vx, vy: Integer): SmallInt;
-function GetLines(Text: string; FontID: DWORD; MaxWidth: Word): SSArray;
-procedure Sort(var a: SSArray);
 function Sscanf(const s: string; const fmt: string;
                 const Pointers: array of Pointer): Integer;
 function InDWArray(a: DWORD; arr: DWArray): Boolean;
@@ -98,7 +98,34 @@ implementation
 
 uses
   Math, geom, e_log, g_map, g_gfx, g_player, SysUtils, MAPDEF,
-  StrUtils, e_graphics, g_monsters, g_items, g_game;
+  StrUtils, g_monsters, g_items, g_game;
+
+{$PUSH}
+{$WARN 2054 OFF} // unknwon env var
+{$WARN 6018 OFF} // unreachable code
+function g_GetBuilderName (): AnsiString;
+begin
+  if {$I %D2DF_BUILD_USER%} <> '' then
+    result := {$I %D2DF_BUILD_USER%} // custom
+  else if {$I %USER%} <> '' then
+    result := {$I %USER%} // unix username
+  else if {$I %USERNAME%} <> '' then
+    result := {$I %USERNAME%} // windows username
+  else
+    result := 'unknown'
+end;
+
+function g_GetBuildHash (full: Boolean = True): AnsiString;
+begin
+  if {$I %D2DF_BUILD_HASH%} <> '' then
+    if full then
+      result := {$I %D2DF_BUILD_HASH%}
+    else
+      result := Copy({$I %D2DF_BUILD_HASH%}, 1, 7)
+  else
+    result := 'custom build'
+end;
+{$POP}
 
 function g_PatchLength(X1, Y1, X2, Y2: Integer): Word;
 begin
@@ -452,23 +479,6 @@ begin
   Result := tab[a];
 end;
 
-function g_Look(a, b: PObj; d: TDirection): Boolean;
-begin
-  if not gmon_dbg_los_enabled then begin result := false; exit; end; // always "wall hit"
-
-  if ((b^.X > a^.X) and (d = TDirection.D_LEFT)) or
-     ((b^.X < a^.X) and (d = TDirection.D_RIGHT)) then
-  begin
-    Result := False;
-    Exit;
-  end;
-
-  Result := g_TraceVector(a^.X+a^.Rect.X+(a^.Rect.Width div 2),
-                          a^.Y+a^.Rect.Y+(a^.Rect.Height div 2),
-                          b^.X+b^.Rect.X+(b^.Rect.Width div 2),
-                          b^.Y+b^.Rect.Y+(b^.Rect.Height div 2));
-end;
-
 function GetAngle(baseX, baseY, pointX, PointY: Integer): SmallInt;
 var
   c: Single;
@@ -628,58 +638,6 @@ begin
     end;
 end;
 
-function GetLines (Text: string; FontID: DWORD; MaxWidth: Word): SSArray;
-  var i, j, len, lines: Integer; w, cw, ch: Word; skip: Boolean;
-begin
-  result := nil; lines := 0; w := 0;
-  j := 1; i := 1; len := Length(Text);
-  while i <= len do
-  begin
-    e_CharFont_GetSize(FontID, '' + Text[i], cw, ch);
-    if (i >= len) or (w + cw >= MaxWidth) then
-    begin
-      skip := (i < len) and (Text[i] <> ' ');
-      if skip then
-      begin
-        // alt: while (i >= j) and (Text[i] <> ' ') do Dec(i);
-        while (i <= len) and (Text[i] <> ' ') do Inc(i);
-      end;
-      while (i >= j) and (Text[i] = ' ') do Dec(i);
-      (* --- *)
-      SetLength(result, lines + 1);
-      result[lines] := Copy(Text, j, i - j + 1);
-      Inc(lines);
-      (* --- *)
-      if skip then
-      begin
-        while (i <= len) and (Text[i] = ' ') do Inc(i);
-        Inc(i);
-      end;
-      j := i + 1;
-      w := 0
-    end;
-    Inc(w, cw);
-    Inc(i)
-  end;
-end;
-
-procedure Sort(var a: SSArray);
-var
-  i, j: Integer;
-  s: string;
-begin
-  if a = nil then Exit;
-
-  for i := High(a) downto Low(a) do
-    for j := Low(a) to High(a)-1 do
-      if LowerCase(a[j]) > LowerCase(a[j+1]) then
-      begin
-        s := a[j];
-        a[j] := a[j+1];
-        a[j+1] := s;
-      end;
-end;
-
 function Sscanf(const s: String; const fmt: String;
                 const Pointers: array of Pointer): Integer;
 var