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" || wasfreed(e))
20 error(sprintf("W_Crylink_CheckLinks: entity is not a spike but a %s (freed: %d)", e.classname, wasfreed(e)));
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;
42 me.classname = "spike_oktoremove";
44 W_Crylink_CheckLinks(next);
47 void W_Crylink_Dequeue(entity e)
49 W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
52 // force projectile to explode
53 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 if(e.projectiledeathtype & HITTYPE_SECONDARY)
66 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);
68 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);
70 W_Crylink_LinkExplode(e.queuenext, e2);
72 e.classname = "spike_oktoremove";
76 // adjust towards center
77 // returns the origin where they will meet... and the time till the meeting is
78 // stored in w_crylink_linkjoin_time.
79 // could possibly network this origin and time, and display a special particle
80 // effect when projectiles meet there :P
81 // jspeed: MINIMUM jing speed
82 // jtime: MAXIMUM jing time (0: none)
83 float w_crylink_linkjoin_time;
84 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
86 vector avg_origin, avg_velocity;
91 // FIXME remove this debug code
92 W_Crylink_CheckLinks(e);
94 w_crylink_linkjoin_time = 0;
96 avg_origin = e.origin;
97 avg_velocity = e.velocity;
99 for(p = e; (p = p.queuenext) != e; )
101 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
102 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
105 avg_origin *= (1.0 / n);
106 avg_velocity *= (1.0 / n);
109 return avg_origin; // nothing to do
111 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
112 avg_dist = pow(vlen(e.origin - avg_origin), 2);
113 for(p = e; (p = p.queuenext) != e; )
114 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
115 avg_dist *= (1.0 / n);
116 avg_dist = sqrt(avg_dist);
119 return avg_origin; // no change needed
121 if(jspeed == 0 && jtime == 0)
123 e.velocity = avg_velocity;
124 UpdateCSQCProjectile(e);
125 for(p = e; (p = p.queuenext) != e; )
127 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
128 UpdateCSQCProjectile(p);
136 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
138 w_crylink_linkjoin_time = jtime;
141 w_crylink_linkjoin_time = avg_dist / jspeed;
142 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
144 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
145 UpdateCSQCProjectile(e);
146 for(p = e; (p = p.queuenext) != e; )
148 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
149 UpdateCSQCProjectile(p);
153 // jspeed -> +infinity:
154 // w_crylink_linkjoin_time -> +0
155 // targ_origin -> avg_origin
156 // p->velocity -> HUEG towards center
158 // w_crylink_linkjoin_time -> +/- infinity
159 // targ_origin -> avg_velocity * +/- infinity
160 // p->velocity -> avg_velocity
161 // jspeed -> -infinity:
162 // w_crylink_linkjoin_time -> -0
163 // targ_origin -> avg_origin
164 // p->velocity -> HUEG away from center
167 W_Crylink_CheckLinks(e);
172 void W_Crylink_LinkJoinEffect_Think()
174 // is there at least 2 projectiles very close?
177 e = self.owner.crylink_lastgroup;
181 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
183 for(p = e; (p = p.queuenext) != e; )
185 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
190 if(e.projectiledeathtype & HITTYPE_SECONDARY)
192 if(autocvar_g_balance_crylink_secondary_joinexplode)
194 n = n / autocvar_g_balance_crylink_secondary_shots;
195 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
196 autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
197 autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
198 autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
200 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
205 if(autocvar_g_balance_crylink_primary_joinexplode)
207 n = n / autocvar_g_balance_crylink_primary_shots;
208 RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
209 autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
210 autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
211 autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
213 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
221 // NO bounce protection, as bounces are limited!
222 void W_Crylink_Touch (void)
229 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
231 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
235 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
238 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)
240 if(self == self.realowner.crylink_lastgroup)
241 self.realowner.crylink_lastgroup = world;
242 W_Crylink_LinkExplode(self.queuenext, self);
243 self.classname = "spike_oktoremove";
250 W_Crylink_Dequeue(self);
254 self.cnt = self.cnt - 1;
255 self.angles = vectoangles(self.velocity);
257 self.projectiledeathtype |= HITTYPE_BOUNCE;
258 // commented out as it causes a little hitch...
260 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
263 void W_Crylink_Touch2 (void)
270 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
272 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
276 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
279 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)
281 if(self == self.realowner.crylink_lastgroup)
282 self.realowner.crylink_lastgroup = world;
283 W_Crylink_LinkExplode(self.queuenext, self);
284 self.classname = "spike_oktoremove";
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;
318 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_reload_ammo);
320 maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
321 maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
322 if(autocvar_g_balance_crylink_primary_joinexplode)
323 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
325 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CH_WEAPON_A, maxdmg);
330 shots = autocvar_g_balance_crylink_primary_shots;
331 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
333 while (counter < shots)
336 proj.realowner = proj.owner = self;
337 proj.classname = "spike";
338 proj.bot_dodge = TRUE;
339 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
341 proj.queuenext = proj;
342 proj.queueprev = proj;
344 else if(counter == 0) { // first projectile, store in firstproj for now
347 else if(counter == shots - 1) { // last projectile, link up with first projectile
348 prevproj.queuenext = proj;
349 firstproj.queueprev = proj;
350 proj.queuenext = firstproj;
351 proj.queueprev = prevproj;
353 else { // else link up with previous projectile
354 prevproj.queuenext = proj;
355 proj.queueprev = prevproj;
360 proj.movetype = MOVETYPE_BOUNCEMISSILE;
361 PROJECTILE_MAKETRIGGER(proj);
362 proj.projectiledeathtype = WEP_CRYLINK;
363 //proj.gravity = 0.001;
365 setorigin (proj, w_shotorg);
366 setsize(proj, '0 0 0', '0 0 0');
374 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
378 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
379 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
380 proj.touch = W_Crylink_Touch;
382 proj.think = W_Crylink_Fadethink;
385 proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
386 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
387 proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
391 proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
392 proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
393 proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
395 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
396 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
397 //proj.scale = 1 + 1 * proj.cnt;
399 proj.angles = vectoangles (proj.velocity);
401 //proj.glow_size = 20;
403 proj.flags = FL_PROJECTILE;
405 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
407 other = proj; MUTATOR_CALLHOOK(EditProjectile);
409 counter = counter + 1;
411 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
413 self.crylink_lastgroup = proj;
414 W_Crylink_CheckLinks(proj);
415 self.crylink_waitrelease = 1;
419 void W_Crylink_Attack2 (void)
421 local float counter, shots;
422 local entity proj, prevproj, firstproj;
425 W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_secondary_ammo, autocvar_g_balance_crylink_reload_ammo);
427 maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
428 maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
429 if(autocvar_g_balance_crylink_secondary_joinexplode)
430 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
432 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CH_WEAPON_A, maxdmg);
434 shots = autocvar_g_balance_crylink_secondary_shots;
435 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
437 while (counter < shots)
440 proj.realowner = proj.owner = self;
441 proj.classname = "spike";
442 proj.bot_dodge = TRUE;
443 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
445 proj.queuenext = proj;
446 proj.queueprev = proj;
448 else if(counter == 0) { // first projectile, store in firstproj for now
451 else if(counter == shots - 1) { // last projectile, link up with first projectile
452 prevproj.queuenext = proj;
453 firstproj.queueprev = proj;
454 proj.queuenext = firstproj;
455 proj.queueprev = prevproj;
457 else { // else link up with previous projectile
458 prevproj.queuenext = proj;
459 proj.queueprev = prevproj;
464 proj.movetype = MOVETYPE_BOUNCEMISSILE;
465 PROJECTILE_MAKETRIGGER(proj);
466 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
467 //proj.gravity = 0.001;
469 setorigin (proj, w_shotorg);
470 setsize(proj, '0 0 0', '0 0 0');
472 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);
473 proj.touch = W_Crylink_Touch2;
474 proj.think = W_Crylink_Fadethink;
475 if(counter == (shots - 1) / 2)
477 proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
478 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
479 proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
483 proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
484 proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
485 proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
487 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
488 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
489 //proj.scale = 1 + 1 * proj.cnt;
491 proj.angles = vectoangles (proj.velocity);
493 //proj.glow_size = 20;
495 proj.flags = FL_PROJECTILE;
497 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
499 other = proj; MUTATOR_CALLHOOK(EditProjectile);
501 counter = counter + 1;
503 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
505 self.crylink_lastgroup = proj;
506 W_Crylink_CheckLinks(proj);
507 self.crylink_waitrelease = 2;
511 void spawnfunc_weapon_crylink (void)
513 weapon_defaultspawnfunc(WEP_CRYLINK);
516 float w_crylink(float req)
522 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
524 self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
526 else if (req == WR_THINK)
528 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
529 weapon_action(self.weapon, WR_RELOAD);
531 if (self.BUTTON_ATCK)
533 if (self.crylink_waitrelease != 1)
534 if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
537 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
541 if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
543 if (self.crylink_waitrelease != 2)
544 if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
547 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
551 if ((self.crylink_waitrelease == 1 && !self.BUTTON_ATCK) || (self.crylink_waitrelease == 2 && !self.BUTTON_ATCK2))
553 if (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time)
555 // fired and released now!
556 if(self.crylink_lastgroup)
559 entity linkjoineffect;
561 if(self.crylink_waitrelease == 1)
563 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);
568 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);
571 linkjoineffect = spawn();
572 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
573 linkjoineffect.classname = "linkjoineffect";
574 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
575 linkjoineffect.owner = self;
576 setorigin(linkjoineffect, pos);
578 self.crylink_waitrelease = 0;
579 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
580 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
583 self.cnt = WEP_CRYLINK;
584 self.switchweapon = w_getbestweapon(self);
589 else if (req == WR_PRECACHE)
591 precache_model ("models/weapons/g_crylink.md3");
592 precache_model ("models/weapons/v_crylink.md3");
593 precache_model ("models/weapons/h_crylink.iqm");
594 precache_sound ("weapons/crylink_fire.wav");
595 precache_sound ("weapons/crylink_fire2.wav");
596 precache_sound ("weapons/crylink_linkjoin.wav");
597 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
599 else if (req == WR_SETUP)
601 weapon_setup(WEP_CRYLINK);
602 self.current_ammo = ammo_cells;
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)
610 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
611 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_primary_ammo;
614 else if (req == WR_CHECKAMMO2)
616 // don't "run out of ammo" and switch weapons while waiting for release
617 if(self.crylink_lastgroup && self.crylink_waitrelease)
620 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
621 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_secondary_ammo;
624 else if (req == WR_RELOAD)
626 W_Reload(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");
632 float w_crylink(float req)
634 if(req == WR_IMPACTEFFECT)
637 org2 = w_org + w_backoff * 2;
638 if(w_deathtype & HITTYPE_SECONDARY)
640 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
642 sound(self, CH_SHOTS, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
646 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
648 sound(self, CH_SHOTS, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
651 else if(req == WR_PRECACHE)
653 precache_sound("weapons/crylink_impact2.wav");
654 precache_sound("weapons/crylink_impact.wav");
656 else if (req == WR_SUICIDEMESSAGE)
658 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
660 else if (req == WR_KILLMESSAGE)
662 if(w_deathtype & HITTYPE_BOUNCE)
663 w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
664 else if(w_deathtype & HITTYPE_SPLASH)
665 w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
667 w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY