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 211 of file projectile.qc.

212{
213 if (this.count & 0x80)
214 {
215 tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.05, MOVE_NORMAL, this);
217 }
218}
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:32

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 201 of file projectile.qc.

202{
203 TC(int, ch);
204 if (e.silent)
205 return;
206
207 sound(e, ch, samp, vol, attn);
208 e.snd_looping = ch;
209}
#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 82 of file projectile.qc.

83{
84 vector rot;
85 vector trailorigin;
86 int f;
87 bool drawn;
88 float t;
89 float a;
90
91 f = this.flags;
92
93 if (this.count & 0x80)
94 {
95 // UNSET_ONGROUND(this);
98 // the trivial movetypes do not have to match the
99 // server's ticrate as they are ticrate independent
100 // NOTE: this assumption is only true if MOVETYPE_FLY
101 // projectiles detonate on impact. If they continue
102 // moving, we might still be ticrate dependent.
103 else
105 if (!IS_ONGROUND(this))
106 if (this.velocity != '0 0 0')
107 this.angles = vectoangles(this.velocity);
108 }
109 else
110 {
112 }
113
114 if (this.count & 0x80)
115 {
116 drawn = (time >= this.spawntime - 0.02);
117 t = max(time, this.spawntime);
118 }
119 else
120 {
121 drawn = (this.iflags & IFLAG_VALID);
122 t = time;
123 }
124 bool is_nade = Projectile_isnade(this.csqcprojectile_type);
125
126 if (!(f & FL_ONGROUND))
127 {
128 rot = '0 0 0';
129 if (is_nade) rot = this.avelocity;
130 else switch (this.csqcprojectile_type)
131 {
133 rot = '0 -1000 0'; // sideways
134 break;
136 rot = '1000 0 0'; // forward
137 break;
139 rot = '0 0 720'; // spinning
140 break;
141 }
142
143 if (rot)
144 {
145 if (!rot.x && !rot.y)
146 {
147 // cheaper z-only rotation formula
148 this.angles.z = (rot.z * (t - this.spawntime)) % 360;
149 if (this.angles.z < 0)
150 this.angles.z += 360;
151 }
152 else
154 }
155 }
156
157 // negation used to ensure a zero fade_(time/rate) does not affect opacity
158 a = 1 - (time - this.fade_time) * this.fade_rate;
159 this.alpha = bound(0, this.alphamod * a, 1);
160 if (this.alpha <= 0)
161 drawn = 0;
162 this.renderflags = 0;
163
164 vector ang = this.angles;
165 ang.x = -ang.x;
166 trailorigin = this.origin;
167 if (is_nade)
168 {
170 trailorigin += v_up * 4;
171 }
172 else switch (this.csqcprojectile_type)
173 {
177 trailorigin += v_right * 1 + v_forward * -10;
178 break;
179 }
180
181 if (drawn)
182 Projectile_DrawTrail(this, trailorigin);
183 else
184 Projectile_ResetTrail(this, trailorigin);
185
186 this.drawmask = 0;
187
188 if (!drawn)
189 return;
190
191 switch (this.csqcprojectile_type)
192 {
193 // Possibly add dlights here.
194 default:
195 break;
196 }
197
198 this.drawmask = MASK_NORMAL;
199}
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:82
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:146
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:133
float move_movetype
Definition movetypes.qh:80
const int MOVETYPE_FLY
Definition movetypes.qh:138
#define IS_ONGROUND(s)
Definition movetypes.qh:16
#define makevectors
Definition post.qh:21
int csqcprojectile_type
Definition projectile.qc:18
void Projectile_ResetTrail(entity this, vector to)
Definition projectile.qc:26
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:96
vector vector ang
Definition self.qh:96
float fade_time
Definition common.qh:23

References alpha, ang, angles, AnglesTransform_FromAngles(), AnglesTransform_Multiply(), AnglesTransform_ToAngles(), autocvar_cl_projectiles_sloppy, avelocity, bound(), count, csqcprojectile_type, 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 32 of file projectile.qc.

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

References alpha, colormod, csqcprojectile_type, 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 26 of file projectile.qc.

27{
28 this.trail_oldorigin = to;
29 this.trail_oldtime = time;
30}

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 20 of file projectile.qc.

21{
22 this.velocity = this.avelocity = '0 0 0';
24}
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