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 W_Reload(ammo_cells, min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo), autocvar_g_balance_crylink_reload_ammo, autocvar_g_balance_crylink_reload_time, "weapons/reload.wav");
17 void W_Crylink_CheckLinks(entity e)
23 error("W_Crylink_CheckLinks: entity is world");
24 if(e.classname != "spike")
25 error("W_Crylink_CheckLinks: entity is not a spike");
28 for(i = 0; i < 1000; ++i)
30 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
31 error("W_Crylink_CheckLinks: queue is inconsistent");
37 error("W_Crylink_CheckLinks: infinite chain");
40 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
42 W_Crylink_CheckLinks(next);
43 if(me == own.crylink_lastgroup)
44 own.crylink_lastgroup = ((me == next) ? world : next);
45 prev.queuenext = next;
46 next.queueprev = prev;
48 W_Crylink_CheckLinks(next);
51 void W_Crylink_Dequeue(entity e)
53 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
56 // force projectile to explode
57 void W_Crylink_LinkExplode (entity e, entity e2)
60 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
62 if(e == e.realowner.crylink_lastgroup)
63 e.realowner.crylink_lastgroup = world;
65 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);
68 W_Crylink_LinkExplode(e.queuenext, e2);
73 // adjust towards center
74 // returns the origin where they will meet... and the time till the meeting is
75 // stored in w_crylink_linkjoin_time.
76 // could possibly network this origin and time, and display a special particle
77 // effect when projectiles meet there :P
78 // jspeed: MINIMUM jing speed
79 // jtime: MAXIMUM jing time (0: none)
80 float w_crylink_linkjoin_time;
81 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
83 vector avg_origin, avg_velocity;
88 // FIXME remove this debug code
89 W_Crylink_CheckLinks(e);
91 w_crylink_linkjoin_time = 0;
93 avg_origin = e.origin;
94 avg_velocity = e.velocity;
96 for(p = e; (p = p.queuenext) != e; )
98 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
99 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
102 avg_origin *= (1.0 / n);
103 avg_velocity *= (1.0 / n);
106 return avg_origin; // nothing to do
108 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
109 avg_dist = pow(vlen(e.origin - avg_origin), 2);
110 for(p = e; (p = p.queuenext) != e; )
111 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
112 avg_dist *= (1.0 / n);
113 avg_dist = sqrt(avg_dist);
116 return avg_origin; // no change needed
118 if(jspeed == 0 && jtime == 0)
120 e.velocity = avg_velocity;
121 UpdateCSQCProjectile(e);
122 for(p = e; (p = p.queuenext) != e; )
124 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
125 UpdateCSQCProjectile(p);
133 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
135 w_crylink_linkjoin_time = jtime;
138 w_crylink_linkjoin_time = avg_dist / jspeed;
139 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
141 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
142 UpdateCSQCProjectile(e);
143 for(p = e; (p = p.queuenext) != e; )
145 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
146 UpdateCSQCProjectile(p);
150 // jspeed -> +infinity:
151 // w_crylink_linkjoin_time -> +0
152 // targ_origin -> avg_origin
153 // p->velocity -> HUEG towards center
155 // w_crylink_linkjoin_time -> +/- infinity
156 // targ_origin -> avg_velocity * +/- infinity
157 // p->velocity -> avg_velocity
158 // jspeed -> -infinity:
159 // w_crylink_linkjoin_time -> -0
160 // targ_origin -> avg_origin
161 // p->velocity -> HUEG away from center
164 W_Crylink_CheckLinks(e);
169 void W_Crylink_LinkJoinEffect_Think()
171 // is there at least 2 projectiles very close?
174 e = self.owner.crylink_lastgroup;
178 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
180 for(p = e; (p = p.queuenext) != e; )
182 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
187 if(e.projectiledeathtype & HITTYPE_SECONDARY)
189 if(autocvar_g_balance_crylink_secondary_joinexplode)
191 n = n / autocvar_g_balance_crylink_secondary_shots;
192 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
193 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
194 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
195 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
197 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
202 if(autocvar_g_balance_crylink_primary_joinexplode)
204 n = n / autocvar_g_balance_crylink_primary_shots;
205 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
206 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
207 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
208 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
210 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
219 // NO bounce protection, as bounces are limited!
220 void W_Crylink_Touch (void)
225 local entity savenext, saveprev, saveown;
226 saveown = self.realowner;
227 savenext = self.queuenext;
228 saveprev = self.queueprev;
229 if(WarpZone_Projectile_Touch())
232 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
237 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
239 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
243 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
246 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)
248 if(self == self.realowner.crylink_lastgroup)
249 self.realowner.crylink_lastgroup = world;
250 W_Crylink_LinkExplode(self.queuenext, self);
257 W_Crylink_Dequeue(self);
261 self.cnt = self.cnt - 1;
262 self.angles = vectoangles(self.velocity);
264 self.projectiledeathtype |= HITTYPE_BOUNCE;
265 // commented out as it causes a little hitch...
267 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
270 void W_Crylink_Touch2 (void)
275 local entity savenext, saveprev, saveown;
276 savenext = self.queuenext;
277 saveprev = self.queueprev;
278 saveown = self.realowner;
279 if(WarpZone_Projectile_Touch())
282 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
287 a = 1 - (time - self.fade_time) * self.fade_rate;
289 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
293 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
296 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)
298 if(self == self.realowner.crylink_lastgroup)
299 self.realowner.crylink_lastgroup = world;
300 W_Crylink_LinkExplode(self.queuenext, self);
307 W_Crylink_Dequeue(self);
311 self.cnt = self.cnt - 1;
312 self.angles = vectoangles(self.velocity);
314 self.projectiledeathtype |= HITTYPE_BOUNCE;
315 // commented out as it causes a little hitch...
317 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
320 void W_Crylink_Fadethink (void)
322 W_Crylink_Dequeue(self);
326 void W_Crylink_Attack (void)
328 local float counter, shots;
329 local entity proj, prevproj, firstproj;
331 vector forward, right, up;
334 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
335 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
337 if(autocvar_g_balance_crylink_reload_ammo)
339 self.clip_load -= autocvar_g_balance_crylink_primary_ammo;
340 self.weapon_load[WEP_CRYLINK] = self.clip_load;
343 self.ammo_cells -= autocvar_g_balance_crylink_primary_ammo;
346 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
347 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
348 if(autocvar_g_balance_crylink_primary_joinexplode)
349 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
351 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
356 shots = autocvar_g_balance_crylink_primary_shots;
357 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
359 while (counter < shots)
362 proj.realowner = proj.owner = self;
363 proj.classname = "spike";
364 proj.bot_dodge = TRUE;
365 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
367 proj.queuenext = proj;
368 proj.queueprev = proj;
370 else if(counter == 0) { // first projectile, store in firstproj for now
373 else if(counter == shots - 1) { // last projectile, link up with first projectile
374 prevproj.queuenext = proj;
375 firstproj.queueprev = proj;
376 proj.queuenext = firstproj;
377 proj.queueprev = prevproj;
379 else { // else link up with previous projectile
380 prevproj.queuenext = proj;
381 proj.queueprev = prevproj;
386 proj.movetype = MOVETYPE_BOUNCEMISSILE;
387 PROJECTILE_MAKETRIGGER(proj);
388 proj.projectiledeathtype = WEP_CRYLINK;
389 //proj.gravity = 0.001;
391 setorigin (proj, w_shotorg);
392 setsize(proj, '0 0 0', '0 0 0');
400 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
404 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
405 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
406 proj.touch = W_Crylink_Touch;
408 proj.think = W_Crylink_Fadethink;
411 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
412 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
413 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
417 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
418 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
419 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
421 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
422 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
423 //proj.scale = 1 + 1 * proj.cnt;
425 proj.angles = vectoangles (proj.velocity);
427 //proj.glow_size = 20;
429 proj.flags = FL_PROJECTILE;
431 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
433 other = proj; MUTATOR_CALLHOOK(EditProjectile);
435 counter = counter + 1;
437 self.crylink_lastgroup = proj;
438 W_Crylink_CheckLinks(proj);
441 void W_Crylink_Attack2 (void)
443 local float counter, shots;
444 local entity proj, prevproj, firstproj;
447 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
448 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
450 if(autocvar_g_balance_crylink_reload_ammo)
452 self.clip_load -= autocvar_g_balance_crylink_secondary_ammo;
453 self.weapon_load[WEP_CRYLINK] = self.clip_load;
456 self.ammo_cells -= autocvar_g_balance_crylink_secondary_ammo;
459 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
460 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
461 if(autocvar_g_balance_crylink_secondary_joinexplode)
462 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
464 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
466 shots = autocvar_g_balance_crylink_secondary_shots;
467 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
469 while (counter < shots)
472 proj.realowner = proj.owner = self;
473 proj.classname = "spike";
474 proj.bot_dodge = TRUE;
475 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
477 proj.queuenext = proj;
478 proj.queueprev = proj;
480 else if(counter == 0) { // first projectile, store in firstproj for now
483 else if(counter == shots - 1) { // last projectile, link up with first projectile
484 prevproj.queuenext = proj;
485 firstproj.queueprev = proj;
486 proj.queuenext = firstproj;
487 proj.queueprev = prevproj;
489 else { // else link up with previous projectile
490 prevproj.queuenext = proj;
491 proj.queueprev = prevproj;
496 proj.movetype = MOVETYPE_BOUNCEMISSILE;
497 PROJECTILE_MAKETRIGGER(proj);
498 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
499 //proj.gravity = 0.001;
501 setorigin (proj, w_shotorg);
502 setsize(proj, '0 0 0', '0 0 0');
504 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);
505 proj.touch = W_Crylink_Touch2;
506 proj.think = W_Crylink_Fadethink;
507 if(counter == (shots - 1) / 2)
509 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
510 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
511 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
515 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
516 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
517 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
519 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
520 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
521 //proj.scale = 1 + 1 * proj.cnt;
523 proj.angles = vectoangles (proj.velocity);
525 //proj.glow_size = 20;
527 proj.flags = FL_PROJECTILE;
529 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
531 other = proj; MUTATOR_CALLHOOK(EditProjectile);
533 counter = counter + 1;
535 self.crylink_lastgroup = proj;
538 void spawnfunc_weapon_crylink (void)
540 weapon_defaultspawnfunc(WEP_CRYLINK);
543 float w_crylink(float req)
549 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
551 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
553 else if (req == WR_THINK)
555 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
557 else if (self.BUTTON_ATCK)
559 if (!self.crylink_waitrelease)
560 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
563 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
564 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
565 self.crylink_waitrelease = 1;
568 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
570 if (!self.crylink_waitrelease)
571 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
574 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
575 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
576 self.crylink_waitrelease = 2;
581 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
583 // fired and released now!
584 if(self.crylink_lastgroup)
587 entity linkjoineffect;
589 if(self.crylink_waitrelease == 1)
591 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);
596 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);
599 linkjoineffect = spawn();
600 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
601 linkjoineffect.classname = "linkjoineffect";
602 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
603 linkjoineffect.owner = self;
604 setorigin(linkjoineffect, pos);
606 self.crylink_waitrelease = 0;
607 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
610 self.cnt = WEP_CRYLINK;
611 self.switchweapon = w_getbestweapon(self);
616 else if (req == WR_PRECACHE)
618 precache_model ("models/weapons/g_crylink.md3");
619 precache_model ("models/weapons/v_crylink.md3");
620 precache_model ("models/weapons/h_crylink.iqm");
621 precache_sound ("weapons/crylink_fire.wav");
622 precache_sound ("weapons/crylink_fire2.wav");
623 precache_sound ("weapons/crylink_linkjoin.wav");
624 precache_sound ("weapons/reload.wav");
626 else if (req == WR_SETUP)
628 weapon_setup(WEP_CRYLINK);
630 else if (req == WR_CHECKAMMO1)
632 // don't "run out of ammo" and switch weapons while waiting for release
633 if(self.crylink_lastgroup && self.crylink_waitrelease)
636 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
637 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_primary_ammo;
640 else if (req == WR_CHECKAMMO2)
642 // don't "run out of ammo" and switch weapons while waiting for release
643 if(self.crylink_lastgroup && self.crylink_waitrelease)
646 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
647 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_secondary_ammo;
650 else if (req == WR_RELOAD)
658 float w_crylink(float req)
660 if(req == WR_IMPACTEFFECT)
663 org2 = w_org + w_backoff * 2;
664 if(w_deathtype & HITTYPE_SECONDARY)
666 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
668 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
672 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
674 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
677 else if(req == WR_PRECACHE)
679 precache_sound("weapons/crylink_impact2.wav");
680 precache_sound("weapons/crylink_impact.wav");
682 else if (req == WR_SUICIDEMESSAGE)
684 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
686 else if (req == WR_KILLMESSAGE)
688 if(w_deathtype & HITTYPE_BOUNCE)
689 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
690 else if(w_deathtype & HITTYPE_SPLASH)
691 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
693 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY