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