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