2 REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", _("Crylink"));
6 .float crylink_waitrelease;
7 .entity crylink_lastgroup;
12 void W_Crylink_Reload()
14 self.reload_ammo_player = ammo_cells;
15 self.reload_ammo_min = min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo);
16 self.reload_ammo_amount = autocvar_g_balance_crylink_reload_ammo;
17 self.reload_time = autocvar_g_balance_crylink_reload_time;
18 self.reload_sound = "weapons/reload.wav";
23 void W_Crylink_CheckLinks(entity e)
29 error("W_Crylink_CheckLinks: entity is world");
30 if(e.classname != "spike")
31 error("W_Crylink_CheckLinks: entity is not a spike");
34 for(i = 0; i < 1000; ++i)
36 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
37 error("W_Crylink_CheckLinks: queue is inconsistent");
43 error("W_Crylink_CheckLinks: infinite chain");
46 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
48 W_Crylink_CheckLinks(next);
49 if(me == own.crylink_lastgroup)
50 own.crylink_lastgroup = ((me == next) ? world : next);
51 prev.queuenext = next;
52 next.queueprev = prev;
54 W_Crylink_CheckLinks(next);
57 void W_Crylink_Dequeue(entity e)
59 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
62 // force projectile to explode
63 void W_Crylink_LinkExplode (entity e, entity e2)
66 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
68 if(e == e.realowner.crylink_lastgroup)
69 e.realowner.crylink_lastgroup = world;
71 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);
74 W_Crylink_LinkExplode(e.queuenext, e2);
79 // adjust towards center
80 // returns the origin where they will meet... and the time till the meeting is
81 // stored in w_crylink_linkjoin_time.
82 // could possibly network this origin and time, and display a special particle
83 // effect when projectiles meet there :P
84 // jspeed: MINIMUM jing speed
85 // jtime: MAXIMUM jing time (0: none)
86 float w_crylink_linkjoin_time;
87 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
89 vector avg_origin, avg_velocity;
94 // FIXME remove this debug code
95 W_Crylink_CheckLinks(e);
97 w_crylink_linkjoin_time = 0;
99 avg_origin = e.origin;
100 avg_velocity = e.velocity;
102 for(p = e; (p = p.queuenext) != e; )
104 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
105 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
108 avg_origin *= (1.0 / n);
109 avg_velocity *= (1.0 / n);
112 return avg_origin; // nothing to do
114 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
115 avg_dist = pow(vlen(e.origin - avg_origin), 2);
116 for(p = e; (p = p.queuenext) != e; )
117 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
118 avg_dist *= (1.0 / n);
119 avg_dist = sqrt(avg_dist);
122 return avg_origin; // no change needed
124 if(jspeed == 0 && jtime == 0)
126 e.velocity = avg_velocity;
127 UpdateCSQCProjectile(e);
128 for(p = e; (p = p.queuenext) != e; )
130 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
131 UpdateCSQCProjectile(p);
139 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
141 w_crylink_linkjoin_time = jtime;
144 w_crylink_linkjoin_time = avg_dist / jspeed;
145 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
147 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
148 UpdateCSQCProjectile(e);
149 for(p = e; (p = p.queuenext) != e; )
151 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
152 UpdateCSQCProjectile(p);
156 // jspeed -> +infinity:
157 // w_crylink_linkjoin_time -> +0
158 // targ_origin -> avg_origin
159 // p->velocity -> HUEG towards center
161 // w_crylink_linkjoin_time -> +/- infinity
162 // targ_origin -> avg_velocity * +/- infinity
163 // p->velocity -> avg_velocity
164 // jspeed -> -infinity:
165 // w_crylink_linkjoin_time -> -0
166 // targ_origin -> avg_origin
167 // p->velocity -> HUEG away from center
170 W_Crylink_CheckLinks(e);
175 void W_Crylink_LinkJoinEffect_Think()
177 // is there at least 2 projectiles very close?
180 e = self.owner.crylink_lastgroup;
184 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
186 for(p = e; (p = p.queuenext) != e; )
188 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
193 if(e.projectiledeathtype & HITTYPE_SECONDARY)
195 if(autocvar_g_balance_crylink_secondary_joinexplode)
197 n = n / autocvar_g_balance_crylink_secondary_shots;
198 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
199 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
200 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
201 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
203 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
208 if(autocvar_g_balance_crylink_primary_joinexplode)
210 n = n / autocvar_g_balance_crylink_primary_shots;
211 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
212 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
213 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
214 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
216 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
225 // NO bounce protection, as bounces are limited!
226 void W_Crylink_Touch (void)
231 local entity savenext, saveprev, saveown;
232 saveown = self.realowner;
233 savenext = self.queuenext;
234 saveprev = self.queueprev;
235 if(WarpZone_Projectile_Touch())
238 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
243 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
245 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
249 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
252 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)
254 if(self == self.realowner.crylink_lastgroup)
255 self.realowner.crylink_lastgroup = world;
256 W_Crylink_LinkExplode(self.queuenext, self);
263 W_Crylink_Dequeue(self);
267 self.cnt = self.cnt - 1;
268 self.angles = vectoangles(self.velocity);
270 self.projectiledeathtype |= HITTYPE_BOUNCE;
271 // commented out as it causes a little hitch...
273 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
276 void W_Crylink_Touch2 (void)
281 local entity savenext, saveprev, saveown;
282 savenext = self.queuenext;
283 saveprev = self.queueprev;
284 saveown = self.realowner;
285 if(WarpZone_Projectile_Touch())
288 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
293 a = 1 - (time - self.fade_time) * self.fade_rate;
295 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
299 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
302 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)
304 if(self == self.realowner.crylink_lastgroup)
305 self.realowner.crylink_lastgroup = world;
306 W_Crylink_LinkExplode(self.queuenext, self);
313 W_Crylink_Dequeue(self);
317 self.cnt = self.cnt - 1;
318 self.angles = vectoangles(self.velocity);
320 self.projectiledeathtype |= HITTYPE_BOUNCE;
321 // commented out as it causes a little hitch...
323 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
326 void W_Crylink_Fadethink (void)
328 W_Crylink_Dequeue(self);
332 void W_Crylink_Attack (void)
334 local float counter, shots;
335 local entity proj, prevproj, firstproj;
337 vector forward, right, up;
340 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
341 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
343 if(autocvar_g_balance_crylink_reload_ammo)
345 self.clip_load -= autocvar_g_balance_crylink_primary_ammo;
346 self.weapon_load[WEP_CRYLINK] = self.clip_load;
349 self.ammo_cells -= autocvar_g_balance_crylink_primary_ammo;
352 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
353 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
354 if(autocvar_g_balance_crylink_primary_joinexplode)
355 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
357 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
362 shots = autocvar_g_balance_crylink_primary_shots;
363 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
365 while (counter < shots)
368 proj.realowner = proj.owner = self;
369 proj.classname = "spike";
370 proj.bot_dodge = TRUE;
371 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
373 proj.queuenext = proj;
374 proj.queueprev = proj;
376 else if(counter == 0) { // first projectile, store in firstproj for now
379 else if(counter == shots - 1) { // last projectile, link up with first projectile
380 prevproj.queuenext = proj;
381 firstproj.queueprev = proj;
382 proj.queuenext = firstproj;
383 proj.queueprev = prevproj;
385 else { // else link up with previous projectile
386 prevproj.queuenext = proj;
387 proj.queueprev = prevproj;
392 proj.movetype = MOVETYPE_BOUNCEMISSILE;
393 PROJECTILE_MAKETRIGGER(proj);
394 proj.projectiledeathtype = WEP_CRYLINK;
395 //proj.gravity = 0.001;
397 setorigin (proj, w_shotorg);
398 setsize(proj, '0 0 0', '0 0 0');
406 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
410 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
411 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
412 proj.touch = W_Crylink_Touch;
414 proj.think = W_Crylink_Fadethink;
417 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
418 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
419 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
423 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
424 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
425 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
427 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
428 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
429 //proj.scale = 1 + 1 * proj.cnt;
431 proj.angles = vectoangles (proj.velocity);
433 //proj.glow_size = 20;
435 proj.flags = FL_PROJECTILE;
437 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
439 other = proj; MUTATOR_CALLHOOK(EditProjectile);
441 counter = counter + 1;
443 self.crylink_lastgroup = proj;
444 W_Crylink_CheckLinks(proj);
447 void W_Crylink_Attack2 (void)
449 local float counter, shots;
450 local entity proj, prevproj, firstproj;
453 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
454 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
456 if(autocvar_g_balance_crylink_reload_ammo)
458 self.clip_load -= autocvar_g_balance_crylink_secondary_ammo;
459 self.weapon_load[WEP_CRYLINK] = self.clip_load;
462 self.ammo_cells -= autocvar_g_balance_crylink_secondary_ammo;
465 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
466 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
467 if(autocvar_g_balance_crylink_secondary_joinexplode)
468 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
470 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
472 shots = autocvar_g_balance_crylink_secondary_shots;
473 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
475 while (counter < shots)
478 proj.realowner = proj.owner = self;
479 proj.classname = "spike";
480 proj.bot_dodge = TRUE;
481 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
483 proj.queuenext = proj;
484 proj.queueprev = proj;
486 else if(counter == 0) { // first projectile, store in firstproj for now
489 else if(counter == shots - 1) { // last projectile, link up with first projectile
490 prevproj.queuenext = proj;
491 firstproj.queueprev = proj;
492 proj.queuenext = firstproj;
493 proj.queueprev = prevproj;
495 else { // else link up with previous projectile
496 prevproj.queuenext = proj;
497 proj.queueprev = prevproj;
502 proj.movetype = MOVETYPE_BOUNCEMISSILE;
503 PROJECTILE_MAKETRIGGER(proj);
504 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
505 //proj.gravity = 0.001;
507 setorigin (proj, w_shotorg);
508 setsize(proj, '0 0 0', '0 0 0');
510 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);
511 proj.touch = W_Crylink_Touch2;
512 proj.think = W_Crylink_Fadethink;
513 if(counter == (shots - 1) / 2)
515 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
516 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
517 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
521 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
522 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
523 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
525 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
526 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
527 //proj.scale = 1 + 1 * proj.cnt;
529 proj.angles = vectoangles (proj.velocity);
531 //proj.glow_size = 20;
533 proj.flags = FL_PROJECTILE;
535 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
537 other = proj; MUTATOR_CALLHOOK(EditProjectile);
539 counter = counter + 1;
541 self.crylink_lastgroup = proj;
544 void spawnfunc_weapon_crylink (void)
546 weapon_defaultspawnfunc(WEP_CRYLINK);
549 float w_crylink(float req)
555 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
557 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
559 else if (req == WR_THINK)
561 if(autocvar_g_balance_crylink_reload_ammo && self.clip_load < min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo)) // forced reload
563 else if (self.BUTTON_ATCK)
565 if (!self.crylink_waitrelease)
566 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
569 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
570 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
571 self.crylink_waitrelease = 1;
574 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
576 if (!self.crylink_waitrelease)
577 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
580 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
581 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
582 self.crylink_waitrelease = 2;
587 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
589 // fired and released now!
590 if(self.crylink_lastgroup)
593 entity linkjoineffect;
595 if(self.crylink_waitrelease == 1)
597 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);
602 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);
605 linkjoineffect = spawn();
606 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
607 linkjoineffect.classname = "linkjoineffect";
608 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
609 linkjoineffect.owner = self;
610 setorigin(linkjoineffect, pos);
612 self.crylink_waitrelease = 0;
613 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
616 self.cnt = WEP_CRYLINK;
617 self.switchweapon = w_getbestweapon(self);
622 else if (req == WR_PRECACHE)
624 precache_model ("models/weapons/g_crylink.md3");
625 precache_model ("models/weapons/v_crylink.md3");
626 precache_model ("models/weapons/h_crylink.iqm");
627 precache_sound ("weapons/crylink_fire.wav");
628 precache_sound ("weapons/crylink_fire2.wav");
629 precache_sound ("weapons/crylink_linkjoin.wav");
630 precache_sound ("weapons/reload.wav");
632 else if (req == WR_SETUP)
634 weapon_setup(WEP_CRYLINK);
636 else if (req == WR_CHECKAMMO1)
638 // don't "run out of ammo" and switch weapons while waiting for release
639 if(self.crylink_lastgroup && self.crylink_waitrelease)
642 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
643 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_primary_ammo;
646 else if (req == WR_CHECKAMMO2)
648 // don't "run out of ammo" and switch weapons while waiting for release
649 if(self.crylink_lastgroup && self.crylink_waitrelease)
652 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
653 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_secondary_ammo;
656 else if (req == WR_RELOAD)
664 float w_crylink(float req)
666 if(req == WR_IMPACTEFFECT)
669 org2 = w_org + w_backoff * 2;
670 if(w_deathtype & HITTYPE_SECONDARY)
672 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
674 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
678 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
680 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
683 else if(req == WR_PRECACHE)
685 precache_sound("weapons/crylink_impact2.wav");
686 precache_sound("weapons/crylink_impact.wav");
688 else if (req == WR_SUICIDEMESSAGE)
690 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
692 else if (req == WR_KILLMESSAGE)
694 if(w_deathtype & HITTYPE_BOUNCE)
695 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
696 else if(w_deathtype & HITTYPE_SPLASH)
697 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
699 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY