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))
178 W_Crylink_LinkExplode(self.queuenext, self);
185 W_Crylink_Dequeue(self);
189 self.cnt = self.cnt - 1;
190 self.angles = vectoangles(self.velocity);
192 self.projectiledeathtype |= HITTYPE_BOUNCE;
193 // commented out as it causes a little hitch...
195 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
198 void W_Crylink_Touch2 (void)
203 local entity savenext, saveprev, saveown;
204 savenext = self.queuenext;
205 saveprev = self.queueprev;
206 saveown = self.realowner;
207 if(WarpZone_Projectile_Touch())
210 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
215 a = 1 - (time - self.fade_time) * self.fade_rate;
217 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
221 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
224 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))
226 W_Crylink_LinkExplode(self.queuenext, self);
233 W_Crylink_Dequeue(self);
237 self.cnt = self.cnt - 1;
238 self.angles = vectoangles(self.velocity);
240 self.projectiledeathtype |= HITTYPE_BOUNCE;
241 // commented out as it causes a little hitch...
243 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
246 void W_Crylink_Fadethink (void)
248 W_Crylink_Dequeue(self);
252 void W_Crylink_Attack (void)
254 local float counter, shots;
255 local entity proj, prevproj, firstproj;
257 vector forward, right, up;
259 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
260 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
262 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
267 shots = cvar("g_balance_crylink_primary_shots");
268 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
270 while (counter < shots)
273 proj.realowner = proj.owner = self;
274 proj.classname = "spike";
275 proj.bot_dodge = TRUE;
276 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
277 if(counter == 0) { // first projectile, store in firstproj for now
280 else if(counter == shots - 1) { // last projectile, link up with first projectile
281 prevproj.queuenext = proj;
282 firstproj.queueprev = proj;
283 proj.queuenext = firstproj;
284 proj.queueprev = prevproj;
286 else { // else link up with previous projectile
287 prevproj.queuenext = proj;
288 proj.queueprev = prevproj;
293 proj.movetype = MOVETYPE_BOUNCEMISSILE;
294 PROJECTILE_MAKETRIGGER(proj);
295 proj.projectiledeathtype = WEP_CRYLINK;
296 //proj.gravity = 0.001;
298 setorigin (proj, w_shotorg);
299 setsize(proj, '0 0 0', '0 0 0');
307 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
311 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
312 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
313 proj.touch = W_Crylink_Touch;
315 proj.think = W_Crylink_Fadethink;
318 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
319 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
320 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
324 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
325 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
326 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
328 proj.cnt = cvar("g_balance_crylink_primary_bounces");
329 //proj.scale = 1 + 1 * proj.cnt;
331 proj.angles = vectoangles (proj.velocity);
333 //proj.glow_size = 20;
335 proj.flags = FL_PROJECTILE;
337 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
339 other = proj; MUTATOR_CALLHOOK(EditProjectile);
341 counter = counter + 1;
343 self.crylink_lastgroup = proj;
346 void W_Crylink_Attack2 (void)
348 local float counter, shots;
349 local entity proj, prevproj, firstproj;
351 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
352 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
354 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
356 shots = cvar("g_balance_crylink_secondary_shots");
357 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
359 while (counter < shots)
362 proj.realowner = proj.owner = self;
363 proj.classname = "spike";
364 proj.bot_dodge = TRUE;
365 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
366 if(counter == 0) { // first projectile, store in firstproj for now
369 else if(counter == shots - 1) { // last projectile, link up with first projectile
370 prevproj.queuenext = proj;
371 firstproj.queueprev = proj;
372 proj.queuenext = firstproj;
373 proj.queueprev = prevproj;
375 else { // else link up with previous projectile
376 prevproj.queuenext = proj;
377 proj.queueprev = prevproj;
382 proj.movetype = MOVETYPE_BOUNCEMISSILE;
383 PROJECTILE_MAKETRIGGER(proj);
384 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
385 //proj.gravity = 0.001;
387 setorigin (proj, w_shotorg);
388 setsize(proj, '0 0 0', '0 0 0');
390 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);
391 proj.touch = W_Crylink_Touch2;
392 proj.think = W_Crylink_Fadethink;
393 if(counter == (shots - 1) / 2)
395 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
396 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
397 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
401 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
402 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
403 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
405 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
406 //proj.scale = 1 + 1 * proj.cnt;
408 proj.angles = vectoangles (proj.velocity);
410 //proj.glow_size = 20;
412 proj.flags = FL_PROJECTILE;
414 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
416 other = proj; MUTATOR_CALLHOOK(EditProjectile);
418 counter = counter + 1;
420 self.crylink_lastgroup = proj;
423 void spawnfunc_weapon_crylink (void)
425 weapon_defaultspawnfunc(WEP_CRYLINK);
428 float w_crylink(float req)
433 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
435 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
437 else if (req == WR_THINK)
439 if (self.BUTTON_ATCK)
441 if (!self.crylink_waitrelease)
442 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
445 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
446 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
447 self.crylink_waitrelease = 1;
450 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
452 if (!self.crylink_waitrelease)
453 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
456 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
457 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
458 self.crylink_waitrelease = 2;
463 if (self.crylink_waitrelease)
465 // fired and released now!
466 if(self.crylink_lastgroup)
469 if(self.crylink_waitrelease == 1)
471 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
475 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
478 entity linkjoineffect;
479 linkjoineffect = spawn();
480 linkjoineffect.classname = "linkjoineffect";
481 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
482 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
483 linkjoineffect.owner = self;
484 setorigin(linkjoineffect, pos);
486 self.crylink_waitrelease = 0;
487 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
490 self.cnt = WEP_CRYLINK;
491 self.switchweapon = w_getbestweapon(self);
496 else if (req == WR_PRECACHE)
498 precache_model ("models/weapons/g_crylink.md3");
499 precache_model ("models/weapons/v_crylink.md3");
500 precache_model ("models/weapons/h_crylink.iqm");
501 precache_sound ("weapons/crylink_fire.wav");
502 precache_sound ("weapons/crylink_fire2.wav");
503 precache_sound ("weapons/crylink_linkjoin.wav");
505 else if (req == WR_SETUP)
506 weapon_setup(WEP_CRYLINK);
507 else if (req == WR_CHECKAMMO1)
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_primary_ammo");
514 else if (req == WR_CHECKAMMO2)
516 // don't "run out of ammo" and switch weapons while waiting for release
517 if(self.crylink_lastgroup && self.crylink_waitrelease)
519 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
525 float w_crylink(float req)
527 if(req == WR_IMPACTEFFECT)
530 org2 = w_org + w_backoff * 2;
531 if(w_deathtype & HITTYPE_SECONDARY)
533 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
535 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
539 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
541 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
544 else if(req == WR_PRECACHE)
546 precache_sound("weapons/crylink_impact2.wav");
547 precache_sound("weapons/crylink_impact.wav");
549 else if (req == WR_SUICIDEMESSAGE)
551 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
553 else if (req == WR_KILLMESSAGE)
555 if(w_deathtype & HITTYPE_BOUNCE)
556 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
557 else if(w_deathtype & HITTYPE_SPLASH)
558 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
560 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY