]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/w_seeker.qc
Merge remote branch 'origin/master' into samual/seeker_updates
[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 .entity tag_target;
8 .float tag_time;
9
10 void Seeker_Missile_Explode ()
11 {
12         self.event_damage = SUB_Null;
13         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);
14
15         remove (self);
16 }
17
18 void Seeker_Missile_Touch()
19 {
20         PROJECTILE_TOUCH;
21
22         Seeker_Missile_Explode();
23 }
24
25 void Seeker_Missile_Think()
26 {
27         entity e;
28         vector desireddir, olddir, newdir, eorg;
29         float turnrate;
30         float dist;
31         float spd;
32
33         if (time > self.cnt)
34         {
35                 self.projectiledeathtype |= HITTYPE_SPLASH;
36                 Seeker_Missile_Explode();
37         }
38
39         spd = vlen(self.velocity);
40         spd = bound(
41                 spd - autocvar_g_balance_seeker_missile_decel * frametime,
42                 autocvar_g_balance_seeker_missile_speed_max,
43                 spd + autocvar_g_balance_seeker_missile_accel * frametime
44         );
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        = autocvar_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 (autocvar_g_balance_seeker_missile_smart && (dist > autocvar_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 = bound(autocvar_g_balance_seeker_missile_smart_trace_min, vlen(self.origin - trace_endpos), self.wait = autocvar_g_balance_seeker_missile_smart_trace_max);
70
71                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
72                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
73                 }
74                 
75                 newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
76                 self.velocity = newdir * spd; // make me fly in the new direction at my flight speed
77         }
78
79         // Proxy
80         if (autocvar_g_balance_seeker_missile_proxy)
81         {
82                 if ( dist <= autocvar_g_balance_seeker_missile_proxy_maxrange)
83                 {
84                         if (self.autoswitch == 0)
85                         {
86                                 self.autoswitch = time + autocvar_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; // csqc projectiles
115         UpdateCSQCProjectile(self);
116 }
117
118
119
120 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
121 {
122         if (self.health <= 0)
123                 return;
124
125         if (self.owner == attacker)
126                 self.health = self.health - (damage * 0.25);
127         else
128                 self.health = self.health - damage;
129                 
130         if (self.health <= 0)
131                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
132 }
133
134 /*
135 void Seeker_Missile_Animate()
136 {
137         self.frame = self.frame +1;
138         self.nextthink = time + 0.05;
139
140         if (self.enemy != world)
141                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
142                         self.enemy = world;
143
144         if(self.frame == 5)
145         {
146                 self.think           = Seeker_Missile_Think;
147                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
148
149                 if (autocvar_g_balance_seeker_missile_proxy)
150                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
151                 else
152                         self.movetype    = MOVETYPE_FLYMISSILE;
153         }
154
155         UpdateCSQCProjectile(self);
156 }
157 */
158
159 void Seeker_Fire_Missile(vector f_diff, entity m_target)
160 {
161         local entity missile;
162
163         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_reload_ammo);
164
165         makevectors(self.v_angle);
166         W_SetupShot_ProjectileSize (self, '-2 -2 -2', '2 2 2', FALSE, 2, "weapons/seeker_fire.wav", CHAN_WEAPON, 0);
167         w_shotorg += f_diff;
168         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
169
170         //self.detornator         = FALSE;
171
172         missile                 = spawn();
173         missile.owner           = self;
174         missile.classname       = "seeker_missile";
175         missile.bot_dodge       = TRUE;
176         missile.bot_dodgerating = autocvar_g_balance_seeker_missile_damage;
177
178         missile.think           = Seeker_Missile_Think;
179         missile.touch           = Seeker_Missile_Touch;
180         missile.event_damage    = Seeker_Missile_Damage;
181         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
182         missile.cnt             = time + autocvar_g_balance_seeker_missile_lifetime;
183         missile.enemy           = m_target;
184         missile.solid           = SOLID_BBOX;
185         missile.scale           = 2;
186         missile.takedamage      = DAMAGE_YES;
187         missile.health          = autocvar_g_balance_seeker_missile_health;
188         missile.damageforcescale = autocvar_g_balance_seeker_missile_damageforcescale;
189         missile.projectiledeathtype = WEP_SEEKER;
190         //missile.think           = Seeker_Missile_Animate; // csqc projectiles.
191
192
193         setorigin (missile, w_shotorg);
194         setsize (missile, '-4 -4 -4', '4 4 4');
195         missile.movetype    = MOVETYPE_FLYMISSILE;
196         missile.flags       = FL_PROJECTILE;
197         W_SETUPPROJECTILEVELOCITY_UP(missile, g_balance_seeker_missile);
198
199         missile.angles = vectoangles (missile.velocity);
200
201         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
202
203         other = missile; MUTATOR_CALLHOOK(EditProjectile);
204 }
205
206 entity Seeker_Tagged_Info(entity isowner, entity istarget)
207 {
208         entity tag;
209         for(tag = world; (tag = find(tag, classname, "tag_tracker")); ) 
210                 if ((tag.owner == isowner) && (tag.tag_target == istarget))
211                         return tag;
212                 
213         return world;
214 }
215
216 void Seeker_Attack()
217 {
218         entity tracker, closest_target;
219         for(tracker = world; (tracker = find(tracker, classname, "tag_tracker")); ) 
220                 if (tracker.owner == self)
221                         if (closest_target)
222                         {
223                                 if (vlen(self.origin - tracker.tag_target.origin) < vlen(self.origin - closest_target.origin))
224                                         closest_target = tracker.tag_target;
225                         }
226                         else 
227                                 closest_target = tracker.tag_target;
228                 
229         traceline(self.origin + self.view_ofs, closest_target.origin, MOVE_NOMONSTERS, self);
230         if ((!closest_target) || (trace_fraction < 1 && trace_ent != closest_target))
231                 closest_target = world;
232         
233         Seeker_Fire_Missile('0 0 0', closest_target);
234
235 }
236
237 void Seeker_Tracker_Think() // this think method keeps track of the tag entity created to follow/tag down a player. 
238 {
239         // Update the think method information
240         self.nextthink = time;
241         
242         // commit suicide if: You die OR target dies OR you switch away from the seeker OR commit suicide if lifetime is up
243         if ((self.owner.deadflag != DEAD_NO) || (self.tag_target.deadflag != DEAD_NO) || (self.owner.switchweapon != WEP_SEEKER)
244         || (time > self.tag_time + autocvar_g_balance_seeker_tag_lifetime))
245         {
246                 if (self)
247                 {
248                         WaypointSprite_Kill(self.tag_target.waypointsprite_attachedforcarrier);
249                         remove(self);
250                 }
251                 return;
252         }
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_Touch()
274 {
275         vector dir;
276         vector org2;
277         entity e;
278         
279         dir     = normalize (self.owner.origin - self.origin);
280         org2    = findbetterlocation (self.origin, 8);
281
282         te_knightspike(org2);
283
284         self.event_damage = SUB_Null;
285         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT, self);
286
287         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
288         {
289                 // check to see if this person is already tagged by me
290                 entity tag = Seeker_Tagged_Info(self.owner, other);
291                 
292                 if (tag != world) // if so, just update the time at which the player was last tagged.
293                         tag.tag_time = time;
294                 else // if not, create a new tracker just for this person. 
295                 {               
296                         e             = spawn();
297                         e.classname   = "tag_tracker";
298                         e.owner       = self.owner;
299                         e.think       = Seeker_Tracker_Think;
300                         e.nextthink   = time;
301                         e.tag_target  = other;
302                         e.tag_time    = time;
303                         
304                         WaypointSprite_Spawn("ka-ball", autocvar_g_balance_seeker_tag_tracker_lifetime, 0, other, '0 0 64', self.owner, 0, other, waypointsprite_attachedforcarrier, TRUE);
305                         WaypointSprite_UpdateRule(other.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
306                 
307                         print("hit: ", self.owner.netname, " -> ", other.netname, ". \n");
308                 }
309         }
310
311         remove(self);
312         return;
313 }
314
315 void Seeker_Fire_Tag()
316 {
317         local entity missile;
318         W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_seeker_tag_ammo, autocvar_g_balance_seeker_reload_ammo);
319
320         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);
321
322         missile                 = spawn();
323         missile.owner           = self;
324         missile.classname       = "seeker_tag";
325         missile.bot_dodge       = TRUE;
326         missile.bot_dodgerating = 50;
327         missile.touch           = Seeker_Tag_Touch;
328         missile.think           = SUB_Remove;
329         missile.nextthink       = time + autocvar_g_balance_seeker_tag_lifetime;
330         missile.movetype        = MOVETYPE_FLY;
331         missile.solid           = SOLID_BBOX;
332         missile.owner           = self;
333
334         missile.takedamage       = DAMAGE_YES;
335         missile.event_damage    = Seeker_Tag_Explode;
336         missile.health          = autocvar_g_balance_seeker_tag_health;
337         missile.damageforcescale = autocvar_g_balance_seeker_tag_damageforcescale;
338
339         setorigin (missile, w_shotorg);
340         setsize (missile, '-2 -2 -2', '2 2 2');
341
342         missile.flags       = FL_PROJECTILE;
343
344         missile.movetype    = MOVETYPE_FLY;
345         W_SETUPPROJECTILEVELOCITY(missile, g_balance_seeker_tag);
346         missile.angles = vectoangles (missile.velocity);
347
348         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
349
350         other = missile; MUTATOR_CALLHOOK(EditProjectile);
351 }
352
353 void spawnfunc_weapon_seeker (void)
354 {
355         weapon_defaultspawnfunc(WEP_SEEKER);
356 }
357
358 float w_seeker(float req)
359 {
360         float ammo_amount;
361
362         if (req == WR_AIM)
363         {
364                 if (Seeker_Tagged_Info(self, self.enemy) != world)
365                         self.BUTTON_ATCK2 = bot_aim(autocvar_g_balance_seeker_missile_speed_max, 0, autocvar_g_balance_seeker_missile_lifetime, FALSE);
366                 else
367                         self.BUTTON_ATCK = bot_aim(autocvar_g_balance_seeker_tag_speed, 0, autocvar_g_balance_seeker_tag_lifetime, FALSE);
368         }
369         else if (req == WR_THINK)
370         {
371                 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
372                         weapon_action(self.weapon, WR_RELOAD);
373                         
374                 else if (self.BUTTON_ATCK)
375                 {
376                         if (weapon_prepareattack(0, autocvar_g_balance_seeker_tag_refire))
377                         {
378                                 Seeker_Fire_Tag();
379                                 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_seeker_tag_animtime, w_ready);
380                         }
381                 }
382
383                 else if (self.BUTTON_ATCK2)
384                 {
385                         if (weapon_prepareattack(1, autocvar_g_balance_seeker_missile_refire))
386                         {
387                                 Seeker_Attack();
388                                 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_seeker_missile_animtime, w_ready);
389                         }
390                 }
391         }
392         else if (req == WR_PRECACHE)
393         {
394                 precache_model ("models/weapons/g_seeker.md3");
395                 precache_model ("models/weapons/v_seeker.md3");
396                 precache_model ("models/weapons/h_seeker.iqm");
397                 precache_sound ("weapons/tag_fire.wav");
398                 precache_sound ("weapons/flac_fire.wav");
399                 precache_sound ("weapons/seeker_fire.wav");
400                 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
401         }
402         else if (req == WR_SETUP)
403         {
404                 weapon_setup(WEP_SEEKER);
405                 self.current_ammo = ammo_rockets;
406         }
407         else if (req == WR_CHECKAMMO1)
408         {
409                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_seeker_tag_ammo;
410                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_tag_ammo;
411                 return ammo_amount;
412         }
413         else if (req == WR_CHECKAMMO2)
414         {
415                 ammo_amount = self.ammo_rockets >= autocvar_g_balance_seeker_missile_ammo;
416                 ammo_amount += self.weapon_load[WEP_SEEKER] >= autocvar_g_balance_seeker_missile_ammo;
417                 return ammo_amount;
418         }
419         else if (req == WR_RELOAD)
420         {
421                 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");
422         }
423         return TRUE;
424 };
425 #endif
426 #ifdef CSQC
427 float w_seeker(float req)
428 {
429         if(req == WR_IMPACTEFFECT)
430         {
431                 vector org2;
432                 org2 = w_org + w_backoff * 6;
433                 if(w_deathtype & HITTYPE_SECONDARY)
434                 {
435                         pointparticles(particleeffectnum("flac_explode"), org2, '0 0 0', 1);
436                         if(!w_issilent)
437                         {
438                                 if (w_random<0.15)
439                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp1.wav", 1, ATTN_NORM);
440                                 else if (w_random<0.7)
441                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp2.wav", 1, ATTN_NORM);
442                                 else
443                                         sound(self, CHAN_PROJECTILE, "weapons/flacexp3.wav", 1, ATTN_NORM);
444                         }
445                 }
446                 else
447                 {
448                         if(w_deathtype & HITTYPE_BOUNCE)
449                         {
450                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
451                                 if(!w_issilent)
452                                 {
453                                         if (w_random<0.15)
454                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp1.wav", 1, ATTN_NORM);
455                                         else if (w_random<0.7)
456                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp2.wav", 1, ATTN_NORM);
457                                         else
458                                                 sound(self, CHAN_PROJECTILE, "weapons/tagexp3.wav", 1, ATTN_NORM);
459                                 }
460                         }
461                         else if(w_deathtype & HITTYPE_HEADSHOT)
462                         {
463                                 if(!w_issilent)
464                                         sound(self, CHAN_PROJECTILE, "weapons/tag_impact.wav", 1, ATTN_NORM);
465                         }
466                         else
467                         {
468                                 pointparticles(particleeffectnum("hagar_explode"), org2, '0 0 0', 1);
469                                 if(!w_issilent)
470                                 {
471                                         if (w_random<0.15)
472                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp1.wav", 1, ATTN_NORM);
473                                         else if (w_random<0.7)
474                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp2.wav", 1, ATTN_NORM);
475                                         else
476                                                 sound(self, CHAN_PROJECTILE, "weapons/seekerexp3.wav", 1, ATTN_NORM);
477                                 }
478                         }
479                 }
480         }
481         else if(req == WR_PRECACHE)
482         {
483                 precache_sound("weapons/flacexp1.wav");
484                 precache_sound("weapons/flacexp2.wav");
485                 precache_sound("weapons/flacexp3.wav");
486                 precache_sound("weapons/seekerexp1.wav");
487                 precache_sound("weapons/seekerexp2.wav");
488                 precache_sound("weapons/seekerexp3.wav");
489                 precache_sound("weapons/tagexp1.wav");
490                 precache_sound("weapons/tagexp2.wav");
491                 precache_sound("weapons/tagexp3.wav");
492                 precache_sound("weapons/tag_impact.wav");
493         }
494         else if (req == WR_SUICIDEMESSAGE)
495                 w_deathtypestring = _("%s played with tiny rockets");
496         else if (req == WR_KILLMESSAGE)
497         {
498                 if(w_deathtype & HITTYPE_SECONDARY)
499                         w_deathtypestring = _("%s ran into %s's flac");
500                 else
501                         w_deathtypestring = _("%s was tagged by %s");
502         }
503         return TRUE;
504 }
505 #endif
506 #endif