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) \
50 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
53 DEVASTATOR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
55 .float rl_detonate_later;
59 void spawnfunc_weapon_devastator() { weapon_defaultspawnfunc(WEP_DEVASTATOR); }
60 void spawnfunc_weapon_rocketlauncher() { spawnfunc_weapon_devastator(); }
62 void W_Devastator_Unregister()
64 if(self.realowner && self.realowner.lastrocket == self)
66 self.realowner.lastrocket = world;
67 // self.realowner.rl_release = 1;
71 void W_Devastator_Explode()
73 W_Devastator_Unregister();
75 if(other.takedamage == DAMAGE_AIM)
77 if(DIFF_TEAM(self.realowner, other))
78 if(other.deadflag == DEAD_NO)
80 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
82 self.event_damage = func_null;
83 self.takedamage = DAMAGE_NO;
85 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);
87 if (self.realowner.weapon == WEP_DEVASTATOR)
89 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
91 self.realowner.cnt = WEP_DEVASTATOR;
92 ATTACK_FINISHED(self.realowner) = time;
93 self.realowner.switchweapon = w_getbestweapon(self.realowner);
99 void W_Devastator_DoRemoteExplode()
101 W_Devastator_Unregister();
103 self.event_damage = func_null;
104 self.takedamage = DAMAGE_NO;
106 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);
108 if (self.realowner.weapon == WEP_DEVASTATOR)
110 if(self.realowner.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
112 self.realowner.cnt = WEP_DEVASTATOR;
113 ATTACK_FINISHED(self.realowner) = time;
114 self.realowner.switchweapon = w_getbestweapon(self.realowner);
120 void W_Devastator_RemoteExplode()
122 if(self.realowner.deadflag == DEAD_NO)
123 if(self.realowner.lastrocket)
125 if((self.spawnshieldtime >= 0)
126 ? (time >= self.spawnshieldtime) // timer
127 : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > WEP_CVAR(devastator, remote_radius)) // safety device
130 W_Devastator_DoRemoteExplode();
135 vector W_Devastator_SteerTo(vector thisdir, vector goaldir, float maxturn_cos)
137 if(thisdir * goaldir > maxturn_cos)
139 if(thisdir * goaldir < -0.9998) // less than 1 degree and opposite
140 return thisdir; // refuse to guide (better than letting a numerical error happen)
144 // g = normalize(thisdir + goaldir * X)
145 // thisdir * g = maxturn
147 // gg = thisdir + goaldir * X
148 // (thisdir * gg)^2 = maxturn^2 * (gg * gg)
150 // (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
151 f = thisdir * goaldir;
152 // (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
153 // 0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
154 m2 = maxturn_cos * maxturn_cos;
155 v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
156 return normalize(thisdir + goaldir * v_y); // the larger solution!
158 // assume thisdir == -goaldir:
160 // v = solve_qadratic(m2 - 1, -2 * (m2 - 1), m2 - 1)
161 // (m2 - 1) x^2 - 2 * (m2 - 1) * x + (m2 - 1) = 0
162 // x^2 - 2 * x + 1 = 0
165 // normalize(thisdir + goaldir)
168 void W_Devastator_Think (void)
170 vector desireddir, olddir, newdir, desiredorigin, goal;
172 float cosminang, cosmaxang, cosang;
175 self.nextthink = time;
179 self.projectiledeathtype |= HITTYPE_BOUNCE;
180 W_Devastator_Explode ();
185 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0');
186 velspeed = WEP_CVAR(devastator, speed) * g_weaponspeedfactor - (self.velocity * v_forward);
188 self.velocity = self.velocity + v_forward * min(WEP_CVAR(devastator, speedaccel) * g_weaponspeedfactor * frametime, velspeed);
190 // laser guided, or remote detonation
191 if (self.realowner.weapon == WEP_DEVASTATOR)
193 if(self == self.realowner.lastrocket)
194 if(!self.realowner.rl_release)
195 if(!self.BUTTON_ATCK2)
196 if(WEP_CVAR(devastator, guiderate))
197 if(time > self.pushltime)
198 if(self.realowner.deadflag == DEAD_NO)
200 f = WEP_CVAR(devastator, guideratedelay);
202 f = bound(0, (time - self.pushltime) / f, 1);
206 velspeed = vlen(self.velocity);
208 makevectors(self.realowner.v_angle);
209 desireddir = WarpZone_RefSys_TransformVelocity(self.realowner, self, v_forward);
210 desiredorigin = WarpZone_RefSys_TransformOrigin(self.realowner, self, self.realowner.origin + self.realowner.view_ofs);
211 olddir = normalize(self.velocity);
213 // now it gets tricky... we want to move like some curve to approximate the target direction
214 // but we are limiting the rate at which we can turn!
215 goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + WEP_CVAR(devastator, guidegoal)) * desireddir;
216 newdir = W_Devastator_SteerTo(olddir, normalize(goal - self.origin), cos(WEP_CVAR(devastator, guiderate) * f * frametime * DEG2RAD));
218 self.velocity = newdir * velspeed;
219 self.angles = vectoangles(self.velocity);
223 pointparticles(particleeffectnum("rocket_guide"), self.origin, self.velocity, 1);
224 // TODO add a better sound here
225 sound (self.realowner, CH_WEAPON_B, "weapons/rocket_mode.wav", VOL_BASE, ATTN_NORM);
230 if(self.rl_detonate_later)
231 W_Devastator_RemoteExplode();
234 if(self.csqcprojectile_clientanimate == 0)
235 UpdateCSQCProjectile(self);
238 void W_Devastator_Touch (void)
240 if(WarpZone_Projectile_Touch())
243 W_Devastator_Unregister();
246 W_Devastator_Unregister();
247 W_Devastator_Explode ();
250 void W_Devastator_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
252 if (self.health <= 0)
255 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
256 return; // g_projectiles_damage says to halt
258 self.health = self.health - damage;
259 self.angles = vectoangles(self.velocity);
261 if (self.health <= 0)
262 W_PrepareExplosionByDamage(attacker, W_Devastator_Explode);
265 void W_Devastator_Attack (void)
270 W_DecreaseAmmo(WEP_CVAR(devastator, ammo));
272 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 5, "weapons/rocket_fire.wav", CH_WEAPON_A, WEP_CVAR(devastator, damage));
273 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
275 missile = WarpZone_RefSys_SpawnSameRefSys(self);
276 missile.owner = missile.realowner = self;
277 self.lastrocket = missile;
278 if(WEP_CVAR(devastator, detonatedelay) >= 0)
279 missile.spawnshieldtime = time + WEP_CVAR(devastator, detonatedelay);
281 missile.spawnshieldtime = -1;
282 missile.pushltime = time + WEP_CVAR(devastator, guidedelay);
283 missile.classname = "rocket";
284 missile.bot_dodge = TRUE;
285 missile.bot_dodgerating = WEP_CVAR(devastator, damage) * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
287 missile.takedamage = DAMAGE_YES;
288 missile.damageforcescale = WEP_CVAR(devastator, damageforcescale);
289 missile.health = WEP_CVAR(devastator, health);
290 missile.event_damage = W_Devastator_Damage;
291 missile.damagedbycontents = TRUE;
293 missile.movetype = MOVETYPE_FLY;
294 PROJECTILE_MAKETRIGGER(missile);
295 missile.projectiledeathtype = WEP_DEVASTATOR;
296 setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
298 setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
299 W_SetupProjVelocity_Basic(missile, WEP_CVAR(devastator, speedstart), 0);
300 missile.angles = vectoangles (missile.velocity);
302 missile.touch = W_Devastator_Touch;
303 missile.think = W_Devastator_Think;
304 missile.nextthink = time;
305 missile.cnt = time + WEP_CVAR(devastator, lifetime);
306 missile.flags = FL_PROJECTILE;
307 missile.missile_flags = MIF_SPLASH;
309 CSQCProjectile(missile, WEP_CVAR(devastator, guiderate) == 0 && WEP_CVAR(devastator, speedaccel) == 0, PROJECTILE_ROCKET, FALSE); // because of fly sound
311 // muzzle flash for 1st person view
313 setmodel (flash, "models/flash.md3"); // precision set below
314 SUB_SetFade (flash, time, 0.1);
315 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
316 W_AttachToShotorg(flash, '5 0 0');
319 other = missile; MUTATOR_CALLHOOK(EditProjectile);
322 float W_Devastator(float req)
332 // aim and decide to fire if appropriate
333 self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), FALSE);
334 if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
336 // decide whether to detonate rockets
337 entity missile, targetlist, targ;
338 targetlist = findchainfloat(bot_attack, TRUE);
339 for(missile = world; (missile = find(missile, classname, "rocket")); ) if(missile.realowner == self)
344 if(targ != missile.realowner && vlen(targ.origin - missile.origin) < WEP_CVAR(devastator, radius))
346 self.BUTTON_ATCK2 = TRUE;
353 if(self.BUTTON_ATCK2) self.BUTTON_ATCK = FALSE;
361 // aim and decide to fire if appropriate
362 self.BUTTON_ATCK = bot_aim(WEP_CVAR(devastator, speed), 0, WEP_CVAR(devastator, lifetime), FALSE);
363 if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
365 // decide whether to detonate rockets
366 entity missile, targetlist, targ;
367 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
368 float selfdamage, teamdamage, enemydamage;
369 edgedamage = WEP_CVAR(devastator, edgedamage);
370 coredamage = WEP_CVAR(devastator, damage);
371 edgeradius = WEP_CVAR(devastator, radius);
372 recipricoledgeradius = 1 / edgeradius;
376 targetlist = findchainfloat(bot_attack, TRUE);
377 missile = find(world, classname, "rocket");
380 if (missile.realowner != self)
382 missile = find(missile, classname, "rocket");
388 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - missile.origin);
389 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
390 // count potential damage according to type of target
392 selfdamage = selfdamage + d;
393 else if (targ.team == self.team && teamplay)
394 teamdamage = teamdamage + d;
395 else if (bot_shouldattack(targ))
396 enemydamage = enemydamage + d;
399 missile = find(missile, classname, "rocket");
401 float desirabledamage;
402 desirabledamage = enemydamage;
403 if (time > self.invincible_finished && time > self.spawnshieldtime)
404 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
405 if (teamplay && self.team)
406 desirabledamage = desirabledamage - teamdamage;
408 missile = find(world, classname, "rocket");
411 if (missile.realowner != self)
413 missile = find(missile, classname, "rocket");
416 makevectors(missile.v_angle);
418 if (skill > 9) // normal players only do this for the target they are tracking
424 (v_forward * normalize(missile.origin - targ.origin)< 0.1)
425 && desirabledamage > 0.1*coredamage
426 )self.BUTTON_ATCK2 = TRUE;
430 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
431 //As the distance gets larger, a correct detonation gets near imposible
432 //Bots are assumed to use the rocket spawnfunc_light to see if the rocket gets near a player
433 if(v_forward * normalize(missile.origin - self.enemy.origin)< 0.1)
434 if(IS_PLAYER(self.enemy))
435 if(desirabledamage >= 0.1*coredamage)
436 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
437 self.BUTTON_ATCK2 = TRUE;
438 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
441 missile = find(missile, classname, "rocket");
443 // if we would be doing at X percent of the core damage, detonate it
444 // but don't fire a new shot at the same time!
445 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
446 self.BUTTON_ATCK2 = TRUE;
447 if ((skill > 6.5) && (selfdamage > self.health))
448 self.BUTTON_ATCK2 = FALSE;
449 //if(self.BUTTON_ATCK2 == TRUE)
450 // dprint(ftos(desirabledamage),"\n");
451 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
459 if(WEP_CVAR(devastator, reload_ammo) && self.clip_load < WEP_CVAR(devastator, ammo)) // forced reload
460 WEP_ACTION(self.weapon, WR_RELOAD);
465 if(self.rl_release || WEP_CVAR(devastator, guidestop))
466 if(weapon_prepareattack(0, WEP_CVAR(devastator, refire)))
468 W_Devastator_Attack();
469 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR(devastator, animtime), w_ready);
476 if(self.BUTTON_ATCK2)
479 for(rock = world; (rock = find(rock, classname, "rocket")); ) if(rock.realowner == self)
481 if(!rock.rl_detonate_later)
483 rock.rl_detonate_later = TRUE;
488 sound (self, CH_WEAPON_B, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
496 if(autocvar_sv_precacheweapons)
498 precache_model("models/flash.md3");
499 precache_model("models/weapons/g_rl.md3");
500 precache_model("models/weapons/v_rl.md3");
501 precache_model("models/weapons/h_rl.iqm");
502 precache_sound("weapons/rocket_det.wav");
503 precache_sound("weapons/rocket_fire.wav");
504 precache_sound("weapons/rocket_mode.wav");
506 DEVASTATOR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP)
517 // don't switch while guiding a missile
518 if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_DEVASTATOR)
521 if(WEP_CVAR(devastator, reload_ammo))
523 if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo) && self.(weapon_load[WEP_DEVASTATOR]) < WEP_CVAR(devastator, ammo))
526 else if(self.WEP_AMMO(DEVASTATOR) < WEP_CVAR(devastator, ammo))
532 if(self.rl_release == 0)
534 printf("W_Devastator(WR_CHECKAMMO1): %d, %.2f, %d: TRUE\n", self.rl_release, self.WEP_AMMO(DEVASTATOR), WEP_CVAR(devastator, ammo));
539 ammo_amount = self.WEP_AMMO(DEVASTATOR) >= WEP_CVAR(devastator, ammo);
540 ammo_amount += self.(weapon_load[WEP_DEVASTATOR]) >= WEP_CVAR(devastator, ammo);
541 printf("W_Devastator(WR_CHECKAMMO1): %d, %.2f, %d: %s\n", self.rl_release, self.WEP_AMMO(DEVASTATOR), WEP_CVAR(devastator, ammo), (ammo_amount ? "TRUE" : "FALSE"));
545 ammo_amount = self.WEP_AMMO(DEVASTATOR) >= WEP_CVAR(devastator, ammo);
546 ammo_amount += self.(weapon_load[WEP_DEVASTATOR]) >= WEP_CVAR(devastator, ammo);
556 DEVASTATOR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS)
566 W_Reload(WEP_CVAR(devastator, ammo), "weapons/reload.wav");
569 case WR_SUICIDEMESSAGE:
571 return WEAPON_DEVASTATOR_SUICIDE;
575 if((w_deathtype & HITTYPE_BOUNCE) || (w_deathtype & HITTYPE_SPLASH))
576 return WEAPON_DEVASTATOR_MURDER_SPLASH;
578 return WEAPON_DEVASTATOR_MURDER_DIRECT;
585 float W_Devastator(float req)
589 case WR_IMPACTEFFECT:
592 org2 = w_org + w_backoff * 12;
593 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
595 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
601 precache_sound("weapons/rocket_impact.wav");
606 // no weapon specific image for this weapon