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