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