DEADSOFTWARE

g_weapons.g_Weapon_gun: faster traces (i hope)
[d2df-sdl.git] / src / game / g_monsters.pas
index 55a02104f4a56e602de638d507b13490936100cf..ca7ec00e32e8be568d538f6020515c42dbfcc9e6 100644 (file)
@@ -20,7 +20,7 @@ interface
 
 uses
   g_basic, e_graphics, g_phys, g_textures,
-  g_saveload, BinEditor, g_panel;
+  g_saveload, BinEditor, g_panel, z_aabbtree;
 
 const
   MONSTATE_SLEEP  = 0;
@@ -90,6 +90,8 @@ type
     function findNewPrey(): Boolean;
     procedure ActivateTriggers();
 
+    function getMapAABB (): AABB2D; inline;
+
   public
     FNoRespawn: Boolean;
     FFireTime: Integer;
@@ -158,6 +160,8 @@ type
     property GameAccelY: Integer read FObj.Accel.Y write FObj.Accel.Y;
     property GameDirection: TDirection read FDirection write FDirection;
 
+    property mapAABB: AABB2D read getMapAABB;
+
     property StartID: Integer read FStartID;
   end;
 
@@ -181,7 +185,7 @@ function  g_Monsters_GetKilledBy (MonsterType: Byte): String;
 
 
 type
-  TEachMonsterCB = function (monidx: Integer; mon: TMonster): Boolean is nested; // return `true` to stop
+  TEachMonsterCB = function (mon: TMonster): Boolean is nested; // return `true` to stop
 
 // throws on invalid uid
 function g_Mons_ByIdx (uid: Integer): TMonster; inline;
@@ -210,7 +214,7 @@ uses
   e_log, g_main, g_sound, g_gfx, g_player, g_game,
   g_weapons, g_triggers, MAPDEF, g_items, g_options,
   g_console, g_map, Math, SysUtils, g_menu, wadreader,
-  g_language, g_netmsg, z_aabbtree;
+  g_language, g_netmsg;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
@@ -218,6 +222,12 @@ var
   monCheckTrapLastFrameId: DWord;
 
 
+function TMonster.getMapAABB (): AABB2D; inline;
+begin
+  result := AABB2D.CreateWH(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y, FObj.Rect.Width, FObj.Rect.Height);
+end;
+
+
 // ////////////////////////////////////////////////////////////////////////// //
 type
   TDynAABBTreeMonsBase = specialize TDynAABBTreeBase<TMonster>;
@@ -231,7 +241,8 @@ begin
   result := false;
   if (flesh = nil) then raise Exception.Create('DynTree: trying to get dimensions of inexistant monsters');
   if (flesh.Obj.Rect.Width < 1) or (flesh.Obj.Rect.Height < 1) then raise Exception.Create('DynTree: monster without size, wtf?!');
-  aabb := AABB2D.CreateWH(flesh.Obj.X+flesh.Obj.Rect.X, flesh.Obj.Y+flesh.Obj.Rect.Y, flesh.Obj.Rect.Width, flesh.Obj.Rect.Height);
+  //aabb := AABB2D.CreateWH(flesh.Obj.X+flesh.Obj.Rect.X, flesh.Obj.Y+flesh.Obj.Rect.Y, flesh.Obj.Rect.Width, flesh.Obj.Rect.Height);
+  aabb := flesh.getMapAABB();
   if not aabb.valid then raise Exception.Create('wutafuuuuuuu?!');
   result := true;
 end;
@@ -573,6 +584,7 @@ begin
   Result := False;
 end;
 
+
 function BehaviourDamage(SpawnerUID: Word; BH, SelfType: Byte): Boolean;
 var
   m: TMonster;
@@ -602,6 +614,7 @@ begin
   end;
 end;
 
+
 function canShoot(m: Byte): Boolean;
 begin
   Result := False;
@@ -614,7 +627,8 @@ begin
   end;
 end;
 
-function isCorpse(o: PObj; immediately: Boolean): Integer;
+
+function isCorpse (o: PObj; immediately: Boolean): Integer;
 
   function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
   begin
@@ -4447,7 +4461,7 @@ begin
     mon := gMonsters[idx];
     if (mon <> nil) then
     begin
-      result := cb(idx, gMonsters[idx]);
+      result := cb(mon);
       if result then exit;
     end;
   end;
@@ -4466,7 +4480,7 @@ begin
     mon := gMonsters[idx];
     if (mon <> nil) and mon.Live then
     begin
-      result := cb(idx, gMonsters[idx]);
+      result := cb(mon);
       if result then exit;
     end;
   end;
@@ -4513,7 +4527,7 @@ function g_Mons_ForEachAt (x, y: Integer; width, height: Integer; cb: TEachMonst
   function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
   begin
     result := false;
-    if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon.arrIdx, mon);
+    if g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
   end;
 
 var
@@ -4535,7 +4549,7 @@ begin
       begin
         if g_Obj_Collide(x, y, width, height, @mon.Obj) then
         begin
-          result := cb(idx, mon);
+          result := cb(mon);
           if result then exit;
         end;
       end;
@@ -4549,7 +4563,7 @@ function g_Mons_ForEachAliveAt (x, y: Integer; width, height: Integer; cb: TEach
   function monsCollCheck (mon: TMonster; atag: Integer): Boolean;
   begin
     result := false;
-    if mon.Live and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon.arrIdx, mon);
+    if mon.Live and g_Obj_Collide(x, y, width, height, @mon.Obj) then result := cb(mon);
   end;
 
 var
@@ -4578,7 +4592,7 @@ begin
       begin
         if g_Obj_Collide(x, y, width, height, @mon.Obj) then
         begin
-          result := cb(idx, mon);
+          result := cb(mon);
           if result then exit;
         end;
       end;