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