]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
Merge branch 'master' into mirceakitsune/universal_reload_system
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_seeker.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SEEKER, w_seeker, IT_ROCKETS, 8, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "seeker", "seeker", _("T.A.G. Seeker"))
3 #else
4 #ifdef SVQC
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, autocvar_g_balance_seeker_missile_damage, autocvar_g_balance_seeker_missile_edgedamage, autocvar_g_balance_seeker_missile_radius, world, autocvar_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         float spd;
30
31         if (time > self.cnt)
32         {
33                 self.projectiledeathtype |= HITTYPE_SPLASH;
34                 Seeker_Missile_Explode();
35         }
36
37         spd = vlen(self.velocity);
38         spd = bound(
39                 spd - autocvar_g_balance_seeker_missile_decel * frametime,
40                 autocvar_g_balance_seeker_missile_speed_max,
41                 spd + autocvar_g_balance_seeker_missile_accel * frametime
42         );
43
44         if (self.enemy != world)
45                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
46                         self.enemy = world;
47
48         if (self.enemy != world)
49         {
50                 e               = self.enemy;
51                 eorg            = 0.5 * (e.absmin + e.absmax);
52                 turnrate        = autocvar_g_balance_seeker_missile_turnrate; // how fast to turn
53                 desireddir      = normalize(eorg - self.origin);
54                 olddir          = normalize(self.velocity); // get my current direction
55                 dist            = vlen(eorg - self.origin);
56
57                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
58                 if (autocvar_g_balance_seeker_missile_smart && (dist > autocvar_g_balance_seeker_missile_smart_mindist))
59                 {
60                         // Is it a better idea (shorter distance) to trace to the target itself?
61                         if ( vlen(self.origin + olddir * self.wait) < dist)
62                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
63                         else
64                                 traceline(self.origin, eorg, FALSE, self);
65
66                         // Setup adaptive tracelength
67                         self.wait = bound(autocvar_g_balance_seeker_missile_smart_trace_min, vlen(self.origin - trace_endpos), self.wait = autocvar_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); // take the average of the 2 directions; not the best method but simple & easy
74                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
75         }
76
77         // Proxy
78         if (autocvar_g_balance_seeker_missile_proxy)
79         {
80                 if ( dist <= autocvar_g_balance_seeker_missile_proxy_maxrange)
81                 {
82                         if (self.autoswitch == 0)
83                         {
84                                 self.autoswitch = time + autocvar_g_balance_seeker_missile_proxy_delay;
85                         }
86                         else
87                         {
88                                 if (self.autoswitch <= time)
89                                 {
90                                         Seeker_Missile_Explode();
91                                         self.autoswitch = 0;
92                                 }
93                         }
94                 }
95                 else
96                 {
97                         if (self.autoswitch != 0)
98                                 self.autoswitch = 0;
99                 }
100         }
101         ///////////////
102
103         if (self.enemy.deadflag != DEAD_NO)
104         {
105                 self.enemy = world;
106                 self.cnt = time + 1 + (random() * 4);
107                 self.nextthink = self.cnt;
108                 return;
109         }
110
111         //self.angles = vectoangles(self.velocity);                     // turn model in the new flight direction
112         self.nextthink = time;// + 0.05; // csqc projectiles
113         UpdateCSQCProjectile(self);
114 }
115
116
117
118 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
119 {
120         if (self.health <= 0)
121                 return;
122
123         if (self.owner == attacker)
124                 self.health = self.health - (damage * 0.25);
125         else
126                 self.health = self.health - damage;
127                 
128         if (self.health <= 0)
129                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
130 }
131
132 /*
133 void Seeker_Missile_Animate()
134 {
135         self.frame = self.frame +1;
136         self.nextthink = time + 0.05;
137
138         if (self.enemy != world)
139                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
140                         self.enemy = world;
141
142         if(self.frame == 5)
143         {
144                 self.think           = Seeker_Missile_Think;
145                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
146
147                 if (autocvar_g_balance_seeker_missile_proxy)
148                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
149                 else
150                         self.movetype    = MOVETYPE_FLYMISSILE;
151         }
152
153         UpdateCSQCProjectile(self);
154 }
155 */
156
157 void Seeker_Fire_Missile(vector f_diff)
158 {
159         local entity missile;
160
161         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_reload_ammo);
162
163         makevectors(self.v_angle);
164         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", CHAN_WEAPON, 0);
165         w_shotorg += f_diff;
166         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
167
168         //self.detornator         = FALSE;
169
170         missile                 = spawn();
171         missile.owner           = self;
172         missile.classname       = "seeker_missile";
173         missile.bot_dodge       = TRUE;
174         missile.bot_dodgerating = autocvar_g_balance_seeker_missile_damage;
175
176         missile.think           = Seeker_Missile_Think;
177         missile.touch           = Seeker_Missile_Touch;
178         missile.event_damage    = Seeker_Missile_Damage;
179         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
180         missile.cnt             = time + autocvar_g_balance_seeker_missile_lifetime;
181         missile.enemy           = self.enemy;
182         missile.solid           = SOLID_BBOX;
183         missile.scale           = 2;
184         missile.takedamage      = DAMAGE_YES;
185         missile.health          = autocvar_g_balance_seeker_missile_health;
186         missile.damageforcescale = autocvar_g_balance_seeker_missile_damageforcescale;
187         missile.projectiledeathtype = WEP_SEEKER;
188         //missile.think           = Seeker_Missile_Animate; // csqc projectiles.
189
190
191         setorigin (missile, w_shotorg);
192         setsize (missile, '-4 -4 -4', '4 4 4');
193         missile.movetype    = MOVETYPE_FLYMISSILE;
194         missile.flags       = FL_PROJECTILE;
195         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
196
197         missile.angles = vectoangles (missile.velocity);
198
199         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
200
201         other = missile; MUTATOR_CALLHOOK(EditProjectile);
202 }
203
204 void Seeker_Vollycontroler_Think()
205 {
206         float c;
207         entity oldself,oldenemy;
208         self.cnt = self.cnt - 1;
209
210         if((!(self.owner.items & IT_UNLIMITED_AMMO) && self.owner.ammo_rockets < autocvar_g_balance_seeker_missile_ammo) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO) || (self.owner.switchweapon != WEP_SEEKER))
211         {
212                 remove(self);
213                 return;
214         }
215
216         self.nextthink = time + autocvar_g_balance_seeker_missile_delay;
217
218         oldself = self;
219         self = self.owner;
220
221         oldenemy = self.enemy;
222         self.enemy = oldself.enemy;
223
224         c = mod(oldself.cnt, 4);
225         switch(c)
226         {
227                 case 0:
228                         Seeker_Fire_Missile('-1.25 -3.75 0');
229                         break;
230                 case 1:
231                         Seeker_Fire_Missile('+1.25 -3.75 0');
232                         break;
233                 case 2:
234                         Seeker_Fire_Missile('-1.25 +3.75 0');
235                         break;
236                 case 3:
237                 default:
238                         Seeker_Fire_Missile('+1.25 +3.75 0');
239                         break;
240         }
241
242         self.enemy = oldenemy;
243         self = oldself;
244 }
245
246 void Seeker_Tag_Explode ()
247 {
248         //if(other==self.owner)
249         //    return;
250         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
251
252         remove (self);
253 }
254
255 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
256 {
257         if (self.health <= 0)
258                 return;
259         self.health = self.health - damage;
260         if (self.health <= 0)
261                 Seeker_Tag_Explode();
262 }
263
264
265 void Seeker_Tag_Touch()
266 {
267         vector dir;
268         vector org2;
269         entity e;
270         
271         dir     = normalize (self.owner.origin - self.origin);
272         org2    = findbetterlocation (self.origin, 8);
273
274         te_knightspike(org2);
275
276         self.event_damage = SUB_Null;
277         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
278
279         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
280         {               
281                 e           = spawn();
282                 e.cnt       = autocvar_g_balance_seeker_missile_count;
283                 e.owner     = self.owner;
284                 e.enemy     = other;
285                 e.think     = Seeker_Vollycontroler_Think;
286                 e.nextthink = time;
287         }
288
289         remove(self);
290         return;
291 }
292
293 void Seeker_Fire_Tag()
294 {
295         local entity missile;
296         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_seeker_tag_ammo, autocvar_g_balance_seeker_reload_ammo);
297
298         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/tag_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_missile_damage * autocvar_g_balance_seeker_missile_count);
299
300         missile                 = spawn();
301         missile.owner           = self;
302         missile.classname       = "seeker_tag";
303         missile.bot_dodge       = TRUE;
304         missile.bot_dodgerating = 50;
305         missile.touch           = Seeker_Tag_Touch;
306         missile.think           = SUB_Remove;
307         missile.nextthink       = time + autocvar_g_balance_seeker_tag_lifetime;
308         missile.movetype        = MOVETYPE_FLY;
309         missile.solid           = SOLID_BBOX;
310         missile.owner           = self;
311
312         missile.takedamage       = DAMAGE_YES;
313         missile.event_damage    = Seeker_Tag_Explode;
314         missile.health          = autocvar_g_balance_seeker_tag_health;
315         missile.damageforcescale = autocvar_g_balance_seeker_tag_damageforcescale;
316
317         setorigin (missile, w_shotorg);
318         setsize (missile, '-2 -2 -2', '2 2 2');
319
320         missile.flags       = FL_PROJECTILE;
321
322         missile.movetype    = MOVETYPE_FLY;
323         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
324         missile.angles = vectoangles (missile.velocity);
325
326         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
327
328         other = missile; MUTATOR_CALLHOOK(EditProjectile);
329 }
330
331
332 void Seeker_Flac_Explode ()
333 {
334         self.event_damage = SUB_Null;
335
336         RadiusDamage (self, self.owner, autocvar_g_balance_seeker_flac_damage, autocvar_g_balance_seeker_flac_edgedamage, autocvar_g_balance_seeker_flac_radius, world, autocvar_g_balance_seeker_flac_force, self.projectiledeathtype, other);
337
338         remove (self);
339 }
340
341 void Seeker_Flac_Touch()
342 {
343         PROJECTILE_TOUCH;
344
345         Seeker_Flac_Explode();
346 }
347
348 void Seeker_Fire_Flac()
349 {
350         local entity missile;
351         vector f_diff;
352         float c;
353
354         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_seeker_flac_ammo, autocvar_g_balance_seeker_reload_ammo);
355
356         c = mod(self.bulletcounter, 4);
357         switch(c)
358         {
359                 case 0:
360                         f_diff = '-1.25 -3.75 0';
361                         break;
362                 case 1:
363                         f_diff = '+1.25 -3.75 0';
364                         break;
365                 case 2:
366                         f_diff = '-1.25 +3.75 0';
367                         break;
368                 case 3:
369                 default:
370                         f_diff = '+1.25 +3.75 0';
371                         break;
372         }
373         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_flac_damage);
374         w_shotorg += f_diff;
375
376         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
377
378         missile                                 = spawn ();
379         missile.owner                   = missile.realowner = self;
380         missile.classname               = "missile";
381         missile.bot_dodge               = TRUE;
382         missile.bot_dodgerating = autocvar_g_balance_seeker_flac_damage;
383         missile.touch                   = Seeker_Flac_Explode;
384         missile.use                     = Seeker_Flac_Explode; 
385         missile.think                   = adaptor_think2use_hittype_splash;
386         missile.nextthink               = time + autocvar_g_balance_seeker_flac_lifetime + autocvar_g_balance_seeker_flac_lifetime_rand;
387         missile.solid                   = SOLID_BBOX;
388         missile.movetype                = MOVETYPE_FLY; 
389         missile.projectiledeathtype = WEP_SEEKER;
390         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
391         missile.flags                           = FL_PROJECTILE;
392         
393         // csqc projectiles
394         //missile.angles                                = vectoangles (missile.velocity);       
395         //missile.scale = 0.4; // BUG: the model is too big 
396         
397         setorigin (missile, w_shotorg);
398         setsize (missile, '-2 -2 -2', '2 2 2');
399                 
400         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
401         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
402
403         other = missile; MUTATOR_CALLHOOK(EditProjectile);
404 }
405
406 void spawnfunc_weapon_seeker (void)
407 {
408         weapon_defaultspawnfunc(WEP_SEEKER);
409 }
410
411 float w_seeker(float req)
412 {
413         float ammo_amount;
414
415         if (req == WR_AIM)
416                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_seeker_tag_speed, 0, 20, FALSE);
417
418         else if (req == WR_THINK)
419         {
420                 if(autocvar_g_balance_seeker_reload_ammo && self.clip_load < min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo)) // forced reload
421                         weapon_action(self.weapon, WR_RELOAD);
422
423                 else if (self.BUTTON_ATCK)
424                 {
425                         if (weapon_prepareattack(0, autocvar_g_balance_seeker_tag_refire))
426                         {
427                                 Seeker_Fire_Tag();
428                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_seeker_tag_animtime, w_ready);
429                         }
430                 }
431
432                 else if (self.BUTTON_ATCK2)
433                 {
434                         if (weapon_prepareattack(1, autocvar_g_balance_seeker_flac_refire))
435                         {
436                                 Seeker_Fire_Flac();
437                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_seeker_flac_animtime, w_ready);
438                         }
439                 }
440         }
441         else if (req == WR_PRECACHE)
442         {
443                 precache_model ("models/weapons/g_seeker.md3");
444                 precache_model ("models/weapons/v_seeker.md3");
445                 precache_model ("models/weapons/h_seeker.iqm");
446                 precache_sound ("weapons/tag_fire.wav");
447                 precache_sound ("weapons/flac_fire.wav");
448                 precache_sound ("weapons/seeker_fire.wav");
449                 precache_sound ("weapons/reload.wav");
450         }
451         else if (req == WR_SETUP)
452         {
453                 weapon_setup(WEP_SEEKER);
454                 self.current_ammo = ammo_rockets;
455         }
456         else if (req == WR_CHECKAMMO1)
457         {
458                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_missile_ammo;
459                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_missile_ammo;
460                 return ammo_amount;
461         }
462         else if (req == WR_CHECKAMMO2)
463         {
464                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_flac_ammo;
465                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_flac_ammo;
466                 return ammo_amount;
467         }
468         else if (req == WR_RELOAD)
469         {
470                 W_Reload(min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo), autocvar_g_balance_seeker_reload_ammo, autocvar_g_balance_seeker_reload_time, "weapons/reload.wav");
471         }
472         return TRUE;
473 };
474 #endif
475 #ifdef CSQC
476 float w_seeker(float req)
477 {
478         if(req == WR_IMPACTEFFECT)
479         {
480                 vector org2;
481                 org2 = w_org + w_backoff * 6;
482                 if(w_deathtype & HITTYPE_SECONDARY)
483                 {
484                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
485                         if(!w_issilent)
486                         {
487                                 if (w_random<0.15)
488                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
489                                 else if (w_random<0.7)
490                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
491                                 else
492                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
493                         }
494                 }
495                 else
496                 {
497                         if(w_deathtype & HITTYPE_BOUNCE)
498                         {
499                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
500                                 if(!w_issilent)
501                                 {
502                                         if (w_random<0.15)
503                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
504                                         else if (w_random<0.7)
505                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
506                                         else
507                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
508                                 }
509                         }
510                         else if(w_deathtype & HITTYPE_HEADSHOT)
511                         {
512                                 if(!w_issilent)
513                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
514                         }
515                         else
516                         {
517                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
518                                 if(!w_issilent)
519                                 {
520                                         if (w_random<0.15)
521                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
522                                         else if (w_random<0.7)
523                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
524                                         else
525                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
526                                 }
527                         }
528                 }
529         }
530         else if(req == WR_PRECACHE)
531         {
532                 precache_sound("weapons/flacexp1.wav");
533                 precache_sound("weapons/flacexp2.wav");
534                 precache_sound("weapons/flacexp3.wav");
535                 precache_sound("weapons/seekerexp1.wav");
536                 precache_sound("weapons/seekerexp2.wav");
537                 precache_sound("weapons/seekerexp3.wav");
538                 precache_sound("weapons/tagexp1.wav");
539                 precache_sound("weapons/tagexp2.wav");
540                 precache_sound("weapons/tagexp3.wav");
541                 precache_sound("weapons/tag_impact.wav");
542         }
543         else if (req == WR_SUICIDEMESSAGE)
544                 w_deathtypestring = _("%s played with tiny rockets");
545         else if (req == WR_KILLMESSAGE)
546         {
547                 if(w_deathtype & HITTYPE_SECONDARY)
548                         w_deathtypestring = _("%s ran into %s's flac");
549                 else
550                         w_deathtypestring = _("%s was tagged by %s");
551         }
552         return TRUE;
553 }
554 #endif
555 #endif