1 REGISTER_NET_LINKED(ENT_CLIENT_POINTPARTICLES)
4 // NOTE: also contains func_sparks
6 bool pointparticles_SendEntity(entity this, entity to, float fl)
8 WriteHeader(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
10 // optional features to save space
12 if(this.spawnflags & 2)
13 fl |= 0x10; // absolute count on toggle-on
14 if(this.movedir != '0 0 0' || this.velocity != '0 0 0')
15 fl |= 0x20; // 4 bytes - saves CPU
16 if(this.waterlevel || this.count != 1)
17 fl |= 0x40; // 4 bytes - obscure features almost never used
18 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
19 fl |= 0x80; // 14 bytes - saves lots of space
21 WriteByte(MSG_ENTITY, fl);
25 WriteCoord(MSG_ENTITY, this.impulse);
27 WriteCoord(MSG_ENTITY, 0); // off
31 WriteCoord(MSG_ENTITY, this.origin_x);
32 WriteCoord(MSG_ENTITY, this.origin_y);
33 WriteCoord(MSG_ENTITY, this.origin_z);
37 if(this.model != "null")
39 WriteShort(MSG_ENTITY, this.modelindex);
42 WriteCoord(MSG_ENTITY, this.mins_x);
43 WriteCoord(MSG_ENTITY, this.mins_y);
44 WriteCoord(MSG_ENTITY, this.mins_z);
45 WriteCoord(MSG_ENTITY, this.maxs_x);
46 WriteCoord(MSG_ENTITY, this.maxs_y);
47 WriteCoord(MSG_ENTITY, this.maxs_z);
52 WriteShort(MSG_ENTITY, 0);
55 WriteCoord(MSG_ENTITY, this.maxs_x);
56 WriteCoord(MSG_ENTITY, this.maxs_y);
57 WriteCoord(MSG_ENTITY, this.maxs_z);
60 WriteShort(MSG_ENTITY, this.cnt);
61 WriteString(MSG_ENTITY, this.mdl);
64 WriteShort(MSG_ENTITY, compressShortVector(this.velocity));
65 WriteShort(MSG_ENTITY, compressShortVector(this.movedir));
69 WriteShort(MSG_ENTITY, this.waterlevel * 16.0);
70 WriteByte(MSG_ENTITY, this.count * 16.0);
72 WriteString(MSG_ENTITY, this.noise);
75 WriteByte(MSG_ENTITY, floor(this.atten * 64));
76 WriteByte(MSG_ENTITY, floor(this.volume * 255));
78 WriteString(MSG_ENTITY, this.bgmscript);
79 if(this.bgmscript != "")
81 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
82 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
83 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
84 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
90 void pointparticles_use(entity this, entity actor, entity trigger)
92 this.state = !this.state;
96 void pointparticles_think(entity this)
98 if(this.origin != this.oldorigin)
101 this.oldorigin = this.origin;
103 this.nextthink = time;
106 void pointparticles_reset(entity this)
108 if(this.spawnflags & 1)
114 spawnfunc(func_pointparticles)
116 if(this.model != "") { precache_model(this.model); _setmodel(this, this.model); }
117 if(this.noise != "") precache_sound(this.noise);
118 if(this.mdl != "") this.cnt = 0; // use a good handler
120 if(!this.bgmscriptsustain) this.bgmscriptsustain = 1;
121 else if(this.bgmscriptsustain < 0) this.bgmscriptsustain = 0;
123 if(!this.atten) this.atten = ATTEN_NORM;
124 else if(this.atten < 0) this.atten = 0;
125 if(!this.volume) this.volume = 1;
126 if(!this.count) this.count = 1;
127 if(!this.impulse) this.impulse = 1;
131 setorigin(this, this.origin + this.mins);
132 setsize(this, '0 0 0', this.maxs - this.mins);
134 //if(!this.cnt) this.cnt = _particleeffectnum(this.mdl);
136 Net_LinkEntity(this, (this.spawnflags & 4), 0, pointparticles_SendEntity);
140 this.use = pointparticles_use;
141 this.reset = pointparticles_reset;
146 setthink(this, pointparticles_think);
147 this.nextthink = time;
150 spawnfunc(func_sparks)
152 // this.cnt is the amount of sparks that one burst will spawn
154 this.cnt = 25.0; // nice default value
157 // this.wait is the probability that a sparkthink will spawn a spark shower
158 // range: 0 - 1, but 0 makes little sense, so...
159 if(this.wait < 0.05) {
160 this.wait = 0.25; // nice default value
163 this.count = this.cnt;
166 this.velocity = '0 0 -1';
167 this.mdl = "TE_SPARK";
168 this.impulse = 10 * this.wait; // by default 2.5/sec
170 this.cnt = 0; // use mdl
172 spawnfunc_func_pointparticles(this);
176 .int dphitcontentsmask;
178 entityclass(PointParticles);
179 class(PointParticles) .int cnt; // effect number
180 class(PointParticles) .vector velocity; // particle velocity
181 class(PointParticles) .float waterlevel; // direction jitter
182 class(PointParticles) .int count; // count multiplier
183 class(PointParticles) .int impulse; // density
184 class(PointParticles) .string noise; // sound
185 class(PointParticles) .float atten;
186 class(PointParticles) .float volume;
187 class(PointParticles) .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
188 class(PointParticles) .vector movedir; // trace direction
189 class(PointParticles) .float glow_color; // palette index
191 void Draw_PointParticles(entity this)
198 sz = this.maxs - this.mins;
199 n = doBGMScript(this);
200 if(this.absolute == 2)
203 n = this.just_toggled ? this.impulse : 0;
205 n = this.impulse * drawframetime;
209 n *= this.impulse * drawframetime;
210 if(this.just_toggled)
217 for(i = random(); i <= n && fail <= 64*n; ++i)
220 p.x += random() * sz.x;
221 p.y += random() * sz.y;
222 p.z += random() * sz.z;
223 if(WarpZoneLib_BoxTouchesBrush(p, p, this, NULL))
225 if(this.movedir != '0 0 0')
227 traceline(p, p + normalize(this.movedir) * 4096, 0, NULL);
233 eff_num = _particleeffectnum(this.mdl);
234 __pointparticles(eff_num, p, trace_plane_normal * vlen(this.movedir) + this.velocity + randomvec() * this.waterlevel, this.count);
242 eff_num = _particleeffectnum(this.mdl);
243 __pointparticles(eff_num, p, this.velocity + randomvec() * this.waterlevel, this.count);
248 _sound(this, CH_AMBIENT, this.noise, VOL_BASE * this.volume, this.atten);
250 this.just_toggled = 0;
252 else if(this.absolute)
261 void Ent_PointParticles_Remove(entity this)
264 strunzone(this.noise);
265 this.noise = string_null;
267 strunzone(this.bgmscript);
268 this.bgmscript = string_null;
271 this.mdl = string_null;
274 NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew)
281 i = ReadCoord(); // density (<0: point, >0: volume)
282 if(i && !this.impulse && (this.cnt || this.mdl)) // this.cnt check is so it only happens if the ent already existed
283 this.just_toggled = 1;
288 this.origin_x = ReadCoord();
289 this.origin_y = ReadCoord();
290 this.origin_z = ReadCoord();
294 this.modelindex = ReadShort();
299 this.mins_x = ReadCoord();
300 this.mins_y = ReadCoord();
301 this.mins_z = ReadCoord();
302 this.maxs_x = ReadCoord();
303 this.maxs_y = ReadCoord();
304 this.maxs_z = ReadCoord();
309 this.maxs_x = ReadCoord();
310 this.maxs_y = ReadCoord();
311 this.maxs_z = ReadCoord();
316 this.mins = this.maxs = '0 0 0';
319 this.cnt = ReadShort(); // effect number
320 this.mdl = strzone(ReadString()); // effect string
324 this.velocity = decompressShortVector(ReadShort());
325 this.movedir = decompressShortVector(ReadShort());
329 this.velocity = this.movedir = '0 0 0';
333 this.waterlevel = ReadShort() / 16.0;
334 this.count = ReadByte() / 16.0;
342 strunzone(this.noise);
344 strunzone(this.bgmscript);
345 this.noise = strzone(ReadString());
348 this.atten = ReadByte() / 64.0;
349 this.volume = ReadByte() / 255.0;
351 this.bgmscript = strzone(ReadString());
352 if(this.bgmscript != "")
354 this.bgmscriptattack = ReadByte() / 64.0;
355 this.bgmscriptdecay = ReadByte() / 64.0;
356 this.bgmscriptsustain = ReadByte() / 255.0;
357 this.bgmscriptrelease = ReadByte() / 64.0;
359 BGMScript_InitEntity(this);
366 this.absolute = (this.impulse >= 0);
369 v = this.maxs - this.mins;
370 this.impulse *= -v.x * v.y * v.z / 262144; // relative: particles per 64^3 cube
377 setorigin(this, this.origin);
378 setsize(this, this.mins, this.maxs);
379 this.solid = SOLID_NOT;
380 this.draw = Draw_PointParticles;
381 this.entremove = Ent_PointParticles_Remove;