Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
util.qc
Go to the documentation of this file.
1#include "util.qh"
2
3#ifdef SVQC
4
10{
11 if (!this.tur_head)
12 {
13 LOG_DEBUG("Call to turret_tag_fire_update with this.tur_head missing!");
14 this.tur_shotorg = '0 0 0';
15 return false;
16 }
17
18 this.tur_shotorg = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_fire"));
20
21 return true;
22}
23
25void FireImoBeam(entity this, vector start, vector end, vector smin, vector smax,
26 float bforce, float f_dmg, float f_velfactor, int deathtype)
27{
28 vector dir = normalize(end - start);
29 vector force = dir * bforce;
30 end += dir; // go a little bit into the wall because we need to hit this wall later
31
32 // Trace multiple times until we hit a wall, each obstacle will be made non-solid.
33 // Note down which entities were hit so we can damage them later
34 entity o = this;
35 do
36 {
37 WarpZone_tracebox_antilag(this, start, smin, smax, end, false, o, (CS(this).antilag_debug ? CS(this).antilag_debug : ANTILAG_LATENCY(this)));
39 {
40 o = NULL;
41 continue;
42 }
43
44 // If it is NULL we can't hurt it so stop now
45 if (trace_ent == NULL || trace_fraction == 1)
46 break;
47
48 // Make the entity non-solid so we can hit the next one
50 trace_ent.railgunhit = true;
51 trace_ent.railgunhitloc = trace_endpos;
52 trace_ent.railgunhitsolidbackup = trace_ent.solid;
55
56 if (trace_ent.solid == SOLID_BSP) // stop if this is a wall
57 break;
58 trace_ent.solid = SOLID_NOT; // make the entity non-solid
59 }
60 while (true);
61
62 vector endpoint = trace_endpos;
63 entity endent = trace_ent;
64 float endq3surfaceflags = trace_dphitq3surfaceflags;
65
66 // Find all the entities the trace hit and restore their solid state
67 IL_EACH(g_railgunhit, it.railgunhit, it.solid = it.railgunhitsolidbackup);
68
69 // Unlike the railgun, this does NOT check for targets close by
70
71 // Find all the entities the trace hit and hurt them
72 IL_EACH(g_railgunhit, it.railgunhit,
73 {
74 if (it.takedamage)
75 {
76 // Apply the damage
77 // No falloff applied
78 Damage(it, this, this, f_dmg, deathtype, DMG_NOWEP, it.railgunhitloc, it.railgunforce);
79 // Slow down the target
80 it.velocity *= f_velfactor;
81 }
82
83 // Reset fields before the list is cleared
84 it.railgunhit = false;
85 it.railgunhitloc = '0 0 0';
86 it.railgunhitsolidbackup = SOLID_NOT;
87 it.railgundistance = 0;
88 });
89
91
92 // No accuracy, as a weapon entity is not attached
93
94 trace_endpos = endpoint;
95 trace_ent = endent;
96 trace_dphitq3surfaceflags = endq3surfaceflags;
97}
98
99#ifdef TURRET_DEBUG
100void marker_think(entity this)
101{
102 if (this.cnt && this.cnt < time)
103 {
104 setthink(this, SUB_Remove);
105 this.nextthink = time;
106 return;
107 }
108
109 ++this.frame;
110 if (this.frame > 29)
111 this.frame = 0;
112
113 this.nextthink = time;
114}
115
116void mark_error(vector where, float lifetime)
117{
118 entity err = new(error_marker);
119 setmodel(err, MDL_MARKER);
120 setorigin(err, where);
122 setthink(err, marker_think);
123 err.nextthink = time;
124 err.skin = 0;
125 if (lifetime)
126 err.cnt = lifetime + time;
127}
128
129void mark_info(vector where, float lifetime)
130{
131 entity err = new(info_marker);
132 setmodel(err, MDL_MARKER);
133 setorigin(err, where);
135 setthink(err, marker_think);
136 err.nextthink = time;
137 err.skin = 1;
138 if (lifetime)
139 err.cnt = lifetime + time;
140}
141
142entity mark_misc(vector where, float lifetime)
143{
144 entity err = new(mark_misc);
145 setmodel(err, MDL_MARKER);
146 setorigin(err, where);
148 setthink(err, marker_think);
149 err.nextthink = time;
150 err.skin = 3;
151 if (lifetime)
152 err.cnt = lifetime + time;
153 return err;
154}
155
156MODEL(TUR_C512, "models/turrets/c512.md3");
157
159void paint_target(entity onwho, float f_size, vector v_color, float f_time)
160{
161 entity e = spawn();
162 setmodel(e, MDL_TUR_C512);
163 e.scale = f_size / 512;
164 //setsize(e, '0 0 0', '0 0 0');
165 //setattachment(e, onwho, "");
166 setorigin(e, onwho.origin + '0 0 1');
167 e.alpha = 0.15;
169
170 e.velocity = v_color * 32; // + '0 0 1' * 64;
171
172 e.colormod = v_color;
173 SUB_SetFade(e, time, f_time);
174}
175
176void paint_target2(entity onwho, float f_size, vector v_color, float f_time)
177{
178 entity e = spawn();
179 setmodel(e, MDL_TUR_C512);
180 e.scale = f_size / 512;
181 setsize(e, '0 0 0', '0 0 0');
182
183 setorigin(e, onwho.origin + '0 0 1');
184 e.alpha = 0.15;
186
187 e.velocity = v_color * 32; // + '0 0 1' * 64;
188 e.avelocity.x = -128;
189
190 e.colormod = v_color;
191 SUB_SetFade(e, time, f_time);
192}
193
194void paint_target3(vector where, float f_size, vector v_color, float f_time)
195{
196 entity e = spawn();
197 setmodel(e, MDL_TUR_C512);
198 e.scale = f_size / 512;
199 setsize(e, '0 0 0', '0 0 0');
200 setorigin(e, where + '0 0 1');
202 e.velocity = '0 0 0';
203 e.colormod = v_color;
204 SUB_SetFade(e, time, f_time);
205}
206#endif // TURRET_DEBUG
207
208#endif // SVQC
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
float antilag_debug
Definition antilag.qc:18
void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float lag)
Definition antilag.qc:222
#define ANTILAG_LATENCY(e)
Definition antilag.qh:21
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float lifetime
Definition powerups.qc:23
float cnt
Definition powerups.qc:24
#define setmodel(this, m)
Definition model.qh:26
float turret_tag_fire_update(entity this)
Update this.tur_shotorg by getting up2date bone info NOTICE this func overwrites the global v_forward...
Definition util.qc:9
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
entity trace_ent
const float SOLID_NOT
float time
vector trace_endpos
float nextthink
float trace_dphitq3surfaceflags
vector v_forward
float trace_fraction
const float SOLID_BSP
#define spawn
void SUB_Remove(entity this)
Remove entity.
Definition defer.qh:12
#define gettagindex
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define IL_EACH(this, cond, body)
#define IL_CLEAR(this)
Remove all elements.
vector WarpZone_UnTransformOrigin(entity wz, vector org)
Transforms origin org backwards through warpzone wz, as the inverse of WarpZone_TransformOrigin.
Definition common.qc:526
vector WarpZone_TransformVelocity(entity wz, vector vel)
Transforms velocity v across warpzone wz.
Definition common.qc:495
entity WarpZone_trace_firstzone
First warpzone hit by a trace (can differ from the requested zone in case of _ThroughZone,...
Definition common.qh:41
entity WarpZone_trace_transform
Transform accumulator during a trace.
Definition common.qh:40
#define LOG_DEBUG(...)
Definition log.qh:78
float vlen(vector v)
vector normalize(vector v)
#define MODEL(name, path)
Definition all.qh:8
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:133
const int MOVETYPE_FLY
Definition movetypes.qh:138
#define NULL
Definition post.qh:14
#define gettaginfo
Definition post.qh:32
entity err
Definition promise.qc:46
#define setthink(e, f)
vector
Definition self.qh:96
int dir
Definition impulse.qc:89
ClientState CS(Client this)
Definition state.qh:47
void SUB_SetFade(entity ent, float vanish_time, float fading_time)
Definition subs.qc:77
vector tur_shotorg
Definition sv_turrets.qh:30
entity tur_head
Definition sv_turrets.qh:28
IntrusiveList g_railgunhit
Definition tracing.qh:91