]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/wall.qc
d847e50ae7123dd0713c1417202fbea345b2c5de
[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 = ReadVector();
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 = ReadVector();
183                         this.maxs = ReadVector();
184                 }
185                 else
186                         this.mins = this.maxs = '0 0 0';
187                 setsize(this, this.mins, this.maxs);
188
189                 string s = ReadString();
190                 if(substring(s, 0, 1) == "<")
191                 {
192                         strcpy(this.bgmscript, substring(s, 1, -1));
193                         this.bgmscriptangular = 1;
194                 }
195                 else
196                 {
197                         strcpy(this.bgmscript, s);
198                         this.bgmscriptangular = 0;
199                 }
200                 if(this.bgmscript != "")
201                 {
202                         this.bgmscriptattack = ReadByte() / 64.0;
203                         this.bgmscriptdecay = ReadByte() / 64.0;
204                         this.bgmscriptsustain = ReadByte() / 255.0;
205                         this.bgmscriptrelease = ReadByte() / 64.0;
206                         this.movedir = ReadVector();
207                         this.lip = ReadByte() / 255.0;
208                 }
209                 this.fade_start = ReadByte();
210                 this.fade_end = ReadByte();
211                 this.alpha_max = ReadByte();
212                 this.alpha_min = ReadByte();
213                 this.inactive = ReadByte();
214                 this.fade_vertical_offset = ReadShort();
215                 BGMScript_InitEntity(this);
216         }
217
218         return = true;
219
220         InterpolateOrigin_Note(this);
221
222         this.saved = this.(fld);
223
224         this.entremove = Ent_Wall_Remove;
225         this.draw = Ent_Wall_Draw;
226         if (isnew) IL_PUSH(g_drawables, this);
227         setpredraw(this, Ent_Wall_PreDraw);
228 }