Cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / vehicles / vehicle / bumblebee_weapons.qc
1 #ifndef VEHICLE_BUMBLEBEE_WEAPONS_H
2 #define VEHICLE_BUMBLEBEE_WEAPONS_H
3
4 #include "../../weapons/all.qh"
5
6 #endif
7
8 #ifdef IMPLEMENTATION
9
10 #ifdef SVQC
11
12 float autocvar_g_vehicle_bumblebee_cannon_cost;
13 float autocvar_g_vehicle_bumblebee_cannon_damage;
14 float autocvar_g_vehicle_bumblebee_cannon_radius;
15 float autocvar_g_vehicle_bumblebee_cannon_refire;
16 float autocvar_g_vehicle_bumblebee_cannon_speed;
17 float autocvar_g_vehicle_bumblebee_cannon_spread;
18 float autocvar_g_vehicle_bumblebee_cannon_force;
19
20 bool bumble_raygun_send(entity this, entity to, int sf);
21
22 void bumblebee_fire_cannon(entity _gun, string _tagname, entity _owner)
23 {
24     vector v = gettaginfo(_gun, gettagindex(_gun, _tagname));
25     vehicles_projectile(EFFECT_BIGPLASMA_MUZZLEFLASH.eent_eff_name, SND(VEH_BUMBLEBEE_FIRE),
26                         v, normalize(v_forward + randomvec() * autocvar_g_vehicle_bumblebee_cannon_spread) * autocvar_g_vehicle_bumblebee_cannon_speed,
27                         autocvar_g_vehicle_bumblebee_cannon_damage, autocvar_g_vehicle_bumblebee_cannon_radius, autocvar_g_vehicle_bumblebee_cannon_force,  0,
28                         DEATH_VH_BUMB_GUN.m_id, PROJECTILE_BUMBLE_GUN, 0, true, true, _owner);
29 }
30
31 bool bumble_raygun_send(entity this, entity to, float sf)
32 {
33     WriteHeader(MSG_ENTITY, ENT_CLIENT_BUMBLE_RAYGUN);
34
35     WriteByte(MSG_ENTITY, sf);
36     if(sf & BRG_SETUP)
37     {
38         WriteByte(MSG_ENTITY, num_for_edict(self.realowner));
39         WriteByte(MSG_ENTITY, self.realowner.team);
40         WriteByte(MSG_ENTITY, self.cnt);
41     }
42
43     if(sf & BRG_START)
44     {
45         WriteCoord(MSG_ENTITY, self.hook_start_x);
46         WriteCoord(MSG_ENTITY, self.hook_start_y);
47         WriteCoord(MSG_ENTITY, self.hook_start_z);
48     }
49
50     if(sf & BRG_END)
51     {
52         WriteCoord(MSG_ENTITY, self.hook_end_x);
53         WriteCoord(MSG_ENTITY, self.hook_end_y);
54         WriteCoord(MSG_ENTITY, self.hook_end_z);
55     }
56
57     return true;
58 }
59
60 #endif
61
62 #ifdef CSQC
63
64 void bumble_raygun_draw(entity this);
65
66 NET_HANDLE(ENT_CLIENT_BUMBLE_RAYGUN, bool isnew)
67 {
68     int sf = ReadByte();
69
70     if(sf & BRG_SETUP)
71     {
72         self.cnt  = ReadByte();
73         self.team = ReadByte();
74         self.cnt  = ReadByte();
75
76         if(self.cnt)
77             self.colormod = '1 0 0';
78         else
79             self.colormod = '0 1 0';
80
81         self.traileffect = EFFECT_BUMBLEBEE_HEAL_MUZZLEFLASH.m_id;
82         self.lip = particleeffectnum(EFFECT_BUMBLEBEE_HEAL_IMPACT);
83
84         self.draw = bumble_raygun_draw;
85     }
86
87
88     if(sf & BRG_START)
89     {
90         self.origin_x = ReadCoord();
91         self.origin_y = ReadCoord();
92         self.origin_z = ReadCoord();
93         setorigin(self, self.origin);
94     }
95
96     if(sf & BRG_END)
97     {
98         self.move_origin_x = ReadCoord();
99         self.move_origin_y = ReadCoord();
100         self.move_origin_z = ReadCoord();
101     }
102     return true;
103 }
104
105 void bumble_raygun_draw(entity this)
106 {
107     float _len;
108     vector _dir;
109     vector _vtmp1, _vtmp2;
110
111     _len = vlen(self.origin - self.move_origin);
112     _dir = normalize(self.move_origin - self.origin);
113
114     if(self.total_damages < time)
115     {
116         boxparticles(particleeffectnum(Effects_from(self.traileffect)), self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA);
117         boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA);
118         self.total_damages = time + 0.1;
119     }
120
121     float i, df, sz, al;
122     for(i = -0.1; i < 0.2; i += 0.1)
123     {
124         df = DRAWFLAG_NORMAL; //((random() < 0.5) ? DRAWFLAG_ADDITIVE : DRAWFLAG_SCREEN);
125         sz = 5 + random() * 5;
126         al = 0.25 + random() * 0.5;
127         _vtmp1 = self.origin + _dir * _len * (0.25 + i);
128         _vtmp1 += (randomvec() * (_len * 0.2) * (frametime * 2));       //self.raygun_l1;
129         Draw_CylindricLine(self.origin, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
130
131         _vtmp2 = self.origin + _dir * _len * (0.5 + i);
132         _vtmp2 += (randomvec() * (_len * 0.2) * (frametime * 5));       //self.raygun_l2;
133         Draw_CylindricLine(_vtmp1, _vtmp2, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
134
135         _vtmp1 = self.origin + _dir * _len * (0.75 + i);
136         _vtmp1 += randomvec() * (_len * 0.2) * (frametime * 10);     //self.raygun_l3;
137         Draw_CylindricLine(_vtmp2, _vtmp1, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
138
139         Draw_CylindricLine(_vtmp1, self.move_origin +  randomvec() * 32, sz, "gfx/colors/white.tga", 1, 1, self.colormod, al, df, view_origin);
140     }
141 }
142
143 #endif
144
145 #endif