+REGISTER_NET_LINKED(ENT_CLIENT_POINTPARTICLES)
+
#ifdef SVQC
// NOTE: also contains func_sparks
-float pointparticles_SendEntity(entity to, float fl)
+bool pointparticles_SendEntity(entity this, entity to, float fl)
{
- WriteByte(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
+ WriteHeader(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
// optional features to save space
fl = fl & 0x0F;
}
void pointparticles_use()
-{
+{SELFPARAM();
self.state = !self.state;
self.SendFlags |= 2;
}
void pointparticles_think()
-{
+{SELFPARAM();
if(self.origin != self.oldorigin)
{
self.SendFlags |= 4;
self.nextthink = time;
}
-void pointparticles_reset()
+void pointparticles_reset(entity this)
{
- if(self.spawnflags & 1)
- self.state = 1;
+ if(this.spawnflags & 1)
+ this.state = 1;
else
- self.state = 0;
+ this.state = 0;
}
-void spawnfunc_func_pointparticles()
+spawnfunc(func_pointparticles)
{
- if(self.model != "")
- setmodel(self, self.model);
- if(self.noise != "")
- precache_sound (self.noise);
-
- if(!self.bgmscriptsustain)
- self.bgmscriptsustain = 1;
- else if(self.bgmscriptsustain < 0)
- self.bgmscriptsustain = 0;
-
- if(!self.atten)
- self.atten = ATTEN_NORM;
- else if(self.atten < 0)
- self.atten = 0;
- if(!self.volume)
- self.volume = 1;
- if(!self.count)
- self.count = 1;
- if(!self.impulse)
- self.impulse = 1;
-
- if(!self.modelindex)
+ if(this.model != "") _setmodel(this, this.model);
+ if(this.noise != "") precache_sound(this.noise);
+
+ if(!this.bgmscriptsustain) this.bgmscriptsustain = 1;
+ else if(this.bgmscriptsustain < 0) this.bgmscriptsustain = 0;
+
+ if(!this.atten) this.atten = ATTEN_NORM;
+ else if(this.atten < 0) this.atten = 0;
+ if(!this.volume) this.volume = 1;
+ if(!this.count) this.count = 1;
+ if(!this.impulse) this.impulse = 1;
+
+ if(!this.modelindex)
{
- setorigin(self, self.origin + self.mins);
- setsize(self, '0 0 0', self.maxs - self.mins);
+ setorigin(this, this.origin + this.mins);
+ setsize(this, '0 0 0', this.maxs - this.mins);
}
- if(!self.cnt)
- self.cnt = particleeffectnum(self.mdl);
+ if(!this.cnt) this.cnt = _particleeffectnum(this.mdl);
- Net_LinkEntity(self, (self.spawnflags & 4), 0, pointparticles_SendEntity);
+ Net_LinkEntity(this, (this.spawnflags & 4), 0, pointparticles_SendEntity);
IFTARGETED
{
- self.use = pointparticles_use;
- self.reset = pointparticles_reset;
- self.reset();
+ this.use = pointparticles_use;
+ this.reset = pointparticles_reset;
+ this.reset(this);
}
else
- self.state = 1;
- self.think = pointparticles_think;
- self.nextthink = time;
+ this.state = 1;
+ this.think = pointparticles_think;
+ this.nextthink = time;
}
-void spawnfunc_func_sparks()
+spawnfunc(func_sparks)
{
// self.cnt is the amount of sparks that one burst will spawn
if(self.cnt < 1) {
self.wait = 0;
self.cnt = 0; // use mdl
- spawnfunc_func_pointparticles();
+ spawnfunc_func_pointparticles(this);
+}
+#elif defined(CSQC)
+
+.int dphitcontentsmask;
+
+entityclass(PointParticles);
+class(PointParticles) .int cnt; // effect number
+class(PointParticles) .vector velocity; // particle velocity
+class(PointParticles) .float waterlevel; // direction jitter
+class(PointParticles) .int count; // count multiplier
+class(PointParticles) .int impulse; // density
+class(PointParticles) .string noise; // sound
+class(PointParticles) .float atten;
+class(PointParticles) .float volume;
+class(PointParticles) .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
+class(PointParticles) .vector movedir; // trace direction
+class(PointParticles) .float glow_color; // palette index
+
+void Draw_PointParticles(entity this)
+{
+ float n, i, fail;
+ vector p;
+ vector sz;
+ vector o;
+ o = self.origin;
+ sz = self.maxs - self.mins;
+ n = doBGMScript(self);
+ if(self.absolute == 2)
+ {
+ if(n >= 0)
+ n = self.just_toggled ? self.impulse : 0;
+ else
+ n = self.impulse * drawframetime;
+ }
+ else
+ {
+ n *= self.impulse * drawframetime;
+ if(self.just_toggled)
+ if(n < 1)
+ n = 1;
+ }
+ if(n == 0)
+ return;
+ fail = 0;
+ for(i = random(); i <= n && fail <= 64*n; ++i)
+ {
+ p = o + self.mins;
+ p.x += random() * sz.x;
+ p.y += random() * sz.y;
+ p.z += random() * sz.z;
+ if(WarpZoneLib_BoxTouchesBrush(p, p, self, world))
+ {
+ if(self.movedir != '0 0 0')
+ {
+ traceline(p, p + normalize(self.movedir) * 4096, 0, world);
+ p = trace_endpos;
+ __pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count);
+ }
+ else
+ {
+ __pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count);
+ }
+ if(self.noise != "")
+ {
+ setorigin(self, p);
+ _sound(self, CH_AMBIENT, self.noise, VOL_BASE * self.volume, self.atten);
+ }
+ self.just_toggled = 0;
+ }
+ else if(self.absolute)
+ {
+ ++fail;
+ --i;
+ }
+ }
+ setorigin(self, o);
+}
+
+void Ent_PointParticles_Remove()
+{SELFPARAM();
+ if(self.noise)
+ strunzone(self.noise);
+ self.noise = string_null;
+ if(self.bgmscript)
+ strunzone(self.bgmscript);
+ self.bgmscript = string_null;
+}
+
+NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew)
+{
+ float i;
+ vector v;
+ int f = ReadByte();
+ if(f & 2)
+ {
+ i = ReadCoord(); // density (<0: point, >0: volume)
+ if(i && !self.impulse && self.cnt) // self.cnt check is so it only happens if the ent already existed
+ self.just_toggled = 1;
+ self.impulse = i;
+ }
+ if(f & 4)
+ {
+ self.origin_x = ReadCoord();
+ self.origin_y = ReadCoord();
+ self.origin_z = ReadCoord();
+ }
+ if(f & 1)
+ {
+ self.modelindex = ReadShort();
+ if(f & 0x80)
+ {
+ if(self.modelindex)
+ {
+ self.mins_x = ReadCoord();
+ self.mins_y = ReadCoord();
+ self.mins_z = ReadCoord();
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ }
+ else
+ {
+ self.mins = '0 0 0';
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ }
+ }
+ else
+ {
+ self.mins = self.maxs = '0 0 0';
+ }
+
+ self.cnt = ReadShort(); // effect number
+
+ if(f & 0x20)
+ {
+ self.velocity = decompressShortVector(ReadShort());
+ self.movedir = decompressShortVector(ReadShort());
+ }
+ else
+ {
+ self.velocity = self.movedir = '0 0 0';
+ }
+ if(f & 0x40)
+ {
+ self.waterlevel = ReadShort() / 16.0;
+ self.count = ReadByte() / 16.0;
+ }
+ else
+ {
+ self.waterlevel = 0;
+ self.count = 1;
+ }
+ if(self.noise)
+ strunzone(self.noise);
+ if(self.bgmscript)
+ strunzone(self.bgmscript);
+ self.noise = strzone(ReadString());
+ if(self.noise != "")
+ {
+ self.atten = ReadByte() / 64.0;
+ self.volume = ReadByte() / 255.0;
+ }
+ self.bgmscript = strzone(ReadString());
+ if(self.bgmscript != "")
+ {
+ self.bgmscriptattack = ReadByte() / 64.0;
+ self.bgmscriptdecay = ReadByte() / 64.0;
+ self.bgmscriptsustain = ReadByte() / 255.0;
+ self.bgmscriptrelease = ReadByte() / 64.0;
+ }
+ BGMScript_InitEntity(self);
+ }
+
+ return = true;
+
+ if(f & 2)
+ {
+ self.absolute = (self.impulse >= 0);
+ if(!self.absolute)
+ {
+ v = self.maxs - self.mins;
+ self.impulse *= -v.x * v.y * v.z / 262144; // relative: particles per 64^3 cube
+ }
+ }
+
+ if(f & 0x10)
+ self.absolute = 2;
+
+ setorigin(self, self.origin);
+ setsize(self, self.mins, self.maxs);
+ self.solid = SOLID_NOT;
+ self.draw = Draw_PointParticles;
+ self.entremove = Ent_PointParticles_Remove;
}
#endif