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