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