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");
19 if(e.classname != "spike")
20 error("W_Crylink_CheckLinks: entity is not a spike");
23 for(i = 0; i < 1000; ++i)
25 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
26 error("W_Crylink_CheckLinks: queue is inconsistent");
32 error("W_Crylink_CheckLinks: infinite chain");
35 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
37 W_Crylink_CheckLinks(next);
38 if(me == own.crylink_lastgroup)
39 own.crylink_lastgroup = ((me == next) ? world : next);
40 prev.queuenext = next;
41 next.queueprev = prev;
43 W_Crylink_CheckLinks(next);
46 void W_Crylink_Dequeue(entity e)
48 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
51 // force projectile to explode
52 void W_Crylink_LinkExplode (entity e, entity e2)
55 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
57 if(e == e.realowner.crylink_lastgroup)
58 e.realowner.crylink_lastgroup = world;
60 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);
63 W_Crylink_LinkExplode(e.queuenext, e2);
68 // adjust towards center
69 // returns the origin where they will meet... and the time till the meeting is
70 // stored in w_crylink_linkjoin_time.
71 // could possibly network this origin and time, and display a special particle
72 // effect when projectiles meet there :P
73 // jspeed: MINIMUM jing speed
74 // jtime: MAXIMUM jing time (0: none)
75 float w_crylink_linkjoin_time;
76 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
78 vector avg_origin, avg_velocity;
83 // FIXME remove this debug code
84 W_Crylink_CheckLinks(e);
86 w_crylink_linkjoin_time = 0;
88 avg_origin = e.origin;
89 avg_velocity = e.velocity;
91 for(p = e; (p = p.queuenext) != e; )
93 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
94 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
97 avg_origin *= (1.0 / n);
98 avg_velocity *= (1.0 / n);
101 return avg_origin; // nothing to do
103 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
104 avg_dist = pow(vlen(e.origin - avg_origin), 2);
105 for(p = e; (p = p.queuenext) != e; )
106 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
107 avg_dist *= (1.0 / n);
108 avg_dist = sqrt(avg_dist);
111 return avg_origin; // no change needed
113 if(jspeed == 0 && jtime == 0)
115 e.velocity = avg_velocity;
116 UpdateCSQCProjectile(e);
117 for(p = e; (p = p.queuenext) != e; )
119 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
120 UpdateCSQCProjectile(p);
128 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
130 w_crylink_linkjoin_time = jtime;
133 w_crylink_linkjoin_time = avg_dist / jspeed;
134 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
136 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
137 UpdateCSQCProjectile(e);
138 for(p = e; (p = p.queuenext) != e; )
140 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
141 UpdateCSQCProjectile(p);
145 // jspeed -> +infinity:
146 // w_crylink_linkjoin_time -> +0
147 // targ_origin -> avg_origin
148 // p->velocity -> HUEG towards center
150 // w_crylink_linkjoin_time -> +/- infinity
151 // targ_origin -> avg_velocity * +/- infinity
152 // p->velocity -> avg_velocity
153 // jspeed -> -infinity:
154 // w_crylink_linkjoin_time -> -0
155 // targ_origin -> avg_origin
156 // p->velocity -> HUEG away from center
159 W_Crylink_CheckLinks(e);
164 void W_Crylink_LinkJoinEffect_Think()
166 // is there at least 2 projectiles very close?
169 e = self.owner.crylink_lastgroup;
173 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
175 for(p = e; (p = p.queuenext) != e; )
177 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
182 if(e.projectiledeathtype & HITTYPE_SECONDARY)
184 if(autocvar_g_balance_crylink_secondary_joinexplode)
186 n = n / autocvar_g_balance_crylink_secondary_shots;
187 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
188 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
189 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
190 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
192 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
197 if(autocvar_g_balance_crylink_primary_joinexplode)
199 n = n / autocvar_g_balance_crylink_primary_shots;
200 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
201 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
202 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
203 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
205 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
214 // NO bounce protection, as bounces are limited!
215 void W_Crylink_Touch (void)
220 local entity savenext, saveprev, saveown;
221 saveown = self.realowner;
222 savenext = self.queuenext;
223 saveprev = self.queueprev;
224 if(WarpZone_Projectile_Touch())
227 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
232 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
234 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
238 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
241 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)
243 if(self == self.realowner.crylink_lastgroup)
244 self.realowner.crylink_lastgroup = world;
245 W_Crylink_LinkExplode(self.queuenext, self);
252 W_Crylink_Dequeue(self);
256 self.cnt = self.cnt - 1;
257 self.angles = vectoangles(self.velocity);
259 self.projectiledeathtype |= HITTYPE_BOUNCE;
260 // commented out as it causes a little hitch...
262 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
265 void W_Crylink_Touch2 (void)
270 local entity savenext, saveprev, saveown;
271 savenext = self.queuenext;
272 saveprev = self.queueprev;
273 saveown = self.realowner;
274 if(WarpZone_Projectile_Touch())
277 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
282 a = 1 - (time - self.fade_time) * self.fade_rate;
284 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
288 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
291 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)
293 if(self == self.realowner.crylink_lastgroup)
294 self.realowner.crylink_lastgroup = world;
295 W_Crylink_LinkExplode(self.queuenext, self);
302 W_Crylink_Dequeue(self);
306 self.cnt = self.cnt - 1;
307 self.angles = vectoangles(self.velocity);
309 self.projectiledeathtype |= HITTYPE_BOUNCE;
310 // commented out as it causes a little hitch...
312 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
315 void W_Crylink_Fadethink (void)
317 W_Crylink_Dequeue(self);
321 void W_Crylink_Attack (void)
323 local float counter, shots;
324 local entity proj, prevproj, firstproj;
326 vector forward, right, up;
329 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
330 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_primary_ammo;
332 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
333 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
334 if(autocvar_g_balance_crylink_primary_joinexplode)
335 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
337 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
342 shots = autocvar_g_balance_crylink_primary_shots;
343 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
345 while (counter < shots)
348 proj.realowner = proj.owner = self;
349 proj.classname = "spike";
350 proj.bot_dodge = TRUE;
351 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
353 proj.queuenext = proj;
354 proj.queueprev = proj;
356 else if(counter == 0) { // first projectile, store in firstproj for now
359 else if(counter == shots - 1) { // last projectile, link up with first projectile
360 prevproj.queuenext = proj;
361 firstproj.queueprev = proj;
362 proj.queuenext = firstproj;
363 proj.queueprev = prevproj;
365 else { // else link up with previous projectile
366 prevproj.queuenext = proj;
367 proj.queueprev = prevproj;
372 proj.movetype = MOVETYPE_BOUNCEMISSILE;
373 PROJECTILE_MAKETRIGGER(proj);
374 proj.projectiledeathtype = WEP_CRYLINK;
375 //proj.gravity = 0.001;
377 setorigin (proj, w_shotorg);
378 setsize(proj, '0 0 0', '0 0 0');
386 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
390 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
391 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
392 proj.touch = W_Crylink_Touch;
394 proj.think = W_Crylink_Fadethink;
397 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
398 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
399 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
403 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
404 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
405 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
407 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
408 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
409 //proj.scale = 1 + 1 * proj.cnt;
411 proj.angles = vectoangles (proj.velocity);
413 //proj.glow_size = 20;
415 proj.flags = FL_PROJECTILE;
417 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
419 other = proj; MUTATOR_CALLHOOK(EditProjectile);
421 counter = counter + 1;
423 self.crylink_lastgroup = proj;
424 W_Crylink_CheckLinks(proj);
427 void W_Crylink_Attack2 (void)
429 local float counter, shots;
430 local entity proj, prevproj, firstproj;
433 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
434 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_secondary_ammo;
436 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
437 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
438 if(autocvar_g_balance_crylink_secondary_joinexplode)
439 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
441 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
443 shots = autocvar_g_balance_crylink_secondary_shots;
444 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
446 while (counter < shots)
449 proj.realowner = proj.owner = self;
450 proj.classname = "spike";
451 proj.bot_dodge = TRUE;
452 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
454 proj.queuenext = proj;
455 proj.queueprev = proj;
457 else if(counter == 0) { // first projectile, store in firstproj for now
460 else if(counter == shots - 1) { // last projectile, link up with first projectile
461 prevproj.queuenext = proj;
462 firstproj.queueprev = proj;
463 proj.queuenext = firstproj;
464 proj.queueprev = prevproj;
466 else { // else link up with previous projectile
467 prevproj.queuenext = proj;
468 proj.queueprev = prevproj;
473 proj.movetype = MOVETYPE_BOUNCEMISSILE;
474 PROJECTILE_MAKETRIGGER(proj);
475 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
476 //proj.gravity = 0.001;
478 setorigin (proj, w_shotorg);
479 setsize(proj, '0 0 0', '0 0 0');
481 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);
482 proj.touch = W_Crylink_Touch2;
483 proj.think = W_Crylink_Fadethink;
484 if(counter == (shots - 1) / 2)
486 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
487 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
488 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
492 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
493 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
494 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
496 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
497 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
498 //proj.scale = 1 + 1 * proj.cnt;
500 proj.angles = vectoangles (proj.velocity);
502 //proj.glow_size = 20;
504 proj.flags = FL_PROJECTILE;
506 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
508 other = proj; MUTATOR_CALLHOOK(EditProjectile);
510 counter = counter + 1;
512 self.crylink_lastgroup = proj;
515 void spawnfunc_weapon_crylink (void)
517 weapon_defaultspawnfunc(WEP_CRYLINK);
520 float w_crylink(float req)
525 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
527 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
529 else if (req == WR_THINK)
531 if (self.BUTTON_ATCK)
533 if (!self.crylink_waitrelease)
534 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
537 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
538 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
539 self.crylink_waitrelease = 1;
542 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
544 if (!self.crylink_waitrelease)
545 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
548 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
549 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
550 self.crylink_waitrelease = 2;
555 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
557 // fired and released now!
558 if(self.crylink_lastgroup)
561 entity linkjoineffect;
563 if(self.crylink_waitrelease == 1)
565 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);
570 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);
573 linkjoineffect = spawn();
574 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
575 linkjoineffect.classname = "linkjoineffect";
576 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
577 linkjoineffect.owner = self;
578 setorigin(linkjoineffect, pos);
580 self.crylink_waitrelease = 0;
581 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
584 self.cnt = WEP_CRYLINK;
585 self.switchweapon = w_getbestweapon(self);
590 else if (req == WR_PRECACHE)
592 precache_model ("models/weapons/g_crylink.md3");
593 precache_model ("models/weapons/v_crylink.md3");
594 precache_model ("models/weapons/h_crylink.iqm");
595 precache_sound ("weapons/crylink_fire.wav");
596 precache_sound ("weapons/crylink_fire2.wav");
597 precache_sound ("weapons/crylink_linkjoin.wav");
599 else if (req == WR_SETUP)
600 weapon_setup(WEP_CRYLINK);
601 else if (req == WR_CHECKAMMO1)
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 >= autocvar_g_balance_crylink_primary_ammo;
608 else if (req == WR_CHECKAMMO2)
610 // don't "run out of ammo" and switch weapons while waiting for release
611 if(self.crylink_lastgroup && self.crylink_waitrelease)
613 return self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
619 float w_crylink(float req)
621 if(req == WR_IMPACTEFFECT)
624 org2 = w_org + w_backoff * 2;
625 if(w_deathtype & HITTYPE_SECONDARY)
627 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
629 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
633 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
635 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
638 else if(req == WR_PRECACHE)
640 precache_sound("weapons/crylink_impact2.wav");
641 precache_sound("weapons/crylink_impact.wav");
643 else if (req == WR_SUICIDEMESSAGE)
645 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
647 else if (req == WR_KILLMESSAGE)
649 if(w_deathtype & HITTYPE_BOUNCE)
650 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
651 else if(w_deathtype & HITTYPE_SPLASH)
652 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
654 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY