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