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