4 #include <common/constants.qh>
5 #include <common/mapobjects/bgmscript.qh>
6 #include <common/mapobjects/subs.qh>
7 #include <common/mapobjects/triggers.qh>
8 #include <common/net_linked.qh>
9 #include <common/stats.qh>
10 #include <common/weapons/_all.qh>
11 #include <lib/csqcmodel/sv_model.qh>
13 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
18 this.colormap = (actor.team - 1) * 0x11;
23 this.colormap = floor(random() * 256);
24 this.colormap |= BIT(10); // RENDER_COLORMAPPED
27 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
29 g_model_setcolormaptoactivator(this, actor, trigger);
30 this.SendFlags |= (BIT(3) | BIT(0));
33 void g_clientmodel_use(entity this, entity actor, entity trigger)
35 // Flag to set func_clientwall state
36 // 1 == deactivate, 2 == activate, 0 == do nothing
37 if(this.classname == "func_clientwall" || this.classname == "func_clientillusionary")
38 this.antiwall_flag = trigger.antiwall_flag;
40 if (this.antiwall_flag == 1)
43 this.solid = SOLID_NOT;
45 else if (this.antiwall_flag == 2)
48 this.solid = this.default_solid;
50 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
53 void g_model_dropbyspawnflags(entity this)
55 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
57 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
58 setorigin(this, trace_endpos);
60 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
62 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
63 setorigin(this, trace_endpos);
65 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
67 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
68 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
72 void g_clientmodel_dropbyspawnflags(entity this)
76 g_model_dropbyspawnflags(this);
81 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
84 if(this.angles != '0 0 0')
86 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
88 if(this.colormap != 0)
90 if(this.lodmodelindex1)
93 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
94 WriteByte(MSG_ENTITY, sf);
99 WriteShort(MSG_ENTITY, this.colormap);
100 WriteByte(MSG_ENTITY, this.skin);
105 WriteVector(MSG_ENTITY, this.origin);
111 WriteAngleVector(MSG_ENTITY, this.angles);
118 WriteShort(MSG_ENTITY, this.lodmodelindex0);
119 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 32767));
120 WriteShort(MSG_ENTITY, this.lodmodelindex1);
121 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 32767));
122 WriteShort(MSG_ENTITY, this.lodmodelindex2);
125 WriteShort(MSG_ENTITY, this.modelindex);
126 WriteByte(MSG_ENTITY, this.solid);
127 WriteShort(MSG_ENTITY, floor(this.scale * 256));
130 WriteVector(MSG_ENTITY, this.mins);
131 WriteVector(MSG_ENTITY, this.maxs);
133 WriteString(MSG_ENTITY, this.bgmscript);
134 if(this.bgmscript != "")
136 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
137 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
138 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
139 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
140 WriteVector(MSG_ENTITY, this.movedir);
141 WriteByte(MSG_ENTITY, floor(this.lip * 255));
143 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 32767));
144 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
145 WriteByte(MSG_ENTITY, floor(this.alpha_max * 256));
146 WriteByte(MSG_ENTITY, floor(this.alpha_min * 256));
147 WriteByte(MSG_ENTITY, this.inactive);
148 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
155 #define G_MODEL_INIT(ent,sol) \
156 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
157 if(!ent.scale) ent.scale = ent.modelscale; \
158 SetBrushEntityModel(ent,true); \
159 ent.use = g_model_setcolormaptoactivator; \
160 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
161 if(!ent.solid) ent.solid = (sol); \
162 else if(ent.solid < 0) ent.solid = SOLID_NOT;
164 #define G_CLIENTMODEL_INIT(ent,sol) \
165 if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
166 if(!ent.scale) ent.scale = ent.modelscale; \
167 SetBrushEntityModel(ent,true); \
168 ent.use = g_clientmodel_use; \
169 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
170 if(!ent.solid) ent.solid = (sol); \
171 else if(ent.solid < 0) ent.solid = SOLID_NOT; \
172 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; \
173 else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
174 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
175 ent.default_solid = sol;
177 // non-solid model entities:
178 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
179 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
180 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
182 // non-solid brush entities:
183 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
184 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
186 // solid brush entities
187 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
188 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
189 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_BSP) } // DEPRECATED old alias name from some other game
195 void Ent_Wall_PreDraw(entity this)
197 float alph = this.alpha;
204 vector org = getpropertyvec(VF_ORIGIN);
205 if(!checkpvs(org, this))
207 else if(this.fade_start || this.fade_end) {
208 vector offset = '0 0 0';
209 offset_z = this.fade_vertical_offset;
210 vector player_dist_math = org - this.origin - 0.5 * (this.mins + this.maxs) + offset;
211 if (this.fade_end == this.fade_start)
213 if (vdist(player_dist_math, >=, this.fade_start))
220 float player_dist = vlen(player_dist_math);
221 alph = (this.alpha_min + this.alpha_max * bound(0,
222 (this.fade_end - player_dist)
223 / (this.fade_end - this.fade_start), 1)) / 100.0;
232 this.drawmask = (alph <= 0) ? 0 : MASK_NORMAL;
235 void Ent_Wall_Draw(entity this)
240 if(this.bgmscriptangular)
244 this.(fld) = this.saved;
246 if(this.lodmodelindex1)
248 if(autocvar_cl_modeldetailreduction <= 0)
250 if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
251 this.modelindex = this.lodmodelindex2;
252 else if(autocvar_cl_modeldetailreduction <= -1)
253 this.modelindex = this.lodmodelindex1;
255 this.modelindex = this.lodmodelindex0;
259 float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
260 f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
261 f *= 1.0 / bound(0.01, view_quality, 1);
262 if(this.lodmodelindex2 && f > this.loddistance2)
263 this.modelindex = this.lodmodelindex2;
264 else if(f > this.loddistance1)
265 this.modelindex = this.lodmodelindex1;
267 this.modelindex = this.lodmodelindex0;
271 InterpolateOrigin_Do(this);
273 this.saved = this.(fld);
275 f = doBGMScript(this);
278 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
279 this.alpha = 1 + this.lip * f;
280 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
281 this.alpha = 1 - this.lip * (1 - f);
282 this.(fld) = this.(fld) + this.movedir * f;
287 if(this.alpha >= ALPHA_MIN_VISIBLE)
288 this.drawmask = MASK_NORMAL;
293 void Ent_Wall_Remove(entity this)
295 strfree(this.bgmscript);
298 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
303 InterpolateOrigin_Undo(this);
304 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
306 if(this.bgmscriptangular)
310 this.(fld) = this.saved;
317 this.colormap = ReadShort();
320 this.skin = ReadByte();
325 this.origin = ReadVector();
326 setorigin(this, this.origin);
332 this.angles = ReadAngleVector();
334 this.angles = '0 0 0';
341 this.lodmodelindex0 = ReadShort();
342 this.loddistance1 = ReadShort();
343 this.lodmodelindex1 = ReadShort();
344 this.loddistance2 = ReadShort();
345 this.lodmodelindex2 = ReadShort();
349 this.modelindex = ReadShort();
350 this.loddistance1 = 0;
351 this.loddistance2 = 0;
353 this.solid = ReadByte();
354 this.scale = ReadShort() / 256.0;
357 this.mins = ReadVector();
358 this.maxs = ReadVector();
361 this.mins = this.maxs = '0 0 0';
362 setsize(this, this.mins, this.maxs);
364 string s = ReadString();
365 if(substring(s, 0, 1) == "<")
367 strcpy(this.bgmscript, substring(s, 1, -1));
368 this.bgmscriptangular = 1;
372 strcpy(this.bgmscript, s);
373 this.bgmscriptangular = 0;
375 if(this.bgmscript != "")
377 this.bgmscriptattack = ReadByte() / 64.0;
378 this.bgmscriptdecay = ReadByte() / 64.0;
379 this.bgmscriptsustain = ReadByte() / 255.0;
380 this.bgmscriptrelease = ReadByte() / 64.0;
381 this.movedir = ReadVector();
382 this.lip = ReadByte() / 255.0;
384 this.fade_start = ReadShort();
385 this.fade_end = ReadShort();
386 this.alpha_max = ReadByte() / 255.0;
387 this.alpha_min = ReadByte() / 255.0;
388 this.inactive = ReadByte();
389 this.fade_vertical_offset = ReadShort();
390 BGMScript_InitEntity(this);
395 InterpolateOrigin_Note(this);
397 this.saved = this.(fld);
399 this.entremove = Ent_Wall_Remove;
400 this.draw = Ent_Wall_Draw;
401 if (isnew) IL_PUSH(g_drawables, this);
402 setpredraw(this, Ent_Wall_PreDraw);