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