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