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