]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/hook.qc
CSQC handle func_sparks; more to come later (func_pointparticles planned); however...
[divverent/nexuiz.git] / data / qcsrc / client / hook.qc
1 .vector HookStart;
2 .vector HookEnd;
3 .float HookKillTime;
4
5 void Draw_GrapplingHookLine(vector from, vector to, float thickness, vector org, vector view_forward, string texture, float aspect, vector rgb)
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, org - 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, 0);
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         o = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);
43         makevectors(input_angles);
44
45         if(time >= self.HookKillTime)
46                 return;
47         if(self.sv_entnum == player_localentnum - 1)
48                 a = o + v_forward * 8 - v_right * 8 + v_up * -12;
49         else
50                 a = self.HookStart;
51         b = self.HookEnd;
52         if(self.team == COLOR_TEAM1)
53         {
54                 tex = "particles/hook_red";
55                 rgb = '1 .3 .3';
56         }
57         else if(self.team == COLOR_TEAM2)
58         {
59                 tex = "particles/hook_blue";
60                 rgb = '.3 .3 1';
61         }
62         else if(self.team == COLOR_TEAM3)
63         {
64                 tex = "particles/hook_yellow";
65                 rgb = '1 1 .3';
66         }
67         else if(self.team == COLOR_TEAM4)
68         {
69                 tex = "particles/hook_pink";
70                 rgb = '1 .3 1';
71         }
72         else
73         {
74                 tex = "particles/hook_green";
75                 rgb = '.3 1 .3';
76         }
77         if(checkextension("DP_SV_WRITEPICTURE"))
78                 Draw_GrapplingHookLine(b, a, 8, o, v_forward, tex, 0.25, '1 1 1');
79         else
80                 Draw_GrapplingHookLine(b, a, 1, o, v_forward, "", 0.25, rgb);
81 }
82
83 void Net_GrapplingHook()
84 {
85         float i;
86         vector start, end;
87         entity p;
88
89         i = ReadShort();
90         end_x = ReadCoord();
91         end_y = ReadCoord();
92         end_z = ReadCoord();
93         start_x = ReadCoord();
94         start_y = ReadCoord();
95         start_z = ReadCoord();
96
97         if(i <= 0 || i >= 256) // not owned by a client
98                 return;
99         --i;
100
101         p = playerslots[i];
102         if(!p)
103                 return;
104
105         p.HookKillTime = time + 0.1;
106         p.HookStart = start;
107         p.HookEnd = end;
108         p.draw = Draw_GrapplingHook;
109 }