From 3fb071dcefe7c3d8081e5a3906c1983d02b5ccd0 Mon Sep 17 00:00:00 2001 From: "Dmitry D. Chernov" Date: Fri, 28 Jul 2023 05:01:49 +1000 Subject: [PATCH] Game: Split bubbles effect code into a distinct function --- src/game/g_game.pas | 39 ++++++++++++++++++++++-------------- src/game/g_monsters.pas | 44 +++++++++++++++-------------------------- src/game/g_player.pas | 26 +++++++----------------- src/game/g_triggers.pas | 8 +------- src/game/g_weapons.pas | 13 +++--------- 5 files changed, 51 insertions(+), 79 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 2c158c4..0cca553 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -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; diff --git a/src/game/g_monsters.pas b/src/game/g_monsters.pas index d8adad8..ad887ad 100644 --- a/src/game/g_monsters.pas +++ b/src/game/g_monsters.pas @@ -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 diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 1468551..d0275d0 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -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; diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas index 2509650..f8e9e02 100644 --- a/src/game/g_triggers.pas +++ b/src/game/g_triggers.pas @@ -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; diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas index f0fe291..86a9de5 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -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; -- 2.29.2