⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p_weapon.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  else begin
    ent^.client^.anim_priority := ANIM_REVERSE;
    ent^.s.frame := FRAME_wave08;
    ent^.client^.anim_end := FRAME_wave01;  // by.. FAB
  end;
end;


procedure Weapon_Grenade (ent : edict_p); //for g_items
begin
  if ((ent^.client^.newweapon <> Nil) AND (ent^.client^.weaponstate = WEAPON_READY)) then
  begin
    ChangeWeapon (ent);
    Exit;
  end;

  if (ent^.client^.weaponstate = WEAPON_ACTIVATING) then
  begin
    ent^.client^.weaponstate := WEAPON_READY;
    ent^.client^.ps.gunframe := 16;
    Exit;
  end;

  if (ent^.client^.weaponstate = WEAPON_READY) then
  begin
    if ( ((ent^.client^.latched_buttons OR ent^.client^.buttons) AND BUTTON_ATTACK) <> 0 ) then
    begin
      ent^.client^.latched_buttons := ent^.client^.latched_buttons AND (NOT BUTTON_ATTACK);
      if (ent^.client^.pers.inventory[ent^.client^.ammo_index] <> 0) then
      begin
        ent^.client^.ps.gunframe := 1;
        ent^.client^.weaponstate := WEAPON_FIRING;
        ent^.client^.grenade_time := 0;
      end
      else begin
        if (level.time >= ent^.pain_debounce_time) then
        begin
          gi.sound(ent, CHAN_VOICE, gi.soundindex('weapons/noammo.wav'), 1, ATTN_NORM, 0);
          ent^.pain_debounce_time := level.time + 1;
        end;
        NoAmmoWeaponChange (ent);
      end;
      Exit;
    end;

    if ((ent^.client^.ps.gunframe = 29) OR (ent^.client^.ps.gunframe = 34) OR
        (ent^.client^.ps.gunframe = 39) OR (ent^.client^.ps.gunframe = 48)) then
      if (rand() AND 15) <> 0 then
        Exit;

    Inc(ent^.client^.ps.gunframe);
    if (ent^.client^.ps.gunframe > 48) then
      ent^.client^.ps.gunframe := 16;
    Exit;
  end;

  if (ent^.client^.weaponstate = WEAPON_FIRING) then
  begin
    if (ent^.client^.ps.gunframe = 5) then
      gi.sound (ent, CHAN_WEAPON, gi.soundindex('weapons/hgrena1b.wav'), 1, ATTN_NORM, 0);

    if (ent^.client^.ps.gunframe = 11) then
    begin
      if (ent^.client^.grenade_time = 0) then
      begin
        ent^.client^.grenade_time := level.time + GRENADE_TIMER + 0.2;
        ent^.client^.weapon_sound := gi.soundindex('weapons/hgrenc1b.wav');
      end;

      // they waited too long, detonate it in their hand
      if (NOT ent^.client^.grenade_blew_up) AND (level.time >= ent^.client^.grenade_time) then
      begin
        ent^.client^.weapon_sound := 0;
        weapon_grenade_fire (ent, true);
        ent^.client^.grenade_blew_up := true;
      end;

      if ((ent^.client^.buttons AND BUTTON_ATTACK) <> 0) then
        Exit;

      if (ent^.client^.grenade_blew_up) then
        if (level.time >= ent^.client^.grenade_time) then
        begin
          ent^.client^.ps.gunframe := 15;
          ent^.client^.grenade_blew_up := false;
        end
        else
          Exit;
    end;

    if (ent^.client^.ps.gunframe = 12) then
    begin
      ent^.client^.weapon_sound := 0;
      weapon_grenade_fire (ent, false);
    end;

    if ((ent^.client^.ps.gunframe = 15) AND (level.time < ent^.client^.grenade_time)) then
      Exit;

    Inc(ent^.client^.ps.gunframe);

    if (ent^.client^.ps.gunframe = 16) then
    begin
      ent^.client^.grenade_time := 0;
      ent^.client^.weaponstate := WEAPON_READY;
    end;
  end;
end;


{*
======================================================================

GRENADE LAUNCHER

======================================================================
*}
procedure weapon_grenadelauncher_fire (ent : edict_p); cdecl;
var
  offset,
  forward_, right,
  start           : vec3_t;
  radius          : Single; // was Float ..by FAB
  damage : integer;
begin
  damage := 120;

  radius := damage + 40;
  if (is_quad) then
    damage := damage * 4;

  VectorSet(offset, 8, 8, ent^.viewheight-8);
  AngleVectors (ent^.client^.v_angle, @forward_, @right, NIL); // by..FAB
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);

  VectorScale (forward_, -2, ent^.client^.kick_origin);
  ent^.client^.kick_angles[0] := -1;

  fire_grenade (ent, start, forward_, damage, 600, 2.5, radius);

  gi.WriteByte (svc_muzzleflash);
  { According with last Juha help on convert it }
  //gi.WriteShort (ent-g_edicts);  ...by FAB
  gi.WriteShort((Cardinal(ent) - Cardinal(g_edicts))div sizeof(edict_t));
  gi.WriteByte (MZ_GRENADE OR is_silenced);
  gi.multicast (@ent^.s.origin, MULTICAST_PVS); // Added @ ..by FAB

  Inc(ent^.client^.ps.gunframe);

  PlayerNoise(ent, start, PNOISE_WEAPON);

  if ( (Trunc(dmflags^.value) AND DF_INFINITE_AMMO) = 0 ) then
    Dec(ent^.client^.pers.inventory[ent^.client^.ammo_index]);
end;

procedure Weapon_GrenadeLauncher (ent : edict_p); //for g_items
const
  pause_frames : array [0..3] of integer = (34, 51, 59, 0);
  fire_frames  : array [0..1] of integer = (6, 0);
begin
  Weapon_Generic (ent, 5, 16, 59, 64, @pause_frames, @fire_frames, weapon_grenadelauncher_fire);
end;


{*
======================================================================

ROCKET

======================================================================
*}

procedure Weapon_RocketLauncher_Fire (ent : edict_p); cdecl;
var
  offset, start,
  forward_, right : vec3_t;
  damage_radius   : Single;
  damage,
  radius_damage   : integer;
begin
  damage := 100 + Trunc(_random() * 20.0);
  radius_damage := 120;
  damage_radius := 120;
  if (is_quad) then
  begin
    damage := damage *4;
    radius_damage := radius_damage *4;
  end;

  AngleVectors (ent^.client^.v_angle, @forward_, @right, Nil);

  VectorScale (forward_, -2, ent^.client^.kick_origin);
  ent^.client^.kick_angles[0] := -1;

  VectorSet(offset, 8, 8, ent^.viewheight-8);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);
  fire_rocket (ent, start, forward_, damage, 650, damage_radius, radius_damage);

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  { According with last Juha help on convert it }
  gi.WriteShort ((Cardinal(ent)-Cardinal(g_edicts)) div SizeOf(edict_p));
  gi.WriteByte (MZ_ROCKET OR is_silenced);
  gi.multicast (@ent^.s.origin, MULTICAST_PVS);

  Inc(ent^.client^.ps.gunframe);

  PlayerNoise(ent, start, PNOISE_WEAPON);

  if ( (Trunc(dmflags^.value) AND DF_INFINITE_AMMO) = 0 ) then
    Dec(ent^.client^.pers.inventory[ent^.client^.ammo_index]);
end;


procedure Weapon_RocketLauncher (ent : edict_p); //for g_items
const
  pause_frames : array [0..4] of integer = (25, 33, 42, 50, 0);
  fire_frames  : array [0..1] of integer = (5, 0);
begin
  Weapon_Generic (ent, 4, 12, 50, 54, @pause_frames, @fire_frames, Weapon_RocketLauncher_Fire);
end;


{*
======================================================================

BLASTER / HYPERBLASTER

======================================================================
*}

procedure Blaster_Fire (ent : edict_p; const g_offset : vec3_t; damage : integer; hyper : qboolean; effect : integer); cdecl;
var
  forward_, right,
  start,
  offset          : vec3_t;
begin
  if (is_quad) then
    damage := damage *4;
  AngleVectors (ent^.client^.v_angle, @forward_, @right, Nil);
  VectorSet(offset, 24, 8, ent^.viewheight-8);
  VectorAdd (offset, g_offset, offset);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);

  VectorScale (forward_, -2, ent^.client^.kick_origin);
  ent^.client^.kick_angles[0] := -1;

  fire_blaster (ent, start, forward_, damage, 1000, effect, hyper);

  // send muzzle flash
  gi.WriteByte (svc_muzzleflash);
  { According with last Juha help on convert it }
  gi.WriteShort((Cardinal(ent) - Cardinal(g_edicts))div sizeof(edict_t));
  if (hyper) then
    gi.WriteByte (MZ_HYPERBLASTER OR is_silenced)
  else
    gi.WriteByte (MZ_BLASTER OR is_silenced);
  gi.multicast (@ent^.s.origin, MULTICAST_PVS); //added @ ..by FAB

  PlayerNoise(ent, start, PNOISE_WEAPON);
end;

procedure Weapon_Blaster_Fire (ent : edict_p); cdecl;
var
  damage : integer;
begin
  if (deathmatch^.value <> 0) then
    damage := 15
  else
    damage := 10;
  Blaster_Fire (ent, vec3_origin, damage, false, EF_BLASTER);
  Inc(ent^.client^.ps.gunframe);
end;

procedure Weapon_Blaster (ent : edict_p); //for g_items
const
  pause_frames : array [0..2] of integer = (19, 32, 0);
  fire_frames  : array [0..1] of integer = (5, 0);
begin
  Weapon_Generic (ent, 4, 8, 52, 55, @pause_frames, @fire_frames, Weapon_Blaster_Fire);
end;

procedure Weapon_HyperBlaster_Fire (ent : edict_p); cdecl;
var
  rotation : Single; //was Float ..by FAB
  offset   : vec3_t;
  effect,
  damage   : integer;
begin
  ent^.client^.weapon_sound := gi.soundindex('weapons/hyprbl1a.wav');

  if ( (ent^.client^.buttons AND BUTTON_ATTACK) = 0 ) then
  begin
    Inc(ent^.client^.ps.gunframe);
  end
  else begin
    if (ent^.client^.pers.inventory[ent^.client^.ammo_index] = 0) then
    begin
      if (level.time >= ent^.pain_debounce_time) then
      begin
        gi.sound(ent, CHAN_VOICE, gi.soundindex('weapons/noammo.wav'), 1, ATTN_NORM, 0);
        ent^.pain_debounce_time := level.time + 1;
      end;
      NoAmmoWeaponChange (ent);
    end
    else begin
      rotation := (ent^.client^.ps.gunframe - 5) * 2*M_PI/6;
      offset[0] := -4 * sin(rotation);
      offset[1] := 0;
      offset[2] := 4 * cos(rotation);

      if ((ent^.client^.ps.gunframe = 6) OR (ent^.client^.ps.gunframe = 9)) then
        effect := EF_HYPERBLASTER
      else
        effect := 0;

      if (deathmatch^.value <> 0) then
        damage := 15
      else
        damage := 20;

      Blaster_Fire (ent, offset, damage, true, effect);
      if ( (Trunc(dmflags^.value) AND DF_INFINITE_AMMO) = 0 ) then
        Dec(ent^.client^.pers.inventory[ent^.client^.ammo_index]);

      ent^.client^.anim_priority := ANIM_ATTACK;
      if (ent^.client^.ps.pmove.pm_flags AND PMF_DUCKED) <> 0 then
      begin
        ent^.s.frame := FRAME_crattak1 - 1;
        ent^.client^.anim_end := FRAME_crattak9; // by FAB
      end
      else begin
        ent^.s.frame := FRAME_attack1 - 1;
        ent^.client^.anim_end := FRAME_attack8;  // by FAB
      end;
    end;

    Inc(ent^.client^.ps.gunframe);
    if (ent^.client^.ps.gunframe = 12) AND (ent^.client^.pers.inventory[ent^.client^.ammo_index] <> 0) then
      ent^.client^.ps.gunframe := 6;
  end;

  if (ent^.client^.ps.gunframe = 12) then
  begin
    gi.sound(ent, CHAN_AUTO, gi.soundindex('weapons/hyprbd1a.wav'), 1, ATTN_NORM, 0);
    ent^.client^.weapon_sound := 0;
  end;
end;

procedure Weapon_HyperBlaster (ent : edict_p); //for g_items
const
  pause_frames : array [0..0] of integer = (0); //OR pause_frames : integer = 0;
  fire_frames  : array [0..6] of integer = (6, 7, 8, 9, 10, 11, 0);
begin
  Weapon_Generic (ent, 5, 20, 49, 53, @pause_frames, @fire_frames, Weapon_HyperBlaster_Fire);
end;

{*
======================================================================

MACHINEGUN / CHAINGUN

======================================================================
*}

procedure Machinegun_Fire (ent : edict_p); cdecl;
var
  i : integer;
  start,
  forward_, right,
  angles,
  offset         : vec3_t;
  damage, kick : integer;
begin
  damage := 8;
  kick   := 2;

  if ( (ent^.client^.buttons AND BUTTON_ATTACK) = 0 ) then
  begin
    ent^.client^.machinegun_shots := 0;
    Inc(ent^.client^.ps.gunframe);
    Exit;
  end;

  if (ent^.client^.ps.gunframe = 5) then
    ent^.client^.ps.gunframe := 4
  else
    ent^.client^.ps.gunframe := 5;

  if (ent^.client^.pers.inventory[ent^.client^.ammo_index] < 1) then
  begin
    ent^.client^.ps.gunframe := 6;
    if (level.time >= ent^.pain_debounce_time) then
    begin
      gi.sound(ent, CHAN_VOICE, gi.soundindex('weapons/noammo.wav'), 1, ATTN_NORM, 0);
      ent^.pain_debounce_time := level.time + 1;
    end;
    NoAmmoWeaponChange (ent);
    Exit;
  end;

  if (is_quad) then
  begin
    damage := damage *4;
    kick := kick *4;
  end;

  for i := 1 to 2 do
  begin
    ent^.client^.kick_origin[i] := crandom() * 0.35;
    ent^.client^.kick_angles[i] := crandom() * 0.7;
  end;
  ent^.client^.kick_origin[0] := crandom() * 0.35;
  ent^.client^.kick_angles[0] := ent^.client^.machinegun_shots * -1.5;

  // raise the gun as it is firing
  if (deathmatch^.value=0) then
  begin
    Inc(ent^.client^.machinegun_shots);
    if (ent^.client^.machinegun_shots > 9) then
      ent^.client^.machinegun_shots := 9;
  end;

  // get start / end positions
  VectorAdd (ent^.client^.v_angle, ent^.client^.kick_angles, angles);
  AngleVectors (angles, @forward_, @right, Nil);
  VectorSet(offset, 0, 8, ent^.viewheight-8);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);
  fire_bullet (ent, start, forward_, damage, kick, DEFAULT_BULLET_HSPREAD, DEFAULT_BULLET_VSPREAD, MOD_MACHINEGUN);

  gi.WriteByte (svc_muzzleflash);
  { According with last Juha help on convert it }
  gi.WriteShort((Cardinal(ent) - Cardinal(g_edicts))div sizeof(edict_t));
  gi.WriteByte (MZ_MACHINEGUN OR is_silenced);
  gi.multicast (@ent^.s.origin, MULTICAST_PVS);

  PlayerNoise(ent, start, PNOISE_WEAPON);

  if ( (Trunc(dmflags^.value) AND DF_INFINITE_AMMO) = 0 ) then
    Dec(ent^.client^.pers.inventory[ent^.client^.ammo_index]);

  ent^.client^.anim_priority := ANIM_ATTACK;
  if ((ent^.client^.ps.pmove.pm_flags AND PMF_DUCKED) <> 0) then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -