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