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