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