]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/warpzonelib/client.qc
Merge branch 'TimePath/refactor/mod_operator' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / client.qc
1 void WarpZone_Fade_PreDraw()
2 {
3         vector org;
4         org = getpropertyvec(VF_ORIGIN);
5         if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
6                 self.alpha = 0;
7         else if(self.warpzone_fadestart)
8                 self.alpha = bound(0, (self.warpzone_fadeend - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.warpzone_fadeend - self.warpzone_fadestart), 1);
9         else
10                 self.alpha = 1;
11         //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
12         if(self.alpha <= 0)
13                 self.drawmask = 0;
14         else
15                 self.drawmask = MASK_NORMAL;
16 }
17
18 void WarpZone_Read(float isnew)
19 {
20         float f;
21
22         warpzone_warpzones_exist = 1;
23         if (!self.enemy)
24         {
25                 self.enemy = spawn();
26                 self.enemy.classname = "warpzone_from";
27         }
28         self.classname = "trigger_warpzone";
29
30         f = ReadByte();
31         self.warpzone_isboxy = (f & 1);
32         if(f & 4)
33         {
34                 self.origin_x = ReadCoord();
35                 self.origin_y = ReadCoord();
36                 self.origin_z = ReadCoord();
37         }
38         else
39                 self.origin = '0 0 0';
40         self.modelindex = ReadShort();
41         self.mins_x = ReadCoord();
42         self.mins_y = ReadCoord();
43         self.mins_z = ReadCoord();
44         self.maxs_x = ReadCoord();
45         self.maxs_y = ReadCoord();
46         self.maxs_z = ReadCoord();
47         self.scale = ReadByte() / 16;
48         self.enemy.oldorigin_x = ReadCoord();
49         self.enemy.oldorigin_y = ReadCoord();
50         self.enemy.oldorigin_z = ReadCoord();
51         self.enemy.avelocity_x = ReadCoord();
52         self.enemy.avelocity_y = ReadCoord();
53         self.enemy.avelocity_z = ReadCoord();
54         self.oldorigin_x = ReadCoord();
55         self.oldorigin_y = ReadCoord();
56         self.oldorigin_z = ReadCoord();
57         self.avelocity_x = ReadCoord();
58         self.avelocity_y = ReadCoord();
59         self.avelocity_z = ReadCoord();
60
61         if(f & 2)
62         {
63                 self.warpzone_fadestart = ReadShort();
64                 self.warpzone_fadeend = max(self.warpzone_fadestart + 1, ReadShort());
65         }
66         else
67         {
68                 self.warpzone_fadestart = 0;
69                 self.warpzone_fadeend = 0;
70         }
71
72         // common stuff
73         WarpZone_SetUp(self, self.enemy.oldorigin, self.enemy.avelocity, self.oldorigin, self.avelocity);
74
75         // link me
76         //setmodel(self, self.model);
77         setorigin(self, self.origin);
78         setsize(self, self.mins, self.maxs);
79
80         // how to draw
81         // engine currently wants this
82         self.predraw = WarpZone_Fade_PreDraw;
83 }
84
85 void WarpZone_Camera_Read(float isnew)
86 {
87         float f;
88         warpzone_cameras_exist = 1;
89         self.classname = "func_warpzone_camera";
90
91         f = ReadByte();
92         if(f & 4)
93         {
94                 self.origin_x = ReadCoord();
95                 self.origin_y = ReadCoord();
96                 self.origin_z = ReadCoord();
97         }
98         else
99                 self.origin = '0 0 0';
100         self.modelindex = ReadShort();
101         self.mins_x = ReadCoord();
102         self.mins_y = ReadCoord();
103         self.mins_z = ReadCoord();
104         self.maxs_x = ReadCoord();
105         self.maxs_y = ReadCoord();
106         self.maxs_z = ReadCoord();
107         self.scale = ReadByte() / 16;
108         self.oldorigin_x = ReadCoord();
109         self.oldorigin_y = ReadCoord();
110         self.oldorigin_z = ReadCoord();
111         self.avelocity_x = ReadCoord();
112         self.avelocity_y = ReadCoord();
113         self.avelocity_z = ReadCoord();
114
115         if(f & 2)
116         {
117                 self.warpzone_fadestart = ReadShort();
118                 self.warpzone_fadeend = max(self.warpzone_fadestart + 1, ReadShort());
119         }
120         else
121         {
122                 self.warpzone_fadestart = 0;
123                 self.warpzone_fadeend = 0;
124         }
125
126         // common stuff
127         WarpZone_Camera_SetUp(self, self.oldorigin, self.avelocity);
128
129         // engine currently wants this
130         self.drawmask = MASK_NORMAL;
131
132         // link me
133         //setmodel(self, self.model);
134         setorigin(self, self.origin);
135         setsize(self, self.mins, self.maxs);
136
137         // how to draw
138         // engine currently wants this
139         self.predraw = WarpZone_Fade_PreDraw;
140 }
141
142 void CL_RotateMoves(vector ang) = #638;
143 void WarpZone_Teleported_Read(float isnew)
144 {
145         vector v;
146         self.classname = "warpzone_teleported";
147         v_x = ReadCoord();
148         v_y = ReadCoord();
149         v_z = ReadCoord();
150         if(!isnew)
151                 return;
152         self.warpzone_transform = v;
153         setproperty(VF_CL_VIEWANGLES, WarpZone_TransformVAngles(self, getpropertyvec(VF_CL_VIEWANGLES)));
154         if(checkextension("DP_CSQC_ROTATEMOVES"))
155                 CL_RotateMoves(v);
156                 //CL_RotateMoves('0 90 0');
157 }
158
159 float warpzone_fixingview;
160 float warpzone_fixingview_drawexteriormodel;
161 float autocvar_chase_active;
162
163 void WarpZone_View_Outside()
164 {
165         if(!warpzone_fixingview)
166                 return;
167         warpzone_fixingview = 0;
168         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
169 }
170
171 void WarpZone_View_Inside()
172 {
173         if(autocvar_chase_active)
174         {
175                 WarpZone_View_Outside();
176                 return;
177         }
178         if(warpzone_fixingview)
179                 return;
180         warpzone_fixingview = 1;
181         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
182         cvar_set("r_drawexteriormodel", "0");
183 }
184
185 vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3)
186 {
187         vector mi, ma;
188         entity e;
189         float pd;
190
191         mi_x = min(o_x, c0_x, c1_x, c2_x, c3_x);
192         ma_x = max(o_x, c0_x, c1_x, c2_x, c3_x);
193         mi_y = min(o_y, c0_y, c1_y, c2_y, c3_y);
194         ma_y = max(o_y, c0_y, c1_y, c2_y, c3_y);
195         mi_z = min(o_z, c0_z, c1_z, c2_z, c3_z);
196         ma_z = max(o_z, c0_z, c1_z, c2_z, c3_z);
197
198         e = WarpZone_Find(mi, ma);
199         if(e)
200         {
201                 if(WarpZone_PlaneDist(e, o) < 0)
202                         return '0 0 0';
203                         // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs
204                 pd = min(
205                                 WarpZone_PlaneDist(e, c0),
206                                 WarpZone_PlaneDist(e, c1),
207                                 WarpZone_PlaneDist(e, c2),
208                                 WarpZone_PlaneDist(e, c3)
209                         );
210                 if(pd < 0)
211                         return e.warpzone_forward * -pd;
212         }
213
214         return '0 0 0';
215 }
216
217 void WarpZone_FixPMove()
218 {
219         entity e;
220         e = WarpZone_Find(pmove_org, pmove_org);
221         if(e)
222         {
223                 pmove_org = WarpZone_TransformOrigin(e, pmove_org);
224                 input_angles = WarpZone_TransformVAngles(e, input_angles);
225         }
226 }
227
228 #ifndef KEEP_ROLL
229 var float autocvar_cl_rollkillspeed = 10;
230 #endif
231 void WarpZone_FixView()
232 {
233         entity e;
234         vector org, ang, nearclip, corner0, corner1, corner2, corner3, o;
235         float f;
236
237         warpzone_save_view_origin = org = getpropertyvec(VF_ORIGIN);
238         warpzone_save_view_angles = ang = getpropertyvec(VF_ANGLES);
239
240         e = WarpZone_Find(org, org);
241         if(e)
242         {
243                 org = WarpZone_TransformOrigin(e, org);
244                 ang = WarpZone_TransformVAngles(e, ang);
245                 WarpZone_View_Inside();
246         }
247         else
248                 WarpZone_View_Outside();
249
250 #ifndef KEEP_ROLL
251         float rick;
252         if(autocvar_cl_rollkillspeed)
253                 f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
254         else
255                 f = 0;
256
257         rick = getproperty(VF_CL_VIEWANGLES_Z);
258         rick *= f;
259         setproperty(VF_CL_VIEWANGLES_Z, rick);
260         ang_z *= f;
261 #endif
262
263         setproperty(VF_ORIGIN, org);
264         setproperty(VF_ANGLES, ang);
265
266         nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125);
267         corner0 = cs_unproject('0 0 0' + nearclip);
268         corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip);
269         corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip);
270         corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip);
271         o = WarpZone_FixNearClip(org, corner0, corner1, corner2, corner3);
272         if(o != '0 0 0')
273                 setproperty(VF_ORIGIN, org + o);
274 }
275
276 void WarpZone_Init()
277 {
278 }
279
280 void WarpZone_Shutdown()
281 {
282         WarpZone_View_Outside();
283 }