4 #include <server/defs.qh>
5 #include <server/miscfunctions.qh>
6 #include <server/g_subs.qh>
7 #include <common/net_linked.qh>
11 entityclass(BGMScript);
12 classfield(BGMScript) .string bgmscript;
13 classfield(BGMScript) .float bgmscriptattack;
14 classfield(BGMScript) .float bgmscriptdecay;
15 classfield(BGMScript) .float bgmscriptsustain;
16 classfield(BGMScript) .float bgmscriptrelease;
18 #include <common/constants.qh>
19 #include "../../lib/csqcmodel/sv_model.qh"
23 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
28 this.colormap = (actor.team - 1) * 0x11;
33 this.colormap = floor(random() * 256);
34 this.colormap |= BIT(10); // RENDER_COLORMAPPED
37 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
39 g_model_setcolormaptoactivator(this, actor, trigger);
40 this.SendFlags |= (BIT(3) | BIT(0));
43 void g_clientmodel_use(entity this, entity actor, entity trigger)
45 if (this.antiwall_flag == 1)
48 this.solid = SOLID_NOT;
50 else if (this.antiwall_flag == 2)
53 this.solid = this.default_solid;
55 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
58 void g_model_dropbyspawnflags(entity this)
60 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
62 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
63 setorigin(this, trace_endpos);
65 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
67 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
68 setorigin(this, trace_endpos);
70 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
72 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
73 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
77 void g_clientmodel_dropbyspawnflags(entity this)
81 g_model_dropbyspawnflags(this);
86 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
89 if(this.angles != '0 0 0')
91 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
93 if(this.colormap != 0)
95 if(this.lodmodelindex1)
98 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
99 WriteByte(MSG_ENTITY, sf);
104 WriteShort(MSG_ENTITY, this.colormap);
105 WriteByte(MSG_ENTITY, this.skin);
110 WriteVector(MSG_ENTITY, this.origin);
117 WriteAngle(MSG_ENTITY, this.angles.x);
118 WriteAngle(MSG_ENTITY, this.angles.y);
119 WriteAngle(MSG_ENTITY, this.angles.z);
127 WriteShort(MSG_ENTITY, this.lodmodelindex0);
128 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
129 WriteShort(MSG_ENTITY, this.lodmodelindex1);
130 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
131 WriteShort(MSG_ENTITY, this.lodmodelindex2);
134 WriteShort(MSG_ENTITY, this.modelindex);
135 WriteByte(MSG_ENTITY, this.solid);
136 WriteShort(MSG_ENTITY, floor(this.scale * 256));
139 WriteVector(MSG_ENTITY, this.mins);
140 WriteVector(MSG_ENTITY, this.maxs);
142 WriteString(MSG_ENTITY, this.bgmscript);
143 if(this.bgmscript != "")
145 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
146 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
147 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
148 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
149 WriteVector(MSG_ENTITY, this.movedir);
150 WriteByte(MSG_ENTITY, floor(this.lip * 255));
152 WriteByte(MSG_ENTITY, this.fade_start);
153 WriteByte(MSG_ENTITY, this.fade_end);
154 WriteByte(MSG_ENTITY, this.alpha_max);
155 WriteByte(MSG_ENTITY, this.alpha_min);
156 WriteByte(MSG_ENTITY, this.inactive);
157 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
164 #define G_MODEL_INIT(ent,sol) \
165 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
166 if(!ent.scale) ent.scale = ent.modelscale; \
167 SetBrushEntityModel(ent); \
168 ent.use = g_model_setcolormaptoactivator; \
169 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
170 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT;
172 #define G_CLIENTMODEL_INIT(ent,sol) \
173 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
174 if(!ent.scale) ent.scale = ent.modelscale; \
175 SetBrushEntityModel(ent); \
176 ent.use = g_clientmodel_use; \
177 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
178 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT; \
179 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
180 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
181 ent.default_solid = sol;
183 // non-solid model entities:
184 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
185 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
186 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
188 // non-solid brush entities:
189 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
190 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
191 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
193 // solid brush entities
194 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
195 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)