]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/devastator.qc
Merge branch 'master' into terencehill/tooltips_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / devastator.qc
1 #ifndef IMPLEMENTATION
2 REGISTER_WEAPON(
3 /* WEP_##id  */ DEVASTATOR,
4 /* function  */ W_Devastator,
5 /* ammotype  */ ammo_rockets,
6 /* impulse   */ 9,
7 /* flags     */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating    */ BOT_PICKUP_RATING_HIGH,
9 /* color     */ '1 1 0',
10 /* modelname */ "rl",
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairrocketlauncher 0.7",
13 /* wepimg    */ "weaponrocketlauncher",
14 /* refname   */ "devastator",
15 /* wepname   */ _("Devastator")
16 );
17
18 #define DEVASTATOR_SETTINGS(w_cvar,w_prop) DEVASTATOR_SETTINGS_LIST(w_cvar, w_prop, DEVASTATOR, devastator)
19 #define DEVASTATOR_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20         w_cvar(id, sn, NONE, ammo) \
21         w_cvar(id, sn, NONE, animtime) \
22         w_cvar(id, sn, NONE, damage) \
23         w_cvar(id, sn, NONE, damageforcescale) \
24         w_cvar(id, sn, NONE, detonatedelay) \
25         w_cvar(id, sn, NONE, edgedamage) \
26         w_cvar(id, sn, NONE, force) \
27         w_cvar(id, sn, NONE, guidedelay) \
28         w_cvar(id, sn, NONE, guidegoal) \
29         w_cvar(id, sn, NONE, guiderate) \
30         w_cvar(id, sn, NONE, guideratedelay) \
31         w_cvar(id, sn, NONE, guidestop) \
32         w_cvar(id, sn, NONE, health) \
33         w_cvar(id, sn, NONE, lifetime) \
34         w_cvar(id, sn, NONE, radius) \
35         w_cvar(id, sn, NONE, refire) \
36         w_cvar(id, sn, NONE, remote_damage) \
37         w_cvar(id, sn, NONE, remote_edgedamage) \
38         w_cvar(id, sn, NONE, remote_force) \
39         w_cvar(id, sn, NONE, remote_jump_damage) \
40         w_cvar(id, sn, NONE, remote_jump_radius) \
41         w_cvar(id, sn, NONE, remote_jump_velocity_z_add) \
42         w_cvar(id, sn, NONE, remote_jump_velocity_z_max) \
43         w_cvar(id, sn, NONE, remote_jump_velocity_z_min) \
44         w_cvar(id, sn, NONE, remote_radius) \
45         w_cvar(id, sn, NONE, speed) \
46         w_cvar(id, sn, NONE, speedaccel) \
47         w_cvar(id, sn, NONE, speedstart) \
48         w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
49         w_prop(id, sn, float,  reloading_time, reload_time) \
50         w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
51         w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
52         w_prop(id, sn, string, weaponreplace, weaponreplace) \
53         w_prop(id, sn, float,  weaponstart, weaponstart) \
54         w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
55         w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
56
57 #ifdef SVQC
58 DEVASTATOR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
59 .float rl_release;
60 .float rl_detonate_later;
61 #endif
62 #endif
63 #ifdef IMPLEMENTATION
64 #ifdef SVQC
65 spawnfunc(weapon_devastator) { weapon_defaultspawnfunc(WEP_DEVASTATOR.m_id); }
66 spawnfunc(weapon_rocketlauncher) { spawnfunc_weapon_devastator(this); }
67
68 void W_Devastator_Unregister(void)
69 {SELFPARAM();
70         if(self.realowner && self.realowner.lastrocket == self)
71         {
72                 self.realowner.lastrocket = world;
73                 // self.realowner.rl_release = 1;
74         }
75 }
76
77 void W_Devastator_Explode(void)
78 {SELFPARAM();
79         W_Devastator_Unregister();
80
81         if(other.takedamage == DAMAGE_AIM)
82                 if(IS_PLAYER(other))
83                         if(DIFF_TEAM(self.realowner, other))
84                                 if(other.deadflag == DEAD_NO)
85                                         if(IsFlying(other))
86                                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
87
88         self.event_damage = func_null;
89         self.takedamage = DAMAGE_NO;
90
91         RadiusDamage(
92                 self,
93                 self.realowner,
94                 WEP_CVAR(devastator, damage),
95                 WEP_CVAR(devastator, edgedamage),
96                 WEP_CVAR(devastator, radius),
97                 world,
98                 world,
99                 WEP_CVAR(devastator, force),
100                 self.projectiledeathtype,
101                 other
102         );
103
104         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
105         {
106                 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
107                 if(!(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO))
108                 {
109                         self.realowner.cnt = WEP_DEVASTATOR.m_id;
110                         ATTACK_FINISHED(self.realowner) = time;
111                         self.realowner.switchweapon = w_getbestweapon(self.realowner);
112                 }
113         }
114         remove(self);
115 }
116
117 void W_Devastator_DoRemoteExplode(void)
118 {SELFPARAM();
119         W_Devastator_Unregister();
120
121         self.event_damage = func_null;
122         self.takedamage = DAMAGE_NO;
123
124         float handled_as_rocketjump = false;
125
126         entity head = WarpZone_FindRadius(
127                 self.origin,
128                 WEP_CVAR(devastator, remote_jump_radius),
129                 false
130         );
131
132         while(head)
133         {
134                 if(head.takedamage && (head == self.realowner))
135                 {
136                         float distance_to_head = vlen(self.origin - head.WarpZone_findradius_nearest);
137                         if(distance_to_head <= WEP_CVAR(devastator, remote_jump_radius))
138                         {
139                                 // we handled this as a rocketjump :)
140                                 handled_as_rocketjump = true;
141
142                                 // modify velocity
143                                 head.velocity_x *= 0.9;
144                                 head.velocity_y *= 0.9;
145                                 head.velocity_z = bound(
146                                         WEP_CVAR(devastator, remote_jump_velocity_z_min),
147                                         head.velocity.z + WEP_CVAR(devastator, remote_jump_velocity_z_add),
148                                         WEP_CVAR(devastator, remote_jump_velocity_z_max)
149                                 );
150
151                                 // now do the damage
152                                 RadiusDamage(
153                                         self,
154                                         head,
155                                         WEP_CVAR(devastator, remote_jump_damage),
156                                         WEP_CVAR(devastator, remote_jump_damage),
157                                         WEP_CVAR(devastator, remote_jump_radius),
158                                         world,
159                                         head,
160                                         0,
161                                         self.projectiledeathtype | HITTYPE_BOUNCE,
162                                         world
163                                 );
164                                 break;
165                         }
166                 }
167                 head = head.chain;
168         }
169
170         RadiusDamage(
171                 self,
172                 self.realowner,
173                 WEP_CVAR(devastator, remote_damage),
174                 WEP_CVAR(devastator, remote_edgedamage),
175                 WEP_CVAR(devastator, remote_radius),
176                 (handled_as_rocketjump ? head : world),
177                 world,
178                 WEP_CVAR(devastator, remote_force),
179                 self.projectiledeathtype | HITTYPE_BOUNCE,
180                 world
181         );
182
183         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
184         {
185                 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
186                 if(!(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO))
187                 {
188                         self.realowner.cnt = WEP_DEVASTATOR.m_id;
189                         ATTACK_FINISHED(self.realowner) = time;
190                         self.realowner.switchweapon = w_getbestweapon(self.realowner);
191                 }
192         }
193         remove(self);
194 }
195
196 void W_Devastator_RemoteExplode(void)
197 {SELFPARAM();
198         if(self.realowner.deadflag == DEAD_NO)
199         if(self.realowner.lastrocket)
200         {
201                 if((self.spawnshieldtime >= 0)
202                         ? (time >= self.spawnshieldtime) // timer
203                         : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > WEP_CVAR(devastator, remote_radius)) // safety device
204                 )
205                 {
206                         W_Devastator_DoRemoteExplode();
207                 }
208         }
209 }
210
211 vector W_Devastator_SteerTo(vector thisdir, vector goaldir, float maxturn_cos)
212 {
213         if(thisdir * goaldir > maxturn_cos)
214                 return goaldir;
215         if(thisdir * goaldir < -0.9998) // less than 1 degree and opposite
216                 return thisdir; // refuse to guide (better than letting a numerical error happen)
217         float f, m2;
218         vector v;
219         // solve:
220         //   g = normalize(thisdir + goaldir * X)
221         //   thisdir * g = maxturn
222         //
223         //   gg = thisdir + goaldir * X
224         //   (thisdir * gg)^2 = maxturn^2 * (gg * gg)
225         //
226         //   (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
227         f = thisdir * goaldir;
228         //   (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
229         //   0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
230         m2 = maxturn_cos * maxturn_cos;
231         v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
232         return normalize(thisdir + goaldir * v.y); // the larger solution!
233 }
234 // assume thisdir == -goaldir:
235 //   f == -1
236 //   v = solve_qadratic(m2 - 1, -2 * (m2 - 1), m2 - 1)
237 //   (m2 - 1) x^2 - 2 * (m2 - 1) * x + (m2 - 1) = 0
238 //   x^2 - 2 * x + 1 = 0
239 //   (x - 1)^2 = 0
240 //   x = 1
241 //   normalize(thisdir + goaldir)
242 //   normalize(0)
243
244 void W_Devastator_Think(void)
245 {SELFPARAM();
246         vector desireddir, olddir, newdir, desiredorigin, goal;
247         float velspeed, f;
248         self.nextthink = time;
249         if(time > self.cnt)
250         {
251                 other = world;
252                 self.projectiledeathtype |= HITTYPE_BOUNCE;
253                 W_Devastator_Explode();
254                 return;
255         }
256
257         // accelerate
258         makevectors(self.angles.x * '-1 0 0' + self.angles.y * '0 1 0');
259         velspeed = WEP_CVAR(devastator, speed) * W_WeaponSpeedFactor() - (self.velocity * v_forward);
260         if(velspeed > 0)
261                 self.velocity = self.velocity + v_forward * min(WEP_CVAR(devastator, speedaccel) * W_WeaponSpeedFactor() * frametime, velspeed);
262
263         // laser guided, or remote detonation
264         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
265         {
266                 if(self == self.realowner.lastrocket)
267                 if(!self.realowner.rl_release)
268                 if(!self.BUTTON_ATCK2)
269                 if(WEP_CVAR(devastator, guiderate))
270                 if(time > self.pushltime)
271                 if(self.realowner.deadflag == DEAD_NO)
272                 {
273                         f = WEP_CVAR(devastator, guideratedelay);
274                         if(f)
275                                 f = bound(0, (time - self.pushltime) / f, 1);
276                         else
277                                 f = 1;
278
279                         velspeed = vlen(self.velocity);
280
281                         makevectors(self.realowner.v_angle);
282                         desireddir = WarpZone_RefSys_TransformVelocity(self.realowner, self, v_forward);
283                         desiredorigin = WarpZone_RefSys_TransformOrigin(self.realowner, self, self.realowner.origin + self.realowner.view_ofs);
284                         olddir = normalize(self.velocity);
285
286                         // now it gets tricky... we want to move like some curve to approximate the target direction
287                         // but we are limiting the rate at which we can turn!
288                         goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + WEP_CVAR(devastator, guidegoal)) * desireddir;
289                         newdir = W_Devastator_SteerTo(olddir, normalize(goal - self.origin), cos(WEP_CVAR(devastator, guiderate) * f * frametime * DEG2RAD));
290
291                         self.velocity = newdir * velspeed;
292                         self.angles = vectoangles(self.velocity);
293
294                         if(!self.count)
295                         {
296                                 Send_Effect(EFFECT_ROCKET_GUIDE, self.origin, self.velocity, 1);
297                                 // TODO add a better sound here
298                                 sound(self.realowner, CH_WEAPON_B, SND_ROCKET_MODE, VOL_BASE, ATTN_NORM);
299                                 self.count = 1;
300                         }
301                 }
302
303                 if(self.rl_detonate_later)
304                         W_Devastator_RemoteExplode();
305         }
306
307         if(self.csqcprojectile_clientanimate == 0)
308                 UpdateCSQCProjectile(self);
309 }
310
311 void W_Devastator_Touch(void)
312 {SELFPARAM();
313         if(WarpZone_Projectile_Touch())
314         {
315                 if(wasfreed(self))
316                         W_Devastator_Unregister();
317                 return;
318         }
319         W_Devastator_Unregister();
320         W_Devastator_Explode();
321 }
322
323 void W_Devastator_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
324 {SELFPARAM();
325         if(self.health <= 0)
326                 return;
327
328         if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
329                 return; // g_projectiles_damage says to halt
330
331         self.health = self.health - damage;
332         self.angles = vectoangles(self.velocity);
333
334         if(self.health <= 0)
335                 W_PrepareExplosionByDamage(attacker, W_Devastator_Explode);
336 }
337
338 void W_Devastator_Attack(void)
339 {SELFPARAM();
340         entity missile;
341         entity flash;
342
343         W_DecreaseAmmo(WEP_CVAR(devastator, ammo));
344
345         W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 5, SND(ROCKET_FIRE), CH_WEAPON_A, WEP_CVAR(devastator, damage));
346         Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
347
348         missile = WarpZone_RefSys_SpawnSameRefSys(self);
349         missile.owner = missile.realowner = self;
350         self.lastrocket = missile;
351         if(WEP_CVAR(devastator, detonatedelay) >= 0)
352                 missile.spawnshieldtime = time + WEP_CVAR(devastator, detonatedelay);
353         else
354                 missile.spawnshieldtime = -1;
355         missile.pushltime = time + WEP_CVAR(devastator, guidedelay);
356         missile.classname = "rocket";
357         missile.bot_dodge = true;
358         missile.bot_dodgerating = WEP_CVAR(devastator, damage) * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
359
360         missile.takedamage = DAMAGE_YES;
361         missile.damageforcescale = WEP_CVAR(devastator, damageforcescale);
362         missile.health = WEP_CVAR(devastator, health);
363         missile.event_damage = W_Devastator_Damage;
364         missile.damagedbycontents = true;
365
366         missile.movetype = MOVETYPE_FLY;
367         PROJECTILE_MAKETRIGGER(missile);
368         missile.projectiledeathtype = WEP_DEVASTATOR.m_id;
369         setsize(missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
370
371         setorigin(missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
372         W_SetupProjVelocity_Basic(missile, WEP_CVAR(devastator, speedstart), 0);
373         missile.angles = vectoangles(missile.velocity);
374
375         missile.touch = W_Devastator_Touch;
376         missile.think = W_Devastator_Think;
377         missile.nextthink = time;
378         missile.cnt = time + WEP_CVAR(devastator, lifetime);
379         missile.flags = FL_PROJECTILE;
380         missile.missile_flags = MIF_SPLASH;
381
382         CSQCProjectile(missile, WEP_CVAR(devastator, guiderate) == 0 && WEP_CVAR(devastator, speedaccel) == 0, PROJECTILE_ROCKET, false); // because of fly sound
383
384         // muzzle flash for 1st person view
385         flash = spawn();
386         setmodel(flash, MDL_DEVASTATOR_MUZZLEFLASH); // precision set below
387         SUB_SetFade(flash, time, 0.1);
388         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
389         W_AttachToShotorg(flash, '5 0 0');
390
391         // common properties
392         MUTATOR_CALLHOOK(EditProjectile, self, missile);
393 }
394
395 bool W_Devastator(int req)
396 {SELFPARAM();
397         entity rock;
398         float rockfound;
399         float ammo_amount;
400         switch(req)
401         {
402                 #if 0
403                 case WR_AIM:
404                 {
405                         // aim and decide to fire if appropriate
406                         self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), false);
407                         if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
408                         {
409                                 // decide whether to detonate rockets
410                                 entity missile, targetlist, targ;
411                                 targetlist = findchainfloat(bot_attack, true);
412                                 for(missile = world; (missile = find(missile, classname, "rocket")); ) if(missile.realowner == self)
413                                 {
414                                         targ = targetlist;
415                                         while(targ)
416                                         {
417                                                 if(targ != missile.realowner && vlen(targ.origin - missile.origin) < WEP_CVAR(devastator, radius))
418                                                 {
419                                                         self.BUTTON_ATCK2 = true;
420                                                         break;
421                                                 }
422                                                 targ = targ.chain;
423                                         }
424                                 }
425
426                                 if(self.BUTTON_ATCK2) self.BUTTON_ATCK = false;
427                         }
428
429                         return true;
430                 }
431                 #else
432                 case WR_AIM:
433                 {
434                         // aim and decide to fire if appropriate
435                         self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), false);
436                         if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
437                         {
438                                 // decide whether to detonate rockets
439                                 entity missile, targetlist, targ;
440                                 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
441                                 float selfdamage, teamdamage, enemydamage;
442                                 edgedamage = WEP_CVAR(devastator, edgedamage);
443                                 coredamage = WEP_CVAR(devastator, damage);
444                                 edgeradius = WEP_CVAR(devastator, radius);
445                                 recipricoledgeradius = 1 / edgeradius;
446                                 selfdamage = 0;
447                                 teamdamage = 0;
448                                 enemydamage = 0;
449                                 targetlist = findchainfloat(bot_attack, true);
450                                 missile = find(world, classname, "rocket");
451                                 while(missile)
452                                 {
453                                         if(missile.realowner != self)
454                                         {
455                                                 missile = find(missile, classname, "rocket");
456                                                 continue;
457                                         }
458                                         targ = targetlist;
459                                         while(targ)
460                                         {
461                                                 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - missile.origin);
462                                                 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
463                                                 // count potential damage according to type of target
464                                                 if(targ == self)
465                                                         selfdamage = selfdamage + d;
466                                                 else if(targ.team == self.team && teamplay)
467                                                         teamdamage = teamdamage + d;
468                                                 else if(bot_shouldattack(targ))
469                                                         enemydamage = enemydamage + d;
470                                                 targ = targ.chain;
471                                         }
472                                         missile = find(missile, classname, "rocket");
473                                 }
474                                 float desirabledamage;
475                                 desirabledamage = enemydamage;
476                                 if(time > self.invincible_finished && time > self.spawnshieldtime)
477                                         desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
478                                 if(teamplay && self.team)
479                                         desirabledamage = desirabledamage - teamdamage;
480
481                                 missile = find(world, classname, "rocket");
482                                 while(missile)
483                                 {
484                                         if(missile.realowner != self)
485                                         {
486                                                 missile = find(missile, classname, "rocket");
487                                                 continue;
488                                         }
489                                         makevectors(missile.v_angle);
490                                         targ = targetlist;
491                                         if(skill > 9) // normal players only do this for the target they are tracking
492                                         {
493                                                 targ = targetlist;
494                                                 while(targ)
495                                                 {
496                                                         if(
497                                                                 (v_forward * normalize(missile.origin - targ.origin)< 0.1)
498                                                                 && desirabledamage > 0.1*coredamage
499                                                         )self.BUTTON_ATCK2 = true;
500                                                         targ = targ.chain;
501                                                 }
502                                         }else{
503                                                 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
504                                                 //As the distance gets larger, a correct detonation gets near imposible
505                                                 //Bots are assumed to use the rocket spawnfunc_light to see if the rocket gets near a player
506                                                 if(v_forward * normalize(missile.origin - self.enemy.origin)< 0.1)
507                                                         if(IS_PLAYER(self.enemy))
508                                                                 if(desirabledamage >= 0.1*coredamage)
509                                                                         if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
510                                                                                 self.BUTTON_ATCK2 = true;
511                                         //      dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
512                                         }
513
514                                         missile = find(missile, classname, "rocket");
515                                 }
516                                 // if we would be doing at X percent of the core damage, detonate it
517                                 // but don't fire a new shot at the same time!
518                                 if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
519                                         self.BUTTON_ATCK2 = true;
520                                 if((skill > 6.5) && (selfdamage > self.health))
521                                         self.BUTTON_ATCK2 = false;
522                                 //if(self.BUTTON_ATCK2 == true)
523                                 //      dprint(ftos(desirabledamage),"\n");
524                                 if(self.BUTTON_ATCK2 == true) self.BUTTON_ATCK = false;
525                         }
526
527                         return true;
528                 }
529                 #endif
530                 case WR_THINK:
531                 {
532                         if(WEP_CVAR(devastator, reload_ammo) && self.clip_load < WEP_CVAR(devastator, ammo)) // forced reload
533                                 WEP_ACTION(self.weapon, WR_RELOAD);
534                         else
535                         {
536                                 if(self.BUTTON_ATCK)
537                                 {
538                                         if(self.rl_release || WEP_CVAR(devastator, guidestop))
539                                         if(weapon_prepareattack(0, WEP_CVAR(devastator, refire)))
540                                         {
541                                                 W_Devastator_Attack();
542                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(devastator, animtime), w_ready);
543                                                 self.rl_release = 0;
544                                         }
545                                 }
546                                 else
547                                         self.rl_release = 1;
548
549                                 if(self.BUTTON_ATCK2)
550                                 if(self.switchweapon == WEP_DEVASTATOR.m_id)
551                                 {
552                                         rockfound = 0;
553                                         for(rock = world; (rock = find(rock, classname, "rocket")); ) if(rock.realowner == self)
554                                         {
555                                                 if(!rock.rl_detonate_later)
556                                                 {
557                                                         rock.rl_detonate_later = true;
558                                                         rockfound = 1;
559                                                 }
560                                         }
561                                         if(rockfound)
562                                                 sound(self, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
563                                 }
564                         }
565
566                         return true;
567                 }
568                 case WR_INIT:
569                 {
570                         DEVASTATOR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
571                         return true;
572                 }
573                 case WR_SETUP:
574                 {
575                         self.rl_release = 1;
576                         return true;
577                 }
578                 case WR_CHECKAMMO1:
579                 {
580                         #if 0
581                         // don't switch while guiding a missile
582                         if(ATTACK_FINISHED(self) <= time || self.weapon != WEP_DEVASTATOR.m_id)
583                         {
584                                 ammo_amount = false;
585                                 if(WEP_CVAR(devastator, reload_ammo))
586                                 {
587                                         if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo) && self.(weapon_load[WEP_DEVASTATOR.m_id]) < WEP_CVAR(devastator, ammo))
588                                                 ammo_amount = true;
589                                 }
590                                 else if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
591                                         ammo_amount = true;
592                                 return !ammo_amount;
593                         }
594                         #endif
595                         #if 0
596                         if(self.rl_release == 0)
597                         {
598                                 LOG_INFOF("W_Devastator(WR_CHECKAMMO1): %d, %.2f, %d: TRUE\n", self.rl_release, self.WEP_AMMO(DEVASTATOR), WEP_CVAR(devastator, ammo));
599                                 return true;
600                         }
601                         else
602                         {
603                                 ammo_amount = self.WEP_AMMO(DEVASTATOR) >= WEP_CVAR(devastator, ammo);
604                                 ammo_amount += self.(weapon_load[WEP_DEVASTATOR.m_id]) >= WEP_CVAR(devastator, ammo);
605                                 LOG_INFOF("W_Devastator(WR_CHECKAMMO1): %d, %.2f, %d: %s\n", self.rl_release, self.WEP_AMMO(DEVASTATOR), WEP_CVAR(devastator, ammo), (ammo_amount ? "TRUE" : "FALSE"));
606                                 return ammo_amount;
607                         }
608                         #else
609                         ammo_amount = self.WEP_AMMO(DEVASTATOR) >= WEP_CVAR(devastator, ammo);
610                         ammo_amount += self.(weapon_load[WEP_DEVASTATOR.m_id]) >= WEP_CVAR(devastator, ammo);
611                         return ammo_amount;
612                         #endif
613                 }
614                 case WR_CHECKAMMO2:
615                 {
616                         return false;
617                 }
618                 case WR_CONFIG:
619                 {
620                         DEVASTATOR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
621                         return true;
622                 }
623                 case WR_RESETPLAYER:
624                 {
625                         self.rl_release = 0;
626                         return true;
627                 }
628                 case WR_RELOAD:
629                 {
630                         W_Reload(WEP_CVAR(devastator, ammo), SND(RELOAD));
631                         return true;
632                 }
633                 case WR_SUICIDEMESSAGE:
634                 {
635                         return WEAPON_DEVASTATOR_SUICIDE;
636                 }
637                 case WR_KILLMESSAGE:
638                 {
639                         if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
640                                 return WEAPON_DEVASTATOR_MURDER_SPLASH;
641                         else
642                                 return WEAPON_DEVASTATOR_MURDER_DIRECT;
643                 }
644         }
645         return false;
646 }
647 #endif
648 #ifdef CSQC
649 bool W_Devastator(int req)
650 {SELFPARAM();
651         switch(req)
652         {
653                 case WR_IMPACTEFFECT:
654                 {
655                         vector org2;
656                         org2 = w_org + w_backoff * 12;
657                         pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), org2, '0 0 0', 1);
658                         if(!w_issilent)
659                                 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTN_NORM);
660
661                         return true;
662                 }
663                 case WR_INIT:
664                 {
665                         return true;
666                 }
667                 case WR_ZOOMRETICLE:
668                 {
669                         // no weapon specific image for this weapon
670                         return false;
671                 }
672         }
673         return false;
674 }
675 #endif
676 #endif