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 // jspeed: MINIMUM jing speed
48 // jtime: MAXIMUM jing time (0: none)
49 float w_crylink_linkjoin_time;
50 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
52 vector avg_origin, avg_velocity;
57 w_crylink_linkjoin_time = 0;
59 avg_origin = e.origin;
60 avg_velocity = e.velocity;
62 for(p = e; (p = p.queuenext) != e; )
64 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
65 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
68 avg_origin *= (1.0 / n);
69 avg_velocity *= (1.0 / n);
72 return avg_origin; // nothing to do
74 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
75 avg_dist = pow(vlen(e.origin - avg_origin), 2);
76 for(p = e; (p = p.queuenext) != e; )
77 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
78 avg_dist *= (1.0 / n);
79 avg_dist = sqrt(avg_dist);
82 return avg_origin; // no change needed
84 if(jspeed == 0 && jtime == 0)
86 e.velocity = avg_velocity;
87 UpdateCSQCProjectile(e);
88 for(p = e; (p = p.queuenext) != e; )
90 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
91 UpdateCSQCProjectile(p);
99 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
101 w_crylink_linkjoin_time = jtime;
104 w_crylink_linkjoin_time = avg_dist / jspeed;
105 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
107 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
108 UpdateCSQCProjectile(e);
109 for(p = e; (p = p.queuenext) != e; )
111 p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
112 UpdateCSQCProjectile(p);
116 // jspeed -> +infinity:
117 // w_crylink_linkjoin_time -> +0
118 // targ_origin -> avg_origin
119 // p->velocity -> HUEG towards center
121 // w_crylink_linkjoin_time -> +/- infinity
122 // targ_origin -> avg_velocity * +/- infinity
123 // p->velocity -> avg_velocity
124 // jspeed -> -infinity:
125 // w_crylink_linkjoin_time -> -0
126 // targ_origin -> avg_origin
127 // p->velocity -> HUEG away from center
133 void W_Crylink_LinkJoinEffect_Think()
135 // is there at least 2 projectiles very close?
138 e = self.owner.crylink_lastgroup;
142 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
144 for(p = e; (p = p.queuenext) != e; )
146 if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
153 if(e.projectiledeathtype & HITTYPE_SECONDARY)
155 if(cvar("g_balance_crylink_secondary_joinexplode"))
157 n = n / cvar("g_balance_crylink_secondary_shots");
158 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_secondary_joinexplode_damage") * n,
159 cvar("g_balance_crylink_secondary_joinexplode_edgedamage") * n,
160 cvar("g_balance_crylink_secondary_joinexplode_radius") * n, world,
161 cvar("g_balance_crylink_secondary_joinexplode_force") * n, e.projectiledeathtype, other);
166 if(cvar("g_balance_crylink_primary_joinexplode"))
168 n = n / cvar("g_balance_crylink_primary_shots");
169 RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_joinexplode_damage") * n,
170 cvar("g_balance_crylink_primary_joinexplode_edgedamage") * n,
171 cvar("g_balance_crylink_primary_joinexplode_radius") * n, world,
172 cvar("g_balance_crylink_primary_joinexplode_force") * n, e.projectiledeathtype, other);
176 // they seem to touch...
177 // TODO make a specific particle effect for this
178 pointparticles(particleeffectnum("crylink_linkjoin"), self.origin, '0 0 0', 1);
185 // NO bounce protection, as bounces are limited!
186 void W_Crylink_Touch (void)
191 local entity savenext, saveprev, saveown;
192 saveown = self.realowner;
193 savenext = self.queuenext;
194 saveprev = self.queueprev;
195 if(WarpZone_Projectile_Touch())
198 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
203 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
205 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
209 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
212 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"))
214 W_Crylink_LinkExplode(self.queuenext, self);
221 W_Crylink_Dequeue(self);
225 self.cnt = self.cnt - 1;
226 self.angles = vectoangles(self.velocity);
228 self.projectiledeathtype |= HITTYPE_BOUNCE;
229 // commented out as it causes a little hitch...
231 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
234 void W_Crylink_Touch2 (void)
239 local entity savenext, saveprev, saveown;
240 savenext = self.queuenext;
241 saveprev = self.queueprev;
242 saveown = self.realowner;
243 if(WarpZone_Projectile_Touch())
246 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
251 a = 1 - (time - self.fade_time) * self.fade_rate;
253 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
257 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
260 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"))
262 W_Crylink_LinkExplode(self.queuenext, self);
269 W_Crylink_Dequeue(self);
273 self.cnt = self.cnt - 1;
274 self.angles = vectoangles(self.velocity);
276 self.projectiledeathtype |= HITTYPE_BOUNCE;
277 // commented out as it causes a little hitch...
279 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
282 void W_Crylink_Fadethink (void)
284 W_Crylink_Dequeue(self);
288 void W_Crylink_Attack (void)
290 local float counter, shots;
291 local entity proj, prevproj, firstproj;
293 vector forward, right, up;
295 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
296 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
298 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
303 shots = cvar("g_balance_crylink_primary_shots");
304 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
306 while (counter < shots)
309 proj.realowner = proj.owner = self;
310 proj.classname = "spike";
311 proj.bot_dodge = TRUE;
312 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
313 if(counter == 0) { // first projectile, store in firstproj for now
316 else if(counter == shots - 1) { // last projectile, link up with first projectile
317 prevproj.queuenext = proj;
318 firstproj.queueprev = proj;
319 proj.queuenext = firstproj;
320 proj.queueprev = prevproj;
322 else { // else link up with previous projectile
323 prevproj.queuenext = proj;
324 proj.queueprev = prevproj;
329 proj.movetype = MOVETYPE_BOUNCEMISSILE;
330 PROJECTILE_MAKETRIGGER(proj);
331 proj.projectiledeathtype = WEP_CRYLINK;
332 //proj.gravity = 0.001;
334 setorigin (proj, w_shotorg);
335 setsize(proj, '0 0 0', '0 0 0');
343 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
347 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
348 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
349 proj.touch = W_Crylink_Touch;
351 proj.think = W_Crylink_Fadethink;
354 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
355 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
356 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
360 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
361 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
362 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
364 proj.cnt = cvar("g_balance_crylink_primary_bounces");
365 //proj.scale = 1 + 1 * proj.cnt;
367 proj.angles = vectoangles (proj.velocity);
369 //proj.glow_size = 20;
371 proj.flags = FL_PROJECTILE;
373 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
375 other = proj; MUTATOR_CALLHOOK(EditProjectile);
377 counter = counter + 1;
379 self.crylink_lastgroup = proj;
382 void W_Crylink_Attack2 (void)
384 local float counter, shots;
385 local entity proj, prevproj, firstproj;
387 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
388 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
390 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
392 shots = cvar("g_balance_crylink_secondary_shots");
393 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
395 while (counter < shots)
398 proj.realowner = proj.owner = self;
399 proj.classname = "spike";
400 proj.bot_dodge = TRUE;
401 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
402 if(counter == 0) { // first projectile, store in firstproj for now
405 else if(counter == shots - 1) { // last projectile, link up with first projectile
406 prevproj.queuenext = proj;
407 firstproj.queueprev = proj;
408 proj.queuenext = firstproj;
409 proj.queueprev = prevproj;
411 else { // else link up with previous projectile
412 prevproj.queuenext = proj;
413 proj.queueprev = prevproj;
418 proj.movetype = MOVETYPE_BOUNCEMISSILE;
419 PROJECTILE_MAKETRIGGER(proj);
420 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
421 //proj.gravity = 0.001;
423 setorigin (proj, w_shotorg);
424 setsize(proj, '0 0 0', '0 0 0');
426 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);
427 proj.touch = W_Crylink_Touch2;
428 proj.think = W_Crylink_Fadethink;
429 if(counter == (shots - 1) / 2)
431 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
432 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
433 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
437 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
438 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
439 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
441 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
442 //proj.scale = 1 + 1 * proj.cnt;
444 proj.angles = vectoangles (proj.velocity);
446 //proj.glow_size = 20;
448 proj.flags = FL_PROJECTILE;
450 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
452 other = proj; MUTATOR_CALLHOOK(EditProjectile);
454 counter = counter + 1;
456 self.crylink_lastgroup = proj;
459 void spawnfunc_weapon_crylink (void)
461 weapon_defaultspawnfunc(WEP_CRYLINK);
464 float w_crylink(float req)
469 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
471 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
473 else if (req == WR_THINK)
475 if (self.BUTTON_ATCK)
477 if (!self.crylink_waitrelease)
478 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
481 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
482 if(cvar("g_balance_crylink_primary_joinspeed") != 0 || cvar("g_balance_crylink_primary_jointime") != 0)
483 self.crylink_waitrelease = 1;
486 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
488 if (!self.crylink_waitrelease)
489 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
492 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
493 if(cvar("g_balance_crylink_secondary_joinspeed") != 0 || cvar("g_balance_crylink_secondary_jointime") != 0)
494 self.crylink_waitrelease = 2;
499 if (self.crylink_waitrelease)
501 // fired and released now!
502 if(self.crylink_lastgroup)
505 entity linkjoineffect;
508 if(self.crylink_waitrelease == 1)
510 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"), cvar("g_balance_crylink_primary_jointime"));
515 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"), cvar("g_balance_crylink_secondary_jointime"));
518 linkjoineffect = spawn();
519 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
520 linkjoineffect.classname = "linkjoineffect";
521 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
522 linkjoineffect.owner = self;
523 setorigin(linkjoineffect, pos);
527 self.crylink_waitrelease = 0;
528 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
531 self.cnt = WEP_CRYLINK;
532 self.switchweapon = w_getbestweapon(self);
537 else if (req == WR_PRECACHE)
539 precache_model ("models/weapons/g_crylink.md3");
540 precache_model ("models/weapons/v_crylink.md3");
541 precache_model ("models/weapons/h_crylink.iqm");
542 precache_sound ("weapons/crylink_fire.wav");
543 precache_sound ("weapons/crylink_fire2.wav");
544 precache_sound ("weapons/crylink_linkjoin.wav");
546 else if (req == WR_SETUP)
547 weapon_setup(WEP_CRYLINK);
548 else if (req == WR_CHECKAMMO1)
550 // don't "run out of ammo" and switch weapons while waiting for release
551 if(self.crylink_lastgroup && self.crylink_waitrelease)
553 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
555 else if (req == WR_CHECKAMMO2)
557 // don't "run out of ammo" and switch weapons while waiting for release
558 if(self.crylink_lastgroup && self.crylink_waitrelease)
560 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
566 float w_crylink(float req)
568 if(req == WR_IMPACTEFFECT)
571 org2 = w_org + w_backoff * 2;
572 if(w_deathtype & HITTYPE_SECONDARY)
574 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
576 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
580 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
582 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
585 else if(req == WR_PRECACHE)
587 precache_sound("weapons/crylink_impact2.wav");
588 precache_sound("weapons/crylink_impact.wav");
590 else if (req == WR_SUICIDEMESSAGE)
592 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
594 else if (req == WR_KILLMESSAGE)
596 if(w_deathtype & HITTYPE_BOUNCE)
597 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
598 else if(w_deathtype & HITTYPE_SPLASH)
599 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
601 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY