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