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 if(e.projectiledeathtype & HITTYPE_SECONDARY)
61 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_damage * a, autocvar_g_balance_crylink_secondary_edgedamage * a, autocvar_g_balance_crylink_secondary_radius, world, autocvar_g_balance_crylink_secondary_force * a, e.projectiledeathtype, other);
63 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);
66 W_Crylink_LinkExplode(e.queuenext, e2);
71 // adjust towards center
72 // returns the origin where they will meet... and the time till the meeting is
73 // stored in w_crylink_linkjoin_time.
74 // could possibly network this origin and time, and display a special particle
75 // effect when projectiles meet there :P
76 // jspeed: MINIMUM jing speed
77 // jtime: MAXIMUM jing time (0: none)
78 float w_crylink_linkjoin_time;
79 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
81 vector avg_origin, avg_velocity;
86 // FIXME remove this debug code
87 W_Crylink_CheckLinks(e);
89 w_crylink_linkjoin_time = 0;
91 avg_origin = e.origin;
92 avg_velocity = e.velocity;
94 for(p = e; (p = p.queuenext) != e; )
96 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
97 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
100 avg_origin *= (1.0 / n);
101 avg_velocity *= (1.0 / n);
104 return avg_origin; // nothing to do
106 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
107 avg_dist = pow(vlen(e.origin - avg_origin), 2);
108 for(p = e; (p = p.queuenext) != e; )
109 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
110 avg_dist *= (1.0 / n);
111 avg_dist = sqrt(avg_dist);
114 return avg_origin; // no change needed
116 if(jspeed == 0 && jtime == 0)
118 e.velocity = avg_velocity;
119 UpdateCSQCProjectile(e);
120 for(p = e; (p = p.queuenext) != e; )
122 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
123 UpdateCSQCProjectile(p);
131 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
133 w_crylink_linkjoin_time = jtime;
136 w_crylink_linkjoin_time = avg_dist / jspeed;
137 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
139 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
140 UpdateCSQCProjectile(e);
141 for(p = e; (p = p.queuenext) != e; )
143 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
144 UpdateCSQCProjectile(p);
148 // jspeed -> +infinity:
149 // w_crylink_linkjoin_time -> +0
150 // targ_origin -> avg_origin
151 // p->velocity -> HUEG towards center
153 // w_crylink_linkjoin_time -> +/- infinity
154 // targ_origin -> avg_velocity * +/- infinity
155 // p->velocity -> avg_velocity
156 // jspeed -> -infinity:
157 // w_crylink_linkjoin_time -> -0
158 // targ_origin -> avg_origin
159 // p->velocity -> HUEG away from center
162 W_Crylink_CheckLinks(e);
167 void W_Crylink_LinkJoinEffect_Think()
169 // is there at least 2 projectiles very close?
172 e = self.owner.crylink_lastgroup;
176 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
178 for(p = e; (p = p.queuenext) != e; )
180 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
185 if(e.projectiledeathtype & HITTYPE_SECONDARY)
187 if(autocvar_g_balance_crylink_secondary_joinexplode)
189 n = n / autocvar_g_balance_crylink_secondary_shots;
190 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
191 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
192 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
193 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
195 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
200 if(autocvar_g_balance_crylink_primary_joinexplode)
202 n = n / autocvar_g_balance_crylink_primary_shots;
203 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
204 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
205 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
206 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
208 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
217 // NO bounce protection, as bounces are limited!
218 void W_Crylink_Touch (void)
223 local entity savenext, saveprev, saveown;
224 saveown = self.realowner;
225 savenext = self.queuenext;
226 saveprev = self.queueprev;
227 if(WarpZone_Projectile_Touch())
230 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
235 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
237 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
241 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
244 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)
246 if(self == self.realowner.crylink_lastgroup)
247 self.realowner.crylink_lastgroup = world;
248 W_Crylink_LinkExplode(self.queuenext, self);
255 W_Crylink_Dequeue(self);
259 self.cnt = self.cnt - 1;
260 self.angles = vectoangles(self.velocity);
262 self.projectiledeathtype |= HITTYPE_BOUNCE;
263 // commented out as it causes a little hitch...
265 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
268 void W_Crylink_Touch2 (void)
273 local entity savenext, saveprev, saveown;
274 savenext = self.queuenext;
275 saveprev = self.queueprev;
276 saveown = self.realowner;
277 if(WarpZone_Projectile_Touch())
280 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
285 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
287 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
291 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
294 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)
296 if(self == self.realowner.crylink_lastgroup)
297 self.realowner.crylink_lastgroup = world;
298 W_Crylink_LinkExplode(self.queuenext, self);
305 W_Crylink_Dequeue(self);
309 self.cnt = self.cnt - 1;
310 self.angles = vectoangles(self.velocity);
312 self.projectiledeathtype |= HITTYPE_BOUNCE;
313 // commented out as it causes a little hitch...
315 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
318 void W_Crylink_Fadethink (void)
320 W_Crylink_Dequeue(self);
324 void W_Crylink_Attack (void)
326 local float counter, shots;
327 local entity proj, prevproj, firstproj;
329 vector forward, right, up;
332 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
333 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_primary_ammo;
335 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
336 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
337 if(autocvar_g_balance_crylink_primary_joinexplode)
338 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
340 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
345 shots = autocvar_g_balance_crylink_primary_shots;
346 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
348 while (counter < shots)
351 proj.realowner = proj.owner = self;
352 proj.classname = "spike";
353 proj.bot_dodge = TRUE;
354 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
356 proj.queuenext = proj;
357 proj.queueprev = proj;
359 else if(counter == 0) { // first projectile, store in firstproj for now
362 else if(counter == shots - 1) { // last projectile, link up with first projectile
363 prevproj.queuenext = proj;
364 firstproj.queueprev = proj;
365 proj.queuenext = firstproj;
366 proj.queueprev = prevproj;
368 else { // else link up with previous projectile
369 prevproj.queuenext = proj;
370 proj.queueprev = prevproj;
375 proj.movetype = MOVETYPE_BOUNCEMISSILE;
376 PROJECTILE_MAKETRIGGER(proj);
377 proj.projectiledeathtype = WEP_CRYLINK;
378 //proj.gravity = 0.001;
380 setorigin (proj, w_shotorg);
381 setsize(proj, '0 0 0', '0 0 0');
389 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
393 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
394 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
395 proj.touch = W_Crylink_Touch;
397 proj.think = W_Crylink_Fadethink;
400 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
401 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
402 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
406 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
407 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
408 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
410 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
411 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
412 //proj.scale = 1 + 1 * proj.cnt;
414 proj.angles = vectoangles (proj.velocity);
416 //proj.glow_size = 20;
418 proj.flags = FL_PROJECTILE;
420 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
422 other = proj; MUTATOR_CALLHOOK(EditProjectile);
424 counter = counter + 1;
426 self.crylink_lastgroup = proj;
427 W_Crylink_CheckLinks(proj);
430 void W_Crylink_Attack2 (void)
432 local float counter, shots;
433 local entity proj, prevproj, firstproj;
436 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
437 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_secondary_ammo;
439 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
440 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
441 if(autocvar_g_balance_crylink_secondary_joinexplode)
442 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
444 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
446 shots = autocvar_g_balance_crylink_secondary_shots;
447 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
449 while (counter < shots)
452 proj.realowner = proj.owner = self;
453 proj.classname = "spike";
454 proj.bot_dodge = TRUE;
455 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
457 proj.queuenext = proj;
458 proj.queueprev = proj;
460 else if(counter == 0) { // first projectile, store in firstproj for now
463 else if(counter == shots - 1) { // last projectile, link up with first projectile
464 prevproj.queuenext = proj;
465 firstproj.queueprev = proj;
466 proj.queuenext = firstproj;
467 proj.queueprev = prevproj;
469 else { // else link up with previous projectile
470 prevproj.queuenext = proj;
471 proj.queueprev = prevproj;
476 proj.movetype = MOVETYPE_BOUNCEMISSILE;
477 PROJECTILE_MAKETRIGGER(proj);
478 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
479 //proj.gravity = 0.001;
481 setorigin (proj, w_shotorg);
482 setsize(proj, '0 0 0', '0 0 0');
484 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);
485 proj.touch = W_Crylink_Touch2;
486 proj.think = W_Crylink_Fadethink;
487 if(counter == (shots - 1) / 2)
489 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
490 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
491 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
495 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
496 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
497 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
499 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
500 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
501 //proj.scale = 1 + 1 * proj.cnt;
503 proj.angles = vectoangles (proj.velocity);
505 //proj.glow_size = 20;
507 proj.flags = FL_PROJECTILE;
509 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
511 other = proj; MUTATOR_CALLHOOK(EditProjectile);
513 counter = counter + 1;
515 self.crylink_lastgroup = proj;
518 void spawnfunc_weapon_crylink (void)
520 weapon_defaultspawnfunc(WEP_CRYLINK);
523 float w_crylink(float req)
528 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
530 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
532 else if (req == WR_THINK)
534 if (self.BUTTON_ATCK)
536 if (!self.crylink_waitrelease)
537 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
540 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
541 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
542 self.crylink_waitrelease = 1;
545 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
547 if (!self.crylink_waitrelease)
548 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
551 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
552 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
553 self.crylink_waitrelease = 2;
558 if (self.crylink_waitrelease && (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time))
560 // fired and released now!
561 if(self.crylink_lastgroup)
564 entity linkjoineffect;
566 if(self.crylink_waitrelease == 1)
568 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);
573 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);
576 linkjoineffect = spawn();
577 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
578 linkjoineffect.classname = "linkjoineffect";
579 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
580 linkjoineffect.owner = self;
581 setorigin(linkjoineffect, pos);
583 self.crylink_waitrelease = 0;
584 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
587 self.cnt = WEP_CRYLINK;
588 self.switchweapon = w_getbestweapon(self);
593 else if (req == WR_PRECACHE)
595 precache_model ("models/weapons/g_crylink.md3");
596 precache_model ("models/weapons/v_crylink.md3");
597 precache_model ("models/weapons/h_crylink.iqm");
598 precache_sound ("weapons/crylink_fire.wav");
599 precache_sound ("weapons/crylink_fire2.wav");
600 precache_sound ("weapons/crylink_linkjoin.wav");
602 else if (req == WR_SETUP)
603 weapon_setup(WEP_CRYLINK);
604 else if (req == WR_CHECKAMMO1)
606 // don't "run out of ammo" and switch weapons while waiting for release
607 if(self.crylink_lastgroup && self.crylink_waitrelease)
609 return self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
611 else if (req == WR_CHECKAMMO2)
613 // don't "run out of ammo" and switch weapons while waiting for release
614 if(self.crylink_lastgroup && self.crylink_waitrelease)
616 return self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
622 float w_crylink(float req)
624 if(req == WR_IMPACTEFFECT)
627 org2 = w_org + w_backoff * 2;
628 if(w_deathtype & HITTYPE_SECONDARY)
630 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
632 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
636 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
638 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
641 else if(req == WR_PRECACHE)
643 precache_sound("weapons/crylink_impact2.wav");
644 precache_sound("weapons/crylink_impact.wav");
646 else if (req == WR_SUICIDEMESSAGE)
648 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
650 else if (req == WR_KILLMESSAGE)
652 if(w_deathtype & HITTYPE_BOUNCE)
653 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
654 else if(w_deathtype & HITTYPE_SPLASH)
655 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
657 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY