2 REGISTER_WEAPON(ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, 9, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_HIGH, "rl", "rocketlauncher", _("Rocket Launcher"))
6 .float rl_detonate_later;
8 void W_Rocket_Unregister()
10 if(self.realowner && self.realowner.lastrocket == self)
12 self.realowner.lastrocket = world;
13 // self.realowner.rl_release = 1;
17 void W_Rocket_Explode ()
19 W_Rocket_Unregister();
21 if(other.takedamage == DAMAGE_AIM)
22 if(other.classname == "player")
23 if(IsDifferentTeam(self.realowner, other))
24 if(other.deadflag == DEAD_NO)
26 AnnounceTo(self.realowner, "airshot");
28 self.event_damage = SUB_Null;
29 self.takedamage = DAMAGE_NO;
31 RadiusDamage (self, self.realowner, autocvar_g_balance_rocketlauncher_damage, autocvar_g_balance_rocketlauncher_edgedamage, autocvar_g_balance_rocketlauncher_radius, world, autocvar_g_balance_rocketlauncher_force, self.projectiledeathtype, other);
33 if (self.realowner.weapon == WEP_ROCKET_LAUNCHER)
35 if(self.realowner.ammo_rockets < autocvar_g_balance_rocketlauncher_ammo)
37 self.realowner.cnt = WEP_ROCKET_LAUNCHER;
38 ATTACK_FINISHED(self.realowner) = time;
39 self.realowner.switchweapon = w_getbestweapon(self.realowner);
45 void W_Rocket_DoRemoteExplode ()
47 W_Rocket_Unregister();
49 self.event_damage = SUB_Null;
50 self.takedamage = DAMAGE_NO;
52 RadiusDamage (self, self.realowner, autocvar_g_balance_rocketlauncher_remote_damage, autocvar_g_balance_rocketlauncher_remote_edgedamage, autocvar_g_balance_rocketlauncher_remote_radius, world, autocvar_g_balance_rocketlauncher_remote_force, self.projectiledeathtype | HITTYPE_BOUNCE, world);
54 if (self.realowner.weapon == WEP_ROCKET_LAUNCHER)
56 if(self.realowner.ammo_rockets < autocvar_g_balance_rocketlauncher_ammo)
58 self.realowner.cnt = WEP_ROCKET_LAUNCHER;
59 ATTACK_FINISHED(self.realowner) = time;
60 self.realowner.switchweapon = w_getbestweapon(self.realowner);
66 entity FindLaserTarget(entity e, float dist_variance, float dot_variance)
68 entity head, selected;
70 float dist, maxdist,// bestdist,
79 makevectors(e.angles);
81 head = find(world, classname, "laser_target");
85 dir = normalize(head.origin - self.origin);
86 dot = dir * v_forward;
87 dist = vlen(head.origin - self.origin);
91 // gain points for being in front
92 points = points + ((dot+1)*0.5) * 500
93 * (1 + crandom()*dot_variance);
94 // gain points for being close away
95 points = points + (1 - dist/maxdist) * 1000
96 * (1 + crandom()*dot_variance);
98 traceline(e.origin, head.origin, TRUE, self);
99 if(trace_fraction < 1)
104 if(points > bestpoints)//random() > 0.5)//
110 head = find(head, classname, "laser_target");
113 //bprint(selected.realowner.netname);
118 void W_Rocket_RemoteExplode()
120 if(self.realowner.deadflag == DEAD_NO)
121 if(self.realowner.lastrocket)
123 if((self.spawnshieldtime >= 0)
124 ? (time >= self.spawnshieldtime) // timer
125 : (vlen(NearestPointOnBox(self.realowner, self.origin) - self.origin) > autocvar_g_balance_rocketlauncher_remote_radius) // safety device
128 W_Rocket_DoRemoteExplode();
133 vector rocket_steerto(vector thisdir, vector goaldir, float maxturn_cos)
135 if(thisdir * goaldir > maxturn_cos)
140 // g = normalize(thisdir + goaldir * X)
141 // thisdir * g = maxturn
143 // gg = thisdir + goaldir * X
144 // (thisdir * gg)^2 = maxturn^2 * (gg * gg)
146 // (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
147 f = thisdir * goaldir;
148 // (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
149 // 0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
150 m2 = maxturn_cos * maxturn_cos;
151 v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
152 return normalize(thisdir + goaldir * v_y); // the larger solution!
155 void W_Rocket_Think (void)
157 vector desireddir, olddir, newdir, desiredorigin, goal;
159 float cosminang, cosmaxang, cosang;
162 self.nextthink = time;
166 self.projectiledeathtype |= HITTYPE_BOUNCE;
172 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0');
173 velspeed = autocvar_g_balance_rocketlauncher_speed * g_weaponspeedfactor - (self.velocity * v_forward);
175 self.velocity = self.velocity + v_forward * min(autocvar_g_balance_rocketlauncher_speedaccel * g_weaponspeedfactor * frametime, velspeed);
177 // laser guided, or remote detonation
178 if (self.realowner.weapon == WEP_ROCKET_LAUNCHER)
180 if(self == self.realowner.lastrocket)
181 if not(self.realowner.rl_release)
182 if not(self.BUTTON_ATCK2)
183 if(autocvar_g_balance_rocketlauncher_guiderate)
184 if(time > self.pushltime)
185 if(self.realowner.deadflag == DEAD_NO)
187 f = autocvar_g_balance_rocketlauncher_guideratedelay;
189 f = bound(0, (time - self.pushltime) / f, 1);
193 velspeed = vlen(self.velocity);
195 makevectors(self.realowner.v_angle);
196 desireddir = WarpZone_RefSys_TransformVelocity(self.realowner, self, v_forward);
197 desiredorigin = WarpZone_RefSys_TransformOrigin(self.realowner, self, self.realowner.origin + self.realowner.view_ofs);
198 olddir = normalize(self.velocity);
200 // now it gets tricky... we want to move like some curve to approximate the target direction
201 // but we are limiting the rate at which we can turn!
202 goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + autocvar_g_balance_rocketlauncher_guidegoal) * desireddir;
203 newdir = rocket_steerto(olddir, normalize(goal - self.origin), cos(autocvar_g_balance_rocketlauncher_guiderate * f * frametime * DEG2RAD));
205 self.velocity = newdir * velspeed;
206 self.angles = vectoangles(self.velocity);
210 pointparticles(particleeffectnum("rocket_guide"), self.origin, self.velocity, 1);
211 // TODO add a better sound here
212 sound (self.realowner, CH_WEAPON_B, "weapons/rocket_mode.wav", VOL_BASE, ATTN_NORM);
217 if(self.rl_detonate_later)
218 W_Rocket_RemoteExplode();
221 if(self.csqcprojectile_clientanimate == 0)
222 UpdateCSQCProjectile(self);
225 void W_Rocket_Touch (void)
227 if(WarpZone_Projectile_Touch())
230 W_Rocket_Unregister();
233 W_Rocket_Unregister();
237 void W_Rocket_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
239 if (self.health <= 0)
242 if (!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
243 return; // g_projectiles_damage says to halt
245 self.health = self.health - damage;
246 self.angles = vectoangles(self.velocity);
248 if (self.health <= 0)
249 W_PrepareExplosionByDamage(attacker, W_Rocket_Explode);
252 void W_Rocket_Attack (void)
257 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_rocketlauncher_ammo, autocvar_g_balance_rocketlauncher_reload_ammo);
259 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 5, "weapons/rocket_fire.wav", CH_WEAPON_A, autocvar_g_balance_rocketlauncher_damage);
260 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
262 missile = WarpZone_RefSys_SpawnSameRefSys(self);
263 missile.owner = missile.realowner = self;
264 self.lastrocket = missile;
265 if(autocvar_g_balance_rocketlauncher_detonatedelay >= 0)
266 missile.spawnshieldtime = time + autocvar_g_balance_rocketlauncher_detonatedelay;
268 missile.spawnshieldtime = -1;
269 missile.pushltime = time + autocvar_g_balance_rocketlauncher_guidedelay;
270 missile.classname = "rocket";
271 missile.bot_dodge = TRUE;
272 missile.bot_dodgerating = autocvar_g_balance_rocketlauncher_damage * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
274 missile.takedamage = DAMAGE_YES;
275 missile.damageforcescale = autocvar_g_balance_rocketlauncher_damageforcescale;
276 missile.health = autocvar_g_balance_rocketlauncher_health;
277 missile.event_damage = W_Rocket_Damage;
278 missile.damagedbycontents = TRUE;
280 missile.movetype = MOVETYPE_FLY;
281 PROJECTILE_MAKETRIGGER(missile);
282 missile.projectiledeathtype = WEP_ROCKET_LAUNCHER;
283 setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
285 setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
286 W_SetupProjectileVelocity(missile, autocvar_g_balance_rocketlauncher_speedstart, 0);
287 missile.angles = vectoangles (missile.velocity);
289 missile.touch = W_Rocket_Touch;
290 missile.think = W_Rocket_Think;
291 missile.nextthink = time;
292 missile.cnt = time + autocvar_g_balance_rocketlauncher_lifetime;
293 missile.flags = FL_PROJECTILE;
295 CSQCProjectile(missile, autocvar_g_balance_rocketlauncher_guiderate == 0 && autocvar_g_balance_rocketlauncher_speedaccel == 0, PROJECTILE_ROCKET, FALSE); // because of fly sound
297 // muzzle flash for 1st person view
299 setmodel (flash, "models/flash.md3"); // precision set below
300 SUB_SetFade (flash, time, 0.1);
301 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
302 W_AttachToShotorg(flash, '5 0 0');
305 other = missile; MUTATOR_CALLHOOK(EditProjectile);
308 void spawnfunc_weapon_rocketlauncher (void); // defined in t_items.qc
310 float w_rlauncher(float req)
318 // aim and decide to fire if appropriate
319 self.BUTTON_ATCK = bot_aim(autocvar_g_balance_rocketlauncher_speed, 0, autocvar_g_balance_rocketlauncher_lifetime, FALSE);
320 if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
322 // decide whether to detonate rockets
323 entity missile, targetlist, targ;
324 float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
325 float selfdamage, teamdamage, enemydamage;
326 edgedamage = autocvar_g_balance_rocketlauncher_edgedamage;
327 coredamage = autocvar_g_balance_rocketlauncher_damage;
328 edgeradius = autocvar_g_balance_rocketlauncher_radius;
329 recipricoledgeradius = 1 / edgeradius;
333 targetlist = findchainfloat(bot_attack, TRUE);
334 missile = find(world, classname, "rocket");
337 if (missile.realowner != self)
339 missile = find(missile, classname, "rocket");
345 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - missile.origin);
346 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
347 // count potential damage according to type of target
349 selfdamage = selfdamage + d;
350 else if (targ.team == self.team && teamplay)
351 teamdamage = teamdamage + d;
352 else if (bot_shouldattack(targ))
353 enemydamage = enemydamage + d;
356 missile = find(missile, classname, "rocket");
358 float desirabledamage;
359 desirabledamage = enemydamage;
360 if (time > self.invincible_finished && time > self.spawnshieldtime)
361 desirabledamage = desirabledamage - selfdamage * autocvar_g_balance_selfdamagepercent;
362 if (teamplay && self.team)
363 desirabledamage = desirabledamage - teamdamage;
365 missile = find(world, classname, "rocket");
368 if (missile.realowner != self)
370 missile = find(missile, classname, "rocket");
373 makevectors(missile.v_angle);
375 if (skill > 9) // normal players only do this for the target they are tracking
381 (v_forward * normalize(missile.origin - targ.origin)< 0.1)
382 && desirabledamage > 0.1*coredamage
383 )self.BUTTON_ATCK2 = TRUE;
387 float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
388 //As the distance gets larger, a correct detonation gets near imposible
389 //Bots are assumed to use the rocket spawnfunc_light to see if the rocket gets near a player
390 if(v_forward * normalize(missile.origin - self.enemy.origin)< 0.1)
391 if(self.enemy.classname == "player")
392 if(desirabledamage >= 0.1*coredamage)
393 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
394 self.BUTTON_ATCK2 = TRUE;
395 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
398 missile = find(missile, classname, "rocket");
400 // if we would be doing at X percent of the core damage, detonate it
401 // but don't fire a new shot at the same time!
402 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
403 self.BUTTON_ATCK2 = TRUE;
404 if ((skill > 6.5) && (selfdamage > self.health))
405 self.BUTTON_ATCK2 = FALSE;
406 //if(self.BUTTON_ATCK2 == TRUE)
407 // dprint(ftos(desirabledamage),"\n");
408 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
411 else if (req == WR_THINK)
413 if(autocvar_g_balance_rocketlauncher_reload_ammo && self.clip_load < autocvar_g_balance_rocketlauncher_ammo) // forced reload
414 weapon_action(self.weapon, WR_RELOAD);
417 if (self.BUTTON_ATCK)
419 if(self.rl_release || autocvar_g_balance_rocketlauncher_guidestop)
420 if(weapon_prepareattack(0, autocvar_g_balance_rocketlauncher_refire))
423 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_rocketlauncher_animtime, w_ready);
430 if (self.BUTTON_ATCK2)
433 for(rock = world; (rock = find(rock, classname, "rocket")); ) if(rock.realowner == self)
435 if(!rock.rl_detonate_later)
437 rock.rl_detonate_later = TRUE;
442 sound (self, CH_WEAPON_B, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
446 else if (req == WR_PRECACHE)
448 precache_model ("models/flash.md3");
449 precache_model ("models/weapons/g_rl.md3");
450 precache_model ("models/weapons/v_rl.md3");
451 precache_model ("models/weapons/h_rl.iqm");
452 precache_sound ("weapons/rocket_det.wav");
453 precache_sound ("weapons/rocket_fire.wav");
454 precache_sound ("weapons/rocket_mode.wav");
455 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
457 else if (req == WR_SETUP)
459 weapon_setup(WEP_ROCKET_LAUNCHER);
460 self.current_ammo = ammo_rockets;
463 else if (req == WR_CHECKAMMO1)
465 // don't switch while guiding a missile
466 if (ATTACK_FINISHED(self) <= time || self.weapon != WEP_ROCKET_LAUNCHER)
468 if(autocvar_g_balance_rocketlauncher_reload_ammo)
470 if(self.ammo_rockets < autocvar_g_balance_rocketlauncher_ammo && self.(weapon_load[WEP_ROCKET_LAUNCHER]) < autocvar_g_balance_rocketlauncher_ammo)
473 else if(self.ammo_rockets < autocvar_g_balance_rocketlauncher_ammo)
478 else if (req == WR_CHECKAMMO2)
480 else if (req == WR_RESETPLAYER)
484 else if (req == WR_RELOAD)
486 W_Reload(autocvar_g_balance_rocketlauncher_ammo, autocvar_g_balance_rocketlauncher_reload_ammo, autocvar_g_balance_rocketlauncher_reload_time, "weapons/reload.wav");
492 float w_rlauncher(float req)
494 if(req == WR_IMPACTEFFECT)
497 org2 = w_org + w_backoff * 12;
498 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
500 sound(self, CH_SHOTS, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
502 else if(req == WR_PRECACHE)
504 precache_sound("weapons/rocket_impact.wav");
506 else if (req == WR_SUICIDEMESSAGE)
507 w_deathtypestring = _("%s blew themself up with their rocketlauncher");
508 else if (req == WR_KILLMESSAGE)
510 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
511 w_deathtypestring = _("%s got too close to %s's rocket");
512 else if(w_deathtype & HITTYPE_SPLASH)
513 w_deathtypestring = _("%s almost dodged %s's rocket");
515 w_deathtypestring = _("%s ate %s's rocket");