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