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