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