4 #include <server/defs.qh>
5 #include <server/miscfunctions.qh>
6 #include <common/net_linked.qh>
10 entityclass(BGMScript);
11 classfield(BGMScript) .string bgmscript;
12 classfield(BGMScript) .float bgmscriptattack;
13 classfield(BGMScript) .float bgmscriptdecay;
14 classfield(BGMScript) .float bgmscriptsustain;
15 classfield(BGMScript) .float bgmscriptrelease;
17 #include <common/constants.qh>
18 #include "../../lib/csqcmodel/sv_model.qh"
22 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
27 this.colormap = (actor.team - 1) * 0x11;
32 this.colormap = floor(random() * 256);
33 this.colormap |= BIT(10); // RENDER_COLORMAPPED
36 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
38 g_model_setcolormaptoactivator(this, actor, trigger);
39 this.SendFlags |= (BIT(3) | BIT(0));
42 void g_clientmodel_use(entity this, entity actor, entity trigger)
44 if (this.antiwall_flag == 1)
47 this.solid = SOLID_NOT;
49 else if (this.antiwall_flag == 2)
52 this.solid = this.default_solid;
54 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
57 void g_model_dropbyspawnflags(entity this)
59 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
61 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
62 setorigin(this, trace_endpos);
64 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
66 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
67 setorigin(this, trace_endpos);
69 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
71 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
72 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
76 void g_clientmodel_dropbyspawnflags(entity this)
80 g_model_dropbyspawnflags(this);
85 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
88 if(this.angles != '0 0 0')
90 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
92 if(this.colormap != 0)
94 if(this.lodmodelindex1)
97 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
98 WriteByte(MSG_ENTITY, sf);
103 WriteShort(MSG_ENTITY, this.colormap);
104 WriteByte(MSG_ENTITY, this.skin);
109 WriteVector(MSG_ENTITY, this.origin);
116 WriteAngle(MSG_ENTITY, this.angles.x);
117 WriteAngle(MSG_ENTITY, this.angles.y);
118 WriteAngle(MSG_ENTITY, this.angles.z);
126 WriteShort(MSG_ENTITY, this.lodmodelindex0);
127 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
128 WriteShort(MSG_ENTITY, this.lodmodelindex1);
129 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
130 WriteShort(MSG_ENTITY, this.lodmodelindex2);
133 WriteShort(MSG_ENTITY, this.modelindex);
134 WriteByte(MSG_ENTITY, this.solid);
135 WriteShort(MSG_ENTITY, floor(this.scale * 256));
138 WriteVector(MSG_ENTITY, this.mins);
139 WriteVector(MSG_ENTITY, this.maxs);
141 WriteString(MSG_ENTITY, this.bgmscript);
142 if(this.bgmscript != "")
144 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
145 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
146 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
147 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
148 WriteVector(MSG_ENTITY, this.movedir);
149 WriteByte(MSG_ENTITY, floor(this.lip * 255));
151 WriteByte(MSG_ENTITY, this.fade_start);
152 WriteByte(MSG_ENTITY, this.fade_end);
153 WriteByte(MSG_ENTITY, this.alpha_max);
154 WriteByte(MSG_ENTITY, this.alpha_min);
155 WriteByte(MSG_ENTITY, this.inactive);
156 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
163 #define G_MODEL_INIT(ent,sol) \
164 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
165 if(!ent.scale) ent.scale = ent.modelscale; \
166 SetBrushEntityModel(ent); \
167 ent.use = g_model_setcolormaptoactivator; \
168 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
169 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT;
171 #define G_CLIENTMODEL_INIT(ent,sol) \
172 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
173 if(!ent.scale) ent.scale = ent.modelscale; \
174 SetBrushEntityModel(ent); \
175 ent.use = g_clientmodel_use; \
176 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
177 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT; \
178 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
179 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
180 ent.default_solid = sol;
182 // non-solid model entities:
183 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
184 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
185 spawnfunc(misc_models) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old compat entity with confusing name, do not use
187 // non-solid brush entities:
188 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
189 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
190 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
192 // solid brush entities
193 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
194 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
200 void Ent_Wall_PreDraw(entity this)
208 vector org = getpropertyvec(VF_ORIGIN);
209 if(!checkpvs(org, this))
211 else if(this.fade_start || this.fade_end) {
212 vector offset = '0 0 0';
213 offset_z = this.fade_vertical_offset;
214 float player_dist = vlen(org - this.origin - 0.5 * (this.mins + this.maxs) + offset);
215 if (this.fade_end == this.fade_start)
217 if (player_dist >= this.fade_start)
224 this.alpha = (this.alpha_min + this.alpha_max * bound(0,
225 (this.fade_end - player_dist)
226 / (this.fade_end - this.fade_start), 1)) / 100.0;
237 this.drawmask = MASK_NORMAL;
240 void Ent_Wall_Draw(entity this)
245 if(this.bgmscriptangular)
249 this.(fld) = this.saved;
251 if(this.lodmodelindex1)
253 if(autocvar_cl_modeldetailreduction <= 0)
255 if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
256 this.modelindex = this.lodmodelindex2;
257 else if(autocvar_cl_modeldetailreduction <= -1)
258 this.modelindex = this.lodmodelindex1;
260 this.modelindex = this.lodmodelindex0;
264 float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
265 f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
266 f *= 1.0 / bound(0.01, view_quality, 1);
267 if(this.lodmodelindex2 && f > this.loddistance2)
268 this.modelindex = this.lodmodelindex2;
269 else if(f > this.loddistance1)
270 this.modelindex = this.lodmodelindex1;
272 this.modelindex = this.lodmodelindex0;
276 InterpolateOrigin_Do(this);
278 this.saved = this.(fld);
280 f = doBGMScript(this);
283 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
284 this.alpha = 1 + this.lip * f;
285 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
286 this.alpha = 1 - this.lip * (1 - f);
287 this.(fld) = this.(fld) + this.movedir * f;
292 if(this.alpha >= ALPHA_MIN_VISIBLE)
293 this.drawmask = MASK_NORMAL;
298 void Ent_Wall_Remove(entity this)
300 strfree(this.bgmscript);
303 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
308 InterpolateOrigin_Undo(this);
309 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
311 if(this.bgmscriptangular)
315 this.(fld) = this.saved;
322 this.colormap = ReadShort();
325 this.skin = ReadByte();
330 this.origin = ReadVector();
331 setorigin(this, this.origin);
338 this.angles_x = ReadAngle();
339 this.angles_y = ReadAngle();
340 this.angles_z = ReadAngle();
343 this.angles = '0 0 0';
350 this.lodmodelindex0 = ReadShort();
351 this.loddistance1 = ReadShort();
352 this.lodmodelindex1 = ReadShort();
353 this.loddistance2 = ReadShort();
354 this.lodmodelindex2 = ReadShort();
358 this.modelindex = ReadShort();
359 this.loddistance1 = 0;
360 this.loddistance2 = 0;
362 this.solid = ReadByte();
363 this.scale = ReadShort() / 256.0;
366 this.mins = ReadVector();
367 this.maxs = ReadVector();
370 this.mins = this.maxs = '0 0 0';
371 setsize(this, this.mins, this.maxs);
373 string s = ReadString();
374 if(substring(s, 0, 1) == "<")
376 strcpy(this.bgmscript, substring(s, 1, -1));
377 this.bgmscriptangular = 1;
381 strcpy(this.bgmscript, s);
382 this.bgmscriptangular = 0;
384 if(this.bgmscript != "")
386 this.bgmscriptattack = ReadByte() / 64.0;
387 this.bgmscriptdecay = ReadByte() / 64.0;
388 this.bgmscriptsustain = ReadByte() / 255.0;
389 this.bgmscriptrelease = ReadByte() / 64.0;
390 this.movedir = ReadVector();
391 this.lip = ReadByte() / 255.0;
393 this.fade_start = ReadByte();
394 this.fade_end = ReadByte();
395 this.alpha_max = ReadByte();
396 this.alpha_min = ReadByte();
397 this.inactive = ReadByte();
398 this.fade_vertical_offset = ReadShort();
399 BGMScript_InitEntity(this);
404 InterpolateOrigin_Note(this);
406 this.saved = this.(fld);
408 this.entremove = Ent_Wall_Remove;
409 this.draw = Ent_Wall_Draw;
410 if (isnew) IL_PUSH(g_drawables, this);
411 setpredraw(this, Ent_Wall_PreDraw);