]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_models.qc
Merge master into qc_physics_prehax (blame TimePath if it's completely broken)
[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 |= 1;
30 }
31
32 void g_model_dropbyspawnflags()
33 {
34         if((self.spawnflags & 3) == 1) // ALIGN_ORIGIN
35         {
36                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
37                 setorigin(self, trace_endpos);
38         }
39         else if((self.spawnflags & 3) == 2) // ALIGN_BOTTOM
40         {
41                 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
42                 setorigin(self, trace_endpos);
43         }
44         else if((self.spawnflags & 3) == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
45         {
46                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
47                 setorigin(self, trace_endpos - '0 0 1' * self.mins.z);
48         }
49 }
50
51 void g_clientmodel_dropbyspawnflags()
52 {
53         vector o0;
54         o0 = self.origin;
55         g_model_dropbyspawnflags();
56         if(self.origin != o0)
57                 self.SendFlags |= 2;
58 }
59
60 float g_clientmodel_genericsendentity (entity to, int sf)
61 {
62         sf = sf & 0x0F;
63         if(self.angles != '0 0 0')
64                 sf |= 0x10;
65         if(self.solid && (self.mins != '0 0 0' || self.maxs != '0 0 0'))
66                 sf |= 0x20;
67         if(self.colormap != 0)
68                 sf |= 0x40;
69         if(self.lodmodelindex1)
70                 sf |= 0x80;
71
72         WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
73         WriteByte(MSG_ENTITY, sf);
74
75         if(sf & 1)
76         {
77                 if(sf & 0x40)
78                         WriteShort(MSG_ENTITY, self.colormap);
79         }
80
81         if(sf & 2)
82         {
83                 WriteCoord(MSG_ENTITY, self.origin.x);
84                 WriteCoord(MSG_ENTITY, self.origin.y);
85                 WriteCoord(MSG_ENTITY, self.origin.z);
86         }
87
88         if(sf & 4)
89         {
90                 if(sf & 0x10)
91                 {
92                         WriteAngle(MSG_ENTITY, self.angles.x);
93                         WriteAngle(MSG_ENTITY, self.angles.y);
94                         WriteAngle(MSG_ENTITY, self.angles.z);
95                 }
96         }
97
98         if(sf & 8)
99         {
100                 if(sf & 0x80)
101                 {
102                         WriteShort(MSG_ENTITY, self.lodmodelindex0);
103                         WriteShort(MSG_ENTITY, bound(0, self.loddistance1, 65535));
104                         WriteShort(MSG_ENTITY, self.lodmodelindex1);
105                         WriteShort(MSG_ENTITY, bound(0, self.loddistance2, 65535));
106                         WriteShort(MSG_ENTITY, self.lodmodelindex2);
107                 }
108                 else
109                         WriteShort(MSG_ENTITY, self.modelindex);
110                 WriteByte(MSG_ENTITY, self.solid);
111                 WriteShort(MSG_ENTITY, floor(self.scale * 256));
112                 if(sf & 0x20)
113                 {
114                         WriteCoord(MSG_ENTITY, self.mins.x);
115                         WriteCoord(MSG_ENTITY, self.mins.y);
116                         WriteCoord(MSG_ENTITY, self.mins.z);
117                         WriteCoord(MSG_ENTITY, self.maxs.x);
118                         WriteCoord(MSG_ENTITY, self.maxs.y);
119                         WriteCoord(MSG_ENTITY, self.maxs.z);
120                 }
121                 WriteString(MSG_ENTITY, self.bgmscript);
122                 if(self.bgmscript != "")
123                 {
124                         WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
125                         WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
126                         WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
127                         WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
128                         WriteCoord(MSG_ENTITY, self.movedir.x);
129                         WriteCoord(MSG_ENTITY, self.movedir.y);
130                         WriteCoord(MSG_ENTITY, self.movedir.z);
131                         WriteByte(MSG_ENTITY, floor(self.lip * 255));
132                 }
133         }
134
135         return true;
136 }
137
138
139 #define G_MODEL_INIT(sol) \
140         if(self.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) self.movetype = MOVETYPE_PHYSICS; \
141         if(!self.scale) self.scale = self.modelscale; \
142         SetBrushEntityModel(); \
143         self.use = g_model_setcolormaptoactivator; \
144         InitializeEntity(self, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
145         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT;
146
147 #define G_CLIENTMODEL_INIT(sol) \
148         if(self.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) self.movetype = MOVETYPE_PHYSICS; \
149         if(!self.scale) self.scale = self.modelscale; \
150         SetBrushEntityModel(); \
151         self.use = g_clientmodel_setcolormaptoactivator; \
152         InitializeEntity(self, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
153         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT; \
154         if(!self.bgmscriptsustain) self.bgmscriptsustain = 1; else if(self.bgmscriptsustain < 0) self.bgmscriptsustain = 0; \
155         Net_LinkEntity(self, true, 0, g_clientmodel_genericsendentity);
156
157 // non-solid model entities:
158 void spawnfunc_misc_gamemodel()         { self.angles_x = -self.angles.x; G_MODEL_INIT      (SOLID_NOT) } // model entity
159 void spawnfunc_misc_clientmodel()       { self.angles_x = -self.angles.x; G_CLIENTMODEL_INIT(SOLID_NOT) } // model entity
160 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
161
162 // non-solid brush entities:
163 void spawnfunc_func_illusionary()       { G_MODEL_INIT      (SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
164 void spawnfunc_func_clientillusionary() { G_CLIENTMODEL_INIT(SOLID_NOT) } // brush entity
165 void spawnfunc_func_static()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old alias name from some other game
166
167 // solid brush entities
168 void spawnfunc_func_wall()              { G_MODEL_INIT      (SOLID_BSP) } // Q1 name
169 void spawnfunc_func_clientwall()        { G_CLIENTMODEL_INIT(SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)