3 #include "autocvars.qh"
5 #include "bgmscript.qh"
8 #include "../lib/csqcmodel/interpolate.qh"
14 void Ent_Wall_PreDraw(entity this)
22 vector org = getpropertyvec(VF_ORIGIN);
23 if(!checkpvs(org, this))
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)
31 if (player_dist >= this.fade_start)
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;
51 this.drawmask = MASK_NORMAL;
54 void Ent_Wall_Draw(entity this)
59 if(this.bgmscriptangular)
63 this.(fld) = this.saved;
65 if(this.lodmodelindex1)
67 if(autocvar_cl_modeldetailreduction <= 0)
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;
74 this.modelindex = this.lodmodelindex0;
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;
86 this.modelindex = this.lodmodelindex0;
90 InterpolateOrigin_Do(this);
92 this.saved = this.(fld);
94 f = doBGMScript(this);
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;
106 if(this.alpha >= ALPHA_MIN_VISIBLE)
107 this.drawmask = MASK_NORMAL;
112 void Ent_Wall_Remove(entity this)
115 strunzone(this.bgmscript);
116 this.bgmscript = string_null;
119 NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
124 InterpolateOrigin_Undo(this);
125 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
127 if(this.bgmscriptangular)
131 this.(fld) = this.saved;
138 this.colormap = ReadShort();
141 this.skin = ReadByte();
146 this.origin = ReadVector();
147 setorigin(this, this.origin);
154 this.angles_x = ReadAngle();
155 this.angles_y = ReadAngle();
156 this.angles_z = ReadAngle();
159 this.angles = '0 0 0';
166 this.lodmodelindex0 = ReadShort();
167 this.loddistance1 = ReadShort();
168 this.lodmodelindex1 = ReadShort();
169 this.loddistance2 = ReadShort();
170 this.lodmodelindex2 = ReadShort();
174 this.modelindex = ReadShort();
175 this.loddistance1 = 0;
176 this.loddistance2 = 0;
178 this.solid = ReadByte();
179 this.scale = ReadShort() / 256.0;
182 this.mins = ReadVector();
183 this.maxs = ReadVector();
186 this.mins = this.maxs = '0 0 0';
187 setsize(this, this.mins, this.maxs);
189 string s = ReadString();
190 if(substring(s, 0, 1) == "<")
192 strcpy(this.bgmscript, substring(s, 1, -1));
193 this.bgmscriptangular = 1;
197 strcpy(this.bgmscript, s);
198 this.bgmscriptangular = 0;
200 if(this.bgmscript != "")
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;
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);
220 InterpolateOrigin_Note(this);
222 this.saved = this.(fld);
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);