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);
72 avg_dist = sqrt(avg_dist);
74 w_crylink_linkjoin_time = 0;
76 return avg_origin; // no change needed
80 e.velocity = avg_velocity;
81 UpdateCSQCProjectile(e);
82 for(p = e; (p = p.queuenext) != e; )
84 p.velocity = avg_velocity;
85 UpdateCSQCProjectile(p);
90 w_crylink_linkjoin_time = avg_dist / joinspeed;
91 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
93 e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
94 UpdateCSQCProjectile(e);
95 for(p = e; (p = p.queuenext) != e; )
97 p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
98 UpdateCSQCProjectile(p);
102 // joinspeed -> +infinity:
103 // w_crylink_linkjoin_time -> +0
104 // targ_origin -> avg_origin
105 // p->velocity -> HUEG towards center
107 // w_crylink_linkjoin_time -> +/- infinity
108 // targ_origin -> avg_velocity * +/- infinity
109 // p->velocity -> avg_velocity
110 // joinspeed -> -infinity:
111 // w_crylink_linkjoin_time -> -0
112 // targ_origin -> avg_origin
113 // p->velocity -> HUEG away from center
119 // NO bounce protection, as bounces are limited!
120 void W_Crylink_Touch (void)
125 local entity savenext, saveprev, saveown;
126 saveown = self.realowner;
127 savenext = self.queuenext;
128 saveprev = self.queueprev;
129 if(WarpZone_Projectile_Touch())
132 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
137 a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
139 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
143 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
146 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)
148 W_Crylink_LinkExplode(self.queuenext, self);
152 self.cnt = self.cnt - 1;
153 self.angles = vectoangles(self.velocity);
155 self.projectiledeathtype |= HITTYPE_BOUNCE;
156 // commented out as it causes a little hitch...
158 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
161 void W_Crylink_Touch2 (void)
166 local entity savenext, saveprev, saveown;
167 savenext = self.queuenext;
168 saveprev = self.queueprev;
169 saveown = self.realowner;
170 if(WarpZone_Projectile_Touch())
173 W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
178 a = 1 - (time - self.fade_time) * self.fade_rate;
180 finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
184 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
187 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))
189 W_Crylink_LinkExplode(self.queuenext, self);
196 W_Crylink_Dequeue(self);
200 self.cnt = self.cnt - 1;
201 self.angles = vectoangles(self.velocity);
203 self.projectiledeathtype |= HITTYPE_BOUNCE;
204 // commented out as it causes a little hitch...
206 // CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
209 void W_Crylink_Fadethink (void)
211 W_Crylink_Dequeue(self);
215 void W_Crylink_Attack (void)
217 local float counter, shots;
218 local entity proj, prevproj, firstproj;
220 vector forward, right, up;
222 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
223 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
225 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
230 shots = cvar("g_balance_crylink_primary_shots");
231 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
233 while (counter < shots)
236 proj.realowner = proj.owner = self;
237 proj.classname = "spike";
238 proj.bot_dodge = TRUE;
239 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
240 if(counter == 0) { // first projectile, store in firstproj for now
243 else if(counter == shots - 1) { // last projectile, link up with first projectile
244 prevproj.queuenext = proj;
245 firstproj.queueprev = proj;
246 proj.queuenext = firstproj;
247 proj.queueprev = prevproj;
249 else { // else link up with previous projectile
250 prevproj.queuenext = proj;
251 proj.queueprev = prevproj;
256 proj.movetype = MOVETYPE_BOUNCEMISSILE;
257 PROJECTILE_MAKETRIGGER(proj);
258 proj.projectiledeathtype = WEP_CRYLINK;
259 //proj.gravity = 0.001;
261 setorigin (proj, w_shotorg);
262 setsize(proj, '0 0 0', '0 0 0');
270 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
274 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
275 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
276 proj.touch = W_Crylink_Touch;
278 proj.think = W_Crylink_Fadethink;
281 proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
282 self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
283 proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
285 else if(counter <= 3)
287 proj.fade_time = time + cvar("g_balance_crylink_primary_star_lifetime");
288 self.fade_rate = 1 / cvar("g_balance_crylink_primary_star_fadetime");
289 proj.nextthink = time + cvar("g_balance_crylink_primary_star_lifetime") + cvar("g_balance_crylink_primary_star_fadetime");
293 proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
294 self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
295 proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
297 proj.cnt = cvar("g_balance_crylink_primary_bounces");
298 //proj.scale = 1 + 1 * proj.cnt;
300 proj.angles = vectoangles (proj.velocity);
302 //proj.glow_size = 20;
304 proj.flags = FL_PROJECTILE;
306 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
308 other = proj; MUTATOR_CALLHOOK(EditProjectile);
310 counter = counter + 1;
312 self.crylink_lastgroup = proj;
315 void W_Crylink_Attack2 (void)
317 local float counter, shots;
318 local entity proj, prevproj, firstproj;
320 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
321 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
323 W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
325 shots = cvar("g_balance_crylink_secondary_shots");
326 pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
328 while (counter < shots)
331 proj.realowner = proj.owner = self;
332 proj.classname = "spike";
333 proj.bot_dodge = TRUE;
334 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
335 if(counter == 0) { // first projectile, store in firstproj for now
338 else if(counter == shots - 1) { // last projectile, link up with first projectile
339 prevproj.queuenext = proj;
340 firstproj.queueprev = proj;
341 proj.queuenext = firstproj;
342 proj.queueprev = prevproj;
344 else { // else link up with previous projectile
345 prevproj.queuenext = proj;
346 proj.queueprev = prevproj;
351 proj.movetype = MOVETYPE_BOUNCEMISSILE;
352 PROJECTILE_MAKETRIGGER(proj);
353 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
354 //proj.gravity = 0.001;
356 setorigin (proj, w_shotorg);
357 setsize(proj, '0 0 0', '0 0 0');
359 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);
360 proj.touch = W_Crylink_Touch2;
361 proj.think = W_Crylink_Fadethink;
362 if(counter == (shots - 1) / 2)
364 proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
365 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
366 proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
370 proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
371 self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
372 proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
374 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
375 //proj.scale = 1 + 1 * proj.cnt;
377 proj.angles = vectoangles (proj.velocity);
379 //proj.glow_size = 20;
381 proj.flags = FL_PROJECTILE;
383 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
385 other = proj; MUTATOR_CALLHOOK(EditProjectile);
387 counter = counter + 1;
389 self.crylink_lastgroup = proj;
392 void spawnfunc_weapon_crylink (void)
394 weapon_defaultspawnfunc(WEP_CRYLINK);
397 float w_crylink(float req)
402 self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
404 self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
406 else if (req == WR_THINK)
408 if (self.BUTTON_ATCK)
410 if (!self.crylink_waitrelease)
411 if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
414 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
415 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
416 self.crylink_waitrelease = 1;
419 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
421 if (!self.crylink_waitrelease)
422 if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
425 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
426 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
427 self.crylink_waitrelease = 2;
432 if (self.crylink_waitrelease)
434 // fired and released now!
435 if(self.crylink_lastgroup)
437 if(self.crylink_waitrelease == 1)
439 W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
443 W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
447 self.crylink_waitrelease = 0;
450 else if (req == WR_PRECACHE)
452 precache_model ("models/weapons/g_crylink.md3");
453 precache_model ("models/weapons/v_crylink.md3");
454 precache_model ("models/weapons/h_crylink.iqm");
455 precache_sound ("weapons/crylink_fire.wav");
456 precache_sound ("weapons/crylink_fire2.wav");
458 else if (req == WR_SETUP)
459 weapon_setup(WEP_CRYLINK);
460 else if (req == WR_CHECKAMMO1)
461 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
462 else if (req == WR_CHECKAMMO2)
463 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
468 float w_crylink(float req)
470 if(req == WR_IMPACTEFFECT)
473 org2 = w_org + w_backoff * 2;
474 if(w_deathtype & HITTYPE_SECONDARY)
476 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
478 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
482 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
484 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
487 else if(req == WR_PRECACHE)
489 precache_sound("weapons/crylink_impact2.wav");
490 precache_sound("weapons/crylink_impact.wav");
492 else if (req == WR_SUICIDEMESSAGE)
494 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
496 else if (req == WR_KILLMESSAGE)
498 if(w_deathtype & HITTYPE_BOUNCE)
499 w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
500 else if(w_deathtype & HITTYPE_SPLASH)
501 w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
503 w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY