]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/wall.qc
Merge branch 'master' into Mario/balance
[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         }
140
141         if(f & 2)
142         {
143                 this.origin_x = ReadCoord();
144                 this.origin_y = ReadCoord();
145                 this.origin_z = ReadCoord();
146                 setorigin(this, this.origin);
147         }
148
149         if(f & 4)
150         {
151                 if(f & 0x10)
152                 {
153                         this.angles_x = ReadAngle();
154                         this.angles_y = ReadAngle();
155                         this.angles_z = ReadAngle();
156                 }
157                 else
158                         this.angles = '0 0 0';
159         }
160
161         if(f & 8)
162         {
163                 if(f & 0x80)
164                 {
165                         this.lodmodelindex0 = ReadShort();
166                         this.loddistance1 = ReadShort();
167                         this.lodmodelindex1 = ReadShort();
168                         this.loddistance2 = ReadShort();
169                         this.lodmodelindex2 = ReadShort();
170                 }
171                 else
172                 {
173                         this.modelindex = ReadShort();
174                         this.loddistance1 = 0;
175                         this.loddistance2 = 0;
176                 }
177                 this.solid = ReadByte();
178                 this.scale = ReadShort() / 256.0;
179                 if(f & 0x20)
180                 {
181                         this.mins_x = ReadCoord();
182                         this.mins_y = ReadCoord();
183                         this.mins_z = ReadCoord();
184                         this.maxs_x = ReadCoord();
185                         this.maxs_y = ReadCoord();
186                         this.maxs_z = ReadCoord();
187                 }
188                 else
189                         this.mins = this.maxs = '0 0 0';
190                 setsize(this, this.mins, this.maxs);
191
192                 if(this.bgmscript)
193                         strunzone(this.bgmscript);
194                 this.bgmscript = ReadString();
195                 if(substring(this.bgmscript, 0, 1) == "<")
196                 {
197                         this.bgmscript = strzone(substring(this.bgmscript, 1, -1));
198                         this.bgmscriptangular = 1;
199                 }
200                 else
201                 {
202                         this.bgmscript = strzone(this.bgmscript);
203                         this.bgmscriptangular = 0;
204                 }
205                 if(this.bgmscript != "")
206                 {
207                         this.bgmscriptattack = ReadByte() / 64.0;
208                         this.bgmscriptdecay = ReadByte() / 64.0;
209                         this.bgmscriptsustain = ReadByte() / 255.0;
210                         this.bgmscriptrelease = ReadByte() / 64.0;
211                         this.movedir_x = ReadCoord();
212                         this.movedir_y = ReadCoord();
213                         this.movedir_z = ReadCoord();
214                         this.lip = ReadByte() / 255.0;
215                 }
216                 this.fade_start = ReadShort();
217                 this.fade_end = ReadShort();
218                 this.alpha_max = ReadShort();
219                 this.alpha_min = ReadShort();
220                 this.inactive = ReadShort();
221                 this.fade_vertical_offset = ReadShort();
222                 BGMScript_InitEntity(this);
223         }
224
225         return = true;
226
227         InterpolateOrigin_Note(this);
228
229         this.saved = this.(fld);
230
231         this.entremove = Ent_Wall_Remove;
232         this.draw = Ent_Wall_Draw;
233         setpredraw(this, Ent_Wall_PreDraw);
234 }