]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/warpzonelib/client.qc
Merge commit '9805d7cf0ce8875950b667e16982fcecd02068ad'
[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 float warpzone_saved;
106 vector warpzone_saved_origin;
107 vector warpzone_saved_angles;
108 vector warpzone_saved_cl_viewangles;
109 #ifndef KEEP_ROLL
110 var float autocvar_cl_rollkillspeed = 10;
111 #endif
112 void WarpZone_FixView()
113 {
114         float pd, f;
115         entity e;
116         warpzone_saved = 0;
117         warpzone_saved_origin = warpzone_fixview_origin;
118         warpzone_saved_angles = warpzone_fixview_angles;
119         warpzone_saved_cl_viewangles = warpzone_fixview_cl_viewangles;
120
121 #ifndef KEEP_ROLL
122         if(warpzone_fixview_angles_z != 0 || warpzone_fixview_cl_viewangles_z != 0)
123         {
124                 if(autocvar_cl_rollkillspeed)
125                         f = max(0, (1 - frametime * autocvar_cl_rollkillspeed));
126                 else
127                         f = 0;
128                 warpzone_fixview_angles_z *= f;
129                 warpzone_fixview_cl_viewangles_z *= f;
130                 warpzone_saved_angles_z *= f; // PERMANENTLY apply that change!
131                 warpzone_saved_cl_viewangles_z *= f; // PERMANENTLY apply that change!
132                 warpzone_saved = 2;
133                 R_SetView(VF_CL_VIEWANGLES_Z, warpzone_fixview_angles_z);
134         }
135 #endif
136
137         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
138         if(e)
139         {
140                 warpzone_saved = 1;
141                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
142                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
143                 warpzone_fixview_cl_viewangles = WarpZone_TransformVAngles(e, warpzone_fixview_cl_viewangles);
144                 WarpZone_Inside();
145         }
146         else
147                 WarpZone_Outside();
148
149         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
150         float nearclip = 4;
151         e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip);
152         if(e)
153         {
154                 pd = WarpZone_PlaneDist(e, warpzone_fixview_origin);
155                 if(pd >= 0 && pd < nearclip)
156                 {
157                         warpzone_saved = 1;
158                         warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd);
159                 }
160         }
161
162         if(warpzone_saved == 1)
163         {
164                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
165                 R_SetView(VF_ANGLES, warpzone_fixview_cl_viewangles);
166         }
167 }
168 void WarpZone_UnFixView()
169 {
170         if(warpzone_saved)
171         {
172                 warpzone_fixview_origin = warpzone_saved_origin;
173                 warpzone_fixview_angles = warpzone_saved_angles;
174                 warpzone_fixview_cl_viewangles = warpzone_saved_cl_viewangles;
175                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
176                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
177                 R_SetView(VF_CL_VIEWANGLES, warpzone_fixview_cl_viewangles);
178         }
179 }
180
181 void WarpZone_Init()
182 {
183 }
184
185 void WarpZone_Shutdown()
186 {
187         WarpZone_Outside();
188 }