]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
Attempt to further simplify the reload code, as requested. First part of the first...
[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 W_Seeker_Reload()
9 {
10         W_Reload(ammo_rockets, 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");
11 }
12
13 void Seeker_Missile_Explode ()
14 {
15         self.event_damage = SUB_Null;
16         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);
17
18         remove (self);
19 }
20
21 void Seeker_Missile_Touch()
22 {
23         PROJECTILE_TOUCH;
24
25         Seeker_Missile_Explode();
26 }
27
28 void Seeker_Missile_Think()
29 {
30         entity e;
31         vector desireddir, olddir, newdir, eorg;
32         float turnrate;
33         float dist;
34         float spd;
35
36         if (time > self.cnt)
37         {
38                 self.projectiledeathtype |= HITTYPE_SPLASH;
39                 Seeker_Missile_Explode();
40         }
41
42         spd = vlen(self.velocity);
43         spd = bound(
44                 spd - autocvar_g_balance_seeker_missile_decel * frametime,
45                 autocvar_g_balance_seeker_missile_speed_max,
46                 spd + autocvar_g_balance_seeker_missile_accel * frametime
47         );
48
49         if (self.enemy != world)
50                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
51                         self.enemy = world;
52
53         if (self.enemy != world)
54         {
55                 e               = self.enemy;
56                 eorg            = 0.5 * (e.absmin + e.absmax);
57                 turnrate        = autocvar_g_balance_seeker_missile_turnrate; // how fast to turn
58                 desireddir      = normalize(eorg - self.origin);
59                 olddir          = normalize(self.velocity); // get my current direction
60                 dist            = vlen(eorg - self.origin);
61
62                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
63                 if (autocvar_g_balance_seeker_missile_smart && (dist > autocvar_g_balance_seeker_missile_smart_mindist))
64                 {
65                         // Is it a better idea (shorter distance) to trace to the target itself?
66                         if ( vlen(self.origin + olddir * self.wait) < dist)
67                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
68                         else
69                                 traceline(self.origin, eorg, FALSE, self);
70
71                         // Setup adaptive tracelength
72                         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);
73
74                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
75                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
76                 }
77                 
78                 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
79                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
80         }
81
82         // Proxy
83         if (autocvar_g_balance_seeker_missile_proxy)
84         {
85                 if ( dist <= autocvar_g_balance_seeker_missile_proxy_maxrange)
86                 {
87                         if (self.autoswitch == 0)
88                         {
89                                 self.autoswitch = time + autocvar_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; // csqc projectiles
118         UpdateCSQCProjectile(self);
119 }
120
121
122
123 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
124 {
125         if (self.health <= 0)
126                 return;
127
128         if (self.owner == attacker)
129                 self.health = self.health - (damage * 0.25);
130         else
131                 self.health = self.health - damage;
132                 
133         if (self.health <= 0)
134                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
135 }
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 (autocvar_g_balance_seeker_missile_proxy)
153                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
154                 else
155                         self.movetype    = MOVETYPE_FLYMISSILE;
156         }
157
158         UpdateCSQCProjectile(self);
159 }
160 */
161
162 void Seeker_Fire_Missile(vector f_diff)
163 {
164         local entity missile;
165
166         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
167         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
168         {
169                 if(autocvar_g_balance_seeker_reload_ammo)
170                 {
171                         self.clip_load -= autocvar_g_balance_seeker_missile_ammo;
172                         self.weapon_load[WEP_SEEKER] = self.clip_load;
173                 }
174                 else
175                         self.ammo_rockets -= autocvar_g_balance_seeker_missile_ammo;
176         }
177
178         makevectors(self.v_angle);
179         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", CHAN_WEAPON, 0);
180         w_shotorg += f_diff;
181         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
182
183         //self.detornator         = FALSE;
184
185         missile                 = spawn();
186         missile.owner           = self;
187         missile.classname       = "seeker_missile";
188         missile.bot_dodge       = TRUE;
189         missile.bot_dodgerating = autocvar_g_balance_seeker_missile_damage;
190
191         missile.think           = Seeker_Missile_Think;
192         missile.touch           = Seeker_Missile_Touch;
193         missile.event_damage    = Seeker_Missile_Damage;
194         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
195         missile.cnt             = time + autocvar_g_balance_seeker_missile_lifetime;
196         missile.enemy           = self.enemy;
197         missile.solid           = SOLID_BBOX;
198         missile.scale           = 2;
199         missile.takedamage      = DAMAGE_YES;
200         missile.health          = autocvar_g_balance_seeker_missile_health;
201         missile.damageforcescale = autocvar_g_balance_seeker_missile_damageforcescale;
202         missile.projectiledeathtype = WEP_SEEKER;
203         //missile.think           = Seeker_Missile_Animate; // csqc projectiles.
204
205
206         setorigin (missile, w_shotorg);
207         setsize (missile, '-4 -4 -4', '4 4 4');
208         missile.movetype    = MOVETYPE_FLYMISSILE;
209         missile.flags       = FL_PROJECTILE;
210         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
211
212         missile.angles = vectoangles (missile.velocity);
213
214         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
215
216         other = missile; MUTATOR_CALLHOOK(EditProjectile);
217 }
218
219 void Seeker_Vollycontroler_Think()
220 {
221         float c;
222         entity oldself,oldenemy;
223         self.cnt = self.cnt - 1;
224
225         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))
226         {
227                 remove(self);
228                 return;
229         }
230
231         self.nextthink = time + autocvar_g_balance_seeker_missile_delay;
232
233         oldself = self;
234         self = self.owner;
235
236         oldenemy = self.enemy;
237         self.enemy = oldself.enemy;
238
239         c = mod(oldself.cnt, 4);
240         switch(c)
241         {
242                 case 0:
243                         Seeker_Fire_Missile('-1.25 -3.75 0');
244                         break;
245                 case 1:
246                         Seeker_Fire_Missile('+1.25 -3.75 0');
247                         break;
248                 case 2:
249                         Seeker_Fire_Missile('-1.25 +3.75 0');
250                         break;
251                 case 3:
252                 default:
253                         Seeker_Fire_Missile('+1.25 +3.75 0');
254                         break;
255         }
256
257         self.enemy = oldenemy;
258         self = oldself;
259 }
260
261 void Seeker_Tag_Explode ()
262 {
263         //if(other==self.owner)
264         //    return;
265         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
266
267         remove (self);
268 }
269
270 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
271 {
272         if (self.health <= 0)
273                 return;
274         self.health = self.health - damage;
275         if (self.health <= 0)
276                 Seeker_Tag_Explode();
277 }
278
279
280 void Seeker_Tag_Touch()
281 {
282         vector dir;
283         vector org2;
284         entity e;
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                 e           = spawn();
297                 e.cnt       = autocvar_g_balance_seeker_missile_count;
298                 e.owner     = self.owner;
299                 e.enemy     = other;
300                 e.think     = Seeker_Vollycontroler_Think;
301                 e.nextthink = time;
302         }
303
304         remove(self);
305         return;
306 }
307
308 void Seeker_Fire_Tag()
309 {
310         local entity missile;
311         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
312         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
313         {
314                 if(autocvar_g_balance_seeker_reload_ammo)
315                 {
316                         self.clip_load -= autocvar_g_balance_seeker_tag_ammo;
317                         self.weapon_load[WEP_SEEKER] = self.clip_load;
318                 }
319                 else
320                         self.ammo_rockets -= autocvar_g_balance_seeker_tag_ammo;
321         }
322
323         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);
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           = SUB_Remove;
332         missile.nextthink       = time + autocvar_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          = autocvar_g_balance_seeker_tag_health;
340         missile.damageforcescale = autocvar_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.movetype    = MOVETYPE_FLY;
348         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
349         missile.angles = vectoangles (missile.velocity);
350
351         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
352
353         other = missile; MUTATOR_CALLHOOK(EditProjectile);
354 }
355
356
357 void Seeker_Flac_Explode ()
358 {
359         self.event_damage = SUB_Null;
360
361         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);
362
363         remove (self);
364 }
365
366 void Seeker_Flac_Touch()
367 {
368         PROJECTILE_TOUCH;
369
370         Seeker_Flac_Explode();
371 }
372
373 void Seeker_Fire_Flac()
374 {
375         local entity missile;
376         vector f_diff;
377         float c;
378
379         // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
380         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
381         {
382                 if(autocvar_g_balance_seeker_reload_ammo)
383                 {
384                         self.clip_load -= autocvar_g_balance_seeker_flac_ammo;
385                         self.weapon_load[WEP_SEEKER] = self.clip_load;
386                 }
387                 else
388                         self.ammo_rockets -= autocvar_g_balance_seeker_flac_ammo;
389         }
390
391         c = mod(self.bulletcounter, 4);
392         switch(c)
393         {
394                 case 0:
395                         f_diff = '-1.25 -3.75 0';
396                         break;
397                 case 1:
398                         f_diff = '+1.25 -3.75 0';
399                         break;
400                 case 2:
401                         f_diff = '-1.25 +3.75 0';
402                         break;
403                 case 3:
404                 default:
405                         f_diff = '+1.25 +3.75 0';
406                         break;
407         }
408         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", CHAN_WEAPON, autocvar_g_balance_seeker_flac_damage);
409         w_shotorg += f_diff;
410
411         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
412
413         missile                                 = spawn ();
414         missile.owner                   = missile.realowner = self;
415         missile.classname               = "missile";
416         missile.bot_dodge               = TRUE;
417         missile.bot_dodgerating = autocvar_g_balance_seeker_flac_damage;
418         missile.touch                   = Seeker_Flac_Explode;
419         missile.use                     = Seeker_Flac_Explode; 
420         missile.think                   = adaptor_think2use_hittype_splash;
421         missile.nextthink               = time + autocvar_g_balance_seeker_flac_lifetime + autocvar_g_balance_seeker_flac_lifetime_rand;
422         missile.solid                   = SOLID_BBOX;
423         missile.movetype                = MOVETYPE_FLY; 
424         missile.projectiledeathtype = WEP_SEEKER;
425         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
426         missile.flags                           = FL_PROJECTILE;
427         
428         // csqc projectiles
429         //missile.angles                                = vectoangles (missile.velocity);       
430         //missile.scale = 0.4; // BUG: the model is too big 
431         
432         setorigin (missile, w_shotorg);
433         setsize (missile, '-2 -2 -2', '2 2 2');
434                 
435         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
436         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
437
438         other = missile; MUTATOR_CALLHOOK(EditProjectile);
439 }
440
441 void spawnfunc_weapon_seeker (void)
442 {
443         weapon_defaultspawnfunc(WEP_SEEKER);
444 }
445
446 float w_seeker(float req)
447 {
448         float ammo_amount;
449
450         if (req == WR_AIM)
451                 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_seeker_tag_speed, 0, 20, FALSE);
452
453         else if (req == WR_THINK)
454         {
455                 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
456                         W_Seeker_Reload();
457
458                 else if (self.BUTTON_ATCK)
459                 {
460                         if (weapon_prepareattack(0, autocvar_g_balance_seeker_tag_refire))
461                         {
462                                 Seeker_Fire_Tag();
463                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_seeker_tag_animtime, w_ready);
464                         }
465                 }
466
467                 else if (self.BUTTON_ATCK2)
468                 {
469                         if (weapon_prepareattack(1, autocvar_g_balance_seeker_flac_refire))
470                         {
471                                 Seeker_Fire_Flac();
472                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_seeker_flac_animtime, w_ready);
473                         }
474                 }
475         }
476         else if (req == WR_PRECACHE)
477         {
478                 precache_model ("models/weapons/g_seeker.md3");
479                 precache_model ("models/weapons/v_seeker.md3");
480                 precache_model ("models/weapons/h_seeker.iqm");
481                 precache_sound ("weapons/tag_fire.wav");
482                 precache_sound ("weapons/flac_fire.wav");
483                 precache_sound ("weapons/seeker_fire.wav");
484                 precache_sound ("weapons/reload.wav");
485         }
486         else if (req == WR_SETUP)
487         {
488                 weapon_setup(WEP_SEEKER);
489         }
490         else if (req == WR_CHECKAMMO1)
491         {
492                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_missile_ammo;
493                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_missile_ammo;
494                 return ammo_amount;
495         }
496         else if (req == WR_CHECKAMMO2)
497         {
498                 ammo_amount = self.ammo_cells >= autocvar_g_balance_seeker_flac_ammo;
499                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_flac_ammo;
500                 return ammo_amount;
501         }
502         else if (req == WR_RELOAD)
503         {
504                 W_Seeker_Reload();
505         }
506         return TRUE;
507 };
508 #endif
509 #ifdef CSQC
510 float w_seeker(float req)
511 {
512         if(req == WR_IMPACTEFFECT)
513         {
514                 vector org2;
515                 org2 = w_org + w_backoff * 6;
516                 if(w_deathtype & HITTYPE_SECONDARY)
517                 {
518                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
519                         if(!w_issilent)
520                         {
521                                 if (w_random<0.15)
522                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
523                                 else if (w_random<0.7)
524                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
525                                 else
526                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
527                         }
528                 }
529                 else
530                 {
531                         if(w_deathtype & HITTYPE_BOUNCE)
532                         {
533                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
534                                 if(!w_issilent)
535                                 {
536                                         if (w_random<0.15)
537                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
538                                         else if (w_random<0.7)
539                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
540                                         else
541                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
542                                 }
543                         }
544                         else if(w_deathtype & HITTYPE_HEADSHOT)
545                         {
546                                 if(!w_issilent)
547                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
548                         }
549                         else
550                         {
551                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
552                                 if(!w_issilent)
553                                 {
554                                         if (w_random<0.15)
555                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
556                                         else if (w_random<0.7)
557                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
558                                         else
559                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
560                                 }
561                         }
562                 }
563         }
564         else if(req == WR_PRECACHE)
565         {
566                 precache_sound("weapons/flacexp1.wav");
567                 precache_sound("weapons/flacexp2.wav");
568                 precache_sound("weapons/flacexp3.wav");
569                 precache_sound("weapons/seekerexp1.wav");
570                 precache_sound("weapons/seekerexp2.wav");
571                 precache_sound("weapons/seekerexp3.wav");
572                 precache_sound("weapons/tagexp1.wav");
573                 precache_sound("weapons/tagexp2.wav");
574                 precache_sound("weapons/tagexp3.wav");
575                 precache_sound("weapons/tag_impact.wav");
576         }
577         else if (req == WR_SUICIDEMESSAGE)
578                 w_deathtypestring = _("%s played with tiny rockets");
579         else if (req == WR_KILLMESSAGE)
580         {
581                 if(w_deathtype & HITTYPE_SECONDARY)
582                         w_deathtypestring = _("%s ran into %s's flac");
583                 else
584                         w_deathtypestring = _("%s was tagged by %s");
585         }
586         return TRUE;
587 }
588 #endif
589 #endif