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