]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
fix rankings scoreboard size
[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 #ifdef SVQC
5 //.float speed; = switchweapon
6 //.float proxytime; = autoswitch
7 //.float tl; = wait
8
9 void Seeker_Missile_Explode ()
10 {
11         self.event_damage = SUB_Null;
12         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);
13
14         remove (self);
15 }
16
17 void Seeker_Missile_Touch()
18 {
19         PROJECTILE_TOUCH;
20
21         Seeker_Missile_Explode();
22 }
23
24 void Seeker_Missile_Think()
25 {
26         entity e;
27         vector desireddir, olddir, newdir, eorg;
28         float turnrate;
29         float dist;
30
31         if (time > self.cnt)
32         {
33                 self.projectiledeathtype |= HITTYPE_SPLASH;
34                 Seeker_Missile_Explode();
35         }
36
37         if (!self.switchweapon)
38                 self.switchweapon = cvar("g_balance_seeker_missile_speed");
39
40         if ((self.switchweapon < cvar("g_balance_seeker_missile_speed_max")) && cvar("g_balance_seeker_missile_speed_accel"))
41                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_accel");
42
43         if (self.switchweapon > cvar("g_balance_seeker_missile_speed_max"))
44                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_decel");
45
46         if (self.enemy != world)
47                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
48                         self.enemy = world;
49
50         if (self.enemy != world)
51         {
52                 e               = self.enemy;
53                 eorg            = 0.5 * (e.absmin + e.absmax);
54                 turnrate        = cvar("g_balance_seeker_missile_turnrate");                // how fast to turn
55                 desireddir      = normalize(eorg - self.origin);
56                 olddir          = normalize(self.velocity);                                         // get my current direction
57                 dist            = vlen(eorg - self.origin);
58
59                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
60                 if (cvar("g_balance_seeker_missile_smart") && (dist > cvar("g_balance_seeker_missile_smart_mindist")))
61                 {
62                         // Is it a better idea (shorter distance) to trace to the target itself?
63                         if ( vlen(self.origin + olddir * self.wait) < dist)
64                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
65                         else
66                                 traceline(self.origin, eorg, FALSE, self);
67
68                         // Setup adaptive tracelength
69                         self.wait = vlen(self.origin - trace_endpos);
70                         if (self.wait < cvar("g_balance_seeker_missile_smart_trace_min")) self.wait = cvar("g_balance_seeker_missile_smart_trace_min");
71                         if (self.wait > cvar("g_balance_seeker_missile_smart_trace_max")) self.wait = cvar("g_balance_seeker_missile_smart_trace_max");
72
73                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
74                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
75                 }
76
77                 //newdir = normalize((olddir + desireddir * turnrate) * 0.5);// take the average of the 2 directions; not the best method but simple & easy
78                 newdir = normalize(olddir + desireddir * turnrate);// take the average of the 2 directions; not the best method but simple & easy
79
80                 self.velocity = newdir * self.switchweapon;                                         // make me fly in the new direction at my flight speed
81         }
82
83         // Proxy
84         if (cvar("g_balance_seeker_missile_proxy"))
85         {
86                 if ( dist <= cvar("g_balance_seeker_missile_proxy_maxrange"))
87                 {
88                         if (self.autoswitch == 0)
89                         {
90                                 self.autoswitch = time + cvar("g_balance_seeker_missile_proxy_delay");
91                         }
92                         else
93                         {
94                                 if (self.autoswitch <= time)
95                                 {
96                                         Seeker_Missile_Explode();
97                                         self.autoswitch = 0;
98                                 }
99                         }
100                 }
101                 else
102                 {
103                         if (self.autoswitch != 0)
104                                 self.autoswitch = 0;
105                 }
106         }
107         ///////////////
108
109         if (self.enemy.deadflag != DEAD_NO)
110         {
111                 self.enemy = world;
112                 self.cnt = time + 1 + (random() * 4);
113                 self.nextthink = self.cnt;
114                 return;
115         }
116
117         self.angles = vectoangles(self.velocity);                       // turn model in the new flight direction
118         self.nextthink = time + 0.05;
119
120         UpdateCSQCProjectile(self);
121 }
122
123
124
125 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
126 {
127         float d;
128         d = damage;
129
130         if (self.health <= 0)
131                 return;
132
133         if (self.owner == attacker)
134                 d = d * 0.25;
135
136         self.health = self.health - d;
137
138         if (self.health <= 0)
139                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
140 }
141
142 void Seeker_Missile_Animate()
143 {
144         self.frame = self.frame +1;
145         self.nextthink = time + 0.05;
146
147         if (self.enemy != world)
148                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
149                         self.enemy = world;
150
151         if(self.frame == 5)
152         {
153                 self.think           = Seeker_Missile_Think;
154                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
155
156                 if (cvar("g_balance_seeker_missile_proxy"))
157                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
158                 else
159                         self.movetype    = MOVETYPE_FLYMISSILE;
160         }
161
162         UpdateCSQCProjectile(self);
163 }
164
165 void Seeker_Fire_Missile(vector f_diff)
166 {
167         local entity missile;
168
169         if not(self.owner.items & IT_UNLIMITED_WEAPON_AMMO)
170                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_missile_ammo");
171
172         makevectors(self.v_angle);
173         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", cvar("g_balance_seeker_missile_damage"));
174         w_shotorg += f_diff;
175         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
176
177         //self.detornator         = FALSE;
178
179         missile                 = spawn();
180         missile.owner           = self;
181         missile.classname       = "seeker_missile";
182         missile.bot_dodge       = TRUE;
183         missile.bot_dodgerating = cvar("g_balance_seeker_missile_damage");
184
185         missile.think           = Seeker_Missile_Animate;
186
187         //if (!cvar("g_balance_seeker_missile_proxy"))
188         missile.touch           = Seeker_Missile_Touch;
189
190         missile.event_damage    = Seeker_Missile_Damage;
191         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
192         missile.cnt             = time + cvar("g_balance_seeker_missile_lifetime");
193         missile.enemy           = self.enemy;
194         missile.solid           = SOLID_BBOX;
195         missile.scale           = 2;
196         missile.takedamage          = DAMAGE_YES;
197         missile.health          = cvar("g_balance_seeker_missile_health");
198         missile.damageforcescale = cvar("g_balance_seeker_missile_damageforcescale");
199         missile.projectiledeathtype = WEP_SEEKER;
200
201         setorigin (missile, w_shotorg);
202         setsize (missile, '-4 -4 -4', '4 4 4');
203
204
205         missile.movetype    = MOVETYPE_FLYMISSILE;// MOVETYPE_TOSS;
206
207         missile.flags       = FL_PROJECTILE;
208
209         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
210
211         missile.switchweapon = vlen(missile.velocity);
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 < cvar("g_balance_seeker_missile_ammo")) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO))
226         {
227                 remove(self);
228                 return;
229         }
230
231         self.nextthink = time + cvar("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 void Seeker_Tag_Think()
280 {
281         remove(self);
282         return;
283 }
284
285 void Seeker_Tag_Touch()
286 {
287         vector dir;
288         vector org2;
289
290         dir     = normalize (self.owner.origin - self.origin);
291         org2    = findbetterlocation (self.origin, 8);
292
293         te_knightspike(org2);
294
295         self.event_damage = SUB_Null;
296         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
297
298         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
299         {
300                 entity e;
301                 e           = spawn();
302                 e.cnt       = cvar("g_balance_seeker_missile_count");
303                 e.owner     = self.owner;
304                 e.enemy     = other;
305                 e.think     = Seeker_Vollycontroler_Think;
306                 e.nextthink = time;
307
308                 //sprint(self.owner, "^1Target lock ^3[^7 ",other.netname, " ^3]^1 acquired - autofire activated.\n");
309                 //sprint(other,"^1You are targeted!\n");
310
311                 // stuffcmd(other,"play2 weapons/zany-alarm4.ogg\n");
312                 // stuffcmd(self.owner, "play2 weapons/zany-lock4.ogg\n");
313         }
314
315         remove(self);
316         return;
317 }
318
319
320
321 void Seeker_Fire_Tag()
322 {
323         local entity missile;
324         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
325                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_tag_ammo");
326
327         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/tag_fire.wav", 0);
328
329         missile                 = spawn();
330         missile.owner           = self;
331         missile.classname       = "seeker_tag";
332         missile.bot_dodge       = TRUE;
333         missile.bot_dodgerating = 50;
334         missile.touch           = Seeker_Tag_Touch;
335         missile.think           = Seeker_Tag_Think;
336         missile.nextthink       = time + cvar("g_balance_seeker_tag_lifetime");
337         missile.movetype        = MOVETYPE_FLY;
338         missile.solid           = SOLID_BBOX;
339         missile.owner           = self;
340
341         missile.takedamage       = DAMAGE_YES;
342         missile.event_damage    = Seeker_Tag_Explode;
343         missile.health          = cvar("g_balance_seeker_tag_health");
344         missile.damageforcescale = cvar("g_balance_seeker_tag_damageforcescale");
345
346         setorigin (missile, w_shotorg);
347         setsize (missile, '-2 -2 -2', '2 2 2');
348
349         missile.flags       = FL_PROJECTILE;
350
351         missile.movetype    = MOVETYPE_FLY;
352         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
353         missile.angles = vectoangles (missile.velocity);
354
355         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
356
357         other = missile; MUTATOR_CALLHOOK(EditProjectile);
358 }
359
360
361 void Seeker_Flac_Explode ()
362 {
363         self.event_damage = SUB_Null;
364
365         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);
366
367         remove (self);
368 }
369
370 void Seeker_Flac_Touch()
371 {
372         PROJECTILE_TOUCH;
373
374         Seeker_Flac_Explode();
375 }
376
377 void Seeker_Fire_Flac()
378 {
379         local entity missile;
380         vector f_diff;
381         float c;
382
383         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
384                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_flac_ammo");
385
386         c = mod(self.bulletcounter, 4);
387         switch(c)
388         {
389                 case 0:
390                         f_diff = '-1.25 -3.75 0';
391                         break;
392                 case 1:
393                         f_diff = '+1.25 -3.75 0';
394                         break;
395                 case 2:
396                         f_diff = '-1.25 +3.75 0';
397                         break;
398                 case 3:
399                 default:
400                         f_diff = '+1.25 +3.75 0';
401                         break;
402         }
403         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", cvar("g_balance_seeker_flac_damage"));
404         w_shotorg += f_diff;
405
406         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
407
408         missile = spawn ();
409         missile.owner = missile.realowner = self;
410         missile.classname = "missile";
411         missile.bot_dodge = TRUE;
412         missile.bot_dodgerating = cvar("g_balance_seeker_flac_damage");
413         missile.touch = Seeker_Flac_Explode;
414         missile.use = Seeker_Flac_Explode;
415         missile.think = adaptor_think2use_hittype_splash;
416         missile.nextthink = time + cvar("g_balance_seeker_flac_lifetime") + cvar("g_balance_seeker_flac_lifetime_rand");
417         missile.solid = SOLID_BBOX;
418         missile.scale = 0.4; // BUG: the model is too big
419         missile.projectiledeathtype = WEP_SEEKER;
420         setorigin (missile, w_shotorg);
421         setsize (missile, '-2 -2 -2', '2 2 2');
422         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
423
424         missile.movetype = MOVETYPE_FLY;
425         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
426
427         missile.angles = vectoangles (missile.velocity);
428         missile.flags = FL_PROJECTILE;
429
430         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
431
432         other = missile; MUTATOR_CALLHOOK(EditProjectile);
433 }
434
435 void spawnfunc_weapon_seeker (void)
436 {
437         weapon_defaultspawnfunc(WEP_SEEKER);
438 }
439
440 float w_seeker(float req)
441 {
442         if (req == WR_AIM)
443                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_seeker_tag_speed"), 0, 20, FALSE);
444
445         else if (req == WR_THINK)
446         {
447                 if (self.BUTTON_ATCK)
448                         if (weapon_prepareattack(0, cvar("g_balance_seeker_tag_refire")))
449                         {
450                                 Seeker_Fire_Tag();
451                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_seeker_tag_animtime"), w_ready);
452                         }
453
454                 if (self.BUTTON_ATCK2)
455                         if (weapon_prepareattack(1, cvar("g_balance_seeker_flac_refire")))
456                         {
457                                 Seeker_Fire_Flac();
458                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_seeker_flac_animtime"), w_ready);
459                         }
460
461         }
462         else if (req == WR_PRECACHE)
463         {
464                 precache_model ("models/weapons/g_seeker.md3");
465                 precache_model ("models/weapons/v_seeker.md3");
466                 precache_model ("models/weapons/h_seeker.iqm");
467                 precache_sound ("weapons/tag_fire.wav");
468                 precache_sound ("weapons/flac_fire.wav");
469                 precache_sound ("weapons/seeker_fire.wav");
470         }
471         else if (req == WR_SETUP)
472                 weapon_setup(WEP_SEEKER);
473         else if (req == WR_CHECKAMMO1)
474                 return self.ammo_rockets >= cvar("g_balance_seeker_tag_ammo") + cvar("g_balance_seeker_missile_ammo");
475         else if (req == WR_CHECKAMMO2)
476                 return self.ammo_rockets >= cvar("g_balance_seeker_flac_ammo");
477         return TRUE;
478 };
479 #endif
480 #ifdef CSQC
481 float w_seeker(float req)
482 {
483         if(req == WR_IMPACTEFFECT)
484         {
485                 vector org2;
486                 org2 = w_org + w_backoff * 6;
487                 if(w_deathtype & HITTYPE_SECONDARY)
488                 {
489                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
490                         if(!w_issilent)
491                         {
492                                 if (w_random<0.15)
493                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
494                                 else if (w_random<0.7)
495                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
496                                 else
497                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
498                         }
499                 }
500                 else
501                 {
502                         if(w_deathtype & HITTYPE_BOUNCE)
503                         {
504                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
505                                 if(!w_issilent)
506                                 {
507                                         if (w_random<0.15)
508                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
509                                         else if (w_random<0.7)
510                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
511                                         else
512                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
513                                 }
514                         }
515                         else if(w_deathtype & HITTYPE_HEADSHOT)
516                         {
517                                 if(!w_issilent)
518                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
519                         }
520                         else
521                         {
522                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
523                                 if(!w_issilent)
524                                 {
525                                         if (w_random<0.15)
526                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
527                                         else if (w_random<0.7)
528                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
529                                         else
530                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
531                                 }
532                         }
533                 }
534         }
535         else if(req == WR_PRECACHE)
536         {
537                 precache_sound("weapons/flacexp1.wav");
538                 precache_sound("weapons/flacexp2.wav");
539                 precache_sound("weapons/flacexp3.wav");
540                 precache_sound("weapons/seekerexp1.wav");
541                 precache_sound("weapons/seekerexp2.wav");
542                 precache_sound("weapons/seekerexp3.wav");
543                 precache_sound("weapons/tagexp1.wav");
544                 precache_sound("weapons/tagexp2.wav");
545                 precache_sound("weapons/tagexp3.wav");
546                 precache_sound("weapons/tag_impact.wav");
547         }
548         else if (req == WR_SUICIDEMESSAGE)
549                 w_deathtypestring = "%s played with tiny rockets";
550         else if (req == WR_KILLMESSAGE)
551         {
552                 if(w_deathtype & HITTYPE_SECONDARY)
553                         w_deathtypestring = "%s ran into %s's flac";
554                 else
555                         w_deathtypestring = "%s was tagged by %s";
556         }
557         return TRUE;
558 }
559 #endif
560 #endif