]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_crylink.qc
Favoured secondary attack over primary
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_crylink.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(CRYLINK, w_crylink, IT_CELLS, 6, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "crylink", "crylink", "Crylink");
3 #else
4 #ifdef SVQC
5 .float gravity;
6 .float crylink_waitrelease;
7 .entity crylink_lastgroup;
8
9 .entity queuenext;
10 .entity queueprev;
11
12 void W_Crylink_CheckLinks(entity e)
13 {
14         float i;
15         entity p;
16
17         if(e == world)
18                 error("W_Crylink_CheckLinks: entity is world");
19
20         p = e;
21         for(i = 0; i < 1000; ++i)
22         {
23                 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
24                         error("W_Crylink_CheckLinks: queue is inconsistent");
25                 p = p.queuenext;
26                 if(p == e)
27                         break;
28         }
29         if(i >= 1000)
30                 error("W_Crylink_CheckLinks: infinite chain");
31 }
32
33 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
34 {
35         if(me == own.crylink_lastgroup)
36                 own.crylink_lastgroup = ((me == next) ? world : next);
37         prev.queuenext = next;
38         next.queueprev = prev;
39 }
40
41 void W_Crylink_Dequeue(entity e)
42 {
43         W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
44 }
45
46 // force projectile to explode
47 void W_Crylink_LinkExplode (entity e, entity e2)
48 {
49         float a;
50         a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
51
52         if(e == e.realowner.crylink_lastgroup)
53                 e.realowner.crylink_lastgroup = world;
54
55         RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_damage * a, autocvar_g_balance_crylink_primary_edgedamage * a, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * a, e.projectiledeathtype, other);
56
57         if(e.queuenext != e2)
58                 W_Crylink_LinkExplode(e.queuenext, e2);
59
60         remove (e);
61 }
62
63 // adjust towards center
64 // returns the origin where they will meet... and the time till the meeting is
65 // stored in w_crylink_linkjoin_time.
66 // could possibly network this origin and time, and display a special particle
67 // effect when projectiles meet there :P
68 // jspeed: MINIMUM jing speed
69 // jtime: MAXIMUM jing time (0: none)
70 float w_crylink_linkjoin_time;
71 vector W_Crylink_LinkJoin(entity e, float jspeed, float jtime)
72 {
73         vector avg_origin, avg_velocity;
74         vector targ_origin;
75         float avg_dist, n;
76         entity p;
77
78         // FIXME remove this debug code
79         W_Crylink_CheckLinks(e);
80
81         w_crylink_linkjoin_time = 0;
82
83         avg_origin = e.origin;
84         avg_velocity = e.velocity;
85         n = 1;
86         for(p = e; (p = p.queuenext) != e; )
87         {
88                 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
89                 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
90                 ++n;
91         }
92         avg_origin *= (1.0 / n);
93         avg_velocity *= (1.0 / n);
94
95         if(n < 2)
96                 return avg_origin; // nothing to do
97
98         // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
99         avg_dist = pow(vlen(e.origin - avg_origin), 2);
100         for(p = e; (p = p.queuenext) != e; )
101                 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
102         avg_dist *= (1.0 / n);
103         avg_dist = sqrt(avg_dist);
104
105         if(avg_dist == 0)
106                 return avg_origin; // no change needed
107
108         if(jspeed == 0 && jtime == 0)
109         {
110                 e.velocity = avg_velocity;
111                 UpdateCSQCProjectile(e);
112                 for(p = e; (p = p.queuenext) != e; )
113                 {
114                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
115                         UpdateCSQCProjectile(p);
116                 }
117         }
118         else
119         {
120                 if(jtime)
121                 {
122                         if(jspeed)
123                                 w_crylink_linkjoin_time = min(jtime, avg_dist / jspeed);
124                         else
125                                 w_crylink_linkjoin_time = jtime;
126                 }
127                 else
128                         w_crylink_linkjoin_time = avg_dist / jspeed;
129                 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
130
131                 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
132                 UpdateCSQCProjectile(e);
133                 for(p = e; (p = p.queuenext) != e; )
134                 {
135                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
136                         UpdateCSQCProjectile(p);
137                 }
138
139                 // analysis:
140                 //   jspeed -> +infinity:
141                 //      w_crylink_linkjoin_time -> +0
142                 //      targ_origin -> avg_origin
143                 //      p->velocity -> HUEG towards center
144                 //   jspeed -> 0:
145                 //      w_crylink_linkjoin_time -> +/- infinity
146                 //      targ_origin -> avg_velocity * +/- infinity
147                 //      p->velocity -> avg_velocity
148                 //   jspeed -> -infinity:
149                 //      w_crylink_linkjoin_time -> -0
150                 //      targ_origin -> avg_origin
151                 //      p->velocity -> HUEG away from center
152         }
153
154         return targ_origin;
155 }
156
157 void W_Crylink_LinkJoinEffect_Think()
158 {
159         // is there at least 2 projectiles very close?
160         entity e, p;
161         float n;
162         e = self.owner.crylink_lastgroup;
163         n = 0;
164         if(e)
165         {
166                 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
167                         ++n;
168                 for(p = e; (p = p.queuenext) != e; )
169                 {
170                         if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
171                                 ++n;
172                 }
173                 if(n >= 2)
174                 {
175                         if(e.projectiledeathtype & HITTYPE_SECONDARY)
176                         {
177                                 if(autocvar_g_balance_crylink_secondary_joinexplode)
178                                 {
179                                         n = n / autocvar_g_balance_crylink_secondary_shots;
180                                         RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_secondary_joinexplode_damage * n,
181                                                                         autocvar_g_balance_crylink_secondary_joinexplode_edgedamage * n,
182                                                                         autocvar_g_balance_crylink_secondary_joinexplode_radius * n, e.realowner,
183                                                                         autocvar_g_balance_crylink_secondary_joinexplode_force * n, e.projectiledeathtype, other);
184
185                                         pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
186                                 }
187                         }
188                         else
189                         {
190                                 if(autocvar_g_balance_crylink_primary_joinexplode)
191                                 {
192                                         n = n / autocvar_g_balance_crylink_primary_shots;
193                                         RadiusDamage (e, e.realowner, autocvar_g_balance_crylink_primary_joinexplode_damage * n,
194                                                                         autocvar_g_balance_crylink_primary_joinexplode_edgedamage * n,
195                                                                         autocvar_g_balance_crylink_primary_joinexplode_radius * n, e.realowner,
196                                                                         autocvar_g_balance_crylink_primary_joinexplode_force * n, e.projectiledeathtype, other);
197
198                                         pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
199                                 }
200                         }
201                 }
202         }
203         remove(self);
204 }
205
206
207 // NO bounce protection, as bounces are limited!
208 void W_Crylink_Touch (void)
209 {
210         float finalhit;
211         float f;
212         //PROJECTILE_TOUCH;
213         local entity savenext, saveprev, saveown;
214         saveown = self.realowner;
215         savenext = self.queuenext;
216         saveprev = self.queueprev;
217         if(WarpZone_Projectile_Touch())
218         {
219                 if(wasfreed(self))
220                         W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
221                 return;
222         }
223
224         float a;
225         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
226
227         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
228         if(finalhit)
229                 f = 1;
230         else
231                 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
232         if(a)
233                 f *= a;
234         if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_primary_damage * f, autocvar_g_balance_crylink_primary_edgedamage * f, autocvar_g_balance_crylink_primary_radius, world, autocvar_g_balance_crylink_primary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_primary_linkexplode)
235         {
236                 if(self == self.realowner.crylink_lastgroup)
237                         self.realowner.crylink_lastgroup = world;
238                 W_Crylink_LinkExplode(self.queuenext, self);
239                 remove (self);
240                 return;
241         }
242         else if(finalhit)
243         {
244                 // just unlink
245                 W_Crylink_Dequeue(self);
246                 remove(self);
247                 return;
248         }
249         self.cnt = self.cnt - 1;
250         self.angles = vectoangles(self.velocity);
251         self.owner = world;
252         self.projectiledeathtype |= HITTYPE_BOUNCE;
253         // commented out as it causes a little hitch...
254         //if(proj.cnt == 0)
255         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
256 }
257
258 void W_Crylink_Touch2 (void)
259 {
260         float finalhit;
261         float f;
262         //PROJECTILE_TOUCH;
263         local entity savenext, saveprev, saveown;
264         savenext = self.queuenext;
265         saveprev = self.queueprev;
266         saveown = self.realowner;
267         if(WarpZone_Projectile_Touch())
268         {
269                 if(wasfreed(self))
270                         W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
271                 return;
272         }
273
274         float a;
275         a = 1 - (time - self.fade_time) * self.fade_rate;
276
277         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
278         if(finalhit)
279                 f = 1;
280         else
281                 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
282         if(a)
283                 f *= a;
284         if (RadiusDamage (self, self.realowner, autocvar_g_balance_crylink_secondary_damage * f, autocvar_g_balance_crylink_secondary_edgedamage * f, autocvar_g_balance_crylink_secondary_radius, world, autocvar_g_balance_crylink_secondary_force * f, self.projectiledeathtype, other) && autocvar_g_balance_crylink_secondary_linkexplode)
285         {
286                 if(self == self.realowner.crylink_lastgroup)
287                         self.realowner.crylink_lastgroup = world;
288                 W_Crylink_LinkExplode(self.queuenext, self);
289                 remove (self);
290                 return;
291         }
292         else if(finalhit)
293         {
294                 // just unlink
295                 W_Crylink_Dequeue(self);
296                 remove(self);
297                 return;
298         }
299         self.cnt = self.cnt - 1;
300         self.angles = vectoangles(self.velocity);
301         self.owner = world;
302         self.projectiledeathtype |= HITTYPE_BOUNCE;
303         // commented out as it causes a little hitch...
304         //if(proj.cnt == 0)
305         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
306 }
307
308 void W_Crylink_Fadethink (void)
309 {
310         W_Crylink_Dequeue(self);
311         remove(self);
312 }
313
314 void W_Crylink_Attack (void)
315 {
316         local float counter, shots;
317         local entity proj, prevproj, firstproj;
318         local vector s;
319         vector forward, right, up;
320         float maxdmg;
321
322         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
323                 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_primary_ammo;
324
325         maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
326         maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
327         if(autocvar_g_balance_crylink_primary_joinexplode)
328                 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
329
330         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CHAN_WEAPON, maxdmg);
331         forward = v_forward;
332         right = v_right;
333         up = v_up;
334
335         shots = autocvar_g_balance_crylink_primary_shots;
336         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
337         proj = world;
338         while (counter < shots)
339         {
340                 proj = spawn ();
341                 proj.realowner = proj.owner = self;
342                 proj.classname = "spike";
343                 proj.bot_dodge = TRUE;
344                 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
345                 if(shots == 1) {
346                         proj.queuenext = proj;
347                         proj.queueprev = proj;
348                 }
349                 else if(counter == 0) { // first projectile, store in firstproj for now
350                         firstproj = proj;
351                 }
352                 else if(counter == shots - 1) { // last projectile, link up with first projectile
353                         prevproj.queuenext = proj;
354                         firstproj.queueprev = proj;
355                         proj.queuenext = firstproj;
356                         proj.queueprev = prevproj;
357                 }
358                 else { // else link up with previous projectile
359                         prevproj.queuenext = proj;
360                         proj.queueprev = prevproj;
361                 }
362
363                 prevproj = proj;
364
365                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
366                 PROJECTILE_MAKETRIGGER(proj);
367                 proj.projectiledeathtype = WEP_CRYLINK;
368                 //proj.gravity = 0.001;
369
370                 setorigin (proj, w_shotorg);
371                 setsize(proj, '0 0 0', '0 0 0');
372
373
374                 s = '0 0 0';
375                 if (counter == 0)
376                         s = '0 0 0';
377                 else
378                 {
379                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
380                         s_y = v_forward_x;
381                         s_z = v_forward_y;
382                 }
383                 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
384                 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
385                 proj.touch = W_Crylink_Touch;
386
387                 proj.think = W_Crylink_Fadethink;
388                 if(counter == 0)
389                 {
390                         proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
391                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
392                         proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
393                 }
394                 else
395                 {
396                         proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
397                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
398                         proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
399                 }
400                 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
401                 //proj.scale = 1 + 1 * proj.cnt;
402
403                 proj.angles = vectoangles (proj.velocity);
404
405                 //proj.glow_size = 20;
406
407                 proj.flags = FL_PROJECTILE;
408
409                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
410
411                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
412
413                 counter = counter + 1;
414         }
415         self.crylink_lastgroup = proj;
416 }
417
418 void W_Crylink_Attack2 (void)
419 {
420         local float counter, shots;
421         local entity proj, prevproj, firstproj;
422         float maxdmg;
423
424         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
425                 self.ammo_cells = self.ammo_cells - autocvar_g_balance_crylink_secondary_ammo;
426
427         maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
428         maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
429         if(autocvar_g_balance_crylink_secondary_joinexplode)
430                 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
431
432         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CHAN_WEAPON, maxdmg);
433
434         shots = autocvar_g_balance_crylink_secondary_shots;
435         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
436         proj = world;
437         while (counter < shots)
438         {
439                 proj = spawn ();
440                 proj.realowner = proj.owner = self;
441                 proj.classname = "spike";
442                 proj.bot_dodge = TRUE;
443                 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
444                 if(shots == 1) {
445                         proj.queuenext = proj;
446                         proj.queueprev = proj;
447                 }
448                 else if(counter == 0) { // first projectile, store in firstproj for now
449                         firstproj = proj;
450                 }
451                 else if(counter == shots - 1) { // last projectile, link up with first projectile
452                         prevproj.queuenext = proj;
453                         firstproj.queueprev = proj;
454                         proj.queuenext = firstproj;
455                         proj.queueprev = prevproj;
456                 }
457                 else { // else link up with previous projectile
458                         prevproj.queuenext = proj;
459                         proj.queueprev = prevproj;
460                 }
461
462                 prevproj = proj;
463
464                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
465                 PROJECTILE_MAKETRIGGER(proj);
466                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
467                 //proj.gravity = 0.001;
468
469                 setorigin (proj, w_shotorg);
470                 setsize(proj, '0 0 0', '0 0 0');
471
472                 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * autocvar_g_balance_crylink_secondary_spread * g_weaponspreadfactor), v_up, autocvar_g_balance_crylink_secondary_speed, 0, 0, 0, FALSE);
473                 proj.touch = W_Crylink_Touch2;
474                 proj.think = W_Crylink_Fadethink;
475                 if(counter == (shots - 1) / 2)
476                 {
477                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
478                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
479                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
480                 }
481                 else
482                 {
483                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
484                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
485                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
486                 }
487                 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
488                 //proj.scale = 1 + 1 * proj.cnt;
489
490                 proj.angles = vectoangles (proj.velocity);
491
492                 //proj.glow_size = 20;
493
494                 proj.flags = FL_PROJECTILE;
495
496                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
497
498                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
499
500                 counter = counter + 1;
501         }
502         self.crylink_lastgroup = proj;
503 }
504
505 void spawnfunc_weapon_crylink (void)
506 {
507         weapon_defaultspawnfunc(WEP_CRYLINK);
508 }
509
510 float w_crylink(float req)
511 {
512         if (req == WR_AIM)
513         {
514                 if (random() < 0.10)
515                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
516                 else
517                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
518         }
519         else if (req == WR_THINK)
520         {
521                 if (self.BUTTON_ATCK)
522                 {
523                         if (!self.crylink_waitrelease)
524                         if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
525                         {
526                                 W_Crylink_Attack();
527                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
528                                 if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
529                                         self.crylink_waitrelease = 1;
530                         }
531                 }
532                 else if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
533                 {
534                         if (!self.crylink_waitrelease)
535                         if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
536                         {
537                                 W_Crylink_Attack2();
538                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
539                                 if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
540                                         self.crylink_waitrelease = 2;
541                         }
542                 }
543                 else
544                 {
545                         if (self.crylink_waitrelease)
546                         {
547                                 // fired and released now!
548                                 if(self.crylink_lastgroup)
549                                 {
550                                         vector pos;
551                                         entity linkjoineffect;
552
553
554                                         if(self.crylink_waitrelease == 1)
555                                         {
556                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_primary_joinspread * autocvar_g_balance_crylink_primary_speed, autocvar_g_balance_crylink_primary_jointime);
557
558                                         }
559                                         else
560                                         {
561                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, autocvar_g_balance_crylink_secondary_joinspread * autocvar_g_balance_crylink_secondary_speed, autocvar_g_balance_crylink_secondary_jointime);
562                                         }
563
564                                         linkjoineffect = spawn();
565                                         linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
566                                         linkjoineffect.classname = "linkjoineffect";
567                                         linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
568                                         linkjoineffect.owner = self;
569                                         setorigin(linkjoineffect, pos);
570
571
572                                 }
573                                 self.crylink_waitrelease = 0;
574                                 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
575                                 {
576                                         // ran out of ammo!
577                                         self.cnt = WEP_CRYLINK;
578                                         self.switchweapon = w_getbestweapon(self);
579                                 }
580                         }
581                 }
582         }
583         else if (req == WR_PRECACHE)
584         {
585                 precache_model ("models/weapons/g_crylink.md3");
586                 precache_model ("models/weapons/v_crylink.md3");
587                 precache_model ("models/weapons/h_crylink.iqm");
588                 precache_sound ("weapons/crylink_fire.wav");
589                 precache_sound ("weapons/crylink_fire2.wav");
590                 precache_sound ("weapons/crylink_linkjoin.wav");
591         }
592         else if (req == WR_SETUP)
593                 weapon_setup(WEP_CRYLINK);
594         else if (req == WR_CHECKAMMO1)
595         {
596                 // don't "run out of ammo" and switch weapons while waiting for release
597                 if(self.crylink_lastgroup && self.crylink_waitrelease)
598                         return TRUE;
599                 return self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
600         }
601         else if (req == WR_CHECKAMMO2)
602         {
603                 // don't "run out of ammo" and switch weapons while waiting for release
604                 if(self.crylink_lastgroup && self.crylink_waitrelease)
605                         return TRUE;
606                 return self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
607         }
608         return TRUE;
609 };
610 #endif
611 #ifdef CSQC
612 float w_crylink(float req)
613 {
614         if(req == WR_IMPACTEFFECT)
615         {
616                 vector org2;
617                 org2 = w_org + w_backoff * 2;
618                 if(w_deathtype & HITTYPE_SECONDARY)
619                 {
620                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
621                         if(!w_issilent)
622                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
623                 }
624                 else
625                 {
626                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
627                         if(!w_issilent)
628                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
629                 }
630         }
631         else if(req == WR_PRECACHE)
632         {
633                 precache_sound("weapons/crylink_impact2.wav");
634                 precache_sound("weapons/crylink_impact.wav");
635         }
636         else if (req == WR_SUICIDEMESSAGE)
637         {
638                 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
639         }
640         else if (req == WR_KILLMESSAGE)
641         {
642                 if(w_deathtype & HITTYPE_BOUNCE)
643                         w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
644                 else if(w_deathtype & HITTYPE_SPLASH)
645                         w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
646                 else
647                         w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY
648         }
649         return TRUE;
650 }
651 #endif
652 #endif