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