4 #include <common/weapons/_all.qh>
5 #include <common/stats.qh>
6 #include <server/miscfunctions.qh>
7 #include <common/net_linked.qh>
10 #include "bgmscript.qh"
12 #include <common/constants.qh>
13 #include <lib/csqcmodel/sv_model.qh>
15 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
20 this.colormap = (actor.team - 1) * 0x11;
25 this.colormap = floor(random() * 256);
26 this.colormap |= BIT(10); // RENDER_COLORMAPPED
29 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
31 g_model_setcolormaptoactivator(this, actor, trigger);
32 this.SendFlags |= (BIT(3) | BIT(0));
35 void g_clientmodel_use(entity this, entity actor, entity trigger)
37 // Flag to set func_clientwall state
38 // 1 == deactivate, 2 == activate, 0 == do nothing
39 if(this.classname == "func_clientwall" || this.classname == "func_clientillusionary")
40 this.antiwall_flag = trigger.antiwall_flag;
42 if (this.antiwall_flag == 1)
45 this.solid = SOLID_NOT;
47 else if (this.antiwall_flag == 2)
50 this.solid = this.default_solid;
52 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
55 void g_model_dropbyspawnflags(entity this)
57 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
59 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
60 setorigin(this, trace_endpos);
62 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
64 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
65 setorigin(this, trace_endpos);
67 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
69 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
70 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
74 void g_clientmodel_dropbyspawnflags(entity this)
78 g_model_dropbyspawnflags(this);
83 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
86 if(this.angles != '0 0 0')
88 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
90 if(this.colormap != 0)
92 if(this.lodmodelindex1)
95 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
96 WriteByte(MSG_ENTITY, sf);
101 WriteShort(MSG_ENTITY, this.colormap);
102 WriteByte(MSG_ENTITY, this.skin);
107 WriteVector(MSG_ENTITY, this.origin);
113 WriteAngleVector(MSG_ENTITY, this.angles);
120 WriteShort(MSG_ENTITY, this.lodmodelindex0);
121 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
122 WriteShort(MSG_ENTITY, this.lodmodelindex1);
123 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
124 WriteShort(MSG_ENTITY, this.lodmodelindex2);
127 WriteShort(MSG_ENTITY, this.modelindex);
128 WriteByte(MSG_ENTITY, this.solid);
129 WriteShort(MSG_ENTITY, floor(this.scale * 256));
132 WriteVector(MSG_ENTITY, this.mins);
133 WriteVector(MSG_ENTITY, this.maxs);
135 WriteString(MSG_ENTITY, this.bgmscript);
136 if(this.bgmscript != "")
138 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
139 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
140 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
141 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
142 WriteVector(MSG_ENTITY, this.movedir);
143 WriteByte(MSG_ENTITY, floor(this.lip * 255));
145 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 65535));
146 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 65535));
147 WriteByte(MSG_ENTITY, floor(this.alpha_max * 256));
148 WriteByte(MSG_ENTITY, floor(this.alpha_min * 256));
149 WriteByte(MSG_ENTITY, this.inactive);
150 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
157 #define G_MODEL_INIT(ent,sol) \
158 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
159 if(!ent.scale) ent.scale = ent.modelscale; \
160 SetBrushEntityModel(ent,true); \
161 ent.use = g_model_setcolormaptoactivator; \
162 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
163 if(!ent.solid) ent.solid = (sol); \
164 else if(ent.solid < 0) ent.solid = SOLID_NOT;
166 #define G_CLIENTMODEL_INIT(ent,sol) \
167 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
168 if(!ent.scale) ent.scale = ent.modelscale; \
169 SetBrushEntityModel(ent,true); \
170 ent.use = g_clientmodel_use; \
171 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
172 if(!ent.solid) ent.solid = (sol); \
173 else if(ent.solid < 0) ent.solid = SOLID_NOT; \
174 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; \
175 else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
176 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
177 ent.default_solid = sol;
179 // non-solid model entities:
180 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
181 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
182 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
184 // non-solid brush entities:
185 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
186 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
188 // solid brush entities
189 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
190 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
191 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_BSP) } // DEPRECATED old alias name from some other game
197 void Ent_Wall_PreDraw(entity this)
199 float alph = this.alpha;
206 vector org = getpropertyvec(VF_ORIGIN);
207 if(!checkpvs(org, this))
209 else if(this.fade_start || this.fade_end) {
210 vector offset = '0 0 0';
211 offset_z = this.fade_vertical_offset;
212 vector player_dist_math = org - this.origin - 0.5 * (this.mins + this.maxs) + offset;
213 if (this.fade_end == this.fade_start)
215 if (vdist(player_dist_math, >=, this.fade_start))
222 float player_dist = vlen(player_dist_math);
223 alph = (this.alpha_min + this.alpha_max * bound(0,
224 (this.fade_end - player_dist)
225 / (this.fade_end - this.fade_start), 1)) / 100.0;
234 this.drawmask = (alph <= 0) ? 0 : MASK_NORMAL;
237 void Ent_Wall_Draw(entity this)
242 if(this.bgmscriptangular)
246 this.(fld) = this.saved;
248 if(this.lodmodelindex1)
250 if(autocvar_cl_modeldetailreduction <= 0)
252 if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
253 this.modelindex = this.lodmodelindex2;
254 else if(autocvar_cl_modeldetailreduction <= -1)
255 this.modelindex = this.lodmodelindex1;
257 this.modelindex = this.lodmodelindex0;
261 float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
262 f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
263 f *= 1.0 / bound(0.01, view_quality, 1);
264 if(this.lodmodelindex2 && f > this.loddistance2)
265 this.modelindex = this.lodmodelindex2;
266 else if(f > this.loddistance1)
267 this.modelindex = this.lodmodelindex1;
269 this.modelindex = this.lodmodelindex0;
273 InterpolateOrigin_Do(this);
275 this.saved = this.(fld);
277 f = doBGMScript(this);
280 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
281 this.alpha = 1 + this.lip * f;
282 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
283 this.alpha = 1 - this.lip * (1 - f);
284 this.(fld) = this.(fld) + this.movedir * f;
289 if(this.alpha >= ALPHA_MIN_VISIBLE)
290 this.drawmask = MASK_NORMAL;
295 void Ent_Wall_Remove(entity this)
297 strfree(this.bgmscript);
300 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
305 InterpolateOrigin_Undo(this);
306 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
308 if(this.bgmscriptangular)
312 this.(fld) = this.saved;
319 this.colormap = ReadShort();
322 this.skin = ReadByte();
327 this.origin = ReadVector();
328 setorigin(this, this.origin);
334 this.angles = ReadAngleVector();
336 this.angles = '0 0 0';
343 this.lodmodelindex0 = ReadShort();
344 this.loddistance1 = ReadShort();
345 this.lodmodelindex1 = ReadShort();
346 this.loddistance2 = ReadShort();
347 this.lodmodelindex2 = ReadShort();
351 this.modelindex = ReadShort();
352 this.loddistance1 = 0;
353 this.loddistance2 = 0;
355 this.solid = ReadByte();
356 this.scale = ReadShort() / 256.0;
359 this.mins = ReadVector();
360 this.maxs = ReadVector();
363 this.mins = this.maxs = '0 0 0';
364 setsize(this, this.mins, this.maxs);
366 string s = ReadString();
367 if(substring(s, 0, 1) == "<")
369 strcpy(this.bgmscript, substring(s, 1, -1));
370 this.bgmscriptangular = 1;
374 strcpy(this.bgmscript, s);
375 this.bgmscriptangular = 0;
377 if(this.bgmscript != "")
379 this.bgmscriptattack = ReadByte() / 64.0;
380 this.bgmscriptdecay = ReadByte() / 64.0;
381 this.bgmscriptsustain = ReadByte() / 255.0;
382 this.bgmscriptrelease = ReadByte() / 64.0;
383 this.movedir = ReadVector();
384 this.lip = ReadByte() / 255.0;
386 this.fade_start = ReadShort();
387 this.fade_end = ReadShort();
388 this.alpha_max = ReadByte() / 255.0;
389 this.alpha_min = ReadByte() / 255.0;
390 this.inactive = ReadByte();
391 this.fade_vertical_offset = ReadShort();
392 BGMScript_InitEntity(this);
397 InterpolateOrigin_Note(this);
399 this.saved = this.(fld);
401 this.entremove = Ent_Wall_Remove;
402 this.draw = Ent_Wall_Draw;
403 if (isnew) IL_PUSH(g_drawables, this);
404 setpredraw(this, Ent_Wall_PreDraw);