DEADSOFTWARE

Game: Split bubbles effect code into a distinct function
authorDmitry D. Chernov <blackdoomer@yandex.ru>
Thu, 27 Jul 2023 19:01:49 +0000 (05:01 +1000)
committerDmitry D. Chernov <blackdoomer@yandex.ru>
Thu, 27 Jul 2023 19:02:18 +0000 (05:02 +1000)
src/game/g_game.pas
src/game/g_monsters.pas
src/game/g_player.pas
src/game/g_triggers.pas
src/game/g_weapons.pas

index 2c158c4e2335c16dfa78df2323cd49f44b5677a6..0cca55387e1b518016faab9f0925fbc2b88c2b41 100644 (file)
@@ -131,6 +131,7 @@ procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
 procedure g_Game_Announce_KillCombo(Param: Integer);
 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
+procedure g_Game_Effect_Bubbles(fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean = False);
 procedure g_Game_StartVote(Command, Initiator: string);
 procedure g_Game_CheckVote;
 procedure g_TakeScreenShot(Filename: string = '');
@@ -667,7 +668,7 @@ end;
 
 // saves a shitty CSV containing the game stats passed to it
 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
-var 
+var
   s: TextFile;
   dir, fname, map, mode, etime: String;
   I: Integer;
@@ -709,7 +710,7 @@ begin
       //   if it's a coop game: monsters killed, monsters total, secrets found, secrets total
       //   otherwise nothing
       if Stat.GameMode in [GM_TDM, GM_CTF] then
-        WriteLn(s, 
+        WriteLn(s,
           Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Score, Stat.TeamStat[TEAM_BLUE].Score]))
       else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
         WriteLn(s,
@@ -5857,7 +5858,7 @@ begin
         // if someone has a higher score, set it to that instead
         gsScoreLimit := max(gsScoreLimit, b);
         gGameSettings.ScoreLimit := gsScoreLimit;
+
         if g_Game_IsNet then MH_SEND_GameSettings;
       end;
     end;
@@ -6070,13 +6071,13 @@ begin
     'p1_priority_kastet':
       begin
         if (Length(P) = 2) then
-          gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
+          gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
         end;
     'p2_priority_kastet':
       begin
         if (Length(P) = 2) then
-          gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
-      end;        
+          gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
+      end;
     'p1_priority_saw':
       begin
         if (Length(P) = 2) then
@@ -6090,13 +6091,13 @@ begin
     'p1_priority_pistol':
       begin
         if (Length(P) = 2) then
-          gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
+          gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
         end;
     'p2_priority_pistol':
       begin
         if (Length(P) = 2) then
-          gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
-      end;         
+          gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
+      end;
     'p1_priority_shotgun1':
       begin
         if (Length(P) = 2) then
@@ -6176,17 +6177,17 @@ begin
       begin
         if (Length(P) = 2) then
           gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
-      end;      
+      end;
     'p1_priority_berserk':
       begin
         if (Length(P) = 2) then
-          gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
+          gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
         end;
     'p2_priority_berserk':
       begin
         if (Length(P) = 2) then
-          gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1); 
-      end;                                                                                  
+          gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
+      end;
   end;
 end;
 
@@ -6952,7 +6953,7 @@ begin
         t := TEAM_RED
       else if P[2] = 'blue' then
         t := TEAM_BLUE
-      else 
+      else
         t := TEAM_NONE;
 
       if Length(P) = 3
@@ -7850,7 +7851,7 @@ begin
       DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
       Filename := 'screenshot-' + date;
     end;
-    
+
     name := e_CatPath(dir, Filename + '.png');
     s := createDiskFile(name);
     try
@@ -8202,6 +8203,14 @@ begin
   hahasnd[Random(3)].Play();
 end;
 
+procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
+begin
+  g_GFX_Bubbles(fX, fY, count, devX, devY);
+  if not Silent then if Random(2) = 0
+    then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
+    else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
+end;
+
 procedure g_Game_StartVote(Command, Initiator: string);
 var
   Need: Integer;
index d8adad853402974c802ba9bfbd3f58761809835e..ad887adfdd29d7e102c3a36069630eb0734437af 100644 (file)
@@ -2468,7 +2468,7 @@ var
   a, b, sx, sy, wx, wy, oldvelx: Integer;
   st: Word;
   o, co: TObj;
-  fall, bubbles: Boolean;
+  fall: Boolean;
   mon: TMonster;
   mit: PMonster;
   it: TMonsterGrid.Iter;
@@ -2476,7 +2476,6 @@ label
   _end;
 begin
   fall := True;
-  bubbles := True;
 
 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
   if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
@@ -2575,23 +2574,18 @@ begin
 
 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
   if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
-  begin
     case FMonsterType of
       MONSTER_FISH:
-        if Random(4) <> 0 then bubbles := False else
-          g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
-                        FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
+        if Random(4) = 0 then
+          g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
+                                FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
       MONSTER_ROBO, MONSTER_BARREL:
-        g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
-                      FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
+        g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
+                              FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
       else
-        g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
-                      FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
+        g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
+                              FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
     end;
-    if bubbles then if Random(2) = 0
-      then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
-      else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
-  end;
 
 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
   if FMonsterType = MONSTER_BARREL then
@@ -3463,14 +3457,13 @@ var
   a, b, sx, sy, oldvelx: Integer;
   st: Word;
   o, co: TObj;
-  fall, bubbles: Boolean;
+  fall: Boolean;
 label
   _end;
 begin
   sx := 0; // SHUT UP COMPILER
   sy := 0;
   fall := True;
-  bubbles := True;
 
 // Ìîíñòð ñòàòè÷åí ïîêà èäåò warmup
   if (gLMSRespawn > LMS_RESPAWN_NONE) then exit;
@@ -3537,23 +3530,18 @@ begin
 
 // Âîçìîæíî, ñîçäàåì ïóçûðüêè â âîäå:
   if WordBool(st and MOVE_INWATER) and (Random(32) = 0) then
-  begin
     case FMonsterType of
       MONSTER_FISH:
-        if Random(4) <> 0 then bubbles := False else
-          g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
-                        FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
+        if Random(4) = 0 then
+          g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
+                                FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
       MONSTER_ROBO, MONSTER_BARREL:
-        g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
-                      FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
+        g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width),
+                              FObj.Y+FObj.Rect.Y + Random(4), 1, 0, 0);
       else
-        g_GFX_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
-                      FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
+        g_Game_Effect_Bubbles(FObj.X+FObj.Rect.X + Random(FObj.Rect.Width-4),
+                              FObj.Y+FObj.Rect.Y + Random(4), 5, 4, 4);
     end;
-    if bubbles then if Random(2) = 0
-      then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
-      else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
-  end;
 
 // Åñëè ïðîøåë ïåðâûé êàäð àíèìàöèè âçðûâà áî÷êè, òî âçðûâ:
   if FMonsterType = MONSTER_BARREL then
index 1468551a3c29fcd0ee26e32bc564ed7800559c2d..d0275d093fca62244370f201ff0cabb68bcb98f8 100644 (file)
@@ -1096,7 +1096,7 @@ begin
         Team := BotList[num].team; // CTF / TDM
 
 // Âûáèðàåì íàñòðîéêè áîòà èç ñïèñêà ïî íîìåðó èëè èìåíè:
-  if lName = '' then 
+  if lName = '' then
     num := Random(Length(BotList))
   else
   begin
@@ -2347,13 +2347,8 @@ begin
         end;
 
       if t = HIT_WATER then
-      begin
-        g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
-                      FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
-        if Random(2) = 0
-          then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
-          else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
-      end;
+        g_Game_Effect_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
+                              FObj.Y+PLAYER_RECT.Y-4, value div 2, 8, 4);
     end;
 
   // Áóôåð óðîíà:
@@ -5424,12 +5419,8 @@ begin
           FAir := 0;
       end
       else if (FAir mod 31 = 0) and not blockmon then
-      begin
-        g_GFX_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2), FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
-        if Random(2) = 0
-          then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
-          else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
-      end;
+        g_Game_Effect_Bubbles(FObj.X+PLAYER_RECT.X+(PLAYER_RECT.Width div 2),
+                              FObj.Y+PLAYER_RECT.Y-4, 5+Random(6), 8, 4);
     end else if FAir < AIR_DEF then
       FAir := AIR_DEF;
 
@@ -6527,11 +6518,8 @@ begin
 
   if BodyInLiquid(0, 0) then
   begin
-    g_GFX_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
-                  Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
-    if Random(2) = 0
-      then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', FObj.X, FObj.Y)
-      else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', FObj.X, FObj.Y);
+    g_Game_Effect_Bubbles(Obj.X+Obj.Rect.X+(Obj.Rect.Width div 2)+Random(3)-1,
+                          Obj.Y+Obj.Rect.Height+8, 1, 8, 4);
     Exit;
   end;
 
index 2509650d413b5ccc9af45f390ad91339bd4a30ad..f8e9e02dcef20c79c8806218c459f79aa8056a93 100644 (file)
@@ -884,13 +884,7 @@ begin
       TRIGGER_EFFECT_DLIQUID: g_GFX_SimpleWater(X, Y, 1, VX, VY, 5, CR, CG, CB);
       TRIGGER_EFFECT_BLOOD: g_GFX_Blood(X, Y, 1, VX, VY, 0, 0, CR, CG, CB);
       TRIGGER_EFFECT_SPARK: g_GFX_Spark(X, Y, 1, GetAngle2(VX, VY), 0, 0);
-      TRIGGER_EFFECT_BUBBLE:
-      begin
-        g_GFX_Bubbles(X, Y, 1, 0, 0);
-        if not Silent then if Random(2) = 0
-          then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', X, Y)
-          else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', X, Y);
-      end;
+      TRIGGER_EFFECT_BUBBLE: g_Game_Effect_Bubbles(X, Y, 1, 0, 0, Silent);
     end;
   end;
 
index f0fe29114071a4c6b9f5ce2f9b64ec678d387e77..86a9de5e15a45b072a8da158d9d981e84cc77dac 100644 (file)
@@ -2278,10 +2278,7 @@ begin
           // Â âîäå øëåéô - ïóçûðè, â âîçäóõå øëåéô - äûì:
             if WordBool(st and MOVE_INWATER) then
             begin
-              g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
-              if Random(2) = 0
-                then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
-                else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
+              g_Game_Effect_Bubbles(cx, cy, 1+Random(3), 16, 16);
             end
             else if g_Frames_Get(_id, 'FRAMES_SMOKE') then
             begin
@@ -2413,12 +2410,8 @@ begin
                 end;
               end
               else
-              begin
-                g_GFX_Bubbles(cx, cy, 1+Random(3), 16, 16);
-                if Random(2) = 0
-                  then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', cx, cy)
-                  else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', cx, cy);
-              end;
+                g_Game_Effect_Bubbles(cx, cy, 1+Random(3), 16, 16);
+
               ShotType := 0;
               Continue;
             end;