DEADSOFTWARE

Add weapbest command
authortravi$ <aidenkovbk@mail.ru>
Sat, 26 Mar 2022 16:46:38 +0000 (19:46 +0300)
committerDmitry Lyashuk <terminalhash@th-mx>
Sat, 26 Mar 2022 17:50:39 +0000 (20:50 +0300)
src/game/g_console.pas
src/game/g_game.pas
src/game/g_player.pas

index b4b67ffb01bb729f2cea7b3cdba867684e8d6d62..35778ef797dc9fbfa9897493209f7d2a00d2d4e8 100644 (file)
@@ -1148,10 +1148,12 @@ begin
   AddCommand('p1_weapnext', GameCommands);
   AddCommand('p1_weapprev', GameCommands);
   AddCommand('p1_weapon', GameCommands);
   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('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);
   AddCommand('p2_dropflag', GameCommands);
 
   AddCommand('god', GameCheats);
index f85024b31b0c05a68e9947476e3180b36d12469f..5f7674fad60b3b38dd537cdfe88b24c5e92ede81 100644 (file)
@@ -7438,6 +7438,14 @@ begin
         gSelectWeapon[b, a] := True
     end
   end
         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
   else if (cmd = 'dropflag') then
   begin
     if g_Game_IsServer then
index fbbd09af8b270a58deee364d75df247bf984a3bf..8ad8931e32ddaff68a1ac89b57e1431003da9464 100644 (file)
@@ -303,6 +303,7 @@ type
     procedure   SetWeaponPrefs(Prefs: Array of Byte);
     procedure   SetWeaponPref(Weapon, Pref: Byte);
     function    GetWeaponPref(Weapon: Byte) : Byte;
     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;
     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;
 
     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
 procedure TPlayer.SwitchTeam;
 begin
   if g_Game_IsClient then