disable the sidespeed/forwardspeed disabling workaround for now
[divverent/nexuiz.git] / data / 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.enemy.oldorigin_x = ReadCoord();
20         self.enemy.oldorigin_y = ReadCoord();
21         self.enemy.oldorigin_z = ReadCoord();
22         self.enemy.avelocity_x = ReadCoord();
23         self.enemy.avelocity_y = ReadCoord();
24         self.enemy.avelocity_z = ReadCoord();
25         self.oldorigin_x = ReadCoord();
26         self.oldorigin_y = ReadCoord();
27         self.oldorigin_z = ReadCoord();
28         self.avelocity_x = ReadCoord();
29         self.avelocity_y = ReadCoord();
30         self.avelocity_z = ReadCoord();
31
32         // common stuff
33         WarpZone_SetUp(self, self.enemy.oldorigin, self.enemy.avelocity, self.oldorigin, self.avelocity);
34
35         // engine currently wants this
36         self.avelocity = AnglesTransform_TurnDirectionFR(self.avelocity);
37
38         self.flags = FL_CAMERA;
39         self.drawmask = MASK_NORMAL;
40
41         // link me
42         //setmodel(self, self.model);
43         setorigin(self, self.origin);
44         setsize(self, self.mins, self.maxs);
45 }
46
47 float warpzone_fixingview;
48 float warpzone_fixingview_drawexteriormodel;
49 //float warpzone_fixingview_sidespeed;
50 //float warpzone_fixingview_forwardspeed;
51 void WarpZone_Inside()
52 {
53         if(warpzone_fixingview)
54                 return;
55         warpzone_fixingview = 1;
56         warpzone_fixingview_drawexteriormodel = cvar("r_drawexteriormodel");
57         //warpzone_fixingview_sidespeed = cvar("cl_sidespeed");
58         //warpzone_fixingview_forwardspeed = cvar("cl_forwardspeed");
59         cvar_set("r_drawexteriormodel", "0");
60         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed / 100)); // just keep a bit of it in case player gets stuck
61         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed / 100)); // just keep a bit of it in case player gets stuck
62 }
63
64 void WarpZone_Outside()
65 {
66         if(!warpzone_fixingview)
67                 return;
68         warpzone_fixingview = 0;
69         cvar_set("r_drawexteriormodel", ftos(warpzone_fixingview_drawexteriormodel));
70         //cvar_set("cl_sidespeed", ftos(warpzone_fixingview_sidespeed));
71         //cvar_set("cl_forwardspeed", ftos(warpzone_fixingview_forwardspeed));
72 }
73
74 float warpzone_saved;
75 vector warpzone_saved_origin;
76 vector warpzone_saved_angles;
77 void WarpZone_FixView()
78 {
79         float pd;
80         entity e;
81         warpzone_saved = 0;
82         warpzone_saved_origin = warpzone_fixview_origin;
83         warpzone_saved_angles = warpzone_fixview_angles;
84
85         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
86         if(e)
87         {
88                 warpzone_saved = 1;
89                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
90                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
91                 WarpZone_Inside();
92         }
93         else
94                 WarpZone_Outside();
95
96         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
97         float nearclip = 2;
98         e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip);
99         if(e)
100         {
101                 pd = WarpZone_PlaneDist(e, warpzone_fixview_origin);
102                 if(pd >= 0 && pd < nearclip)
103                 {
104                         warpzone_saved = 1;
105                         warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd);
106                 }
107         }
108
109         if(warpzone_saved)
110         {
111                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
112                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
113         }
114 }
115 void WarpZone_UnFixView()
116 {
117         if(warpzone_saved)
118         {
119                 warpzone_fixview_origin = warpzone_saved_origin;
120                 warpzone_fixview_angles = warpzone_saved_angles;
121                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
122                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
123         }
124 }
125
126 void WarpZone_Init()
127 {
128 }
129
130 void WarpZone_Shutdown()
131 {
132         WarpZone_Outside();
133 }