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
31 // go a little bit into the wall because we need to hit this wall later
32 end += dir;
33
34 // trace multiple times until we hit a wall, each obstacle will be made unsolid.
35 // note down which entities were hit so we can damage them later
36 entity o = this;
37 while (1)
38 {
39 WarpZone_tracebox_antilag(this, start, smin, smax, end, false, o, (CS(this).antilag_debug ? CS(this).antilag_debug : ANTILAG_LATENCY(this)));
41 {
42 o = NULL;
43 continue;
44 }
45
46 // if it is NULL we can't hurt it so stop now
47 if (trace_ent == NULL || trace_fraction == 1)
48 break;
49
50 // make the entity non-solid so we can hit the next one
52 trace_ent.railgunhit = true;
53 trace_ent.railgunhitloc = end;
54 trace_ent.railgunhitsolidbackup = trace_ent.solid;
57
58 // stop if this is a wall
59 if (trace_ent.solid == SOLID_BSP)
60 break;
61
62 // make the entity non-solid
63 trace_ent.solid = SOLID_NOT;
64 }
65
66 vector endpoint = trace_endpos;
67 entity endent = trace_ent;
68 float endq3surfaceflags = trace_dphitq3surfaceflags;
69
70 // find all the entities the railgun hit and restore their solid state
71 IL_EACH(g_railgunhit, it.railgunhit, it.solid = it.railgunhitsolidbackup);
72
73 // Unlike the railgun, this does NOT check for targets close by
74
75 // find all the entities the railgun hit and hurt them
76 IL_EACH(g_railgunhit, it.railgunhit,
77 {
78 // removal from the list is handled below
79 // no falloff applied
80
81 // apply the damage
82 if (it.takedamage)
83 {
84 Damage(it, this, this, f_dmg, deathtype, DMG_NOWEP, it.railgunhitloc, it.railgunforce);
85 // slow down the target
86 it.velocity *= f_velfactor;
87 }
88
89 it.railgunhitloc = '0 0 0';
90 it.railgunhitsolidbackup = SOLID_NOT;
91 it.railgunhit = false;
92 it.railgundistance = 0;
93 });
94
96
97 // no accuracy, as a weapon entity is not attached
98
99 trace_endpos = endpoint;
100 trace_ent = endent;
101 trace_dphitq3surfaceflags = endq3surfaceflags;
102}
103
104#ifdef TURRET_DEBUG
105void marker_think(entity this)
106{
107 if (this.cnt && this.cnt < time)
108 {
109 setthink(this, SUB_Remove);
110 this.nextthink = time;
111 return;
112 }
113
114 ++this.frame;
115 if (this.frame > 29)
116 this.frame = 0;
117
118 this.nextthink = time;
119}
120
121void mark_error(vector where, float lifetime)
122{
123 entity err = new(error_marker);
124 setmodel(err, MDL_MARKER);
125 setorigin(err, where);
127 setthink(err, marker_think);
128 err.nextthink = time;
129 err.skin = 0;
130 if (lifetime)
131 err.cnt = lifetime + time;
132}
133
134void mark_info(vector where, float lifetime)
135{
136 entity err = new(info_marker);
137 setmodel(err, MDL_MARKER);
138 setorigin(err, where);
140 setthink(err, marker_think);
141 err.nextthink = time;
142 err.skin = 1;
143 if (lifetime)
144 err.cnt = lifetime + time;
145}
146
147entity mark_misc(vector where, float lifetime)
148{
149 entity err = new(mark_misc);
150 setmodel(err, MDL_MARKER);
151 setorigin(err, where);
153 setthink(err, marker_think);
154 err.nextthink = time;
155 err.skin = 3;
156 if (lifetime)
157 err.cnt = lifetime + time;
158 return err;
159}
160
161MODEL(TUR_C512, "models/turrets/c512.md3");
162
164void paint_target(entity onwho, float f_size, vector v_color, float f_time)
165{
166 entity e = spawn();
167 setmodel(e, MDL_TUR_C512);
168 e.scale = f_size / 512;
169 //setsize(e, '0 0 0', '0 0 0');
170 //setattachment(e, onwho, "");
171 setorigin(e, onwho.origin + '0 0 1');
172 e.alpha = 0.15;
174
175 e.velocity = v_color * 32; // + '0 0 1' * 64;
176
177 e.colormod = v_color;
178 SUB_SetFade(e, time, f_time);
179}
180
181void paint_target2(entity onwho, float f_size, vector v_color, float f_time)
182{
183 entity e = spawn();
184 setmodel(e, MDL_TUR_C512);
185 e.scale = f_size / 512;
186 setsize(e, '0 0 0', '0 0 0');
187
188 setorigin(e, onwho.origin + '0 0 1');
189 e.alpha = 0.15;
191
192 e.velocity = v_color * 32; // + '0 0 1' * 64;
193 e.avelocity.x = -128;
194
195 e.colormod = v_color;
196 SUB_SetFade(e, time, f_time);
197}
198
199void paint_target3(vector where, float f_size, vector v_color, float f_time)
200{
201 entity e = spawn();
202 setmodel(e, MDL_TUR_C512);
203 e.scale = f_size / 512;
204 setsize(e, '0 0 0', '0 0 0');
205 setorigin(e, where + '0 0 1');
207 e.velocity = '0 0 0';
208 e.colormod = v_color;
209 SUB_SetFade(e, time, f_time);
210}
211#endif // TURRET_DEBUG
212
213#endif // SVQC
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
float antilag_debug
Definition antilag.qc:19
void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
Definition antilag.qc:228
#define ANTILAG_LATENCY(e)
Definition antilag.qh:19
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:13
#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_TransformVelocity(entity wz, vector v)
Definition common.qc:514
vector WarpZone_UnTransformOrigin(entity wz, vector v)
Definition common.qc:544
entity WarpZone_trace_firstzone
Definition common.qh:38
entity WarpZone_trace_transform
Definition common.qh:37
#define LOG_DEBUG(...)
Definition log.qh:80
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:129
const int MOVETYPE_FLY
Definition movetypes.qh:134
#define NULL
Definition post.qh:14
#define gettaginfo
Definition post.qh:32
entity err
Definition promise.qc:44
#define setthink(e, f)
vector
Definition self.qh:92
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:89