DEADSOFTWARE

Add option to skip fist switching
authortravi$ <aidenkovbk@mail.ru>
Sat, 26 Mar 2022 17:41:05 +0000 (20:41 +0300)
committerDmitry Lyashuk <terminalhash@th-mx>
Sat, 26 Mar 2022 17:50:50 +0000 (20:50 +0300)
src/game/g_console.pas
src/game/g_game.pas
src/game/g_language.pas
src/game/g_menu.pas
src/game/g_netmsg.pas
src/game/g_player.pas

index 35778ef797dc9fbfa9897493209f7d2a00d2d4e8..87a1fba23b9c5120f144dd618f41080078dd80ad 100644 (file)
@@ -1040,6 +1040,8 @@ begin
   AddCommand('p2_autoswitch', PlayerSettingsCVars);
   AddCommand('p1_switch_empty', PlayerSettingsCVars);
   AddCommand('p2_switch_empty', PlayerSettingsCVars);
+  AddCommand('p1_skip_fist', PlayerSettingsCVars);
+  AddCommand('p2_skip_fist', PlayerSettingsCVars);
   AddCommand('p1_priority_kastet', PlayerSettingsCVars);
   AddCommand('p2_priority_kastet', PlayerSettingsCVars);
   AddCommand('p1_priority_saw', PlayerSettingsCVars);
index 5f7674fad60b3b38dd537cdfe88b24c5e92ede81..7e30028766f9080332d9568345b134bb3fa3b812 100644 (file)
@@ -66,7 +66,7 @@ type
     WeaponSwitch: Byte;
     WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
     SwitchToEmpty: Byte;
-    SwitchToFist: Byte;
+    SkipFist: Byte;
   end;
 
   TMegaWADInfo = record
@@ -4354,6 +4354,7 @@ begin
       gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
       gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
       gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+      gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
       g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
       if g_Game_IsServer and g_Game_IsNet then
         MH_SEND_PlayerCreate(gPlayer1.UID);
@@ -4387,6 +4388,7 @@ begin
       gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
       gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
       gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
+      gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
       g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
       if g_Game_IsServer and g_Game_IsNet then
         MH_SEND_PlayerCreate(gPlayer2.UID);
@@ -4505,6 +4507,7 @@ begin
   gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
   gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
   gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+  gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
   nPl := 1;
 
 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
@@ -4523,6 +4526,7 @@ begin
     gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
     gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
     gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
+    gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
     Inc(nPl);
   end;
 
@@ -4605,6 +4609,7 @@ begin
     gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
     gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
     gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+    gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
     Inc(nPl);
   end;
 
@@ -4624,6 +4629,7 @@ begin
     gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
     gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
     gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
+    gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
     Inc(nPl);
   end;
 
@@ -4714,6 +4720,7 @@ begin
     gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
     gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
     gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+    gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
   end;
 
   if nPlayers >= 2 then
@@ -4732,6 +4739,7 @@ begin
     gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
     gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
     gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
+    gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
   end;
 
   g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
@@ -4913,6 +4921,7 @@ begin
           gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
           gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
           gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+          gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
           gPlayer1.UID := NetPlrUID1;
           gPlayer1.Reset(True);
 
@@ -5969,6 +5978,16 @@ begin
         if (Length(P) = 2) then
           gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
         end;
+    'p1_skip_fist':
+      begin
+        if (Length(P) = 2) then
+          gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
+        end;
+    'p2_skip_fist':
+      begin
+        if (Length(P) = 2) then
+          gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
+        end;
     'p1_priority_kastet':
       begin
         if (Length(P) = 2) then
index 131bd61dbe99ad7cc75e9d6f5f729598cfa33e36..c2de375deaf88166be14862fbc51a2726a157e80 100644 (file)
@@ -1272,7 +1272,7 @@ const
     ('MENU KASTET ALLOW',              'Switch to fist',
                                        'Âûáèðàòü êàñòåò'),
     ('MENU KASTET ALLOW BERSERK',      'Only with berserk',
-                                       'Åñòü áåðñåðê'),
+                                       'Òîëüêî ñ áåðñåðêîì'),
     ('MENU KASTET ALLOW ALWAYS',       'Always',
                                        'Âñåãäà'),
     ('MENU WEAPON PRIORITY PLAYER 1',  'Player 1 Priority',
index 69cd445cb09fbb797432559356de6e25b25b7b74..6f351683332b19aa23e217808de3688ff572db48 100644 (file)
@@ -357,8 +357,8 @@ begin
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1WeaponMenu').GetControl('mOptionsPlayersP1WeaponMenu'));
   gPlayer1Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
   gPlayer1Settings.SwitchToEmpty := TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex;
-
-
+  gPlayer1Settings.SkipFist := TGUISwitch(menu.GetControl('swWeaponAllowFist')).ItemIndex;
+  
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP1WeaponMenu').GetControl('mOptionsPreferencesP1WeaponMenu'));
   with menu do
   begin
@@ -371,6 +371,7 @@ begin
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP2WeaponMenu').GetControl('mOptionsPlayersP2WeaponMenu'));
   gPlayer2Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
   gPlayer2Settings.SwitchToEmpty := TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex;
+  gPlayer2Settings.SkipFist := TGUISwitch(menu.GetControl('swWeaponAllowFist')).ItemIndex;
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP2WeaponMenu').GetControl('mOptionsPreferencesP2WeaponMenu'));
   with menu do
   begin
@@ -409,6 +410,7 @@ begin
       if (gPlayer1.WeapSwitchMode = 2) then
         gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
       gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
+      gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
       if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
     end;
 
@@ -425,6 +427,7 @@ begin
       if (gPlayer2.WeapSwitchMode = 2) then
         gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
       gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
+      gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
     end;
   end;
 
@@ -656,7 +659,7 @@ begin
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1WeaponMenu').GetControl('mOptionsPlayersP1WeaponMenu'));
   TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex := gPlayer1Settings.WeaponSwitch;
   TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex := gPlayer1Settings.SwitchToEmpty;
-
+  TGUISwitch(menu.GetControl('swWeaponAllowFist')).ItemIndex := gPlayer1Settings.SkipFist;
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP1WeaponMenu').GetControl('mOptionsPreferencesP1WeaponMenu'));
   for i := WP_FIRST to WP_LAST+1 do
   begin
@@ -667,6 +670,7 @@ begin
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP2WeaponMenu').GetControl('mOptionsPlayersP2WeaponMenu'));
   TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex := gPlayer2Settings.WeaponSwitch;
   TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex := gPlayer2Settings.SwitchToEmpty;
+  TGUISwitch(menu.GetControl('swWeaponAllowFist')).ItemIndex := gPlayer2Settings.SkipFist;
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP2WeaponMenu').GetControl('mOptionsPreferencesP2WeaponMenu'));
   for i := WP_FIRST to WP_LAST+1 do
   begin
@@ -3288,6 +3292,12 @@ begin
       AddItem(_lc[I_MENU_YES]);
       AddItem(_lc[I_MENU_NO]);
     end;
+    with AddSwitch(_lc[I_MENU_KASTET_ALLOW]) do
+    begin
+      Name := 'swWeaponAllowFist';
+      AddItem(_lc[I_MENU_KASTET_ALLOW_ALWAYS]);
+      AddItem(_lc[I_MENU_KASTET_ALLOW_BERSERK]);
+    end;
     AddButton(@ProcOptionsPlayerP1WeaponPreferencesMenu, _lc[I_MENU_WEAPON_SWITCH_PRIORITY]);
     ReAlign();
   end;
@@ -3341,6 +3351,12 @@ begin
       AddItem(_lc[I_MENU_YES]);
       AddItem(_lc[I_MENU_NO]);
     end;
+    with AddSwitch(_lc[I_MENU_KASTET_ALLOW]) do
+    begin
+      Name := 'swWeaponAllowFist';
+      AddItem(_lc[I_MENU_KASTET_ALLOW_ALWAYS]);
+      AddItem(_lc[I_MENU_KASTET_ALLOW_BERSERK]);
+    end;
     AddButton(@ProcOptionsPlayerP2WeaponPreferencesMenu, _lc[I_MENU_WEAPON_SWITCH_PRIORITY]);
     ReAlign();
   end;
index 55b99b3705acbc0ddbe05e00b04ba3657ea2c9fd..910a480a78d25b4073593853012ef1a7d8e6a5b4 100644 (file)
@@ -383,6 +383,7 @@ var
   WeapSwitch: Byte;
   TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
   SwitchEmpty: Byte;
+  SkipF: Byte;
   PID: Word;
   Color: TRGB;
   I: Integer;
@@ -403,6 +404,7 @@ begin
       for I := WP_FIRST to WP_LAST + 1 do
         TmpPrefArray[I] := M.ReadByte();
     SwitchEmpty := M.ReadByte();
+    SkipF := M.ReadByte();
   except
     Err := True;
   end;
@@ -462,6 +464,7 @@ begin
     if (WeapSwitch = 2) then
       SetWeaponPrefs(TmpPrefArray);
     SwitchToEmpty := SwitchEmpty;
+    SkipFist := SkipF;
     Reset(True);
   end;
 
@@ -715,6 +718,7 @@ var
   TmpWeapSwitch: Byte;
   TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
   TmpSwEmpty: Byte;
+  TmpSkipF: Byte;
   I: Integer;
   Pl: TPlayer;
   Err: Boolean;
@@ -732,6 +736,7 @@ begin
       for I := WP_FIRST to WP_LAST + 1 do
         TmpPrefArray[I] := M.ReadByte();
     TmpSwEmpty := M.ReadByte();
+    TmpSkipF := M.ReadByte();
   except
     Err := True;
   end;
@@ -763,6 +768,10 @@ begin
 
   if (TmpSwEmpty <> Pl.SwitchToEmpty) then
     Pl.SwitchToEmpty := TmpSwEmpty;
+
+  if (TmpSkipF <> Pl.SkipFist) then
+    Pl.SkipFist := TmpSkipF;
+
   MH_SEND_PlayerSettings(Pl.UID, TmpModel);
 end;
 
@@ -3159,6 +3168,7 @@ begin
     for i := WP_FIRST to WP_LAST + 1 do
       NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
   NetOut.Write(gPlayer1Settings.SwitchToEmpty);
+  NetOut.Write(gPlayer1Settings.SkipFist);
 
   g_Net_Client_Send(True, NET_CHAN_SERVICE);
 end;
@@ -3312,6 +3322,8 @@ begin
     for i := WP_FIRST to WP_LAST + 1 do
       NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
   NetOut.Write(gPlayer1Settings.SwitchToEmpty);
+  NetOut.Write(gPlayer1Settings.SkipFist);
+
   g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
 end;
 
index 8ad8931e32ddaff68a1ac89b57e1431003da9464..8f4331079506d89ee91e6c0b00d13701ad8c5153 100644 (file)
@@ -261,6 +261,7 @@ type
     FWeapSwitchMode: Byte;
     FWeapPreferences: Array [WP_FIRST .. WP_LAST+1] of Byte;
     FSwitchToEmpty: Byte;
+    FSkipFist: Byte;
     FColor:     TRGB;
     FPreferredTeam: Byte;
     FSpectator: Boolean;
@@ -304,6 +305,7 @@ type
     procedure   SetWeaponPref(Weapon, Pref: Byte);
     function    GetWeaponPref(Weapon: Byte) : Byte;
     function    GetMorePrefered() : Byte;
+    function    MaySwitch(Weapon: Byte) : Boolean;
     function    Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
     function    Collide(Panel: TPanel): Boolean; overload;
     function    Collide(X, Y: Integer): Boolean; overload;
@@ -385,6 +387,7 @@ type
     property    CurrWeap: Byte read FCurrWeap write FCurrWeap;
     property    WeapSwitchMode: Byte read FWeapSwitchMode write FWeapSwitchMode;
     property    SwitchToEmpty: Byte read FSwitchToEmpty write FSwitchToEmpty;
+    property    SkipFist: Byte read FSkipFist write FSkipFist;
     property    MonsterKills: Integer read FMonsterKills write FMonsterKills;
     property    Secrets: Integer read FSecrets;
     property    GodMode: Boolean read FGodMode write FGodMode;
@@ -2036,6 +2039,16 @@ begin
   result := testedWeap;
 end;
 
+function TPlayer.maySwitch(Weapon: Byte) : Boolean;
+begin
+  result := true;
+  if (Weapon = WEAPON_KASTET) and (FSkipFist <> 0) then
+    if (FSkipFist = 1) and (not (R_BERSERK in FRulez)) then
+      result := false
+  else if (FSwitchToEmpty = 0) and not hasAmmoForWeapon(Weapon) then
+    result := false
+end;
+
 procedure TPlayer.SwitchTeam;
 begin
   if g_Game_IsClient then
@@ -3809,7 +3822,7 @@ begin
     for i := 0 to High(FWeapon) do
     begin
       cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
-      if FWeapon[cwi] and ((FSwitchToEmpty = 1) or hasAmmoForWeapon(cwi))  then
+      if FWeapon[cwi] and maySwitch(cwi)  then
       begin
         //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
         result := Byte(cwi);