]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_crylink.qc
crylink: properly calculate maxdmg
[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_Dequeue_Raw(entity own, entity prev, entity me, entity next)
13 {
14         if(me == own.crylink_lastgroup)
15                 own.crylink_lastgroup = ((me == next) ? world : next);
16         prev.queuenext = next;
17         next.queueprev = prev;
18 }
19
20 void W_Crylink_Dequeue(entity e)
21 {
22         W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
23 }
24
25 // force projectile to explode
26 void W_Crylink_LinkExplode (entity e, entity e2)
27 {
28         float a;
29         a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
30
31         if(e == e.realowner.crylink_lastgroup)
32                 e.realowner.crylink_lastgroup = world;
33
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);
35
36         if(e.queuenext != e2)
37                 W_Crylink_LinkExplode(e.queuenext, e2);
38
39         remove (e);
40 }
41
42 void W_Crylink_CheckLinks(entity e)
43 {
44         float i;
45         entity p;
46
47         if(e == world)
48                 error("W_Crylink_CheckLinks: entity is world");
49
50         p = e;
51         for(i = 0; i < 1000; ++i)
52         {
53                 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
54                         error("W_Crylink_CheckLinks: queue is inconsistent");
55                 p = p.queuenext;
56                 if(p == e)
57                         break;
58         }
59         if(i >= 1000)
60                 error("W_Crylink_CheckLinks: infinite chain");
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(cvar("g_balance_crylink_secondary_joinexplode"))
178                                 {
179                                         n = n / cvar("g_balance_crylink_secondary_shots");
180                                         RadiusDamage (e, e.realowner, cvar("g_balance_crylink_secondary_joinexplode_damage") * n, 
181                                                                         cvar("g_balance_crylink_secondary_joinexplode_edgedamage") * n, 
182                                                                         cvar("g_balance_crylink_secondary_joinexplode_radius") * n, e.realowner, 
183                                                                         cvar("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(cvar("g_balance_crylink_primary_joinexplode"))
191                                 {
192                                         n = n / cvar("g_balance_crylink_primary_shots");
193                                         RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_joinexplode_damage") * n, 
194                                                                         cvar("g_balance_crylink_primary_joinexplode_edgedamage") * n, 
195                                                                         cvar("g_balance_crylink_primary_joinexplode_radius") * n, e.realowner, 
196                                                                         cvar("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 = cvar("g_balance_crylink_primary_bouncedamagefactor");
232         if(a)
233                 f *= a;
234         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"))
235         {
236                 W_Crylink_LinkExplode(self.queuenext, self);
237                 remove (self);
238                 return;
239         }
240         else if(finalhit)
241         {
242                 // just unlink
243                 W_Crylink_Dequeue(self);
244                 remove(self);
245                 return;
246         }
247         self.cnt = self.cnt - 1;
248         self.angles = vectoangles(self.velocity);
249         self.owner = world;
250         self.projectiledeathtype |= HITTYPE_BOUNCE;
251         // commented out as it causes a little hitch...
252         //if(proj.cnt == 0)
253         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
254 }
255
256 void W_Crylink_Touch2 (void)
257 {
258         float finalhit;
259         float f;
260         //PROJECTILE_TOUCH;
261         local entity savenext, saveprev, saveown;
262         savenext = self.queuenext;
263         saveprev = self.queueprev;
264         saveown = self.realowner;
265         if(WarpZone_Projectile_Touch())
266         {
267                 if(wasfreed(self))
268                         W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
269                 return;
270         }
271
272         float a;
273         a = 1 - (time - self.fade_time) * self.fade_rate;
274
275         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
276         if(finalhit)
277                 f = 1;
278         else
279                 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
280         if(a)
281                 f *= a;
282         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"))
283         {
284                 W_Crylink_LinkExplode(self.queuenext, self);
285                 remove (self);
286                 return;
287         }
288         else if(finalhit)
289         {
290                 // just unlink
291                 W_Crylink_Dequeue(self);
292                 remove(self);
293                 return;
294         }
295         self.cnt = self.cnt - 1;
296         self.angles = vectoangles(self.velocity);
297         self.owner = world;
298         self.projectiledeathtype |= HITTYPE_BOUNCE;
299         // commented out as it causes a little hitch...
300         //if(proj.cnt == 0)
301         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
302 }
303
304 void W_Crylink_Fadethink (void)
305 {
306         W_Crylink_Dequeue(self);
307         remove(self);
308 }
309
310 void W_Crylink_Attack (void)
311 {
312         local float counter, shots;
313         local entity proj, prevproj, firstproj;
314         local vector s;
315         vector forward, right, up;
316         float maxdmg;
317
318         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
319                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
320
321         maxdmg = cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots");
322         maxdmg *= 1 + cvar("g_balance_crylink_primary_bouncedamagefactor") * cvar("g_balance_crylink_primary_bounces");
323         if(cvar("g_balance_crylink_primary_joinexplode"))
324                 maxdmg += cvar("g_balance_crylink_primary_joinexplode_damage");
325
326         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", maxdmg);
327         forward = v_forward;
328         right = v_right;
329         up = v_up;
330
331         shots = cvar("g_balance_crylink_primary_shots");
332         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
333         proj = world;
334         while (counter < shots)
335         {
336                 proj = spawn ();
337                 proj.realowner = proj.owner = self;
338                 proj.classname = "spike";
339                 proj.bot_dodge = TRUE;
340                 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
341                 if(shots == 1) {
342                         proj.queuenext = proj;
343                         proj.queueprev = proj;
344                 }
345                 else if(counter == 0) { // first projectile, store in firstproj for now
346                         firstproj = proj;
347                 }
348                 else if(counter == shots - 1) { // last projectile, link up with first projectile
349                         prevproj.queuenext = proj;
350                         firstproj.queueprev = proj;
351                         proj.queuenext = firstproj;
352                         proj.queueprev = prevproj;
353                 }
354                 else { // else link up with previous projectile
355                         prevproj.queuenext = proj;
356                         proj.queueprev = prevproj;
357                 }
358
359                 prevproj = proj;
360
361                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
362                 PROJECTILE_MAKETRIGGER(proj);
363                 proj.projectiledeathtype = WEP_CRYLINK;
364                 //proj.gravity = 0.001;
365
366                 setorigin (proj, w_shotorg);
367                 setsize(proj, '0 0 0', '0 0 0');
368
369
370                 s = '0 0 0';
371                 if (counter == 0)
372                         s = '0 0 0';
373                 else
374                 {
375                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
376                         s_y = v_forward_x;
377                         s_z = v_forward_y;
378                 }
379                 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
380                 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0, FALSE);
381                 proj.touch = W_Crylink_Touch;
382
383                 proj.think = W_Crylink_Fadethink;
384                 if(counter == 0)
385                 {
386                         proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
387                         proj.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
388                         proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
389                 }
390                 else
391                 {
392                         proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
393                         proj.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
394                         proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
395                 }
396                 proj.cnt = cvar("g_balance_crylink_primary_bounces");
397                 //proj.scale = 1 + 1 * proj.cnt;
398
399                 proj.angles = vectoangles (proj.velocity);
400
401                 //proj.glow_size = 20;
402
403                 proj.flags = FL_PROJECTILE;
404
405                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
406
407                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
408
409                 counter = counter + 1;
410         }
411         self.crylink_lastgroup = proj;
412 }
413
414 void W_Crylink_Attack2 (void)
415 {
416         local float counter, shots;
417         local entity proj, prevproj, firstproj;
418         float maxdmg;
419
420         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
421                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
422
423         maxdmg = cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots");
424         maxdmg *= 1 + cvar("g_balance_crylink_secondary_bouncedamagefactor") * cvar("g_balance_crylink_secondary_bounces");
425         if(cvar("g_balance_crylink_secondary_joinexplode"))
426                 maxdmg += cvar("g_balance_crylink_secondary_joinexplode_damage");
427
428         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", maxdmg);
429
430         shots = cvar("g_balance_crylink_secondary_shots");
431         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
432         proj = world;
433         while (counter < shots)
434         {
435                 proj = spawn ();
436                 proj.realowner = proj.owner = self;
437                 proj.classname = "spike";
438                 proj.bot_dodge = TRUE;
439                 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
440                 if(shots == 1) {
441                         proj.queuenext = proj;
442                         proj.queueprev = proj;
443                 }
444                 else if(counter == 0) { // first projectile, store in firstproj for now
445                         firstproj = proj;
446                 }
447                 else if(counter == shots - 1) { // last projectile, link up with first projectile
448                         prevproj.queuenext = proj;
449                         firstproj.queueprev = proj;
450                         proj.queuenext = firstproj;
451                         proj.queueprev = prevproj;
452                 }
453                 else { // else link up with previous projectile
454                         prevproj.queuenext = proj;
455                         proj.queueprev = prevproj;
456                 }
457
458                 prevproj = proj;
459
460                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
461                 PROJECTILE_MAKETRIGGER(proj);
462                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
463                 //proj.gravity = 0.001;
464
465                 setorigin (proj, w_shotorg);
466                 setsize(proj, '0 0 0', '0 0 0');
467
468                 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, FALSE);
469                 proj.touch = W_Crylink_Touch2;
470                 proj.think = W_Crylink_Fadethink;
471                 if(counter == (shots - 1) / 2)
472                 {
473                         proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
474                         proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
475                         proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
476                 }
477                 else
478                 {
479                         proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
480                         proj.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
481                         proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
482                 }
483                 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
484                 //proj.scale = 1 + 1 * proj.cnt;
485
486                 proj.angles = vectoangles (proj.velocity);
487
488                 //proj.glow_size = 20;
489
490                 proj.flags = FL_PROJECTILE;
491
492                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
493
494                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
495
496                 counter = counter + 1;
497         }
498         self.crylink_lastgroup = proj;
499 }
500
501 void spawnfunc_weapon_crylink (void)
502 {
503         weapon_defaultspawnfunc(WEP_CRYLINK);
504 }
505
506 float w_crylink(float req)
507 {
508         if (req == WR_AIM)
509         {
510                 if (random() > 0.15)
511                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
512                 else
513                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
514         }
515         else if (req == WR_THINK)
516         {
517                 if (self.BUTTON_ATCK)
518                 {
519                         if (!self.crylink_waitrelease)
520                         if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
521                         {
522                                 W_Crylink_Attack();
523                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
524                                 if(cvar("g_balance_crylink_primary_joinspread") != 0 || cvar("g_balance_crylink_primary_jointime") != 0)
525                                         self.crylink_waitrelease = 1;
526                         }
527                 }
528                 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
529                 {
530                         if (!self.crylink_waitrelease)
531                         if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
532                         {
533                                 W_Crylink_Attack2();
534                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
535                                 if(cvar("g_balance_crylink_secondary_joinspread") != 0 || cvar("g_balance_crylink_secondary_jointime") != 0)
536                                         self.crylink_waitrelease = 2;
537                         }
538                 }
539                 else
540                 {
541                         if (self.crylink_waitrelease)
542                         {
543                                 // fired and released now!
544                                 if(self.crylink_lastgroup)
545                                 {
546                                         vector pos;
547                                         entity linkjoineffect;
548                                         
549                                         
550                                         if(self.crylink_waitrelease == 1)
551                                         {
552                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspread") * cvar("g_balance_crylink_primary_speed"), cvar("g_balance_crylink_primary_jointime"));
553                                                 
554                                         }
555                                         else
556                                         {
557                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspread") * cvar("g_balance_crylink_secondary_speed"), cvar("g_balance_crylink_secondary_jointime"));
558                                         }
559                                         
560                                         linkjoineffect = spawn();
561                                         linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
562                                         linkjoineffect.classname = "linkjoineffect";                                    
563                                         linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
564                                         linkjoineffect.owner = self;
565                                         setorigin(linkjoineffect, pos);
566
567
568                                 }
569                                 self.crylink_waitrelease = 0;
570                                 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
571                                 {
572                                         // ran out of ammo!
573                                         self.cnt = WEP_CRYLINK;
574                                         self.switchweapon = w_getbestweapon(self);
575                                 }
576                         }
577                 }
578         }
579         else if (req == WR_PRECACHE)
580         {
581                 precache_model ("models/weapons/g_crylink.md3");
582                 precache_model ("models/weapons/v_crylink.md3");
583                 precache_model ("models/weapons/h_crylink.iqm");
584                 precache_sound ("weapons/crylink_fire.wav");
585                 precache_sound ("weapons/crylink_fire2.wav");
586                 precache_sound ("weapons/crylink_linkjoin.wav");
587         }
588         else if (req == WR_SETUP)
589                 weapon_setup(WEP_CRYLINK);
590         else if (req == WR_CHECKAMMO1)
591         {
592                 // don't "run out of ammo" and switch weapons while waiting for release
593                 if(self.crylink_lastgroup && self.crylink_waitrelease)
594                         return TRUE;
595                 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
596         }
597         else if (req == WR_CHECKAMMO2)
598         {
599                 // don't "run out of ammo" and switch weapons while waiting for release
600                 if(self.crylink_lastgroup && self.crylink_waitrelease)
601                         return TRUE;
602                 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
603         }
604         return TRUE;
605 };
606 #endif
607 #ifdef CSQC
608 float w_crylink(float req)
609 {
610         if(req == WR_IMPACTEFFECT)
611         {
612                 vector org2;
613                 org2 = w_org + w_backoff * 2;
614                 if(w_deathtype & HITTYPE_SECONDARY)
615                 {
616                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
617                         if(!w_issilent)
618                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
619                 }
620                 else
621                 {
622                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
623                         if(!w_issilent)
624                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
625                 }
626         }
627         else if(req == WR_PRECACHE)
628         {
629                 precache_sound("weapons/crylink_impact2.wav");
630                 precache_sound("weapons/crylink_impact.wav");
631         }
632         else if (req == WR_SUICIDEMESSAGE)
633         {
634                 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
635         }
636         else if (req == WR_KILLMESSAGE)
637         {
638                 if(w_deathtype & HITTYPE_BOUNCE)
639                         w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
640                 else if(w_deathtype & HITTYPE_SPLASH)
641                         w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
642                 else
643                         w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY
644         }
645         return TRUE;
646 }
647 #endif
648 #endif