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