]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_seeker.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SEEKER, w_seeker, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "seeker", "seeker", _("T.A.G. Seeker"))
3 #else
4 #ifdef SVQC
5 //.float proxytime; = autoswitch
6 //.float tl; = wait
7
8 void W_Seeker_Reload()
9 {
10         self.reload_ammo_player = ammo_rockets;
11         self.reload_ammo_min = min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo);
12         self.reload_ammo_amount = autocvar_g_balance_seeker_reload_ammo;
13         self.reload_time = autocvar_g_balance_seeker_reload_time;
14         self.reload_sound = "weapons/reload.wav";
15
16         W_Reload();
17 }
18
19 void Seeker_Missile_Explode ()
20 {
21         self.event_damage = SUB_Null;
22         RadiusDamage (self, self.owner, autocvar_g_balance_seeker_missile_damage, autocvar_g_balance_seeker_missile_edgedamage, autocvar_g_balance_seeker_missile_radius, world, autocvar_g_balance_seeker_missile_force, self.projectiledeathtype, other);
23
24         remove (self);
25 }
26
27 void Seeker_Missile_Touch()
28 {
29         PROJECTILE_TOUCH;
30
31         Seeker_Missile_Explode();
32 }
33
34 void Seeker_Missile_Think()
35 {
36         entity e;
37         vector desireddir, olddir, newdir, eorg;
38         float turnrate;
39         float dist;
40         float spd;
41
42         if (time > self.cnt)
43         {
44                 self.projectiledeathtype |= HITTYPE_SPLASH;
45                 Seeker_Missile_Explode();
46         }
47
48         spd = vlen(self.velocity);
49         spd = bound(
50                 spd - autocvar_g_balance_seeker_missile_decel * frametime,
51                 autocvar_g_balance_seeker_missile_speed_max,
52                 spd + autocvar_g_balance_seeker_missile_accel * frametime
53         );
54
55         if (self.enemy != world)
56                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
57                         self.enemy = world;
58
59         if (self.enemy != world)
60         {
61                 e               = self.enemy;
62                 eorg            = 0.5 * (e.absmin + e.absmax);
63                 turnrate        = autocvar_g_balance_seeker_missile_turnrate; // how fast to turn
64                 desireddir      = normalize(eorg - self.origin);
65                 olddir          = normalize(self.velocity); // get my current direction
66                 dist            = vlen(eorg - self.origin);
67
68                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
69                 if (autocvar_g_balance_seeker_missile_smart && (dist > autocvar_g_balance_seeker_missile_smart_mindist))
70                 {
71                         // Is it a better idea (shorter distance) to trace to the target itself?
72                         if ( vlen(self.origin + olddir * self.wait) < dist)
73                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
74                         else
75                                 traceline(self.origin, eorg, FALSE, self);
76
77                         // Setup adaptive tracelength
78                         self.wait = bound(autocvar_g_balance_seeker_missile_smart_trace_min, vlen(self.origin - trace_endpos), self.wait = autocvar_g_balance_seeker_missile_smart_trace_max);
79
80                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
81                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
82                 }
83                 
84                 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
85                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
86         }
87
88         // Proxy
89         if (autocvar_g_balance_seeker_missile_proxy)
90         {
91                 if ( dist <= autocvar_g_balance_seeker_missile_proxy_maxrange)
92                 {
93                         if (self.autoswitch == 0)
94                         {
95                                 self.autoswitch = time + autocvar_g_balance_seeker_missile_proxy_delay;
96                         }
97                         else
98                         {
99                                 if (self.autoswitch <= time)
100                                 {
101                                         Seeker_Missile_Explode();
102                                         self.autoswitch = 0;
103                                 }
104                         }
105                 }
106                 else
107                 {
108                         if (self.autoswitch != 0)
109                                 self.autoswitch = 0;
110                 }
111         }
112         ///////////////
113
114         if (self.enemy.deadflag != DEAD_NO)
115         {
116                 self.enemy = world;
117                 self.cnt = time + 1 + (random() * 4);
118                 self.nextthink = self.cnt;
119                 return;
120         }
121
122         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
123         self.nextthink = time;// + 0.05; // csqc projectiles
124         UpdateCSQCProjectile(self);
125 }
126
127
128
129 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
130 {
131         if (self.health <= 0)
132                 return;
133
134         if (self.owner == attacker)
135                 self.health = self.health - (damage * 0.25);
136         else
137                 self.health = self.health - damage;
138                 
139         if (self.health <= 0)
140                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
141 }
142
143 /*
144 void Seeker_Missile_Animate()
145 {
146         self.frame = self.frame +1;
147         self.nextthink = time + 0.05;
148
149         if (self.enemy != world)
150                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
151                         self.enemy = world;
152
153         if(self.frame == 5)
154         {
155                 self.think           = Seeker_Missile_Think;
156                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
157
158                 if (autocvar_g_balance_seeker_missile_proxy)
159                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
160                 else
161                         self.movetype    = MOVETYPE_FLYMISSILE;
162         }
163
164         UpdateCSQCProjectile(self);
165 }
166 */
167
168 void Seeker_Fire_Missile(vector f_diff)
169 {
170         local entity missile;
171
172         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
173         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
174         {
175                 if(autocvar_g_balance_seeker_reload_ammo)
176                 {
177                         self.clip_load -= autocvar_g_balance_seeker_missile_ammo;
178                         self.weapon_load[WEP_SEEKER] = self.clip_load;
179                 }
180                 else
181                         self.ammo_rockets -= autocvar_g_balance_seeker_missile_ammo;
182         }
183
184         makevectors(self.v_angle);
185         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", CHAN_WEAPON, 0);
186         w_shotorg += f_diff;
187         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
188
189         //self.detornator         = FALSE;
190
191         missile                 = spawn();
192         missile.owner           = self;
193         missile.classname       = "seeker_missile";
194         missile.bot_dodge       = TRUE;
195         missile.bot_dodgerating = autocvar_g_balance_seeker_missile_damage;
196
197         missile.think           = Seeker_Missile_Think;
198         missile.touch           = Seeker_Missile_Touch;
199         missile.event_damage    = Seeker_Missile_Damage;
200         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
201         missile.cnt             = time + autocvar_g_balance_seeker_missile_lifetime;
202         missile.enemy           = self.enemy;
203         missile.solid           = SOLID_BBOX;
204         missile.scale           = 2;
205         missile.takedamage      = DAMAGE_YES;
206         missile.health          = autocvar_g_balance_seeker_missile_health;
207         missile.damageforcescale = autocvar_g_balance_seeker_missile_damageforcescale;
208         missile.projectiledeathtype = WEP_SEEKER;
209         //missile.think           = Seeker_Missile_Animate; // csqc projectiles.
210
211
212         setorigin (missile, w_shotorg);
213         setsize (missile, '-4 -4 -4', '4 4 4');
214         missile.movetype    = MOVETYPE_FLYMISSILE;
215         missile.flags       = FL_PROJECTILE;
216         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
217
218         missile.angles = vectoangles (missile.velocity);
219
220         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
221
222         other = missile; MUTATOR_CALLHOOK(EditProjectile);
223 }
224
225 void Seeker_Vollycontroler_Think()
226 {
227         float c;
228         entity oldself,oldenemy;
229         self.cnt = self.cnt - 1;
230
231         if((!(self.owner.items & IT_UNLIMITED_AMMO) && self.owner.ammo_rockets < autocvar_g_balance_seeker_missile_ammo) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO) || (self.owner.switchweapon != WEP_SEEKER))
232         {
233                 remove(self);
234                 return;
235         }
236
237         self.nextthink = time + autocvar_g_balance_seeker_missile_delay;
238
239         oldself = self;
240         self = self.owner;
241
242         oldenemy = self.enemy;
243         self.enemy = oldself.enemy;
244
245         c = mod(oldself.cnt, 4);
246         switch(c)
247         {
248                 case 0:
249                         Seeker_Fire_Missile('-1.25 -3.75 0');
250                         break;
251                 case 1:
252                         Seeker_Fire_Missile('+1.25 -3.75 0');
253                         break;
254                 case 2:
255                         Seeker_Fire_Missile('-1.25 +3.75 0');
256                         break;
257                 case 3:
258                 default:
259                         Seeker_Fire_Missile('+1.25 +3.75 0');
260                         break;
261         }
262
263         self.enemy = oldenemy;
264         self = oldself;
265 }
266
267 void Seeker_Tag_Explode ()
268 {
269         //if(other==self.owner)
270         //    return;
271         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
272
273         remove (self);
274 }
275
276 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
277 {
278         if (self.health <= 0)
279                 return;
280         self.health = self.health - damage;
281         if (self.health <= 0)
282                 Seeker_Tag_Explode();
283 }
284
285
286 void Seeker_Tag_Touch()
287 {
288         vector dir;
289         vector org2;
290         entity e;
291         
292         dir     = normalize (self.owner.origin - self.origin);
293         org2    = findbetterlocation (self.origin, 8);
294
295         te_knightspike(org2);
296
297         self.event_damage = SUB_Null;
298         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
299
300         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
301         {               
302                 e           = spawn();
303                 e.cnt       = autocvar_g_balance_seeker_missile_count;
304                 e.owner     = self.owner;
305                 e.enemy     = other;
306                 e.think     = Seeker_Vollycontroler_Think;
307                 e.nextthink = time;
308         }
309
310         remove(self);
311         return;
312 }
313
314 void Seeker_Fire_Tag()
315 {
316         local entity missile;
317         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
318         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
319         {
320                 if(autocvar_g_balance_seeker_reload_ammo)
321                 {
322                         self.clip_load -= autocvar_g_balance_seeker_tag_ammo;
323                         self.weapon_load[WEP_SEEKER] = self.clip_load;
324                 }
325                 else
326                         self.ammo_rockets -= autocvar_g_balance_seeker_tag_ammo;
327         }
328
329         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/tag_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_missile_damage * autocvar_g_balance_seeker_missile_count);
330
331         missile                 = spawn();
332         missile.owner           = self;
333         missile.classname       = "seeker_tag";
334         missile.bot_dodge       = TRUE;
335         missile.bot_dodgerating = 50;
336         missile.touch           = Seeker_Tag_Touch;
337         missile.think           = SUB_Remove;
338         missile.nextthink       = time + autocvar_g_balance_seeker_tag_lifetime;
339         missile.movetype        = MOVETYPE_FLY;
340         missile.solid           = SOLID_BBOX;
341         missile.owner           = self;
342
343         missile.takedamage       = DAMAGE_YES;
344         missile.event_damage    = Seeker_Tag_Explode;
345         missile.health          = autocvar_g_balance_seeker_tag_health;
346         missile.damageforcescale = autocvar_g_balance_seeker_tag_damageforcescale;
347
348         setorigin (missile, w_shotorg);
349         setsize (missile, '-2 -2 -2', '2 2 2');
350
351         missile.flags       = FL_PROJECTILE;
352
353         missile.movetype    = MOVETYPE_FLY;
354         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
355         missile.angles = vectoangles (missile.velocity);
356
357         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
358
359         other = missile; MUTATOR_CALLHOOK(EditProjectile);
360 }
361
362
363 void Seeker_Flac_Explode ()
364 {
365         self.event_damage = SUB_Null;
366
367         RadiusDamage (self, self.owner, autocvar_g_balance_seeker_flac_damage, autocvar_g_balance_seeker_flac_edgedamage, autocvar_g_balance_seeker_flac_radius, world, autocvar_g_balance_seeker_flac_force, self.projectiledeathtype, other);
368
369         remove (self);
370 }
371
372 void Seeker_Flac_Touch()
373 {
374         PROJECTILE_TOUCH;
375
376         Seeker_Flac_Explode();
377 }
378
379 void Seeker_Fire_Flac()
380 {
381         local entity missile;
382         vector f_diff;
383         float c;
384
385         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
386         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
387         {
388                 if(autocvar_g_balance_seeker_reload_ammo)
389                 {
390                         self.clip_load -= autocvar_g_balance_seeker_flac_ammo;
391                         self.weapon_load[WEP_SEEKER] = self.clip_load;
392                 }
393                 else
394                         self.ammo_rockets -= autocvar_g_balance_seeker_flac_ammo;
395         }
396
397         c = mod(self.bulletcounter, 4);
398         switch(c)
399         {
400                 case 0:
401                         f_diff = '-1.25 -3.75 0';
402                         break;
403                 case 1:
404                         f_diff = '+1.25 -3.75 0';
405                         break;
406                 case 2:
407                         f_diff = '-1.25 +3.75 0';
408                         break;
409                 case 3:
410                 default:
411                         f_diff = '+1.25 +3.75 0';
412                         break;
413         }
414         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_flac_damage);
415         w_shotorg += f_diff;
416
417         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
418
419         missile                                 = spawn ();
420         missile.owner                   = missile.realowner = self;
421         missile.classname               = "missile";
422         missile.bot_dodge               = TRUE;
423         missile.bot_dodgerating = autocvar_g_balance_seeker_flac_damage;
424         missile.touch                   = Seeker_Flac_Explode;
425         missile.use                     = Seeker_Flac_Explode; 
426         missile.think                   = adaptor_think2use_hittype_splash;
427         missile.nextthink               = time + autocvar_g_balance_seeker_flac_lifetime + autocvar_g_balance_seeker_flac_lifetime_rand;
428         missile.solid                   = SOLID_BBOX;
429         missile.movetype                = MOVETYPE_FLY; 
430         missile.projectiledeathtype = WEP_SEEKER;
431         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
432         missile.flags                           = FL_PROJECTILE;
433         
434         // csqc projectiles
435         //missile.angles                                = vectoangles (missile.velocity);       
436         //missile.scale = 0.4; // BUG: the model is too big 
437         
438         setorigin (missile, w_shotorg);
439         setsize (missile, '-2 -2 -2', '2 2 2');
440                 
441         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
442         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
443
444         other = missile; MUTATOR_CALLHOOK(EditProjectile);
445 }
446
447 void spawnfunc_weapon_seeker (void)
448 {
449         weapon_defaultspawnfunc(WEP_SEEKER);
450 }
451
452 float w_seeker(float req)
453 {
454         float ammo_amount;
455
456         if (req == WR_AIM)
457                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_seeker_tag_speed, 0, 20, FALSE);
458
459         else if (req == WR_THINK)
460         {
461                 if(autocvar_g_balance_seeker_reload_ammo && self.clip_load < min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo)) // forced reload
462                         W_Seeker_Reload();
463
464                 else if (self.BUTTON_ATCK)
465                 {
466                         if (weapon_prepareattack(0, autocvar_g_balance_seeker_tag_refire))
467                         {
468                                 Seeker_Fire_Tag();
469                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_seeker_tag_animtime, w_ready);
470                         }
471                 }
472
473                 else if (self.BUTTON_ATCK2)
474                 {
475                         if (weapon_prepareattack(1, autocvar_g_balance_seeker_flac_refire))
476                         {
477                                 Seeker_Fire_Flac();
478                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_seeker_flac_animtime, w_ready);
479                         }
480                 }
481         }
482         else if (req == WR_PRECACHE)
483         {
484                 precache_model ("models/weapons/g_seeker.md3");
485                 precache_model ("models/weapons/v_seeker.md3");
486                 precache_model ("models/weapons/h_seeker.iqm");
487                 precache_sound ("weapons/tag_fire.wav");
488                 precache_sound ("weapons/flac_fire.wav");
489                 precache_sound ("weapons/seeker_fire.wav");
490                 precache_sound ("weapons/reload.wav");
491         }
492         else if (req == WR_SETUP)
493         {
494                 weapon_setup(WEP_SEEKER);
495         }
496         else if (req == WR_CHECKAMMO1)
497         {
498                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_missile_ammo;
499                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_missile_ammo;
500                 return ammo_amount;
501         }
502         else if (req == WR_CHECKAMMO2)
503         {
504                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_flac_ammo;
505                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_flac_ammo;
506                 return ammo_amount;
507         }
508         else if (req == WR_RELOAD)
509         {
510                 W_Seeker_Reload();
511         }
512         return TRUE;
513 };
514 #endif
515 #ifdef CSQC
516 float w_seeker(float req)
517 {
518         if(req == WR_IMPACTEFFECT)
519         {
520                 vector org2;
521                 org2 = w_org + w_backoff * 6;
522                 if(w_deathtype & HITTYPE_SECONDARY)
523                 {
524                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
525                         if(!w_issilent)
526                         {
527                                 if (w_random<0.15)
528                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
529                                 else if (w_random<0.7)
530                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
531                                 else
532                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
533                         }
534                 }
535                 else
536                 {
537                         if(w_deathtype & HITTYPE_BOUNCE)
538                         {
539                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
540                                 if(!w_issilent)
541                                 {
542                                         if (w_random<0.15)
543                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
544                                         else if (w_random<0.7)
545                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
546                                         else
547                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
548                                 }
549                         }
550                         else if(w_deathtype & HITTYPE_HEADSHOT)
551                         {
552                                 if(!w_issilent)
553                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
554                         }
555                         else
556                         {
557                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
558                                 if(!w_issilent)
559                                 {
560                                         if (w_random<0.15)
561                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
562                                         else if (w_random<0.7)
563                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
564                                         else
565                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
566                                 }
567                         }
568                 }
569         }
570         else if(req == WR_PRECACHE)
571         {
572                 precache_sound("weapons/flacexp1.wav");
573                 precache_sound("weapons/flacexp2.wav");
574                 precache_sound("weapons/flacexp3.wav");
575                 precache_sound("weapons/seekerexp1.wav");
576                 precache_sound("weapons/seekerexp2.wav");
577                 precache_sound("weapons/seekerexp3.wav");
578                 precache_sound("weapons/tagexp1.wav");
579                 precache_sound("weapons/tagexp2.wav");
580                 precache_sound("weapons/tagexp3.wav");
581                 precache_sound("weapons/tag_impact.wav");
582         }
583         else if (req == WR_SUICIDEMESSAGE)
584                 w_deathtypestring = _("%s played with tiny rockets");
585         else if (req == WR_KILLMESSAGE)
586         {
587                 if(w_deathtype & HITTYPE_SECONDARY)
588                         w_deathtypestring = _("%s ran into %s's flac");
589                 else
590                         w_deathtypestring = _("%s was tagged by %s");
591         }
592         return TRUE;
593 }
594 #endif
595 #endif