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