teamradar: fix clip fail
[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.avelocity = AnglesTransform_TurnDirectionFR(self.avelocity);
38         self.drawmask = MASK_NORMAL;
39
40         // link me
41         //setmodel(self, self.model);
42         setorigin(self, self.origin);
43         setsize(self, self.mins, self.maxs);
44 }
45
46 vector WarpZone_Camera_camera_transform(vector org, vector ang)
47 {
48         // a fixed camera view
49         trace_endpos = self.oldorigin;
50         makevectors(self.avelocity);
51         return self.oldorigin;
52 }
53
54 void WarpZone_Camera_Read(float isnew)
55 {
56         self.classname = "func_warpzone_camera";
57         self.origin_x = ReadCoord();
58         self.origin_y = ReadCoord();
59         self.origin_z = ReadCoord();
60         self.modelindex = ReadShort();
61         self.mins_x = ReadCoord();
62         self.mins_y = ReadCoord();
63         self.mins_z = ReadCoord();
64         self.maxs_x = ReadCoord();
65         self.maxs_y = ReadCoord();
66         self.maxs_z = ReadCoord();
67         self.scale = ReadByte() / 16;
68         self.oldorigin_x = ReadCoord();
69         self.oldorigin_y = ReadCoord();
70         self.oldorigin_z = ReadCoord();
71         self.avelocity_x = ReadCoord();
72         self.avelocity_y = ReadCoord();
73         self.avelocity_z = ReadCoord();
74
75         // engine currently wants this
76         self.drawmask = MASK_NORMAL;
77         self.camera_transform = WarpZone_Camera_camera_transform;
78
79         // link me
80         //setmodel(self, self.model);
81         setorigin(self, self.origin);
82         setsize(self, self.mins, self.maxs);
83 }
84
85 float warpzone_fixingview;
86 float warpzone_fixingview_drawexteriormodel;
87 //float warpzone_fixingview_sidespeed;
88 //float warpzone_fixingview_forwardspeed;
89 void WarpZone_Inside()
90 {
91         if(warpzone_fixingview)
92                 return;
93         warpzone_fixingview = 1;
94         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
95         //warpzone_fixingview_sidespeed = cvar("cl_sidespeed");
96         //warpzone_fixingview_forwardspeed = cvar("cl_forwardspeed");
97         cvar_set("r_drawexteriormodel", "0");
98         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed / 100)); // just keep a bit of it in case player gets stuck
99         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed / 100)); // just keep a bit of it in case player gets stuck
100 }
101
102 void WarpZone_Outside()
103 {
104         if(!warpzone_fixingview)
105                 return;
106         warpzone_fixingview = 0;
107         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
108         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed));
109         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed));
110 }
111
112 float warpzone_saved;
113 vector warpzone_saved_origin;
114 vector warpzone_saved_angles;
115 vector warpzone_saved_cl_viewangles;
116 #ifndef KEEP_ROLL
117 var float autocvar_cl_rollkillspeed = 10;
118 #endif
119 void WarpZone_FixView()
120 {
121         float pd, f;
122         entity e;
123         warpzone_saved = 0;
124         warpzone_saved_origin = warpzone_fixview_origin;
125         warpzone_saved_angles = warpzone_fixview_angles;
126         warpzone_saved_cl_viewangles = warpzone_fixview_cl_viewangles;
127
128 #ifndef KEEP_ROLL
129         if(warpzone_fixview_angles_z != 0 || warpzone_fixview_cl_viewangles_z != 0)
130         {
131                 if(autocvar_cl_rollkillspeed)
132                         f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
133                 else
134                         f = 0;
135                 warpzone_fixview_angles_z *= f;
136                 warpzone_fixview_cl_viewangles_z *= f;
137                 warpzone_saved_angles_z *= f; // PERMANENTLY apply that change!
138                 warpzone_saved_cl_viewangles_z *= f; // PERMANENTLY apply that change!
139                 warpzone_saved = 2;
140                 R_SetView(VF_CL_VIEWANGLES_Z, warpzone_fixview_angles_z);
141         }
142 #endif
143
144         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
145         if(e)
146         {
147                 warpzone_saved = 1;
148                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
149                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
150                 warpzone_fixview_cl_viewangles = WarpZone_TransformVAngles(e, warpzone_fixview_cl_viewangles);
151                 WarpZone_Inside();
152         }
153         else
154                 WarpZone_Outside();
155
156         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
157         float nearclip = 2;
158         e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip);
159         if(e)
160         {
161                 pd = WarpZone_PlaneDist(e, warpzone_fixview_origin);
162                 if(pd >= 0 && pd < nearclip)
163                 {
164                         warpzone_saved = 1;
165                         warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd);
166                 }
167         }
168
169         if(warpzone_saved == 1)
170         {
171                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
172                 R_SetView(VF_ANGLES, warpzone_fixview_cl_viewangles);
173         }
174 }
175 void WarpZone_UnFixView()
176 {
177         if(warpzone_saved)
178         {
179                 warpzone_fixview_origin = warpzone_saved_origin;
180                 warpzone_fixview_angles = warpzone_saved_angles;
181                 warpzone_fixview_cl_viewangles = warpzone_saved_cl_viewangles;
182                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
183                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
184                 R_SetView(VF_CL_VIEWANGLES, warpzone_fixview_cl_viewangles);
185         }
186 }
187
188 void WarpZone_Init()
189 {
190 }
191
192 void WarpZone_Shutdown()
193 {
194         WarpZone_Outside();
195 }