make weapon death messages translatable
[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_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 not(self.items & IT_UNLIMITED_WEAPON_AMMO)
162                 self.ammo_rockets = self.ammo_rockets - autocvar_g_balance_seeker_missile_ammo;
163
164         makevectors(self.v_angle);
165         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", CHAN_WEAPON, 0);
166         w_shotorg += f_diff;
167         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
168
169         //self.detornator         = FALSE;
170
171         missile                 = spawn();
172         missile.owner           = self;
173         missile.classname       = "seeker_missile";
174         missile.bot_dodge       = TRUE;
175         missile.bot_dodgerating = autocvar_g_balance_seeker_missile_damage;
176
177         missile.think           = Seeker_Missile_Think;
178         missile.touch           = Seeker_Missile_Touch;
179         missile.event_damage    = Seeker_Missile_Damage;
180         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
181         missile.cnt             = time + autocvar_g_balance_seeker_missile_lifetime;
182         missile.enemy           = self.enemy;
183         missile.solid           = SOLID_BBOX;
184         missile.scale           = 2;
185         missile.takedamage      = DAMAGE_YES;
186         missile.health          = autocvar_g_balance_seeker_missile_health;
187         missile.damageforcescale = autocvar_g_balance_seeker_missile_damageforcescale;
188         missile.projectiledeathtype = WEP_SEEKER;
189         //missile.think           = Seeker_Missile_Animate; // csqc projectiles.
190
191
192         setorigin (missile, w_shotorg);
193         setsize (missile, '-4 -4 -4', '4 4 4');
194         missile.movetype    = MOVETYPE_FLYMISSILE;
195         missile.flags       = FL_PROJECTILE;
196         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
197
198         missile.angles = vectoangles (missile.velocity);
199
200         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
201
202         other = missile; MUTATOR_CALLHOOK(EditProjectile);
203 }
204
205 void Seeker_Vollycontroler_Think()
206 {
207         float c;
208         entity oldself,oldenemy;
209         self.cnt = self.cnt - 1;
210
211         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))
212         {
213                 remove(self);
214                 return;
215         }
216
217         self.nextthink = time + autocvar_g_balance_seeker_missile_delay;
218
219         oldself = self;
220         self = self.owner;
221
222         oldenemy = self.enemy;
223         self.enemy = oldself.enemy;
224
225         c = mod(oldself.cnt, 4);
226         switch(c)
227         {
228                 case 0:
229                         Seeker_Fire_Missile('-1.25 -3.75 0');
230                         break;
231                 case 1:
232                         Seeker_Fire_Missile('+1.25 -3.75 0');
233                         break;
234                 case 2:
235                         Seeker_Fire_Missile('-1.25 +3.75 0');
236                         break;
237                 case 3:
238                 default:
239                         Seeker_Fire_Missile('+1.25 +3.75 0');
240                         break;
241         }
242
243         self.enemy = oldenemy;
244         self = oldself;
245 }
246
247 void Seeker_Tag_Explode ()
248 {
249         //if(other==self.owner)
250         //    return;
251         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
252
253         remove (self);
254 }
255
256 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
257 {
258         if (self.health <= 0)
259                 return;
260         self.health = self.health - damage;
261         if (self.health <= 0)
262                 Seeker_Tag_Explode();
263 }
264
265
266 void Seeker_Tag_Touch()
267 {
268         vector dir;
269         vector org2;
270         entity e;
271         
272         dir     = normalize (self.owner.origin - self.origin);
273         org2    = findbetterlocation (self.origin, 8);
274
275         te_knightspike(org2);
276
277         self.event_damage = SUB_Null;
278         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
279
280         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
281         {               
282                 e           = spawn();
283                 e.cnt       = autocvar_g_balance_seeker_missile_count;
284                 e.owner     = self.owner;
285                 e.enemy     = other;
286                 e.think     = Seeker_Vollycontroler_Think;
287                 e.nextthink = time;
288         }
289
290         remove(self);
291         return;
292 }
293
294 void Seeker_Fire_Tag()
295 {
296         local entity missile;
297         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
298                 self.ammo_rockets = self.ammo_rockets - autocvar_g_balance_seeker_tag_ammo;
299
300         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);
301
302         missile                 = spawn();
303         missile.owner           = self;
304         missile.classname       = "seeker_tag";
305         missile.bot_dodge       = TRUE;
306         missile.bot_dodgerating = 50;
307         missile.touch           = Seeker_Tag_Touch;
308         missile.think           = SUB_Remove;
309         missile.nextthink       = time + autocvar_g_balance_seeker_tag_lifetime;
310         missile.movetype        = MOVETYPE_FLY;
311         missile.solid           = SOLID_BBOX;
312         missile.owner           = self;
313
314         missile.takedamage       = DAMAGE_YES;
315         missile.event_damage    = Seeker_Tag_Explode;
316         missile.health          = autocvar_g_balance_seeker_tag_health;
317         missile.damageforcescale = autocvar_g_balance_seeker_tag_damageforcescale;
318
319         setorigin (missile, w_shotorg);
320         setsize (missile, '-2 -2 -2', '2 2 2');
321
322         missile.flags       = FL_PROJECTILE;
323
324         missile.movetype    = MOVETYPE_FLY;
325         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
326         missile.angles = vectoangles (missile.velocity);
327
328         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
329
330         other = missile; MUTATOR_CALLHOOK(EditProjectile);
331 }
332
333
334 void Seeker_Flac_Explode ()
335 {
336         self.event_damage = SUB_Null;
337
338         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);
339
340         remove (self);
341 }
342
343 void Seeker_Flac_Touch()
344 {
345         PROJECTILE_TOUCH;
346
347         Seeker_Flac_Explode();
348 }
349
350 void Seeker_Fire_Flac()
351 {
352         local entity missile;
353         vector f_diff;
354         float c;
355
356         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
357                 self.ammo_rockets = self.ammo_rockets - autocvar_g_balance_seeker_flac_ammo;
358
359         c = mod(self.bulletcounter, 4);
360         switch(c)
361         {
362                 case 0:
363                         f_diff = '-1.25 -3.75 0';
364                         break;
365                 case 1:
366                         f_diff = '+1.25 -3.75 0';
367                         break;
368                 case 2:
369                         f_diff = '-1.25 +3.75 0';
370                         break;
371                 case 3:
372                 default:
373                         f_diff = '+1.25 +3.75 0';
374                         break;
375         }
376         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_flac_damage);
377         w_shotorg += f_diff;
378
379         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
380
381         missile                                 = spawn ();
382         missile.owner                   = missile.realowner = self;
383         missile.classname               = "missile";
384         missile.bot_dodge               = TRUE;
385         missile.bot_dodgerating = autocvar_g_balance_seeker_flac_damage;
386         missile.touch                   = Seeker_Flac_Explode;
387         missile.use                     = Seeker_Flac_Explode; 
388         missile.think                   = adaptor_think2use_hittype_splash;
389         missile.nextthink               = time + autocvar_g_balance_seeker_flac_lifetime + autocvar_g_balance_seeker_flac_lifetime_rand;
390         missile.solid                   = SOLID_BBOX;
391         missile.movetype                = MOVETYPE_FLY; 
392         missile.projectiledeathtype = WEP_SEEKER;
393         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
394         missile.flags                           = FL_PROJECTILE;
395         
396         // csqc projectiles
397         //missile.angles                                = vectoangles (missile.velocity);       
398         //missile.scale = 0.4; // BUG: the model is too big 
399         
400         setorigin (missile, w_shotorg);
401         setsize (missile, '-2 -2 -2', '2 2 2');
402                 
403         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
404         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
405
406         other = missile; MUTATOR_CALLHOOK(EditProjectile);
407 }
408
409 void spawnfunc_weapon_seeker (void)
410 {
411         weapon_defaultspawnfunc(WEP_SEEKER);
412 }
413
414 float w_seeker(float req)
415 {
416         if (req == WR_AIM)
417                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_seeker_tag_speed, 0, 20, FALSE);
418
419         else if (req == WR_THINK)
420         {
421                 if (self.BUTTON_ATCK)
422                         if (weapon_prepareattack(0, autocvar_g_balance_seeker_tag_refire))
423                         {
424                                 Seeker_Fire_Tag();
425                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_seeker_tag_animtime, w_ready);
426                         }
427
428                 if (self.BUTTON_ATCK2)
429                         if (weapon_prepareattack(1, autocvar_g_balance_seeker_flac_refire))
430                         {
431                                 Seeker_Fire_Flac();
432                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_seeker_flac_animtime, w_ready);
433                         }
434
435         }
436         else if (req == WR_PRECACHE)
437         {
438                 precache_model ("models/weapons/g_seeker.md3");
439                 precache_model ("models/weapons/v_seeker.md3");
440                 precache_model ("models/weapons/h_seeker.iqm");
441                 precache_sound ("weapons/tag_fire.wav");
442                 precache_sound ("weapons/flac_fire.wav");
443                 precache_sound ("weapons/seeker_fire.wav");
444         }
445         else if (req == WR_SETUP)
446                 weapon_setup(WEP_SEEKER);
447         else if (req == WR_CHECKAMMO1)
448                 return self.ammo_rockets >= autocvar_g_balance_seeker_tag_ammo + autocvar_g_balance_seeker_missile_ammo;
449         else if (req == WR_CHECKAMMO2)
450                 return self.ammo_rockets >= autocvar_g_balance_seeker_flac_ammo;
451         return TRUE;
452 };
453 #endif
454 #ifdef CSQC
455 float w_seeker(float req)
456 {
457         if(req == WR_IMPACTEFFECT)
458         {
459                 vector org2;
460                 org2 = w_org + w_backoff * 6;
461                 if(w_deathtype & HITTYPE_SECONDARY)
462                 {
463                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
464                         if(!w_issilent)
465                         {
466                                 if (w_random<0.15)
467                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
468                                 else if (w_random<0.7)
469                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
470                                 else
471                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
472                         }
473                 }
474                 else
475                 {
476                         if(w_deathtype & HITTYPE_BOUNCE)
477                         {
478                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
479                                 if(!w_issilent)
480                                 {
481                                         if (w_random<0.15)
482                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
483                                         else if (w_random<0.7)
484                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
485                                         else
486                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
487                                 }
488                         }
489                         else if(w_deathtype & HITTYPE_HEADSHOT)
490                         {
491                                 if(!w_issilent)
492                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
493                         }
494                         else
495                         {
496                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
497                                 if(!w_issilent)
498                                 {
499                                         if (w_random<0.15)
500                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
501                                         else if (w_random<0.7)
502                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
503                                         else
504                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
505                                 }
506                         }
507                 }
508         }
509         else if(req == WR_PRECACHE)
510         {
511                 precache_sound("weapons/flacexp1.wav");
512                 precache_sound("weapons/flacexp2.wav");
513                 precache_sound("weapons/flacexp3.wav");
514                 precache_sound("weapons/seekerexp1.wav");
515                 precache_sound("weapons/seekerexp2.wav");
516                 precache_sound("weapons/seekerexp3.wav");
517                 precache_sound("weapons/tagexp1.wav");
518                 precache_sound("weapons/tagexp2.wav");
519                 precache_sound("weapons/tagexp3.wav");
520                 precache_sound("weapons/tag_impact.wav");
521         }
522         else if (req == WR_SUICIDEMESSAGE)
523                 w_deathtypestring = _("%s played with tiny rockets");
524         else if (req == WR_KILLMESSAGE)
525         {
526                 if(w_deathtype & HITTYPE_SECONDARY)
527                         w_deathtypestring = _("%s ran into %s's flac");
528                 else
529                         w_deathtypestring = _("%s was tagged by %s");
530         }
531         return TRUE;
532 }
533 #endif
534 #endif