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