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_Dequeue_Raw(entity own, entity prev, entity me, entity next)
14 if(me == own.crylink_lastgroup)
15 own.crylink_lastgroup = ((me == next) ? world : next);
16 prev.queuenext = next;
17 next.queueprev = prev;
20 void W_Crylink_Dequeue(entity e)
22 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
25 // force projectile to explode
26 void W_Crylink_LinkExplode (entity e, entity e2)
29 a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
31 if(e == e.realowner.crylink_lastgroup)
32 e.realowner.crylink_lastgroup = world;
34 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_damage") * a, cvar("g_balance_crylink_primary_edgedamage") * a, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * a, e.projectiledeathtype, other);
37 W_Crylink_LinkExplode(e.queuenext, e2);
42 void W_Crylink_CheckLinks(entity e)
48 error("W_Crylink_CheckLinks: entity is world");
51 for(i = 0; i < 1000; ++i)
53 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
54 error("W_Crylink_CheckLinks: queue is inconsistent");
60 error("W_Crylink_CheckLinks: infinite chain");
63 // adjust towards center
64 // returns the origin where they will meet... and the time till the meeting is
65 // stored in w_crylink_linkjoin_time.
66 // could possibly network this origin and time, and display a special particle
67 // effect when projectiles meet there :P
68 // jspeed: MINIMUM jing speed
69 // jtime: MAXIMUM jing time (0: none)
70 float w_crylink_linkjoin_time;
71 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
73 vector avg_origin, avg_velocity;
78 // FIXME remove this debug code
79 W_Crylink_CheckLinks(e);
81 w_crylink_linkjoin_time = 0;
83 avg_origin = e.origin;
84 avg_velocity = e.velocity;
86 for(p = e; (p = p.queuenext) != e; )
88 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
89 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
92 avg_origin *= (1.0 / n);
93 avg_velocity *= (1.0 / n);
96 return avg_origin; // nothing to do
98 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
99 avg_dist = pow(vlen(e.origin - avg_origin), 2);
100 for(p = e; (p = p.queuenext) != e; )
101 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
102 avg_dist *= (1.0 / n);
103 avg_dist = sqrt(avg_dist);
106 return avg_origin; // no change needed
108 if(jspeed == 0 && jtime == 0)
110 e.velocity = avg_velocity;
111 UpdateCSQCProjectile(e);
112 for(p = e; (p = p.queuenext) != e; )
114 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
115 UpdateCSQCProjectile(p);
123 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
125 w_crylink_linkjoin_time = jtime;
128 w_crylink_linkjoin_time = avg_dist / jspeed;
129 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
131 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
132 UpdateCSQCProjectile(e);
133 for(p = e; (p = p.queuenext) != e; )
135 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
136 UpdateCSQCProjectile(p);
140 // jspeed -> +infinity:
141 // w_crylink_linkjoin_time -> +0
142 // targ_origin -> avg_origin
143 // p->velocity -> HUEG towards center
145 // w_crylink_linkjoin_time -> +/- infinity
146 // targ_origin -> avg_velocity * +/- infinity
147 // p->velocity -> avg_velocity
148 // jspeed -> -infinity:
149 // w_crylink_linkjoin_time -> -0
150 // targ_origin -> avg_origin
151 // p->velocity -> HUEG away from center
157 void W_Crylink_LinkJoinEffect_Think()
159 // is there at least 2 projectiles very close?
162 e = self.owner.crylink_lastgroup;
166 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
168 for(p = e; (p = p.queuenext) != e; )
170 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
175 if(e.projectiledeathtype & HITTYPE_SECONDARY)
177 if(cvar("g_balance_crylink_secondary_joinexplode"))
179 n = n / cvar("g_balance_crylink_secondary_shots");
180 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_secondary_joinexplode_damage") * n,
181 cvar("g_balance_crylink_secondary_joinexplode_edgedamage") * n,
182 cvar("g_balance_crylink_secondary_joinexplode_radius") * n, e.realowner,
183 cvar("g_balance_crylink_secondary_joinexplode_force") * n, e.projectiledeathtype, other);
185 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
190 if(cvar("g_balance_crylink_primary_joinexplode"))
192 n = n / cvar("g_balance_crylink_primary_shots");
193 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_joinexplode_damage") * n,
194 cvar("g_balance_crylink_primary_joinexplode_edgedamage") * n,
195 cvar("g_balance_crylink_primary_joinexplode_radius") * n, e.realowner,
196 cvar("g_balance_crylink_primary_joinexplode_force") * n, e.projectiledeathtype, other);
198 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
207 // NO bounce protection, as bounces are limited!
208 void W_Crylink_Touch (void)
213 local entity savenext, saveprev, saveown;
214 saveown = self.realowner;
215 savenext = self.queuenext;
216 saveprev = self.queueprev;
217 if(WarpZone_Projectile_Touch())
220 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
225 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
227 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
231 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
234 if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, self.projectiledeathtype, other) && cvar("g_balance_crylink_primary_linkexplode"))
236 W_Crylink_LinkExplode(self.queuenext, self);
243 W_Crylink_Dequeue(self);
247 self.cnt = self.cnt - 1;
248 self.angles = vectoangles(self.velocity);
250 self.projectiledeathtype |= HITTYPE_BOUNCE;
251 // commented out as it causes a little hitch...
253 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
256 void W_Crylink_Touch2 (void)
261 local entity savenext, saveprev, saveown;
262 savenext = self.queuenext;
263 saveprev = self.queueprev;
264 saveown = self.realowner;
265 if(WarpZone_Projectile_Touch())
268 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
273 a = 1 - (time - self.fade_time) * self.fade_rate;
275 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
279 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
282 if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, self.projectiledeathtype, other) && cvar("g_balance_crylink_secondary_linkexplode"))
284 W_Crylink_LinkExplode(self.queuenext, self);
291 W_Crylink_Dequeue(self);
295 self.cnt = self.cnt - 1;
296 self.angles = vectoangles(self.velocity);
298 self.projectiledeathtype |= HITTYPE_BOUNCE;
299 // commented out as it causes a little hitch...
301 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
304 void W_Crylink_Fadethink (void)
306 W_Crylink_Dequeue(self);
310 void W_Crylink_Attack (void)
312 local float counter, shots;
313 local entity proj, prevproj, firstproj;
315 vector forward, right, up;
317 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
318 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
320 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
325 shots = cvar("g_balance_crylink_primary_shots");
326 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
328 while (counter < shots)
331 proj.realowner = proj.owner = self;
332 proj.classname = "spike";
333 proj.bot_dodge = TRUE;
334 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
336 proj.queuenext = proj;
337 proj.queueprev = proj;
339 else if(counter == 0) { // first projectile, store in firstproj for now
342 else if(counter == shots - 1) { // last projectile, link up with first projectile
343 prevproj.queuenext = proj;
344 firstproj.queueprev = proj;
345 proj.queuenext = firstproj;
346 proj.queueprev = prevproj;
348 else { // else link up with previous projectile
349 prevproj.queuenext = proj;
350 proj.queueprev = prevproj;
355 proj.movetype = MOVETYPE_BOUNCEMISSILE;
356 PROJECTILE_MAKETRIGGER(proj);
357 proj.projectiledeathtype = WEP_CRYLINK;
358 //proj.gravity = 0.001;
360 setorigin (proj, w_shotorg);
361 setsize(proj, '0 0 0', '0 0 0');
369 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
373 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
374 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0, FALSE);
375 proj.touch = W_Crylink_Touch;
377 proj.think = W_Crylink_Fadethink;
380 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
381 proj.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
382 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
386 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
387 proj.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
388 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
390 proj.cnt = cvar("g_balance_crylink_primary_bounces");
391 //proj.scale = 1 + 1 * proj.cnt;
393 proj.angles = vectoangles (proj.velocity);
395 //proj.glow_size = 20;
397 proj.flags = FL_PROJECTILE;
399 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
401 other = proj; MUTATOR_CALLHOOK(EditProjectile);
403 counter = counter + 1;
405 self.crylink_lastgroup = proj;
408 void W_Crylink_Attack2 (void)
410 local float counter, shots;
411 local entity proj, prevproj, firstproj;
413 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
414 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
416 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
418 shots = cvar("g_balance_crylink_secondary_shots");
419 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
421 while (counter < shots)
424 proj.realowner = proj.owner = self;
425 proj.classname = "spike";
426 proj.bot_dodge = TRUE;
427 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
429 proj.queuenext = proj;
430 proj.queueprev = proj;
432 else if(counter == 0) { // first projectile, store in firstproj for now
435 else if(counter == shots - 1) { // last projectile, link up with first projectile
436 prevproj.queuenext = proj;
437 firstproj.queueprev = proj;
438 proj.queuenext = firstproj;
439 proj.queueprev = prevproj;
441 else { // else link up with previous projectile
442 prevproj.queuenext = proj;
443 proj.queueprev = prevproj;
448 proj.movetype = MOVETYPE_BOUNCEMISSILE;
449 PROJECTILE_MAKETRIGGER(proj);
450 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
451 //proj.gravity = 0.001;
453 setorigin (proj, w_shotorg);
454 setsize(proj, '0 0 0', '0 0 0');
456 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread") * g_weaponspreadfactor), v_up, cvar("g_balance_crylink_secondary_speed"), 0, 0, 0, FALSE);
457 proj.touch = W_Crylink_Touch2;
458 proj.think = W_Crylink_Fadethink;
459 if(counter == (shots - 1) / 2)
461 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
462 proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
463 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
467 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
468 proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
469 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
471 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
472 //proj.scale = 1 + 1 * proj.cnt;
474 proj.angles = vectoangles (proj.velocity);
476 //proj.glow_size = 20;
478 proj.flags = FL_PROJECTILE;
480 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
482 other = proj; MUTATOR_CALLHOOK(EditProjectile);
484 counter = counter + 1;
486 self.crylink_lastgroup = proj;
489 void spawnfunc_weapon_crylink (void)
491 weapon_defaultspawnfunc(WEP_CRYLINK);
494 float w_crylink(float req)
499 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
501 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
503 else if (req == WR_THINK)
505 if (self.BUTTON_ATCK)
507 if (!self.crylink_waitrelease)
508 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
511 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
512 if(cvar("g_balance_crylink_primary_joinspread") != 0 || cvar("g_balance_crylink_primary_jointime") != 0)
513 self.crylink_waitrelease = 1;
516 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
518 if (!self.crylink_waitrelease)
519 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
522 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
523 if(cvar("g_balance_crylink_secondary_joinspread") != 0 || cvar("g_balance_crylink_secondary_jointime") != 0)
524 self.crylink_waitrelease = 2;
529 if (self.crylink_waitrelease)
531 // fired and released now!
532 if(self.crylink_lastgroup)
535 entity linkjoineffect;
538 if(self.crylink_waitrelease == 1)
540 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspread") * cvar("g_balance_crylink_primary_speed"), cvar("g_balance_crylink_primary_jointime"));
545 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspread") * cvar("g_balance_crylink_secondary_speed"), cvar("g_balance_crylink_secondary_jointime"));
548 linkjoineffect = spawn();
549 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
550 linkjoineffect.classname = "linkjoineffect";
551 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
552 linkjoineffect.owner = self;
553 setorigin(linkjoineffect, pos);
557 self.crylink_waitrelease = 0;
558 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
561 self.cnt = WEP_CRYLINK;
562 self.switchweapon = w_getbestweapon(self);
567 else if (req == WR_PRECACHE)
569 precache_model ("models/weapons/g_crylink.md3");
570 precache_model ("models/weapons/v_crylink.md3");
571 precache_model ("models/weapons/h_crylink.iqm");
572 precache_sound ("weapons/crylink_fire.wav");
573 precache_sound ("weapons/crylink_fire2.wav");
574 precache_sound ("weapons/crylink_linkjoin.wav");
576 else if (req == WR_SETUP)
577 weapon_setup(WEP_CRYLINK);
578 else if (req == WR_CHECKAMMO1)
580 // don't "run out of ammo" and switch weapons while waiting for release
581 if(self.crylink_lastgroup && self.crylink_waitrelease)
583 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
585 else if (req == WR_CHECKAMMO2)
587 // don't "run out of ammo" and switch weapons while waiting for release
588 if(self.crylink_lastgroup && self.crylink_waitrelease)
590 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
596 float w_crylink(float req)
598 if(req == WR_IMPACTEFFECT)
601 org2 = w_org + w_backoff * 2;
602 if(w_deathtype & HITTYPE_SECONDARY)
604 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
606 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
610 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
612 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
615 else if(req == WR_PRECACHE)
617 precache_sound("weapons/crylink_impact2.wav");
618 precache_sound("weapons/crylink_impact.wav");
620 else if (req == WR_SUICIDEMESSAGE)
622 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
624 else if (req == WR_KILLMESSAGE)
626 if(w_deathtype & HITTYPE_BOUNCE)
627 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
628 else if(w_deathtype & HITTYPE_SPLASH)
629 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
631 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY