]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/wall.qc
Fix (de)activation of func_button
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / wall.qc
1 #include "wall.qh"
2
3 #include "autocvars.qh"
4 #include "main.qh"
5 #include "bgmscript.qh"
6
7
8 #include "../lib/csqcmodel/interpolate.qh"
9
10 .float alpha;
11 .float scale;
12 .vector movedir;
13
14 void Ent_Wall_PreDraw(entity this)
15 {
16         if (this.inactive)
17         {
18                 this.alpha = 0;
19         }
20         else
21         {
22                 vector org = getpropertyvec(VF_ORIGIN);
23                 if(!checkpvs(org, this))
24                         this.alpha = 0;
25                 else if(this.fade_start || this.fade_end) {
26                         vector offset = '0 0 0';
27                         offset_z = this.fade_vertical_offset;
28                         float player_dist = vlen(org - this.origin - 0.5 * (this.mins + this.maxs) + offset);
29                         if (this.fade_end == this.fade_start)
30                         {
31                                 if (player_dist >= this.fade_start)
32                                         this.alpha = 0;
33                                 else
34                                         this.alpha = 1;
35                         }
36                         else
37                         {
38                                 this.alpha = (this.alpha_min + this.alpha_max * bound(0,
39                                                            (this.fade_end - player_dist)
40                                                            / (this.fade_end - this.fade_start), 1)) / 100.0;
41                         }
42                 }
43                 else
44                 {
45                         this.alpha = 1;
46                 }
47         }
48         if(this.alpha <= 0)
49                 this.drawmask = 0;
50         else
51                 this.drawmask = MASK_NORMAL;
52 }
53
54 void Ent_Wall_Draw(entity this)
55 {
56         float f;
57         var .vector fld;
58
59         if(this.bgmscriptangular)
60                 fld = angles;
61         else
62                 fld = origin;
63         this.(fld) = this.saved;
64
65         if(this.lodmodelindex1)
66         {
67                 if(autocvar_cl_modeldetailreduction <= 0)
68                 {
69                         if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
70                                 this.modelindex = this.lodmodelindex2;
71                         else if(autocvar_cl_modeldetailreduction <= -1)
72                                 this.modelindex = this.lodmodelindex1;
73                         else
74                                 this.modelindex = this.lodmodelindex0;
75                 }
76                 else
77                 {
78                         float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
79                         f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
80                         f *= 1.0 / bound(0.01, view_quality, 1);
81                         if(this.lodmodelindex2 && f > this.loddistance2)
82                                 this.modelindex = this.lodmodelindex2;
83                         else if(f > this.loddistance1)
84                                 this.modelindex = this.lodmodelindex1;
85                         else
86                                 this.modelindex = this.lodmodelindex0;
87                 }
88         }
89
90         InterpolateOrigin_Do(this);
91
92         this.saved = this.(fld);
93
94         f = doBGMScript(this);
95         if(f >= 0)
96         {
97                 if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
98                         this.alpha = 1 + this.lip * f;
99                 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
100                         this.alpha = 1 - this.lip * (1 - f);
101                 this.(fld) = this.(fld) + this.movedir * f;
102         }
103         else
104                 this.alpha = 1;
105
106         if(this.alpha >= ALPHA_MIN_VISIBLE)
107                 this.drawmask = MASK_NORMAL;
108         else
109                 this.drawmask = 0;
110 }
111
112 void Ent_Wall_Remove(entity this)
113 {
114         if(this.bgmscript)
115                 strunzone(this.bgmscript);
116         this.bgmscript = string_null;
117 }
118
119 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
120 {
121         int f;
122         var .vector fld;
123
124         InterpolateOrigin_Undo(this);
125         this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
126
127         if(this.bgmscriptangular)
128                 fld = angles;
129         else
130                 fld = origin;
131         this.(fld) = this.saved;
132
133         f = ReadByte();
134
135         if(f & 1)
136         {
137                 if(f & 0x40)
138                         this.colormap = ReadShort();
139                 else
140                         this.colormap = 0;
141                 this.skin = ReadByte();
142         }
143
144         if(f & 2)
145         {
146                 this.origin_x = ReadCoord();
147                 this.origin_y = ReadCoord();
148                 this.origin_z = ReadCoord();
149                 setorigin(this, this.origin);
150         }
151
152         if(f & 4)
153         {
154                 if(f & 0x10)
155                 {
156                         this.angles_x = ReadAngle();
157                         this.angles_y = ReadAngle();
158                         this.angles_z = ReadAngle();
159                 }
160                 else
161                         this.angles = '0 0 0';
162         }
163
164         if(f & 8)
165         {
166                 if(f & 0x80)
167                 {
168                         this.lodmodelindex0 = ReadShort();
169                         this.loddistance1 = ReadShort();
170                         this.lodmodelindex1 = ReadShort();
171                         this.loddistance2 = ReadShort();
172                         this.lodmodelindex2 = ReadShort();
173                 }
174                 else
175                 {
176                         this.modelindex = ReadShort();
177                         this.loddistance1 = 0;
178                         this.loddistance2 = 0;
179                 }
180                 this.solid = ReadByte();
181                 this.scale = ReadShort() / 256.0;
182                 if(f & 0x20)
183                 {
184                         this.mins_x = ReadCoord();
185                         this.mins_y = ReadCoord();
186                         this.mins_z = ReadCoord();
187                         this.maxs_x = ReadCoord();
188                         this.maxs_y = ReadCoord();
189                         this.maxs_z = ReadCoord();
190                 }
191                 else
192                         this.mins = this.maxs = '0 0 0';
193                 setsize(this, this.mins, this.maxs);
194
195                 if(this.bgmscript)
196                         strunzone(this.bgmscript);
197                 this.bgmscript = ReadString();
198                 if(substring(this.bgmscript, 0, 1) == "<")
199                 {
200                         this.bgmscript = strzone(substring(this.bgmscript, 1, -1));
201                         this.bgmscriptangular = 1;
202                 }
203                 else
204                 {
205                         this.bgmscript = strzone(this.bgmscript);
206                         this.bgmscriptangular = 0;
207                 }
208                 if(this.bgmscript != "")
209                 {
210                         this.bgmscriptattack = ReadByte() / 64.0;
211                         this.bgmscriptdecay = ReadByte() / 64.0;
212                         this.bgmscriptsustain = ReadByte() / 255.0;
213                         this.bgmscriptrelease = ReadByte() / 64.0;
214                         this.movedir_x = ReadCoord();
215                         this.movedir_y = ReadCoord();
216                         this.movedir_z = ReadCoord();
217                         this.lip = ReadByte() / 255.0;
218                 }
219                 this.fade_start = ReadByte();
220                 this.fade_end = ReadByte();
221                 this.alpha_max = ReadByte();
222                 this.alpha_min = ReadByte();
223                 this.inactive = ReadByte();
224                 this.fade_vertical_offset = ReadShort();
225                 BGMScript_InitEntity(this);
226         }
227
228         return = true;
229
230         InterpolateOrigin_Note(this);
231
232         this.saved = this.(fld);
233
234         this.entremove = Ent_Wall_Remove;
235         this.draw = Ent_Wall_Draw;
236         if (isnew) IL_PUSH(g_drawables, this);
237         setpredraw(this, Ent_Wall_PreDraw);
238 }