]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/g_models.qc
fix the finish CTS kill delay
[xonotic/xonotic-data.pk3dir.git] / 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         if(self.lodmodelindex1)
61                 sf |= 0x80;
62         
63         WriteByte(MSG_ENTITY, ENT_CLIENT_WALL);
64         WriteByte(MSG_ENTITY, sf);
65
66         if(sf & 1)
67         {
68                 if(sf & 0x40)
69                         WriteShort(MSG_ENTITY, self.colormap);
70         }
71
72         if(sf & 2)
73         {
74                 WriteCoord(MSG_ENTITY, self.origin_x);
75                 WriteCoord(MSG_ENTITY, self.origin_y);
76                 WriteCoord(MSG_ENTITY, self.origin_z);
77         }
78
79         if(sf & 4)
80         {
81                 if(sf & 0x10)
82                 {
83                         WriteAngle(MSG_ENTITY, self.angles_x);
84                         WriteAngle(MSG_ENTITY, self.angles_y);
85                         WriteAngle(MSG_ENTITY, self.angles_z);
86                 }
87         }
88
89         if(sf & 8)
90         {
91                 if(sf & 0x80)
92                 {
93                         WriteShort(MSG_ENTITY, self.lodmodelindex0);
94                         WriteShort(MSG_ENTITY, bound(0, self.loddistance1, 65535));
95                         WriteShort(MSG_ENTITY, self.lodmodelindex1);
96                         WriteShort(MSG_ENTITY, bound(0, self.loddistance2, 65535));
97                         WriteShort(MSG_ENTITY, self.lodmodelindex2);
98                 }
99                 else
100                         WriteShort(MSG_ENTITY, self.modelindex);
101                 WriteByte(MSG_ENTITY, self.solid);
102                 WriteShort(MSG_ENTITY, floor(self.scale * 256));
103                 if(sf & 0x20)
104                 {
105                         WriteCoord(MSG_ENTITY, self.mins_x);
106                         WriteCoord(MSG_ENTITY, self.mins_y);
107                         WriteCoord(MSG_ENTITY, self.mins_z);
108                         WriteCoord(MSG_ENTITY, self.maxs_x);
109                         WriteCoord(MSG_ENTITY, self.maxs_y);
110                         WriteCoord(MSG_ENTITY, self.maxs_z);
111                 }
112                 WriteString(MSG_ENTITY, self.bgmscript);
113                 if(self.bgmscript != "")
114                 {
115                         WriteByte(MSG_ENTITY, floor(self.bgmscriptattack * 64));
116                         WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 64));
117                         WriteByte(MSG_ENTITY, floor(self.bgmscriptsustain * 255));
118                         WriteByte(MSG_ENTITY, floor(self.bgmscriptrelease * 64));
119                         WriteCoord(MSG_ENTITY, self.movedir_x);
120                         WriteCoord(MSG_ENTITY, self.movedir_y);
121                         WriteCoord(MSG_ENTITY, self.movedir_z);
122                         WriteByte(MSG_ENTITY, floor(self.lip * 255));
123                 }
124         }
125
126         return TRUE;
127 }
128
129
130 #define G_MODEL_INIT(sol) \
131         SetBrushEntityModel(); \
132         if(!self.scale) self.scale = self.modelscale; \
133         self.use = g_model_setcolormaptoactivator; \
134         InitializeEntity(self, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
135         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT;
136
137 #define G_CLIENTMODEL_INIT(sol) \
138         SetBrushEntityModel(); \
139         if(!self.scale) self.scale = self.modelscale; \
140         self.use = g_clientmodel_setcolormaptoactivator; \
141         InitializeEntity(self, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
142         if(!self.solid) self.solid = (sol); else if(self.solid < 0) self.solid = SOLID_NOT; \
143         if(!self.bgmscriptsustain) self.bgmscriptsustain = 1; else if(self.bgmscriptsustain < 0) self.bgmscriptsustain = 0; \
144         Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
145
146 // non-solid model entities:
147 void spawnfunc_misc_gamemodel()         { self.angles_x = -self.angles_x; G_MODEL_INIT      (SOLID_NOT) } // model entity
148 void spawnfunc_misc_clientmodel()       { self.angles_x = -self.angles_x; G_CLIENTMODEL_INIT(SOLID_NOT) } // model entity
149 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
150
151 // non-solid brush entities:
152 void spawnfunc_func_illusionary()       { G_MODEL_INIT      (SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
153 void spawnfunc_func_clientillusionary() { G_CLIENTMODEL_INIT(SOLID_NOT) } // brush entity
154 void spawnfunc_func_static()            { G_MODEL_INIT      (SOLID_NOT) } // DEPRECATED old alias name from some other game
155
156 // solid brush entities
157 void spawnfunc_func_wall()              { G_MODEL_INIT      (SOLID_BSP) } // Q1 name
158 void spawnfunc_func_clientwall()        { G_CLIENTMODEL_INIT(SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)