misc_laser is now client side too (untested too)
[divverent/nexuiz.git] / data / qcsrc / client / hook.qc
1 .vector HookStart;
2 .vector HookEnd;
3 .float HookKillTime;
4
5 void Draw_CylindricLine(vector from, vector to, float thickness, string texture, float aspect, vector rgb, float drawflag)
6 {
7         // I want to draw a quad...
8         // from and to are MIDPOINTS.
9         
10         float t;
11         vector axis, thickdir, A, B, C, D;
12         float length_tex;
13
14         t = -2 * time;
15         t = random();
16
17         axis = normalize(to - from);
18         length_tex = aspect * vlen(to - from) / thickness;
19
20         // direction is perpendicular to the view normal, and perpendicular to the axis
21         thickdir = normalize(cross(axis, view_origin - from));
22
23         A = from - thickdir * (thickness / 2);
24         B = from + thickdir * (thickness / 2);
25         C = to + thickdir * (thickness / 2);
26         D = to - thickdir * (thickness / 2);
27
28         R_BeginPolygon(texture, drawflag);
29         R_PolygonVertex(A, '0 0 0' + t * '1 0 0', rgb, 1);
30         R_PolygonVertex(B, '0 1 0' + t * '1 0 0', rgb, 1);
31         R_PolygonVertex(C, '0 1 0' + (t + length_tex) * '1 0 0', rgb, 1);
32         R_PolygonVertex(D, '0 0 0' + (t + length_tex) * '1 0 0', rgb, 1);
33         R_EndPolygon();
34 }
35
36 void Draw_GrapplingHook()
37 {
38         vector a, b, o;
39         string tex;
40         vector rgb;
41
42         if(time >= self.HookKillTime)
43                 return;
44         if(self.sv_entnum == player_localentnum - 1)
45                 a = view_origin + view_forward * 8 - view_right * 8 + view_up * -12;
46         else
47                 a = self.HookStart;
48         b = self.HookEnd;
49         if(self.team == COLOR_TEAM1)
50         {
51                 tex = "particles/hook_red";
52                 rgb = '1 .3 .3';
53         }
54         else if(self.team == COLOR_TEAM2)
55         {
56                 tex = "particles/hook_blue";
57                 rgb = '.3 .3 1';
58         }
59         else if(self.team == COLOR_TEAM3)
60         {
61                 tex = "particles/hook_yellow";
62                 rgb = '1 1 .3';
63         }
64         else if(self.team == COLOR_TEAM4)
65         {
66                 tex = "particles/hook_pink";
67                 rgb = '1 .3 1';
68         }
69         else
70         {
71                 tex = "particles/hook_green";
72                 rgb = '.3 1 .3';
73         }
74         if(checkextension("DP_SV_WRITEPICTURE"))
75                 Draw_CylindricLine(b, a, 8, tex, 0.25, '1 1 1', DRAWFLAG_NORMAL);
76         else
77                 Draw_CylindricLine(b, a, 1, "", 0.25, rgb, DRAWFLAG_NORMAL);
78 }
79
80 void Net_GrapplingHook()
81 {
82         float i;
83         vector start, end;
84         entity p;
85
86         i = ReadShort();
87         end_x = ReadCoord();
88         end_y = ReadCoord();
89         end_z = ReadCoord();
90         start_x = ReadCoord();
91         start_y = ReadCoord();
92         start_z = ReadCoord();
93
94         if(i <= 0 || i >= 256) // not owned by a client
95                 return;
96         --i;
97
98         p = playerslots[i];
99         if(!p)
100                 return;
101
102         p.HookKillTime = time + 0.1;
103         p.HookStart = start;
104         p.HookEnd = end;
105         p.draw = Draw_GrapplingHook;
106 }