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