diff --git a/src/game/g_player.pas b/src/game/g_player.pas
index 558edf291005ae96e782a5a526694dc9b57bb8b5..d7f305e68757bfb287d836b28dab9d398497155b 100644 (file)
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
procedure cycleWeapon (dir: Integer);
function getNextWeaponIndex (): Byte; // return 255 for "no switch"
procedure resetWeaponQueue ();
procedure cycleWeapon (dir: Integer);
function getNextWeaponIndex (): Byte; // return 255 for "no switch"
procedure resetWeaponQueue ();
+ function hasAmmoForWeapon (weapon: Byte): Boolean;
public
FDamageBuffer: Integer;
public
FDamageBuffer: Integer;
FNextWeapDelay := 0;
end;
FNextWeapDelay := 0;
end;
+function TPlayer.hasAmmoForWeapon (weapon: Byte): Boolean;
+begin
+ result := false;
+ case weapon of
+ WEAPON_KASTET, WEAPON_SAW: result := true;
+ WEAPON_SHOTGUN1, WEAPON_SHOTGUN2: result := (FAmmo[A_SHELLS] > 0);
+ WEAPON_PISTOL, WEAPON_CHAINGUN, WEAPON_SUPERPULEMET: result := (FAmmo[A_BULLETS] > 0);
+ WEAPON_ROCKETLAUNCHER: result := (FAmmo[A_ROCKETS] > 0);
+ WEAPON_PLASMA, WEAPON_BFG: result := (FAmmo[A_CELLS] > 0);
+ else result := (weapon < length(FWeapon));
+ end;
+end;
+
// return 255 for "no switch"
function TPlayer.getNextWeaponIndex (): Byte;
var
// return 255 for "no switch"
function TPlayer.getNextWeaponIndex (): Byte;
var
result := 255; // default result: "no switch"
for i := 0 to High(wantThisWeapon) do wantThisWeapon[i] := false;
for i := 0 to High(FWeapon) do if (FNextWeap and (1 shl i)) <> 0 then begin wantThisWeapon[i] := true; Inc(wwc); end;
result := 255; // default result: "no switch"
for i := 0 to High(wantThisWeapon) do wantThisWeapon[i] := false;
for i := 0 to High(FWeapon) do if (FNextWeap and (1 shl i)) <> 0 then begin wantThisWeapon[i] := true; Inc(wwc); end;
- if wantThisWeapon[FCurrWeap] then
- begin
- // these hacks implements alternating between SG and SSG; sorry
- if FCurrWeap = WEAPON_SHOTGUN1 then begin wantThisWeapon[WEAPON_SHOTGUN2] := true; Inc(wwc); end;
- if FCurrWeap = WEAPON_SHOTGUN2 then begin wantThisWeapon[WEAPON_SHOTGUN1] := true; Inc(wwc); end;
- // these hacks implements alternating between knuckles and chainsaw; sorry
- if FCurrWeap = WEAPON_KASTET then begin wantThisWeapon[WEAPON_SAW] := true; Inc(wwc); end;
- if FCurrWeap = WEAPON_SAW then begin wantThisWeapon[WEAPON_KASTET] := true; Inc(wwc); end;
- end;
// exclude currently selected weapon from the set
wantThisWeapon[FCurrWeap] := false;
// slow down alterations a little
// exclude currently selected weapon from the set
wantThisWeapon[FCurrWeap] := false;
// slow down alterations a little
// more than one weapon requested, assume "alteration" and check alteration delay
if FNextWeapDelay > 0 then begin FNextWeap := 0; exit; end; // yeah
end;
// more than one weapon requested, assume "alteration" and check alteration delay
if FNextWeapDelay > 0 then begin FNextWeap := 0; exit; end; // yeah
end;
- // no more hacks (yet)
// do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
// do not reset weapon queue, it will be done in `RealizeCurrentWeapon()`
+ if wwc < 1 then begin resetWeaponQueue(); exit; end;
+ //e_WriteLog(Format('wwc=%d', [wwc]), MSG_WARNING);
// try weapons in descending order
for i := High(FWeapon) downto 0 do
begin
// try weapons in descending order
for i := High(FWeapon) downto 0 do
begin
- if wantThisWeapon[i] and FWeapon[i] then
+ if wantThisWeapon[i] and FWeapon[i] and ((wwc = 1) or hasAmmoForWeapon(i)) then
begin
// i found her!
result := Byte(i);
exit;
end;
end;
begin
// i found her!
result := Byte(i);
exit;
end;
end;
+ // no suitable weapon found, so reset the queue, to avoid accidental "queuing" of weapon w/o ammo
+ resetWeaponQueue();
end;
procedure TPlayer.RealizeCurrentWeapon();
end;
procedure TPlayer.RealizeCurrentWeapon();
FJetFuel := JET_MAX;
end;
FJetFuel := JET_MAX;
end;
+ ITEM_MEDKIT_SMALL: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 10, PLAYER_HP_SOFT);
+ ITEM_MEDKIT_LARGE: if FHealth < PLAYER_HP_SOFT then IncMax(FHealth, 25, PLAYER_HP_SOFT);
+
+ ITEM_ARMOR_GREEN: if FArmor < PLAYER_AP_SOFT then FArmor := PLAYER_AP_SOFT;
+ ITEM_ARMOR_BLUE: if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
+
+ ITEM_SPHERE_BLUE: if FHealth < PLAYER_HP_LIMIT then IncMax(FHealth, 100, PLAYER_HP_LIMIT);
+ ITEM_SPHERE_WHITE:
+ if (FHealth < PLAYER_HP_LIMIT) or (FArmor < PLAYER_AP_LIMIT) then
+ begin
+ if FHealth < PLAYER_HP_LIMIT then FHealth := PLAYER_HP_LIMIT;
+ if FArmor < PLAYER_AP_LIMIT then FArmor := PLAYER_AP_LIMIT;
+ end;
+
ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;
ITEM_WEAPON_SAW: FWeapon[WEAPON_SAW] := True;
ITEM_WEAPON_SHOTGUN1: FWeapon[WEAPON_SHOTGUN1] := True;
ITEM_WEAPON_SHOTGUN2: FWeapon[WEAPON_SHOTGUN2] := True;