make the cameras actually work
[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.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 #ifndef KEEP_ROLL
116 var float autocvar_cl_rollkillspeed = 10;
117 #endif
118 void WarpZone_FixView()
119 {
120         float pd;
121         entity e;
122         warpzone_saved = 0;
123         warpzone_saved_origin = warpzone_fixview_origin;
124         warpzone_saved_angles = warpzone_fixview_angles;
125
126 #ifndef KEEP_ROLL
127         if(autocvar_cl_rollkillspeed)
128                 R_SetView(VF_CL_VIEWANGLES_Z, input_angles_z * max(0, (1 - frametime * autocvar_cl_rollkillspeed)));
129         else
130                 R_SetView(VF_CL_VIEWANGLES_Z, 0);
131 #endif
132
133         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
134         if(e)
135         {
136                 warpzone_saved = 1;
137                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
138                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
139                 WarpZone_Inside();
140         }
141         else
142                 WarpZone_Outside();
143
144         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
145         float nearclip = 2;
146         e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip);
147         if(e)
148         {
149                 pd = WarpZone_PlaneDist(e, warpzone_fixview_origin);
150                 if(pd >= 0 && pd < nearclip)
151                 {
152                         warpzone_saved = 1;
153                         warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd);
154                 }
155         }
156
157         if(warpzone_saved)
158         {
159                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
160                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
161         }
162 }
163 void WarpZone_UnFixView()
164 {
165         if(warpzone_saved)
166         {
167                 warpzone_fixview_origin = warpzone_saved_origin;
168                 warpzone_fixview_angles = warpzone_saved_angles;
169                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
170                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
171         }
172 }
173
174 void WarpZone_Init()
175 {
176 }
177
178 void WarpZone_Shutdown()
179 {
180         WarpZone_Outside();
181 }