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_waitrelease;
7 .entity crylink_lastgroup;
12 void W_Crylink_CheckLinks(entity e)
18 error("W_Crylink_CheckLinks: entity is world");
21 for(i = 0; i < 1000; ++i)
23 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
24 error("W_Crylink_CheckLinks: queue is inconsistent");
30 error("W_Crylink_CheckLinks: infinite chain");
33 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
35 if(me == own.crylink_lastgroup)
36 own.crylink_lastgroup = ((me == next) ? world : next);
37 prev.queuenext = next;
38 next.queueprev = prev;
41 void W_Crylink_Dequeue(entity e)
43 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
46 // force projectile to explode
47 void W_Crylink_LinkExplode (entity e, entity e2)
50 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
52 if(e == e.realowner.crylink_lastgroup)
53 e.realowner.crylink_lastgroup = world;
55 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);
58 W_Crylink_LinkExplode(e.queuenext, e2);
63 // adjust towards center
64 // returns the origin where they will meet... and the time till the meeting is
65 // stored in w_crylink_linkjoin_time.
66 // could possibly network this origin and time, and display a special particle
67 // effect when projectiles meet there :P
68 // jspeed: MINIMUM jing speed
69 // jtime: MAXIMUM jing time (0: none)
70 float w_crylink_linkjoin_time;
71 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
73 vector avg_origin, avg_velocity;
78 // FIXME remove this debug code
79 W_Crylink_CheckLinks(e);
81 w_crylink_linkjoin_time = 0;
83 avg_origin = e.origin;
84 avg_velocity = e.velocity;
86 for(p = e; (p = p.queuenext) != e; )
88 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
89 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
92 avg_origin *= (1.0 / n);
93 avg_velocity *= (1.0 / n);
96 return avg_origin; // nothing to do
98 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
99 avg_dist = pow(vlen(e.origin - avg_origin), 2);
100 for(p = e; (p = p.queuenext) != e; )
101 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
102 avg_dist *= (1.0 / n);
103 avg_dist = sqrt(avg_dist);
106 return avg_origin; // no change needed
108 if(jspeed == 0 && jtime == 0)
110 e.velocity = avg_velocity;
111 UpdateCSQCProjectile(e);
112 for(p = e; (p = p.queuenext) != e; )
114 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
115 UpdateCSQCProjectile(p);
123 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
125 w_crylink_linkjoin_time = jtime;
128 w_crylink_linkjoin_time = avg_dist / jspeed;
129 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
131 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
132 UpdateCSQCProjectile(e);
133 for(p = e; (p = p.queuenext) != e; )
135 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
136 UpdateCSQCProjectile(p);
140 // jspeed -> +infinity:
141 // w_crylink_linkjoin_time -> +0
142 // targ_origin -> avg_origin
143 // p->velocity -> HUEG towards center
145 // w_crylink_linkjoin_time -> +/- infinity
146 // targ_origin -> avg_velocity * +/- infinity
147 // p->velocity -> avg_velocity
148 // jspeed -> -infinity:
149 // w_crylink_linkjoin_time -> -0
150 // targ_origin -> avg_origin
151 // p->velocity -> HUEG away from center
157 void W_Crylink_LinkJoinEffect_Think()
159 // is there at least 2 projectiles very close?
162 e = self.owner.crylink_lastgroup;
166 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
168 for(p = e; (p = p.queuenext) != e; )
170 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
175 if(e.projectiledeathtype & HITTYPE_SECONDARY)
177 if(cvar("g_balance_crylink_secondary_joinexplode"))
179 n = n / cvar("g_balance_crylink_secondary_shots");
180 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_secondary_joinexplode_damage") * n,
181 cvar("g_balance_crylink_secondary_joinexplode_edgedamage") * n,
182 cvar("g_balance_crylink_secondary_joinexplode_radius") * n, e.realowner,
183 cvar("g_balance_crylink_secondary_joinexplode_force") * n, e.projectiledeathtype, other);
185 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
190 if(cvar("g_balance_crylink_primary_joinexplode"))
192 n = n / cvar("g_balance_crylink_primary_shots");
193 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_joinexplode_damage") * n,
194 cvar("g_balance_crylink_primary_joinexplode_edgedamage") * n,
195 cvar("g_balance_crylink_primary_joinexplode_radius") * n, e.realowner,
196 cvar("g_balance_crylink_primary_joinexplode_force") * n, e.projectiledeathtype, other);
198 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
207 // NO bounce protection, as bounces are limited!
208 void W_Crylink_Touch (void)
213 local entity savenext, saveprev, saveown;
214 saveown = self.realowner;
215 savenext = self.queuenext;
216 saveprev = self.queueprev;
217 if(WarpZone_Projectile_Touch())
220 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
225 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
227 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
231 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
234 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) && cvar("g_balance_crylink_primary_linkexplode"))
236 if(self == self.realowner.crylink_lastgroup)
237 self.realowner.crylink_lastgroup = world;
238 W_Crylink_LinkExplode(self.queuenext, self);
245 W_Crylink_Dequeue(self);
249 self.cnt = self.cnt - 1;
250 self.angles = vectoangles(self.velocity);
252 self.projectiledeathtype |= HITTYPE_BOUNCE;
253 // commented out as it causes a little hitch...
255 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
258 void W_Crylink_Touch2 (void)
263 local entity savenext, saveprev, saveown;
264 savenext = self.queuenext;
265 saveprev = self.queueprev;
266 saveown = self.realowner;
267 if(WarpZone_Projectile_Touch())
270 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
275 a = 1 - (time - self.fade_time) * self.fade_rate;
277 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
281 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
284 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) && cvar("g_balance_crylink_secondary_linkexplode"))
286 if(self == self.realowner.crylink_lastgroup)
287 self.realowner.crylink_lastgroup = world;
288 W_Crylink_LinkExplode(self.queuenext, self);
295 W_Crylink_Dequeue(self);
299 self.cnt = self.cnt - 1;
300 self.angles = vectoangles(self.velocity);
302 self.projectiledeathtype |= HITTYPE_BOUNCE;
303 // commented out as it causes a little hitch...
305 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
308 void W_Crylink_Fadethink (void)
310 W_Crylink_Dequeue(self);
314 void W_Crylink_Attack (void)
316 local float counter, shots;
317 local entity proj, prevproj, firstproj;
319 vector forward, right, up;
322 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
323 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
325 maxdmg = cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots");
326 maxdmg *= 1 + cvar("g_balance_crylink_primary_bouncedamagefactor") * cvar("g_balance_crylink_primary_bounces");
327 if(cvar("g_balance_crylink_primary_joinexplode"))
328 maxdmg += cvar("g_balance_crylink_primary_joinexplode_damage");
330 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
335 shots = cvar("g_balance_crylink_primary_shots");
336 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
338 while (counter < shots)
341 proj.realowner = proj.owner = self;
342 proj.classname = "spike";
343 proj.bot_dodge = TRUE;
344 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
346 proj.queuenext = proj;
347 proj.queueprev = proj;
349 else if(counter == 0) { // first projectile, store in firstproj for now
352 else if(counter == shots - 1) { // last projectile, link up with first projectile
353 prevproj.queuenext = proj;
354 firstproj.queueprev = proj;
355 proj.queuenext = firstproj;
356 proj.queueprev = prevproj;
358 else { // else link up with previous projectile
359 prevproj.queuenext = proj;
360 proj.queueprev = prevproj;
365 proj.movetype = MOVETYPE_BOUNCEMISSILE;
366 PROJECTILE_MAKETRIGGER(proj);
367 proj.projectiledeathtype = WEP_CRYLINK;
368 //proj.gravity = 0.001;
370 setorigin (proj, w_shotorg);
371 setsize(proj, '0 0 0', '0 0 0');
379 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
383 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
384 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0, FALSE);
385 proj.touch = W_Crylink_Touch;
387 proj.think = W_Crylink_Fadethink;
390 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
391 proj.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
392 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
396 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
397 proj.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
398 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
400 proj.cnt = cvar("g_balance_crylink_primary_bounces");
401 //proj.scale = 1 + 1 * proj.cnt;
403 proj.angles = vectoangles (proj.velocity);
405 //proj.glow_size = 20;
407 proj.flags = FL_PROJECTILE;
409 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
411 other = proj; MUTATOR_CALLHOOK(EditProjectile);
413 counter = counter + 1;
415 self.crylink_lastgroup = proj;
418 void W_Crylink_Attack2 (void)
420 local float counter, shots;
421 local entity proj, prevproj, firstproj;
424 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
425 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
427 maxdmg = cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots");
428 maxdmg *= 1 + cvar("g_balance_crylink_secondary_bouncedamagefactor") * cvar("g_balance_crylink_secondary_bounces");
429 if(cvar("g_balance_crylink_secondary_joinexplode"))
430 maxdmg += cvar("g_balance_crylink_secondary_joinexplode_damage");
432 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
434 shots = cvar("g_balance_crylink_secondary_shots");
435 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
437 while (counter < shots)
440 proj.realowner = proj.owner = self;
441 proj.classname = "spike";
442 proj.bot_dodge = TRUE;
443 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
445 proj.queuenext = proj;
446 proj.queueprev = proj;
448 else if(counter == 0) { // first projectile, store in firstproj for now
451 else if(counter == shots - 1) { // last projectile, link up with first projectile
452 prevproj.queuenext = proj;
453 firstproj.queueprev = proj;
454 proj.queuenext = firstproj;
455 proj.queueprev = prevproj;
457 else { // else link up with previous projectile
458 prevproj.queuenext = proj;
459 proj.queueprev = prevproj;
464 proj.movetype = MOVETYPE_BOUNCEMISSILE;
465 PROJECTILE_MAKETRIGGER(proj);
466 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
467 //proj.gravity = 0.001;
469 setorigin (proj, w_shotorg);
470 setsize(proj, '0 0 0', '0 0 0');
472 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, FALSE);
473 proj.touch = W_Crylink_Touch2;
474 proj.think = W_Crylink_Fadethink;
475 if(counter == (shots - 1) / 2)
477 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
478 proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
479 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
483 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
484 proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
485 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
487 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
488 //proj.scale = 1 + 1 * proj.cnt;
490 proj.angles = vectoangles (proj.velocity);
492 //proj.glow_size = 20;
494 proj.flags = FL_PROJECTILE;
496 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
498 other = proj; MUTATOR_CALLHOOK(EditProjectile);
500 counter = counter + 1;
502 self.crylink_lastgroup = proj;
505 void spawnfunc_weapon_crylink (void)
507 weapon_defaultspawnfunc(WEP_CRYLINK);
510 float w_crylink(float req)
515 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
517 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
519 else if (req == WR_THINK)
521 if (self.BUTTON_ATCK)
523 if (!self.crylink_waitrelease)
524 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
527 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
528 if(cvar("g_balance_crylink_primary_joinspread") != 0 || cvar("g_balance_crylink_primary_jointime") != 0)
529 self.crylink_waitrelease = 1;
532 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
534 if (!self.crylink_waitrelease)
535 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
538 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
539 if(cvar("g_balance_crylink_secondary_joinspread") != 0 || cvar("g_balance_crylink_secondary_jointime") != 0)
540 self.crylink_waitrelease = 2;
545 if (self.crylink_waitrelease)
547 // fired and released now!
548 if(self.crylink_lastgroup)
551 entity linkjoineffect;
554 if(self.crylink_waitrelease == 1)
556 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspread") * cvar("g_balance_crylink_primary_speed"), cvar("g_balance_crylink_primary_jointime"));
561 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspread") * cvar("g_balance_crylink_secondary_speed"), cvar("g_balance_crylink_secondary_jointime"));
564 linkjoineffect = spawn();
565 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
566 linkjoineffect.classname = "linkjoineffect";
567 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
568 linkjoineffect.owner = self;
569 setorigin(linkjoineffect, pos);
573 self.crylink_waitrelease = 0;
574 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
577 self.cnt = WEP_CRYLINK;
578 self.switchweapon = w_getbestweapon(self);
583 else if (req == WR_PRECACHE)
585 precache_model ("models/weapons/g_crylink.md3");
586 precache_model ("models/weapons/v_crylink.md3");
587 precache_model ("models/weapons/h_crylink.iqm");
588 precache_sound ("weapons/crylink_fire.wav");
589 precache_sound ("weapons/crylink_fire2.wav");
590 precache_sound ("weapons/crylink_linkjoin.wav");
592 else if (req == WR_SETUP)
593 weapon_setup(WEP_CRYLINK);
594 else if (req == WR_CHECKAMMO1)
596 // don't "run out of ammo" and switch weapons while waiting for release
597 if(self.crylink_lastgroup && self.crylink_waitrelease)
599 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
601 else if (req == WR_CHECKAMMO2)
603 // don't "run out of ammo" and switch weapons while waiting for release
604 if(self.crylink_lastgroup && self.crylink_waitrelease)
606 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
612 float w_crylink(float req)
614 if(req == WR_IMPACTEFFECT)
617 org2 = w_org + w_backoff * 2;
618 if(w_deathtype & HITTYPE_SECONDARY)
620 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
622 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
626 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
628 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
631 else if(req == WR_PRECACHE)
633 precache_sound("weapons/crylink_impact2.wav");
634 precache_sound("weapons/crylink_impact.wav");
636 else if (req == WR_SUICIDEMESSAGE)
638 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
640 else if (req == WR_KILLMESSAGE)
642 if(w_deathtype & HITTYPE_BOUNCE)
643 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
644 else if(w_deathtype & HITTYPE_SPLASH)
645 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
647 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY