Scaled the weapon models down about 30% to match 2.5.2 sizes. Except the tuba, I...
[divverent/nexuiz.git] / data / qcsrc / server / g_models.qc
1 .float modelscale;
2
3 void g_model_setcolormaptoactivator (void)
4 {
5         if(teams_matter)
6         {
7                 if(activator.team)
8                         self.colormap = (activator.team - 1) * 0x11;
9                 else
10                         self.colormap = 0x00;
11         }
12         else
13                 self.colormap = floor(random() * 256);
14         self.colormap |= 1024; // RENDER_COLORMAPPED
15 }
16
17 void g_clientmodel_setcolormaptoactivator (void)
18 {
19         g_model_setcolormaptoactivator();
20         self.SendFlags |= 1;
21 }
22
23 void g_model_dropbyspawnflags()
24 {
25         if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
26         {
27                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
28                 setorigin(self, trace_endpos);
29         }
30         else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
31         {
32                 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
33                 setorigin(self, trace_endpos);
34         }
35         else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
36         {
37                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
38                 setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
39         }
40 }
41
42 void g_clientmodel_dropbyspawnflags()
43 {
44         vector o0;
45         o0 = self.origin;
46         g_model_dropbyspawnflags();
47         if(self.origin != o0)
48                 self.SendFlags |= 2;
49 }
50
51 float g_clientmodel_genericsendentity (entity to, float sf)
52 {
53         sf = sf & 0x0F;
54         if(self.angles != '0 0 0')
55                 sf |= 0x10;
56         if(self.solid && (self.mins != '0 0 0' || self.maxs != '0 0 0'))
57                 sf |= 0x20;
58         if(self.colormap != 0)
59                 sf |= 0x40;
60         
61         WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
62         WriteByte(MSG_ENTITY, sf);
63
64         if(sf & 1)
65         {
66                 if(sf & 0x40)
67                         WriteShort(MSG_ENTITY, self.colormap);
68         }
69
70         if(sf & 2)
71         {
72                 WriteCoord(MSG_ENTITY, self.origin_x);
73                 WriteCoord(MSG_ENTITY, self.origin_y);
74                 WriteCoord(MSG_ENTITY, self.origin_z);
75         }
76
77         if(sf & 4)
78         {
79                 if(sf & 0x10)
80                 {
81                         WriteAngle(MSG_ENTITY, self.angles_x);
82                         WriteAngle(MSG_ENTITY, self.angles_y);
83                         WriteAngle(MSG_ENTITY, self.angles_z);
84                 }
85         }
86
87         if(sf & 8)
88         {
89                 WriteShort(MSG_ENTITY, self.modelindex);
90                 WriteByte(MSG_ENTITY, self.solid);
91                 WriteByte(MSG_ENTITY, floor(self.scale * 16));
92                 if(sf & 0x20)
93                 {
94                         WriteCoord(MSG_ENTITY, self.mins_x);
95                         WriteCoord(MSG_ENTITY, self.mins_y);
96                         WriteCoord(MSG_ENTITY, self.mins_z);
97                         WriteCoord(MSG_ENTITY, self.maxs_x);
98                         WriteCoord(MSG_ENTITY, self.maxs_y);
99                         WriteCoord(MSG_ENTITY, self.maxs_z);
100                 }
101                 WriteString(MSG_ENTITY, self.bgmscript);
102                 if(self.bgmscript != "")
103                 {
104                         WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
105                         WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
106                         WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
107                         WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
108                         WriteCoord(MSG_ENTITY, self.movedir_x);
109                         WriteCoord(MSG_ENTITY, self.movedir_y);
110                         WriteCoord(MSG_ENTITY, self.movedir_z);
111                         WriteByte(MSG_ENTITY, floor(self.lip * 255));
112                 }
113         }
114
115         return TRUE;
116 }
117
118
119 #define G_MODEL_INIT(sol) \
120         SetBrushEntityModel(); \
121         if(!self.scale) self.scale = self.modelscale; \
122         self.use = g_model_setcolormaptoactivator; \
123         InitializeEntity(self, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
124         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT;
125
126 #define G_CLIENTMODEL_INIT(sol) \
127         SetBrushEntityModelNoLOD(); \
128         if(!self.scale) self.scale = self.modelscale; \
129         self.use = g_clientmodel_setcolormaptoactivator; \
130         InitializeEntity(self, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
131         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT; \
132         if(!self.bgmscriptsustain) self.bgmscriptsustain = 1; else if(self.bgmscriptsustain < 0) self.bgmscriptsustain = 0; \
133         Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
134
135 // non-solid model entities:
136 void spawnfunc_misc_gamemodel()         { G_MODEL_INIT      (SOLID_NOT) } // model entity
137 void spawnfunc_misc_clientmodel()       { G_CLIENTMODEL_INIT(SOLID_NOT) } // model entity
138 void spawnfunc_misc_models()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old compat entity with confusing name, do not use
139
140 // non-solid brush entities:
141 void spawnfunc_func_illusionary()       { G_MODEL_INIT      (SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
142 void spawnfunc_func_clientillusionary() { G_CLIENTMODEL_INIT(SOLID_NOT) } // brush entity
143 void spawnfunc_func_static()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old alias name from some other game
144
145 // solid brush entities
146 void spawnfunc_func_wall()              { G_MODEL_INIT      (SOLID_BSP) } // Q1 name
147 void spawnfunc_func_clientwall()        { G_CLIENTMODEL_INIT(SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)