]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_crylink.qc
ae3600de755bf6cfd296b9bf3f20f54406999630
[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 // NO bounce protection, as bounces are limited!
219 void W_Crylink_Touch (void)
220 {
221         float finalhit;
222         float f;
223         PROJECTILE_TOUCH;
224
225         float a;
226         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
227
228         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
229         if(finalhit)
230                 f = 1;
231         else
232                 f = autocvar_g_balance_crylink_primary_bouncedamagefactor;
233         if(a)
234                 f *= a;
235         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)
236         {
237                 if(self == self.realowner.crylink_lastgroup)
238                         self.realowner.crylink_lastgroup = world;
239                 W_Crylink_LinkExplode(self.queuenext, self);
240                 self.classname = "spike_oktoremove";
241                 remove (self);
242                 return;
243         }
244         else if(finalhit)
245         {
246                 // just unlink
247                 W_Crylink_Dequeue(self);
248                 remove(self);
249                 return;
250         }
251         self.cnt = self.cnt - 1;
252         self.angles = vectoangles(self.velocity);
253         self.owner = world;
254         self.projectiledeathtype |= HITTYPE_BOUNCE;
255         // commented out as it causes a little hitch...
256         //if(proj.cnt == 0)
257         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
258 }
259
260 void W_Crylink_Touch2 (void)
261 {
262         float finalhit;
263         float f;
264         PROJECTILE_TOUCH;
265
266         float a;
267         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
268
269         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
270         if(finalhit)
271                 f = 1;
272         else
273                 f = autocvar_g_balance_crylink_secondary_bouncedamagefactor;
274         if(a)
275                 f *= a;
276         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)
277         {
278                 if(self == self.realowner.crylink_lastgroup)
279                         self.realowner.crylink_lastgroup = world;
280                 W_Crylink_LinkExplode(self.queuenext, self);
281                 self.classname = "spike_oktoremove";
282                 remove (self);
283                 return;
284         }
285         else if(finalhit)
286         {
287                 // just unlink
288                 W_Crylink_Dequeue(self);
289                 remove(self);
290                 return;
291         }
292         self.cnt = self.cnt - 1;
293         self.angles = vectoangles(self.velocity);
294         self.owner = world;
295         self.projectiledeathtype |= HITTYPE_BOUNCE;
296         // commented out as it causes a little hitch...
297         //if(proj.cnt == 0)
298         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
299 }
300
301 void W_Crylink_Fadethink (void)
302 {
303         W_Crylink_Dequeue(self);
304         remove(self);
305 }
306
307 void W_Crylink_Attack (void)
308 {
309         local float counter, shots;
310         local entity proj, prevproj, firstproj;
311         local vector s;
312         vector forward, right, up;
313         float maxdmg;
314
315         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_reload_ammo);
316
317         maxdmg = autocvar_g_balance_crylink_primary_damage*autocvar_g_balance_crylink_primary_shots;
318         maxdmg *= 1 + autocvar_g_balance_crylink_primary_bouncedamagefactor * autocvar_g_balance_crylink_primary_bounces;
319         if(autocvar_g_balance_crylink_primary_joinexplode)
320                 maxdmg += autocvar_g_balance_crylink_primary_joinexplode_damage;
321
322         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CH_WEAPON_A, maxdmg);
323         forward = v_forward;
324         right = v_right;
325         up = v_up;
326
327         shots = autocvar_g_balance_crylink_primary_shots;
328         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
329         proj = world;
330         while (counter < shots)
331         {
332                 proj = spawn ();
333                 proj.realowner = proj.owner = self;
334                 proj.classname = "spike";
335                 proj.bot_dodge = TRUE;
336                 proj.bot_dodgerating = autocvar_g_balance_crylink_primary_damage;
337                 if(shots == 1) {
338                         proj.queuenext = proj;
339                         proj.queueprev = proj;
340                 }
341                 else if(counter == 0) { // first projectile, store in firstproj for now
342                         firstproj = proj;
343                 }
344                 else if(counter == shots - 1) { // last projectile, link up with first projectile
345                         prevproj.queuenext = proj;
346                         firstproj.queueprev = proj;
347                         proj.queuenext = firstproj;
348                         proj.queueprev = prevproj;
349                 }
350                 else { // else link up with previous projectile
351                         prevproj.queuenext = proj;
352                         proj.queueprev = prevproj;
353                 }
354
355                 prevproj = proj;
356
357                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
358                 PROJECTILE_MAKETRIGGER(proj);
359                 proj.projectiledeathtype = WEP_CRYLINK;
360                 //proj.gravity = 0.001;
361
362                 setorigin (proj, w_shotorg);
363                 setsize(proj, '0 0 0', '0 0 0');
364
365
366                 s = '0 0 0';
367                 if (counter == 0)
368                         s = '0 0 0';
369                 else
370                 {
371                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
372                         s_y = v_forward_x;
373                         s_z = v_forward_y;
374                 }
375                 s = s * autocvar_g_balance_crylink_primary_spread * g_weaponspreadfactor;
376                 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, autocvar_g_balance_crylink_primary_speed, 0, 0, 0, FALSE);
377                 proj.touch = W_Crylink_Touch;
378
379                 proj.think = W_Crylink_Fadethink;
380                 if(counter == 0)
381                 {
382                         proj.fade_time = time + autocvar_g_balance_crylink_primary_middle_lifetime;
383                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_middle_fadetime;
384                         proj.nextthink = time + autocvar_g_balance_crylink_primary_middle_lifetime + autocvar_g_balance_crylink_primary_middle_fadetime;
385                 }
386                 else
387                 {
388                         proj.fade_time = time + autocvar_g_balance_crylink_primary_other_lifetime;
389                         proj.fade_rate = 1 / autocvar_g_balance_crylink_primary_other_fadetime;
390                         proj.nextthink = time + autocvar_g_balance_crylink_primary_other_lifetime + autocvar_g_balance_crylink_primary_other_fadetime;
391                 }
392                 proj.teleport_time = time + autocvar_g_balance_crylink_primary_joindelay;
393                 proj.cnt = autocvar_g_balance_crylink_primary_bounces;
394                 //proj.scale = 1 + 1 * proj.cnt;
395
396                 proj.angles = vectoangles (proj.velocity);
397
398                 //proj.glow_size = 20;
399
400                 proj.flags = FL_PROJECTILE;
401
402                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
403
404                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
405
406                 counter = counter + 1;
407         }
408         if(autocvar_g_balance_crylink_primary_joinspread != 0 || autocvar_g_balance_crylink_primary_jointime != 0)
409         {
410                 self.crylink_lastgroup = proj;
411                 W_Crylink_CheckLinks(proj);
412                 self.crylink_waitrelease = 1;
413         }
414 }
415
416 void W_Crylink_Attack2 (void)
417 {
418         local float counter, shots;
419         local entity proj, prevproj, firstproj;
420         float maxdmg;
421
422         W_DecreaseAmmo(ammo_cells, autocvar_g_balance_crylink_secondary_ammo, autocvar_g_balance_crylink_reload_ammo);
423
424         maxdmg = autocvar_g_balance_crylink_secondary_damage*autocvar_g_balance_crylink_secondary_shots;
425         maxdmg *= 1 + autocvar_g_balance_crylink_secondary_bouncedamagefactor * autocvar_g_balance_crylink_secondary_bounces;
426         if(autocvar_g_balance_crylink_secondary_joinexplode)
427                 maxdmg += autocvar_g_balance_crylink_secondary_joinexplode_damage;
428
429         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CH_WEAPON_A, maxdmg);
430
431         shots = autocvar_g_balance_crylink_secondary_shots;
432         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
433         proj = world;
434         while (counter < shots)
435         {
436                 proj = spawn ();
437                 proj.realowner = proj.owner = self;
438                 proj.classname = "spike";
439                 proj.bot_dodge = TRUE;
440                 proj.bot_dodgerating = autocvar_g_balance_crylink_secondary_damage;
441                 if(shots == 1) {
442                         proj.queuenext = proj;
443                         proj.queueprev = proj;
444                 }
445                 else if(counter == 0) { // first projectile, store in firstproj for now
446                         firstproj = proj;
447                 }
448                 else if(counter == shots - 1) { // last projectile, link up with first projectile
449                         prevproj.queuenext = proj;
450                         firstproj.queueprev = proj;
451                         proj.queuenext = firstproj;
452                         proj.queueprev = prevproj;
453                 }
454                 else { // else link up with previous projectile
455                         prevproj.queuenext = proj;
456                         proj.queueprev = prevproj;
457                 }
458
459                 prevproj = proj;
460
461                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
462                 PROJECTILE_MAKETRIGGER(proj);
463                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
464                 //proj.gravity = 0.001;
465
466                 setorigin (proj, w_shotorg);
467                 setsize(proj, '0 0 0', '0 0 0');
468
469                 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);
470                 proj.touch = W_Crylink_Touch2;
471                 proj.think = W_Crylink_Fadethink;
472                 if(counter == (shots - 1) / 2)
473                 {
474                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_middle_lifetime;
475                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_middle_fadetime;
476                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_middle_lifetime + autocvar_g_balance_crylink_secondary_middle_fadetime;
477                 }
478                 else
479                 {
480                         proj.fade_time = time + autocvar_g_balance_crylink_secondary_line_lifetime;
481                         proj.fade_rate = 1 / autocvar_g_balance_crylink_secondary_line_fadetime;
482                         proj.nextthink = time + autocvar_g_balance_crylink_secondary_line_lifetime + autocvar_g_balance_crylink_secondary_line_fadetime;
483                 }
484                 proj.teleport_time = time + autocvar_g_balance_crylink_secondary_joindelay;
485                 proj.cnt = autocvar_g_balance_crylink_secondary_bounces;
486                 //proj.scale = 1 + 1 * proj.cnt;
487
488                 proj.angles = vectoangles (proj.velocity);
489
490                 //proj.glow_size = 20;
491
492                 proj.flags = FL_PROJECTILE;
493
494                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
495
496                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
497
498                 counter = counter + 1;
499         }
500         if(autocvar_g_balance_crylink_secondary_joinspread != 0 || autocvar_g_balance_crylink_secondary_jointime != 0)
501         {
502                 self.crylink_lastgroup = proj;
503                 W_Crylink_CheckLinks(proj);
504                 self.crylink_waitrelease = 2;
505         }
506 }
507
508 void spawnfunc_weapon_crylink (void)
509 {
510         weapon_defaultspawnfunc(WEP_CRYLINK);
511 }
512
513 float w_crylink(float req)
514 {
515         float ammo_amount;
516         if (req == WR_AIM)
517         {
518                 if (random() < 0.10)
519                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_crylink_primary_speed, 0, autocvar_g_balance_crylink_primary_middle_lifetime, FALSE);
520                 else
521                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_crylink_secondary_speed, 0, autocvar_g_balance_crylink_secondary_middle_lifetime, FALSE);
522         }
523         else if (req == WR_THINK)
524         {
525                 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
526                         weapon_action(self.weapon, WR_RELOAD);
527
528                 if (self.BUTTON_ATCK)
529                 {
530                         if (self.crylink_waitrelease != 1)
531                         if (weapon_prepareattack(0, autocvar_g_balance_crylink_primary_refire))
532                         {
533                                 W_Crylink_Attack();
534                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_crylink_primary_animtime, w_ready);
535                         }
536                 }
537
538                 if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
539                 {
540                         if (self.crylink_waitrelease != 2)
541                         if (weapon_prepareattack(1, autocvar_g_balance_crylink_secondary_refire))
542                         {
543                                 W_Crylink_Attack2();
544                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_crylink_secondary_animtime, w_ready);
545                         }
546                 }
547
548                 if ((self.crylink_waitrelease == 1 && !self.BUTTON_ATCK) || (self.crylink_waitrelease == 2 && !self.BUTTON_ATCK2))
549                 {
550                         if (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time)
551                         {
552                                 // fired and released now!
553                                 if(self.crylink_lastgroup)
554                                 {
555                                         vector pos;
556                                         entity linkjoineffect;
557
558                                         if(self.crylink_waitrelease == 1)
559                                         {
560                                                 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);
561
562                                         }
563                                         else
564                                         {
565                                                 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);
566                                         }
567
568                                         linkjoineffect = spawn();
569                                         linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
570                                         linkjoineffect.classname = "linkjoineffect";
571                                         linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
572                                         linkjoineffect.owner = self;
573                                         setorigin(linkjoineffect, pos);
574                                 }
575                                 self.crylink_waitrelease = 0;
576                                 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
577                                 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
578                                 {
579                                         // ran out of ammo!
580                                         self.cnt = WEP_CRYLINK;
581                                         self.switchweapon = w_getbestweapon(self);
582                                 }
583                         }
584                 }
585         }
586         else if (req == WR_PRECACHE)
587         {
588                 precache_model ("models/weapons/g_crylink.md3");
589                 precache_model ("models/weapons/v_crylink.md3");
590                 precache_model ("models/weapons/h_crylink.iqm");
591                 precache_sound ("weapons/crylink_fire.wav");
592                 precache_sound ("weapons/crylink_fire2.wav");
593                 precache_sound ("weapons/crylink_linkjoin.wav");
594                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
595         }
596         else if (req == WR_SETUP)
597         {
598                 weapon_setup(WEP_CRYLINK);
599                 self.current_ammo = ammo_cells;
600         }
601         else if (req == WR_CHECKAMMO1)
602         {
603                 // don't "run out of ammo" and switch weapons while waiting for release
604                 if(self.crylink_lastgroup && self.crylink_waitrelease)
605                         return TRUE;
606
607                 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_primary_ammo;
608                 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_primary_ammo;
609                 return ammo_amount;
610         }
611         else if (req == WR_CHECKAMMO2)
612         {
613                 // don't "run out of ammo" and switch weapons while waiting for release
614                 if(self.crylink_lastgroup && self.crylink_waitrelease)
615                         return TRUE;
616
617                 ammo_amount = self.ammo_cells >= autocvar_g_balance_crylink_secondary_ammo;
618                 ammo_amount += self.weapon_load[WEP_CRYLINK] >= autocvar_g_balance_crylink_secondary_ammo;
619                 return ammo_amount;
620         }
621         else if (req == WR_RELOAD)
622         {
623                 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");
624         }
625         return TRUE;
626 };
627 #endif
628 #ifdef CSQC
629 float w_crylink(float req)
630 {
631         if(req == WR_IMPACTEFFECT)
632         {
633                 vector org2;
634                 org2 = w_org + w_backoff * 2;
635                 if(w_deathtype & HITTYPE_SECONDARY)
636                 {
637                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
638                         if(!w_issilent)
639                                 sound(self, CH_SHOTS, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
640                 }
641                 else
642                 {
643                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
644                         if(!w_issilent)
645                                 sound(self, CH_SHOTS, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
646                 }
647         }
648         else if(req == WR_PRECACHE)
649         {
650                 precache_sound("weapons/crylink_impact2.wav");
651                 precache_sound("weapons/crylink_impact.wav");
652         }
653         else if (req == WR_SUICIDEMESSAGE)
654         {
655                 w_deathtypestring = _("%s succeeded at self-destructing themself with the Crylink");
656         }
657         else if (req == WR_KILLMESSAGE)
658         {
659                 if(w_deathtype & HITTYPE_BOUNCE)
660                         w_deathtypestring = _("%s could not hide from %s's Crylink"); // unchecked: SPLASH (SECONDARY can't be)
661                 else if(w_deathtype & HITTYPE_SPLASH)
662                         w_deathtypestring = _("%s was too close to %s's Crylink"); // unchecked: SECONDARY
663                 else
664                         w_deathtypestring = _("%s took a close look at %s's Crylink"); // unchecked: SECONDARY
665         }
666         return TRUE;
667 }
668 #endif
669 #endif