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