Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / w_seeker.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(
3 /* WEP_##id  */ SEEKER,
4 /* function  */ W_Seeker,
5 /* ammotype  */ ammo_rockets,
6 /* impulse   */ 8,
7 /* flags     */ WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH,
8 /* rating    */ BOT_PICKUP_RATING_MID,
9 /* color     */ '0.5 1 0',
10 /* modelname */ "seeker",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairseeker 0.8",
13 /* wepimg    */ "weaponseeker",
14 /* refname   */ "seeker",
15 /* wepname   */ _("T.A.G. Seeker")
16 );
17
18 #define SEEKER_SETTINGS(w_cvar,w_prop) SEEKER_SETTINGS_LIST(w_cvar, w_prop, SEEKER, seeker)
19 #define SEEKER_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, NONE, type) \
21         w_cvar(id, sn, NONE, flac_ammo) \
22         w_cvar(id, sn, NONE, flac_animtime) \
23         w_cvar(id, sn, NONE, flac_damage) \
24         w_cvar(id, sn, NONE, flac_edgedamage) \
25         w_cvar(id, sn, NONE, flac_force) \
26         w_cvar(id, sn, NONE, flac_lifetime) \
27         w_cvar(id, sn, NONE, flac_lifetime_rand) \
28         w_cvar(id, sn, NONE, flac_radius) \
29         w_cvar(id, sn, NONE, flac_refire) \
30         w_cvar(id, sn, NONE, flac_speed) \
31         w_cvar(id, sn, NONE, flac_speed_up) \
32         w_cvar(id, sn, NONE, flac_speed_z) \
33         w_cvar(id, sn, NONE, flac_spread) \
34         w_cvar(id, sn, NONE, missile_accel) \
35         w_cvar(id, sn, NONE, missile_ammo) \
36         w_cvar(id, sn, NONE, missile_animtime) \
37         w_cvar(id, sn, NONE, missile_count) \
38         w_cvar(id, sn, NONE, missile_damage) \
39         w_cvar(id, sn, NONE, missile_damageforcescale) \
40         w_cvar(id, sn, NONE, missile_decel) \
41         w_cvar(id, sn, NONE, missile_delay) \
42         w_cvar(id, sn, NONE, missile_edgedamage) \
43         w_cvar(id, sn, NONE, missile_force) \
44         w_cvar(id, sn, NONE, missile_health) \
45         w_cvar(id, sn, NONE, missile_lifetime) \
46         w_cvar(id, sn, NONE, missile_proxy) \
47         w_cvar(id, sn, NONE, missile_proxy_delay) \
48         w_cvar(id, sn, NONE, missile_proxy_maxrange) \
49         w_cvar(id, sn, NONE, missile_radius) \
50         w_cvar(id, sn, NONE, missile_refire) \
51         w_cvar(id, sn, NONE, missile_smart) \
52         w_cvar(id, sn, NONE, missile_smart_mindist) \
53         w_cvar(id, sn, NONE, missile_smart_trace_max) \
54         w_cvar(id, sn, NONE, missile_smart_trace_min) \
55         w_cvar(id, sn, NONE, missile_speed) \
56         w_cvar(id, sn, NONE, missile_speed_max) \
57         w_cvar(id, sn, NONE, missile_speed_up) \
58         w_cvar(id, sn, NONE, missile_speed_z) \
59         w_cvar(id, sn, NONE, missile_spread) \
60         w_cvar(id, sn, NONE, missile_turnrate) \
61         w_cvar(id, sn, NONE, tag_ammo) \
62         w_cvar(id, sn, NONE, tag_animtime) \
63         w_cvar(id, sn, NONE, tag_damageforcescale) \
64         w_cvar(id, sn, NONE, tag_health) \
65         w_cvar(id, sn, NONE, tag_lifetime) \
66         w_cvar(id, sn, NONE, tag_refire) \
67         w_cvar(id, sn, NONE, tag_speed) \
68         w_cvar(id, sn, NONE, tag_spread) \
69         w_cvar(id, sn, NONE, tag_tracker_lifetime) \
70         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
71         w_prop(id, sn, float,  reloading_time, reload_time) \
72         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
73         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
74         w_prop(id, sn, string, weaponreplace, weaponreplace) \
75         w_prop(id, sn, float,  weaponstart, weaponstart) \
76         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
77         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
78
79 #ifdef SVQC
80 SEEKER_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
81 .entity tag_target, wps_tag_tracker;
82 .float tag_time;
83 #endif
84 #else
85 #ifdef SVQC
86 void spawnfunc_weapon_seeker(void) { weapon_defaultspawnfunc(WEP_SEEKER); }
87
88 // ============================
89 // Begin: Missile functions, these are general functions to be manipulated by other code
90 // ============================
91 void W_Seeker_Missile_Explode(void)
92 {
93         self.event_damage = func_null;
94         RadiusDamage(self, self.realowner, WEP_CVAR(seeker, missile_damage), WEP_CVAR(seeker, missile_edgedamage), WEP_CVAR(seeker, missile_radius), world, world, WEP_CVAR(seeker, missile_force), self.projectiledeathtype, other);
95
96         remove(self);
97 }
98
99 void W_Seeker_Missile_Touch(void)
100 {
101         PROJECTILE_TOUCH;
102
103         W_Seeker_Missile_Explode();
104 }
105
106 void W_Seeker_Missile_Think(void)
107 {
108         entity e;
109         vector desireddir, olddir, newdir, eorg;
110         float turnrate;
111         float dist;
112         float spd;
113
114         if(time > self.cnt)
115         {
116                 self.projectiledeathtype |= HITTYPE_SPLASH;
117                 W_Seeker_Missile_Explode();
118         }
119
120         spd = vlen(self.velocity);
121         spd = bound(
122                 spd - WEP_CVAR(seeker, missile_decel) * frametime,
123                 WEP_CVAR(seeker, missile_speed_max),
124                 spd + WEP_CVAR(seeker, missile_accel) * frametime
125         );
126
127         if(self.enemy != world)
128                 if(self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
129                         self.enemy = world;
130
131         if(self.enemy != world)
132         {
133                 e               = self.enemy;
134                 eorg            = 0.5 * (e.absmin + e.absmax);
135                 turnrate        = WEP_CVAR(seeker, missile_turnrate); // how fast to turn
136                 desireddir      = normalize(eorg - self.origin);
137                 olddir          = normalize(self.velocity); // get my current direction
138                 dist            = vlen(eorg - self.origin);
139
140                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
141                 if(WEP_CVAR(seeker, missile_smart) && (dist > WEP_CVAR(seeker, missile_smart_mindist)))
142                 {
143                         // Is it a better idea (shorter distance) to trace to the target itself?
144                         if( vlen(self.origin + olddir * self.wait) < dist)
145                                 traceline(self.origin, self.origin + olddir * self.wait, false, self);
146                         else
147                                 traceline(self.origin, eorg, false, self);
148
149                         // Setup adaptive tracelength
150                         self.wait = bound(WEP_CVAR(seeker, missile_smart_trace_min), vlen(self.origin - trace_endpos), self.wait = WEP_CVAR(seeker, missile_smart_trace_max));
151
152                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
153                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
154                 }
155
156                 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
157                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
158         }
159         else
160                 dist = 0;
161
162         // Proxy
163         if(WEP_CVAR(seeker, missile_proxy))
164         {
165                 if(dist <= WEP_CVAR(seeker, missile_proxy_maxrange))
166                 {
167                         if(self.autoswitch == 0)
168                         {
169                                 self.autoswitch = time + WEP_CVAR(seeker, missile_proxy_delay);
170                         }
171                         else
172                         {
173                                 if(self.autoswitch <= time)
174                                 {
175                                         W_Seeker_Missile_Explode();
176                                         self.autoswitch = 0;
177                                 }
178                         }
179                 }
180                 else
181                 {
182                         if(self.autoswitch != 0)
183                                 self.autoswitch = 0;
184                 }
185         }
186         ///////////////
187
188         if(self.enemy.deadflag != DEAD_NO)
189         {
190                 self.enemy = world;
191                 self.cnt = time + 1 + (random() * 4);
192                 self.nextthink = self.cnt;
193                 return;
194         }
195
196         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
197         self.nextthink = time;// + 0.05; // csqc projectiles
198         UpdateCSQCProjectile(self);
199 }
200
201
202
203 void W_Seeker_Missile_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
204 {
205         if(self.health <= 0)
206                 return;
207
208         if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
209                 return; // g_projectiles_damage says to halt
210
211         if(self.realowner == attacker)
212                 self.health = self.health - (damage * 0.25);
213         else
214                 self.health = self.health - damage;
215
216         if(self.health <= 0)
217                 W_PrepareExplosionByDamage(attacker, W_Seeker_Missile_Explode);
218 }
219
220 /*
221 void W_Seeker_Missile_Animate(void)
222 {
223         self.frame = self.frame +1;
224         self.nextthink = time + 0.05;
225
226         if(self.enemy != world)
227                 if(self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
228                         self.enemy = world;
229
230         if(self.frame == 5)
231         {
232                 self.think           = W_Seeker_Missile_Think;
233                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
234
235                 if(autocvar_g_balance_seeker_missile_proxy)
236                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
237                 else
238                         self.movetype    = MOVETYPE_FLYMISSILE;
239         }
240
241         UpdateCSQCProjectile(self);
242 }
243 */
244
245 void W_Seeker_Fire_Missile(vector f_diff, entity m_target)
246 {
247         entity missile;
248
249         W_DecreaseAmmo(WEP_CVAR(seeker, missile_ammo));
250
251         makevectors(self.v_angle);
252         W_SetupShot_ProjectileSize(self, '-2 -2 -2', '2 2 2', false, 2, "weapons/seeker_fire.wav", CH_WEAPON_A, 0);
253         w_shotorg += f_diff;
254         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
255
256         //self.detornator         = false;
257
258         missile                 = spawn();
259         missile.owner           = missile.realowner = self;
260         missile.classname       = "seeker_missile";
261         missile.bot_dodge       = true;
262         missile.bot_dodgerating = WEP_CVAR(seeker, missile_damage);
263
264         missile.think           = W_Seeker_Missile_Think;
265         missile.touch           = W_Seeker_Missile_Touch;
266         missile.event_damage    = W_Seeker_Missile_Damage;
267         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
268         missile.cnt             = time + WEP_CVAR(seeker, missile_lifetime);
269         missile.enemy           = m_target;
270         missile.solid           = SOLID_BBOX;
271         missile.scale           = 2;
272         missile.takedamage      = DAMAGE_YES;
273         missile.health          = WEP_CVAR(seeker, missile_health);
274         missile.damageforcescale = WEP_CVAR(seeker, missile_damageforcescale);
275         missile.damagedbycontents = true;
276         //missile.think           = W_Seeker_Missile_Animate; // csqc projectiles.
277
278         if(missile.enemy != world)
279                 missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
280         else
281                 missile.projectiledeathtype = WEP_SEEKER;
282
283
284         setorigin(missile, w_shotorg);
285         setsize(missile, '-4 -4 -4', '4 4 4');
286         missile.movetype    = MOVETYPE_FLYMISSILE;
287         missile.flags       = FL_PROJECTILE;
288         missile.missile_flags = MIF_SPLASH | MIF_GUIDED_TAG;
289
290         W_SetupProjVelocity_UP_PRE(missile, seeker, missile_);
291
292         missile.angles = vectoangles(missile.velocity);
293
294         CSQCProjectile(missile, false, PROJECTILE_SEEKER, true);
295
296         other = missile; MUTATOR_CALLHOOK(EditProjectile);
297 }
298
299 // ============================
300 // Begin: FLAC, close range attack meant for defeating rockets which are coming at you.
301 // ============================
302 void W_Seeker_Flac_Explode(void)
303 {
304         self.event_damage = func_null;
305
306         RadiusDamage(self, self.realowner, WEP_CVAR(seeker, flac_damage), WEP_CVAR(seeker, flac_edgedamage), WEP_CVAR(seeker, flac_radius), world, world, WEP_CVAR(seeker, flac_force), self.projectiledeathtype, other);
307
308         remove(self);
309 }
310
311 void W_Seeker_Flac_Touch(void)
312 {
313         PROJECTILE_TOUCH;
314
315         W_Seeker_Flac_Explode();
316 }
317
318 void W_Seeker_Fire_Flac(void)
319 {
320         entity missile;
321         vector f_diff;
322         float c;
323
324         W_DecreaseAmmo(WEP_CVAR(seeker, flac_ammo));
325
326         c = self.bulletcounter % 4;
327         switch(c)
328         {
329                 case 0:
330                         f_diff = '-1.25 -3.75 0';
331                         break;
332                 case 1:
333                         f_diff = '+1.25 -3.75 0';
334                         break;
335                 case 2:
336                         f_diff = '-1.25 +3.75 0';
337                         break;
338                 case 3:
339                 default:
340                         f_diff = '+1.25 +3.75 0';
341                         break;
342         }
343         W_SetupShot_ProjectileSize(self, '-2 -2 -2', '2 2 2', false, 2, "weapons/flac_fire.wav", CH_WEAPON_A, WEP_CVAR(seeker, flac_damage));
344         w_shotorg += f_diff;
345
346         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
347
348         missile                                 = spawn();
349         missile.owner                   = missile.realowner = self;
350         missile.classname               = "missile";
351         missile.bot_dodge               = true;
352         missile.bot_dodgerating = WEP_CVAR(seeker, flac_damage);
353         missile.touch                   = W_Seeker_Flac_Explode;
354         missile.use                     = W_Seeker_Flac_Explode;
355         missile.think                   = adaptor_think2use_hittype_splash;
356         missile.nextthink               = time + WEP_CVAR(seeker, flac_lifetime) + WEP_CVAR(seeker, flac_lifetime_rand);
357         missile.solid                   = SOLID_BBOX;
358         missile.movetype                = MOVETYPE_FLY;
359         missile.projectiledeathtype = WEP_SEEKER;
360         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
361         missile.flags                           = FL_PROJECTILE;
362         missile.missile_flags       = MIF_SPLASH;
363
364         // csqc projectiles
365         //missile.angles                                = vectoangles(missile.velocity);
366         //missile.scale = 0.4; // BUG: the model is too big
367
368         setorigin(missile, w_shotorg);
369         setsize(missile, '-2 -2 -2', '2 2 2');
370
371         W_SetupProjVelocity_UP_PRE(missile, seeker, flac_);
372         CSQCProjectile(missile, true, PROJECTILE_FLAC, true);
373
374         other = missile; MUTATOR_CALLHOOK(EditProjectile);
375 }
376
377 // ============================
378 // Begin: Tag and rocket controllers
379 // ============================
380 entity W_Seeker_Tagged_Info(entity isowner, entity istarget)
381 {
382         entity tag;
383         for(tag = world; (tag = find(tag, classname, "tag_tracker")); )
384                 if((tag.realowner == isowner) && (tag.tag_target == istarget))
385                         return tag;
386
387         return world;
388 }
389
390 void W_Seeker_Attack(void)
391 {
392         entity tracker, closest_target;
393
394         closest_target = world;
395         for(tracker = world; (tracker = find(tracker, classname, "tag_tracker")); ) if (tracker.realowner == self)
396         {
397                 if(closest_target)
398                 {
399                         if(vlen(self.origin - tracker.tag_target.origin) < vlen(self.origin - closest_target.origin))
400                                 closest_target = tracker.tag_target;
401                 }
402                 else
403                         closest_target = tracker.tag_target;
404         }
405
406         traceline(self.origin + self.view_ofs, closest_target.origin, MOVE_NOMONSTERS, self);
407         if((!closest_target) || ((trace_fraction < 1) && (trace_ent != closest_target)))
408                 closest_target = world;
409
410         W_Seeker_Fire_Missile('0 0 0', closest_target);
411 }
412
413 void W_Seeker_Vollycontroller_Think(void) // TODO: Merge this with W_Seeker_Attack
414 {
415         float c;
416         entity oldself,oldenemy;
417         self.cnt = self.cnt - 1;
418
419         if((!(self.realowner.items & IT_UNLIMITED_AMMO) && self.realowner.WEP_AMMO(SEEKER) < WEP_CVAR(seeker, missile_ammo)) || (self.cnt <= -1) || (self.realowner.deadflag != DEAD_NO) || (self.realowner.switchweapon != WEP_SEEKER))
420         {
421                 remove(self);
422                 return;
423         }
424
425         self.nextthink = time + WEP_CVAR(seeker, missile_delay) * W_WeaponRateFactor();
426
427         oldself = self;
428         self = self.realowner;
429
430         oldenemy = self.enemy;
431         self.enemy = oldself.enemy;
432
433         c = self.cnt % 4;
434         switch(c)
435         {
436                 case 0:
437                         W_Seeker_Fire_Missile('-1.25 -3.75 0', self.enemy);
438                         break;
439                 case 1:
440                         W_Seeker_Fire_Missile('+1.25 -3.75 0', self.enemy);
441                         break;
442                 case 2:
443                         W_Seeker_Fire_Missile('-1.25 +3.75 0', self.enemy);
444                         break;
445                 case 3:
446                 default:
447                         W_Seeker_Fire_Missile('+1.25 +3.75 0', self.enemy);
448                         break;
449         }
450
451         self.enemy = oldenemy;
452         self = oldself;
453 }
454
455 void W_Seeker_Tracker_Think(void)
456 {
457         // commit suicide if: You die OR target dies OR you switch away from the seeker OR commit suicide if lifetime is up
458         if((self.realowner.deadflag != DEAD_NO) || (self.tag_target.deadflag != DEAD_NO) || (self.realowner.switchweapon != WEP_SEEKER)
459         || (time > self.tag_time + WEP_CVAR(seeker, tag_tracker_lifetime)))
460         {
461                 if(self)
462                 {
463                         WaypointSprite_Kill(self.tag_target.wps_tag_tracker);
464                         remove(self);
465                 }
466                 return;
467         }
468
469         // Update the think method information
470         self.nextthink = time;
471 }
472
473 // ============================
474 // Begin: Tag projectile
475 // ============================
476 void W_Seeker_Tag_Explode(void)
477 {
478         //if(other==self.realowner)
479         //    return;
480         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, other.species, self);
481
482         remove(self);
483 }
484
485 void W_Seeker_Tag_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
486 {
487         if(self.health <= 0)
488                 return;
489         self.health = self.health - damage;
490         if(self.health <= 0)
491                 W_Seeker_Tag_Explode();
492 }
493
494 void W_Seeker_Tag_Touch(void)
495 {
496         vector dir;
497         vector org2;
498         entity e;
499
500         PROJECTILE_TOUCH;
501
502         dir     = normalize(self.realowner.origin - self.origin);
503         org2    = findbetterlocation(self.origin, 8);
504
505         te_knightspike(org2);
506
507         self.event_damage = func_null;
508         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE | HITTYPE_SECONDARY, other.species, self);
509
510         if(other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
511         {
512                 // check to see if this person is already tagged by me
513                 entity tag = W_Seeker_Tagged_Info(self.realowner, other);
514
515                 if(tag != world)
516                 {
517                         if(other.wps_tag_tracker && (WEP_CVAR(seeker, type) == 1)) // don't attach another waypointsprite without killing the old one first
518                                 WaypointSprite_Kill(other.wps_tag_tracker);
519
520                         tag.tag_time = time;
521                 }
522                 else
523                 {
524                         //sprint(self.realowner, strcat("You just tagged ^2", other.netname, "^7 with a tracking device!\n"));
525                         e             = spawn();
526                         e.cnt         = WEP_CVAR(seeker, missile_count);
527                         e.classname   = "tag_tracker";
528                         e.owner       = self.owner;
529                         e.realowner   = self.realowner;
530
531                         if(WEP_CVAR(seeker, type) == 1)
532                         {
533                                 e.tag_target  = other;
534                                 e.tag_time    = time;
535                                 e.think       = W_Seeker_Tracker_Think;
536                         }
537                         else
538                         {
539                                 e.enemy     = other;
540                                 e.think     = W_Seeker_Vollycontroller_Think;
541                         }
542
543                         e.nextthink   = time;
544                 }
545
546                 if(WEP_CVAR(seeker, type) == 1)
547                 {
548                         WaypointSprite_Spawn("tagged-target", WEP_CVAR(seeker, tag_tracker_lifetime), 0, other, '0 0 64', self.realowner, 0, other, wps_tag_tracker, true, RADARICON_TAGGED, '0.5 1 0');
549                         WaypointSprite_UpdateRule(other.wps_tag_tracker, 0, SPRITERULE_DEFAULT);
550                 }
551         }
552
553         remove(self);
554         return;
555 }
556
557 void W_Seeker_Fire_Tag(void)
558 {
559         entity missile;
560         W_DecreaseAmmo(WEP_CVAR(seeker, tag_ammo));
561
562         W_SetupShot_ProjectileSize(self, '-2 -2 -2', '2 2 2', false, 2, "weapons/tag_fire.wav", CH_WEAPON_A, WEP_CVAR(seeker, missile_damage) * WEP_CVAR(seeker, missile_count));
563
564         missile                 = spawn();
565         missile.owner           = missile.realowner = self;
566         missile.classname       = "seeker_tag";
567         missile.bot_dodge       = true;
568         missile.bot_dodgerating = 50;
569         missile.touch           = W_Seeker_Tag_Touch;
570         missile.think           = SUB_Remove;
571         missile.nextthink       = time + WEP_CVAR(seeker, tag_lifetime);
572         missile.movetype        = MOVETYPE_FLY;
573         missile.solid           = SOLID_BBOX;
574
575         missile.takedamage       = DAMAGE_YES;
576         missile.event_damage     = W_Seeker_Tag_Damage;
577         missile.health           = WEP_CVAR(seeker, tag_health);
578         missile.damageforcescale = WEP_CVAR(seeker, tag_damageforcescale);
579
580         setorigin(missile, w_shotorg);
581         setsize(missile, '-2 -2 -2', '2 2 2');
582
583         missile.flags       = FL_PROJECTILE;
584         //missile.missile_flags = MIF_..?;
585
586         missile.movetype    = MOVETYPE_FLY;
587         W_SetupProjVelocity_PRE(missile, seeker, tag_);
588         missile.angles = vectoangles(missile.velocity);
589
590         CSQCProjectile(missile, true, PROJECTILE_TAG, false); // has sound
591
592         other = missile; MUTATOR_CALLHOOK(EditProjectile);
593 }
594
595 // ============================
596 // Begin: Genereal weapon functions
597 // ============================
598
599 float W_Seeker(float req)
600 {
601         float ammo_amount;
602
603         switch(req)
604         {
605                 case WR_AIM:
606                 {
607                         if(WEP_CVAR(seeker, type) == 1)
608                                 if(W_Seeker_Tagged_Info(self, self.enemy) != world)
609                                         self.BUTTON_ATCK = bot_aim(WEP_CVAR(seeker, missile_speed_max), 0, WEP_CVAR(seeker, missile_lifetime), false);
610                                 else
611                                         self.BUTTON_ATCK2 = bot_aim(WEP_CVAR(seeker, tag_speed), 0, WEP_CVAR(seeker, tag_lifetime), false);
612                         else
613                                 self.BUTTON_ATCK = bot_aim(WEP_CVAR(seeker, tag_speed), 0, WEP_CVAR(seeker, tag_lifetime), false);
614                         return true;
615                 }
616                 case WR_THINK:
617                 {
618                         if(autocvar_g_balance_seeker_reload_ammo && self.clip_load < min(WEP_CVAR(seeker, missile_ammo), WEP_CVAR(seeker, tag_ammo))) // forced reload
619                                 WEP_ACTION(self.weapon, WR_RELOAD);
620
621                         else if(self.BUTTON_ATCK)
622                         {
623                                 if(WEP_CVAR(seeker, type) == 1)
624                                 {
625                                         if(weapon_prepareattack(0, WEP_CVAR(seeker, missile_refire)))
626                                         {
627                                                 W_Seeker_Attack();
628                                                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(seeker, missile_animtime), w_ready);
629                                         }
630                                 }
631                                 else
632                                 {
633                                         if(weapon_prepareattack(0, WEP_CVAR(seeker, tag_refire)))
634                                         {
635                                                 W_Seeker_Fire_Tag();
636                                                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(seeker, tag_animtime), w_ready);
637                                         }
638                                 }
639                         }
640
641                         else if(self.BUTTON_ATCK2)
642                         {
643                                 if(WEP_CVAR(seeker, type) == 1)
644                                 {
645                                         if(weapon_prepareattack(0, WEP_CVAR(seeker, tag_refire)))
646                                         {
647                                                 W_Seeker_Fire_Tag();
648                                                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(seeker, tag_animtime), w_ready);
649                                         }
650                                 }
651                                 else
652                                 {
653                                         if(weapon_prepareattack(0, WEP_CVAR(seeker, flac_refire)))
654                                         {
655                                                 W_Seeker_Fire_Flac();
656                                                 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR(seeker, flac_animtime), w_ready);
657                                         }
658                                 }
659                         }
660
661                         return true;
662                 }
663                 case WR_INIT:
664                 {
665                         precache_model("models/weapons/g_seeker.md3");
666                         precache_model("models/weapons/v_seeker.md3");
667                         precache_model("models/weapons/h_seeker.iqm");
668                         precache_sound("weapons/tag_fire.wav");
669                         precache_sound("weapons/flac_fire.wav");
670                         precache_sound("weapons/seeker_fire.wav");
671                         SEEKER_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
672                         return true;
673                 }
674                 case WR_CHECKAMMO1:
675                 {
676                         if(WEP_CVAR(seeker, type) == 1)
677                         {
678                                 ammo_amount = self.WEP_AMMO(SEEKER) >= WEP_CVAR(seeker, missile_ammo);
679                                 ammo_amount += self.(weapon_load[WEP_SEEKER]) >= WEP_CVAR(seeker, missile_ammo);
680                         }
681                         else
682                         {
683                                 ammo_amount = self.WEP_AMMO(SEEKER) >= WEP_CVAR(seeker, tag_ammo);
684                                 ammo_amount += self.(weapon_load[WEP_SEEKER]) >= WEP_CVAR(seeker, tag_ammo);
685                         }
686                         return ammo_amount;
687                 }
688                 case WR_CHECKAMMO2:
689                 {
690                         if(WEP_CVAR(seeker, type) == 1)
691                         {
692                                 ammo_amount = self.WEP_AMMO(SEEKER) >= WEP_CVAR(seeker, tag_ammo);
693                                 ammo_amount += self.(weapon_load[WEP_SEEKER]) >= WEP_CVAR(seeker, tag_ammo);
694                         }
695                         else
696                         {
697                                 ammo_amount = self.WEP_AMMO(SEEKER) >= WEP_CVAR(seeker, flac_ammo);
698                                 ammo_amount += self.(weapon_load[WEP_SEEKER]) >= WEP_CVAR(seeker, flac_ammo);
699                         }
700                         return ammo_amount;
701                 }
702                 case WR_CONFIG:
703                 {
704                         SEEKER_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
705                         return true;
706                 }
707                 case WR_RELOAD:
708                 {
709                         W_Reload(min(WEP_CVAR(seeker, missile_ammo), WEP_CVAR(seeker, tag_ammo)), "weapons/reload.wav");
710                         return true;
711                 }
712                 case WR_SUICIDEMESSAGE:
713                 {
714                         return WEAPON_SEEKER_SUICIDE;
715                 }
716                 case WR_KILLMESSAGE:
717                 {
718                         if(w_deathtype & HITTYPE_SECONDARY)
719                                 return WEAPON_SEEKER_MURDER_TAG;
720                         else
721                                 return WEAPON_SEEKER_MURDER_SPRAY;
722                 }
723         }
724         return false;
725 }
726 #endif
727 #ifdef CSQC
728 float W_Seeker(float req)
729 {
730         switch(req)
731         {
732                 case WR_IMPACTEFFECT:
733                 {
734                         vector org2;
735                         org2 = w_org + w_backoff * 6;
736                         if(w_deathtype & HITTYPE_BOUNCE)
737                         {
738                                 if(w_deathtype & HITTYPE_SECONDARY)
739                                 {
740                                         if(!w_issilent)
741                                                 sound(self, CH_SHOTS, "weapons/tag_impact.wav", 1, ATTEN_NORM);
742                                 }
743                                 else
744                                 {
745                                         pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
746                                         if(!w_issilent)
747                                         {
748                                                 if(w_random<0.15)
749                                                         sound(self, CH_SHOTS, "weapons/tagexp1.wav", 1, ATTEN_NORM);
750                                                 else if(w_random<0.7)
751                                                         sound(self, CH_SHOTS, "weapons/tagexp2.wav", 1, ATTEN_NORM);
752                                                 else
753                                                         sound(self, CH_SHOTS, "weapons/tagexp3.wav", 1, ATTEN_NORM);
754                                         }
755                                 }
756                         }
757                         else
758                         {
759                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
760                                 if(!w_issilent)
761                                 {
762                                         if(w_random<0.15)
763                                                 sound(self, CH_SHOTS, "weapons/seekerexp1.wav", 1, ATTEN_NORM);
764                                         else if(w_random<0.7)
765                                                 sound(self, CH_SHOTS, "weapons/seekerexp2.wav", 1, ATTEN_NORM);
766                                         else
767                                                 sound(self, CH_SHOTS, "weapons/seekerexp3.wav", 1, ATTEN_NORM);
768                                 }
769                         }
770                         return true;
771                 }
772                 case WR_INIT:
773                 {
774                         precache_sound("weapons/seekerexp1.wav");
775                         precache_sound("weapons/seekerexp2.wav");
776                         precache_sound("weapons/seekerexp3.wav");
777                         precache_sound("weapons/tagexp1.wav");
778                         precache_sound("weapons/tagexp2.wav");
779                         precache_sound("weapons/tagexp3.wav");
780                         precache_sound("weapons/tag_impact.wav");
781                         return true;
782                 }
783                 case WR_ZOOMRETICLE:
784                 {
785                         // no weapon specific image for this weapon
786                         return false;
787                 }
788         }
789         return false;
790 }
791 #endif
792 #endif