4 #include "../common/triggers/subs.qh"
5 #include "../common/triggers/triggers.qh"
7 entityclass(BGMScript);
8 class(BGMScript) .string bgmscript;
9 class(BGMScript) .float bgmscriptattack;
10 class(BGMScript) .float bgmscriptdecay;
11 class(BGMScript) .float bgmscriptsustain;
12 class(BGMScript) .float bgmscriptrelease;
14 #include "../common/constants.qh"
15 #include "../lib/csqcmodel/sv_model.qh"
19 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
24 this.colormap = (actor.team - 1) * 0x11;
29 this.colormap = floor(random() * 256);
30 this.colormap |= BIT(10); // RENDER_COLORMAPPED
33 void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trigger)
35 g_model_setcolormaptoactivator(this, actor, trigger);
36 this.SendFlags |= (BIT(3) | BIT(0));
39 void g_clientmodel_use(entity this, entity actor, entity trigger)
41 if (this.antiwall_flag == 1)
44 this.solid = SOLID_NOT;
46 else if (this.antiwall_flag == 2)
49 this.solid = this.default_solid;
51 g_clientmodel_setcolormaptoactivator(this, actor, trigger);
54 void g_model_dropbyspawnflags(entity this)
56 if((this.spawnflags & 3) == 1) // ALIGN_ORIGIN
58 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
59 setorigin(this, trace_endpos);
61 else if((this.spawnflags & 3) == 2) // ALIGN_BOTTOM
63 tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
64 setorigin(this, trace_endpos);
66 else if((this.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
68 traceline(this.origin, this.origin - '0 0 4096', MOVE_NOMONSTERS, this);
69 setorigin(this, trace_endpos - '0 0 1' * this.mins.z);
73 void g_clientmodel_dropbyspawnflags(entity this)
77 g_model_dropbyspawnflags(this);
82 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
85 if(this.angles != '0 0 0')
87 if(this.mins != '0 0 0' || this.maxs != '0 0 0')
89 if(this.colormap != 0)
91 if(this.lodmodelindex1)
94 WriteHeader(MSG_ENTITY, ENT_CLIENT_WALL);
95 WriteByte(MSG_ENTITY, sf);
100 WriteShort(MSG_ENTITY, this.colormap);
105 WriteCoord(MSG_ENTITY, this.origin.x);
106 WriteCoord(MSG_ENTITY, this.origin.y);
107 WriteCoord(MSG_ENTITY, this.origin.z);
114 WriteAngle(MSG_ENTITY, this.angles.x);
115 WriteAngle(MSG_ENTITY, this.angles.y);
116 WriteAngle(MSG_ENTITY, this.angles.z);
124 WriteShort(MSG_ENTITY, this.lodmodelindex0);
125 WriteShort(MSG_ENTITY, bound(0, this.loddistance1, 65535));
126 WriteShort(MSG_ENTITY, this.lodmodelindex1);
127 WriteShort(MSG_ENTITY, bound(0, this.loddistance2, 65535));
128 WriteShort(MSG_ENTITY, this.lodmodelindex2);
131 WriteShort(MSG_ENTITY, this.modelindex);
132 WriteByte(MSG_ENTITY, this.solid);
133 WriteShort(MSG_ENTITY, floor(this.scale * 256));
136 WriteCoord(MSG_ENTITY, this.mins.x);
137 WriteCoord(MSG_ENTITY, this.mins.y);
138 WriteCoord(MSG_ENTITY, this.mins.z);
139 WriteCoord(MSG_ENTITY, this.maxs.x);
140 WriteCoord(MSG_ENTITY, this.maxs.y);
141 WriteCoord(MSG_ENTITY, this.maxs.z);
143 WriteString(MSG_ENTITY, this.bgmscript);
144 if(this.bgmscript != "")
146 WriteByte(MSG_ENTITY, floor(this.bgmscriptattack * 64));
147 WriteByte(MSG_ENTITY, floor(this.bgmscriptdecay * 64));
148 WriteByte(MSG_ENTITY, floor(this.bgmscriptsustain * 255));
149 WriteByte(MSG_ENTITY, floor(this.bgmscriptrelease * 64));
150 WriteCoord(MSG_ENTITY, this.movedir.x);
151 WriteCoord(MSG_ENTITY, this.movedir.y);
152 WriteCoord(MSG_ENTITY, this.movedir.z);
153 WriteByte(MSG_ENTITY, floor(this.lip * 255));
155 WriteShort(MSG_ENTITY, this.fade_start);
156 WriteShort(MSG_ENTITY, this.fade_end);
157 WriteShort(MSG_ENTITY, this.alpha_max);
158 WriteShort(MSG_ENTITY, this.alpha_min);
159 WriteShort(MSG_ENTITY, this.inactive);
160 WriteShort(MSG_ENTITY, this.fade_vertical_offset);
167 #define G_MODEL_INIT(ent,sol) \
168 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) ent.movetype = MOVETYPE_PHYSICS; \
169 if(!ent.scale) ent.scale = ent.modelscale; \
170 SetBrushEntityModel(); \
171 ent.use = g_model_setcolormaptoactivator; \
172 InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
173 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT;
175 #define G_CLIENTMODEL_INIT(ent,sol) \
176 if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) ent.movetype = MOVETYPE_PHYSICS; \
177 if(!ent.scale) ent.scale = ent.modelscale; \
178 SetBrushEntityModel(); \
179 ent.use = g_clientmodel_use; \
180 InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
181 if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT; \
182 if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
183 Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
184 ent.default_solid = sol;
186 // non-solid model entities:
187 spawnfunc(misc_gamemodel) { this.angles_x = -this.angles.x; G_MODEL_INIT (this, SOLID_NOT) } // model entity
188 spawnfunc(misc_clientmodel) { this.angles_x = -this.angles.x; G_CLIENTMODEL_INIT(this, SOLID_NOT) } // model entity
189 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
191 // non-solid brush entities:
192 spawnfunc(func_illusionary) { G_MODEL_INIT (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
193 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
194 spawnfunc(func_static) { G_MODEL_INIT (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
196 // solid brush entities
197 spawnfunc(func_wall) { G_MODEL_INIT (this, SOLID_BSP) } // Q1 name
198 spawnfunc(func_clientwall) { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)