]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_seeker.qc
added dpm weapon support
[divverent/nexuiz.git] / data / qcsrc / server / w_seeker.qc
1 //.float speed; = switchweapon
2 //.float proxytime; = autoswitch
3 //.float tl; = wait
4
5 void Seeker_Missile_Explode ()
6 {
7         self.event_damage = SUB_Null;
8         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);
9
10         remove (self);
11 }
12
13 void Seeker_Missile_Touch()
14 {
15         PROJECTILE_TOUCH;
16
17         Seeker_Missile_Explode();
18 }
19
20 void Seeker_Missile_Think()
21 {
22         entity e;
23         vector desireddir, olddir, newdir, eorg;
24         float turnrate;
25         float dist;
26
27         if (time > self.cnt)
28                 Seeker_Missile_Explode();
29
30         if (!self.switchweapon)
31                 self.switchweapon = cvar("g_balance_seeker_missile_speed");
32
33         if ((self.switchweapon < cvar("g_balance_seeker_missile_speed_max")) && cvar("g_balance_seeker_missile_speed_accel"))
34                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_accel");
35
36         if (self.switchweapon > cvar("g_balance_seeker_missile_speed_max"))
37                 self.switchweapon = self.switchweapon * cvar("g_balance_seeker_missile_decel");
38
39         if (self.enemy != world)
40                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
41                         self.enemy = world;
42
43         if (self.enemy != world)
44         {
45                 e               = self.enemy;
46                 eorg            = 0.5 * (e.absmin + e.absmax);
47                 turnrate        = cvar("g_balance_seeker_missile_turnrate");                // how fast to turn
48                 desireddir      = normalize(eorg - self.origin);
49                 olddir          = normalize(self.velocity);                                         // get my current direction
50                 dist            = vlen(eorg - self.origin);
51
52                 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
53                 if (cvar("g_balance_seeker_missile_smart") && (dist > cvar("g_balance_seeker_missile_smart_mindist")))
54                 {
55                         // Is it a better idea (shorter distance) to trace to the target itself?
56                         if ( vlen(self.origin + olddir * self.wait) < dist)
57                                 traceline(self.origin, self.origin + olddir * self.wait, FALSE, self);
58                         else
59                                 traceline(self.origin, eorg, FALSE, self);
60
61                         // Setup adaptive tracelength
62                         self.wait = vlen(self.origin - trace_endpos);
63                         if (self.wait < cvar("g_balance_seeker_missile_smart_trace_min")) self.wait = cvar("g_balance_seeker_missile_smart_trace_min");
64                         if (self.wait > cvar("g_balance_seeker_missile_smart_trace_max")) self.wait = cvar("g_balance_seeker_missile_smart_trace_max");
65
66                         // Calc how important it is that we turn and add this to the desierd (enemy) dir.
67                         desireddir  = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
68                 }
69
70                 //newdir = normalize((olddir + desireddir * turnrate) * 0.5);// take the average of the 2 directions; not the best method but simple & easy
71                 newdir = normalize(olddir + desireddir * turnrate);// take the average of the 2 directions; not the best method but simple & easy
72
73                 self.velocity = newdir * self.switchweapon;                                         // make me fly in the new direction at my flight speed
74         }
75
76         // Proxy
77         if (cvar("g_balance_seeker_missile_proxy"))
78         {
79                 if ( dist <= cvar("g_balance_seeker_missile_proxy_maxrange"))
80                 {
81                         if (self.autoswitch == 0)
82                         {
83                                 self.autoswitch = time + cvar("g_balance_seeker_missile_proxy_delay");
84                         }
85                         else
86                         {
87                                 if (self.autoswitch <= time)
88                                 {
89                                         Seeker_Missile_Explode();
90                                         self.autoswitch = 0;
91                                 }
92                         }
93                 }
94                 else
95                 {
96                         if (self.autoswitch != 0)
97                                 self.autoswitch = 0;
98                 }
99         }
100         ///////////////
101
102         if (self.enemy.deadflag != DEAD_NO)
103         {
104                 self.enemy = world;
105                 self.cnt = time + 1 + (random() * 4);
106                 self.nextthink = self.cnt;
107                 return;
108         }
109
110         self.angles = vectoangles(self.velocity);                       // turn model in the new flight direction
111         self.nextthink = time + 0.05;
112
113         UpdateCSQCProjectile(self);
114 }
115
116
117
118 void Seeker_Missile_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
119 {
120         float d;
121         d = damage;
122
123         if (self.owner == attacker)
124                 d = d * 0.25;
125
126         self.health = self.health - d;
127
128         if (self.health <= 0)
129                 W_PrepareExplosionByDamage(attacker, Seeker_Missile_Explode);
130 }
131
132 void Seeker_Missile_Animate()
133 {
134         self.frame = self.frame +1;
135         self.nextthink = time + 0.05;
136
137         if (self.enemy != world)
138                 if (self.enemy.takedamage != DAMAGE_AIM || self.enemy.deadflag != DEAD_NO)
139                         self.enemy = world;
140
141         if(self.frame == 5)
142         {
143                 self.think           = Seeker_Missile_Think;
144                 self.nextthink       = time;// + cvar("g_balance_seeker_missile_activate_delay"); // cant dealy with csqc projectiles
145
146                 if (cvar("g_balance_seeker_guided_proxy"))
147                         self.movetype    = MOVETYPE_BOUNCEMISSILE;
148                 else
149                         self.movetype    = MOVETYPE_FLYMISSILE;
150         }
151
152         UpdateCSQCProjectile(self);
153 }
154
155 void Seeker_Fire_Missile(vector f_org)
156 {
157         local entity missile;
158
159         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
160                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_missile_ammo");
161
162         makevectors(self.v_angle);
163         W_SetupShot (self, f_org, FALSE, 2, "weapons/seeker_fire.wav");
164         pointparticles(particleeffectnum("seeker_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
165
166         //self.detornator         = FALSE;
167
168         missile                 = spawn();
169         missile.owner           = self;
170         missile.classname       = "seeker_missile";
171         missile.bot_dodge       = TRUE;
172         missile.bot_dodgerating = cvar("g_balance_seeker_missile_damage");
173
174         missile.think           = Seeker_Missile_Animate;
175
176         //if (!cvar("g_balance_seeker_missile_proxy"))
177         missile.touch           = Seeker_Missile_Touch;
178
179         missile.event_damage    = Seeker_Missile_Damage;
180         missile.nextthink       = time;// + 0.2;// + cvar("g_balance_seeker_missile_activate_delay");
181         missile.cnt             = time + cvar("g_balance_seeker_missile_lifetime");
182         missile.enemy           = self.enemy;
183         missile.switchweapon           = cvar("g_balance_seeker_missile_speed");
184         missile.solid           = SOLID_BBOX;
185         missile.scale           = 2;
186         missile.takedamage          = DAMAGE_YES;
187         missile.damageforcescale    = 4;
188         missile.health              = 5;
189         missile.projectiledeathtype = WEP_SEEKER;
190
191         setorigin (missile, w_shotorg);
192         setsize (missile, '-2 -2 -2', '2 2 2');
193
194
195         missile.movetype    = MOVETYPE_FLYMISSILE;// MOVETYPE_TOSS;
196
197         missile.flags       = FL_PROJECTILE;
198
199         missile.velocity    = (w_shotdir + '0 0 0.45') * missile.switchweapon;
200         W_SetupProjectileVelocity(missile);
201
202         missile.switchweapon = vlen(missile.velocity);
203         missile.angles = vectoangles (missile.velocity);
204
205         CSQCProjectile(missile, FALSE, PROJECTILE_SEEKER, TRUE);
206 }
207
208 void Seeker_Vollycontroler_Think()
209 {
210         float c;
211         entity oldself,oldenemy;
212         self.cnt = self.cnt - 1;
213
214         if ((self.owner.ammo_rockets < cvar("g_balance_seeker_missile_ammo")) || (self.cnt <= -1) || (self.owner.deadflag != DEAD_NO))
215         {
216                 remove(self);
217                 return;
218         }
219
220         self.nextthink = time + cvar("g_balance_seeker_missile_delay");
221
222         oldself = self;
223         self = self.owner;
224
225         oldenemy = self.enemy;
226         self.enemy = oldself.enemy;
227
228         c = mod(oldself.cnt, 4);
229         switch(c)
230         {
231                 case 0:
232                         Seeker_Fire_Missile('37.5 17 -22');
233                         break;
234                 case 1:
235                         Seeker_Fire_Missile('37.5 9.5 -22');
236                         break;
237                 case 2:
238                         Seeker_Fire_Missile('40 17 -29');
239                         break;
240                 case 3:
241                 default:
242                         Seeker_Fire_Missile('40 9.5 -29');
243                         break;
244         }
245
246         self.enemy = oldenemy;
247         self = oldself;
248 }
249
250 void Seeker_Tag_Explode ()
251 {
252         //if(other==self.owner)
253         //    return;
254         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_BOUNCE);
255
256         remove (self);
257 }
258
259 void Seeker_Tag_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
260 {
261         self.health = self.health - damage;
262         if (self.health <= 0)
263                 Seeker_Tag_Explode();
264 }
265
266 void Seeker_Tag_Think()
267 {
268         remove(self);
269         return;
270 }
271
272 void Seeker_Tag_Touch()
273 {
274         vector dir;
275         vector org2;
276
277         dir     = normalize (self.owner.origin - self.origin);
278         org2    = findbetterlocation (self.origin, 8);
279
280         te_knightspike(org2);
281
282         self.event_damage = SUB_Null;
283         Damage_DamageInfo(self.origin, 0, 0, 0, self.velocity, WEP_SEEKER | HITTYPE_HEADSHOT);
284
285         if (other.takedamage == DAMAGE_AIM && other.deadflag == DEAD_NO)
286         {
287                 entity e;
288                 e           = spawn();
289                 e.cnt       = cvar("g_balance_seeker_missile_count");
290                 e.owner     = self.owner;
291                 e.enemy     = other;
292                 e.think     = Seeker_Vollycontroler_Think;
293                 e.nextthink = time;
294
295                 //sprint(self.owner, "^1Target lock ^3[^7 ",other.netname, " ^3]^1 acquired - autofire activated.\n");
296                 //sprint(other,"^1You are targeted!\n");
297
298                 // stuffcmd(other,"play2 weapons/zany-alarm4.ogg\n");
299                 // stuffcmd(self.owner, "play2 weapons/zany-lock4.ogg\n");
300         }
301
302         remove(self);
303         return;
304 }
305
306
307
308 void Seeker_Fire_Tag()
309 {
310         local entity missile;
311         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
312                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_tag_ammo");
313
314         W_SetupShot (self, '56 13 -15', FALSE, 2, "weapons/tag_fire.wav");
315
316         missile                 = spawn();
317         missile.owner           = self;
318         missile.classname       = "seeker_tag";
319         missile.bot_dodge       = TRUE;
320         missile.bot_dodgerating = 50;
321         missile.touch           = Seeker_Tag_Touch;
322         missile.think           = Seeker_Tag_Think;
323         missile.nextthink       = time + 15;
324         missile.movetype        = MOVETYPE_FLY;
325         missile.solid           = SOLID_BBOX;
326         missile.owner           = self;
327
328         missile.takedamage       = DAMAGE_YES;
329         missile.event_damage    = Seeker_Tag_Explode;
330         missile.health          = 5;
331
332         setorigin (missile, w_shotorg);
333
334         missile.flags       = FL_PROJECTILE;
335
336         missile.velocity    = w_shotdir  * cvar("g_balance_seeker_tag_speed");
337         missile.movetype    = MOVETYPE_BOUNCEMISSILE;
338         W_SetupProjectileVelocity(missile);
339         missile.angles = vectoangles (missile.velocity);
340
341         CSQCProjectile(missile, TRUE, PROJECTILE_TAG, FALSE); // has sound
342 }
343
344
345 void Seeker_Flac_Explode ()
346 {
347         self.event_damage = SUB_Null;
348
349         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);
350
351         remove (self);
352 }
353
354 void Seeker_Flac_Touch()
355 {
356         PROJECTILE_TOUCH;
357
358         Seeker_Flac_Explode();
359 }
360
361 void Seeker_Fire_Flac()
362 {
363         local entity missile;
364         vector f_org;
365         float c;
366
367         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
368                 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_seeker_flac_ammo");
369
370         c = mod(self.bulletcounter, 4);
371         switch(c)
372         {
373                 case 1:
374                         f_org = '37.5 17 -22';
375                         break;
376                 case 2:
377                         f_org = '37.5 9.5 -22';
378                         break;
379                 case 3:
380                         f_org = '40 17 -29';
381                         break;
382                 case 0:
383                 default:
384                         f_org = '40 9.5 -29';
385                         break;
386         }
387         W_SetupShot (self, f_org, FALSE, 2, "weapons/flac_fire.wav");
388
389         pointparticles(particleeffectnum("hagar_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
390
391         missile = spawn ();
392         missile.owner = missile.realowner = self;
393         missile.classname = "missile";
394         missile.bot_dodge = TRUE;
395         missile.bot_dodgerating = cvar("g_balance_seeker_flac_damage");
396         missile.touch = Seeker_Flac_Explode;
397         missile.use = Seeker_Flac_Explode;
398         missile.think = Seeker_Flac_Explode;
399         missile.nextthink = time + cvar("g_balance_seeker_flac_lifetime") + cvar("g_balance_seeker_flac_lifetime_rand");
400         missile.solid = SOLID_BBOX;
401         missile.scale = 0.4; // BUG: the model is too big
402         missile.projectiledeathtype = WEP_SEEKER;
403         setorigin (missile, w_shotorg);
404         missile.projectiledeathtype = WEP_SEEKER | HITTYPE_SECONDARY;
405
406         missile.movetype = MOVETYPE_FLY;
407         w_shotdir = w_shotdir + '0 0 0.3';
408         missile.velocity    = (w_shotdir  + randomvec() * cvar("g_balance_seeker_flac_spread")) * cvar("g_balance_seeker_flac_speed");
409
410         W_SetupProjectileVelocity(missile);
411
412         missile.angles = vectoangles (missile.velocity);
413         missile.flags = FL_PROJECTILE;
414
415         CSQCProjectile(missile, TRUE, PROJECTILE_FLAC, TRUE);
416 }
417
418 void spawnfunc_weapon_seeker (void)
419 {
420         weapon_defaultspawnfunc(WEP_SEEKER);
421 }
422
423 float w_seeker(float req)
424 {
425         if (req == WR_AIM)
426                 self.BUTTON_ATCK = bot_aim(cvar("g_balance_seeker_tag_speed"), 0, 20, FALSE);
427
428         else if (req == WR_THINK)
429         {
430                 if (self.BUTTON_ATCK)
431                         if (weapon_prepareattack(0, cvar("g_balance_seeker_tag_refire")))
432                         {
433                                 Seeker_Fire_Tag();
434                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_seeker_tag_animtime"), w_ready);
435                         }
436
437                 if (self.BUTTON_ATCK2)
438                         if (weapon_prepareattack(1, cvar("g_balance_seeker_flac_refire")))
439                         {
440                                 Seeker_Fire_Flac();
441                                 weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_seeker_flac_animtime"), w_ready);
442                         }
443
444         }
445         else if (req == WR_PRECACHE)
446         {
447                 precache_model ("models/weapons/g_seeker.md3");
448                 precache_model ("models/weapons/v_seeker.md3");
449                 precache_model ("models/weapons/w_seeker.zym");
450                 precache_sound ("weapons/tag_fire.wav");
451                 precache_sound ("weapons/flac_fire.wav");
452                 precache_sound ("weapons/seeker_fire.wav");
453         }
454         else if (req == WR_SETUP)
455                 weapon_setup(WEP_SEEKER);
456         else if (req == WR_CHECKAMMO1)
457                 return self.ammo_rockets >= cvar("g_balance_seeker_tag_ammo") + cvar("g_balance_seeker_missile_ammo");
458         else if (req == WR_CHECKAMMO2)
459                 return self.ammo_rockets >= cvar("g_balance_seeker_flac_ammo");
460         else if (req == WR_SUICIDEMESSAGE)
461                 w_deathtypestring = "played with tiny rockets";
462         else if (req == WR_KILLMESSAGE)
463         {
464                 if(w_deathtype & HITTYPE_SECONDARY)
465                         w_deathtypestring = "ran into #'s flac";
466                 else
467                         w_deathtypestring = "was tagged by";
468         }
469         return TRUE;
470 };
471