DEADSOFTWARE

Add option to skip fist switching
[d2df-sdl.git] / src / game / g_player.pas
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);