Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
projectile.qh File Reference
Include dependency graph for projectile.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 classfield (Projectile).int traileffect
void Ent_RemoveProjectile (entity this)
 entityclass (Projectile)
void loopsound (entity e, int ch, Sound samp, float vol, float attn)
void Projectile_Draw (entity this)
void Projectile_DrawTrail (entity this, vector to)
void Projectile_ResetTrail (entity this, vector to)
void SUB_Stop (entity this, entity toucher)

Variables

bool autocvar_cl_projectiles_sloppy
 fade_rate
 iorigin2

Function Documentation

◆ classfield()

classfield ( Projectile )

◆ Ent_RemoveProjectile()

void Ent_RemoveProjectile ( entity this)

Definition at line 209 of file projectile.qc.

210{
211 if (this.count & 0x80)
212 {
213 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
215 }
216}
float count
Definition powerups.qc:22
const float MOVE_NORMAL
vector mins
vector velocity
vector trace_endpos
vector maxs
vector origin
void Projectile_DrawTrail(entity this, vector to)
Definition projectile.qc:30

References count, entity(), maxs, mins, MOVE_NORMAL, origin, Projectile_DrawTrail(), trace_endpos, and velocity.

Referenced by NET_HANDLE().

◆ entityclass()

entityclass ( Projectile )

◆ loopsound()

void loopsound ( entity e,
int ch,
Sound samp,
float vol,
float attn )

Definition at line 199 of file projectile.qc.

200{
201 TC(int, ch);
202 if (e.silent)
203 return;
204
205 sound(e, ch, samp, vol, attn);
206 e.snd_looping = ch;
207}
#define TC(T, sym)
Definition _all.inc:82
#define sound(e, c, s, v, a)
Definition sound.qh:52

References entity(), sound, and TC.

Referenced by MUTATOR_HOOKFUNCTION(), NET_HANDLE(), and NET_HANDLE().

◆ Projectile_Draw()

void Projectile_Draw ( entity this)

Definition at line 80 of file projectile.qc.

81{
82 vector rot;
83 vector trailorigin;
84 int f;
85 bool drawn;
86 float t;
87 float a;
88
89 f = this.flags;
90
91 if (this.count & 0x80)
92 {
93 // UNSET_ONGROUND(this);
96 // the trivial movetypes do not have to match the
97 // server's ticrate as they are ticrate independent
98 // NOTE: this assumption is only true if MOVETYPE_FLY
99 // projectiles detonate on impact. If they continue
100 // moving, we might still be ticrate dependent.
101 else
103 if (!IS_ONGROUND(this))
104 if (this.velocity != '0 0 0')
105 this.angles = vectoangles(this.velocity);
106 }
107 else
108 {
110 }
111
112 if (this.count & 0x80)
113 {
114 drawn = (time >= this.spawntime - 0.02);
115 t = max(time, this.spawntime);
116 }
117 else
118 {
119 drawn = (this.iflags & IFLAG_VALID);
120 t = time;
121 }
122 bool is_nade = Projectile_isnade(this.cnt);
123
124 if (!(f & FL_ONGROUND))
125 {
126 rot = '0 0 0';
127 if (is_nade) rot = this.avelocity;
128 else switch (this.cnt)
129 {
131 rot = '0 -1000 0'; // sideways
132 break;
134 rot = '1000 0 0'; // forward
135 break;
137 rot = '0 0 720'; // spinning
138 break;
139 }
140
141 if (rot)
142 {
143 if (!rot.x && !rot.y)
144 {
145 // cheaper z-only rotation formula
146 this.angles.z = (rot.z * (t - this.spawntime)) % 360;
147 if (this.angles.z < 0)
148 this.angles.z += 360;
149 }
150 else
152 }
153 }
154
155 // negation used to ensure a zero fade_(time/rate) does not affect opacity
156 a = 1 - (time - this.fade_time) * this.fade_rate;
157 this.alpha = bound(0, this.alphamod * a, 1);
158 if (this.alpha <= 0)
159 drawn = 0;
160 this.renderflags = 0;
161
162 vector ang = this.angles;
163 ang.x = -ang.x;
164 trailorigin = this.origin;
165 if (is_nade)
166 {
168 trailorigin += v_up * 4;
169 }
170 else switch (this.cnt)
171 {
175 trailorigin += v_right * 1 + v_forward * -10;
176 break;
177 }
178
179 if (drawn)
180 Projectile_DrawTrail(this, trailorigin);
181 else
182 Projectile_ResetTrail(this, trailorigin);
183
184 this.drawmask = 0;
185
186 if (!drawn)
187 return;
188
189 switch (this.cnt)
190 {
191 // Possibly add dlights here.
192 default:
193 break;
194 }
195
196 this.drawmask = MASK_NORMAL;
197}
vector AnglesTransform_ToAngles(vector v)
vector AnglesTransform_Multiply(vector t1, vector t2)
vector AnglesTransform_FromAngles(vector v)
bool Projectile_isnade(int p)
Definition cl_nades.qc:77
float cnt
Definition powerups.qc:24
float alpha
Definition items.qc:13
float spawntime
Definition items.qh:16
float renderflags
Definition main.qh:111
const int FL_ONGROUND
Definition constants.qh:78
vector v_up
float flags
float drawmask
vector avelocity
const float MASK_NORMAL
float time
vector v_right
vector v_forward
ent angles
Definition ent_cs.qc:121
void InterpolateOrigin_Do(entity this)
set origin based on iorigin1 (old pos), iorigin2 (desired pos), and time
const int IFLAG_VALID
int iflags
float bound(float min, float value, float max)
vector vectoangles(vector v)
float max(float f,...)
void Movetype_Physics_MatchServer(entity this, bool sloppy)
Definition movetypes.qc:817
void Movetype_Physics_NoMatchServer(entity this)
Definition movetypes.qc:805
const int MOVETYPE_NONE
Definition movetypes.qh:129
float move_movetype
Definition movetypes.qh:76
const int MOVETYPE_FLY
Definition movetypes.qh:134
#define IS_ONGROUND(s)
Definition movetypes.qh:16
#define makevectors
Definition post.qh:21
void Projectile_ResetTrail(entity this, vector to)
Definition projectile.qc:24
bool autocvar_cl_projectiles_sloppy
Definition projectile.qh:5
fade_rate
Definition projectile.qh:14
const int PROJECTILE_HOOKBOMB
const int PROJECTILE_GRENADE_BOUNCING
Definition projectiles.qh:9
const int PROJECTILE_ROCKET
Definition projectiles.qh:4
const int PROJECTILE_GRENADE
Definition projectiles.qh:8
vector
Definition self.qh:92
vector vector ang
Definition self.qh:92
float fade_time
Definition common.qh:23

References alpha, ang, angles, AnglesTransform_FromAngles(), AnglesTransform_Multiply(), AnglesTransform_ToAngles(), autocvar_cl_projectiles_sloppy, avelocity, bound(), cnt, count, drawmask, entity(), fade_rate, fade_time, FL_ONGROUND, flags, IFLAG_VALID, iflags, InterpolateOrigin_Do(), IS_ONGROUND, makevectors, MASK_NORMAL, max(), move_movetype, MOVETYPE_FLY, MOVETYPE_NONE, Movetype_Physics_MatchServer(), Movetype_Physics_NoMatchServer(), origin, Projectile_DrawTrail(), PROJECTILE_GRENADE, PROJECTILE_GRENADE_BOUNCING, PROJECTILE_HOOKBOMB, Projectile_isnade(), Projectile_ResetTrail(), PROJECTILE_ROCKET, renderflags, spawntime, time, v_forward, v_right, v_up, vectoangles(), vector, and velocity.

Referenced by NET_HANDLE().

◆ Projectile_DrawTrail()

void Projectile_DrawTrail ( entity this,
vector to )

Definition at line 30 of file projectile.qc.

31{
32 vector from = this.trail_oldorigin;
33 // float t0 = this.trail_oldtime;
34 this.trail_oldorigin = to;
35 this.trail_oldtime = time;
36
37 // force the effect even for stationary firemine
38 if (this.cnt == PROJECTILE_FIREMINE)
39 if (from == to)
40 from.z += 1;
41
42 // Note: alpha value 0 actually means 1 on entities.
43 // This can be relevant when coming from CSQCModel_Effects_Apply.
44 float a = (this.alpha == 0) ? 1 : this.alpha;
45
46 // TODO: Do we actually need alpha support? Consider removing this
47 // support entirely and instead making necessary adjustments in
48 // effectinfo.
49 //
50 // Right now (2024-12-30), only Crylink can generate alpha via
51 // fade_rate/fade_time, and only PROJECTILE_PORTO_* set a fixed alpha
52 // (and reuse the Arc's TE_WIZSPIKE).
53 if (this.traileffect && a > 0)
54 {
55 float f = PARTICLES_DRAWASTRAIL;
56 if (a < 1)
57 {
58 // Do some of the fading using particle count, and some of it using alpha.
59 // Fading by particle count is less smooth but also cheaper to render.
60 // A higher power here performs more of the fading using particle count.
61 const float fade_power = 0.5;
62 particles_fade = pow(a, fade_power);
63 particles_alphamin = particles_alphamax = a / particles_fade; // == pow(a, 1 - fade_power)
65 //LOG_INFOF("particle fade: %f alpha: %f", particles_fade, particles_alphamin);
66 }
67 //else
68 // LOG_INFOF("particle fade skipped");
69
70 if (this.colormod != '0 0 0')
71 {
74 }
75 entity eff = REGISTRY_GET(Effects, this.traileffect);
76 boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, f);
77 }
78}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
vector colormod
Definition powerups.qc:21
vector particles_colormin
float particles_alphamax
vector particles_colormax
float PARTICLES_USEALPHA
float particles_alphamin
float PARTICLES_USECOLOR
float particles_fade
float PARTICLES_USEFADE
float PARTICLES_DRAWASTRAIL
#define particleeffectnum(e)
Definition effect.qh:3
#define pow(a, b)
Definition _all.inc:67
const int PROJECTILE_FIREMINE
#define REGISTRY_GET(id, i)
Definition registry.qh:43
entity this
Definition self.qh:72

References alpha, cnt, colormod, entity(), particleeffectnum, particles_alphamax, particles_alphamin, particles_colormax, particles_colormin, PARTICLES_DRAWASTRAIL, particles_fade, PARTICLES_USEALPHA, PARTICLES_USECOLOR, PARTICLES_USEFADE, pow, PROJECTILE_FIREMINE, REGISTRY_GET, time, vector, and velocity.

Referenced by CSQCModel_Effects_Apply(), Ent_RemoveProjectile(), and Projectile_Draw().

◆ Projectile_ResetTrail()

void Projectile_ResetTrail ( entity this,
vector to )

Definition at line 24 of file projectile.qc.

25{
26 this.trail_oldorigin = to;
27 this.trail_oldtime = time;
28}

References entity(), time, and vector.

Referenced by CSQCModel_Effects_Apply(), CSQCModel_Effects_PostUpdate(), and Projectile_Draw().

◆ SUB_Stop()

void SUB_Stop ( entity this,
entity toucher )

Definition at line 18 of file projectile.qc.

19{
20 this.velocity = this.avelocity = '0 0 0';
22}
void set_movetype(entity this, int mt)
Definition movetypes.qc:4

References avelocity, entity(), MOVETYPE_NONE, set_movetype(), toucher, and velocity.

Referenced by NET_HANDLE().

Variable Documentation

◆ autocvar_cl_projectiles_sloppy

bool autocvar_cl_projectiles_sloppy

Definition at line 5 of file projectile.qh.

Referenced by Projectile_Draw().

◆ fade_rate

◆ iorigin2

iorigin2