summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ee6a478)
raw | patch | inline | side by side (parent: ee6a478)
author | Dmitry Lyashuk <terminalhash@th-mx> | |
Sat, 26 Mar 2022 14:20:22 +0000 (17:20 +0300) | ||
committer | Dmitry Lyashuk <terminalhash@th-mx> | |
Sat, 26 Mar 2022 14:20:22 +0000 (17:20 +0300) |
diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index 8c0c41e0e22cb6282cb669e07e665a214f03a065..b4b67ffb01bb729f2cea7b3cdba867684e8d6d62 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
AddCommand('p1_team', PlayerSettingsCVars);
AddCommand('p2_team', PlayerSettingsCVars);
AddCommand('p1_autoswitch', PlayerSettingsCVars);
- AddCommand('p2_autoswitch', PlayerSettingsCVars);
+ AddCommand('p2_autoswitch', PlayerSettingsCVars);
+ AddCommand('p1_switch_empty', PlayerSettingsCVars);
+ AddCommand('p2_switch_empty', PlayerSettingsCVars);
AddCommand('p1_priority_kastet', PlayerSettingsCVars);
- AddCommand('p2_priority_kastet', PlayerSettingsCVars);
+ AddCommand('p2_priority_kastet', PlayerSettingsCVars);
AddCommand('p1_priority_saw', PlayerSettingsCVars);
AddCommand('p2_priority_saw', PlayerSettingsCVars);
AddCommand('p1_priority_pistol', PlayerSettingsCVars);
WriteLn(f, 'p1_model ', QuoteStr(Model));
WriteLn(f, 'p1_team ', FormatTeam(Team));
WriteLn(f, 'p1_autoswitch ', WeaponSwitch);
- WriteLn(f, 'p1_priority_kastet ', Max(0, WeaponPreferences[WEAPON_KASTET]));
+ WriteLn(f, 'p1_switch_empty ', SwitchToEmpty);
+ WriteLn(f, 'p1_priority_kastet ', Max(0, WeaponPreferences[WEAPON_KASTET]));
WriteLn(f, 'p1_priority_saw ', Max(0, WeaponPreferences[WEAPON_SAW]));
- WriteLn(f, 'p1_priority_pistol ', Max(0, WeaponPreferences[WEAPON_PISTOL]));
+ WriteLn(f, 'p1_priority_pistol ', Max(0, WeaponPreferences[WEAPON_PISTOL]));
WriteLn(f, 'p1_priority_shotgun1 ', Max(0, WeaponPreferences[WEAPON_SHOTGUN1]));
WriteLn(f, 'p1_priority_shotgun2 ', Max(0, WeaponPreferences[WEAPON_SHOTGUN2] ));
WriteLn(f, 'p1_priority_chaingun ', Max(0, WeaponPreferences[WEAPON_CHAINGUN]));
WriteLn(f, 'p2_model ', QuoteStr(Model));
WriteLn(f, 'p2_team ', FormatTeam(Team));
WriteLn(f, 'p2_autoswitch ', WeaponSwitch);
- WriteLn(f, 'p2_priority_kastet ', Max(0, WeaponPreferences[WEAPON_KASTET]));
+ WriteLn(f, 'p2_switch_empty ', SwitchToEmpty);
+ WriteLn(f, 'p2_priority_kastet ', Max(0, WeaponPreferences[WEAPON_KASTET]));
WriteLn(f, 'p2_priority_saw ', Max(0, WeaponPreferences[WEAPON_SAW]));
WriteLn(f, 'p2_priority_pistol ', Max(0, WeaponPreferences[WEAPON_PISTOL]));
WriteLn(f, 'p2_priority_shotgun1 ', Max(0, WeaponPreferences[WEAPON_SHOTGUN1]));
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 7674db9b76dc9cf841172af8daa03b5ae4b466b2..f85024b31b0c05a68e9947476e3180b36d12469f 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
Model: String;
Color: TRGB;
Team: Byte;
+ // ones below are sent only to the server
WeaponSwitch: Byte;
WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
+ SwitchToEmpty: Byte;
+ SwitchToFist: Byte;
end;
TMegaWADInfo = record
else
begin
gPlayer1.Name := gPlayer1Settings.Name;
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
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);
else
begin
gPlayer2.Name := gPlayer2Settings.Name;
+ gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
+ gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
+ gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
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);
end;
gPlayer1.Name := gPlayer1Settings.Name;
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
nPl := 1;
// Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
end;
gPlayer2.Name := gPlayer2Settings.Name;
+ gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
+ gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
+ gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
Inc(nPl);
end;
end;
gPlayer1.Name := gPlayer1Settings.Name;
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
Inc(nPl);
end;
end;
gPlayer2.Name := gPlayer2Settings.Name;
+ gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
+ gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
+ gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
Inc(nPl);
end;
end;
gPlayer1.Name := gPlayer1Settings.Name;
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
end;
if nPlayers >= 2 then
end;
gPlayer2.Name := gPlayer2Settings.Name;
+ gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
+ gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
+ gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
end;
g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
end;
gPlayer1.Name := gPlayer1Settings.Name;
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
gPlayer1.UID := NetPlrUID1;
gPlayer1.Reset(True);
if (Length(P) = 2) then
gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
end;
+ 'p1_switch_empty':
+ begin
+ if (Length(P) = 2) then
+ gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
+ end;
+ 'p2_switch_empty':
+ begin
+ if (Length(P) = 2) then
+ gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
+ end;
'p1_priority_kastet':
begin
if (Length(P) = 2) then
index 900ae427022bae92ab866a6f14c0b6cbbcfe234e..131bd61dbe99ad7cc75e9d6f5f729598cfa33e36 100644 (file)
--- a/src/game/g_language.pas
+++ b/src/game/g_language.pas
I_MENU_WEAPON_SWITCH_LINEAR,
I_MENU_WEAPON_SWITCH_PREFERENCE,
I_MENU_WEAPON_SWITCH_PRIORITY,
+ I_MENU_WEAPON_ALLOW_EMPTY,
+ I_MENU_KASTET_ALLOW,
+ I_MENU_KASTET_ALLOW_BERSERK,
+ I_MENU_KASTET_ALLOW_ALWAYS,
I_MENU_WEAPON_PRIORITY_PLAYER_1,
I_MENU_WEAPON_PRIORITY_PLAYER_2,
'Ïî ïðèîðèòåòó'),
('MENU WEAPON SWITCH PRIORITY', 'Weapon priority',
'Ïðèîðèòåòíîñòü îðóæèÿ'),
+ ('MENU WEAPON ALLOW EMPTY', 'Skip empty weapons',
+ 'Ïðîïóñêàòü ïóñòîå îðóæèå'),
+ ('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',
'Ïðèîðèòåò îðóæèÿ (1)'),
('MENU WEAPON PRIORITY PLAYER 2', 'Player 2 Priority',
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index 2f6ce09122ea1f2daa5bb42d879b57949bd9fe90..69cd445cb09fbb797432559356de6e25b25b7b74 100644 (file)
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
end;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1WeaponMenu').GetControl('mOptionsPlayersP1WeaponMenu'));
- gPlayer1Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
+ gPlayer1Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
+ gPlayer1Settings.SwitchToEmpty := TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex;
+
menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP1WeaponMenu').GetControl('mOptionsPreferencesP1WeaponMenu'));
with menu do
end;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP2WeaponMenu').GetControl('mOptionsPlayersP2WeaponMenu'));
- gPlayer2Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
-
+ gPlayer2Settings.WeaponSwitch := TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex;
+ gPlayer2Settings.SwitchToEmpty := TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP2WeaponMenu').GetControl('mOptionsPreferencesP2WeaponMenu'));
with menu do
begin
else
if gPlayer1.Team <> gPlayer1Settings.Team then
gPlayer1.SwitchTeam;
-
+ gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
+ if (gPlayer1.WeapSwitchMode = 2) then
+ gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
+ gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
end;
else
if gPlayer2.Team <> gPlayer2Settings.Team then
gPlayer2.SwitchTeam;
+ gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
+ if (gPlayer2.WeapSwitchMode = 2) then
+ gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
+ gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
end;
end;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1WeaponMenu').GetControl('mOptionsPlayersP1WeaponMenu'));
TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex := gPlayer1Settings.WeaponSwitch;
+ TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex := gPlayer1Settings.SwitchToEmpty;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP1WeaponMenu').GetControl('mOptionsPreferencesP1WeaponMenu'));
for i := WP_FIRST to WP_LAST+1 do
menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP2WeaponMenu').GetControl('mOptionsPlayersP2WeaponMenu'));
TGUISwitch(menu.GetControl('swWeaponAutoswitch')).ItemIndex := gPlayer2Settings.WeaponSwitch;
-
+ TGUISwitch(menu.GetControl('swWeaponAllowEmpty')).ItemIndex := gPlayer2Settings.SwitchToEmpty;
menu := TGUIMenu(g_GUI_GetWindow('OptionsPreferencesP2WeaponMenu').GetControl('mOptionsPreferencesP2WeaponMenu'));
for i := WP_FIRST to WP_LAST+1 do
begin
AddItem(_lc[I_MENU_WEAPON_SWITCH_LINEAR]);
AddItem(_lc[I_MENU_WEAPON_SWITCH_PREFERENCE]);
end;
+ with AddSwitch(_lc[I_MENU_WEAPON_ALLOW_EMPTY]) do
+ begin
+ Name := 'swWeaponAllowEmpty';
+ AddItem(_lc[I_MENU_YES]);
+ AddItem(_lc[I_MENU_NO]);
+ end;
AddButton(@ProcOptionsPlayerP1WeaponPreferencesMenu, _lc[I_MENU_WEAPON_SWITCH_PRIORITY]);
ReAlign();
end;
AddItem(_lc[I_MENU_WEAPON_SWITCH_LINEAR]);
AddItem(_lc[I_MENU_WEAPON_SWITCH_PREFERENCE]);
end;
+ with AddSwitch(_lc[I_MENU_WEAPON_ALLOW_EMPTY]) do
+ begin
+ Name := 'swWeaponAllowEmpty';
+ AddItem(_lc[I_MENU_YES]);
+ AddItem(_lc[I_MENU_NO]);
+ end;
AddButton(@ProcOptionsPlayerP2WeaponPreferencesMenu, _lc[I_MENU_WEAPON_SWITCH_PRIORITY]);
ReAlign();
end;
diff --git a/src/game/g_net.pas b/src/game/g_net.pas
index 27825c263cf738da7301a6454a7b629d9ff8bc10..edd6024a49af09237130e98d105a0d3d0948efb9 100644 (file)
--- a/src/game/g_net.pas
+++ b/src/game/g_net.pas
e_log, e_msg, utils, ENet, Classes, md5, MAPDEF{$IFDEF USE_MINIUPNPC}, miniupnpc;{$ELSE};{$ENDIF}
const
- NET_PROTOCOL_VER = 187;
+ NET_PROTOCOL_VER = 188;
NET_MAXCLIENTS = 24;
NET_CHANS = 12;
diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas
index b7a0fdd903cc0fa4c4a1e6bae0f2a2ec333fc8f2..55b99b3705acbc0ddbe05e00b04ba3657ea2c9fd 100644 (file)
--- a/src/game/g_netmsg.pas
+++ b/src/game/g_netmsg.pas
var
Ver, PName, Model, Pw: string;
R, G, B, T: Byte;
+ WeapSwitch: Byte;
+ TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+ SwitchEmpty: Byte;
PID: Word;
Color: TRGB;
I: Integer;
G := M.ReadByte();
B := M.ReadByte();
T := M.ReadByte();
+ WeapSwitch := M.ReadByte();
+ if (WeapSwitch = 2) then
+ for I := WP_FIRST to WP_LAST + 1 do
+ TmpPrefArray[I] := M.ReadByte();
+ SwitchEmpty := M.ReadByte();
except
Err := True;
end;
with g_Player_Get(PID) do
begin
Name := PName;
+ WeapSwitchMode := WeapSwitch;
+ if (WeapSwitch = 2) then
+ SetWeaponPrefs(TmpPrefArray);
+ SwitchToEmpty := SwitchEmpty;
Reset(True);
end;
TmpModel: string;
TmpColor: TRGB;
TmpTeam: Byte;
+ TmpWeapSwitch: Byte;
+ TmpPrefArray: Array [WP_FIRST .. WP_LAST + 1] of Byte;
+ TmpSwEmpty: Byte;
+ I: Integer;
Pl: TPlayer;
Err: Boolean;
begin
TmpColor.G := M.ReadByte();
TmpColor.B := M.ReadByte();
TmpTeam := M.ReadByte();
+ TmpWeapSwitch := M.ReadByte();
+ if (TmpWeapSwitch = 2) then
+ for I := WP_FIRST to WP_LAST + 1 do
+ TmpPrefArray[I] := M.ReadByte();
+ TmpSwEmpty := M.ReadByte();
except
Err := True;
end;
if TmpModel <> Pl.Model.Name then
Pl.SetModel(TmpModel);
+ if (TmpWeapSwitch <> Pl.WeapSwitchMode) then
+ Pl.WeapSwitchMode := TmpWeapSwitch;
+
+ if (TmpWeapSwitch = 2) then
+ Pl.SetWeaponPrefs(TmpPrefArray);
+
+ if (TmpSwEmpty <> Pl.SwitchToEmpty) then
+ Pl.SwitchToEmpty := TmpSwEmpty;
MH_SEND_PlayerSettings(Pl.UID, TmpModel);
end;
PID: Word;
Pl: TPlayer;
I, OldFire: Integer;
- checkWeapon: Boolean;
OldJet, Flam: Boolean;
NewTeam: Byte;
begin
NewTeam := M.ReadByte();
for I := WP_FIRST to WP_LAST do
- begin
- checkWeapon := (M.ReadByte() <> 0);
- if ( (gPlayer1Settings.WeaponSwitch = 0) and (gPlayer2Settings.WeaponSwitch = 0) ) or ( (I = WEAPON_KASTET) or (I = WEAPON_PISTOL) or (checkWeapon = False) or (FWeapon[I] = True) ) then
- FWeapon[I] := checkWeapon
- else
- begin
- if ((PID = gPlayer1.UID) and (gPlayer1Settings.WeaponSwitch <> 0)) or ( (gPlayer2 <> nil) and (PID = gPlayer2.UID) and (gPlayer2Settings.WeaponSwitch <> 0) ) then
- begin
- FWeapon[I] := True;
- if (PID = gPlayer1.UID) then
- if (gPlayer1Settings.WeaponSwitch = 1) or ( (gPlayer1Settings.WeaponSwitch = 2) and (gPlayer1Settings.WeaponPreferences[I] > gPlayer1Settings.WeaponPreferences[CurrWeap]) ) then
- begin
- gSelectWeapon[0, I] := True;
- end
- else
- if (gPlayer2Settings.WeaponSwitch = 1) or ( (gPlayer2Settings.WeaponSwitch = 2) and (gPlayer2Settings.WeaponPreferences[I] > gPlayer2Settings.WeaponPreferences[CurrWeap]) ) then
- gSelectWeapon[1, I] := True;
- end
- else
- FWeapon[I] := checkWeapon;
- end;
- end;
+ FWeapon[I] := (M.ReadByte() <> 0);
+
for I := A_BULLETS to A_HIGH do
FAmmo[I] := M.ReadWord();
FRulez := FRulez + [R_KEY_GREEN];
if (M.ReadByte() <> 0) then
FRulez := FRulez + [R_KEY_BLUE];
- checkWeapon := M.ReadByte() <> 0;
- if (checkWeapon) then
- begin
+ if (M.ReadByte() <> 0) then
FRulez := FRulez + [R_BERSERK];
- if ((gPlayer2Settings.WeaponSwitch <> 0) and (gPlayer2Settings.WeaponSwitch <> 0)) and ((PID = gPlayer1.UID) or ( (gPlayer2 <> nil) and (PID = gPlayer2.UID) )) then
- begin
- if (PID = gPlayer1.UID) then
- begin
- if (gPlayer1Settings.WeaponSwitch = 1) or ( (gPlayer1Settings.WeaponSwitch = 2) and (gPlayer1Settings.WeaponPreferences[WP_LAST+1] > gPlayer1Settings.WeaponPreferences[CurrWeap]) ) then
- begin
- gSelectWeapon[0, WEAPON_KASTET] := True;
- end;
- end
- else
- begin
- if (gPlayer2Settings.WeaponSwitch = 1) or ( (gPlayer2Settings.WeaponSwitch = 2) and (gPlayer2Settings.WeaponPreferences[WP_LAST+1] > gPlayer2Settings.WeaponPreferences[CurrWeap]) ) then
- begin
- gSelectWeapon[0, WEAPON_KASTET] := True;
- end;
- end;
- end;
- end;
Frags := M.ReadLongInt();
Death := M.ReadLongInt();
TmpModel: string;
TmpColor: TRGB;
TmpTeam: Byte;
+ i: Integer;
Pl: TPlayer;
PID: Word;
begin
// CLIENT SEND
procedure MC_SEND_Info(Password: string);
+var i: Integer;
begin
NetOut.Clear();
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
+ NetOut.Write(gPlayer1Settings.WeaponSwitch);
+ if (gPlayer1Settings.WeaponSwitch = 2) then
+ for i := WP_FIRST to WP_LAST + 1 do
+ NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+ NetOut.Write(gPlayer1Settings.SwitchToEmpty);
g_Net_Client_Send(True, NET_CHAN_SERVICE);
end;
end;
procedure MC_SEND_PlayerSettings();
+var i: Integer;
begin
NetOut.Write(Byte(NET_MSG_PLRSET));
NetOut.Write(gPlayer1Settings.Name);
NetOut.Write(gPlayer1Settings.Color.G);
NetOut.Write(gPlayer1Settings.Color.B);
NetOut.Write(gPlayer1Settings.Team);
+ NetOut.Write(gPlayer1Settings.WeaponSwitch);
+ if (gPlayer1Settings.WeaponSwitch = 2) then
+ for i := WP_FIRST to WP_LAST + 1 do
+ NetOut.Write(gPlayer1Settings.WeaponPreferences[i]);
+ NetOut.Write(gPlayer1Settings.SwitchToEmpty);
g_Net_Client_Send(True, NET_CHAN_IMPORTANT);
end;
diff --git a/src/game/g_player.pas b/src/game/g_player.pas
index b04cdc2cf1a42740ce70fbbacf5143bbb8dd0b54..fbbd09af8b270a58deee364d75df247bf984a3bf 100644 (file)
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
function getNextWeaponIndex (): Byte; // return 255 for "no switch"
procedure resetWeaponQueue ();
function hasAmmoForWeapon (weapon: Byte): Boolean;
+ function shouldSwitch (weapon: Byte; hadWeapon: Boolean) : Boolean;
procedure doDamage (v: Integer);
FReloading: Array [WP_FIRST..WP_LAST] of Word;
FTime: Array [T_RESPAWN..T_FLAGCAP] of DWORD;
FKeys: Array [KEY_LEFT..KEY_CHAT] of TKeyState;
+ FWeapSwitchMode: Byte;
+ FWeapPreferences: Array [WP_FIRST .. WP_LAST+1] of Byte;
+ FSwitchToEmpty: Byte;
FColor: TRGB;
FPreferredTeam: Byte;
FSpectator: Boolean;
function IsKeyPressed(K: Byte): Boolean;
function GetKeys(): Byte;
function PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean): Boolean; virtual;
+ procedure SetWeaponPrefs(Prefs: Array of Byte);
+ procedure SetWeaponPref(Weapon, Pref: Byte);
+ function GetWeaponPref(Weapon: Byte) : Byte;
function Collide(X, Y: Integer; Width, Height: Word): Boolean; overload;
function Collide(Panel: TPanel): Boolean; overload;
function Collide(X, Y: Integer): Boolean; overload;
property Death: Integer read FDeath write FDeath;
property Kills: Integer read FKills write FKills;
property CurrWeap: Byte read FCurrWeap write FCurrWeap;
+ property WeapSwitchMode: Byte read FWeapSwitchMode write FWeapSwitchMode;
+ property SwitchToEmpty: Byte read FSwitchToEmpty write FSwitchToEmpty;
property MonsterKills: Integer read FMonsterKills write FMonsterKills;
property Secrets: Integer read FSecrets;
property GodMode: Boolean read FGodMode write FGodMode;
if FModel <> nil then FModel.Color := Color;
end;
+
+
function TPlayer.GetColor(): TRGB;
begin
result := FModel.Color;
end;
+procedure TPlayer.SetWeaponPrefs(Prefs: Array of Byte);
+var i: Integer;
+begin
+ for i := WP_FIRST to WP_LAST + 1 do
+ begin
+ if (Prefs[i] < 0) or (Prefs[i] > WP_LAST + 1) then
+ FWeapPreferences[i] := 0
+ else FWeapPreferences[i] := Prefs[i];
+ end;
+end;
+
+procedure TPlayer.SetWeaponPref(Weapon, Pref: Byte);
+begin
+ if (Weapon < 0) or (Weapon > WP_LAST + 1) then
+ exit
+ else if (Pref >= 0) and (Pref <= WP_LAST + 1) and (Weapon >= 0) and (Weapon <= WP_LAST + 1) then
+ FWeapPreferences[Weapon] := Pref
+ else if (Weapon >= 0) and (Weapon <= WP_LAST + 1) and ((Pref < 0) or (Pref > WP_LAST + 1)) then
+ FWeapPreferences[Weapon] := 0;
+end;
+
+function TPlayer.GetWeaponPref(Weapon: Byte) : Byte;
+begin
+ if (Weapon < 0) or (Weapon > WP_LAST + 1) then
+ result := 0
+ else if (FWeapPreferences[Weapon] < 0) or (FWeapPreferences[Weapon] > WP_LAST + 1) then
+ result := 0
+ else
+ result := FWeapPreferences[Weapon];
+end;
+
procedure TPlayer.SwitchTeam;
begin
if g_Game_IsClient then
end;
end;
+function TPlayer.shouldSwitch (weapon: Byte; hadWeapon: Boolean): Boolean;
+begin
+ result := false;
+ if (weapon < 0) or (weapon > WP_LAST + 1) then
+ begin
+ result := false;
+ exit;
+ end;
+ if (FWeapSwitchMode = 1) and not hadWeapon then
+ result := true
+ else if (FWeapSwitchMode = 2) then
+ result := (FWeapPreferences[weapon] > FWeapPreferences[FCurrWeap]);
+end;
+
// return 255 for "no switch"
function TPlayer.getNextWeaponIndex (): Byte;
var
dir, cwi: Integer;
begin
result := 255; // default result: "no switch"
+ //e_LogWriteFln('FSWITCHTOEMPTY: %s', [FSwitchToEmpty], TMsgType.Notify);
// had weapon cycling on previous frame? remove that flag
if (FNextWeap and $2000) <> 0 then
begin
for i := 0 to High(FWeapon) do
begin
cwi := (cwi+length(FWeapon)+dir) mod length(FWeapon);
- if FWeapon[cwi] then
+ if FWeapon[cwi] and ((FSwitchToEmpty = 1) or hasAmmoForWeapon(cwi)) then
begin
- //e_WriteLog(Format(' SWITCH: cur=%d; new=%d', [FCurrWeap, cwi]), MSG_WARNING);
+ //e_LogWriteFln(' SWITCH: cur=%d; new=%d %s %s', [FCurrWeap, cwi, FSwitchToEmpty, hasAmmoForWeapon(cwi)], TMsgType.Notify);
result := Byte(cwi);
FNextWeapDelay := WEAPON_DELAY;
exit;
wantThisWeapon[i] := true;
Inc(wwc);
end;
+
// exclude currently selected weapon from the set
wantThisWeapon[FCurrWeap] := false;
// slow down alterations a little
result := Byte(i);
resetWeaponQueue();
FNextWeapDelay := WEAPON_DELAY * 2; // anyway, 'cause why not
+ //e_LogWriteFln('FOUND %s %s %s', [result, FSwitchToEmpty, hasAmmoForWeapon(i)], TMsgType.Notify);
exit;
end;
end;
end;
nw := getNextWeaponIndex();
+ //
if nw = 255 then exit; // don't reset anything here
if nw > High(FWeapon) then
begin
@@ -3882,8 +3942,8 @@ function TPlayer.PickItem(ItemType: Byte; arespawn: Boolean; var remove: Boolean
var
a: Boolean;
- switchWeapon: Byte;
- hadWeapon: Boolean;
+ switchWeapon: Byte = -1;
+ hadWeapon: Boolean = False;
begin
Result := False;
if g_Game_IsClient then Exit;
if not (R_BERSERK in FRulez) then
begin
Include(FRulez, R_BERSERK);
- (*
- if allowBerserkSwitching then
- begin
- FCurrWeap := WEAPON_KASTET;
- resetWeaponQueue();
- FModel.SetWeapon(WEAPON_KASTET);
- end; *)
- if ( (g_Game_IsNet = False) or (NetMode = NET_SERVER) ) and ( ( (Self = gPlayer1) and (gPlayer1Settings.WeaponSwitch <> 0) ) or ( (gPlayer2 <> nil) and (Self = gPlayer2) and (gPlayer2Settings.WeaponSwitch <> 0) )) then
- begin
- if (Self = gPlayer1) then
- begin
- if (gPlayer1Settings.WeaponSwitch = 1) or ( (gPlayer1Settings.WeaponSwitch = 2) and (gPlayer1Settings.WeaponPreferences[WP_LAST+1] > gPlayer1Settings.WeaponPreferences[FCurrWeap]) ) then
- begin
- FCurrWeap := WEAPON_KASTET;
- resetWeaponQueue();
- FModel.SetWeapon(WEAPON_KASTET);
- end;
- end
- else
- begin
- if (gPlayer2Settings.WeaponSwitch = 1) or ( (gPlayer2Settings.WeaponSwitch = 2) and (gPlayer2Settings.WeaponPreferences[WP_LAST+1] > gPlayer2Settings.WeaponPreferences[FCurrWeap]) ) then
- begin
- FCurrWeap := WEAPON_KASTET;
- resetWeaponQueue();
- FModel.SetWeapon(WEAPON_KASTET);
- end;
- end;
- end;
+ if (shouldSwitch(WP_LAST + 1, false)) then
+ QueueWeaponSwitch(WEAPON_KASTET);
if gFlash <> 0 then
begin
Inc(FPain, 100);
if gFlash = 2 then Inc(FPickup, 5);
end;
end;
- if ( (g_Game_IsNet = False) or (NetMode = NET_SERVER) ) and ( ( (Self = gPlayer1) and (gPlayer1Settings.WeaponSwitch <> 0) ) or ( (gPlayer2 <> nil) and (Self = gPlayer2) and (gPlayer2Settings.WeaponSwitch <> 0) )) then
- begin
- if (hadWeapon = False) then
- begin
- if (Self = gPlayer1) and ( (gPlayer1Settings.WeaponSwitch = 1) or ( (gPlayer1Settings.WeaponSwitch = 2)
- and (gPlayer1Settings.WeaponPreferences[switchWeapon] > gPlayer1Settings.WeaponPreferences[FCurrWeap]) ) ) then
- begin
- FCurrWeap := switchWeapon;
- resetWeaponQueue();
- FModel.SetWeapon(switchWeapon);
- end
- else if (Self = gPlayer2) and ( (gPlayer2Settings.WeaponSwitch = 1) or ( (gPlayer2Settings.WeaponSwitch = 2)
- and (gPlayer2Settings.WeaponPreferences[switchWeapon] > gPlayer2Settings.WeaponPreferences[FCurrWeap]) ) ) then
- begin
- FCurrWeap := switchWeapon;
- resetWeaponQueue();
- FModel.SetWeapon(switchWeapon);
- end;
- end;
- end;
+
+ if (shouldSwitch(switchWeapon, hadWeapon)) then
+ QueueWeaponSwitch(switchWeapon);
end;
procedure TPlayer.Touch();