From: travi$ Date: Sat, 26 Mar 2022 16:46:38 +0000 (+0300) Subject: Add weapbest command X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=a7ab3742313f79cefd688def25534d692dc7346c;p=d2df-sdl.git Add weapbest command --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index b4b67ff..35778ef 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -1148,10 +1148,12 @@ begin AddCommand('p1_weapnext', GameCommands); AddCommand('p1_weapprev', GameCommands); AddCommand('p1_weapon', GameCommands); + AddCommand('p1_weapbest', GameCommands); AddCommand('p1_dropflag', GameCommands); AddCommand('p2_weapnext', GameCommands); AddCommand('p2_weapprev', GameCommands); AddCommand('p2_weapon', GameCommands); + AddCommand('p2_weapbest', GameCommands); AddCommand('p2_dropflag', GameCommands); AddCommand('god', GameCheats); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index f85024b..5f7674f 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -7438,6 +7438,14 @@ begin gSelectWeapon[b, a] := True end end + else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then + begin + b := ord(cmd[2]) - ord('1'); + if b = 0 then + gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True + else + gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True; + end else if (cmd = 'dropflag') then begin if g_Game_IsServer then diff --git a/src/game/g_player.pas b/src/game/g_player.pas index fbbd09a..8ad8931 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -303,6 +303,7 @@ type procedure SetWeaponPrefs(Prefs: Array of Byte); procedure SetWeaponPref(Weapon, Pref: Byte); function GetWeaponPref(Weapon: Byte) : Byte; + function GetMorePrefered() : Byte; function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload; function Collide(Panel: TPanel): Boolean; overload; function Collide(X, Y: Integer): Boolean; overload; @@ -2023,6 +2024,18 @@ begin result := FWeapPreferences[Weapon]; end; +function TPlayer.GetMorePrefered() : Byte; +var testedWeap, i: Byte; +begin + testedWeap := FCurrWeap; + for i := WP_FIRST to WP_LAST do + if FWeapon[i] and (FWeapPreferences[i] > FWeapPreferences[testedWeap]) then + testedWeap := i; + if (R_BERSERK in FRulez) and (FWeapPreferences[WP_LAST + 1] > FWeapPreferences[testedWeap]) then + testedWeap := WEAPON_KASTET; + result := testedWeap; +end; + procedure TPlayer.SwitchTeam; begin if g_Game_IsClient then