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