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) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
170 if(!ent.scale) ent.scale = ent.modelscale; \
171 SetBrushEntityModel(ent); \
172 ent.use = g_model_setcolormaptoactivator; \
173 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
174 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT;
176 #define G_CLIENTMODEL_INIT(ent,sol) \
177 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
178 if(!ent.scale) ent.scale = ent.modelscale; \
179 SetBrushEntityModel(ent); \
180 ent.use = g_clientmodel_use; \
181 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
182 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT; \
183 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
184 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
185 ent.default_solid = sol;
187 // non-solid model entities:
188 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
189 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
190 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
192 // non-solid brush entities:
193 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
194 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
195 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
197 // solid brush entities
198 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
199 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
205 void Ent_Wall_PreDraw(entity this)
207 float alph = this.alpha;
214 vector org = getpropertyvec(VF_ORIGIN);
215 if(!checkpvs(org, this))
217 else if(this.fade_start || this.fade_end) {
218 vector offset = '0 0 0';
219 offset_z = this.fade_vertical_offset;
220 vector player_dist_math = org - this.origin - 0.5 * (this.mins + this.maxs) + offset;
221 if (this.fade_end == this.fade_start)
223 if (vdist(player_dist_math, >=, this.fade_start))
230 float player_dist = vlen(player_dist_math);
231 alph = (this.alpha_min + this.alpha_max * bound(0,
232 (this.fade_end - player_dist)
233 / (this.fade_end - this.fade_start), 1)) / 100.0;
242 this.drawmask = (alph <= 0) ? 0 : MASK_NORMAL;
245 void Ent_Wall_Draw(entity this)
250 if(this.bgmscriptangular)
254 this.(fld) = this.saved;
256 if(this.lodmodelindex1)
258 if(autocvar_cl_modeldetailreduction <= 0)
260 if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
261 this.modelindex = this.lodmodelindex2;
262 else if(autocvar_cl_modeldetailreduction <= -1)
263 this.modelindex = this.lodmodelindex1;
265 this.modelindex = this.lodmodelindex0;
269 float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
270 f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
271 f *= 1.0 / bound(0.01, view_quality, 1);
272 if(this.lodmodelindex2 && f > this.loddistance2)
273 this.modelindex = this.lodmodelindex2;
274 else if(f > this.loddistance1)
275 this.modelindex = this.lodmodelindex1;
277 this.modelindex = this.lodmodelindex0;
281 InterpolateOrigin_Do(this);
283 this.saved = this.(fld);
285 f = doBGMScript(this);
288 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
289 this.alpha = 1 + this.lip * f;
290 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
291 this.alpha = 1 - this.lip * (1 - f);
292 this.(fld) = this.(fld) + this.movedir * f;
297 if(this.alpha >= ALPHA_MIN_VISIBLE)
298 this.drawmask = MASK_NORMAL;
303 void Ent_Wall_Remove(entity this)
305 strfree(this.bgmscript);
308 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
313 InterpolateOrigin_Undo(this);
314 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
316 if(this.bgmscriptangular)
320 this.(fld) = this.saved;
327 this.colormap = ReadShort();
330 this.skin = ReadByte();
335 this.origin = ReadVector();
336 setorigin(this, this.origin);
343 this.angles_x = ReadAngle();
344 this.angles_y = ReadAngle();
345 this.angles_z = ReadAngle();
348 this.angles = '0 0 0';
355 this.lodmodelindex0 = ReadShort();
356 this.loddistance1 = ReadShort();
357 this.lodmodelindex1 = ReadShort();
358 this.loddistance2 = ReadShort();
359 this.lodmodelindex2 = ReadShort();
363 this.modelindex = ReadShort();
364 this.loddistance1 = 0;
365 this.loddistance2 = 0;
367 this.solid = ReadByte();
368 this.scale = ReadShort() / 256.0;
371 this.mins = ReadVector();
372 this.maxs = ReadVector();
375 this.mins = this.maxs = '0 0 0';
376 setsize(this, this.mins, this.maxs);
378 string s = ReadString();
379 if(substring(s, 0, 1) == "<")
381 strcpy(this.bgmscript, substring(s, 1, -1));
382 this.bgmscriptangular = 1;
386 strcpy(this.bgmscript, s);
387 this.bgmscriptangular = 0;
389 if(this.bgmscript != "")
391 this.bgmscriptattack = ReadByte() / 64.0;
392 this.bgmscriptdecay = ReadByte() / 64.0;
393 this.bgmscriptsustain = ReadByte() / 255.0;
394 this.bgmscriptrelease = ReadByte() / 64.0;
395 this.movedir = ReadVector();
396 this.lip = ReadByte() / 255.0;
398 this.fade_start = ReadShort();
399 this.fade_end = ReadShort();
400 this.alpha_max = ReadByte() / 255.0;
401 this.alpha_min = ReadByte() / 255.0;
402 this.inactive = ReadByte();
403 this.fade_vertical_offset = ReadShort();
404 BGMScript_InitEntity(this);
409 InterpolateOrigin_Note(this);
411 this.saved = this.(fld);
413 this.entremove = Ent_Wall_Remove;
414 this.draw = Ent_Wall_Draw;
415 if (isnew) IL_PUSH(g_drawables, this);
416 setpredraw(this, Ent_Wall_PreDraw);