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

📄 p_weapon.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 4 页
字号:
       (ent^.client^.pers.inventory[index] = 1) ) then
  begin
    gi.cprintf (ent, PRINT_HIGH, 'Can''t drop current weapon'#10);
    Exit;
  end;

  Drop_Item (ent, item);
  Dec(ent^.client^.pers.inventory[index]);
end;


{*
================
Weapon_Generic

A generic function to handle the basics of weapon thinking
================
*}
//const
//  FRAME_FIRE_FIRST	 = (FRAME_ACTIVATE_LAST + 1);
//  FRAME_IDLE_FIRST	 = (FRAME_FIRE_LAST + 1);
//  FRAME_DEACTIVATE_FIRST = (FRAME_IDLE_LAST + 1);

// (GAME <> CTF)
{$IFDEF CTF}
{procedure static void Weapon_Generic2 (edict_t *ent,
                                       int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST,
                                       int *pause_frames, int *fire_frames, void ( *fire)(edict_t *ent));}
procedure Weapon_Generic2 (ent : edict_p;
                           FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST : integer;
                           pause_frames, fire_frames : array of integer{;, void ( *fire)(edict_t *ent)});
var
  n : integer;
begin
  if (ent.deadflag <> 0) OR (ent.s.modelindex <> 255) then // VWep animations screw up corpses
    Exit;

  if (ent.client.weaponstate = WEAPON_DROPPING) then
  begin
    if (ent.client.ps.gunframe = FRAME_DEACTIVATE_LAST)
    then begin
      ChangeWeapon (ent);
      Exit;
    end
    else begin
      if ((FRAME_DEACTIVATE_LAST - ent.client.ps.gunframe) = 4) then
      begin
        ent.client.anim_priority := ANIM_REVERSE;
        if ((ent.client.ps.pmove.pm_flags AND PMF_DUCKED) <> 0)
        then begin
          ent.s.frame := FRAME_crpain4+1; // by FAB
          ent.client.anim_end := FRAME_crpain1;  // by FAB
        end
        else begin
          ent.s.frame := FRAME_pain304+1;     // by FAB
          ent.client.anim_end := FRAME_pain301;  // by FAB
        end;
      end;
    end;//else

    Inc(ent.client.ps.gunframe);
    Exit;
  end;

  if (ent.client.weaponstate = WEAPON_ACTIVATING) then
  begin
    if (ent.client.ps.gunframe = FRAME_ACTIVATE_LAST) OR (instantweap.value <> 0) then  // by FAB
    begin
      ent.client.weaponstate := WEAPON_READY;
      ent.client.ps.gunframe := FRAME_IDLE_FIRST;  // by FAB
      // we go recursive here to instant ready the weapon
      Weapon_Generic2 (ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST,
                       FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames,
                       fire_frames{, fire});
      Exit;
    end;

    Inc(ent.client.ps.gunframe);
    Exit;
  end;

//  if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING)) then
  if (ent.client.newweapon <> Nil) AND (ent.client.weaponstate <> WEAPON_FIRING) then
  begin
    ent.client.weaponstate := WEAPON_DROPPING;
    if (instantweap.value <> 0) // by FAB
    then begin
      ChangeWeapon(ent);
      Exit;
    end
    else
      ent.client.ps.gunframe := FRAME_DEACTIVATE_FIRST ; //by FAB

    if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4) then //by FAB
    begin
      ent.client.anim_priority := ANIM_REVERSE;
      if ((ent.client.ps.pmove.pm_flags AND PMF_DUCKED) <> 0)
      then begin
        ent.s.frame := FRAME_crpain4+1;  // by FAB
        ent.client.anim_end := FRAME_crpain1; // by FAB
      end
      else begin
        ent.s.frame := FRAME_pain304+1;    // by FAB
        ent.client.anim_end := FRAME_pain301; //by FAB
      end;
    end;
    Exit;
  end;

  if (ent.client.weaponstate = WEAPON_READY) then
  begin
//    if ( ((ent.client.latched_buttons|ent.client.buttons) & BUTTON_ATTACK) )
    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.ammo_index=0) OR
           (ent.client.pers.inventory[ent.client.ammo_index] >= ent.client.pers.weapon.quantity) )
      then begin
        ent.client.ps.gunframe := FRAME_FIRE_FIRST; // by FAB
        ent.client.weaponstate := WEAPON_FIRING;    // by FAB

        // start the animation
        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;   // by FAB
          ent.client.anim_end := FRAME_crattak9; //by FAB
        end
        else begin
          ent.s.frame := FRAME_attack1-1;    //by FAB
          ent.client.anim_end := FRAME_attack8;  //by FAB
        end;
      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;//else
    end
    else begin
      if (ent.client.ps.gunframe = FRAME_IDLE_LAST) then
      begin
        ent.client.ps.gunframe := FRAME_IDLE_FIRST; // by FAB
        Exit;
      end;

     if (pause_frames) then
     begin
        //for (n = 0; pause_frames[n]; n++)
        for n:=0 to pause_frames [n]-1 do
        begin
          if (ent.client.ps.gunframe = pause_frames[n]) then
            if (rand() and 15) <> 0 then
              Exit;
         end;
      end;
      Inc(ent.client.ps.gunframe);
      Exit;
    end;//else
  end;//if

  if (ent.client.weaponstate = WEAPON_FIRING) then
  begin
    for (n = 0; fire_frames[n]; n++)
        for n:= 0 to fire_frames[n]-1 do
        begin
      if (ent.client.ps.gunframe = fire_frames[n]) then
      begin
//ZOID
(*        if (!CTFApplyStrengthSound(ent)) then *)
//ZOID
          if (ent.client.quad_framenum > level.framenum) then
            gi.sound(ent, CHAN_ITEM, gi.soundindex('items/damage3.wav'), 1, ATTN_NORM, 0);
//ZOID
(*        CTFApplyHasteSound(ent); *)
//ZOID

        fire (ent);
        exit ; //Break;
      end;
    end;
//    if (!fire_frames[n]) then
    if (fire_frames[n]=0) then
      Inc(ent.client.ps.gunframe);

    if (ent.client.ps.gunframe = FRAME_IDLE_FIRST+1) then // by FAB
      ent.client.weaponstate := WEAPON_READY;
  end;//if
end;//procedure onlyCTF

//ZOID
{procedure Weapon_Generic (edict_t *ent,
                          int FRAME_ACTIVATE_LAST, int FRAME_FIRE_LAST, int FRAME_IDLE_LAST, int FRAME_DEACTIVATE_LAST,
                          int *pause_frames, int *fire_frames, void ( *fire)(edict_t *ent))}
procedure Weapon_Generic (ent : edict_p;
                          FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST : integer;
                          pause_frames, fire_frames : array of integer{;, void ( *fire)(edict_t *ent)});
var
  oldstate : integer;
begin
  oldstate := ent^.client^.weaponstate; // by FAB

  Weapon_Generic2 (ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST,
                   FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames,
                   fire_frames{, fire});

  // run the weapon frame again if hasted
  if (*((stricmp(ent.client.pers.weapon.pickup_name, 'Grapple') = 0) AND
     (ent.client.weaponstate = WEAPON_FIRING) then
    Exit;

(*if ((CTFApplyHaste(ent) ||
		(Q_stricmp(ent->client->pers.weapon->pickup_name, "Grapple") == 0 &&
		ent->client->weaponstate != WEAPON_FIRING))
		&& oldstate == ent->client->weaponstate)* )

  if ( CTFApplyHaste(ent) OR
       ( (Q_stricmp(ent.client.pers.weapon.pickup_name, 'Grapple') = 0) AND
         (ent.client.weaponstate <> WEAPON_FIRING) )
     ) AND
     (oldstate = ent.client.weaponstate) then*)
    Weapon_Generic2 (ent, FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST,
                     FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST, pause_frames,
                     fire_frames{, fire});
end;//procedure onlyCTF
//ZOID*)
{$ELSE}
procedure Weapon_Generic (ent : edict_p;
                          FRAME_ACTIVATE_LAST, FRAME_FIRE_LAST, FRAME_IDLE_LAST, FRAME_DEACTIVATE_LAST : integer;
                          pause_frames, fire_frames : PIntegerArray; fire : Proc_edit_s);
var
  FRAME_FIRE_FIRST,
  FRAME_IDLE_FIRST,
  FRAME_DEACTIVATE_FIRST,
  n : integer;
begin
  if (ent^.deadflag <> 0) OR (ent^.s.modelindex <> 255) then // VWep animations screw up corpses
    Exit;

  FRAME_FIRE_FIRST	 := (FRAME_ACTIVATE_LAST + 1);
  FRAME_IDLE_FIRST	 := (FRAME_FIRE_LAST + 1);
  FRAME_DEACTIVATE_FIRST := (FRAME_IDLE_LAST + 1);

  if (ent^.client^.weaponstate = WEAPON_DROPPING) then
  begin
    if (ent^.client^.ps.gunframe = FRAME_DEACTIVATE_LAST) then
    begin
      ChangeWeapon (ent);
      Exit;
    end
    else if ((FRAME_DEACTIVATE_LAST - ent^.client^.ps.gunframe) = 4) then
    begin
      ent^.client^.anim_priority := ANIM_REVERSE;
      if ((ent^.client^.ps.pmove.pm_flags AND PMF_DUCKED) <> 0) then
      begin
        ent^.s.frame := FRAME_crpain4 + 1; // by FAB
        ent^.client^.anim_end := FRAME_crpain1; //by FAB
      end
      else begin
        ent^.s.frame := FRAME_pain304 + 1;  //by FAB
        ent^.client^.anim_end := FRAME_pain301; //by FAB
      end;
    end;

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

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

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

  if (ent^.client^.newweapon <> Nil) AND (ent^.client^.weaponstate <> WEAPON_FIRING) then
  begin
    ent^.client^.weaponstate := WEAPON_DROPPING;
    ent^.client^.ps.gunframe := FRAME_DEACTIVATE_FIRST;

    if ((FRAME_DEACTIVATE_LAST - FRAME_DEACTIVATE_FIRST) < 4) then
    begin
      ent^.client^.anim_priority := ANIM_REVERSE;
      if (ent^.client^.ps.pmove.pm_flags AND PMF_DUCKED) <> 0 then
      begin
        ent^.s.frame := FRAME_crpain4 + 1;  // by FAB
        ent^.client^.anim_end := FRAME_crpain1;  //by FAB
      end
      else begin
        ent^.s.frame := FRAME_pain304 + 1;  //by FAB
        ent^.client^.anim_end := FRAME_pain301; //by FAB
      end;
    end;
    Exit;
  end;

  if (ent^.client^.weaponstate = WEAPON_READY) then
  begin
//    if ( ((ent.client.latched_buttons OR ent.client.buttons) & BUTTON_ATTACK) )
    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^.ammo_index = 0) OR
           (ent^.client^.pers.inventory[ent^.client^.ammo_index] >= ent^.client^.pers.weapon^.quantity) ) then
      begin
        ent^.client^.ps.gunframe := FRAME_FIRE_FIRST;
        ent^.client^.weaponstate := WEAPON_FIRING; // by FAB

        // start the animation
        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; //by FAB
          ent^.client^.anim_end := FRAME_crattak9;// by FAB
        end
        else begin
          ent^.s.frame := FRAME_attack1 - 1;  //by FAB
          ent^.client^.anim_end := FRAME_attack8; //by FAB
        end;
      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;
    end
    else begin
      if (ent^.client^.ps.gunframe = FRAME_IDLE_LAST) then
      begin
        ent^.client^.ps.gunframe := FRAME_IDLE_FIRST;
        Exit;
      end;

      if (pause_frames <> nil) then
      begin
        n := 0;
        while pause_frames[n] <> 0 do
        begin
          if (ent^.client^.ps.gunframe = pause_frames[n]) then
            if (rand() and 15) <> 0 then
              Exit;
          n := n + 1;
        end;
      end;

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

  if (ent^.client^.weaponstate = WEAPON_FIRING) then
  begin
    n := 0;
    while fire_frames[n] <> 0 do
    begin
        if (ent^.client^.ps.gunframe = fire_frames[n]) then
        begin
          if (ent^.client^.quad_framenum > level.framenum) then
            gi.sound(ent, CHAN_ITEM, gi.soundindex('items/damage3.wav'), 1, ATTN_NORM, 0);

          fire (ent);
          Break;
        end;
        n := n + 1;
    end;

    if (fire_frames[n] = 0) then
      Inc(ent^.client^.ps.gunframe);

    if (ent^.client^.ps.gunframe = FRAME_IDLE_FIRST+1) then
      ent^.client^.weaponstate := WEAPON_READY;
  end;
end;
{$ENDIF}


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

GRENADE

======================================================================
*}
const
  GRENADE_TIMER	   = 3.0;
  GRENADE_MINSPEED = 400;
  GRENADE_MAXSPEED = 800;

procedure weapon_grenade_fire (ent : edict_p; held : qboolean); cdecl;
var
  offset,
  forward_, right,
  start           : vec3_t;
  timer,
  radius          : Single; // was Float ...by FAB
  speed, damage : integer;
begin
  damage := 125;  

  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);

  timer := ent^.client^.grenade_time - level.time;
  (* speed = GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER); *)
  speed := Trunc(GRENADE_MINSPEED + (GRENADE_TIMER - timer) * ((GRENADE_MAXSPEED - GRENADE_MINSPEED) / GRENADE_TIMER));
  fire_grenade2 (ent, start, forward_, damage, speed, timer, radius, held);

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

  ent^.client^.grenade_time := level.time + 1.0;

  if (ent^.deadflag <> 0) OR (ent^.s.modelindex <> 255) then // VWep animations screw up corpses
    Exit;

{$IFNDEF CTF}  //onlyGAME
  if (ent^.health <= 0) then
    Exit;
{$ENDIF}

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

⌨️ 快捷键说明

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