change all function declarations (except builtins and data types) to ANSI C-like...
[divverent/nexuiz.git] / data / qcsrc / server / w_crylink.qc
1 .float gravity;
2 const vector proj_color = '1 1 1';
3
4 .entity realowner;
5
6 void W_Crylink_Touch (void)
7 {
8         float finalhit;
9         float f;
10         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
11         {
12                 remove(self);
13                 return;
14         }
15         pointparticles(particleeffectnum("crylink_impactbig"), self.origin, '0 0 0', 1);
16         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
17         if(finalhit)
18                 f = 1;
19         else
20                 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
21         if(self.alpha)
22                 f *= self.alpha;
23         RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, IT_CRYLINK);
24         if (finalhit)
25         {
26                 remove (self);
27                 return;
28         }
29         self.cnt = self.cnt - 1;
30         self.angles = vectoangles(self.velocity);
31         self.owner = world;
32         //self.scale = 1 + self.cnt;
33 }
34
35 void W_Crylink_Touch2 (void)
36 {
37         float finalhit;
38         float f;
39         if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
40         {
41                 remove(self);
42                 return;
43         }
44         pointparticles(particleeffectnum("crylink_impact"), self.origin, '0 0 0', 1);
45         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
46         if(finalhit)
47                 f = 1;
48         else
49                 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
50         if(self.alpha)
51                 f *= self.alpha;
52         RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, IT_CRYLINK);
53         if (finalhit)
54         {
55                 remove (self);
56                 return;
57         }
58         self.cnt = self.cnt - 1;
59         self.angles = vectoangles(self.velocity);
60         self.owner = world;
61 //      self.scale = 1 + 1 * self.cnt;
62 }
63
64 void W_Crylink_Attack (void)
65 {
66         local float counter, shots;
67         local entity proj;
68         local vector s;
69
70         if (cvar("g_use_ammunition"))
71                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
72
73         W_SetupShot (self, '25 8 -8', FALSE, 2, "weapons/crylink_fire.wav");
74
75         shots = cvar("g_balance_crylink_primary_shots");
76         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
77         while (counter < shots)
78         {
79                 proj = spawn ();
80                 proj.realowner = proj.owner = self;
81                 proj.classname = "spike";
82                 proj.bot_dodge = TRUE;
83                 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
84
85                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
86                 proj.solid = SOLID_BBOX;
87                 //proj.gravity = 0.001;
88
89                 setmodel (proj, "models/plasmatrail.mdl"); // precision set below
90                 setsize (proj, '0 0 0', '0 0 0');
91                 setorigin (proj, w_shotorg);
92
93                 s = '0 0 0';
94                 if (counter == 0)
95                         s = '0 0 0';
96                 else if (counter == 1)
97                         s = '0 0 1';
98                 else if (counter == 2)
99                         s = '0 -0.71 -0.71';
100                 else if (counter == 3)
101                         s = '0 0.71 -0.71';
102                 else
103                         s = randomvec();
104                 s = s * cvar("g_balance_crylink_primary_spread");
105                 proj.velocity = (w_shotdir + v_right * s_y + v_up * s_z) * cvar("g_balance_crylink_primary_speed");
106 //              proj.velocity = (w_shotdir + randomvec() * cvar("g_balance_crylink_primary_spread")) * cvar("g_balance_crylink_primary_speed");
107                 W_SetupProjectileVelocity(proj);
108                 proj.touch = W_Crylink_Touch;
109                 if(counter == 0)
110                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_middle_lifetime"), cvar("g_balance_crylink_primary_middle_fadetime"));
111                 else if(counter <= 3)
112                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_star_lifetime"), cvar("g_balance_crylink_primary_star_fadetime"));
113                 else
114                         SUB_SetFade(proj, time + cvar("g_balance_crylink_primary_other_lifetime"), cvar("g_balance_crylink_primary_other_fadetime"));
115                 proj.cnt = cvar("g_balance_crylink_primary_bounces");
116                 proj.scale = 1 + 1 * proj.cnt;
117
118                 proj.angles = vectoangles (proj.velocity);
119
120                 //proj.glow_size = 20;
121
122                 proj.effects = EF_LOWPRECISION;
123                 proj.flags = FL_PROJECTILE;
124                 proj.colormod = proj_color;
125                 counter = counter + 1;
126         }
127 }
128
129 void W_Crylink_Attack2 (void)
130 {
131         local float counter, shots;
132         local entity proj;
133
134         if (cvar("g_use_ammunition"))
135                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
136
137         W_SetupShot (self, '25 8 -8', FALSE, 2, "weapons/crylink_fire.wav");
138
139         shots = cvar("g_balance_crylink_secondary_shots");
140         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
141         while (counter < shots)
142         {
143                 proj = spawn ();
144                 proj.realowner = proj.owner = self;
145                 proj.classname = "spike";
146                 proj.bot_dodge = TRUE;
147                 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
148
149                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
150                 proj.solid = SOLID_BBOX;
151                 //proj.gravity = 0.001;
152
153                 setmodel (proj, "models/plasmatrail.mdl"); // precision set below
154                 setsize (proj, '0 0 0', '0 0 0');
155                 setorigin (proj, w_shotorg);
156
157                 proj.velocity = (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread")) * cvar("g_balance_crylink_secondary_speed");
158                 W_SetupProjectileVelocity(proj);
159                 proj.touch = W_Crylink_Touch2;
160                 if(counter == (shots - 1) / 2)
161                         SUB_SetFade(proj, time + cvar("g_balance_crylink_secondary_middle_lifetime"), cvar("g_balance_crylink_secondary_middle_fadetime"));
162                 else
163                         SUB_SetFade(proj, time + cvar("g_balance_crylink_secondary_line_lifetime"), cvar("g_balance_crylink_secondary_line_fadetime"));
164                 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
165                 proj.scale = 1 + 1 * proj.cnt;
166
167                 proj.angles = vectoangles (proj.velocity);
168
169                 //proj.glow_size = 20;
170
171                 proj.effects = EF_LOWPRECISION;
172                 proj.flags = FL_PROJECTILE;
173                 proj.colormod = proj_color;
174                 counter = counter + 1;
175         }
176 }
177
178
179 /*
180 // experimental lightning gun
181 void W_Crylink_Attack3 (void)
182 {
183         if (cvar("g_use_ammunition"))
184                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
185         W_SetupShot (self, '25 8 -8', TRUE, 0, "weapons/crylink_fire.wav");
186
187         traceline_antilag(self, w_shotorg, w_shotorg + w_shotdir * 1000, FALSE, self, self.ping * 0.001);
188
189         pointparticles(particleeffectnum("lightning_muzzleflash", w_shotorg, w_shotdir * 1000, 1);
190         pointparticles(particleeffectnum("lightning_impact", trace_endpos, trace_plane_normal * 1000, 1);
191         trailparticles(world, particleeffectnum("lightning_beam", w_shotorg, trace_endpos);
192
193         if (trace_fraction < 1)
194                 Damage(trace_ent, self, self, cvar("g_balance_crylink_primary_damage"), IT_CRYLINK, trace_endpos, '0 0 0');
195 }
196 */
197
198 float w_crylink(float req)
199 {
200         if (req == WR_AIM)
201         {
202                 if (random() > 0.15)
203                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
204                 else
205                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
206         }
207         else if (req == WR_THINK)
208         {
209                 if (self.BUTTON_ATCK)
210                 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
211                 {
212                         W_Crylink_Attack();
213                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
214                 }
215                 if (self.BUTTON_ATCK2)
216                 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
217                 {
218                         W_Crylink_Attack2();
219                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
220                 }
221         }
222         else if (req == WR_PRECACHE)
223         {
224                 precache_model ("models/plasma.mdl");
225                 precache_model ("models/plasmatrail.mdl");
226                 precache_model ("models/weapons/g_crylink.md3");
227                 precache_model ("models/weapons/v_crylink.md3");
228                 precache_model ("models/weapons/w_crylink.zym");
229                 precache_sound ("weapons/crylink_fire.wav");
230         }
231         else if (req == WR_SETUP)
232                 weapon_setup(WEP_CRYLINK, "crylink", IT_CELLS);
233         else if (req == WR_CHECKAMMO1)
234                 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
235         else if (req == WR_CHECKAMMO2)
236                 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
237         else if (req == WR_REGISTER)
238                 weapon_register(WEP_CRYLINK, min(cvar("g_balance_crylink_primary_ammo"), cvar("g_balance_crylink_secondary_ammo")));
239         return TRUE;
240 };