From: travi$ Date: Sat, 26 Mar 2022 17:41:05 +0000 (+0300) Subject: Add option to skip fist switching X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=3bc93c7ecd534237343aaa3b83dca053c53b9bc5;p=d2df-sdl.git Add option to skip fist switching --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 35778ef..87a1fba 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -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); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5f7674f..7e30028 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -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 diff --git a/src/game/g_language.pas b/src/game/g_language.pas index 131bd61..c2de375 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -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', diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 69cd445..6f35168 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -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; diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 55b99b3..910a480 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -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; diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 8ad8931..8f43310 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -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);