📄 p_weapon.pas
字号:
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));
var
n : integer;
begin
if (ent.deadflag) 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;
ent.client.anim_end := FRAME_crpain1;
end
else begin
ent.s.frame := FRAME_pain304+1;
ent.client.anim_end := FRAME_pain301;
end;
end;
end;//else
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) then
begin
ent.client.weaponstate := WEAPON_READY;
ent.client.ps.gunframe := FRAME_IDLE_FIRST;
// 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;
ent.client.ps.gunframe++;
Exit;
end;
// if ((ent->client->newweapon) && (ent->client->weaponstate != WEAPON_FIRING)) then
if ((ent.client.newweapon) AND (ent.client.weaponstate <> WEAPON_FIRING)) then
begin
ent.client.weaponstate := WEAPON_DROPPING;
if (instantweap.value)
then
ChangeWeapon(ent);
Exit;
end
else
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;
ent.client.anim_end := FRAME_crpain1;
end
else begin
ent.s.frame := FRAME_pain304+1;
ent.client.anim_end := FRAME_pain301;
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) 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;
// 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;
ent.client.anim_end := FRAME_crattak9;
end
else begin
ent.s.frame := FRAME_attack1-1;
ent.client.anim_end := FRAME_attack8;
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;
Exit;
end;
if (pause_frames) then
for (n = 0; pause_frames[n]; n++)
if (ent.client.ps.gunframe = pause_frames[n]) then
if random(15) then
Exit;
ent.client.ps.gunframe++;
Exit;
end;//else
end;//if
if (ent.client.weaponstate = WEAPON_FIRING) then
begin
for (n = 0; fire_frames[n]; n++)
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);
Break;
end;
if (!fire_frames[n]) then
ent.client.ps.gunframe++;
if (ent.client.ps.gunframe = FRAME_IDLE_FIRST+1) then
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))
begin
int oldstate = ent->client->weaponstate;
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 (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));
var
n : integer;
begin
if (ent.deadflag) 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;
{Y} if (ent.client.ps.pmove.pm_flags AND PMF_DUCKED) <> 0
then begin
ent.s.frame := FRAME_crpain4+1;
ent.client.anim_end := FRAME_crpain1;
end
else begin
ent.s.frame := FRAME_pain304+1;
ent.client.anim_end := FRAME_pain301;
end;
end;
end;//else
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;
ent.client.ps.gunframe++;
Exit;
end;
if (ent.client.newweapon) 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;
{Y} if (ent.client.ps.pmove.pm_flags AND PMF_DUCKED) <> 0
then begin
ent.s.frame := FRAME_crpain4+1;
ent.client.anim_end := FRAME_crpain1;
end
else begin
ent.s.frame := FRAME_pain304+1;
ent.client.anim_end := FRAME_pain301;
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) 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;
// start the animation
ent.client.anim_priority := ANIM_ATTACK;
{Y} 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;
end
else begin
ent.s.frame := FRAME_attack1-1;
ent.client.anim_end := FRAME_attack8;
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;
Exit;
end;
if (pause_frames) then
{Y} for (n = 0; pause_frames[n]; n++)
if (ent.client.ps.gunframe = pause_frames[n]) then
if random(15) then
Exit;
ent.client.ps.gunframe++;
Exit;
end;//else
end;//if
if (ent.client.weaponstate = WEAPON_FIRING) then
begin
{Y} for (n = 0; fire_frames[n]; n++)
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;
if (!fire_frames[n]) then
ent.client.ps.gunframe++;
if (ent.client.ps.gunframe = FRAME_IDLE_FIRST+1) then
ent.client.weaponstate := WEAPON_READY;
end;
end;//procedure onlyGAME
{$ENDIF}
{*
======================================================================
GRENADE
======================================================================
*}
const
GRENADE_TIMER = 3.0;
GRENADE_MINSPEED = 400;
GRENADE_MAXSPEED = 800;
// (GAME <> CTF)
procedure weapon_grenade_fire (edict_t *ent, qboolean held);
var
offset,
forward_, right,
start : vec3_t;
timer,
radius : float;
int damage = 125;
int speed;
begin
radius := damage+40;
if (is_quad) then
damage := damage *4;
VectorSet(offset, 8, 8, ent.viewheight-8);
AngleVectors (ent.client.v_angle, forward_, right, NULL);
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);
fire_grenade2 (ent, start, forward_, damage, speed, timer, radius, held);
// if (! ( (int)dmflags.value & DF_INFINITE_AMMO ) ) then
if ( (Trunc(dmflags.value) AND DF_INFINITE_AMMO) = 0 ) then
ent.client.pers.inventory[ent.client.ammo_index]--;
ent.client.grenade_time := level.time + 1.0;
if (ent.deadflag 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;
end
else begin
ent.client.anim_priority := ANIM_REVERSE;
ent.s.frame := FRAME_wave08;
ent.client.anim_end := FRAME_wave01;
end;
end;//procedure (GAME <> CTF)
// (GAME=CTF)
procedure Weapon_Grenade (edict_t *ent);
begin
if ((ent.client.newweapon) 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -