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