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