]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/weapons/weapon/devastator.qc
Port devastator
[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 void spawnfunc_weapon_devastator(void) { weapon_defaultspawnfunc(WEP_DEVASTATOR.m_id); }
68 void spawnfunc_weapon_rocketlauncher(void) { spawnfunc_weapon_devastator(); }
69
70 void W_Devastator_Unregister(void)
71 {SELFPARAM();
72         if(self.realowner && self.realowner.lastrocket == self)
73         {
74                 self.realowner.lastrocket = world;
75                 // self.realowner.rl_release = 1;
76         }
77 }
78
79 void W_Devastator_Explode(void)
80 {SELFPARAM();
81         W_Devastator_Unregister();
82
83         if(other.takedamage == DAMAGE_AIM)
84                 if(IS_PLAYER(other))
85                         if(DIFF_TEAM(self.realowner, other))
86                                 if(other.deadflag == DEAD_NO)
87                                         if(IsFlying(other))
88                                                 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
89
90         self.event_damage = func_null;
91         self.takedamage = DAMAGE_NO;
92
93         RadiusDamage(
94                 self,
95                 self.realowner,
96                 WEP_CVAR(devastator, damage),
97                 WEP_CVAR(devastator, edgedamage),
98                 WEP_CVAR(devastator, radius),
99                 world,
100                 world,
101                 WEP_CVAR(devastator, force),
102                 self.projectiledeathtype,
103                 other
104         );
105
106         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
107         {
108                 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
109                 if(!(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO))
110                 {
111                         self.realowner.cnt = WEP_DEVASTATOR.m_id;
112                         ATTACK_FINISHED(self.realowner) = time;
113                         self.realowner.switchweapon = w_getbestweapon(self.realowner);
114                 }
115         }
116         remove(self);
117 }
118
119 void W_Devastator_DoRemoteExplode(void)
120 {SELFPARAM();
121         W_Devastator_Unregister();
122
123         self.event_damage = func_null;
124         self.takedamage = DAMAGE_NO;
125
126         float handled_as_rocketjump = false;
127
128         entity head = WarpZone_FindRadius(
129                 self.origin,
130                 WEP_CVAR(devastator, remote_jump_radius),
131                 false
132         );
133
134         while(head)
135         {
136                 if(head.takedamage && (head == self.realowner))
137                 {
138                         float distance_to_head = vlen(self.origin - head.WarpZone_findradius_nearest);
139                         if(distance_to_head <= WEP_CVAR(devastator, remote_jump_radius))
140                         {
141                                 // we handled this as a rocketjump :)
142                                 handled_as_rocketjump = true;
143
144                                 // modify velocity
145                                 head.velocity_x *= 0.9;
146                                 head.velocity_y *= 0.9;
147                                 head.velocity_z = bound(
148                                         WEP_CVAR(devastator, remote_jump_velocity_z_min),
149                                         head.velocity.z + WEP_CVAR(devastator, remote_jump_velocity_z_add),
150                                         WEP_CVAR(devastator, remote_jump_velocity_z_max)
151                                 );
152
153                                 // now do the damage
154                                 RadiusDamage(
155                                         self,
156                                         head,
157                                         WEP_CVAR(devastator, remote_jump_damage),
158                                         WEP_CVAR(devastator, remote_jump_damage),
159                                         WEP_CVAR(devastator, remote_jump_radius),
160                                         world,
161                                         head,
162                                         0,
163                                         self.projectiledeathtype | HITTYPE_BOUNCE,
164                                         world
165                                 );
166                                 break;
167                         }
168                 }
169                 head = head.chain;
170         }
171
172         RadiusDamage(
173                 self,
174                 self.realowner,
175                 WEP_CVAR(devastator, remote_damage),
176                 WEP_CVAR(devastator, remote_edgedamage),
177                 WEP_CVAR(devastator, remote_radius),
178                 (handled_as_rocketjump ? head : world),
179                 world,
180                 WEP_CVAR(devastator, remote_force),
181                 self.projectiledeathtype | HITTYPE_BOUNCE,
182                 world
183         );
184
185         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
186         {
187                 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
188                 if(!(self.realowner.items & IT_UNLIMITED_WEAPON_AMMO))
189                 {
190                         self.realowner.cnt = WEP_DEVASTATOR.m_id;
191                         ATTACK_FINISHED(self.realowner) = time;
192                         self.realowner.switchweapon = w_getbestweapon(self.realowner);
193                 }
194         }
195         remove(self);
196 }
197
198 void W_Devastator_RemoteExplode(void)
199 {SELFPARAM();
200         if(self.realowner.deadflag == DEAD_NO)
201         if(self.realowner.lastrocket)
202         {
203                 if((self.spawnshieldtime >= 0)
204                         ? (time >= self.spawnshieldtime) // timer
205                         : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > WEP_CVAR(devastator, remote_radius)) // safety device
206                 )
207                 {
208                         W_Devastator_DoRemoteExplode();
209                 }
210         }
211 }
212
213 vector W_Devastator_SteerTo(vector thisdir, vector goaldir, float maxturn_cos)
214 {
215         if(thisdir * goaldir > maxturn_cos)
216                 return goaldir;
217         if(thisdir * goaldir < -0.9998) // less than 1 degree and opposite
218                 return thisdir; // refuse to guide (better than letting a numerical error happen)
219         float f, m2;
220         vector v;
221         // solve:
222         //   g = normalize(thisdir + goaldir * X)
223         //   thisdir * g = maxturn
224         //
225         //   gg = thisdir + goaldir * X
226         //   (thisdir * gg)^2 = maxturn^2 * (gg * gg)
227         //
228         //   (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
229         f = thisdir * goaldir;
230         //   (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
231         //   0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
232         m2 = maxturn_cos * maxturn_cos;
233         v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
234         return normalize(thisdir + goaldir * v.y); // the larger solution!
235 }
236 // assume thisdir == -goaldir:
237 //   f == -1
238 //   v = solve_qadratic(m2 - 1, -2 * (m2 - 1), m2 - 1)
239 //   (m2 - 1) x^2 - 2 * (m2 - 1) * x + (m2 - 1) = 0
240 //   x^2 - 2 * x + 1 = 0
241 //   (x - 1)^2 = 0
242 //   x = 1
243 //   normalize(thisdir + goaldir)
244 //   normalize(0)
245
246 void W_Devastator_Think(void)
247 {SELFPARAM();
248         vector desireddir, olddir, newdir, desiredorigin, goal;
249         float velspeed, f;
250         self.nextthink = time;
251         if(time > self.cnt)
252         {
253                 other = world;
254                 self.projectiledeathtype |= HITTYPE_BOUNCE;
255                 W_Devastator_Explode();
256                 return;
257         }
258
259         // accelerate
260         makevectors(self.angles.x * '-1 0 0' + self.angles.y * '0 1 0');
261         velspeed = WEP_CVAR(devastator, speed) * W_WeaponSpeedFactor() - (self.velocity * v_forward);
262         if(velspeed > 0)
263                 self.velocity = self.velocity + v_forward * min(WEP_CVAR(devastator, speedaccel) * W_WeaponSpeedFactor() * frametime, velspeed);
264
265         // laser guided, or remote detonation
266         if(self.realowner.weapon == WEP_DEVASTATOR.m_id)
267         {
268                 if(self == self.realowner.lastrocket)
269                 if(!self.realowner.rl_release)
270                 if(!self.BUTTON_ATCK2)
271                 if(WEP_CVAR(devastator, guiderate))
272                 if(time > self.pushltime)
273                 if(self.realowner.deadflag == DEAD_NO)
274                 {
275                         f = WEP_CVAR(devastator, guideratedelay);
276                         if(f)
277                                 f = bound(0, (time - self.pushltime) / f, 1);
278                         else
279                                 f = 1;
280
281                         velspeed = vlen(self.velocity);
282
283                         makevectors(self.realowner.v_angle);
284                         desireddir = WarpZone_RefSys_TransformVelocity(self.realowner, self, v_forward);
285                         desiredorigin = WarpZone_RefSys_TransformOrigin(self.realowner, self, self.realowner.origin + self.realowner.view_ofs);
286                         olddir = normalize(self.velocity);
287
288                         // now it gets tricky... we want to move like some curve to approximate the target direction
289                         // but we are limiting the rate at which we can turn!
290                         goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + WEP_CVAR(devastator, guidegoal)) * desireddir;
291                         newdir = W_Devastator_SteerTo(olddir, normalize(goal - self.origin), cos(WEP_CVAR(devastator, guiderate) * f * frametime * DEG2RAD));
292
293                         self.velocity = newdir * velspeed;
294                         self.angles = vectoangles(self.velocity);
295
296                         if(!self.count)
297                         {
298                                 Send_Effect(EFFECT_ROCKET_GUIDE, self.origin, self.velocity, 1);
299                                 // TODO add a better sound here
300                                 sound(self.realowner, CH_WEAPON_B, SND_ROCKET_MODE, VOL_BASE, ATTN_NORM);
301                                 self.count = 1;
302                         }
303                 }
304
305                 if(self.rl_detonate_later)
306                         W_Devastator_RemoteExplode();
307         }
308
309         if(self.csqcprojectile_clientanimate == 0)
310                 UpdateCSQCProjectile(self);
311 }
312
313 void W_Devastator_Touch(void)
314 {SELFPARAM();
315         if(WarpZone_Projectile_Touch())
316         {
317                 if(wasfreed(self))
318                         W_Devastator_Unregister();
319                 return;
320         }
321         W_Devastator_Unregister();
322         W_Devastator_Explode();
323 }
324
325 void W_Devastator_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
326 {SELFPARAM();
327         if(self.health <= 0)
328                 return;
329
330         if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
331                 return; // g_projectiles_damage says to halt
332
333         self.health = self.health - damage;
334         self.angles = vectoangles(self.velocity);
335
336         if(self.health <= 0)
337                 W_PrepareExplosionByDamage(attacker, W_Devastator_Explode);
338 }
339
340 void W_Devastator_Attack(void)
341 {SELFPARAM();
342         entity missile;
343         entity flash;
344
345         W_DecreaseAmmo(WEP_CVAR(devastator, ammo));
346
347         W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 5, SND(ROCKET_FIRE), CH_WEAPON_A, WEP_CVAR(devastator, damage));
348         Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
349
350         missile = WarpZone_RefSys_SpawnSameRefSys(self);
351         missile.owner = missile.realowner = self;
352         self.lastrocket = missile;
353         if(WEP_CVAR(devastator, detonatedelay) >= 0)
354                 missile.spawnshieldtime = time + WEP_CVAR(devastator, detonatedelay);
355         else
356                 missile.spawnshieldtime = -1;
357         missile.pushltime = time + WEP_CVAR(devastator, guidedelay);
358         missile.classname = "rocket";
359         missile.bot_dodge = true;
360         missile.bot_dodgerating = WEP_CVAR(devastator, damage) * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
361
362         missile.takedamage = DAMAGE_YES;
363         missile.damageforcescale = WEP_CVAR(devastator, damageforcescale);
364         missile.health = WEP_CVAR(devastator, health);
365         missile.event_damage = W_Devastator_Damage;
366         missile.damagedbycontents = true;
367
368         missile.movetype = MOVETYPE_FLY;
369         PROJECTILE_MAKETRIGGER(missile);
370         missile.projectiledeathtype = WEP_DEVASTATOR.m_id;
371         setsize(missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
372
373         setorigin(missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
374         W_SetupProjVelocity_Basic(missile, WEP_CVAR(devastator, speedstart), 0);
375         missile.angles = vectoangles(missile.velocity);
376
377         missile.touch = W_Devastator_Touch;
378         missile.think = W_Devastator_Think;
379         missile.nextthink = time;
380         missile.cnt = time + WEP_CVAR(devastator, lifetime);
381         missile.flags = FL_PROJECTILE;
382         missile.missile_flags = MIF_SPLASH;
383
384         CSQCProjectile(missile, WEP_CVAR(devastator, guiderate) == 0 && WEP_CVAR(devastator, speedaccel) == 0, PROJECTILE_ROCKET, false); // because of fly sound
385
386         // muzzle flash for 1st person view
387         flash = spawn();
388         setmodel(flash, MDL_DEVASTATOR_MUZZLEFLASH); // precision set below
389         SUB_SetFade(flash, time, 0.1);
390         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
391         W_AttachToShotorg(flash, '5 0 0');
392
393         // common properties
394         MUTATOR_CALLHOOK(EditProjectile, self, missile);
395 }
396
397                 #if 0
398                 METHOD(Devastator, wr_aim, bool(entity thiswep))
399                 {
400                         // aim and decide to fire if appropriate
401                         self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), false);
402                         if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
403                         {
404                                 // decide whether to detonate rockets
405                                 entity missile, targetlist, targ;
406                                 targetlist = findchainfloat(bot_attack, true);
407                                 for(missile = world; (missile = find(missile, classname, "rocket")); ) if(missile.realowner == self)
408                                 {
409                                         targ = targetlist;
410                                         while(targ)
411                                         {
412                                                 if(targ != missile.realowner && vlen(targ.origin - missile.origin) < WEP_CVAR(devastator, radius))
413                                                 {
414                                                         self.BUTTON_ATCK2 = true;
415                                                         break;
416                                                 }
417                                                 targ = targ.chain;
418                                         }
419                                 }
420
421                                 if(self.BUTTON_ATCK2) self.BUTTON_ATCK = false;
422                         }
423
424                         return true;
425                 }
426                 #else
427                 METHOD(Devastator, wr_aim, bool(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                         return true;
523                 }
524                 #endif
525                 METHOD(Devastator, wr_think, bool(entity thiswep))
526                 {
527                         if(WEP_CVAR(devastator, reload_ammo) && self.clip_load < WEP_CVAR(devastator, ammo)) // forced reload
528                                 _WEP_ACTION(self.weapon, WR_RELOAD);
529                         else
530                         {
531                                 if(self.BUTTON_ATCK)
532                                 {
533                                         if(self.rl_release || WEP_CVAR(devastator, guidestop))
534                                         if(weapon_prepareattack(0, WEP_CVAR(devastator, refire)))
535                                         {
536                                                 W_Devastator_Attack();
537                                                 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(devastator, animtime), w_ready);
538                                                 self.rl_release = 0;
539                                         }
540                                 }
541                                 else
542                                         self.rl_release = 1;
543
544                                 if(self.BUTTON_ATCK2)
545                                 if(self.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 == self)
550                                         {
551                                                 if(!rock.rl_detonate_later)
552                                                 {
553                                                         rock.rl_detonate_later = true;
554                                                         rockfound = true;
555                                                 }
556                                         }
557                                         if(rockfound)
558                                                 sound(self, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
559                                 }
560                         }
561
562                         return true;
563                 }
564                 METHOD(Devastator, wr_init, bool(entity thiswep))
565                 {
566                         DEVASTATOR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
567                         return true;
568                 }
569                 METHOD(Devastator, wr_setup, bool(entity thiswep))
570                 {
571                         self.rl_release = 1;
572                         return true;
573                 }
574                 METHOD(Devastator, wr_checkammo1, bool(entity thiswep))
575                 {
576                         #if 0
577                         // don't switch while guiding a missile
578                         if(ATTACK_FINISHED(self) <= time || self.weapon != WEP_DEVASTATOR.m_id)
579                         {
580                                 ammo_amount = false;
581                                 if(WEP_CVAR(devastator, reload_ammo))
582                                 {
583                                         if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo) && self.(weapon_load[WEP_DEVASTATOR.m_id]) < WEP_CVAR(devastator, ammo))
584                                                 ammo_amount = true;
585                                 }
586                                 else if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
587                                         ammo_amount = true;
588                                 return !ammo_amount;
589                         }
590                         #endif
591                         #if 0
592                         if(self.rl_release == 0)
593                         {
594                                 LOG_INFOF("W_Devastator(WR_CHECKAMMO1): %d, %.2f, %d: TRUE\n", self.rl_release, self.WEP_AMMO(DEVASTATOR), WEP_CVAR(devastator, ammo));
595                                 return true;
596                         }
597                         else
598                         {
599                                 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                                 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"));
602                                 return ammo_amount;
603                         }
604                         #else
605                         float ammo_amount = self.WEP_AMMO(DEVASTATOR) >= WEP_CVAR(devastator, ammo);
606                         ammo_amount += self.(weapon_load[WEP_DEVASTATOR.m_id]) >= WEP_CVAR(devastator, ammo);
607                         return ammo_amount;
608                         #endif
609                 }
610                 METHOD(Devastator, wr_checkammo2, bool(entity thiswep))
611                 {
612                         return false;
613                 }
614                 METHOD(Devastator, wr_config, bool(entity thiswep))
615                 {
616                         DEVASTATOR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
617                         return true;
618                 }
619                 METHOD(Devastator, wr_resetplayer, bool(entity thiswep))
620                 {
621                         self.rl_release = 0;
622                         return true;
623                 }
624                 METHOD(Devastator, wr_reload, bool(entity thiswep))
625                 {
626                         W_Reload(WEP_CVAR(devastator, ammo), SND(RELOAD));
627                         return true;
628                 }
629                 METHOD(Devastator, wr_suicidemessage, bool(entity thiswep))
630                 {
631                         return WEAPON_DEVASTATOR_SUICIDE;
632                 }
633                 METHOD(Devastator, wr_killmessage, bool(entity thiswep))
634                 {
635                         if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
636                                 return WEAPON_DEVASTATOR_MURDER_SPLASH;
637                         else
638                                 return WEAPON_DEVASTATOR_MURDER_DIRECT;
639                 }
640
641 #endif
642 #ifdef CSQC
643
644                 METHOD(Devastator, wr_impacteffect, bool(entity thiswep))
645                 {
646                         vector org2;
647                         org2 = w_org + w_backoff * 12;
648                         pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), org2, '0 0 0', 1);
649                         if(!w_issilent)
650                                 sound(self, CH_SHOTS, SND_ROCKET_IMPACT, VOL_BASE, ATTN_NORM);
651
652                         return true;
653                 }
654                 METHOD(Devastator, wr_init, bool(entity thiswep))
655                 {
656                         return true;
657                 }
658                 METHOD(Devastator, wr_zoomreticle, bool(entity thiswep))
659                 {
660                         // no weapon specific image for this weapon
661                         return false;
662                 }
663
664 #endif
665 #endif