]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
seeker volley controller: work properly with IT_UNLIMITED_WEAPON_AMMO
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / w_seeker.qc
1 #ifdef REGISTER_WEAPON
2 REGISTER_WEAPON(SEEKER, w_seeker, IT_ROCKETS, 9, WEP_FLAG_NORMAL | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "seeker", "seeker", "T.A.G. Seeker");
3 #else
4 //.float speed; = switchweapon
5 //.float proxytime; = autoswitch
6 //.float tl; = wait
7
8 void Seeker_Missile_Explode ()
9 {
10         self.event_damage = SUB_Null;
11         RadiusDamage (self, self.owner, cvar("g_balance_seeker_missile_damage"), cvar("g_balance_seeker_missile_edgedamage"), cvar("g_balance_seeker_missile_radius"), world, cvar("g_balance_seeker_missile_force"), self.projectiledeathtype, other);
12
13         remove (self);
14 }
15
16 void Seeker_Missile_Touch()
17 {
18         PROJECTILE_TOUCH;
19
20         Seeker_Missile_Explode();
21 }
22
23 void Seeker_Missile_Think()
24 {
25         entity e;
26         vector desireddir, olddir, newdir, eorg;
27         float turnrate;
28         float dist;
29
30         if (time > self.cnt)
31                 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_missile_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.owner.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.solid           = SOLID_BBOX;
191         missile.scale           = 2;
192         missile.takedamage          = DAMAGE_YES;
193         missile.health          = cvar("g_balance_seeker_missile_health");
194         missile.damageforcescale = cvar("g_balance_seeker_missile_damageforcescale");
195         missile.projectiledeathtype = WEP_SEEKER;
196
197         setorigin (missile, w_shotorg);
198         setsize (missile, '-4 -4 -4', '4 4 4');
199
200
201         missile.movetype    = MOVETYPE_FLYMISSILE;// MOVETYPE_TOSS;
202
203         missile.flags       = FL_PROJECTILE;
204
205         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
206
207         missile.switchweapon = vlen(missile.velocity);
208         missile.angles = vectoangles (missile.velocity);
209
210         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
211 }
212
213 void Seeker_Vollycontroler_Think()
214 {
215         float c;
216         entity oldself,oldenemy;
217         self.cnt = self.cnt - 1;
218
219         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
220         if ((self.owner.ammo_rockets < cvar("g_balance_seeker_missile_ammo")) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO))
221         {
222                 remove(self);
223                 return;
224         }
225
226         self.nextthink = time + cvar("g_balance_seeker_missile_delay");
227
228         oldself = self;
229         self = self.owner;
230
231         oldenemy = self.enemy;
232         self.enemy = oldself.enemy;
233
234         c = mod(oldself.cnt, 4);
235         switch(c)
236         {
237                 case 0:
238                         Seeker_Fire_Missile('-1.25 -3.75 0');
239                         break;
240                 case 1:
241                         Seeker_Fire_Missile('+1.25 -3.75 0');
242                         break;
243                 case 2:
244                         Seeker_Fire_Missile('-1.25 +3.75 0');
245                         break;
246                 case 3:
247                 default:
248                         Seeker_Fire_Missile('+1.25 +3.75 0');
249                         break;
250         }
251
252         self.enemy = oldenemy;
253         self = oldself;
254 }
255
256 void Seeker_Tag_Explode ()
257 {
258         //if(other==self.owner)
259         //    return;
260         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE, self);
261
262         remove (self);
263 }
264
265 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
266 {
267         if (self.health <= 0)
268                 return;
269         self.health = self.health - damage;
270         if (self.health <= 0)
271                 Seeker_Tag_Explode();
272 }
273
274 void Seeker_Tag_Think()
275 {
276         remove(self);
277         return;
278 }
279
280 void Seeker_Tag_Touch()
281 {
282         vector dir;
283         vector org2;
284
285         dir     = normalize (self.owner.origin - self.origin);
286         org2    = findbetterlocation (self.origin, 8);
287
288         te_knightspike(org2);
289
290         self.event_damage = SUB_Null;
291         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
292
293         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
294         {
295                 entity e;
296                 e           = spawn();
297                 e.cnt       = cvar("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                 //sprint(self.owner, "^1Target lock ^3[^7 ",other.netname, " ^3]^1 acquired - autofire activated.\n");
304                 //sprint(other,"^1You are targeted!\n");
305
306                 // stuffcmd(other,"play2 weapons/zany-alarm4.ogg\n");
307                 // stuffcmd(self.owner, "play2 weapons/zany-lock4.ogg\n");
308         }
309
310         remove(self);
311         return;
312 }
313
314
315
316 void Seeker_Fire_Tag()
317 {
318         local entity missile;
319         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
320                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_tag_ammo");
321
322         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/tag_fire.wav", 0);
323
324         missile                 = spawn();
325         missile.owner           = self;
326         missile.classname       = "seeker_tag";
327         missile.bot_dodge       = TRUE;
328         missile.bot_dodgerating = 50;
329         missile.touch           = Seeker_Tag_Touch;
330         missile.think           = Seeker_Tag_Think;
331         missile.nextthink       = time + cvar("g_balance_seeker_tag_lifetime");
332         missile.movetype        = MOVETYPE_FLY;
333         missile.solid           = SOLID_BBOX;
334         missile.owner           = self;
335
336         missile.takedamage       = DAMAGE_YES;
337         missile.event_damage    = Seeker_Tag_Explode;
338         missile.health          = cvar("g_balance_seeker_tag_health");
339         missile.damageforcescale = cvar("g_balance_seeker_tag_damageforcescale");
340
341         setorigin (missile, w_shotorg);
342         setsize (missile, '-2 -2 -2', '2 2 2');
343
344         missile.flags       = FL_PROJECTILE;
345
346         missile.movetype    = MOVETYPE_FLY;
347         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
348         missile.angles = vectoangles (missile.velocity);
349
350         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
351 }
352
353
354 void Seeker_Flac_Explode ()
355 {
356         self.event_damage = SUB_Null;
357
358         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);
359
360         remove (self);
361 }
362
363 void Seeker_Flac_Touch()
364 {
365         PROJECTILE_TOUCH;
366
367         Seeker_Flac_Explode();
368 }
369
370 void Seeker_Fire_Flac()
371 {
372         local entity missile;
373         vector f_diff;
374         float c;
375
376         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
377                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_flac_ammo");
378
379         c = mod(self.bulletcounter, 4);
380         switch(c)
381         {
382                 case 0:
383                         f_diff = '-1.25 -3.75 0';
384                         break;
385                 case 1:
386                         f_diff = '+1.25 -3.75 0';
387                         break;
388                 case 2:
389                         f_diff = '-1.25 +3.75 0';
390                         break;
391                 case 3:
392                 default:
393                         f_diff = '+1.25 +3.75 0';
394                         break;
395         }
396         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/flac_fire.wav", cvar("g_balance_seeker_flac_damage"));
397         w_shotorg += f_diff;
398
399         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
400
401         missile = spawn ();
402         missile.owner = missile.realowner = self;
403         missile.classname = "missile";
404         missile.bot_dodge = TRUE;
405         missile.bot_dodgerating = cvar("g_balance_seeker_flac_damage");
406         missile.touch = Seeker_Flac_Explode;
407         missile.use = Seeker_Flac_Explode;
408         missile.think = Seeker_Flac_Explode;
409         missile.nextthink = time + cvar("g_balance_seeker_flac_lifetime") + cvar("g_balance_seeker_flac_lifetime_rand");
410         missile.solid = SOLID_BBOX;
411         missile.scale = 0.4; // BUG: the model is too big
412         missile.projectiledeathtype = WEP_SEEKER;
413         setorigin (missile, w_shotorg);
414         setsize (missile, '-2 -2 -2', '2 2 2');
415         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
416
417         missile.movetype = MOVETYPE_FLY;
418         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_flac);
419
420         missile.angles = vectoangles (missile.velocity);
421         missile.flags = FL_PROJECTILE;
422
423         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
424 }
425
426 void spawnfunc_weapon_seeker (void)
427 {
428         weapon_defaultspawnfunc(WEP_SEEKER);
429 }
430
431 float w_seeker(float req)
432 {
433         if (req == WR_AIM)
434                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_seeker_tag_speed"), 0, 20, FALSE);
435
436         else if (req == WR_THINK)
437         {
438                 if (self.BUTTON_ATCK)
439                         if (weapon_prepareattack(0, cvar("g_balance_seeker_tag_refire")))
440                         {
441                                 Seeker_Fire_Tag();
442                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_seeker_tag_animtime"), w_ready);
443                         }
444
445                 if (self.BUTTON_ATCK2)
446                         if (weapon_prepareattack(1, cvar("g_balance_seeker_flac_refire")))
447                         {
448                                 Seeker_Fire_Flac();
449                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_seeker_flac_animtime"), w_ready);
450                         }
451
452         }
453         else if (req == WR_PRECACHE)
454         {
455                 precache_model ("models/weapons/g_seeker.md3");
456                 precache_model ("models/weapons/v_seeker.md3");
457                 precache_model ("models/weapons/h_seeker.dpm");
458                 precache_sound ("weapons/tag_fire.wav");
459                 precache_sound ("weapons/flac_fire.wav");
460                 precache_sound ("weapons/seeker_fire.wav");
461         }
462         else if (req == WR_SETUP)
463                 weapon_setup(WEP_SEEKER);
464         else if (req == WR_CHECKAMMO1)
465                 return self.ammo_rockets >= cvar("g_balance_seeker_tag_ammo") + cvar("g_balance_seeker_missile_ammo");
466         else if (req == WR_CHECKAMMO2)
467                 return self.ammo_rockets >= cvar("g_balance_seeker_flac_ammo");
468         else if (req == WR_SUICIDEMESSAGE)
469                 w_deathtypestring = "played with tiny rockets";
470         else if (req == WR_KILLMESSAGE)
471         {
472                 if(w_deathtype & HITTYPE_SECONDARY)
473                         w_deathtypestring = "ran into #'s flac";
474                 else
475                         w_deathtypestring = "was tagged by";
476         }
477         return TRUE;
478 };
479 #endif