DEADSOFTWARE

Game: Monster burning propagation fix
[d2df-sdl.git] / src / game / g_monsters.pas
index 4cba5acb10b21bd2487e25d577e7a4611455449a..02bea1f632bb906c89b5b56a220b757ec2d1b484 100644 (file)
@@ -40,6 +40,8 @@ const
   MONSTATE_REVIVE = 10;
   MONSTATE_RUNOUT = 11;
 
+  MON_BURN_TIME   = 100;
+
 { in mapdef now
   BH_NORMAL   = 0;
   BH_KILLER   = 1;
@@ -145,7 +147,7 @@ type
     function  AnimIsReverse: Boolean;
     function  shoot(o: PObj; immediately: Boolean): Boolean;
     function  kick(o: PObj): Boolean;
-    procedure CatchFire(Attacker: Word);
+    procedure CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
     procedure OnFireFlame(Times: DWORD = 1);
 
     procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right!
@@ -322,8 +324,8 @@ uses
 procedure g_Mons_ProfilersBegin ();
 begin
   if (profMonsLOS = nil) then profMonsLOS := TProfiler.Create('LOS CALC', g_profile_history_size);
-  profMonsLOS.mainBegin(g_profile_los);
-  if g_profile_los then
+  if (profMonsLOS <> nil) then profMonsLOS.mainBegin(g_profile_los);
+  if g_profile_los and (profMonsLOS <> nil) then
   begin
     profMonsLOS.sectionBegin('loscalc');
     profMonsLOS.sectionEnd();
@@ -332,17 +334,17 @@ end;
 
 procedure g_Mons_ProfilersEnd ();
 begin
-  if (profMonsLOS <> nil) and (g_profile_los) then profMapCollision.mainEnd();
+  if (profMonsLOS <> nil) and (g_profile_los) then profMonsLOS.mainEnd();
 end;
 
 procedure g_Mons_LOS_Start (); inline;
 begin
-  profMonsLOS.sectionBeginAccum('loscalc');
+  if (profMonsLOS <> nil) then profMonsLOS.sectionBeginAccum('loscalc');
 end;
 
 procedure g_Mons_LOS_End (); inline;
 begin
-  profMonsLOS.sectionEnd();
+  if (profMonsLOS <> nil) then profMonsLOS.sectionEnd();
 end;
 
 
@@ -2469,6 +2471,14 @@ begin
   st := g_Obj_Move(@FObj, fall, True, True);
   positionChanged(); // this updates spatial accelerators
 
+// Åñëè ãîðèì - ïîäæèãàåì äðóãèõ ìîíñòðîâ, íî íå íà 100 òèêîâ êàæäûé ðàç:
+  if FFireTime > 0 then
+    for a := 0 to High(gMonsters) do
+      if (gMonsters[a] <> nil) and (gMonsters[a].alive) and
+         (gMonsters[a].FUID <> FUID) and
+         g_Obj_Collide(@FObj, @gMonsters[a].Obj) then
+        gMonsters[a].CatchFire(FFireAttacker, FFireTime);
+
 // Âûëåòåë çà êàðòó - óäàëÿåì è çàïóñêàåì òðèããåðû:
   if WordBool(st and MOVE_FALLOUT) or (FObj.X < -1000) or
      (FObj.X > gMapInfo.Width+1000) or (FObj.Y < -1000) then
@@ -2825,7 +2835,7 @@ begin
 
                   // Ðûáà ïëûâåò ââåðõ:
                     if FObj.Vel.Y < 0 then
-                      if not g_Obj_CollideWater(@FObj, 0, -16) then
+                      if not g_Obj_CollideLiquid(@FObj, 0, -16) then
                       begin
                       // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
                         FObj.Vel.Y := 0;
@@ -3243,6 +3253,19 @@ _end:
               wx := FObj.X + wx;
               wy := FObj.Y + MONSTER_ANIMTABLE[FMonsterType].wY;
 
+            // Ìîíñòð íå ìîæåò öåëèòüñÿ â îáúåêò çà ñïèíîé, ñòðåëÿÿ âëåâî:
+              if (FDirection = TDirection.D_LEFT) and (tx > wx) then
+              begin
+                tx := wx - 32;
+                ty := wy + Random(11) - 5;
+              end;
+            // È àíàëîãè÷íî, ñòðåëÿÿ âïðàâî:
+              if (FDirection = TDirection.D_RIGHT) and (tx < wx) then
+              begin
+                tx := wx + 32;
+                ty := wy + Random(11) - 5;
+              end;
+
             // Äåëàåì âûñòðåë íóæíûì îðóæèåì:
               case FMonsterType of
                 MONSTER_IMP:
@@ -3661,7 +3684,7 @@ begin
 
                   // Ðûáà ïëûâåò ââåðõ:
                     if FObj.Vel.Y < 0 then
-                      if not g_Obj_CollideWater(@FObj, 0, -16) then
+                      if not g_Obj_CollideLiquid(@FObj, 0, -16) then
                       begin
                       // Âñïëûëè äî ïîâåðõíîñòè - ñòîï:
                         FObj.Vel.Y := 0;
@@ -4623,9 +4646,12 @@ begin
   SetLength(FDieTriggers, 0);
 end;
 
-procedure TMonster.CatchFire(Attacker: Word);
+procedure TMonster.CatchFire(Attacker: Word; Timeout: Integer = MON_BURN_TIME);
 begin
-  FFireTime := 100;
+  if Timeout <= 0 then exit;
+  if FFireTime <= 0 then
+    g_Sound_PlayExAt('SOUND_IGNITE', FObj.X, FObj.Y);
+  FFireTime := Timeout;
   FFireAttacker := Attacker;
   if g_Game_IsNet and g_Game_IsServer then MH_SEND_MonsterState(FUID);
 end;