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