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_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 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_reload_ammo);
331 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
332 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
333 if(autocvar_g_balance_crylink_primary_joinexplode)
334 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
336 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
341 shots = autocvar_g_balance_crylink_primary_shots;
342 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
344 while (counter < shots)
347 proj.realowner = proj.owner = self;
348 proj.classname = "spike";
349 proj.bot_dodge = TRUE;
350 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
352 proj.queuenext = proj;
353 proj.queueprev = proj;
355 else if(counter == 0) { // first projectile, store in firstproj for now
358 else if(counter == shots - 1) { // last projectile, link up with first projectile
359 prevproj.queuenext = proj;
360 firstproj.queueprev = proj;
361 proj.queuenext = firstproj;
362 proj.queueprev = prevproj;
364 else { // else link up with previous projectile
365 prevproj.queuenext = proj;
366 proj.queueprev = prevproj;
371 proj.movetype = MOVETYPE_BOUNCEMISSILE;
372 PROJECTILE_MAKETRIGGER(proj);
373 proj.projectiledeathtype = WEP_CRYLINK;
374 //proj.gravity = 0.001;
376 setorigin (proj, w_shotorg);
377 setsize(proj, '0 0 0', '0 0 0');
385 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
389 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
390 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
391 proj.touch = W_Crylink_Touch;
393 proj.think = W_Crylink_Fadethink;
396 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
397 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
398 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
402 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
403 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
404 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
406 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
407 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
408 //proj.scale = 1 + 1 * proj.cnt;
410 proj.angles = vectoangles (proj.velocity);
412 //proj.glow_size = 20;
414 proj.flags = FL_PROJECTILE;
416 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
418 other = proj; MUTATOR_CALLHOOK(EditProjectile);
420 counter = counter + 1;
422 self.crylink_lastgroup = proj;
423 W_Crylink_CheckLinks(proj);
426 void W_Crylink_Attack2 (void)
428 local float counter, shots;
429 local entity proj, prevproj, firstproj;
432 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_secondary_ammo, autocvar_g_balance_crylink_reload_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)
524 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
526 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
528 else if (req == WR_THINK)
530 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
531 weapon_action(self.weapon, WR_RELOAD);
532 else if (self.BUTTON_ATCK)
534 if (!self.crylink_waitrelease)
535 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
538 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
539 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
540 self.crylink_waitrelease = 1;
543 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
545 if (!self.crylink_waitrelease)
546 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
549 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
550 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
551 self.crylink_waitrelease = 2;
556 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
558 // fired and released now!
559 if(self.crylink_lastgroup)
562 entity linkjoineffect;
564 if(self.crylink_waitrelease == 1)
566 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);
571 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);
574 linkjoineffect = spawn();
575 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
576 linkjoineffect.classname = "linkjoineffect";
577 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
578 linkjoineffect.owner = self;
579 setorigin(linkjoineffect, pos);
581 self.crylink_waitrelease = 0;
582 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
585 self.cnt = WEP_CRYLINK;
586 self.switchweapon = w_getbestweapon(self);
591 else if (req == WR_PRECACHE)
593 precache_model ("models/weapons/g_crylink.md3");
594 precache_model ("models/weapons/v_crylink.md3");
595 precache_model ("models/weapons/h_crylink.iqm");
596 precache_sound ("weapons/crylink_fire.wav");
597 precache_sound ("weapons/crylink_fire2.wav");
598 precache_sound ("weapons/crylink_linkjoin.wav");
599 precache_sound ("weapons/reload.wav");
601 else if (req == WR_SETUP)
603 weapon_setup(WEP_CRYLINK);
605 else if (req == WR_CHECKAMMO1)
607 // don't "run out of ammo" and switch weapons while waiting for release
608 if(self.crylink_lastgroup && self.crylink_waitrelease)
611 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
612 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_primary_ammo;
615 else if (req == WR_CHECKAMMO2)
617 // don't "run out of ammo" and switch weapons while waiting for release
618 if(self.crylink_lastgroup && self.crylink_waitrelease)
621 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
622 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_secondary_ammo;
625 else if (req == WR_RELOAD)
627 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");
633 float w_crylink(float req)
635 if(req == WR_IMPACTEFFECT)
638 org2 = w_org + w_backoff * 2;
639 if(w_deathtype & HITTYPE_SECONDARY)
641 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
643 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
647 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
649 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
652 else if(req == WR_PRECACHE)
654 precache_sound("weapons/crylink_impact2.wav");
655 precache_sound("weapons/crylink_impact.wav");
657 else if (req == WR_SUICIDEMESSAGE)
659 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
661 else if (req == WR_KILLMESSAGE)
663 if(w_deathtype & HITTYPE_BOUNCE)
664 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
665 else if(w_deathtype & HITTYPE_SPLASH)
666 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
668 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY