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