7b5a6b0715b5d0df58a6885de1c462bf38e311af
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / wall.qc
1 .float lip;
2 .float bgmscriptangular;
3 .float lodmodelindex0, lodmodelindex1, lodmodelindex2;
4 .float loddistance1, loddistance2;
5 .vector saved;
6
7 void Ent_Wall_Draw()
8 {
9         float f;
10         var .vector fld;
11
12         if(self.bgmscriptangular)
13                 fld = angles;
14         else
15                 fld = origin;
16         self.fld = self.saved;
17
18         if(self.lodmodelindex1)
19         {
20                 if(autocvar_cl_modeldetailreduction <= 0)
21                 {
22                         if(self.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
23                                 self.modelindex = self.lodmodelindex2;
24                         else if(autocvar_cl_modeldetailreduction <= -1)
25                                 self.modelindex = self.lodmodelindex1;
26                         else
27                                 self.modelindex = self.lodmodelindex0;
28                 }
29                 else
30                 {
31                         float distance = vlen(NearestPointOnBox(self, view_origin) - view_origin);
32                         f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
33                         f *= 1.0 / bound(0.01, view_quality, 1);
34                         if(self.lodmodelindex2 && f > self.loddistance2)
35                                 self.modelindex = self.lodmodelindex2;
36                         else if(f > self.loddistance1)
37                                 self.modelindex = self.lodmodelindex1;
38                         else
39                                 self.modelindex = self.lodmodelindex0;
40                 }
41         }
42
43         InterpolateOrigin_Do();
44
45         self.saved = self.fld;
46
47         f = BGMScript(self);
48         if(f >= 0)
49         {
50                 if(self.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
51                         self.alpha = 1 + self.lip * f;
52                 else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
53                         self.alpha = 1 - self.lip * (1 - f);
54                 self.fld = self.fld + self.movedir * f;
55         }
56         else
57                 self.alpha = 1;
58
59         if(self.alpha >= ALPHA_MIN_VISIBLE)
60                 self.drawmask = MASK_NORMAL;
61         else
62                 self.drawmask = 0;
63 }
64
65 void Ent_Wall_Remove()
66 {
67         if(self.bgmscript)
68                 strunzone(self.bgmscript);
69         self.bgmscript = string_null;
70 }
71
72 void Ent_Wall()
73 {
74         int f;
75         var .vector fld;
76
77         InterpolateOrigin_Undo();
78         self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
79
80         if(self.bgmscriptangular)
81                 fld = angles;
82         else
83                 fld = origin;
84         self.fld = self.saved;
85
86         f = ReadByte();
87
88         if(f & 1)
89         {
90                 if(f & 0x40)
91                         self.colormap = ReadShort();
92                 else
93                         self.colormap = 0;
94         }
95
96         if(f & 2)
97         {
98                 self.origin_x = ReadCoord();
99                 self.origin_y = ReadCoord();
100                 self.origin_z = ReadCoord();
101                 setorigin(self, self.origin);
102         }
103
104         if(f & 4)
105         {
106                 if(f & 0x10)
107                 {
108                         self.angles_x = ReadAngle();
109                         self.angles_y = ReadAngle();
110                         self.angles_z = ReadAngle();
111                 }
112                 else
113                         self.angles = '0 0 0';
114         }
115
116         if(f & 8)
117         {
118                 if(f & 0x80)
119                 {
120                         self.lodmodelindex0 = ReadShort();
121                         self.loddistance1 = ReadShort();
122                         self.lodmodelindex1 = ReadShort();
123                         self.loddistance2 = ReadShort();
124                         self.lodmodelindex2 = ReadShort();
125                 }
126                 else
127                 {
128                         self.modelindex = ReadShort();
129                         self.loddistance1 = 0;
130                         self.loddistance2 = 0;
131                 }
132                 self.solid = ReadByte();
133                 self.scale = ReadShort() / 256.0;
134                 if(f & 0x20)
135                 {
136                         self.mins_x = ReadCoord();
137                         self.mins_y = ReadCoord();
138                         self.mins_z = ReadCoord();
139                         self.maxs_x = ReadCoord();
140                         self.maxs_y = ReadCoord();
141                         self.maxs_z = ReadCoord();
142                 }
143                 else
144                         self.mins = self.maxs = '0 0 0';
145                 setsize(self, self.mins, self.maxs);
146
147                 if(self.bgmscript)
148                         strunzone(self.bgmscript);
149                 self.bgmscript = ReadString();
150                 if(substring(self.bgmscript, 0, 1) == "<")
151                 {
152                         self.bgmscript = strzone(substring(self.bgmscript, 1, -1));
153                         self.bgmscriptangular = 1;
154                 }
155                 else
156                 {
157                         self.bgmscript = strzone(self.bgmscript);
158                         self.bgmscriptangular = 0;
159                 }
160                 if(self.bgmscript != "")
161                 {
162                         self.bgmscriptattack = ReadByte() / 64.0;
163                         self.bgmscriptdecay = ReadByte() / 64.0;
164                         self.bgmscriptsustain = ReadByte() / 255.0;
165                         self.bgmscriptrelease = ReadByte() / 64.0;
166                         self.movedir_x = ReadCoord();
167                         self.movedir_y = ReadCoord();
168                         self.movedir_z = ReadCoord();
169                         self.lip = ReadByte() / 255.0;
170                 }
171                 BGMScript_InitEntity(self);
172         }
173
174         InterpolateOrigin_Note();
175
176         self.saved = self.fld;
177
178         self.entremove = Ent_Wall_Remove;
179         self.draw = Ent_Wall_Draw;
180 }