]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_crylink.qc
crylink counter works different for some time now, the _star_lifetime cvars are obsol...
[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 void W_Crylink_Dequeue_Raw(entity own, entity prev, entity me, entity next)
13 {
14         if(me == own.crylink_lastgroup)
15                 own.crylink_lastgroup = ((me == next) ? world : next);
16         prev.queuenext = next;
17         next.queueprev = prev;
18 }
19
20 void W_Crylink_Dequeue(entity e)
21 {
22         W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
23 }
24
25 // force projectile to explode
26 void W_Crylink_LinkExplode (entity e, entity e2)
27 {
28         float a;
29         a = bound(0, 1 - (time - e.fade_time) * e.fade_rate, 1);
30
31         if(e == e.realowner.crylink_lastgroup)
32                 e.realowner.crylink_lastgroup = world;
33
34         RadiusDamage (e, e.realowner, cvar("g_balance_crylink_primary_damage") * a, cvar("g_balance_crylink_primary_edgedamage") * a, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * a, e.projectiledeathtype, other);
35
36         if(e.queuenext != e2)
37                 W_Crylink_LinkExplode(e.queuenext, e2);
38
39         remove (e);
40 }
41
42 // adjust towards center
43 // returns the origin where they will meet... and the time till the meeting is
44 // stored in w_crylink_linkjoin_time.
45 // could possibly network this origin and time, and display a special particle
46 // effect when projectiles meet there :P
47 float w_crylink_linkjoin_time;
48 vector W_Crylink_LinkJoin(entity e, float joinspeed)
49 {
50         vector avg_origin, avg_velocity;
51         vector targ_origin;
52         float avg_dist, n;
53         entity p;
54
55         w_crylink_linkjoin_time = 0;
56
57         avg_origin = e.origin;
58         avg_velocity = e.velocity;
59         n = 1;
60         for(p = e; (p = p.queuenext) != e; )
61         {
62                 avg_origin += p.origin;
63                 avg_velocity += p.velocity;
64                 ++n;
65         }
66         avg_origin *= (1.0 / n);
67         avg_velocity *= (1.0 / n);
68
69         if(n < 2)
70                 return avg_origin; // nothing to do
71
72         // yes, mathematically we can do this in ONE step, but beware of 32bit floats...
73         avg_dist = pow(vlen(e.origin - avg_origin), 2);
74         for(p = e; (p = p.queuenext) != e; )
75                 avg_dist += pow(vlen(e.origin - avg_origin), 2);
76         avg_dist *= (1.0 / n);
77         avg_dist = sqrt(avg_dist);
78
79         if(avg_dist == 0)
80                 return avg_origin; // no change needed
81
82         if(joinspeed == 0)
83         {
84                 e.velocity = avg_velocity;
85                 UpdateCSQCProjectile(e);
86                 for(p = e; (p = p.queuenext) != e; )
87                 {
88                         p.velocity = avg_velocity;
89                         UpdateCSQCProjectile(p);
90                 }
91         }
92         else
93         {
94                 w_crylink_linkjoin_time = avg_dist / joinspeed;
95                 targ_origin = avg_origin + w_crylink_linkjoin_time * avg_velocity;
96
97                 e.velocity = (targ_origin - e.origin) * (joinspeed / avg_dist);
98                 UpdateCSQCProjectile(e);
99                 for(p = e; (p = p.queuenext) != e; )
100                 {
101                         p.velocity = (targ_origin - p.origin) * (joinspeed / avg_dist);
102                         UpdateCSQCProjectile(p);
103                 }
104
105                 // analysis:
106                 //   joinspeed -> +infinity:
107                 //      w_crylink_linkjoin_time -> +0
108                 //      targ_origin -> avg_origin
109                 //      p->velocity -> HUEG towards center
110                 //   joinspeed -> 0:
111                 //      w_crylink_linkjoin_time -> +/- infinity
112                 //      targ_origin -> avg_velocity * +/- infinity
113                 //      p->velocity -> avg_velocity
114                 //   joinspeed -> -infinity:
115                 //      w_crylink_linkjoin_time -> -0
116                 //      targ_origin -> avg_origin
117                 //      p->velocity -> HUEG away from center
118         }
119
120         return targ_origin;
121 }
122
123 void W_Crylink_LinkJoinEffect_Think()
124 {
125         // is there at least 2 projectiles very close?
126         entity e, p;
127         float n;
128         e = self.owner.crylink_lastgroup;
129         n = 0;
130         if(e)
131         {
132                 if(vlen(e.origin - self.origin) < vlen(e.velocity) * frametime)
133                         ++n;
134                 for(p = e; (p = p.queuenext) != e; )
135                 {
136                         if(vlen(p.origin - self.origin) < vlen(p.velocity) * frametime)
137                                 ++n;
138                 }
139                 if(n >= 2)
140                 {
141                         // they seem to touch...
142                         // TODO make a specific particle effect for this
143                         pointparticles(particleeffectnum("crylink_linkjoin"), self.origin, '0 0 0', 1);
144                 }
145         }
146         remove(self);
147 }
148
149 // NO bounce protection, as bounces are limited!
150 void W_Crylink_Touch (void)
151 {
152         float finalhit;
153         float f;
154         //PROJECTILE_TOUCH;
155         local entity savenext, saveprev, saveown;
156         saveown = self.realowner;
157         savenext = self.queuenext;
158         saveprev = self.queueprev;
159         if(WarpZone_Projectile_Touch())
160         {
161                 if(wasfreed(self))
162                         W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
163                 return;
164         }
165
166         float a;
167         a = bound(0, 1 - (time - self.fade_time) * self.fade_rate, 1);
168
169         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
170         if(finalhit)
171                 f = 1;
172         else
173                 f = cvar("g_balance_crylink_primary_bouncedamagefactor");
174         if(a)
175                 f *= a;
176         if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_primary_damage") * f, cvar("g_balance_crylink_primary_edgedamage") * f, cvar("g_balance_crylink_primary_radius"), world, cvar("g_balance_crylink_primary_force") * f, self.projectiledeathtype, other) || finalhit)
177         {
178                 W_Crylink_LinkExplode(self.queuenext, self);
179                 remove (self);
180                 return;
181         }
182         self.cnt = self.cnt - 1;
183         self.angles = vectoangles(self.velocity);
184         self.owner = world;
185         self.projectiledeathtype |= HITTYPE_BOUNCE;
186         // commented out as it causes a little hitch...
187         //if(proj.cnt == 0)
188         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
189 }
190
191 void W_Crylink_Touch2 (void)
192 {
193         float finalhit;
194         float f;
195         //PROJECTILE_TOUCH;
196         local entity savenext, saveprev, saveown;
197         savenext = self.queuenext;
198         saveprev = self.queueprev;
199         saveown = self.realowner;
200         if(WarpZone_Projectile_Touch())
201         {
202                 if(wasfreed(self))
203                         W_Crylink_Dequeue_Raw(saveown, saveprev, self, savenext);
204                 return;
205         }
206
207         float a;
208         a = 1 - (time - self.fade_time) * self.fade_rate;
209
210         finalhit = ((self.cnt <= 0) || (other.takedamage != DAMAGE_NO));
211         if(finalhit)
212                 f = 1;
213         else
214                 f = cvar("g_balance_crylink_secondary_bouncedamagefactor");
215         if(a)
216                 f *= a;
217         if (RadiusDamage (self, self.realowner, cvar("g_balance_crylink_secondary_damage") * f, cvar("g_balance_crylink_secondary_edgedamage") * f, cvar("g_balance_crylink_secondary_radius"), world, cvar("g_balance_crylink_secondary_force") * f, self.projectiledeathtype, other))
218         {
219                 W_Crylink_LinkExplode(self.queuenext, self);
220                 remove (self);
221                 return;
222         }
223         else if(finalhit)
224         {
225                 // just unlink
226                 W_Crylink_Dequeue(self);
227                 remove(self);
228                 return;
229         }
230         self.cnt = self.cnt - 1;
231         self.angles = vectoangles(self.velocity);
232         self.owner = world;
233         self.projectiledeathtype |= HITTYPE_BOUNCE;
234         // commented out as it causes a little hitch...
235         //if(proj.cnt == 0)
236         //      CSQCProjectile(proj, TRUE, PROJECTILE_CRYLINK, TRUE);
237 }
238
239 void W_Crylink_Fadethink (void)
240 {
241         W_Crylink_Dequeue(self);
242         remove(self);
243 }
244
245 void W_Crylink_Attack (void)
246 {
247         local float counter, shots;
248         local entity proj, prevproj, firstproj;
249         local vector s;
250         vector forward, right, up;
251
252         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
253                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_primary_ammo");
254
255         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire.wav", (cvar("g_balance_crylink_primary_damage")*cvar("g_balance_crylink_primary_shots")));
256         forward = v_forward;
257         right = v_right;
258         up = v_up;
259
260         shots = cvar("g_balance_crylink_primary_shots");
261         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
262         proj = world;
263         while (counter < shots)
264         {
265                 proj = spawn ();
266                 proj.realowner = proj.owner = self;
267                 proj.classname = "spike";
268                 proj.bot_dodge = TRUE;
269                 proj.bot_dodgerating = cvar("g_balance_crylink_primary_damage");
270                 if(counter == 0) { // first projectile, store in firstproj for now
271                         firstproj = proj;
272                 }
273                 else if(counter == shots - 1) { // last projectile, link up with first projectile
274                         prevproj.queuenext = proj;
275                         firstproj.queueprev = proj;
276                         proj.queuenext = firstproj;
277                         proj.queueprev = prevproj;
278                 }
279                 else { // else link up with previous projectile
280                         prevproj.queuenext = proj;
281                         proj.queueprev = prevproj;
282                 }
283
284                 prevproj = proj;
285
286                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
287                 PROJECTILE_MAKETRIGGER(proj);
288                 proj.projectiledeathtype = WEP_CRYLINK;
289                 //proj.gravity = 0.001;
290
291                 setorigin (proj, w_shotorg);
292                 setsize(proj, '0 0 0', '0 0 0');
293
294
295                 s = '0 0 0';
296                 if (counter == 0)
297                         s = '0 0 0';
298                 else
299                 {
300                         makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
301                         s_y = v_forward_x;
302                         s_z = v_forward_y;
303                 }
304                 s = s * cvar("g_balance_crylink_primary_spread") * g_weaponspreadfactor;
305                 W_SetupProjectileVelocityEx(proj, w_shotdir + right * s_y + up * s_z, v_up, cvar("g_balance_crylink_primary_speed"), 0, 0, 0);
306                 proj.touch = W_Crylink_Touch;
307
308                 proj.think = W_Crylink_Fadethink;
309                 if(counter == 0)
310                 {
311                         proj.fade_time = time + cvar("g_balance_crylink_primary_middle_lifetime");
312                         self.fade_rate = 1 / cvar("g_balance_crylink_primary_middle_fadetime");
313                         proj.nextthink = time + cvar("g_balance_crylink_primary_middle_lifetime") + cvar("g_balance_crylink_primary_middle_fadetime");
314                 }
315                 else
316                 {
317                         proj.fade_time = time + cvar("g_balance_crylink_primary_other_lifetime");
318                         self.fade_rate = 1 / cvar("g_balance_crylink_primary_other_fadetime");
319                         proj.nextthink = time + cvar("g_balance_crylink_primary_other_lifetime") + cvar("g_balance_crylink_primary_other_fadetime");
320                 }
321                 proj.cnt = cvar("g_balance_crylink_primary_bounces");
322                 //proj.scale = 1 + 1 * proj.cnt;
323
324                 proj.angles = vectoangles (proj.velocity);
325
326                 //proj.glow_size = 20;
327
328                 proj.flags = FL_PROJECTILE;
329
330                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
331
332                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
333
334                 counter = counter + 1;
335         }
336         self.crylink_lastgroup = proj;
337 }
338
339 void W_Crylink_Attack2 (void)
340 {
341         local float counter, shots;
342         local entity proj, prevproj, firstproj;
343
344         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
345                 self.ammo_cells = self.ammo_cells - cvar("g_balance_crylink_secondary_ammo");
346
347         W_SetupShot (self, FALSE, 2, "weapons/crylink_fire2.wav", (cvar("g_balance_crylink_secondary_damage")*cvar("g_balance_crylink_secondary_shots")));
348
349         shots = cvar("g_balance_crylink_secondary_shots");
350         pointparticles(particleeffectnum("crylink_muzzleflash"), w_shotorg, w_shotdir * 1000, shots);
351         proj = world;
352         while (counter < shots)
353         {
354                 proj = spawn ();
355                 proj.realowner = proj.owner = self;
356                 proj.classname = "spike";
357                 proj.bot_dodge = TRUE;
358                 proj.bot_dodgerating = cvar("g_balance_crylink_secondary_damage");
359                 if(counter == 0) { // first projectile, store in firstproj for now
360                         firstproj = proj;
361                 }
362                 else if(counter == shots - 1) { // last projectile, link up with first projectile
363                         prevproj.queuenext = proj;
364                         firstproj.queueprev = proj;
365                         proj.queuenext = firstproj;
366                         proj.queueprev = prevproj;
367                 }
368                 else { // else link up with previous projectile
369                         prevproj.queuenext = proj;
370                         proj.queueprev = prevproj;
371                 }
372
373                 prevproj = proj;
374
375                 proj.movetype = MOVETYPE_BOUNCEMISSILE;
376                 PROJECTILE_MAKETRIGGER(proj);
377                 proj.projectiledeathtype = WEP_CRYLINK | HITTYPE_SECONDARY;
378                 //proj.gravity = 0.001;
379
380                 setorigin (proj, w_shotorg);
381                 setsize(proj, '0 0 0', '0 0 0');
382
383                 W_SetupProjectileVelocityEx(proj, (w_shotdir + (((counter + 0.5) / shots) * 2 - 1) * v_right * cvar("g_balance_crylink_secondary_spread") * g_weaponspreadfactor), v_up, cvar("g_balance_crylink_secondary_speed"), 0, 0, 0);
384                 proj.touch = W_Crylink_Touch2;
385                 proj.think = W_Crylink_Fadethink;
386                 if(counter == (shots - 1) / 2)
387                 {
388                         proj.fade_time = time + cvar("g_balance_crylink_secondary_middle_lifetime");
389                         self.fade_rate = 1 / cvar("g_balance_crylink_secondary_middle_fadetime");
390                         proj.nextthink = time + cvar("g_balance_crylink_secondary_middle_lifetime") + cvar("g_balance_crylink_secondary_middle_fadetime");
391                 }
392                 else
393                 {
394                         proj.fade_time = time + cvar("g_balance_crylink_secondary_line_lifetime");
395                         self.fade_rate = 1 / cvar("g_balance_crylink_secondary_line_fadetime");
396                         proj.nextthink = time + cvar("g_balance_crylink_secondary_line_lifetime") + cvar("g_balance_crylink_secondary_line_fadetime");
397                 }
398                 proj.cnt = cvar("g_balance_crylink_secondary_bounces");
399                 //proj.scale = 1 + 1 * proj.cnt;
400
401                 proj.angles = vectoangles (proj.velocity);
402
403                 //proj.glow_size = 20;
404
405                 proj.flags = FL_PROJECTILE;
406
407                 CSQCProjectile(proj, TRUE, (proj.cnt ? PROJECTILE_CRYLINK_BOUNCING : PROJECTILE_CRYLINK), TRUE);
408
409                 other = proj; MUTATOR_CALLHOOK(EditProjectile);
410
411                 counter = counter + 1;
412         }
413         self.crylink_lastgroup = proj;
414 }
415
416 void spawnfunc_weapon_crylink (void)
417 {
418         weapon_defaultspawnfunc(WEP_CRYLINK);
419 }
420
421 float w_crylink(float req)
422 {
423         if (req == WR_AIM)
424         {
425                 if (random() > 0.15)
426                         self.BUTTON_ATCK = bot_aim(cvar("g_balance_crylink_primary_speed"), 0, cvar("g_balance_crylink_primary_middle_lifetime"), FALSE);
427                 else
428                         self.BUTTON_ATCK2 = bot_aim(cvar("g_balance_crylink_secondary_speed"), 0, cvar("g_balance_crylink_secondary_middle_lifetime"), FALSE);
429         }
430         else if (req == WR_THINK)
431         {
432                 if (self.BUTTON_ATCK)
433                 {
434                         if (!self.crylink_waitrelease)
435                         if (weapon_prepareattack(0, cvar("g_balance_crylink_primary_refire")))
436                         {
437                                 W_Crylink_Attack();
438                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_crylink_primary_animtime"), w_ready);
439                                 if(cvar("g_balance_crylink_primary_joinspeed") != 0)
440                                         self.crylink_waitrelease = 1;
441                         }
442                 }
443                 else if(self.BUTTON_ATCK2 && cvar("g_balance_crylink_secondary"))
444                 {
445                         if (!self.crylink_waitrelease)
446                         if (weapon_prepareattack(1, cvar("g_balance_crylink_secondary_refire")))
447                         {
448                                 W_Crylink_Attack2();
449                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_crylink_secondary_animtime"), w_ready);
450                                 if(cvar("g_balance_crylink_secondary_joinspeed") != 0)
451                                         self.crylink_waitrelease = 2;
452                         }
453                 }
454                 else
455                 {
456                         if (self.crylink_waitrelease)
457                         {
458                                 // fired and released now!
459                                 if(self.crylink_lastgroup)
460                                 {
461                                         vector pos;
462                                         if(self.crylink_waitrelease == 1)
463                                         {
464                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_primary_joinspeed"));
465                                         }
466                                         else
467                                         {
468                                                 pos = W_Crylink_LinkJoin(self.crylink_lastgroup, cvar("g_balance_crylink_secondary_joinspeed"));
469                                         }
470
471                                         entity linkjoineffect;
472                                         linkjoineffect = spawn();
473                                         linkjoineffect.classname = "linkjoineffect";
474                                         linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
475                                         linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
476                                         linkjoineffect.owner = self;
477                                         setorigin(linkjoineffect, pos);
478                                 }
479                                 self.crylink_waitrelease = 0;
480                                 if(!w_crylink(WR_CHECKAMMO1) && !w_crylink(WR_CHECKAMMO2))
481                                 {
482                                         // ran out of ammo!
483                                         self.cnt = WEP_CRYLINK;
484                                         self.switchweapon = w_getbestweapon(self);
485                                 }
486                         }
487                 }
488         }
489         else if (req == WR_PRECACHE)
490         {
491                 precache_model ("models/weapons/g_crylink.md3");
492                 precache_model ("models/weapons/v_crylink.md3");
493                 precache_model ("models/weapons/h_crylink.iqm");
494                 precache_sound ("weapons/crylink_fire.wav");
495                 precache_sound ("weapons/crylink_fire2.wav");
496                 precache_sound ("weapons/crylink_linkjoin.wav");
497         }
498         else if (req == WR_SETUP)
499                 weapon_setup(WEP_CRYLINK);
500         else if (req == WR_CHECKAMMO1)
501         {
502                 // don't "run out of ammo" and switch weapons while waiting for release
503                 if(self.crylink_lastgroup && self.crylink_waitrelease)
504                         return TRUE;
505                 return self.ammo_cells >= cvar("g_balance_crylink_primary_ammo");
506         }
507         else if (req == WR_CHECKAMMO2)
508         {
509                 // don't "run out of ammo" and switch weapons while waiting for release
510                 if(self.crylink_lastgroup && self.crylink_waitrelease)
511                         return TRUE;
512                 return self.ammo_cells >= cvar("g_balance_crylink_secondary_ammo");
513         }
514         return TRUE;
515 };
516 #endif
517 #ifdef CSQC
518 float w_crylink(float req)
519 {
520         if(req == WR_IMPACTEFFECT)
521         {
522                 vector org2;
523                 org2 = w_org + w_backoff * 2;
524                 if(w_deathtype & HITTYPE_SECONDARY)
525                 {
526                         pointparticles(particleeffectnum("crylink_impact"), org2, '0 0 0', 1);
527                         if(!w_issilent)
528                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact2.wav", VOL_BASE, ATTN_NORM);
529                 }
530                 else
531                 {
532                         pointparticles(particleeffectnum("crylink_impactbig"), org2, '0 0 0', 1);
533                         if(!w_issilent)
534                                 sound(self, CHAN_PROJECTILE, "weapons/crylink_impact.wav", VOL_BASE, ATTN_NORM);
535                 }
536         }
537         else if(req == WR_PRECACHE)
538         {
539                 precache_sound("weapons/crylink_impact2.wav");
540                 precache_sound("weapons/crylink_impact.wav");
541         }
542         else if (req == WR_SUICIDEMESSAGE)
543         {
544                 w_deathtypestring = "%s succeeded at self-destructing themself with the Crylink";
545         }
546         else if (req == WR_KILLMESSAGE)
547         {
548                 if(w_deathtype & HITTYPE_BOUNCE)
549                         w_deathtypestring = "%s could not hide from %s's Crylink"; // unchecked: SPLASH (SECONDARY can't be)
550                 else if(w_deathtype & HITTYPE_SPLASH)
551                         w_deathtypestring = "%s was too close to %s's Crylink"; // unchecked: SECONDARY
552                 else
553                         w_deathtypestring = "%s took a close look at %s's Crylink"; // unchecked: SECONDARY
554         }
555         return TRUE;
556 }
557 #endif
558 #endif