]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/w_crylink.qc
Begin moving per-weapon crosshair selection as weapon specific info
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_crylink.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id */ CRYLINK,
4 /* function */ W_Crylink,
5 /* ammotype */ ammo_cells,
6 /* impulse  */ 6,
7 /* flags    */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating   */ BOT_PICKUP_RATING_MID,
9 /* color        */ '1 0.5 1',
10 /* model    */ "crylink",
11 /* crosshair */ "gfx/crosshaircrylink",
12 /* netname  */ "crylink",
13 /* fullname */ _("Crylink")
14 );
15
16 #define CRYLINK_SETTINGS(w_cvar,w_prop) CRYLINK_SETTINGS_LIST(w_cvar, w_prop, CRYLINK, crylink)
17 #define CRYLINK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
18         w_cvar(id, sn, BOTH, ammo) \
19         w_cvar(id, sn, BOTH, animtime) \
20         w_cvar(id, sn, BOTH, damage) \
21         w_cvar(id, sn, BOTH, edgedamage) \
22         w_cvar(id, sn, BOTH, radius) \
23         w_cvar(id, sn, BOTH, force) \
24         w_cvar(id, sn, BOTH, spread) \
25         w_cvar(id, sn, BOTH, refire) \
26         w_cvar(id, sn, BOTH, speed) \
27         w_cvar(id, sn, BOTH, shots) \
28         w_cvar(id, sn, BOTH, bounces) \
29         w_cvar(id, sn, BOTH, bouncedamagefactor) \
30         w_cvar(id, sn, BOTH, middle_lifetime) \
31         w_cvar(id, sn, BOTH, middle_fadetime) \
32         w_cvar(id, sn, BOTH, other_lifetime) \
33         w_cvar(id, sn, BOTH, other_fadetime) \
34         w_cvar(id, sn, BOTH, linkexplode) \
35         w_cvar(id, sn, BOTH, joindelay) \
36         w_cvar(id, sn, BOTH, joinspread) \
37         w_cvar(id, sn, BOTH, joinexplode) \
38         w_cvar(id, sn, BOTH, joinexplode_damage) \
39         w_cvar(id, sn, BOTH, joinexplode_edgedamage) \
40         w_cvar(id, sn, BOTH, joinexplode_radius) \
41         w_cvar(id, sn, BOTH, joinexplode_force) \
42         w_cvar(id, sn, SEC,  spreadtype) \
43         w_cvar(id, sn, NONE, secondary) \
44         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
45         w_prop(id, sn, float,  reloading_time, reload_time) \
46         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
47         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
48         w_prop(id, sn, string, weaponreplace, weaponreplace) \
49         w_prop(id, sn, float,  weaponstart, weaponstart) \
50         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride)
51
52 #ifdef SVQC
53 CRYLINK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
54 .float gravity;
55 .float crylink_waitrelease;
56 .entity crylink_lastgroup;
57
58 .entity queuenext;
59 .entity queueprev;
60 #endif
61 #else
62 #ifdef SVQC
63 void spawnfunc_weapon_crylink() { weapon_defaultspawnfunc(WEP_CRYLINK); }
64
65 void W_Crylink_CheckLinks(entity e)
66 {
67         float i;
68         entity p;
69
70         if(e == world)
71                 error("W_Crylink_CheckLinks: entity is world");
72         if(e.classname != "spike" || wasfreed(e))
73                 error(sprintf("W_Crylink_CheckLinks: entity is not a spike but a %s (freed: %d)", e.classname, wasfreed(e)));
74
75         p = e;
76         for(i = 0; i < 1000; ++i)
77         {
78                 if(p.queuenext.queueprev != p || p.queueprev.queuenext != p)
79                         error("W_Crylink_CheckLinks: queue is inconsistent");
80                 p = p.queuenext;
81                 if(p == e)
82                         break;
83         }
84         if(i >= 1000)
85                 error("W_Crylink_CheckLinks: infinite chain");
86 }
87
88 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
89 {
90         W_Crylink_CheckLinks(next);
91         if(me == own.crylink_lastgroup)
92                 own.crylink_lastgroup = ((me == next) ? world : next);
93         prev.queuenext = next;
94         next.queueprev = prev;
95         me.classname = "spike_oktoremove";
96         if(me != next)
97                 W_Crylink_CheckLinks(next);
98 }
99
100 void W_Crylink_Dequeue(entity e)
101 {
102         W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
103 }
104
105 void W_Crylink_Reset(void)
106 {
107         W_Crylink_Dequeue(self);
108         remove(self);
109 }
110
111 // force projectile to explode
112 void W_Crylink_LinkExplode (entity e, entity e2)
113 {
114         float a;
115
116         if(e == e2)
117                 return;
118
119         a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
120
121         if(e == e.realowner.crylink_lastgroup)
122                 e.realowner.crylink_lastgroup = world;
123                 
124         float isprimary = !(e.projectiledeathtype & HITTYPE_SECONDARY);
125                 
126         RadiusDamage(e, e.realowner, WEP_CVAR_BOTH(crylink, isprimary, damage) * a, WEP_CVAR_BOTH(crylink, isprimary, edgedamage) * a, WEP_CVAR_BOTH(crylink, isprimary, radius), world, world, WEP_CVAR_BOTH(crylink, isprimary, force) * a, e.projectiledeathtype, other);
127
128         W_Crylink_LinkExplode(e.queuenext, e2);
129
130         e.classname = "spike_oktoremove";
131         remove (e);
132 }
133
134 // adjust towards center
135 // returns the origin where they will meet... and the time till the meeting is
136 // stored in w_crylink_linkjoin_time.
137 // could possibly network this origin and time, and display a special particle
138 // effect when projectiles meet there :P
139 // jspeed: joining speed (calculate this as join spread * initial speed)
140 float w_crylink_linkjoin_time;
141 vector W_Crylink_LinkJoin(entity e, float jspeed)
142 {
143         vector avg_origin, avg_velocity;
144         vector targ_origin;
145         float avg_dist, n;
146         entity p;
147
148         // FIXME remove this debug code
149         W_Crylink_CheckLinks(e);
150
151         w_crylink_linkjoin_time = 0;
152
153         avg_origin = e.origin;
154         avg_velocity = e.velocity;
155         n = 1;
156         for(p = e; (p = p.queuenext) != e; )
157         {
158                 avg_origin += WarpZone_RefSys_TransformOrigin(p, e, p.origin);
159                 avg_velocity += WarpZone_RefSys_TransformVelocity(p, e, p.velocity);
160                 ++n;
161         }
162         avg_origin *= (1.0 / n);
163         avg_velocity *= (1.0 / n);
164
165         if(n < 2)
166                 return avg_origin; // nothing to do
167
168         // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
169         avg_dist = pow(vlen(e.origin - avg_origin), 2);
170         for(p = e; (p = p.queuenext) != e; )
171                 avg_dist += pow(vlen(WarpZone_RefSys_TransformOrigin(p, e, p.origin) - avg_origin), 2);
172         avg_dist *= (1.0 / n);
173         avg_dist = sqrt(avg_dist);
174
175         if(avg_dist == 0)
176                 return avg_origin; // no change needed
177
178         if(jspeed == 0)
179         {
180                 e.velocity = avg_velocity;
181                 UpdateCSQCProjectile(e);
182                 for(p = e; (p = p.queuenext) != e; )
183                 {
184                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, avg_velocity);
185                         UpdateCSQCProjectile(p);
186                 }
187                 targ_origin = avg_origin + 1000000000 * normalize(avg_velocity); // HUUUUUUGE
188         }
189         else
190         {
191                 w_crylink_linkjoin_time = avg_dist / jspeed;
192                 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
193
194                 e.velocity = (targ_origin - e.origin) * (1.0 / w_crylink_linkjoin_time);
195                 UpdateCSQCProjectile(e);
196                 for(p = e; (p = p.queuenext) != e; )
197                 {
198                         p.velocity = WarpZone_RefSys_TransformVelocity(e, p, (targ_origin - WarpZone_RefSys_TransformOrigin(p, e, p.origin)) * (1.0 / w_crylink_linkjoin_time));
199                         UpdateCSQCProjectile(p);
200                 }
201
202                 // analysis:
203                 //   jspeed -> +infinity:
204                 //      w_crylink_linkjoin_time -> +0
205                 //      targ_origin -> avg_origin
206                 //      p->velocity -> HUEG towards center
207                 //   jspeed -> 0:
208                 //      w_crylink_linkjoin_time -> +/- infinity
209                 //      targ_origin -> avg_velocity * +/- infinity
210                 //      p->velocity -> avg_velocity
211                 //   jspeed -> -infinity:
212                 //      w_crylink_linkjoin_time -> -0
213                 //      targ_origin -> avg_origin
214                 //      p->velocity -> HUEG away from center
215         }
216
217         W_Crylink_CheckLinks(e);
218
219         return targ_origin;
220 }
221
222 void W_Crylink_LinkJoinEffect_Think()
223 {
224         // is there at least 2 projectiles very close?
225         entity e, p;
226         float n;
227         e = self.owner.crylink_lastgroup;
228         n = 0;
229         if(e)
230         {
231                 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
232                         ++n;
233                 for(p = e; (p = p.queuenext) != e; )
234                 {
235                         if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
236                                 ++n;
237                 }
238                 if(n >= 2)
239                 {
240                         float isprimary = !(e.projectiledeathtype & HITTYPE_SECONDARY);
241                         
242                         if(WEP_CVAR_BOTH(crylink, isprimary, joinexplode))
243                         {
244                                 n /= WEP_CVAR_BOTH(crylink, isprimary, shots);
245                                 RadiusDamage(
246                                         e,
247                                         e.realowner,
248                                         WEP_CVAR_BOTH(crylink, isprimary, joinexplode_damage) * n,
249                                         WEP_CVAR_BOTH(crylink, isprimary, joinexplode_edgedamage) * n,
250                                         WEP_CVAR_BOTH(crylink, isprimary, joinexplode_radius) * n,
251                                         e.realowner,
252                                         world,
253                                         WEP_CVAR_BOTH(crylink, isprimary, joinexplode_force) * n,
254                                         e.projectiledeathtype,
255                                         other
256                                 );
257                                 pointparticles(particleeffectnum("crylink_joinexplode"), self.origin, '0 0 0', n);
258                         }
259                 }
260         }
261         remove(self);
262 }
263
264 float W_Crylink_Touch_WouldHitFriendly(entity projectile, float rad)
265 {
266         entity head = WarpZone_FindRadius((projectile.origin + (projectile.mins + projectile.maxs) * 0.5), rad + MAX_DAMAGEEXTRARADIUS, FALSE);
267         float hit_friendly = 0;
268         float hit_enemy = 0;
269
270         while(head)
271         {
272                 if((head.takedamage != DAMAGE_NO) && (head.deadflag == DEAD_NO))
273                 {
274                         if(SAME_TEAM(head, projectile.realowner))
275                                 ++hit_friendly;
276                         else
277                                 ++hit_enemy;
278                 }
279                         
280                 head = head.chain;
281         }
282
283         return (hit_enemy ? FALSE : hit_friendly);
284 }
285
286 // NO bounce protection, as bounces are limited!
287 void W_Crylink_Touch (void)
288 {
289         float finalhit;
290         float f;
291         float isprimary = !(self.projectiledeathtype & HITTYPE_SECONDARY);
292         PROJECTILE_TOUCH;
293
294         float a;
295         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
296
297         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
298         if(finalhit)
299                 f = 1;
300         else
301                 f = WEP_CVAR_BOTH(crylink, isprimary, bouncedamagefactor);
302         if(a)
303                 f *= a;
304
305         float totaldamage = RadiusDamage(self, self.realowner, WEP_CVAR_BOTH(crylink, isprimary, damage) * f, WEP_CVAR_BOTH(crylink, isprimary, edgedamage) * f, WEP_CVAR_BOTH(crylink, isprimary, radius), world, world, WEP_CVAR_BOTH(crylink, isprimary, force) * f, self.projectiledeathtype, other);
306                 
307         if(totaldamage && ((WEP_CVAR_BOTH(crylink, isprimary, linkexplode) == 2) || ((WEP_CVAR_BOTH(crylink, isprimary, linkexplode) == 1) && !W_Crylink_Touch_WouldHitFriendly(self, WEP_CVAR_BOTH(crylink, isprimary, radius)))))
308         {
309                 if(self == self.realowner.crylink_lastgroup)
310                         self.realowner.crylink_lastgroup = world;
311                 W_Crylink_LinkExplode(self.queuenext, self);
312                 self.classname = "spike_oktoremove";
313                 remove (self);
314                 return;
315         }
316         else if(finalhit)
317         {
318                 // just unlink
319                 W_Crylink_Dequeue(self);
320                 remove(self);
321                 return;
322         }
323         self.cnt = self.cnt - 1;
324         self.angles = vectoangles(self.velocity);
325         self.owner = world;
326         self.projectiledeathtype |= HITTYPE_BOUNCE;
327         // commented out as it causes a little hitch...
328         //if(proj.cnt == 0)
329         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
330 }
331
332 void W_Crylink_Fadethink (void)
333 {
334         W_Crylink_Dequeue(self);
335         remove(self);
336 }
337
338 void W_Crylink_Attack (void)
339 {
340         float counter, shots;
341         entity proj, prevproj, firstproj;
342         vector s;
343         vector forward, right, up;
344         float maxdmg;
345
346         W_DecreaseAmmo(WEP_CVAR_PRI(crylink, ammo));
347
348         maxdmg = WEP_CVAR_PRI(crylink, damage) * WEP_CVAR_PRI(crylink, shots);
349         maxdmg *= 1 + WEP_CVAR_PRI(crylink, bouncedamagefactor) * WEP_CVAR_PRI(crylink, bounces);
350         if(WEP_CVAR_PRI(crylink, joinexplode))
351                 maxdmg += WEP_CVAR_PRI(crylink, joinexplode_damage);
352
353         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", CH_WEAPON_A, maxdmg);
354         forward = v_forward;
355         right = v_right;
356         up = v_up;
357
358         shots = WEP_CVAR_PRI(crylink, shots);
359         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
360         proj = prevproj = firstproj = world;
361         for(counter = 0; counter < shots; ++counter)
362         {
363                 proj = spawn ();
364                 proj.reset = W_Crylink_Reset;
365                 proj.realowner = proj.owner = self;
366                 proj.classname = "spike";
367                 proj.bot_dodge = TRUE;
368                 proj.bot_dodgerating = WEP_CVAR_PRI(crylink, damage);
369                 if(shots == 1) {
370                         proj.queuenext = proj;
371                         proj.queueprev = proj;
372                 }
373                 else if(counter == 0) { // first projectile, store in firstproj for now
374                         firstproj = proj;
375                 }
376                 else if(counter == shots - 1) { // last projectile, link up with first projectile
377                         prevproj.queuenext = proj;
378                         firstproj.queueprev = proj;
379                         proj.queuenext = firstproj;
380                         proj.queueprev = prevproj;
381                 }
382                 else { // else link up with previous projectile
383                         prevproj.queuenext = proj;
384                         proj.queueprev = prevproj;
385                 }
386
387                 prevproj = proj;
388
389                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
390                 PROJECTILE_MAKETRIGGER(proj);
391                 proj.projectiledeathtype = WEP_CRYLINK;
392                 //proj.gravity = 0.001;
393
394                 setorigin (proj, w_shotorg);
395                 setsize(proj, '0 0 0', '0 0 0');
396
397
398                 s = '0 0 0';
399                 if (counter == 0)
400                         s = '0 0 0';
401                 else
402                 {
403                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
404                         s_y = v_forward_x;
405                         s_z = v_forward_y;
406                 }
407                 s = s * WEP_CVAR_PRI(crylink, spread) * g_weaponspreadfactor;
408                 W_SetupProjVelocity_Explicit(proj, w_shotdir + right * s_y + up * s_z, v_up, WEP_CVAR_PRI(crylink, speed), 0, 0, 0, FALSE);
409                 proj.touch = W_Crylink_Touch;
410
411                 proj.think = W_Crylink_Fadethink;
412                 if(counter == 0)
413                 {
414                         proj.fade_time = time + WEP_CVAR_PRI(crylink, middle_lifetime);
415                         proj.fade_rate = 1 / WEP_CVAR_PRI(crylink, middle_fadetime);
416                         proj.nextthink = time + WEP_CVAR_PRI(crylink, middle_lifetime) + WEP_CVAR_PRI(crylink, middle_fadetime);
417                 }
418                 else
419                 {
420                         proj.fade_time = time + WEP_CVAR_PRI(crylink, other_lifetime);
421                         proj.fade_rate = 1 / WEP_CVAR_PRI(crylink, other_fadetime);
422                         proj.nextthink = time + WEP_CVAR_PRI(crylink, other_lifetime) + WEP_CVAR_PRI(crylink, other_fadetime);
423                 }
424                 proj.teleport_time = time + WEP_CVAR_PRI(crylink, joindelay);
425                 proj.cnt = WEP_CVAR_PRI(crylink, bounces);
426                 //proj.scale = 1 + 1 * proj.cnt;
427
428                 proj.angles = vectoangles (proj.velocity);
429
430                 //proj.glow_size = 20;
431
432                 proj.flags = FL_PROJECTILE;
433                 proj.missile_flags = MIF_SPLASH;
434     
435                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
436
437                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
438         }
439         if(WEP_CVAR_PRI(crylink, joinspread) != 0)
440         {
441                 self.crylink_lastgroup = proj;
442                 W_Crylink_CheckLinks(proj);
443                 self.crylink_waitrelease = 1;
444         }
445 }
446
447 void W_Crylink_Attack2 (void)
448 {
449         float counter, shots;
450         entity proj, prevproj, firstproj;
451         vector s;
452         vector forward, right, up;
453         float maxdmg;
454
455         W_DecreaseAmmo(WEP_CVAR_SEC(crylink, ammo));
456
457         maxdmg = WEP_CVAR_SEC(crylink, damage) * WEP_CVAR_SEC(crylink, shots);
458         maxdmg *= 1 + WEP_CVAR_SEC(crylink, bouncedamagefactor) * WEP_CVAR_SEC(crylink, bounces);
459         if(WEP_CVAR_SEC(crylink, joinexplode))
460                 maxdmg += WEP_CVAR_SEC(crylink, joinexplode_damage);
461
462         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", CH_WEAPON_A, maxdmg);
463         forward = v_forward;
464         right = v_right;
465         up = v_up;
466
467         shots = WEP_CVAR_SEC(crylink, shots);
468         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
469         proj = prevproj = firstproj = world;
470         for(counter = 0; counter < shots; ++counter)
471         {
472                 proj = spawn ();
473                 proj.reset = W_Crylink_Reset;
474                 proj.realowner = proj.owner = self;
475                 proj.classname = "spike";
476                 proj.bot_dodge = TRUE;
477                 proj.bot_dodgerating = WEP_CVAR_SEC(crylink, damage);
478                 if(shots == 1) {
479                         proj.queuenext = proj;
480                         proj.queueprev = proj;
481                 }
482                 else if(counter == 0) { // first projectile, store in firstproj for now
483                         firstproj = proj;
484                 }
485                 else if(counter == shots - 1) { // last projectile, link up with first projectile
486                         prevproj.queuenext = proj;
487                         firstproj.queueprev = proj;
488                         proj.queuenext = firstproj;
489                         proj.queueprev = prevproj;
490                 }
491                 else { // else link up with previous projectile
492                         prevproj.queuenext = proj;
493                         proj.queueprev = prevproj;
494                 }
495
496                 prevproj = proj;
497
498                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
499                 PROJECTILE_MAKETRIGGER(proj);
500                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
501                 //proj.gravity = 0.001;
502
503                 setorigin (proj, w_shotorg);
504                 setsize(proj, '0 0 0', '0 0 0');
505
506                 if(WEP_CVAR_SEC(crylink, spreadtype) == 1)
507                 {
508                         s = '0 0 0';
509                         if (counter == 0)
510                                 s = '0 0 0';
511                         else
512                         {
513                                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
514                                 s_y = v_forward_x;
515                                 s_z = v_forward_y;
516                         }
517                         s = s * WEP_CVAR_SEC(crylink, spread) * g_weaponspreadfactor;
518                         s = w_shotdir + right * s_y + up * s_z;
519                 }
520                 else
521                 {
522                         s = (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * WEP_CVAR_SEC(crylink, spread) * g_weaponspreadfactor);
523                 }
524
525                 W_SetupProjVelocity_Explicit(proj, s, v_up, WEP_CVAR_SEC(crylink, speed), 0, 0, 0, FALSE);
526                 proj.touch = W_Crylink_Touch;
527                 proj.think = W_Crylink_Fadethink;
528                 if(counter == (shots - 1) / 2)
529                 {
530                         proj.fade_time = time + WEP_CVAR_SEC(crylink, middle_lifetime);
531                         proj.fade_rate = 1 / WEP_CVAR_SEC(crylink, middle_fadetime);
532                         proj.nextthink = time + WEP_CVAR_SEC(crylink, middle_lifetime) + WEP_CVAR_SEC(crylink, middle_fadetime);
533                 }
534                 else
535                 {
536                         proj.fade_time = time + WEP_CVAR_SEC(crylink, other_lifetime);
537                         proj.fade_rate = 1 / WEP_CVAR_SEC(crylink, other_fadetime);
538                         proj.nextthink = time + WEP_CVAR_SEC(crylink, other_lifetime) + WEP_CVAR_SEC(crylink, other_fadetime);
539                 }
540                 proj.teleport_time = time + WEP_CVAR_SEC(crylink, joindelay);
541                 proj.cnt = WEP_CVAR_SEC(crylink, bounces);
542                 //proj.scale = 1 + 1 * proj.cnt;
543
544                 proj.angles = vectoangles (proj.velocity);
545
546                 //proj.glow_size = 20;
547
548                 proj.flags = FL_PROJECTILE;
549         proj.missile_flags = MIF_SPLASH;
550         
551                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
552
553                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
554         }
555         if(WEP_CVAR_SEC(crylink, joinspread) != 0)
556         {
557                 self.crylink_lastgroup = proj;
558                 W_Crylink_CheckLinks(proj);
559                 self.crylink_waitrelease = 2;
560         }
561 }
562
563 float W_Crylink(float req)
564 {
565         float ammo_amount;
566         switch(req)
567         {
568                 case WR_AIM:
569                 {
570                         if (random() < 0.10)
571                                 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(crylink, speed), 0, WEP_CVAR_PRI(crylink, middle_lifetime), FALSE);
572                         else
573                                 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(crylink, speed), 0, WEP_CVAR_SEC(crylink, middle_lifetime), FALSE);
574                                 
575                         return TRUE;
576                 }
577                 case WR_THINK:
578                 {
579                         if(autocvar_g_balance_crylink_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo))) // forced reload
580                                 WEP_ACTION(self.weapon, WR_RELOAD);
581
582                         if (self.BUTTON_ATCK)
583                         {
584                                 if (self.crylink_waitrelease != 1)
585                                 if (weapon_prepareattack(0, WEP_CVAR_PRI(crylink, refire)))
586                                 {
587                                         W_Crylink_Attack();
588                                         weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(crylink, animtime), w_ready);
589                                 }
590                         }
591
592                         if(self.BUTTON_ATCK2 && autocvar_g_balance_crylink_secondary)
593                         {
594                                 if (self.crylink_waitrelease != 2)
595                                 if (weapon_prepareattack(1, WEP_CVAR_SEC(crylink, refire)))
596                                 {
597                                         W_Crylink_Attack2();
598                                         weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(crylink, animtime), w_ready);
599                                 }
600                         }
601
602                         if ((self.crylink_waitrelease == 1 && !self.BUTTON_ATCK) || (self.crylink_waitrelease == 2 && !self.BUTTON_ATCK2))
603                         {
604                                 if (!self.crylink_lastgroup || time > self.crylink_lastgroup.teleport_time)
605                                 {
606                                         // fired and released now!
607                                         if(self.crylink_lastgroup)
608                                         {
609                                                 vector pos;
610                                                 entity linkjoineffect;
611                                                 float isprimary = (self.crylink_waitrelease == 1);
612                                                 
613                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, WEP_CVAR_BOTH(crylink, isprimary, joinspread) * WEP_CVAR_BOTH(crylink, isprimary, speed));
614
615                                                 linkjoineffect = spawn();
616                                                 linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
617                                                 linkjoineffect.classname = "linkjoineffect";
618                                                 linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
619                                                 linkjoineffect.owner = self;
620                                                 setorigin(linkjoineffect, pos);
621                                         }
622                                         self.crylink_waitrelease = 0;
623                                         if(!W_Crylink(WR_CHECKAMMO1) && !W_Crylink(WR_CHECKAMMO2))
624                                         if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
625                                         {
626                                                 // ran out of ammo!
627                                                 self.cnt = WEP_CRYLINK;
628                                                 self.switchweapon = w_getbestweapon(self);
629                                         }
630                                 }
631                         }
632                         
633                         return TRUE;
634                 }
635                 case WR_INIT:
636                 {
637                         precache_model ("models/weapons/g_crylink.md3");
638                         precache_model ("models/weapons/v_crylink.md3");
639                         precache_model ("models/weapons/h_crylink.iqm");
640                         precache_sound ("weapons/crylink_fire.wav");
641                         precache_sound ("weapons/crylink_fire2.wav");
642                         precache_sound ("weapons/crylink_linkjoin.wav");
643                         CRYLINK_SETTINGS(WEP_SKIPCVAR, WEP_SET_PROP)
644                         return TRUE;
645                 }
646                 case WR_CHECKAMMO1:
647                 {
648                         // don't "run out of ammo" and switch weapons while waiting for release
649                         if(self.crylink_lastgroup && self.crylink_waitrelease)
650                                 return TRUE;
651
652                         ammo_amount = self.WEP_AMMO(CRYLINK) >= WEP_CVAR_PRI(crylink, ammo);
653                         ammo_amount += self.(weapon_load[WEP_CRYLINK]) >= WEP_CVAR_PRI(crylink, ammo);
654                         return ammo_amount;
655                 }
656                 case WR_CHECKAMMO2:
657                 {
658                         // don't "run out of ammo" and switch weapons while waiting for release
659                         if(self.crylink_lastgroup && self.crylink_waitrelease)
660                                 return TRUE;
661
662                         ammo_amount = self.WEP_AMMO(CRYLINK) >= WEP_CVAR_SEC(crylink, ammo);
663                         ammo_amount += self.(weapon_load[WEP_CRYLINK]) >= WEP_CVAR_SEC(crylink, ammo);
664                         return ammo_amount;
665                 }
666                 case WR_CONFIG:
667                 {
668                         CRYLINK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
669                         return TRUE;
670                 }
671                 case WR_RELOAD:
672                 {
673                         W_Reload(min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo)), "weapons/reload.wav");
674                         return TRUE;
675                 }
676                 case WR_SUICIDEMESSAGE:
677                 {
678                         return WEAPON_CRYLINK_SUICIDE;
679                 }
680                 case WR_KILLMESSAGE:
681                 {
682                         return WEAPON_CRYLINK_MURDER;
683                 }
684         }
685         return TRUE;
686 }
687 #endif
688 #ifdef CSQC
689 float W_Crylink(float req)
690 {
691         switch(req)
692         {
693                 case WR_IMPACTEFFECT:
694                 {
695                         vector org2;
696                         org2 = w_org + w_backoff * 2;
697                         if(w_deathtype & HITTYPE_SECONDARY)
698                         {
699                                 pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
700                                 if(!w_issilent)
701                                         sound(self, CH_SHOTS, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
702                         }
703                         else
704                         {
705                                 pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
706                                 if(!w_issilent)
707                                         sound(self, CH_SHOTS, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
708                         }
709                         
710                         return TRUE;
711                 }
712                 case WR_INIT:
713                 {
714                         precache_sound("weapons/crylink_impact2.wav");
715                         precache_sound("weapons/crylink_impact.wav");
716                         return TRUE;
717                 }
718                 case WR_ZOOMRETICLE:
719                 {
720                         // no weapon specific image for this weapon
721                         return FALSE;
722                 }
723         }
724         return TRUE;
725 }
726 #endif
727 #endif