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

📄 p_weapon.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  begin
    ent^.s.frame := FRAME_crattak1 -  trunc((_random()+0.25));
    ent^.client^.anim_end := FRAME_crattak9;
  end
  else begin
    ent^.s.frame := FRAME_attack1 -  trunc(_random()+0.25);
    ent^.client^.anim_end := FRAME_attack8;
  end;
end;

procedure Weapon_Machinegun (ent : edict_p); //for g_items
const
  pause_frames : array [0..2] of integer = (23, 45, 0);
  fire_frames  : array [0..2] of integer = (4, 5, 0);
begin
  Weapon_Generic (ent, 3, 5, 45, 49, @pause_frames, @fire_frames, Machinegun_Fire);
end;


procedure Chaingun_Fire (ent : edict_p); cdecl;
var
  i,
  shots,
  damage              : integer;
  start,
  forward_, right, up,
  offset              : vec3_t;
  r, u                : Single; //was Float ..by FAB
  kick : integer;
begin
  kick := 2; 

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

  if (ent^.client^.ps.gunframe = 5) then
    gi.sound(ent, CHAN_AUTO, gi.soundindex('weapons/chngnu1a.wav'), 1, ATTN_IDLE, 0);

  if (ent^.client^.ps.gunframe = 14) AND ((ent^.client^.buttons AND BUTTON_ATTACK) = 0) then
  begin
    ent^.client^.ps.gunframe := 32;
    ent^.client^.weapon_sound := 0;
    Exit;
  end
  else if ( (ent^.client^.ps.gunframe = 21) AND ((ent^.client^.buttons AND BUTTON_ATTACK) <> 0) AND
  (ent^.client^.pers.inventory[ent^.client^.ammo_index] <> 0) ) then
    ent^.client^.ps.gunframe := 15
  else
    Inc(ent^.client^.ps.gunframe);

  if (ent^.client^.ps.gunframe = 22) then     // by FAB
  begin
    ent^.client^.weapon_sound := 0;
    gi.sound(ent, CHAN_AUTO, gi.soundindex('weapons/chngnd1a.wav'), 1, ATTN_IDLE, 0);
  end
  else
    ent^.client^.weapon_sound := gi.soundindex('weapons/chngnl1a.wav');  // by FAB

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

  if (ent^.client^.ps.gunframe <= 9) then
    shots := 1
  else if (ent^.client^.ps.gunframe <= 14) then
  begin
    if (ent^.client^.buttons AND BUTTON_ATTACK) <> 0 then
      shots := 2
    else
      shots := 1;
  end
  else
    shots := 3;

  if (ent^.client^.pers.inventory[ent^.client^.ammo_index] < shots) then
    shots := ent^.client^.pers.inventory[ent^.client^.ammo_index];

  if (shots = 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);
    Exit;
  end;

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

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

  for i := 0 to (shots - 1) do
  begin
    // get start / end positions
    AngleVectors (ent^.client^.v_angle, @forward_, @right, @up);
    r := 7 + crandom()*4;
    u := crandom()*4;
    VectorSet(offset, 0, r, u + 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_CHAINGUN);
  end;

  // 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));
  gi.WriteByte ((MZ_CHAINGUN1 + shots - 1) OR is_silenced);
  gi.multicast (@ent^.s.origin, MULTICAST_PVS); //added @ ..by FAB

  PlayerNoise(ent, start, PNOISE_WEAPON);

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

procedure Weapon_Chaingun (ent : edict_p); //for g_items
const
  pause_frames : array [0..4] of integer = (38, 43, 51, 61, 0);
  fire_frames  : array [0..17] of integer = (5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 0);
begin
  Weapon_Generic (ent, 4, 31, 61, 64, @pause_frames, @fire_frames, Chaingun_Fire);
end;


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

SHOTGUN / SUPERSHOTGUN

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

procedure weapon_shotgun_fire (ent : edict_p); cdecl;
var
  start,
  forward_, right,
  offset         : vec3_t;
  damage, kick : integer;
begin
  damage := 4;
  kick   := 8;

  if (ent^.client^.ps.gunframe = 9) then
  begin
    Inc(ent^.client^.ps.gunframe);
    Exit;
  end;

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

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

  VectorSet(offset, 0, 8,  ent^.viewheight-8);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);

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

  if (deathmatch^.value <> 0) then
    fire_shotgun (ent, start, forward_, damage, kick, 500, 500, DEFAULT_DEATHMATCH_SHOTGUN_COUNT, MOD_SHOTGUN)
  else
    fire_shotgun (ent, start, forward_, damage, kick, 500, 500, DEFAULT_SHOTGUN_COUNT, MOD_SHOTGUN);

  // 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));
  gi.WriteByte (MZ_SHOTGUN 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_Shotgun (ent : edict_p); //for g_items
const
  pause_frames : array [0..3] of integer = (22, 28, 34, 0);
  fire_frames  : array [0..2] of integer = (8, 9, 0);
begin
  Weapon_Generic (ent, 7, 18, 36, 39, @pause_frames, @fire_frames, weapon_shotgun_fire);
end;


procedure weapon_supershotgun_fire (ent : edict_p); cdecl;
var
  start,
  forward_, right,
  offset,
  v              : vec3_t;
  damage, kick : integer;
begin
  damage := 6;
  kick   := 12;

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

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

  VectorSet(offset, 0, 8,  ent^.viewheight-8);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);

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

  v[PITCH] := ent^.client^.v_angle[PITCH];
  v[YAW]   := ent^.client^.v_angle[YAW] - 5;
  v[ROLL]  := ent^.client^.v_angle[ROLL];
  AngleVectors (v, @forward_, Nil, Nil);
  fire_shotgun (ent, start, forward_, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT DIV 2, MOD_SSHOTGUN);
  v[YAW]   := ent^.client^.v_angle[YAW] + 5;
  AngleVectors (v, @forward_, Nil, Nil);
  fire_shotgun (ent, start, forward_, damage, kick, DEFAULT_SHOTGUN_HSPREAD, DEFAULT_SHOTGUN_VSPREAD, DEFAULT_SSHOTGUN_COUNT DIV 2, MOD_SSHOTGUN);

  // 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));
  gi.WriteByte (MZ_SSHOTGUN 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
    ent^.client^.pers.inventory[ent^.client^.ammo_index] := ent^.client^.pers.inventory[ent^.client^.ammo_index] -2;
end;


procedure Weapon_SuperShotgun (ent : edict_p); //for g_items
const
  pause_frames : array [0..3] of integer = (29, 42, 57, 0);
  fire_frames  : array [0..1] of integer = (7, 0);
begin
  Weapon_Generic (ent, 6, 17, 57, 61, @pause_frames, @fire_frames, weapon_supershotgun_fire);
end;


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

RAILGUN

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

procedure weapon_railgun_fire (ent : edict_p); cdecl;
var
  start,
  forward_, right,
  offset          : vec3_t;
  damage,
  kick            : integer;
begin
  if (deathmatch^.value <> 0) then
  begin
  // normal damage is too extreme in dm
    damage := 100;
    kick := 200;
  end
  else begin
    damage := 150;
    kick := 250;
  end;

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

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

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

  VectorSet(offset, 0, 7,  ent^.viewheight-8);
  P_ProjectSource (ent^.client, ent^.s.origin, offset, forward_, right, start);
  fire_rail (ent, start, forward_, damage, kick);

  // 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));
  gi.WriteByte (MZ_RAILGUN 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_Railgun (ent : edict_p); //for g_items
const
  pause_frames : array [0..1] of integer = (56, 0);
  fire_frames  : array [0..1] of integer = (4, 0);
begin
  Weapon_Generic (ent, 3, 18, 56, 61, @pause_frames, @fire_frames, weapon_railgun_fire);
end;


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

BFG10K

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

procedure weapon_bfg_fire (ent : edict_p); cdecl;
var
  offset, start,
  forward_, right  : vec3_t;
  damage           : integer;
  damage_radius: Single;
begin
  damage_radius := 1000;
  
  if (deathmatch^.value <> 0) then
    damage := 200
  else
    damage := 500;

  if (ent^.client^.ps.gunframe = 9) then
  begin
    // 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));
    gi.WriteByte (MZ_BFG or is_silenced);
    gi.multicast (@ent^.s.origin, MULTICAST_PVS); //added @ ..by FAB

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

    PlayerNoise(ent, ent^.s.origin, PNOISE_WEAPON);
    Exit;
  end;

  // cells can go down during windup (from power armor hits), so
  // check again and abort firing if we don't have enough now
  if (ent^.client^.pers.inventory[ent^.client^.ammo_index] < 50) then
  begin
    Inc(ent^.client^.ps.gunframe);
    Exit;
  end;

  if (is_quad) then
    damage := damage *4;

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

  VectorScale (forward_, -2, ent^.client^.kick_origin);

  // make a big pitch kick with an inverse fall
  ent.client.v_dmg_pitch := -40;
  ent.client.v_dmg_roll := crandom()*8;
  ent.client.v_dmg_time := level.time + DAMAGE_TIME;

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

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

  PlayerNoise(ent, start, PNOISE_WEAPON);

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


procedure Weapon_BFG (ent : edict_p); //for g_items
const
  pause_frames : array [0..4] of integer = (39, 45, 50, 55, 0);
  fire_frames  : array [0..2] of integer = (9, 17, 0);
begin
  Weapon_Generic (ent, 8, 32, 55, 58, @pause_frames, @fire_frames , weapon_bfg_fire );
end;


//======================================================================

// End of file
//end.


{
My current problems:
--------------------
1) C2PAS: "if" & "for"

   C-code:
     if (pause_frames) then
      for (n = 0; pause_frames[n]; n++)
   PAS-code:
     if Assigned(pause_frames) then
     begin
       n := 0;
       while pause_frames[n] <> 0 do
       begin
         ...
         Inc(n);
       end;
     end;

2) OK!
}

end.

⌨️ 快捷键说明

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