3 /* WEP_##id */ DEVASTATOR,
4 /* function */ W_Devastator,
5 /* ammotype */ ammo_rockets,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_HIGH,
11 /* simplemdl */ "foobar",
12 /* crosshair */ "gfx/crosshairrocketlauncher 0.5875",
13 /* wepimg */ "weaponrocketlauncher",
14 /* refname */ "devastator",
15 /* wepname */ _("Devastator")
18 #define DEVASTATOR_SETTINGS(w_cvar,w_prop) DEVASTATOR_SETTINGS_LIST(w_cvar, w_prop, DEVASTATOR, devastator)
19 #define DEVASTATOR_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
20 w_cvar(id, sn, NONE, ammo) \
21 w_cvar(id, sn, NONE, animtime) \
22 w_cvar(id, sn, NONE, damage) \
23 w_cvar(id, sn, NONE, damageforcescale) \
24 w_cvar(id, sn, NONE, detonatedelay) \
25 w_cvar(id, sn, NONE, edgedamage) \
26 w_cvar(id, sn, NONE, force) \
27 w_cvar(id, sn, NONE, guidedelay) \
28 w_cvar(id, sn, NONE, guidegoal) \
29 w_cvar(id, sn, NONE, guiderate) \
30 w_cvar(id, sn, NONE, guideratedelay) \
31 w_cvar(id, sn, NONE, guidestop) \
32 w_cvar(id, sn, NONE, health) \
33 w_cvar(id, sn, NONE, lifetime) \
34 w_cvar(id, sn, NONE, radius) \
35 w_cvar(id, sn, NONE, refire) \
36 w_cvar(id, sn, NONE, remote_damage) \
37 w_cvar(id, sn, NONE, remote_edgedamage) \
38 w_cvar(id, sn, NONE, remote_force) \
39 w_cvar(id, sn, NONE, remote_radius) \
40 w_cvar(id, sn, NONE, speed) \
41 w_cvar(id, sn, NONE, speedaccel) \
42 w_cvar(id, sn, NONE, speedstart) \
43 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
44 w_prop(id, sn, float, reloading_time, reload_time) \
45 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
46 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
47 w_prop(id, sn, string, weaponreplace, weaponreplace) \
48 w_prop(id, sn, float, weaponstart, weaponstart) \
49 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride)
52 DEVASTATOR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
54 .float rl_detonate_later;
58 void spawnfunc_weapon_devastator() { weapon_defaultspawnfunc(WEP_DEVASTATOR); }
59 void spawnfunc_weapon_rocketlauncher() { spawnfunc_weapon_devastator(); }
61 void W_Devastator_Unregister()
63 if(self.realowner && self.realowner.lastrocket == self)
65 self.realowner.lastrocket = world;
66 // self.realowner.rl_release = 1;
70 void W_Devastator_Explode()
72 W_Devastator_Unregister();
74 if(other.takedamage == DAMAGE_AIM)
76 if(DIFF_TEAM(self.realowner, other))
77 if(other.deadflag == DEAD_NO)
79 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
81 self.event_damage = func_null;
82 self.takedamage = DAMAGE_NO;
84 RadiusDamage (self, self.realowner, WEP_CVAR(devastator, damage), WEP_CVAR(devastator, edgedamage), WEP_CVAR(devastator, radius), world, world, WEP_CVAR(devastator, force), self.projectiledeathtype, other);
86 if (self.realowner.weapon == WEP_DEVASTATOR)
88 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
90 self.realowner.cnt = WEP_DEVASTATOR;
91 ATTACK_FINISHED(self.realowner) = time;
92 self.realowner.switchweapon = w_getbestweapon(self.realowner);
98 void W_Devastator_DoRemoteExplode()
100 W_Devastator_Unregister();
102 self.event_damage = func_null;
103 self.takedamage = DAMAGE_NO;
105 RadiusDamage (self, self.realowner, WEP_CVAR(devastator, remote_damage), WEP_CVAR(devastator, remote_edgedamage), WEP_CVAR(devastator, remote_radius), world, world, WEP_CVAR(devastator, remote_force), self.projectiledeathtype | HITTYPE_BOUNCE, world);
107 if (self.realowner.weapon == WEP_DEVASTATOR)
109 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
111 self.realowner.cnt = WEP_DEVASTATOR;
112 ATTACK_FINISHED(self.realowner) = time;
113 self.realowner.switchweapon = w_getbestweapon(self.realowner);
119 void W_Devastator_RemoteExplode()
121 if(self.realowner.deadflag == DEAD_NO)
122 if(self.realowner.lastrocket)
124 if((self.spawnshieldtime >= 0)
125 ? (time >= self.spawnshieldtime) // timer
126 : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > WEP_CVAR(devastator, remote_radius)) // safety device
129 W_Devastator_DoRemoteExplode();
134 vector W_Devastator_SteerTo(vector thisdir, vector goaldir, float maxturn_cos)
136 if(thisdir * goaldir > maxturn_cos)
138 if(thisdir * goaldir < -0.9998) // less than 1 degree and opposite
139 return thisdir; // refuse to guide (better than letting a numerical error happen)
143 // g = normalize(thisdir + goaldir * X)
144 // thisdir * g = maxturn
146 // gg = thisdir + goaldir * X
147 // (thisdir * gg)^2 = maxturn^2 * (gg * gg)
149 // (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
150 f = thisdir * goaldir;
151 // (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
152 // 0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
153 m2 = maxturn_cos * maxturn_cos;
154 v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
155 return normalize(thisdir + goaldir * v_y); // the larger solution!
157 // assume thisdir == -goaldir:
159 // v = solve_qadratic(m2 - 1, -2 * (m2 - 1), m2 - 1)
160 // (m2 - 1) x^2 - 2 * (m2 - 1) * x + (m2 - 1) = 0
161 // x^2 - 2 * x + 1 = 0
164 // normalize(thisdir + goaldir)
167 void W_Devastator_Think (void)
169 vector desireddir, olddir, newdir, desiredorigin, goal;
171 float cosminang, cosmaxang, cosang;
174 self.nextthink = time;
178 self.projectiledeathtype |= HITTYPE_BOUNCE;
179 W_Devastator_Explode ();
184 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0');
185 velspeed = WEP_CVAR(devastator, speed) * g_weaponspeedfactor - (self.velocity * v_forward);
187 self.velocity = self.velocity + v_forward * min(WEP_CVAR(devastator, speedaccel) * g_weaponspeedfactor * frametime, velspeed);
189 // laser guided, or remote detonation
190 if (self.realowner.weapon == WEP_DEVASTATOR)
192 if(self == self.realowner.lastrocket)
193 if(!self.realowner.rl_release)
194 if(!self.BUTTON_ATCK2)
195 if(WEP_CVAR(devastator, guiderate))
196 if(time > self.pushltime)
197 if(self.realowner.deadflag == DEAD_NO)
199 f = WEP_CVAR(devastator, guideratedelay);
201 f = bound(0, (time - self.pushltime) / f, 1);
205 velspeed = vlen(self.velocity);
207 makevectors(self.realowner.v_angle);
208 desireddir = WarpZone_RefSys_TransformVelocity(self.realowner, self, v_forward);
209 desiredorigin = WarpZone_RefSys_TransformOrigin(self.realowner, self, self.realowner.origin + self.realowner.view_ofs);
210 olddir = normalize(self.velocity);
212 // now it gets tricky... we want to move like some curve to approximate the target direction
213 // but we are limiting the rate at which we can turn!
214 goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + WEP_CVAR(devastator, guidegoal)) * desireddir;
215 newdir = W_Devastator_SteerTo(olddir, normalize(goal - self.origin), cos(WEP_CVAR(devastator, guiderate) * f * frametime * DEG2RAD));
217 self.velocity = newdir * velspeed;
218 self.angles = vectoangles(self.velocity);
222 pointparticles(particleeffectnum("rocket_guide"), self.origin, self.velocity, 1);
223 // TODO add a better sound here
224 sound (self.realowner, CH_WEAPON_B, "weapons/rocket_mode.wav", VOL_BASE, ATTN_NORM);
229 if(self.rl_detonate_later)
230 W_Devastator_RemoteExplode();
233 if(self.csqcprojectile_clientanimate == 0)
234 UpdateCSQCProjectile(self);
237 void W_Devastator_Touch (void)
239 if(WarpZone_Projectile_Touch())
242 W_Devastator_Unregister();
245 W_Devastator_Unregister();
246 W_Devastator_Explode ();
249 void W_Devastator_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
251 if (self.health <= 0)
254 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
255 return; // g_projectiles_damage says to halt
257 self.health = self.health - damage;
258 self.angles = vectoangles(self.velocity);
260 if (self.health <= 0)
261 W_PrepareExplosionByDamage(attacker, W_Devastator_Explode);
264 void W_Devastator_Attack (void)
269 W_DecreaseAmmo(WEP_CVAR(devastator, ammo));
271 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 5, "weapons/rocket_fire.wav", CH_WEAPON_A, WEP_CVAR(devastator, damage));
272 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
274 missile = WarpZone_RefSys_SpawnSameRefSys(self);
275 missile.owner = missile.realowner = self;
276 self.lastrocket = missile;
277 if(WEP_CVAR(devastator, detonatedelay) >= 0)
278 missile.spawnshieldtime = time + WEP_CVAR(devastator, detonatedelay);
280 missile.spawnshieldtime = -1;
281 missile.pushltime = time + WEP_CVAR(devastator, guidedelay);
282 missile.classname = "rocket";
283 missile.bot_dodge = TRUE;
284 missile.bot_dodgerating = WEP_CVAR(devastator, damage) * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
286 missile.takedamage = DAMAGE_YES;
287 missile.damageforcescale = WEP_CVAR(devastator, damageforcescale);
288 missile.health = WEP_CVAR(devastator, health);
289 missile.event_damage = W_Devastator_Damage;
290 missile.damagedbycontents = TRUE;
292 missile.movetype = MOVETYPE_FLY;
293 PROJECTILE_MAKETRIGGER(missile);
294 missile.projectiledeathtype = WEP_DEVASTATOR;
295 setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
297 setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
298 W_SetupProjVelocity_Basic(missile, WEP_CVAR(devastator, speedstart), 0);
299 missile.angles = vectoangles (missile.velocity);
301 missile.touch = W_Devastator_Touch;
302 missile.think = W_Devastator_Think;
303 missile.nextthink = time;
304 missile.cnt = time + WEP_CVAR(devastator, lifetime);
305 missile.flags = FL_PROJECTILE;
306 missile.missile_flags = MIF_SPLASH;
308 CSQCProjectile(missile, WEP_CVAR(devastator, guiderate) == 0 && WEP_CVAR(devastator, speedaccel) == 0, PROJECTILE_ROCKET, FALSE); // because of fly sound
310 // muzzle flash for 1st person view
312 setmodel (flash, "models/flash.md3"); // precision set below
313 SUB_SetFade (flash, time, 0.1);
314 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
315 W_AttachToShotorg(flash, '5 0 0');
318 other = missile; MUTATOR_CALLHOOK(EditProjectile);
321 float W_Devastator(float req)
328 case WR_AIM: // WEAPONTODO: rewrite this, it's WAY too complicated for what it should be
330 // aim and decide to fire if appropriate
331 self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), FALSE);
332 if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
334 // decide whether to detonate rockets
335 entity missile, targetlist, targ;
336 targetlist = findchainfloat(bot_attack, TRUE);
337 for(missile = world; (missile = find(missile, classname, "rocket")); ) if(missile.realowner == self)
342 if(targ != missile.realowner && vlen(targ.origin - missile.origin) < WEP_CVAR(devastator, radius))
344 self.BUTTON_ATCK2 = TRUE;
351 if(self.BUTTON_ATCK2) self.BUTTON_ATCK = FALSE;
358 if(WEP_CVAR(devastator, reload_ammo) && self.clip_load < WEP_CVAR(devastator, ammo)) // forced reload
359 WEP_ACTION(self.weapon, WR_RELOAD);
364 if(self.rl_release || WEP_CVAR(devastator, guidestop))
365 if(weapon_prepareattack(0, WEP_CVAR(devastator, refire)))
367 W_Devastator_Attack();
368 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(devastator, animtime), w_ready);
375 if(self.BUTTON_ATCK2)
378 for(rock = world; (rock = find(rock, classname, "rocket")); ) if(rock.realowner == self)
380 if(!rock.rl_detonate_later)
382 rock.rl_detonate_later = TRUE;
387 sound (self, CH_WEAPON_B, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
395 if(autocvar_sv_precacheweapons)
397 precache_model("models/flash.md3");
398 precache_model("models/weapons/g_rl.md3");
399 precache_model("models/weapons/v_rl.md3");
400 precache_model("models/weapons/h_rl.iqm");
401 precache_sound("weapons/rocket_det.wav");
402 precache_sound("weapons/rocket_fire.wav");
403 precache_sound("weapons/rocket_mode.wav");
405 DEVASTATOR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
415 // don't switch while guiding a missile
416 if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_DEVASTATOR)
419 if(WEP_CVAR(devastator, reload_ammo))
421 if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo) && self.(weapon_load[WEP_DEVASTATOR]) < WEP_CVAR(devastator, ammo))
424 else if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
437 DEVASTATOR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
447 W_Reload(WEP_CVAR(devastator, ammo), "weapons/reload.wav");
450 case WR_SUICIDEMESSAGE:
452 return WEAPON_DEVASTATOR_SUICIDE;
456 if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
457 return WEAPON_DEVASTATOR_MURDER_SPLASH;
459 return WEAPON_DEVASTATOR_MURDER_DIRECT;
466 float W_Devastator(float req)
470 case WR_IMPACTEFFECT:
473 org2 = w_org + w_backoff * 12;
474 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
476 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
482 precache_sound("weapons/rocket_impact.wav");
487 // no weapon specific image for this weapon