Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
phaser_weapon.qc
Go to the documentation of this file.
1#include "phaser_weapon.qh"
2
3#ifdef SVQC
4
5void beam_think(entity this);
6
8SOUND(PhaserTurretAttack_FIRE, W_Sound("electro_fire"));
9SOUND(PhaserTurretAttack_IMPACT, W_Sound("neximpact"));
10METHOD(PhaserTurretAttack, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
11{
12 bool isPlayer = IS_PLAYER(actor);
13 if (fire & 1)
14 if (!isPlayer || weapon_prepareattack(thiswep, actor, weaponentity, false, 1))
15 {
16 float prev_shot_speed = actor.shot_speed;
17 if (isPlayer)
18 {
19 turret_initparams(actor);
20 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_PhaserTurretAttack_FIRE, CH_WEAPON_B, 0, DEATH_TURRET_PHASER.m_id);
21 actor.tur_shotdir_updated = w_shotdir;
22 actor.tur_shotorg = w_shotorg;
23 actor.tur_head = actor;
24 actor.shot_speed = 1;
25 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0.5, w_ready);
26 }
27 entity beam = new(PhaserTurret_beam);
28 setmodel(beam, MDL_TUR_PHASER_BEAM);
29 beam.effects = EF_LOWPRECISION;
30 beam.solid = SOLID_NOT;
31 setthink(beam, beam_think);
32 beam.cnt = time + actor.shot_speed;
33 beam.shot_spread = time + 2;
34 beam.nextthink = time;
35 beam.realowner = actor;
36 beam.owner = actor;
37 beam.shot_dmg = actor.shot_dmg / (actor.shot_speed / frametime);
38 beam.scale = actor.target_range / 256;
40 beam.enemy = actor.enemy;
41 beam.bot_dodge = true;
42 IL_PUSH(g_bot_dodge, beam);
43 beam.bot_dodgerating = beam.shot_dmg;
44 sound (beam, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
45 actor.fireflag = 1;
46
47 beam.attack_finished_single[0] = actor.attack_finished_single[0];
48 actor.attack_finished_single[0] = time; // + autocvar_sys_ticrate;
49
50 setattachment(beam, actor.tur_head, "tag_fire");
51
52 soundat(actor, trace_endpos, CH_SHOTS, SND(PhaserTurretAttack_IMPACT), VOL_BASE, ATTEN_NORM);
53 if (!isPlayer && actor.tur_head.frame == 0)
54 actor.tur_head.frame = 1;
55 if (isPlayer)
56 actor.shot_speed = prev_shot_speed;
57 }
58}
59
61{
62 entity actor = this.realowner;
63 if (time > this.cnt || IS_DEAD(actor))
64 {
65 actor.attack_finished_single[0] = time + actor.shot_refire;
66 actor.fireflag = 2;
67 actor.tur_head.frame = 10;
68 sound(this, CH_SHOTS_SINGLE, SND_Null, VOL_BASE, ATTEN_NORM);
69 delete(this);
70 return;
71 }
72
73 turret_do_updates(actor);
74
75 if (time - this.shot_spread > 0)
76 {
77 this.shot_spread = time + 2;
78 sound(this, CH_SHOTS_SINGLE, SND_TUR_PHASER, VOL_BASE, ATTEN_NORM);
79 }
80
81 this.nextthink = time;
82
83 actor.attack_finished_single[0] = time + frametime;
84 FireImoBeam(actor, actor.tur_shotorg,
85 actor.tur_shotorg + actor.tur_shotdir_updated * actor.target_range,
86 '-1 -1 -1' * actor.shot_radius,
87 '1 1 1' * actor.shot_radius,
88 actor.shot_force,
89 this.shot_dmg,
90 0.75,
91 DEATH_TURRET_PHASER.m_id
92 );
94}
95
96#endif // SVQC
IntrusiveList g_bot_dodge
Definition api.qh:150
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
#define setmodel(this, m)
Definition model.qh:26
#define IS_DEAD(s)
Definition player.qh:244
#define IS_PLAYER(s)
Definition player.qh:242
void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax, float bforce, float f_dmg, float f_velfactor, int deathtype)
Railgun-like beam, but has thickness and suppots slowing of target.
Definition util.qc:25
float frametime
const float SOLID_NOT
float time
vector trace_endpos
float nextthink
vector v_forward
float EF_LOWPRECISION
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
vector WarpZone_UnTransformOrigin(entity wz, vector org)
Transforms origin org backwards through warpzone wz, as the inverse of WarpZone_TransformOrigin.
Definition common.qc:526
entity WarpZone_trace_transform
Transform accumulator during a trace.
Definition common.qh:40
float vlen(vector v)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:133
#define METHOD(cname, name, prototype)
Definition oo.qh:274
int fireflag
Definition phaser.qc:11
void beam_think(entity this)
float scale
Definition projectile.qc:14
#define setthink(e, f)
const float VOL_BASE
Definition sound.qh:36
const int CH_SHOTS
Definition sound.qh:14
const int CH_SHOTS_SINGLE
Definition sound.qh:15
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
const int CH_WEAPON_B
Definition sound.qh:8
string W_Sound(string w_snd)
Definition all.qc:226
void soundat(entity e, vector o, int chan, string samp, float vol, float _atten)
Definition all.qc:80
#define SND(id)
Definition all.qh:35
#define SOUND(name, path)
Definition all.qh:30
void turret_do_updates(entity t_turret)
updates enemy distances, predicted impact point/time and updated aim<->predict impact distance.
void turret_initparams(entity tur)
entity realowner
vector w_shotdir
Definition tracing.qh:20
vector w_shotorg
Definition tracing.qh:19
#define W_SetupShot_Dir(ent, wepent, s_forward, antilag, recoil, snd, chan, maxdamage, deathtype)
Definition tracing.qh:32
void weapon_thinkf(entity actor,.entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor,.entity weaponentity, int fire) func)
bool weapon_prepareattack(Weapon thiswep, entity actor,.entity weaponentity, bool secondary, float attacktime)
void w_ready(Weapon thiswep, entity actor,.entity weaponentity, int fire)