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 W_Crylink_CheckLinks(next);
36 if(me == own.crylink_lastgroup)
37 own.crylink_lastgroup = ((me == next) ? world : next);
38 prev.queuenext = next;
39 next.queueprev = prev;
41 W_Crylink_CheckLinks(next);
44 void W_Crylink_Dequeue(entity e)
46 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
49 // force projectile to explode
50 void W_Crylink_LinkExplode (entity e, entity e2)
53 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
55 if(e == e.realowner.crylink_lastgroup)
56 e.realowner.crylink_lastgroup = world;
58 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_damage * a, autocvar_g_balance_crylink_primary_edgedamage * a, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * a, e.projectiledeathtype, other);
61 W_Crylink_LinkExplode(e.queuenext, e2);
66 // adjust towards center
67 // returns the origin where they will meet... and the time till the meeting is
68 // stored in w_crylink_linkjoin_time.
69 // could possibly network this origin and time, and display a special particle
70 // effect when projectiles meet there :P
71 // jspeed: MINIMUM jing speed
72 // jtime: MAXIMUM jing time (0: none)
73 float w_crylink_linkjoin_time;
74 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
76 vector avg_origin, avg_velocity;
81 // FIXME remove this debug code
82 W_Crylink_CheckLinks(e);
84 w_crylink_linkjoin_time = 0;
86 avg_origin = e.origin;
87 avg_velocity = e.velocity;
89 for(p = e; (p = p.queuenext) != e; )
91 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
92 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
95 avg_origin *= (1.0 / n);
96 avg_velocity *= (1.0 / n);
99 return avg_origin; // nothing to do
101 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
102 avg_dist = pow(vlen(e.origin - avg_origin), 2);
103 for(p = e; (p = p.queuenext) != e; )
104 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
105 avg_dist *= (1.0 / n);
106 avg_dist = sqrt(avg_dist);
109 return avg_origin; // no change needed
111 if(jspeed == 0 && jtime == 0)
113 e.velocity = avg_velocity;
114 UpdateCSQCProjectile(e);
115 for(p = e; (p = p.queuenext) != e; )
117 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
118 UpdateCSQCProjectile(p);
126 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
128 w_crylink_linkjoin_time = jtime;
131 w_crylink_linkjoin_time = avg_dist / jspeed;
132 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
134 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
135 UpdateCSQCProjectile(e);
136 for(p = e; (p = p.queuenext) != e; )
138 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
139 UpdateCSQCProjectile(p);
143 // jspeed -> +infinity:
144 // w_crylink_linkjoin_time -> +0
145 // targ_origin -> avg_origin
146 // p->velocity -> HUEG towards center
148 // w_crylink_linkjoin_time -> +/- infinity
149 // targ_origin -> avg_velocity * +/- infinity
150 // p->velocity -> avg_velocity
151 // jspeed -> -infinity:
152 // w_crylink_linkjoin_time -> -0
153 // targ_origin -> avg_origin
154 // p->velocity -> HUEG away from center
157 W_Crylink_CheckLinks(e);
162 void W_Crylink_LinkJoinEffect_Think()
164 // is there at least 2 projectiles very close?
167 e = self.owner.crylink_lastgroup;
171 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
173 for(p = e; (p = p.queuenext) != e; )
175 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
180 if(e.projectiledeathtype & HITTYPE_SECONDARY)
182 if(autocvar_g_balance_crylink_secondary_joinexplode)
184 n = n / autocvar_g_balance_crylink_secondary_shots;
185 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
186 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
187 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
188 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
190 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
195 if(autocvar_g_balance_crylink_primary_joinexplode)
197 n = n / autocvar_g_balance_crylink_primary_shots;
198 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
199 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
200 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
201 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
203 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
212 // NO bounce protection, as bounces are limited!
213 void W_Crylink_Touch (void)
218 local entity savenext, saveprev, saveown;
219 saveown = self.realowner;
220 savenext = self.queuenext;
221 saveprev = self.queueprev;
222 if(WarpZone_Projectile_Touch())
225 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
230 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
232 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
236 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
239 if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_primary_damage * f, autocvar_g_balance_crylink_primary_edgedamage * f, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_primary_linkexplode)
241 if(self == self.realowner.crylink_lastgroup)
242 self.realowner.crylink_lastgroup = world;
243 W_Crylink_LinkExplode(self.queuenext, self);
250 W_Crylink_Dequeue(self);
254 self.cnt = self.cnt - 1;
255 self.angles = vectoangles(self.velocity);
257 self.projectiledeathtype |= HITTYPE_BOUNCE;
258 // commented out as it causes a little hitch...
260 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
263 void W_Crylink_Touch2 (void)
268 local entity savenext, saveprev, saveown;
269 savenext = self.queuenext;
270 saveprev = self.queueprev;
271 saveown = self.realowner;
272 if(WarpZone_Projectile_Touch())
275 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
280 a = 1 - (time - self.fade_time) * self.fade_rate;
282 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
286 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
289 if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_secondary_damage * f, autocvar_g_balance_crylink_secondary_edgedamage * f, autocvar_g_balance_crylink_secondary_radius, world, autocvar_g_balance_crylink_secondary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_secondary_linkexplode)
291 if(self == self.realowner.crylink_lastgroup)
292 self.realowner.crylink_lastgroup = world;
293 W_Crylink_LinkExplode(self.queuenext, self);
300 W_Crylink_Dequeue(self);
304 self.cnt = self.cnt - 1;
305 self.angles = vectoangles(self.velocity);
307 self.projectiledeathtype |= HITTYPE_BOUNCE;
308 // commented out as it causes a little hitch...
310 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
313 void W_Crylink_Fadethink (void)
315 W_Crylink_Dequeue(self);
319 void W_Crylink_Attack (void)
321 local float counter, shots;
322 local entity proj, prevproj, firstproj;
324 vector forward, right, up;
327 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
328 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_primary_ammo;
330 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
331 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
332 if(autocvar_g_balance_crylink_primary_joinexplode)
333 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
335 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
340 shots = autocvar_g_balance_crylink_primary_shots;
341 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
343 while (counter < shots)
346 proj.realowner = proj.owner = self;
347 proj.classname = "spike";
348 proj.bot_dodge = TRUE;
349 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
351 proj.queuenext = proj;
352 proj.queueprev = proj;
354 else if(counter == 0) { // first projectile, store in firstproj for now
357 else if(counter == shots - 1) { // last projectile, link up with first projectile
358 prevproj.queuenext = proj;
359 firstproj.queueprev = proj;
360 proj.queuenext = firstproj;
361 proj.queueprev = prevproj;
363 else { // else link up with previous projectile
364 prevproj.queuenext = proj;
365 proj.queueprev = prevproj;
370 proj.movetype = MOVETYPE_BOUNCEMISSILE;
371 PROJECTILE_MAKETRIGGER(proj);
372 proj.projectiledeathtype = WEP_CRYLINK;
373 //proj.gravity = 0.001;
375 setorigin (proj, w_shotorg);
376 setsize(proj, '0 0 0', '0 0 0');
384 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
388 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
389 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
390 proj.touch = W_Crylink_Touch;
392 proj.think = W_Crylink_Fadethink;
395 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
396 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
397 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
401 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
402 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
403 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
405 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
406 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
407 //proj.scale = 1 + 1 * proj.cnt;
409 proj.angles = vectoangles (proj.velocity);
411 //proj.glow_size = 20;
413 proj.flags = FL_PROJECTILE;
415 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
417 other = proj; MUTATOR_CALLHOOK(EditProjectile);
419 counter = counter + 1;
421 self.crylink_lastgroup = proj;
422 W_Crylink_CheckLinks(proj);
425 void W_Crylink_Attack2 (void)
427 local float counter, shots;
428 local entity proj, prevproj, firstproj;
431 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
432 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_secondary_ammo;
434 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
435 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
436 if(autocvar_g_balance_crylink_secondary_joinexplode)
437 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
439 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
441 shots = autocvar_g_balance_crylink_secondary_shots;
442 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
444 while (counter < shots)
447 proj.realowner = proj.owner = self;
448 proj.classname = "spike";
449 proj.bot_dodge = TRUE;
450 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
452 proj.queuenext = proj;
453 proj.queueprev = proj;
455 else if(counter == 0) { // first projectile, store in firstproj for now
458 else if(counter == shots - 1) { // last projectile, link up with first projectile
459 prevproj.queuenext = proj;
460 firstproj.queueprev = proj;
461 proj.queuenext = firstproj;
462 proj.queueprev = prevproj;
464 else { // else link up with previous projectile
465 prevproj.queuenext = proj;
466 proj.queueprev = prevproj;
471 proj.movetype = MOVETYPE_BOUNCEMISSILE;
472 PROJECTILE_MAKETRIGGER(proj);
473 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
474 //proj.gravity = 0.001;
476 setorigin (proj, w_shotorg);
477 setsize(proj, '0 0 0', '0 0 0');
479 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * autocvar_g_balance_crylink_secondary_spread * g_weaponspreadfactor), v_up, autocvar_g_balance_crylink_secondary_speed, 0, 0, 0, FALSE);
480 proj.touch = W_Crylink_Touch2;
481 proj.think = W_Crylink_Fadethink;
482 if(counter == (shots - 1) / 2)
484 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
485 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
486 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
490 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
491 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
492 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
494 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
495 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
496 //proj.scale = 1 + 1 * proj.cnt;
498 proj.angles = vectoangles (proj.velocity);
500 //proj.glow_size = 20;
502 proj.flags = FL_PROJECTILE;
504 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
506 other = proj; MUTATOR_CALLHOOK(EditProjectile);
508 counter = counter + 1;
510 self.crylink_lastgroup = proj;
513 void spawnfunc_weapon_crylink (void)
515 weapon_defaultspawnfunc(WEP_CRYLINK);
518 float w_crylink(float req)
523 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
525 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
527 else if (req == WR_THINK)
529 if (self.BUTTON_ATCK)
531 if (!self.crylink_waitrelease)
532 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
535 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
536 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
537 self.crylink_waitrelease = 1;
540 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
542 if (!self.crylink_waitrelease)
543 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
546 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
547 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
548 self.crylink_waitrelease = 2;
553 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
555 // fired and released now!
556 if(self.crylink_lastgroup)
559 entity linkjoineffect;
561 if(self.crylink_waitrelease == 1)
563 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_primary_joinspread * autocvar_g_balance_crylink_primary_speed, autocvar_g_balance_crylink_primary_jointime);
568 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_secondary_joinspread * autocvar_g_balance_crylink_secondary_speed, autocvar_g_balance_crylink_secondary_jointime);
571 linkjoineffect = spawn();
572 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
573 linkjoineffect.classname = "linkjoineffect";
574 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
575 linkjoineffect.owner = self;
576 setorigin(linkjoineffect, pos);
578 self.crylink_waitrelease = 0;
579 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
582 self.cnt = WEP_CRYLINK;
583 self.switchweapon = w_getbestweapon(self);
588 else if (req == WR_PRECACHE)
590 precache_model ("models/weapons/g_crylink.md3");
591 precache_model ("models/weapons/v_crylink.md3");
592 precache_model ("models/weapons/h_crylink.iqm");
593 precache_sound ("weapons/crylink_fire.wav");
594 precache_sound ("weapons/crylink_fire2.wav");
595 precache_sound ("weapons/crylink_linkjoin.wav");
597 else if (req == WR_SETUP)
598 weapon_setup(WEP_CRYLINK);
599 else if (req == WR_CHECKAMMO1)
601 // don't "run out of ammo" and switch weapons while waiting for release
602 if(self.crylink_lastgroup && self.crylink_waitrelease)
604 return self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
606 else if (req == WR_CHECKAMMO2)
608 // don't "run out of ammo" and switch weapons while waiting for release
609 if(self.crylink_lastgroup && self.crylink_waitrelease)
611 return self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
617 float w_crylink(float req)
619 if(req == WR_IMPACTEFFECT)
622 org2 = w_org + w_backoff * 2;
623 if(w_deathtype & HITTYPE_SECONDARY)
625 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
627 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
631 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
633 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
636 else if(req == WR_PRECACHE)
638 precache_sound("weapons/crylink_impact2.wav");
639 precache_sound("weapons/crylink_impact.wav");
641 else if (req == WR_SUICIDEMESSAGE)
643 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
645 else if (req == WR_KILLMESSAGE)
647 if(w_deathtype & HITTYPE_BOUNCE)
648 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
649 else if(w_deathtype & HITTYPE_SPLASH)
650 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
652 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY