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");
315 else if(counter <= 3)
317 proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
318 self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
319 proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
323 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
324 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
325 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
327 proj.cnt = cvar("g_balance_crylink_primary_bounces");
328 //proj.scale = 1 + 1 * proj.cnt;
330 proj.angles = vectoangles (proj.velocity);
332 //proj.glow_size = 20;
334 proj.flags = FL_PROJECTILE;
336 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
338 other = proj; MUTATOR_CALLHOOK(EditProjectile);
340 counter = counter + 1;
342 self.crylink_lastgroup = proj;
345 void W_Crylink_Attack2 (void)
347 local float counter, shots;
348 local entity proj, prevproj, firstproj;
350 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
351 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
353 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
355 shots = cvar("g_balance_crylink_secondary_shots");
356 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
358 while (counter < shots)
361 proj.realowner = proj.owner = self;
362 proj.classname = "spike";
363 proj.bot_dodge = TRUE;
364 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
365 if(counter == 0) { // first projectile, store in firstproj for now
368 else if(counter == shots - 1) { // last projectile, link up with first projectile
369 prevproj.queuenext = proj;
370 firstproj.queueprev = proj;
371 proj.queuenext = firstproj;
372 proj.queueprev = prevproj;
374 else { // else link up with previous projectile
375 prevproj.queuenext = proj;
376 proj.queueprev = prevproj;
381 proj.movetype = MOVETYPE_BOUNCEMISSILE;
382 PROJECTILE_MAKETRIGGER(proj);
383 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
384 //proj.gravity = 0.001;
386 setorigin (proj, w_shotorg);
387 setsize(proj, '0 0 0', '0 0 0');
389 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);
390 proj.touch = W_Crylink_Touch2;
391 proj.think = W_Crylink_Fadethink;
392 if(counter == (shots - 1) / 2)
394 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
395 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
396 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
400 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
401 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
402 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
404 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
405 //proj.scale = 1 + 1 * proj.cnt;
407 proj.angles = vectoangles (proj.velocity);
409 //proj.glow_size = 20;
411 proj.flags = FL_PROJECTILE;
413 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
415 other = proj; MUTATOR_CALLHOOK(EditProjectile);
417 counter = counter + 1;
419 self.crylink_lastgroup = proj;
422 void spawnfunc_weapon_crylink (void)
424 weapon_defaultspawnfunc(WEP_CRYLINK);
427 float w_crylink(float req)
432 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
434 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
436 else if (req == WR_THINK)
438 if (self.BUTTON_ATCK)
440 if (!self.crylink_waitrelease)
441 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
444 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
445 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
446 self.crylink_waitrelease = 1;
449 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
451 if (!self.crylink_waitrelease)
452 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
455 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
456 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
457 self.crylink_waitrelease = 2;
462 if (self.crylink_waitrelease)
464 // fired and released now!
465 if(self.crylink_lastgroup)
468 if(self.crylink_waitrelease == 1)
470 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
474 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
477 entity linkjoineffect;
478 linkjoineffect = spawn();
479 linkjoineffect.classname = "linkjoineffect";
480 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
481 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
482 linkjoineffect.owner = self;
483 setorigin(linkjoineffect, pos);
485 self.crylink_waitrelease = 0;
486 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
489 self.cnt = WEP_CRYLINK;
490 self.switchweapon = w_getbestweapon(self);
495 else if (req == WR_PRECACHE)
497 precache_model ("models/weapons/g_crylink.md3");
498 precache_model ("models/weapons/v_crylink.md3");
499 precache_model ("models/weapons/h_crylink.iqm");
500 precache_sound ("weapons/crylink_fire.wav");
501 precache_sound ("weapons/crylink_fire2.wav");
502 precache_sound ("weapons/crylink_linkjoin.wav");
504 else if (req == WR_SETUP)
505 weapon_setup(WEP_CRYLINK);
506 else if (req == WR_CHECKAMMO1)
508 // don't "run out of ammo" and switch weapons while waiting for release
509 if(self.crylink_lastgroup && self.crylink_waitrelease)
511 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
513 else if (req == WR_CHECKAMMO2)
515 // don't "run out of ammo" and switch weapons while waiting for release
516 if(self.crylink_lastgroup && self.crylink_waitrelease)
518 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
524 float w_crylink(float req)
526 if(req == WR_IMPACTEFFECT)
529 org2 = w_org + w_backoff * 2;
530 if(w_deathtype & HITTYPE_SECONDARY)
532 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
534 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
538 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
540 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
543 else if(req == WR_PRECACHE)
545 precache_sound("weapons/crylink_impact2.wav");
546 precache_sound("weapons/crylink_impact.wav");
548 else if (req == WR_SUICIDEMESSAGE)
550 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
552 else if (req == WR_KILLMESSAGE)
554 if(w_deathtype & HITTYPE_BOUNCE)
555 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
556 else if(w_deathtype & HITTYPE_SPLASH)
557 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
559 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY