]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/warpzonelib/client.qc
Merge remote branch 'origin/master' into fruitiex/multijump
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / client.qc
1 void WarpZone_Read(float isnew)
2 {
3         ++warpzone_warpzones_exist;
4         if not(self.enemy)
5         {
6                 self.enemy = spawn();
7                 self.enemy.classname = "warpzone_from";
8         }
9         self.classname = "trigger_warpzone";
10
11         self.warpzone_isboxy = ReadByte();
12         self.origin_x = ReadCoord();
13         self.origin_y = ReadCoord();
14         self.origin_z = ReadCoord();
15         self.modelindex = ReadShort();
16         self.mins_x = ReadCoord();
17         self.mins_y = ReadCoord();
18         self.mins_z = ReadCoord();
19         self.maxs_x = ReadCoord();
20         self.maxs_y = ReadCoord();
21         self.maxs_z = ReadCoord();
22         self.scale = ReadByte() / 16;
23         self.enemy.oldorigin_x = ReadCoord();
24         self.enemy.oldorigin_y = ReadCoord();
25         self.enemy.oldorigin_z = ReadCoord();
26         self.enemy.avelocity_x = ReadCoord();
27         self.enemy.avelocity_y = ReadCoord();
28         self.enemy.avelocity_z = ReadCoord();
29         self.oldorigin_x = ReadCoord();
30         self.oldorigin_y = ReadCoord();
31         self.oldorigin_z = ReadCoord();
32         self.avelocity_x = ReadCoord();
33         self.avelocity_y = ReadCoord();
34         self.avelocity_z = ReadCoord();
35
36         // common stuff
37         WarpZone_SetUp(self, self.enemy.oldorigin, self.enemy.avelocity, self.oldorigin, self.avelocity);
38
39         // engine currently wants this
40         self.drawmask = MASK_NORMAL;
41
42         // link me
43         //setmodel(self, self.model);
44         setorigin(self, self.origin);
45         setsize(self, self.mins, self.maxs);
46 }
47
48 void WarpZone_Camera_Read(float isnew)
49 {
50         ++warpzone_cameras_exist;
51         self.classname = "func_warpzone_camera";
52         self.origin_x = ReadCoord();
53         self.origin_y = ReadCoord();
54         self.origin_z = ReadCoord();
55         self.modelindex = ReadShort();
56         self.mins_x = ReadCoord();
57         self.mins_y = ReadCoord();
58         self.mins_z = ReadCoord();
59         self.maxs_x = ReadCoord();
60         self.maxs_y = ReadCoord();
61         self.maxs_z = ReadCoord();
62         self.scale = ReadByte() / 16;
63         self.oldorigin_x = ReadCoord();
64         self.oldorigin_y = ReadCoord();
65         self.oldorigin_z = ReadCoord();
66         self.avelocity_x = ReadCoord();
67         self.avelocity_y = ReadCoord();
68         self.avelocity_z = ReadCoord();
69
70         // common stuff
71         WarpZone_Camera_SetUp(self, self.oldorigin, self.avelocity);
72
73         // engine currently wants this
74         self.drawmask = MASK_NORMAL;
75
76         // link me
77         //setmodel(self, self.model);
78         setorigin(self, self.origin);
79         setsize(self, self.mins, self.maxs);
80 }
81
82 float warpzone_fixingview;
83 float warpzone_fixingview_drawexteriormodel;
84 //float warpzone_fixingview_sidespeed;
85 //float warpzone_fixingview_forwardspeed;
86 void WarpZone_Inside()
87 {
88         if(warpzone_fixingview)
89                 return;
90         warpzone_fixingview = 1;
91         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
92         //warpzone_fixingview_sidespeed = cvar("cl_sidespeed");
93         //warpzone_fixingview_forwardspeed = cvar("cl_forwardspeed");
94         cvar_set("r_drawexteriormodel", "0");
95         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed / 100)); // just keep a bit of it in case player gets stuck
96         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed / 100)); // just keep a bit of it in case player gets stuck
97 }
98
99 void WarpZone_Outside()
100 {
101         if(!warpzone_fixingview)
102                 return;
103         warpzone_fixingview = 0;
104         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
105         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed));
106         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed));
107 }
108
109 vector WarpZone_FixNearClip(vector o, vector c0, vector c1, vector c2, vector c3)
110 {
111         float nearclipdistance;
112         vector mi, ma;
113         entity e;
114         float pd;
115
116         mi_x = min5(o_x, c0_x, c1_x, c2_x, c3_x);
117         ma_x = max5(o_x, c0_x, c1_x, c2_x, c3_x);
118         mi_y = min5(o_y, c0_y, c1_y, c2_y, c3_y);
119         ma_y = max5(o_y, c0_y, c1_y, c2_y, c3_y);
120         mi_z = min5(o_z, c0_z, c1_z, c2_z, c3_z);
121         ma_z = max5(o_z, c0_z, c1_z, c2_z, c3_z);
122
123         e = WarpZone_Find(mi, ma);
124         if(e)
125         {
126                 if(WarpZone_PlaneDist(e, o) < 0)
127                         return '0 0 0';
128                         // can't really be, though, but if it is, this is not my warpzone, but a random different one in the same mins/maxs
129                 pd = min4(
130                                 WarpZone_PlaneDist(e, c0),
131                                 WarpZone_PlaneDist(e, c1),
132                                 WarpZone_PlaneDist(e, c2),
133                                 WarpZone_PlaneDist(e, c3)
134                         );
135                 if(pd < 0)
136                         return e.warpzone_forward * -pd;
137         }
138
139         return '0 0 0';
140 }
141
142 float warpzone_saved;
143 vector warpzone_saved_origin;
144 vector warpzone_saved_angles;
145 vector warpzone_saved_cl_viewangles;
146 #ifndef KEEP_ROLL
147 var float autocvar_cl_rollkillspeed = 10;
148 #endif
149 void WarpZone_FixView()
150 {
151         float pd, f;
152         vector o;
153         entity e;
154         vector corner0, corner1, corner2, corner3, nearclip;
155
156         warpzone_saved = 0;
157         warpzone_saved_origin = warpzone_fixview_origin;
158         warpzone_saved_angles = warpzone_fixview_angles;
159         warpzone_saved_cl_viewangles = warpzone_fixview_cl_viewangles;
160
161         nearclip = '0 0 1' * (cvar("r_nearclip") * 1.125);
162         corner0 = cs_unproject('0 0 0' + nearclip);
163         corner1 = cs_unproject('1 0 0' * cvar("vid_conwidth") + nearclip);
164         corner2 = cs_unproject('0 1 0' * cvar("vid_conheight") + nearclip);
165         corner3 = cs_unproject('1 0 0' * cvar("vid_conwidth") + '0 1 0' * cvar("vid_conheight") + nearclip);
166
167 #ifndef KEEP_ROLL
168         if(warpzone_fixview_angles_z != 0 || warpzone_fixview_cl_viewangles_z != 0)
169         {
170                 if(autocvar_cl_rollkillspeed)
171                         f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
172                 else
173                         f = 0;
174                 warpzone_fixview_angles_z *= f;
175                 warpzone_fixview_cl_viewangles_z *= f;
176                 warpzone_saved_angles_z *= f; // PERMANENTLY apply that change!
177                 warpzone_saved_cl_viewangles_z *= f; // PERMANENTLY apply that change!
178                 warpzone_saved = 2;
179                 R_SetView(VF_CL_VIEWANGLES_Z, warpzone_fixview_angles_z);
180         }
181 #endif
182
183         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
184         if(e)
185         {
186                 warpzone_saved = 1;
187                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
188                 corner0 = WarpZone_TransformOrigin(e, corner0);
189                 corner1 = WarpZone_TransformOrigin(e, corner1);
190                 corner2 = WarpZone_TransformOrigin(e, corner2);
191                 corner3 = WarpZone_TransformOrigin(e, corner3);
192                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
193                 warpzone_fixview_cl_viewangles = WarpZone_TransformVAngles(e, warpzone_fixview_cl_viewangles);
194                 WarpZone_Inside();
195         }
196         else
197                 WarpZone_Outside();
198
199         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
200         o = WarpZone_FixNearClip(warpzone_fixview_origin, corner0, corner1, corner2, corner3);
201         if(o != '0 0 0')
202         {
203                 warpzone_saved = 1;
204                 warpzone_fixview_origin += o;
205         }
206
207         if(warpzone_saved == 1)
208         {
209                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
210                 R_SetView(VF_ANGLES, warpzone_fixview_cl_viewangles);
211         }
212 }
213 void WarpZone_UnFixView()
214 {
215         if(warpzone_saved)
216         {
217                 warpzone_fixview_origin = warpzone_saved_origin;
218                 warpzone_fixview_angles = warpzone_saved_angles;
219                 warpzone_fixview_cl_viewangles = warpzone_saved_cl_viewangles;
220                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
221                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
222                 R_SetView(VF_CL_VIEWANGLES, warpzone_fixview_cl_viewangles);
223         }
224 }
225
226 void WarpZone_Init()
227 {
228 }
229
230 void WarpZone_Shutdown()
231 {
232         WarpZone_Outside();
233 }