4 #include <common/net_linked.qh>
5 #include "../common/triggers/subs.qh"
6 #include "../common/triggers/triggers.qh"
8 entityclass(BGMScript);
9 class(BGMScript) .string bgmscript;
10 class(BGMScript) .float bgmscriptattack;
11 class(BGMScript) .float bgmscriptdecay;
12 class(BGMScript) .float bgmscriptsustain;
13 class(BGMScript) .float bgmscriptrelease;
15 #include "../common/constants.qh"
16 #include "../lib/csqcmodel/sv_model.qh"
20 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
25 this.colormap = (actor.team - 1) * 0x11;
30 this.colormap = floor(random() * 256);
31 this.colormap |= BIT(10); // RENDER_COLORMAPPED
34 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
36 g_model_setcolormaptoactivator(this, actor, trigger);
37 this.SendFlags |= (BIT(3) | BIT(0));
40 void g_clientmodel_use(entity this, entity actor, entity trigger)
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);
106 WriteCoord(MSG_ENTITY, this.origin.x);
107 WriteCoord(MSG_ENTITY, this.origin.y);
108 WriteCoord(MSG_ENTITY, this.origin.z);
115 WriteAngle(MSG_ENTITY, this.angles.x);
116 WriteAngle(MSG_ENTITY, this.angles.y);
117 WriteAngle(MSG_ENTITY, this.angles.z);
125 WriteShort(MSG_ENTITY, this.lodmodelindex0);
126 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
127 WriteShort(MSG_ENTITY, this.lodmodelindex1);
128 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
129 WriteShort(MSG_ENTITY, this.lodmodelindex2);
132 WriteShort(MSG_ENTITY, this.modelindex);
133 WriteByte(MSG_ENTITY, this.solid);
134 WriteShort(MSG_ENTITY, floor(this.scale * 256));
137 WriteCoord(MSG_ENTITY, this.mins.x);
138 WriteCoord(MSG_ENTITY, this.mins.y);
139 WriteCoord(MSG_ENTITY, this.mins.z);
140 WriteCoord(MSG_ENTITY, this.maxs.x);
141 WriteCoord(MSG_ENTITY, this.maxs.y);
142 WriteCoord(MSG_ENTITY, this.maxs.z);
144 WriteString(MSG_ENTITY, this.bgmscript);
145 if(this.bgmscript != "")
147 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
148 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
149 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
150 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
151 WriteCoord(MSG_ENTITY, this.movedir.x);
152 WriteCoord(MSG_ENTITY, this.movedir.y);
153 WriteCoord(MSG_ENTITY, this.movedir.z);
154 WriteByte(MSG_ENTITY, floor(this.lip * 255));
156 WriteByte(MSG_ENTITY, this.fade_start);
157 WriteByte(MSG_ENTITY, this.fade_end);
158 WriteByte(MSG_ENTITY, this.alpha_max);
159 WriteByte(MSG_ENTITY, this.alpha_min);
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)