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