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