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