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