From: fgsfds Date: Tue, 1 Aug 2017 15:05:14 +0000 (+0300) Subject: add direct weapon switching X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=7cd1c130359bef86087eaefe317526775e8ad4f8;p=d2df-sdl.git add direct weapon switching --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 6a11291..c3f4b58 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1233,6 +1233,7 @@ procedure processPlayerControls (plr: TPlayer; var ctrl: TPlayerControl; var Mov var time: Word; strafeDir: Byte; + i: Integer; begin if (plr = nil) then exit; if (p2hack) then time := 1000 else time := 1; @@ -1279,6 +1280,13 @@ begin if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then plr.PressKey(KEY_NEXTWEAPON); if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then plr.PressKey(KEY_PREVWEAPON); if isKeyPressed(KeyOpen, KeyOpen2) then plr.PressKey(KEY_OPEN); + + for i := 0 to High(KeyWeapon) do + if isKeyPressed(KeyWeapon[i], KeyWeapon2[i]) then + begin + plr.ForceWeapon(i); + Break; + end; end; end; diff --git a/src/game/g_language.pas b/src/game/g_language.pas index d340408..5f73c2d 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -101,6 +101,17 @@ type I_GAME_CHEAT_AIMLINE, I_GAME_CHEAT_AUTOMAP, + I_GAME_WEAPON0, + I_GAME_WEAPON1, + I_GAME_WEAPON2, + I_GAME_WEAPON3, + I_GAME_WEAPON4, + I_GAME_WEAPON5, + I_GAME_WEAPON6, + I_GAME_WEAPON7, + I_GAME_WEAPON8, + I_GAME_WEAPON9, + I_MENU_START_GAME, I_MENU_MAIN_MENU, I_MENU_NEW_GAME, @@ -185,6 +196,8 @@ type I_MENU_PLAYER_2, I_MENU_PLAYER_1_ALT, I_MENU_PLAYER_2_ALT, + I_MENU_PLAYER_1_WEAPONS, + I_MENU_PLAYER_2_WEAPONS, I_MENU_CONTROL_JOYSTICKS, I_MENU_CONTROL_DEADZONE, @@ -756,6 +769,27 @@ const ('GAME CHEAT AUTOMAP', 'ID2DT', 'ID2DT'), + ('GAME WEAPON0', 'Fist', + 'Êàñòåò'), + ('GAME WEAPON1', 'Chainsaw', + 'Áåíçîïèëà'), + ('GAME WEAPON2', 'Pistol', + 'Ïèñòîëåò'), + ('GAME WEAPON3', 'Shotgun', + 'Äðîáîâèê'), + ('GAME WEAPON4', 'Super Shotgun', + 'Äâóñòâîëêà'), + ('GAME WEAPON5', 'Chaingun', + 'Ïóëåìåò'), + ('GAME WEAPON6', 'Rocket Launcher', + 'Ðàêåòíèöà'), + ('GAME WEAPON7', 'Plasma Gun', + 'Ïëàçìàãàí'), + ('GAME WEAPON8', 'BFG9000', + 'BFG9000'), + ('GAME WEAPON9', 'Super Chaingun', + 'Ñóïåðïóëåìåò'), + ('MENU START GAME', 'Start Game', 'ÍÀ×ÀÒÜ ÈÃÐÓ'), ('MENU MAIN MENU', 'Menu', @@ -916,10 +950,14 @@ const 'Ïåðâûé èãðîê, êëàâèàòóðà'), ('MENU PLAYER 2', 'Player 2 KEYBOARD', 'Âòîðîé èãðîê, êëàâèàòóðà'), - ('MENU PLAYER 1 ALT', 'Player 1 GAMEPAD', - 'Ïåðâûé èãðîê GAMEPAD'), - ('MENU PLAYER 2 ALT', 'Player 2 GAMEPAD', - 'Âòîðîé èãðîê GAMEPAD'), + ('MENU PLAYER 1 ALT', 'Player 1, GAMEPAD', + 'Ïåðâûé èãðîê, GAMEPAD'), + ('MENU PLAYER 2 ALT', 'Player 2, GAMEPAD', + 'Âòîðîé èãðîê, GAMEPAD'), + ('MENU PLAYER 1 WEAPONS', 'Player 1, Weapons', + 'Ïåðâûé èãðîê, îðóæèå'), + ('MENU PLAYER 2 WEAPONS', 'Player 2, Weapons', + 'Âòîðîé èãðîê, îðóæèå'), ('MENU CONTROL JOYSTICKS', 'Joystick Settings', 'Íàñòðîéêè äæîéñòèêîâ'), diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 5cd389b..2f216ff 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -192,6 +192,13 @@ begin KeyStrafe2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key; end; + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP1MenuWeapons').GetControl('mOptionsControlsP1MenuWeapons')); + with menu, gGameControls.P1Control do + begin + for i := 0 to 9 do + KeyWeapon[i] := TGUIKeyRead(GetControl(_lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)])).Key; + end; + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP2Menu').GetControl('mOptionsControlsP2Menu')); with menu, gGameControls.P2Control do begin @@ -221,6 +228,13 @@ begin KeyStrafe2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key; end; + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP2MenuWeapons').GetControl('mOptionsControlsP2MenuWeapons')); + with menu, gGameControls.P2Control do + begin + for i := 0 to 9 do + KeyWeapon[i] := TGUIKeyRead(GetControl(_lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)])).Key; + end; + if e_JoysticksAvailable > 0 then begin menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsJoystickMenu').GetControl('mOptionsControlsJoystickMenu')); @@ -2602,8 +2616,10 @@ begin AddSpace(); AddButton(nil, _lc[I_MENU_PLAYER_1], 'OptionsControlsP1Menu'); AddButton(nil, _lc[I_MENU_PLAYER_1_ALT], 'OptionsControlsP1MenuAlt'); + AddButton(nil, _lc[I_MENU_PLAYER_1_WEAPONS], 'OptionsControlsP1MenuWeapons'); AddButton(nil, _lc[I_MENU_PLAYER_2], 'OptionsControlsP2Menu'); AddButton(nil, _lc[I_MENU_PLAYER_2_ALT], 'OptionsControlsP2MenuAlt'); + AddButton(nil, _lc[I_MENU_PLAYER_2_WEAPONS], 'OptionsControlsP2MenuWeapons'); AddSpace(); if e_JoysticksAvailable <> 0 then AddButton(nil, _lc[I_MENU_CONTROL_JOYSTICKS], 'OptionsControlsJoystickMenu'); @@ -2629,7 +2645,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('OptionsControlsP1MenuAlt'); - with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_1]))) do + with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_1_ALT]))) do begin Name := 'mOptionsControlsP1MenuAlt'; AddKeyRead(_lc[I_MENU_CONTROL_LEFT]).Name := _lc[I_MENU_CONTROL_LEFT]; @@ -2646,6 +2662,17 @@ begin Menu.DefControl := 'mOptionsControlsP1MenuAlt'; g_GUI_AddWindow(Menu); + Menu := TGUIWindow.Create('OptionsControlsP1MenuWeapons'); + with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_1_WEAPONS]))) do + begin + Name := 'mOptionsControlsP1MenuWeapons'; + for i := 0 to 9 do + AddKeyRead(_lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)]).Name := + _lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)]; + end; + Menu.DefControl := 'mOptionsControlsP1MenuWeapons'; + g_GUI_AddWindow(Menu); + Menu := TGUIWindow.Create('OptionsControlsP2Menu'); with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_2]))) do begin @@ -2664,7 +2691,7 @@ begin g_GUI_AddWindow(Menu); Menu := TGUIWindow.Create('OptionsControlsP2MenuAlt'); - with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_2]))) do + with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_2_ALT]))) do begin Name := 'mOptionsControlsP2MenuAlt'; AddKeyRead(_lc[I_MENU_CONTROL_LEFT]).Name := _lc[I_MENU_CONTROL_LEFT]; @@ -2681,6 +2708,18 @@ begin Menu.DefControl := 'mOptionsControlsP2MenuAlt'; g_GUI_AddWindow(Menu); + + Menu := TGUIWindow.Create('OptionsControlsP2MenuWeapons'); + with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_2_WEAPONS]))) do + begin + Name := 'mOptionsControlsP2MenuWeapons'; + for i := 0 to 9 do + AddKeyRead(_lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)]).Name := + _lc[TStrings_Locale(Cardinal(I_GAME_WEAPON0) + i)]; + end; + Menu.DefControl := 'mOptionsControlsP2MenuWeapons'; + g_GUI_AddWindow(Menu); + Menu := TGUIWindow.Create('OptionsControlsJoystickMenu'); with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_CONTROL_JOYSTICKS]))) do begin diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index 64377a6..abc65a0 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -430,7 +430,7 @@ end; function MH_RECV_PlayerPos(C: pTNetClient; P: Pointer): Word; var - Dir: Byte; + Dir, WeaponSelect: Byte; PID: Word; kByte: Word; Pl: TPlayer; @@ -452,8 +452,10 @@ begin NetTime := GT; kByte := e_Raw_Read_Word(P); Dir := e_Raw_Read_Byte(P); + WeaponSelect := e_Raw_Read_Byte(P); if Direction <> TDirection(Dir) then JustTeleported := False; + SetDirection(TDirection(Dir)); ReleaseKeys; @@ -472,6 +474,9 @@ begin if LongBool(kByte and NET_KEY_OPEN) then PressKey(KEY_OPEN, 10000); if LongBool(kByte and NET_KEY_NW) then PressKey(KEY_NEXTWEAPON, 10000); if LongBool(kByte and NET_KEY_PW) then PressKey(KEY_PREVWEAPON, 10000); + + if WeaponSelect <> 255 then + ForceWeapon(WeaponSelect); end; // MH_SEND_PlayerPos(False, PID, C^.ID); @@ -2782,6 +2787,8 @@ var kByte: Word; Predict: Boolean; strafeDir: Byte; + WeaponSelect: Byte = 255; + I: Integer; begin if not gGameOn then Exit; if gPlayers = nil then Exit; @@ -2846,6 +2853,9 @@ begin if isKeyPressed(KeyOpen, KeyOpen2) then kByte := kByte or NET_KEY_OPEN; if isKeyPressed(KeyNextWeapon, KeyNextWeapon2) then kByte := kByte or NET_KEY_NW; if isKeyPressed(KeyPrevWeapon, KeyPrevWeapon2) then kByte := kByte or NET_KEY_PW; + for I := 0 to High(KeyWeapon) do + if isKeyPressed(KeyWeapon[I], KeyWeapon2[I]) then + WeaponSelect := I; end; // fix movebutton state P1MoveButton := P1MoveButton or (strafeDir shl 4); @@ -2857,6 +2867,7 @@ begin e_Buffer_Write(@NetOut, gTime); e_Buffer_Write(@NetOut, kByte); e_Buffer_Write(@NetOut, Byte(gPlayer1.Direction)); + e_Buffer_Write(@NetOut, WeaponSelect); g_Net_Client_Send(True, NET_CHAN_PLAYERPOS); //kBytePrev := kByte; diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 2ad3e6e..5caaf40 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -33,6 +33,7 @@ type KeyPrevWeapon: Word; KeyOpen: Word; KeyStrafe: Word; + KeyWeapon: array [0..9] of Word; KeyRight2: Word; KeyLeft2: Word; @@ -44,6 +45,7 @@ type KeyPrevWeapon2: Word; KeyOpen2: Word; KeyStrafe2: Word; + KeyWeapon2: array [0..9] of Word; end; TGameControls = record @@ -178,6 +180,8 @@ begin KeyPrevWeapon := 71; KeyOpen := 54; KeyStrafe := 0; + for i := 0 to High(KeyWeapon) do + KeyWeapon[i] := 0; KeyRight2 := 0; KeyLeft2 := 0; @@ -189,6 +193,8 @@ begin KeyPrevWeapon2 := 0; KeyOpen2 := 0; KeyStrafe2 := 0; + for i := 0 to High(KeyWeapon2) do + KeyWeapon2[i] := 0; end; with gGameControls.P2Control do @@ -203,6 +209,8 @@ begin KeyPrevWeapon := 17; KeyOpen := 58; KeyStrafe := 0; + for i := 0 to High(KeyWeapon) do + KeyWeapon[i] := 0; KeyRight2 := 0; KeyLeft2 := 0; @@ -214,6 +222,8 @@ begin KeyPrevWeapon2 := 0; KeyOpen2 := 0; KeyStrafe2 := 0; + for i := 0 to High(KeyWeapon2) do + KeyWeapon2[i] := 0; end; with gPlayer1Settings do @@ -321,6 +331,8 @@ begin KeyPrevWeapon := ReadInt('Player1', 'KeyPrevWeapon', 17); KeyOpen := ReadInt('Player1', 'KeyOpen', 58); KeyStrafe := ReadInt('Player1', 'KeyStrafe', 0); + for i := 0 to High(KeyWeapon) do + KeyWeapon[i] := ReadInt('Player1', 'KeyWeapon' + IntToStr(i), 0); KeyRight2 := ReadInt('Player1', 'KeyRight2', 0); KeyLeft2 := ReadInt('Player1', 'KeyLeft2', 0); @@ -332,6 +344,8 @@ begin KeyPrevWeapon2 := ReadInt('Player1', 'KeyPrevWeapon2', 0); KeyOpen2 := ReadInt('Player1', 'KeyOpen2', 0); KeyStrafe2 := ReadInt('Player1', 'KeyStrafe2', 0); + for i := 0 to High(KeyWeapon2) do + KeyWeapon2[i] := ReadInt('Player1', 'KeyWeapon2' + IntToStr(i), 0); end; with gPlayer1Settings, config do @@ -358,6 +372,8 @@ begin KeyPrevWeapon := ReadInt('Player2', 'KeyPrevWeapon', 71); KeyOpen := ReadInt('Player2', 'KeyOpen', 54); KeyStrafe := ReadInt('Player2', 'KeyStrafe', 0); + for i := 0 to High(KeyWeapon) do + KeyWeapon[i] := ReadInt('Player2', 'KeyWeapon' + IntToStr(i), 0); KeyRight2 := ReadInt('Player2', 'KeyRight2', 0); KeyLeft2 := ReadInt('Player2', 'KeyLeft2', 0); @@ -369,6 +385,8 @@ begin KeyPrevWeapon2 := ReadInt('Player2', 'KeyPrevWeapon2', 0); KeyOpen2 := ReadInt('Player2', 'KeyOpen2', 0); KeyStrafe2 := ReadInt('Player2', 'KeyStrafe2', 0); + for i := 0 to High(KeyWeapon2) do + KeyWeapon2[i] := ReadInt('Player2', 'KeyWeapon2' + IntToStr(i), 0); end; with gPlayer2Settings, config do @@ -561,6 +579,8 @@ begin WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon); WriteInt('Player1', 'KeyOpen', KeyOpen); WriteInt('Player1', 'KeyStrafe', KeyStrafe); + for i := 0 to High(KeyWeapon) do + WriteInt('Player1', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]); WriteInt('Player1', 'KeyRight2', KeyRight2); WriteInt('Player1', 'KeyLeft2', KeyLeft2); @@ -572,6 +592,8 @@ begin WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2); WriteInt('Player1', 'KeyOpen2', KeyOpen2); WriteInt('Player1', 'KeyStrafe2', KeyStrafe2); + for i := 0 to High(KeyWeapon2) do + WriteInt('Player1', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]); WriteStr('Player1', 'Name', Name); WriteStr('Player1', 'model', Model); @@ -593,6 +615,8 @@ begin WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon); WriteInt('Player2', 'KeyOpen', KeyOpen); WriteInt('Player2', 'KeyStrafe', KeyStrafe); + for i := 0 to High(KeyWeapon) do + WriteInt('Player2', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]); WriteInt('Player2', 'KeyRight2', KeyRight2); WriteInt('Player2', 'KeyLeft2', KeyLeft2); @@ -604,6 +628,8 @@ begin WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2); WriteInt('Player2', 'KeyOpen2', KeyOpen2); WriteInt('Player2', 'KeyStrafe2', KeyStrafe2); + for i := 0 to High(KeyWeapon2) do + WriteInt('Player2', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]); WriteStr('Player2', 'Name', Name); WriteStr('Player2', 'model', Model); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index f2a98ff..caddc0d 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -287,6 +287,7 @@ type procedure NetFire(Wpn: Byte; X, Y, AX, AY: Integer; WID: Integer = -1); procedure DoLerp(Level: Integer = 2); procedure SetLerp(XTo, YTo: Integer); + procedure ForceWeapon(Weapon: Byte); procedure JetpackOn; procedure JetpackOff; @@ -3250,6 +3251,30 @@ begin 150, 0, 0); end; +procedure TPlayer.ForceWeapon(Weapon: Byte); +var + i: Byte; +begin + if g_Game_IsClient then Exit; + if Weapon > High(FWeapon) then Exit; + if FBFGFireCounter <> -1 then Exit; + + if FTime[T_SWITCH] > gTime then Exit; + + for i := WEAPON_KASTET to WEAPON_SUPERPULEMET do + if FReloading[i] > 0 then Exit; + + if FWeapon[Weapon] then + begin + FCurrWeap := Weapon; + FTime[T_SWITCH] := gTime+156; + if FCurrWeap = WEAPON_SAW then + FSawSoundSelect.PlayAt(FObj.X, FObj.Y); + FModel.SetWeapon(FCurrWeap); + if g_Game_IsNet then MH_SEND_PlayerStats(FUID); + end; +end; + procedure TPlayer.NextWeapon(); var i: Byte;