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