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 // Flag to set func_clientwall state
45 // 1 == deactivate, 2 == activate, 0 == do nothing
46 if(this.classname == "func_clientwall" || this.classname == "func_clientillusionary")
47 this.antiwall_flag = trigger.antiwall_flag;
49 if (this.antiwall_flag == 1)
52 this.solid = SOLID_NOT;
54 else if (this.antiwall_flag == 2)
57 this.solid = this.default_solid;
59 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
62 void g_model_dropbyspawnflags(entity this)
64 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
66 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
67 setorigin(this, trace_endpos);
69 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
71 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
72 setorigin(this, trace_endpos);
74 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
76 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
77 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
81 void g_clientmodel_dropbyspawnflags(entity this)
85 g_model_dropbyspawnflags(this);
90 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
93 if(this.angles != '0 0 0')
95 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
97 if(this.colormap != 0)
99 if(this.lodmodelindex1)
102 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
103 WriteByte(MSG_ENTITY, sf);
108 WriteShort(MSG_ENTITY, this.colormap);
109 WriteByte(MSG_ENTITY, this.skin);
114 WriteVector(MSG_ENTITY, this.origin);
121 WriteAngle(MSG_ENTITY, this.angles.x);
122 WriteAngle(MSG_ENTITY, this.angles.y);
123 WriteAngle(MSG_ENTITY, this.angles.z);
131 WriteShort(MSG_ENTITY, this.lodmodelindex0);
132 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
133 WriteShort(MSG_ENTITY, this.lodmodelindex1);
134 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
135 WriteShort(MSG_ENTITY, this.lodmodelindex2);
138 WriteShort(MSG_ENTITY, this.modelindex);
139 WriteByte(MSG_ENTITY, this.solid);
140 WriteShort(MSG_ENTITY, floor(this.scale * 256));
143 WriteVector(MSG_ENTITY, this.mins);
144 WriteVector(MSG_ENTITY, this.maxs);
146 WriteString(MSG_ENTITY, this.bgmscript);
147 if(this.bgmscript != "")
149 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
150 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
151 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
152 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
153 WriteVector(MSG_ENTITY, this.movedir);
154 WriteByte(MSG_ENTITY, floor(this.lip * 255));
156 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 65535));
157 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 65535));
158 WriteByte(MSG_ENTITY, floor(this.alpha_max * 256));
159 WriteByte(MSG_ENTITY, floor(this.alpha_min * 256));
160 WriteByte(MSG_ENTITY, this.inactive);
161 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
168 #define G_MODEL_INIT(ent,sol) \
169 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
170 if(!ent.scale) ent.scale = ent.modelscale; \
171 SetBrushEntityModel(ent,true); \
172 ent.use = g_model_setcolormaptoactivator; \
173 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
174 if(!ent.solid) ent.solid = (sol); \
175 else if(ent.solid < 0) ent.solid = SOLID_NOT;
177 #define G_CLIENTMODEL_INIT(ent,sol) \
178 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
179 if(!ent.scale) ent.scale = ent.modelscale; \
180 SetBrushEntityModel(ent,true); \
181 ent.use = g_clientmodel_use; \
182 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
183 if(!ent.solid) ent.solid = (sol); \
184 else if(ent.solid < 0) ent.solid = SOLID_NOT; \
185 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; \
186 else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
187 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
188 ent.default_solid = sol;
190 // non-solid model entities:
191 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
192 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
193 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
195 // non-solid brush entities:
196 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
197 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
198 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
200 // solid brush entities
201 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
202 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
208 void Ent_Wall_PreDraw(entity this)
210 float alph = this.alpha;
217 vector org = getpropertyvec(VF_ORIGIN);
218 if(!checkpvs(org, this))
220 else if(this.fade_start || this.fade_end) {
221 vector offset = '0 0 0';
222 offset_z = this.fade_vertical_offset;
223 vector player_dist_math = org - this.origin - 0.5 * (this.mins + this.maxs) + offset;
224 if (this.fade_end == this.fade_start)
226 if (vdist(player_dist_math, >=, this.fade_start))
233 float player_dist = vlen(player_dist_math);
234 alph = (this.alpha_min + this.alpha_max * bound(0,
235 (this.fade_end - player_dist)
236 / (this.fade_end - this.fade_start), 1)) / 100.0;
245 this.drawmask = (alph <= 0) ? 0 : MASK_NORMAL;
248 void Ent_Wall_Draw(entity this)
253 if(this.bgmscriptangular)
257 this.(fld) = this.saved;
259 if(this.lodmodelindex1)
261 if(autocvar_cl_modeldetailreduction <= 0)
263 if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
264 this.modelindex = this.lodmodelindex2;
265 else if(autocvar_cl_modeldetailreduction <= -1)
266 this.modelindex = this.lodmodelindex1;
268 this.modelindex = this.lodmodelindex0;
272 float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
273 f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
274 f *= 1.0 / bound(0.01, view_quality, 1);
275 if(this.lodmodelindex2 && f > this.loddistance2)
276 this.modelindex = this.lodmodelindex2;
277 else if(f > this.loddistance1)
278 this.modelindex = this.lodmodelindex1;
280 this.modelindex = this.lodmodelindex0;
284 InterpolateOrigin_Do(this);
286 this.saved = this.(fld);
288 f = doBGMScript(this);
291 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
292 this.alpha = 1 + this.lip * f;
293 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
294 this.alpha = 1 - this.lip * (1 - f);
295 this.(fld) = this.(fld) + this.movedir * f;
300 if(this.alpha >= ALPHA_MIN_VISIBLE)
301 this.drawmask = MASK_NORMAL;
306 void Ent_Wall_Remove(entity this)
308 strfree(this.bgmscript);
311 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
316 InterpolateOrigin_Undo(this);
317 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
319 if(this.bgmscriptangular)
323 this.(fld) = this.saved;
330 this.colormap = ReadShort();
333 this.skin = ReadByte();
338 this.origin = ReadVector();
339 setorigin(this, this.origin);
346 this.angles_x = ReadAngle();
347 this.angles_y = ReadAngle();
348 this.angles_z = ReadAngle();
351 this.angles = '0 0 0';
358 this.lodmodelindex0 = ReadShort();
359 this.loddistance1 = ReadShort();
360 this.lodmodelindex1 = ReadShort();
361 this.loddistance2 = ReadShort();
362 this.lodmodelindex2 = ReadShort();
366 this.modelindex = ReadShort();
367 this.loddistance1 = 0;
368 this.loddistance2 = 0;
370 this.solid = ReadByte();
371 this.scale = ReadShort() / 256.0;
374 this.mins = ReadVector();
375 this.maxs = ReadVector();
378 this.mins = this.maxs = '0 0 0';
379 setsize(this, this.mins, this.maxs);
381 string s = ReadString();
382 if(substring(s, 0, 1) == "<")
384 strcpy(this.bgmscript, substring(s, 1, -1));
385 this.bgmscriptangular = 1;
389 strcpy(this.bgmscript, s);
390 this.bgmscriptangular = 0;
392 if(this.bgmscript != "")
394 this.bgmscriptattack = ReadByte() / 64.0;
395 this.bgmscriptdecay = ReadByte() / 64.0;
396 this.bgmscriptsustain = ReadByte() / 255.0;
397 this.bgmscriptrelease = ReadByte() / 64.0;
398 this.movedir = ReadVector();
399 this.lip = ReadByte() / 255.0;
401 this.fade_start = ReadShort();
402 this.fade_end = ReadShort();
403 this.alpha_max = ReadByte() / 255.0;
404 this.alpha_min = ReadByte() / 255.0;
405 this.inactive = ReadByte();
406 this.fade_vertical_offset = ReadShort();
407 BGMScript_InitEntity(this);
412 InterpolateOrigin_Note(this);
414 this.saved = this.(fld);
416 this.entremove = Ent_Wall_Remove;
417 this.draw = Ent_Wall_Draw;
418 if (isnew) IL_PUSH(g_drawables, this);
419 setpredraw(this, Ent_Wall_PreDraw);