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 // adjust towards center
43 // returns the origin where they will meet... and the time till the meeting is
44 // stored in w_crylink_linkjoin_time.
45 // could possibly network this origin and time, and display a special particle
46 // effect when projectiles meet there :P
47 float w_crylink_linkjoin_time;
48 vector W_Crylink_LinkJoin(entity e, float joinspeed)
50 vector avg_origin, avg_velocity;
55 w_crylink_linkjoin_time = 0;
57 avg_origin = e.origin;
58 avg_velocity = e.velocity;
60 for(p = e; (p = p.queuenext) != e; )
62 avg_origin += p.origin;
63 avg_velocity += p.velocity;
66 avg_origin *= (1.0 / n);
67 avg_velocity *= (1.0 / n);
70 return avg_origin; // nothing to do
72 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
73 avg_dist = pow(vlen(e.origin - avg_origin), 2);
74 for(p = e; (p = p.queuenext) != e; )
75 avg_dist += pow(vlen(e.origin - avg_origin), 2);
76 avg_dist *= (1.0 / n);
77 avg_dist = sqrt(avg_dist);
80 return avg_origin; // no change needed
84 e.velocity = avg_velocity;
85 UpdateCSQCProjectile(e);
86 for(p = e; (p = p.queuenext) != e; )
88 p.velocity = avg_velocity;
89 UpdateCSQCProjectile(p);
94 w_crylink_linkjoin_time = avg_dist / joinspeed;
95 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
97 e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
98 UpdateCSQCProjectile(e);
99 for(p = e; (p = p.queuenext) != e; )
101 p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
102 UpdateCSQCProjectile(p);
106 // joinspeed -> +infinity:
107 // w_crylink_linkjoin_time -> +0
108 // targ_origin -> avg_origin
109 // p->velocity -> HUEG towards center
111 // w_crylink_linkjoin_time -> +/- infinity
112 // targ_origin -> avg_velocity * +/- infinity
113 // p->velocity -> avg_velocity
114 // joinspeed -> -infinity:
115 // w_crylink_linkjoin_time -> -0
116 // targ_origin -> avg_origin
117 // p->velocity -> HUEG away from center
123 void W_Crylink_LinkJoinEffect_Think()
125 // is there at least 2 projectiles very close?
128 e = self.owner.crylink_lastgroup;
132 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
134 for(p = e; (p = p.queuenext) != e; )
136 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
141 // they seem to touch...
142 // TODO make a specific particle effect for this
143 pointparticles(particleeffectnum("crylink_linkjoin"), self.origin, '0 0 0', 1);
149 // NO bounce protection, as bounces are limited!
150 void W_Crylink_Touch (void)
155 local entity savenext, saveprev, saveown;
156 saveown = self.realowner;
157 savenext = self.queuenext;
158 saveprev = self.queueprev;
159 if(WarpZone_Projectile_Touch())
162 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
167 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
169 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
173 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
176 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) || finalhit)
178 W_Crylink_LinkExplode(self.queuenext, self);
182 self.cnt = self.cnt - 1;
183 self.angles = vectoangles(self.velocity);
185 self.projectiledeathtype |= HITTYPE_BOUNCE;
186 // commented out as it causes a little hitch...
188 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
191 void W_Crylink_Touch2 (void)
196 local entity savenext, saveprev, saveown;
197 savenext = self.queuenext;
198 saveprev = self.queueprev;
199 saveown = self.realowner;
200 if(WarpZone_Projectile_Touch())
203 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
208 a = 1 - (time - self.fade_time) * self.fade_rate;
210 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
214 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
217 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))
219 W_Crylink_LinkExplode(self.queuenext, self);
226 W_Crylink_Dequeue(self);
230 self.cnt = self.cnt - 1;
231 self.angles = vectoangles(self.velocity);
233 self.projectiledeathtype |= HITTYPE_BOUNCE;
234 // commented out as it causes a little hitch...
236 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
239 void W_Crylink_Fadethink (void)
241 W_Crylink_Dequeue(self);
245 void W_Crylink_Attack (void)
247 local float counter, shots;
248 local entity proj, prevproj, firstproj;
250 vector forward, right, up;
252 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
253 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
255 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
260 shots = cvar("g_balance_crylink_primary_shots");
261 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
263 while (counter < shots)
266 proj.realowner = proj.owner = self;
267 proj.classname = "spike";
268 proj.bot_dodge = TRUE;
269 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
270 if(counter == 0) { // first projectile, store in firstproj for now
273 else if(counter == shots - 1) { // last projectile, link up with first projectile
274 prevproj.queuenext = proj;
275 firstproj.queueprev = proj;
276 proj.queuenext = firstproj;
277 proj.queueprev = prevproj;
279 else { // else link up with previous projectile
280 prevproj.queuenext = proj;
281 proj.queueprev = prevproj;
286 proj.movetype = MOVETYPE_BOUNCEMISSILE;
287 PROJECTILE_MAKETRIGGER(proj);
288 proj.projectiledeathtype = WEP_CRYLINK;
289 //proj.gravity = 0.001;
291 setorigin (proj, w_shotorg);
292 setsize(proj, '0 0 0', '0 0 0');
300 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
304 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
305 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
306 proj.touch = W_Crylink_Touch;
308 proj.think = W_Crylink_Fadethink;
311 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
312 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
313 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
317 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
318 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
319 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
321 proj.cnt = cvar("g_balance_crylink_primary_bounces");
322 //proj.scale = 1 + 1 * proj.cnt;
324 proj.angles = vectoangles (proj.velocity);
326 //proj.glow_size = 20;
328 proj.flags = FL_PROJECTILE;
330 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
332 other = proj; MUTATOR_CALLHOOK(EditProjectile);
334 counter = counter + 1;
336 self.crylink_lastgroup = proj;
339 void W_Crylink_Attack2 (void)
341 local float counter, shots;
342 local entity proj, prevproj, firstproj;
344 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
345 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
347 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
349 shots = cvar("g_balance_crylink_secondary_shots");
350 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
352 while (counter < shots)
355 proj.realowner = proj.owner = self;
356 proj.classname = "spike";
357 proj.bot_dodge = TRUE;
358 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
359 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 | HITTYPE_SECONDARY;
378 //proj.gravity = 0.001;
380 setorigin (proj, w_shotorg);
381 setsize(proj, '0 0 0', '0 0 0');
383 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);
384 proj.touch = W_Crylink_Touch2;
385 proj.think = W_Crylink_Fadethink;
386 if(counter == (shots - 1) / 2)
388 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
389 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
390 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
394 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
395 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
396 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
398 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
399 //proj.scale = 1 + 1 * proj.cnt;
401 proj.angles = vectoangles (proj.velocity);
403 //proj.glow_size = 20;
405 proj.flags = FL_PROJECTILE;
407 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
409 other = proj; MUTATOR_CALLHOOK(EditProjectile);
411 counter = counter + 1;
413 self.crylink_lastgroup = proj;
416 void spawnfunc_weapon_crylink (void)
418 weapon_defaultspawnfunc(WEP_CRYLINK);
421 float w_crylink(float req)
426 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
428 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
430 else if (req == WR_THINK)
432 if (self.BUTTON_ATCK)
434 if (!self.crylink_waitrelease)
435 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
438 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
439 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
440 self.crylink_waitrelease = 1;
443 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
445 if (!self.crylink_waitrelease)
446 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
449 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
450 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
451 self.crylink_waitrelease = 2;
456 if (self.crylink_waitrelease)
458 // fired and released now!
459 if(self.crylink_lastgroup)
462 if(self.crylink_waitrelease == 1)
464 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
468 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
471 entity linkjoineffect;
472 linkjoineffect = spawn();
473 linkjoineffect.classname = "linkjoineffect";
474 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
475 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
476 linkjoineffect.owner = self;
477 setorigin(linkjoineffect, pos);
479 self.crylink_waitrelease = 0;
480 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
483 self.cnt = WEP_CRYLINK;
484 self.switchweapon = w_getbestweapon(self);
489 else if (req == WR_PRECACHE)
491 precache_model ("models/weapons/g_crylink.md3");
492 precache_model ("models/weapons/v_crylink.md3");
493 precache_model ("models/weapons/h_crylink.iqm");
494 precache_sound ("weapons/crylink_fire.wav");
495 precache_sound ("weapons/crylink_fire2.wav");
496 precache_sound ("weapons/crylink_linkjoin.wav");
498 else if (req == WR_SETUP)
499 weapon_setup(WEP_CRYLINK);
500 else if (req == WR_CHECKAMMO1)
502 // don't "run out of ammo" and switch weapons while waiting for release
503 if(self.crylink_lastgroup && self.crylink_waitrelease)
505 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
507 else if (req == WR_CHECKAMMO2)
509 // don't "run out of ammo" and switch weapons while waiting for release
510 if(self.crylink_lastgroup && self.crylink_waitrelease)
512 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
518 float w_crylink(float req)
520 if(req == WR_IMPACTEFFECT)
523 org2 = w_org + w_backoff * 2;
524 if(w_deathtype & HITTYPE_SECONDARY)
526 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
528 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
532 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
534 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
537 else if(req == WR_PRECACHE)
539 precache_sound("weapons/crylink_impact2.wav");
540 precache_sound("weapons/crylink_impact.wav");
542 else if (req == WR_SUICIDEMESSAGE)
544 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
546 else if (req == WR_KILLMESSAGE)
548 if(w_deathtype & HITTYPE_BOUNCE)
549 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
550 else if(w_deathtype & HITTYPE_SPLASH)
551 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
553 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY