2 REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", "Crylink");
6 .float crylink_release;
7 .entity crylink_lastgroup;
12 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
14 if(me == own.crylink_lastgroup)
15 own.crylink_lastgroup = ((me == next) ? world : next);
16 prev.queuenext = next;
17 next.queueprev = prev;
20 void W_Crylink_Dequeue(entity e)
22 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
25 // force projectile to explode
26 void W_Crylink_LinkExplode (entity e, entity e2)
29 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
31 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_damage") * a, cvar("g_balance_crylink_primary_edgedamage") * a, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * a, e.projectiledeathtype, other);
34 W_Crylink_LinkExplode(e.queuenext, e2);
38 // adjust towards center
39 // returns the origin where they will meet... and the time till the meeting is
40 // stored in w_crylink_linkjoin_time.
41 // could possibly network this origin and time, and display a special particle
42 // effect when projectiles meet there :P
43 float w_crylink_linkjoin_time;
44 vector W_Crylink_LinkJoin(entity e, float joinspeed)
46 vector avg_origin, avg_velocity;
51 avg_origin = e.origin;
52 avg_velocity = e.velocity;
54 for(p = e; (p = p.queuenext) != e; )
56 avg_origin += p.origin;
57 avg_velocity += p.velocity;
60 avg_origin *= (1.0 / n);
61 avg_velocity *= (1.0 / n);
63 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
64 avg_dist = pow(vlen(e.origin - avg_origin), 2);
65 for(p = e; (p = p.queuenext) != e; )
66 avg_dist += pow(vlen(e.origin - avg_origin), 2);
67 avg_dist *= (1.0 / n);
69 w_crylink_linkjoin_time = 0;
71 return avg_origin; // no change needed
75 e.velocity = avg_velocity;
76 UpdateCSQCProjectile(e);
77 for(p = e; (p = p.queuenext) != e; )
79 p.velocity = avg_velocity;
80 UpdateCSQCProjectile(p);
85 w_crylink_linkjoin_time = avg_dist / joinspeed;
86 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
88 e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
89 UpdateCSQCProjectile(e);
90 for(p = e; (p = p.queuenext) != e; )
92 p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
93 UpdateCSQCProjectile(p);
97 // joinspeed -> +infinity:
98 // w_crylink_linkjoin_time -> +0
99 // targ_origin -> avg_origin
100 // p->velocity -> HUEG towards center
102 // w_crylink_linkjoin_time -> +/- infinity
103 // targ_origin -> avg_velocity * +/- infinity
104 // p->velocity -> avg_velocity
105 // joinspeed -> -infinity:
106 // w_crylink_linkjoin_time -> -0
107 // targ_origin -> avg_origin
108 // p->velocity -> HUEG away from center
114 // NO bounce protection, as bounces are limited!
115 void W_Crylink_Touch (void)
120 local entity savenext, saveprev, saveown;
121 saveown = self.realowner;
122 savenext = self.queuenext;
123 saveprev = self.queueprev;
124 if(WarpZone_Projectile_Touch())
127 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
132 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
134 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
138 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
141 if (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, self.projectiledeathtype, other) || finalhit)
143 W_Crylink_LinkExplode(self.queuenext, self);
147 self.cnt = self.cnt - 1;
148 self.angles = vectoangles(self.velocity);
150 self.projectiledeathtype |= HITTYPE_BOUNCE;
151 // commented out as it causes a little hitch...
153 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
156 void W_Crylink_Touch2 (void)
161 local entity savenext, saveprev, saveown;
162 savenext = self.queuenext;
163 saveprev = self.queueprev;
164 saveown = self.realowner;
165 if(WarpZone_Projectile_Touch())
168 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
173 a = 1 - (time - self.fade_time) * self.fade_rate;
175 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
179 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
182 if (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, self.projectiledeathtype, other))
184 W_Crylink_LinkExplode(self.queuenext, self);
191 W_Crylink_Dequeue(self);
195 self.cnt = self.cnt - 1;
196 self.angles = vectoangles(self.velocity);
198 self.projectiledeathtype |= HITTYPE_BOUNCE;
199 // commented out as it causes a little hitch...
201 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
204 void W_Crylink_Fadethink (void)
206 W_Crylink_Dequeue(self);
210 void W_Crylink_Attack (void)
212 local float counter, shots;
213 local entity proj, prevproj, firstproj;
215 vector forward, right, up;
217 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
218 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
220 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
225 shots = cvar("g_balance_crylink_primary_shots");
226 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
228 while (counter < shots)
231 proj.realowner = proj.owner = self;
232 proj.classname = "spike";
233 proj.bot_dodge = TRUE;
234 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
235 if(counter == 0) { // first projectile, store in firstproj for now
238 else if(counter == shots - 1) { // last projectile, link up with first projectile
239 prevproj.queuenext = proj;
240 firstproj.queueprev = proj;
241 proj.queuenext = firstproj;
242 proj.queueprev = prevproj;
244 else { // else link up with previous projectile
245 prevproj.queuenext = proj;
246 proj.queueprev = prevproj;
251 proj.movetype = MOVETYPE_BOUNCEMISSILE;
252 PROJECTILE_MAKETRIGGER(proj);
253 proj.projectiledeathtype = WEP_CRYLINK;
254 //proj.gravity = 0.001;
256 setorigin (proj, w_shotorg);
257 setsize(proj, '0 0 0', '0 0 0');
265 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
269 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
270 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
271 proj.touch = W_Crylink_Touch;
273 proj.think = W_Crylink_Fadethink;
276 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
277 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
278 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
280 else if(counter <= 3)
282 proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
283 self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
284 proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
288 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
289 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
290 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
292 proj.cnt = cvar("g_balance_crylink_primary_bounces");
293 //proj.scale = 1 + 1 * proj.cnt;
295 proj.angles = vectoangles (proj.velocity);
297 //proj.glow_size = 20;
299 proj.flags = FL_PROJECTILE;
301 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
303 other = proj; MUTATOR_CALLHOOK(EditProjectile);
305 counter = counter + 1;
307 self.crylink_lastgroup = proj;
310 void W_Crylink_Attack2 (void)
312 local float counter, shots;
313 local entity proj, prevproj, firstproj;
315 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
316 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
318 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
320 shots = cvar("g_balance_crylink_secondary_shots");
321 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
323 while (counter < shots)
326 proj.realowner = proj.owner = self;
327 proj.classname = "spike";
328 proj.bot_dodge = TRUE;
329 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
330 if(counter == 0) { // first projectile, store in firstproj for now
333 else if(counter == shots - 1) { // last projectile, link up with first projectile
334 prevproj.queuenext = proj;
335 firstproj.queueprev = proj;
336 proj.queuenext = firstproj;
337 proj.queueprev = prevproj;
339 else { // else link up with previous projectile
340 prevproj.queuenext = proj;
341 proj.queueprev = prevproj;
346 proj.movetype = MOVETYPE_BOUNCEMISSILE;
347 PROJECTILE_MAKETRIGGER(proj);
348 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
349 //proj.gravity = 0.001;
351 setorigin (proj, w_shotorg);
352 setsize(proj, '0 0 0', '0 0 0');
354 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread") * g_weaponspreadfactor), v_up, cvar("g_balance_crylink_secondary_speed"), 0, 0, 0);
355 proj.touch = W_Crylink_Touch2;
356 proj.think = W_Crylink_Fadethink;
357 if(counter == (shots - 1) / 2)
359 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
360 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
361 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
365 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
366 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
367 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
369 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
370 //proj.scale = 1 + 1 * proj.cnt;
372 proj.angles = vectoangles (proj.velocity);
374 //proj.glow_size = 20;
376 proj.flags = FL_PROJECTILE;
378 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
380 other = proj; MUTATOR_CALLHOOK(EditProjectile);
382 counter = counter + 1;
384 self.crylink_lastgroup = proj;
387 void spawnfunc_weapon_crylink (void)
389 weapon_defaultspawnfunc(WEP_CRYLINK);
392 float w_crylink(float req)
397 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
399 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
401 else if (req == WR_THINK)
403 if (self.BUTTON_ATCK)
404 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
407 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
409 if (self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
410 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
413 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
416 else if (req == WR_PRECACHE)
418 precache_model ("models/weapons/g_crylink.md3");
419 precache_model ("models/weapons/v_crylink.md3");
420 precache_model ("models/weapons/h_crylink.iqm");
421 precache_sound ("weapons/crylink_fire.wav");
422 precache_sound ("weapons/crylink_fire2.wav");
424 else if (req == WR_SETUP)
425 weapon_setup(WEP_CRYLINK);
426 else if (req == WR_CHECKAMMO1)
427 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
428 else if (req == WR_CHECKAMMO2)
429 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
434 float w_crylink(float req)
436 if(req == WR_IMPACTEFFECT)
439 org2 = w_org + w_backoff * 2;
440 if(w_deathtype & HITTYPE_SECONDARY)
442 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
444 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
448 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
450 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
453 else if(req == WR_PRECACHE)
455 precache_sound("weapons/crylink_impact2.wav");
456 precache_sound("weapons/crylink_impact.wav");
458 else if (req == WR_SUICIDEMESSAGE)
460 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
462 else if (req == WR_KILLMESSAGE)
464 if(w_deathtype & HITTYPE_BOUNCE)
465 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
466 else if(w_deathtype & HITTYPE_SPLASH)
467 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
469 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY