properly set the HITTYPE_BOUNCE flag on all timeout detonations
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_seeker.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SEEKER, w_seeker, IT_ROCKETS, 9, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "seeker", "seeker", "T.A.G. Seeker");
3 #else
4 //.float speed; = switchweapon
5 //.float proxytime; = autoswitch
6 //.float tl; = wait
7
8 void Seeker_Missile_Explode ()
9 {
10         self.event_damage = SUB_Null;
11         RadiusDamage (self, self.owner, cvar("g_balance_seeker_missile_damage"), cvar("g_balance_seeker_missile_edgedamage"), cvar("g_balance_seeker_missile_radius"), world, cvar("g_balance_seeker_missile_force"), self.projectiledeathtype, other);
12
13         remove (self);
14 }
15
16 void Seeker_Missile_Touch()
17 {
18         PROJECTILE_TOUCH;
19
20         Seeker_Missile_Explode();
21 }
22
23 void Seeker_Missile_Think()
24 {
25         entity e;
26         vector desireddir, olddir, newdir, eorg;
27         float turnrate;
28         float dist;
29
30         if (time > self.cnt)
31         {
32                 self.projectiledeathtype |= HITTYPE_SPLASH;
33                 Seeker_Missile_Explode();
34         }
35
36         if (!self.switchweapon)
37                 self.switchweapon = cvar("g_balance_seeker_missile_speed");
38
39         if ((self.switchweapon < cvar("g_balance_seeker_missile_speed_max")) && cvar("g_balance_seeker_missile_speed_accel"))
40                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_accel");
41
42         if (self.switchweapon > cvar("g_balance_seeker_missile_speed_max"))
43                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_decel");
44
45         if (self.enemy != world)
46                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
47                         self.enemy = world;
48
49         if (self.enemy != world)
50         {
51                 e               = self.enemy;
52                 eorg            = 0.5 * (e.absmin + e.absmax);
53                 turnrate        = cvar("g_balance_seeker_missile_turnrate");                // how fast to turn
54                 desireddir      = normalize(eorg - self.origin);
55                 olddir          = normalize(self.velocity);                                         // get my current direction
56                 dist            = vlen(eorg - self.origin);
57
58                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
59                 if (cvar("g_balance_seeker_missile_smart") && (dist > cvar("g_balance_seeker_missile_smart_mindist")))
60                 {
61                         // Is it a better idea (shorter distance) to trace to the target itself?
62                         if ( vlen(self.origin + olddir * self.wait) < dist)
63                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
64                         else
65                                 traceline(self.origin, eorg, FALSE, self);
66
67                         // Setup adaptive tracelength
68                         self.wait = vlen(self.origin - trace_endpos);
69                         if (self.wait < cvar("g_balance_seeker_missile_smart_trace_min")) self.wait = cvar("g_balance_seeker_missile_smart_trace_min");
70                         if (self.wait > cvar("g_balance_seeker_missile_smart_trace_max")) self.wait = cvar("g_balance_seeker_missile_smart_trace_max");
71
72                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
73                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
74                 }
75
76                 //newdir = normalize((olddir + desireddir * turnrate) * 0.5);// take the average of the 2 directions; not the best method but simple & easy
77                 newdir = normalize(olddir + desireddir * turnrate);// take the average of the 2 directions; not the best method but simple & easy
78
79                 self.velocity = newdir * self.switchweapon;                                         // make me fly in the new direction at my flight speed
80         }
81
82         // Proxy
83         if (cvar("g_balance_seeker_missile_proxy"))
84         {
85                 if ( dist <= cvar("g_balance_seeker_missile_proxy_maxrange"))
86                 {
87                         if (self.autoswitch == 0)
88                         {
89                                 self.autoswitch = time + cvar("g_balance_seeker_missile_proxy_delay");
90                         }
91                         else
92                         {
93                                 if (self.autoswitch <= time)
94                                 {
95                                         Seeker_Missile_Explode();
96                                         self.autoswitch = 0;
97                                 }
98                         }
99                 }
100                 else
101                 {
102                         if (self.autoswitch != 0)
103                                 self.autoswitch = 0;
104                 }
105         }
106         ///////////////
107
108         if (self.enemy.deadflag != DEAD_NO)
109         {
110                 self.enemy = world;
111                 self.cnt = time + 1 + (random() * 4);
112                 self.nextthink = self.cnt;
113                 return;
114         }
115
116         self.angles = vectoangles(self.velocity);                       // turn model in the new flight direction
117         self.nextthink = time + 0.05;
118
119         UpdateCSQCProjectile(self);
120 }
121
122
123
124 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
125 {
126         float d;
127         d = damage;
128
129         if (self.health <= 0)
130                 return;
131
132         if (self.owner == attacker)
133                 d = d * 0.25;
134
135         self.health = self.health - d;
136
137         if (self.health <= 0)
138                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
139 }
140
141 void Seeker_Missile_Animate()
142 {
143         self.frame = self.frame +1;
144         self.nextthink = time + 0.05;
145
146         if (self.enemy != world)
147                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
148                         self.enemy = world;
149
150         if(self.frame == 5)
151         {
152                 self.think           = Seeker_Missile_Think;
153                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
154
155                 if (cvar("g_balance_seeker_missile_proxy"))
156                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
157                 else
158                         self.movetype    = MOVETYPE_FLYMISSILE;
159         }
160
161         UpdateCSQCProjectile(self);
162 }
163
164 void Seeker_Fire_Missile(vector f_diff)
165 {
166         local entity missile;
167
168         if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
169                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_missile_ammo");
170
171         makevectors(self.v_angle);
172         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", cvar("g_balance_seeker_missile_damage"));
173         w_shotorg += f_diff;
174         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
175
176         //self.detornator         = FALSE;
177
178         missile                 = spawn();
179         missile.owner           = self;
180         missile.classname       = "seeker_missile";
181         missile.bot_dodge       = TRUE;
182         missile.bot_dodgerating = cvar("g_balance_seeker_missile_damage");
183
184         missile.think           = Seeker_Missile_Animate;
185
186         //if (!cvar("g_balance_seeker_missile_proxy"))
187         missile.touch           = Seeker_Missile_Touch;
188
189         missile.event_damage    = Seeker_Missile_Damage;
190         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
191         missile.cnt             = time + cvar("g_balance_seeker_missile_lifetime");
192         missile.enemy           = self.enemy;
193         missile.solid           = SOLID_BBOX;
194         missile.scale           = 2;
195         missile.takedamage          = DAMAGE_YES;
196         missile.health          = cvar("g_balance_seeker_missile_health");
197         missile.damageforcescale = cvar("g_balance_seeker_missile_damageforcescale");
198         missile.projectiledeathtype = WEP_SEEKER;
199
200         setorigin (missile, w_shotorg);
201         setsize (missile, '-4 -4 -4', '4 4 4');
202
203
204         missile.movetype    = MOVETYPE_FLYMISSILE;// MOVETYPE_TOSS;
205
206         missile.flags       = FL_PROJECTILE;
207
208         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
209
210         missile.switchweapon = vlen(missile.velocity);
211         missile.angles = vectoangles (missile.velocity);
212
213         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
214 }
215
216 void Seeker_Vollycontroler_Think()
217 {
218         float c;
219         entity oldself,oldenemy;
220         self.cnt = self.cnt - 1;
221
222         if((!(self.owner.items & IT_UNLIMITED_AMMO) && self.owner.ammo_rockets < cvar("g_balance_seeker_missile_ammo")) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO))
223         {
224                 remove(self);
225                 return;
226         }
227
228         self.nextthink = time + cvar("g_balance_seeker_missile_delay");
229
230         oldself = self;
231         self = self.owner;
232
233         oldenemy = self.enemy;
234         self.enemy = oldself.enemy;
235
236         c = mod(oldself.cnt, 4);
237         switch(c)
238         {
239                 case 0:
240                         Seeker_Fire_Missile('-1.25 -3.75 0');
241                         break;
242                 case 1:
243                         Seeker_Fire_Missile('+1.25 -3.75 0');
244                         break;
245                 case 2:
246                         Seeker_Fire_Missile('-1.25 +3.75 0');
247                         break;
248                 case 3:
249                 default:
250                         Seeker_Fire_Missile('+1.25 +3.75 0');
251                         break;
252         }
253
254         self.enemy = oldenemy;
255         self = oldself;
256 }
257
258 void Seeker_Tag_Explode ()
259 {
260         //if(other==self.owner)
261         //    return;
262         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
263
264         remove (self);
265 }
266
267 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
268 {
269         if (self.health <= 0)
270                 return;
271         self.health = self.health - damage;
272         if (self.health <= 0)
273                 Seeker_Tag_Explode();
274 }
275
276 void Seeker_Tag_Think()
277 {
278         remove(self);
279         return;
280 }
281
282 void Seeker_Tag_Touch()
283 {
284         vector dir;
285         vector org2;
286
287         dir     = normalize (self.owner.origin - self.origin);
288         org2    = findbetterlocation (self.origin, 8);
289
290         te_knightspike(org2);
291
292         self.event_damage = SUB_Null;
293         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
294
295         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
296         {
297                 entity e;
298                 e           = spawn();
299                 e.cnt       = cvar("g_balance_seeker_missile_count");
300                 e.owner     = self.owner;
301                 e.enemy     = other;
302                 e.think     = Seeker_Vollycontroler_Think;
303                 e.nextthink = time;
304
305                 //sprint(self.owner, "^1Target lock ^3[^7 ",other.netname, " ^3]^1 acquired - autofire activated.\n");
306                 //sprint(other,"^1You are targeted!\n");
307
308                 // stuffcmd(other,"play2 weapons/zany-alarm4.ogg\n");
309                 // stuffcmd(self.owner, "play2 weapons/zany-lock4.ogg\n");
310         }
311
312         remove(self);
313         return;
314 }
315
316
317
318 void Seeker_Fire_Tag()
319 {
320         local entity missile;
321         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
322                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_tag_ammo");
323
324         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/tag_fire.wav", 0);
325
326         missile                 = spawn();
327         missile.owner           = self;
328         missile.classname       = "seeker_tag";
329         missile.bot_dodge       = TRUE;
330         missile.bot_dodgerating = 50;
331         missile.touch           = Seeker_Tag_Touch;
332         missile.think           = Seeker_Tag_Think;
333         missile.nextthink       = time + cvar("g_balance_seeker_tag_lifetime");
334         missile.movetype        = MOVETYPE_FLY;
335         missile.solid           = SOLID_BBOX;
336         missile.owner           = self;
337
338         missile.takedamage       = DAMAGE_YES;
339         missile.event_damage    = Seeker_Tag_Explode;
340         missile.health          = cvar("g_balance_seeker_tag_health");
341         missile.damageforcescale = cvar("g_balance_seeker_tag_damageforcescale");
342
343         setorigin (missile, w_shotorg);
344         setsize (missile, '-2 -2 -2', '2 2 2');
345
346         missile.flags       = FL_PROJECTILE;
347
348         missile.movetype    = MOVETYPE_FLY;
349         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
350         missile.angles = vectoangles (missile.velocity);
351
352         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
353 }
354
355
356 void Seeker_Flac_Explode ()
357 {
358         self.event_damage = SUB_Null;
359
360         RadiusDamage (self, self.owner, cvar("g_balance_seeker_flac_damage"), cvar("g_balance_seeker_flac_edgedamage"), cvar("g_balance_seeker_flac_radius"), world, cvar("g_balance_seeker_flac_force"), self.projectiledeathtype, other);
361
362         remove (self);
363 }
364
365 void Seeker_Flac_Touch()
366 {
367         PROJECTILE_TOUCH;
368
369         Seeker_Flac_Explode();
370 }
371
372 void Seeker_Fire_Flac()
373 {
374         local entity missile;
375         vector f_diff;
376         float c;
377
378         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
379                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_flac_ammo");
380
381         c = mod(self.bulletcounter, 4);
382         switch(c)
383         {
384                 case 0:
385                         f_diff = '-1.25 -3.75 0';
386                         break;
387                 case 1:
388                         f_diff = '+1.25 -3.75 0';
389                         break;
390                 case 2:
391                         f_diff = '-1.25 +3.75 0';
392                         break;
393                 case 3:
394                 default:
395                         f_diff = '+1.25 +3.75 0';
396                         break;
397         }
398         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", cvar("g_balance_seeker_flac_damage"));
399         w_shotorg += f_diff;
400
401         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
402
403         missile = spawn ();
404         missile.owner = missile.realowner = self;
405         missile.classname = "missile";
406         missile.bot_dodge = TRUE;
407         missile.bot_dodgerating = cvar("g_balance_seeker_flac_damage");
408         missile.touch = Seeker_Flac_Explode;
409         missile.use = Seeker_Flac_Explode;
410         missile.think = adaptor_think2use_hittype_splash;
411         missile.nextthink = time + cvar("g_balance_seeker_flac_lifetime") + cvar("g_balance_seeker_flac_lifetime_rand");
412         missile.solid = SOLID_BBOX;
413         missile.scale = 0.4; // BUG: the model is too big
414         missile.projectiledeathtype = WEP_SEEKER;
415         setorigin (missile, w_shotorg);
416         setsize (missile, '-2 -2 -2', '2 2 2');
417         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
418
419         missile.movetype = MOVETYPE_FLY;
420         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
421
422         missile.angles = vectoangles (missile.velocity);
423         missile.flags = FL_PROJECTILE;
424
425         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
426 }
427
428 void spawnfunc_weapon_seeker (void)
429 {
430         weapon_defaultspawnfunc(WEP_SEEKER);
431 }
432
433 float w_seeker(float req)
434 {
435         if (req == WR_AIM)
436                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_seeker_tag_speed"), 0, 20, FALSE);
437
438         else if (req == WR_THINK)
439         {
440                 if (self.BUTTON_ATCK)
441                         if (weapon_prepareattack(0, cvar("g_balance_seeker_tag_refire")))
442                         {
443                                 Seeker_Fire_Tag();
444                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_seeker_tag_animtime"), w_ready);
445                         }
446
447                 if (self.BUTTON_ATCK2)
448                         if (weapon_prepareattack(1, cvar("g_balance_seeker_flac_refire")))
449                         {
450                                 Seeker_Fire_Flac();
451                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_seeker_flac_animtime"), w_ready);
452                         }
453
454         }
455         else if (req == WR_PRECACHE)
456         {
457                 precache_model ("models/weapons/g_seeker.md3");
458                 precache_model ("models/weapons/v_seeker.md3");
459                 precache_model ("models/weapons/h_seeker.iqm");
460                 precache_sound ("weapons/tag_fire.wav");
461                 precache_sound ("weapons/flac_fire.wav");
462                 precache_sound ("weapons/seeker_fire.wav");
463         }
464         else if (req == WR_SETUP)
465                 weapon_setup(WEP_SEEKER);
466         else if (req == WR_CHECKAMMO1)
467                 return self.ammo_rockets >= cvar("g_balance_seeker_tag_ammo") + cvar("g_balance_seeker_missile_ammo");
468         else if (req == WR_CHECKAMMO2)
469                 return self.ammo_rockets >= cvar("g_balance_seeker_flac_ammo");
470         else if (req == WR_SUICIDEMESSAGE)
471                 w_deathtypestring = "played with tiny rockets";
472         else if (req == WR_KILLMESSAGE)
473         {
474                 if(w_deathtype & HITTYPE_SECONDARY)
475                         w_deathtypestring = "ran into #'s flac";
476                 else
477                         w_deathtypestring = "was tagged by";
478         }
479         return TRUE;
480 };
481 #endif