]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_models.qc
#includes: cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_models.qc
1 #include "_all.qh"
2
3 #include "../common/triggers/subs.qh"
4
5 entityclass(BGMScript);
6 class(BGMScript) .string bgmscript;
7 class(BGMScript) .float bgmscriptattack;
8 class(BGMScript) .float bgmscriptdecay;
9 class(BGMScript) .float bgmscriptsustain;
10 class(BGMScript) .float bgmscriptrelease;
11
12 #include "../common/constants.qh"
13 #include "../csqcmodellib/sv_model.qh"
14
15 .float modelscale;
16
17 void g_model_setcolormaptoactivator (void)
18 {SELFPARAM();
19         if(teamplay)
20         {
21                 if(activator.team)
22                         self.colormap = (activator.team - 1) * 0x11;
23                 else
24                         self.colormap = 0x00;
25         }
26         else
27                 self.colormap = floor(random() * 256);
28         self.colormap |= 1024; // RENDER_COLORMAPPED
29 }
30
31 void g_clientmodel_setcolormaptoactivator (void)
32 {SELFPARAM();
33         g_model_setcolormaptoactivator();
34         self.SendFlags |= (8 | 1);
35 }
36
37 void g_clientmodel_use(void)
38 {SELFPARAM();
39         if (self.antiwall_flag == 1)
40         {
41                 self.inactive = 1;
42                 self.solid = SOLID_NOT;
43         }
44         else if (self.antiwall_flag == 2)
45         {
46                 self.inactive = 0;
47                 self.solid = self.default_solid;
48         }
49         g_clientmodel_setcolormaptoactivator();
50 }
51
52 void g_model_dropbyspawnflags()
53 {SELFPARAM();
54         if((self.spawnflags & 3) == 1) // ALIGN_ORIGIN
55         {
56                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
57                 setorigin(self, trace_endpos);
58         }
59         else if((self.spawnflags & 3) == 2) // ALIGN_BOTTOM
60         {
61                 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
62                 setorigin(self, trace_endpos);
63         }
64         else if((self.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
65         {
66                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
67                 setorigin(self, trace_endpos - '0 0 1' * self.mins.z);
68         }
69 }
70
71 void g_clientmodel_dropbyspawnflags()
72 {SELFPARAM();
73         vector o0;
74         o0 = self.origin;
75         g_model_dropbyspawnflags();
76         if(self.origin != o0)
77                 self.SendFlags |= 2;
78 }
79
80 bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
81 {
82         sf = sf & 0x0F;
83         if(self.angles != '0 0 0')
84                 sf |= 0x10;
85         if(self.mins != '0 0 0' || self.maxs != '0 0 0')
86                 sf |= 0x20;
87         if(self.colormap != 0)
88                 sf |= 0x40;
89         if(self.lodmodelindex1)
90                 sf |= 0x80;
91
92         WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
93         WriteByte(MSG_ENTITY, sf);
94
95         if(sf & 1)
96         {
97                 if(sf & 0x40)
98                         WriteShort(MSG_ENTITY, self.colormap);
99         }
100
101         if(sf & 2)
102         {
103                 WriteCoord(MSG_ENTITY, self.origin.x);
104                 WriteCoord(MSG_ENTITY, self.origin.y);
105                 WriteCoord(MSG_ENTITY, self.origin.z);
106         }
107
108         if(sf & 4)
109         {
110                 if(sf & 0x10)
111                 {
112                         WriteAngle(MSG_ENTITY, self.angles.x);
113                         WriteAngle(MSG_ENTITY, self.angles.y);
114                         WriteAngle(MSG_ENTITY, self.angles.z);
115                 }
116         }
117
118         if(sf & 8)
119         {
120                 if(sf & 0x80)
121                 {
122                         WriteShort(MSG_ENTITY, self.lodmodelindex0);
123                         WriteShort(MSG_ENTITY, bound(0, self.loddistance1, 65535));
124                         WriteShort(MSG_ENTITY, self.lodmodelindex1);
125                         WriteShort(MSG_ENTITY, bound(0, self.loddistance2, 65535));
126                         WriteShort(MSG_ENTITY, self.lodmodelindex2);
127                 }
128                 else
129                         WriteShort(MSG_ENTITY, self.modelindex);
130                 WriteByte(MSG_ENTITY, self.solid);
131                 WriteShort(MSG_ENTITY, floor(self.scale * 256));
132                 if(sf & 0x20)
133                 {
134                         WriteCoord(MSG_ENTITY, self.mins.x);
135                         WriteCoord(MSG_ENTITY, self.mins.y);
136                         WriteCoord(MSG_ENTITY, self.mins.z);
137                         WriteCoord(MSG_ENTITY, self.maxs.x);
138                         WriteCoord(MSG_ENTITY, self.maxs.y);
139                         WriteCoord(MSG_ENTITY, self.maxs.z);
140                 }
141                 WriteString(MSG_ENTITY, self.bgmscript);
142                 if(self.bgmscript != "")
143                 {
144                         WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
145                         WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
146                         WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
147                         WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
148                         WriteCoord(MSG_ENTITY, self.movedir.x);
149                         WriteCoord(MSG_ENTITY, self.movedir.y);
150                         WriteCoord(MSG_ENTITY, self.movedir.z);
151                         WriteByte(MSG_ENTITY, floor(self.lip * 255));
152                 }
153                 WriteShort(MSG_ENTITY, self.fade_start);
154                 WriteShort(MSG_ENTITY, self.fade_end);
155                 WriteShort(MSG_ENTITY, self.alpha_max);
156                 WriteShort(MSG_ENTITY, self.alpha_min);
157                 WriteShort(MSG_ENTITY, self.inactive);
158                 WriteShort(MSG_ENTITY, self.fade_vertical_offset);
159         }
160
161         return true;
162 }
163
164
165 #define G_MODEL_INIT(sol) \
166         if(self.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) self.movetype = MOVETYPE_PHYSICS; \
167         if(!self.scale) self.scale = self.modelscale; \
168         SetBrushEntityModel(); \
169         self.use = g_model_setcolormaptoactivator; \
170         InitializeEntity(self, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
171         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT;
172
173 #define G_CLIENTMODEL_INIT(sol) \
174         if(self.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) self.movetype = MOVETYPE_PHYSICS; \
175         if(!self.scale) self.scale = self.modelscale; \
176         SetBrushEntityModel(); \
177         self.use = g_clientmodel_use; \
178         InitializeEntity(self, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
179         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT; \
180         if(!self.bgmscriptsustain) self.bgmscriptsustain = 1; else if(self.bgmscriptsustain < 0) self.bgmscriptsustain = 0; \
181         Net_LinkEntity(self, true, 0, g_clientmodel_genericsendentity); \
182         self.default_solid = sol;
183
184 // non-solid model entities:
185 spawnfunc(misc_gamemodel)         { self.angles_x = -self.angles.x; G_MODEL_INIT      (SOLID_NOT) } // model entity
186 spawnfunc(misc_clientmodel)       { self.angles_x = -self.angles.x; G_CLIENTMODEL_INIT(SOLID_NOT) } // model entity
187 spawnfunc(misc_models)            { self.angles_x = -self.angles.x; G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old compat entity with confusing name, do not use
188
189 // non-solid brush entities:
190 spawnfunc(func_illusionary)       { G_MODEL_INIT      (SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
191 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(SOLID_NOT) } // brush entity
192 spawnfunc(func_static)            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old alias name from some other game
193
194 // solid brush entities
195 spawnfunc(func_wall)              { G_MODEL_INIT      (SOLID_BSP) } // Q1 name
196 spawnfunc(func_clientwall)        { G_CLIENTMODEL_INIT(SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)