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

Go to the source code of this file.

Functions

bool laser_SendEntity (entity this, entity to, float sendflags)
void laser_setactive (entity this, int act)
void laser_use (entity this, entity actor, entity trigger)
void misc_laser_aim (entity this)
void misc_laser_init (entity this)
void misc_laser_think (entity this)
 spawnfunc (misc_laser)

Variables

entity pusher

Function Documentation

◆ laser_SendEntity()

bool laser_SendEntity ( entity this,
entity to,
float sendflags )

Definition at line 123 of file laser.qc.

124{
125 WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER);
126 sendflags = sendflags & 0x0F; // use that bit to indicate finite length laser
127 if(this.spawnflags & LASER_FINITE)
128 sendflags |= SF_LASER_FINITE;
129 if(this.alpha)
130 sendflags |= SF_LASER_ALPHA;
131 if(this.scale != 1 || this.modelscale != 1)
132 sendflags |= SF_LASER_SCALE;
133 if(this.spawnflags & LASER_NOTRACE)
134 sendflags |= SF_LASER_NOTRACE;
135 WriteByte(MSG_ENTITY, sendflags);
136 if(sendflags & SF_LASER_UPDATE_ORIGIN)
137 {
138 WriteVector(MSG_ENTITY, this.origin);
139 }
140 if(sendflags & SF_LASER_UPDATE_EFFECT)
141 {
142 WriteByte(MSG_ENTITY, this.beam_color.x * 255.0);
143 WriteByte(MSG_ENTITY, this.beam_color.y * 255.0);
144 WriteByte(MSG_ENTITY, this.beam_color.z * 255.0);
145 if(sendflags & SF_LASER_ALPHA)
146 WriteByte(MSG_ENTITY, this.alpha * 255.0);
147 if(sendflags & SF_LASER_SCALE)
148 {
149 WriteByte(MSG_ENTITY, bound(0, this.scale * 16.0, 255));
150 WriteByte(MSG_ENTITY, bound(0, this.modelscale * 16.0, 255));
151 }
152 if((sendflags & SF_LASER_FINITE) || !(sendflags & SF_LASER_NOTRACE)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
154 }
155 if(sendflags & SF_LASER_UPDATE_TARGET)
156 {
157 if(sendflags & SF_LASER_FINITE)
158 {
159 WriteVector(MSG_ENTITY, this.enemy.origin);
160 }
161 else
162 {
163 WriteAngleVector2D(MSG_ENTITY, this.mangle);
164 }
165 }
166 if(sendflags & SF_LASER_UPDATE_ACTIVE)
168 return true;
169}
float cnt
Definition powerups.qc:24
float alpha
Definition items.qc:13
int spawnflags
Definition ammo.qh:15
vector origin
int active
Definition defs.qh:34
const int LASER_NOTRACE
Definition laser.qh:17
const int SF_LASER_NOTRACE
Definition laser.qh:25
const int SF_LASER_FINITE
Definition laser.qh:28
vector beam_color
Definition laser.qh:30
const int SF_LASER_UPDATE_EFFECT
Definition laser.qh:23
const int SF_LASER_UPDATE_ACTIVE
Definition laser.qh:22
const int SF_LASER_UPDATE_TARGET
Definition laser.qh:21
const int LASER_FINITE
Definition laser.qh:16
const int SF_LASER_ALPHA
Definition laser.qh:27
const int SF_LASER_UPDATE_ORIGIN
Definition laser.qh:20
const int SF_LASER_SCALE
Definition laser.qh:26
const int MSG_ENTITY
Definition net.qh:115
#define WriteHeader(to, id)
Definition net.qh:221
float bound(float min, float value, float max)
void WriteShort(float data, float dest, float desto)
void WriteByte(float data, float dest, float desto)
float modelscale
Definition models.qh:3
float scale
Definition projectile.qc:14
vector mangle
Definition subs.qh:51
entity enemy
Definition sv_ctf.qh:153

References active, alpha, beam_color, bound(), cnt, enemy, entity(), LASER_FINITE, LASER_NOTRACE, mangle, modelscale, MSG_ENTITY, origin, scale, SF_LASER_ALPHA, SF_LASER_FINITE, SF_LASER_NOTRACE, SF_LASER_SCALE, SF_LASER_UPDATE_ACTIVE, SF_LASER_UPDATE_EFFECT, SF_LASER_UPDATE_ORIGIN, SF_LASER_UPDATE_TARGET, spawnflags, WriteByte(), WriteHeader, and WriteShort().

Referenced by spawnfunc().

◆ laser_setactive()

void laser_setactive ( entity this,
int act )

Definition at line 184 of file laser.qc.

185{
186 int old_status = this.active;
187 if(act == ACTIVE_TOGGLE)
188 {
189 if(this.active == ACTIVE_ACTIVE)
190 {
191 this.active = ACTIVE_NOT;
192 }
193 else
194 {
195 this.active = ACTIVE_ACTIVE;
196 }
197 }
198 else
199 {
200 this.active = act;
201 }
202
203 if (this.active != old_status)
204 {
206 misc_laser_aim(this);
207 }
208}
const int ACTIVE_TOGGLE
Definition defs.qh:40
const int ACTIVE_NOT
Definition defs.qh:36
const int ACTIVE_ACTIVE
Definition defs.qh:37
void misc_laser_aim(entity this)
Definition laser.qc:12
int SendFlags
Definition net.qh:118

References active, ACTIVE_ACTIVE, ACTIVE_NOT, ACTIVE_TOGGLE, entity(), misc_laser_aim(), SendFlags, and SF_LASER_UPDATE_ACTIVE.

Referenced by spawnfunc().

◆ laser_use()

void laser_use ( entity this,
entity actor,
entity trigger )

Definition at line 210 of file laser.qc.

211{
212 this.setactive(this, ACTIVE_TOGGLE);
213}

References ACTIVE_TOGGLE, and entity().

Referenced by spawnfunc().

◆ misc_laser_aim()

void misc_laser_aim ( entity this)

Definition at line 12 of file laser.qc.

13{
14 vector a;
15 if(this.enemy)
16 {
17 if(this.spawnflags & LASER_FINITE)
18 {
19 if(this.enemy.origin != this.mangle)
20 {
21 this.mangle = this.enemy.origin;
23 }
24 }
25 else
26 {
27 a = vectoangles(this.enemy.origin - this.origin);
28 a_x = -a_x;
29 if(a != this.mangle)
30 {
31 this.mangle = a;
33 }
34 }
35 }
36 else
37 {
38 if(this.angles != this.mangle)
39 {
40 this.mangle = this.angles;
42 }
43 }
44 if(this.origin != this.oldorigin)
45 {
47 this.oldorigin = this.origin;
48 }
49}
vector oldorigin
ent angles
Definition ent_cs.qc:121
vector vectoangles(vector v)
vector
Definition self.qh:92

References angles, enemy, entity(), LASER_FINITE, mangle, oldorigin, origin, SendFlags, SF_LASER_UPDATE_ORIGIN, SF_LASER_UPDATE_TARGET, spawnflags, vectoangles(), and vector.

Referenced by laser_setactive(), and misc_laser_think().

◆ misc_laser_init()

void misc_laser_init ( entity this)

Definition at line 51 of file laser.qc.

52{
53 if(this.target != "")
54 this.enemy = find(NULL, targetname, this.target);
55}
entity find(entity start,.string field, string match)
#define NULL
Definition post.qh:14
string targetname
Definition triggers.qh:56
string target
Definition triggers.qh:55

References enemy, entity(), find(), NULL, target, and targetname.

Referenced by spawnfunc().

◆ misc_laser_think()

void misc_laser_think ( entity this)

Definition at line 58 of file laser.qc.

59{
60 vector o;
61 entity hitent;
62 vector hitloc;
63
64 this.nextthink = time;
65
66 if(this.active == ACTIVE_NOT)
67 return;
68
69 misc_laser_aim(this);
70
71 if(this.enemy)
72 {
73 o = this.enemy.origin;
74 if (!(this.spawnflags & LASER_FINITE))
75 o = this.origin + normalize(o - this.origin) * LASER_BEAM_MAXLENGTH;
76 }
77 else
78 {
79 makevectors(this.mangle);
81 }
82
83 if(this.dmg || this.enemy.target != "")
84 {
85 traceline(this.origin, o, MOVE_NORMAL, this);
86 }
87 hitent = trace_ent;
88 hitloc = trace_endpos;
89
90 if(this.enemy.target != "") // DETECTOR laser
91 {
92 if(trace_ent.iscreature)
93 {
94 this.pusher = hitent;
95 if(!this.count)
96 {
97 this.count = 1;
98
99 SUB_UseTargets(this.enemy, this.enemy.pusher, NULL);
100 }
101 }
102 else
103 {
104 if(this.count)
105 {
106 this.count = 0;
107
108 SUB_UseTargets(this.enemy, this.enemy.pusher, NULL);
109 }
110 }
111 }
112
113 if(this.dmg)
114 {
115 if(this.team)
116 if(((this.spawnflags & LASER_INVERT_TEAM) == 0) == (this.team != hitent.team))
117 return;
118 if(hitent.takedamage)
119 Damage(hitent, this, this, ((this.dmg < 0) ? 100000 : (this.dmg * frametime)), DEATH_HURTTRIGGER.m_id, DMG_NOWEP, hitloc, '0 0 0');
120 }
121}
float dmg
Definition breakable.qc:12
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float count
Definition powerups.qc:22
int team
Definition main.qh:188
entity trace_ent
float frametime
const float MOVE_NORMAL
float time
vector trace_endpos
float nextthink
vector v_forward
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition damage.qc:503
#define DMG_NOWEP
Definition damage.qh:104
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
entity pusher
Definition laser.qc:57
const float LASER_BEAM_MAXLENGTH
Definition laser.qh:32
const int LASER_INVERT_TEAM
Definition laser.qh:18
vector normalize(vector v)
#define makevectors
Definition post.qh:21

References active, ACTIVE_NOT, count, Damage(), dmg, DMG_NOWEP, enemy, entity(), frametime, LASER_BEAM_MAXLENGTH, LASER_FINITE, LASER_INVERT_TEAM, makevectors, mangle, misc_laser_aim(), MOVE_NORMAL, nextthink, normalize(), NULL, origin, pusher, spawnflags, SUB_UseTargets(), team, time, trace_endpos, trace_ent, v_forward, and vector.

Referenced by spawnfunc().

◆ spawnfunc()

spawnfunc ( misc_laser )

Definition at line 215 of file laser.qc.

216{
217 if(this.mdl)
218 {
219 if(this.mdl == "none")
220 this.cnt = -1;
221 else
222 {
223 this.cnt = _particleeffectnum(this.mdl);
224 if(this.cnt < 0 && this.dmg)
225 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
226 }
227 }
228 else if(!this.cnt)
229 {
230 if(this.dmg)
231 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
232 else
233 this.cnt = -1;
234 }
235 if(this.cnt < 0)
236 this.cnt = -1;
237
238 if(!this.beam_color && this.colormod)
239 {
240 LOG_WARN("misc_laser uses legacy field 'colormod', please use 'beam_color' instead");
241 this.beam_color = this.colormod;
242 }
243
244 if(this.beam_color == '0 0 0')
245 {
246 if(!this.alpha)
247 this.beam_color = '1 0 0';
248 }
249
250 if(this.message == "")
251 {
252 this.message = "saw the light";
253 }
254 if (this.message2 == "")
255 {
256 this.message2 = "was pushed into a laser by";
257 }
258 if(!this.scale)
259 {
260 this.scale = 1;
261 }
262 if(!this.modelscale)
263 {
264 this.modelscale = 1;
265 }
266 else if(this.modelscale < 0)
267 {
268 this.modelscale = 0;
269 }
271 this.nextthink = time;
273
274 this.mangle = this.angles;
275
276 Net_LinkEntity(this, false, 0, laser_SendEntity);
277
278 this.setactive = laser_setactive;
279
280 if(this.targetname && this.targetname != "")
281 {
282 // backwards compatibility
283 this.use = laser_use;
284 }
285
286 this.reset = generic_netlinked_reset;
287 this.reset(this);
288}
string message
Definition powerups.qc:19
vector colormod
Definition powerups.qc:21
string mdl
Definition item.qh:89
const int INITPRIO_FINDTARGET
Definition constants.qh:96
#define use
#define particleeffectnum(e)
Definition effect.qh:3
void misc_laser_think(entity this)
Definition laser.qc:58
void laser_setactive(entity this, int act)
Definition laser.qc:184
bool laser_SendEntity(entity this, entity to, float sendflags)
Definition laser.qc:123
void laser_use(entity this, entity actor, entity trigger)
Definition laser.qc:210
void misc_laser_init(entity this)
Definition laser.qc:51
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:123
#define LOG_WARN(...)
Definition log.qh:61
#define setthink(e, f)
void generic_netlinked_reset(entity this)
Definition triggers.qc:76
string message2
Definition triggers.qh:19
void InitializeEntity(entity e, void(entity this) func, int order)
Definition world.qc:2209

References alpha, angles, beam_color, cnt, colormod, dmg, generic_netlinked_reset(), InitializeEntity(), INITPRIO_FINDTARGET, laser_SendEntity(), laser_setactive(), laser_use(), LOG_WARN, mangle, mdl, message, message2, misc_laser_init(), misc_laser_think(), modelscale, Net_LinkEntity(), nextthink, particleeffectnum, scale, setthink, targetname, time, and use.

Variable Documentation

◆ pusher

entity pusher

Definition at line 57 of file laser.qc.

Referenced by _GlobalSound(), football_touch(), InitBall(), misc_laser_think(), and PlayerDamage().