DEADSOFTWARE

added `.positionChanged()` to (almost) all entities; don't forget to call it after...
[d2df-sdl.git] / src / game / g_monsters.pas
index 57e3ce96c800185c10684cacf6aac3d6ebaf0473..0d8f3841d1eab4f1127def30e016d7eabdd7852b 100644 (file)
@@ -128,6 +128,8 @@ type
     procedure CatchFire(Attacker: Word);
     procedure OnFireFlame(Times: DWORD = 1);
 
+    procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
+
     property MonsterType: Byte read FMonsterType;
     property MonsterHealth: Integer read FHealth write FHealth;
     property MonsterAmmo: Integer read FAmmo write FAmmo;
@@ -1447,6 +1449,8 @@ begin
   FState := STATE_SLEEP;
   FCurAnim := ANIM_SLEEP;
 
+  positionChanged(); // this updates spatial accelerators
+
   if g_Game_IsNet and g_Game_IsServer then
   begin
     MH_SEND_MonsterPos(FUID);
@@ -1686,6 +1690,7 @@ begin
                              c, True, False);
         g_Obj_Push(@gItems[it].Obj, (FObj.Vel.X div 2)-3+Random(7),
                                     (FObj.Vel.Y div 2)-Random(4));
+        positionChanged(); // this updates spatial accelerators
         if g_Game_IsServer and g_Game_IsNet then
           MH_SEND_ItemSpawn(True, it);
       end;
@@ -2022,6 +2027,7 @@ begin
   if gTime mod (GAME_TICK*2) <> 0 then
   begin
     g_Obj_Move(@FObj, fall, True, True);
+    positionChanged(); // this updates spatial accelerators
     Exit;
   end;
 
@@ -2032,6 +2038,7 @@ begin
 
 // Äâèãàåìñÿ:
   st := g_Obj_Move(@FObj, fall, True, True);
+  positionChanged(); // this updates spatial accelerators
 
 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
   if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
@@ -2421,14 +2428,23 @@ begin
               b := Abs(FObj.Vel.X);
               if b > 1 then b := b * (Random(8 div b) + 1);
               for a := 0 to High(gGibs) do
+              begin
                 if gGibs[a].Live and
                    g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
                                  FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
+                begin
                   // Ïèíàåì êóñêè
                   if FObj.Vel.X < 0 then
-                    g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
+                  begin
+                    g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
+                  end
                   else
+                  begin
                     g_Obj_PushA(@gGibs[a].Obj, b, Random(61));    // íàïðàâî
+                  end;
+                  positionChanged(); // this updates spatial accelerators
+                end;
+              end;
             end;
           // Áîññû ìîãóò ïèíàòü òðóïû:
             if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
@@ -2979,6 +2995,7 @@ begin
   if gTime mod (GAME_TICK*2) <> 0 then
   begin
     g_Obj_Move(@FObj, fall, True, True);
+    positionChanged(); // this updates spatial accelerators
     Exit;
   end;
 
@@ -2989,6 +3006,7 @@ begin
 
 // Äâèãàåìñÿ:
   st := g_Obj_Move(@FObj, fall, True, True);
+  positionChanged(); // this updates spatial accelerators
 
 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
   if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
@@ -3242,14 +3260,23 @@ begin
               b := Abs(FObj.Vel.X);
               if b > 1 then b := b * (Random(8 div b) + 1);
               for a := 0 to High(gGibs) do
+              begin
                 if gGibs[a].Live and
                    g_Obj_Collide(FObj.X+FObj.Rect.X, FObj.Y+FObj.Rect.Y+FObj.Rect.Height-4,
                                  FObj.Rect.Width, 8, @gGibs[a].Obj) and (Random(3) = 0) then
+                begin
                   // Ïèíàåì êóñêè
                   if FObj.Vel.X < 0 then
-                    g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120) // íàëåâî
+                  begin
+                    g_Obj_PushA(@gGibs[a].Obj, b, Random(61)+120); // íàëåâî
+                  end
                   else
+                  begin
                     g_Obj_PushA(@gGibs[a].Obj, b, Random(61));    // íàïðàâî
+                  end;
+                  positionChanged(); // this updates spatial accelerators
+                end;
+              end;
             end;
           // Áîññû ìîãóò ïèíàòü òðóïû:
             if (FMonsterType in [MONSTER_CYBER, MONSTER_SPIDER, MONSTER_ROBO]) and
@@ -4211,4 +4238,9 @@ begin
   end;
 end;
 
+//WARNING! call this after monster position was changed, or coldet will not work right!
+procedure TMonster.positionChanged ();
+begin
+end;
+
 end.