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