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 avg_origin = e.origin;
56 avg_velocity = e.velocity;
58 for(p = e; (p = p.queuenext) != e; )
60 avg_origin += p.origin;
61 avg_velocity += p.velocity;
64 avg_origin *= (1.0 / n);
65 avg_velocity *= (1.0 / n);
67 // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
68 avg_dist = pow(vlen(e.origin - avg_origin), 2);
69 for(p = e; (p = p.queuenext) != e; )
70 avg_dist += pow(vlen(e.origin - avg_origin), 2);
71 avg_dist *= (1.0 / n);
73 w_crylink_linkjoin_time = 0;
75 return avg_origin; // no change needed
79 e.velocity = avg_velocity;
80 UpdateCSQCProjectile(e);
81 for(p = e; (p = p.queuenext) != e; )
83 p.velocity = avg_velocity;
84 UpdateCSQCProjectile(p);
89 w_crylink_linkjoin_time = avg_dist / joinspeed;
90 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
92 e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
93 UpdateCSQCProjectile(e);
94 for(p = e; (p = p.queuenext) != e; )
96 p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
97 UpdateCSQCProjectile(p);
101 // joinspeed -> +infinity:
102 // w_crylink_linkjoin_time -> +0
103 // targ_origin -> avg_origin
104 // p->velocity -> HUEG towards center
106 // w_crylink_linkjoin_time -> +/- infinity
107 // targ_origin -> avg_velocity * +/- infinity
108 // p->velocity -> avg_velocity
109 // joinspeed -> -infinity:
110 // w_crylink_linkjoin_time -> -0
111 // targ_origin -> avg_origin
112 // p->velocity -> HUEG away from center
118 // NO bounce protection, as bounces are limited!
119 void W_Crylink_Touch (void)
124 local entity savenext, saveprev, saveown;
125 saveown = self.realowner;
126 savenext = self.queuenext;
127 saveprev = self.queueprev;
128 if(WarpZone_Projectile_Touch())
131 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
136 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
138 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
142 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
145 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)
147 W_Crylink_LinkExplode(self.queuenext, self);
151 self.cnt = self.cnt - 1;
152 // self.angles = vectoangles(self.velocity); // csqc
154 self.projectiledeathtype |= HITTYPE_BOUNCE;
155 // commented out as it causes a little hitch...
157 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
160 void W_Crylink_Touch2 (void)
165 local entity savenext, saveprev, saveown;
166 savenext = self.queuenext;
167 saveprev = self.queueprev;
168 saveown = self.realowner;
169 if(WarpZone_Projectile_Touch())
172 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
177 a = 1 - (time - self.fade_time) * self.fade_rate;
179 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
183 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
186 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))
188 W_Crylink_LinkExplode(self.queuenext, self);
195 W_Crylink_Dequeue(self);
199 self.cnt = self.cnt - 1;
200 // self.angles = vectoangles(self.velocity); // csqc
202 self.projectiledeathtype |= HITTYPE_BOUNCE;
203 // commented out as it causes a little hitch...
205 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
208 void W_Crylink_Fadethink (void)
210 W_Crylink_Dequeue(self);
214 void W_Crylink_Attack (void)
216 float counter, shots;
217 entity proj, prevproj, firstproj;
218 vector forward, right, up, s;
220 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
221 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
223 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
228 shots = cvar("g_balance_crylink_primary_shots");
229 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
231 while (counter < shots)
234 proj.crylink_waitrelease = time; // keep track of when each projectile was spawned
235 proj.realowner = proj.owner = self;
236 proj.classname = "spike";
237 proj.bot_dodge = TRUE;
238 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
239 if(counter == 0) { // first projectile, store in firstproj for now
242 else if(counter == shots - 1) { // last projectile, link up with first projectile
243 prevproj.queuenext = proj;
244 firstproj.queueprev = proj;
245 proj.queuenext = firstproj;
246 proj.queueprev = prevproj;
248 else { // else link up with previous projectile
249 prevproj.queuenext = proj;
250 proj.queueprev = prevproj;
255 proj.movetype = MOVETYPE_BOUNCEMISSILE;
256 PROJECTILE_MAKETRIGGER(proj);
257 proj.projectiledeathtype = WEP_CRYLINK;
258 //proj.gravity = 0.001;
260 setorigin (proj, w_shotorg);
261 setsize(proj, '0 0 0', '0 0 0');
269 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
273 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
274 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
275 proj.touch = W_Crylink_Touch;
277 proj.think = W_Crylink_Fadethink;
280 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
281 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
282 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
284 else if(counter <= 3)
286 proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
287 self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
288 proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
292 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
293 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
294 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
296 proj.cnt = cvar("g_balance_crylink_primary_bounces");
298 //proj.scale = 1 + 1 * proj.cnt;
299 //proj.angles = vectoangles (proj.velocity); // csqc
300 //proj.glow_size = 20;
302 proj.flags = FL_PROJECTILE;
304 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
306 other = proj; MUTATOR_CALLHOOK(EditProjectile);
308 counter = counter + 1;
310 self.crylink_lastgroup = proj;
313 void W_Crylink_Attack2 (void)
315 local float counter, shots;
316 local entity proj, prevproj, firstproj;
318 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
319 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
321 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
323 shots = cvar("g_balance_crylink_secondary_shots");
324 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
326 while (counter < shots)
329 proj.crylink_waitrelease = time; // keep track of when each projectile was spawned
330 proj.realowner = proj.owner = self;
331 proj.classname = "spike";
332 proj.bot_dodge = TRUE;
333 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
334 if(counter == 0) { // first projectile, store in firstproj for now
337 else if(counter == shots - 1) { // last projectile, link up with first projectile
338 prevproj.queuenext = proj;
339 firstproj.queueprev = proj;
340 proj.queuenext = firstproj;
341 proj.queueprev = prevproj;
343 else { // else link up with previous projectile
344 prevproj.queuenext = proj;
345 proj.queueprev = prevproj;
350 proj.movetype = MOVETYPE_BOUNCEMISSILE;
351 PROJECTILE_MAKETRIGGER(proj);
352 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
353 //proj.gravity = 0.001;
355 setorigin (proj, w_shotorg);
356 setsize(proj, '0 0 0', '0 0 0');
358 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);
359 proj.touch = W_Crylink_Touch2;
360 proj.think = W_Crylink_Fadethink;
361 if(counter == (shots - 1) / 2)
363 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
364 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
365 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
369 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
370 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
371 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
373 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
374 //proj.scale = 1 + 1 * proj.cnt;
376 // proj.angles = vectoangles (proj.velocity); // csqc
378 //proj.glow_size = 20;
380 proj.flags = FL_PROJECTILE;
382 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
384 other = proj; MUTATOR_CALLHOOK(EditProjectile);
386 counter = counter + 1;
388 self.crylink_lastgroup = proj;
391 void spawnfunc_weapon_crylink (void)
393 weapon_defaultspawnfunc(WEP_CRYLINK);
396 float w_crylink(float req)
401 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
403 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
405 else if (req == WR_THINK)
407 if (self.BUTTON_ATCK)
409 if(self.crylink_lastgroup == world)
410 self.crylink_waitrelease = 0;
412 if (!self.crylink_waitrelease)
413 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
416 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
417 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
418 self.crylink_waitrelease = 1; // time + 0.01;
423 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
425 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
428 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
429 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
430 self.crylink_waitrelease = 2;
435 if (self.crylink_waitrelease)
437 // fired and released now!
438 if(self.crylink_lastgroup)
440 // Click and hold fire
441 if (time - self.crylink_lastgroup.crylink_waitrelease > 0.1)
443 //dprint("HoldFire:", ftos(time - self.crylink_lastgroup.crylink_waitrelease), "\nTimer is ", ftos(self.crylink_lastgroup.crylink_waitrelease),"\n");
444 W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
445 // 'splode @ join, if timing is just right, you get the target with the join-explode splash first, then the individual projectile's damage.
447 if(w_crylink_linkjoin_time > 0)
449 self.crylink_lastgroup.think = W_Crylink_Touch;
450 self.crylink_lastgroup.nextthink = w_crylink_linkjoin_time + time;
455 dprint("TapFire:", ftos(time - self.crylink_lastgroup.crylink_waitrelease), "\nTimer is ", ftos(self.crylink_lastgroup.crylink_waitrelease),"\n");
459 self.crylink_waitrelease = 0;
463 else if (req == WR_PRECACHE)
465 precache_model ("models/weapons/g_crylink.md3");
466 precache_model ("models/weapons/v_crylink.md3");
467 precache_model ("models/weapons/h_crylink.iqm");
468 precache_sound ("weapons/crylink_fire.wav");
469 precache_sound ("weapons/crylink_fire2.wav");
471 else if (req == WR_SETUP)
472 weapon_setup(WEP_CRYLINK);
473 else if (req == WR_CHECKAMMO1)
474 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
475 else if (req == WR_CHECKAMMO2)
476 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
481 float w_crylink(float req)
483 if(req == WR_IMPACTEFFECT)
486 org2 = w_org + w_backoff * 2;
487 if(w_deathtype & HITTYPE_SECONDARY)
489 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
491 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
495 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
497 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
500 else if(req == WR_PRECACHE)
502 precache_sound("weapons/crylink_impact2.wav");
503 precache_sound("weapons/crylink_impact.wav");
505 else if (req == WR_SUICIDEMESSAGE)
507 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
509 else if (req == WR_KILLMESSAGE)
511 if(w_deathtype & HITTYPE_BOUNCE)
512 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
513 else if(w_deathtype & HITTYPE_SPLASH)
514 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
516 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY