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.realowner = proj.owner = self;
235 proj.classname = "spike";
236 proj.bot_dodge = TRUE;
237 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
238 if(counter == 0) { // first projectile, store in firstproj for now
241 else if(counter == shots - 1) { // last projectile, link up with first projectile
242 prevproj.queuenext = proj;
243 firstproj.queueprev = proj;
244 proj.queuenext = firstproj;
245 proj.queueprev = prevproj;
247 else { // else link up with previous projectile
248 prevproj.queuenext = proj;
249 proj.queueprev = prevproj;
254 proj.movetype = MOVETYPE_BOUNCEMISSILE;
255 PROJECTILE_MAKETRIGGER(proj);
256 proj.projectiledeathtype = WEP_CRYLINK;
257 //proj.gravity = 0.001;
259 setorigin (proj, w_shotorg);
260 setsize(proj, '0 0 0', '0 0 0');
268 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
272 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
273 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
274 proj.touch = W_Crylink_Touch;
276 proj.think = W_Crylink_Fadethink;
279 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
280 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
281 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
283 else if(counter <= 3)
285 proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
286 self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
287 proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
291 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
292 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
293 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
295 proj.cnt = cvar("g_balance_crylink_primary_bounces");
297 //proj.scale = 1 + 1 * proj.cnt;
298 //proj.angles = vectoangles (proj.velocity); // csqc
299 //proj.glow_size = 20;
301 proj.flags = FL_PROJECTILE;
303 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
305 other = proj; MUTATOR_CALLHOOK(EditProjectile);
307 counter = counter + 1;
309 self.crylink_lastgroup = proj;
312 void W_Crylink_Attack2 (void)
314 local float counter, shots;
315 local entity proj, prevproj, firstproj;
317 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
318 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
320 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
322 shots = cvar("g_balance_crylink_secondary_shots");
323 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
325 while (counter < shots)
328 proj.realowner = proj.owner = self;
329 proj.classname = "spike";
330 proj.bot_dodge = TRUE;
331 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
332 if(counter == 0) { // first projectile, store in firstproj for now
335 else if(counter == shots - 1) { // last projectile, link up with first projectile
336 prevproj.queuenext = proj;
337 firstproj.queueprev = proj;
338 proj.queuenext = firstproj;
339 proj.queueprev = prevproj;
341 else { // else link up with previous projectile
342 prevproj.queuenext = proj;
343 proj.queueprev = prevproj;
348 proj.movetype = MOVETYPE_BOUNCEMISSILE;
349 PROJECTILE_MAKETRIGGER(proj);
350 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
351 //proj.gravity = 0.001;
353 setorigin (proj, w_shotorg);
354 setsize(proj, '0 0 0', '0 0 0');
356 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);
357 proj.touch = W_Crylink_Touch2;
358 proj.think = W_Crylink_Fadethink;
359 if(counter == (shots - 1) / 2)
361 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
362 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
363 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
367 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
368 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
369 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
371 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
372 //proj.scale = 1 + 1 * proj.cnt;
374 // proj.angles = vectoangles (proj.velocity); // csqc
376 //proj.glow_size = 20;
378 proj.flags = FL_PROJECTILE;
380 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
382 other = proj; MUTATOR_CALLHOOK(EditProjectile);
384 counter = counter + 1;
386 self.crylink_lastgroup = proj;
389 void spawnfunc_weapon_crylink (void)
391 weapon_defaultspawnfunc(WEP_CRYLINK);
394 float w_crylink(float req)
399 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
401 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
403 else if (req == WR_THINK)
405 if (self.BUTTON_ATCK)
407 if (!self.crylink_waitrelease)
408 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
411 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
412 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
413 self.crylink_waitrelease = 1;
416 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
418 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
421 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
422 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
423 self.crylink_waitrelease = 2;
428 if (self.crylink_waitrelease)
430 // fired and released now!
431 if(self.crylink_lastgroup)
433 if(self.crylink_waitrelease == 1)
435 W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
437 // 'splode @ join, if timing is just right, you get the target with the join-explode splash first, then the individual projectile's damage.
438 self.crylink_lastgroup.think = W_Crylink_Touch;
439 self.crylink_lastgroup.nextthink = w_crylink_linkjoin_time + time;
444 W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
449 self.crylink_waitrelease = 0;
452 else if (req == WR_PRECACHE)
454 precache_model ("models/weapons/g_crylink.md3");
455 precache_model ("models/weapons/v_crylink.md3");
456 precache_model ("models/weapons/h_crylink.iqm");
457 precache_sound ("weapons/crylink_fire.wav");
458 precache_sound ("weapons/crylink_fire2.wav");
460 else if (req == WR_SETUP)
461 weapon_setup(WEP_CRYLINK);
462 else if (req == WR_CHECKAMMO1)
463 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
464 else if (req == WR_CHECKAMMO2)
465 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
470 float w_crylink(float req)
472 if(req == WR_IMPACTEFFECT)
475 org2 = w_org + w_backoff * 2;
476 if(w_deathtype & HITTYPE_SECONDARY)
478 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
480 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
484 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
486 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
489 else if(req == WR_PRECACHE)
491 precache_sound("weapons/crylink_impact2.wav");
492 precache_sound("weapons/crylink_impact.wav");
494 else if (req == WR_SUICIDEMESSAGE)
496 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
498 else if (req == WR_KILLMESSAGE)
500 if(w_deathtype & HITTYPE_BOUNCE)
501 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
502 else if(w_deathtype & HITTYPE_SPLASH)
503 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
505 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY