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