2 REGISTER_WEAPON(ROCKET_LAUNCHER, w_rlauncher, IT_ROCKETS, 9, WEP_FLAG_NORMAL | 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.owner && self.owner.lastrocket == self)
12 self.owner.lastrocket = world;
13 // self.owner.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.owner, other))
25 AnnounceTo(self.owner, "airshot");
27 self.event_damage = SUB_Null;
28 self.takedamage = DAMAGE_NO;
30 RadiusDamage (self, self.owner, cvar("g_balance_rocketlauncher_damage"), cvar("g_balance_rocketlauncher_edgedamage"), cvar("g_balance_rocketlauncher_radius"), world, cvar("g_balance_rocketlauncher_force"), self.projectiledeathtype, other);
32 if (self.owner.weapon == WEP_ROCKET_LAUNCHER)
34 if(self.owner.ammo_rockets < cvar("g_balance_rocketlauncher_ammo"))
36 self.owner.cnt = WEP_ROCKET_LAUNCHER;
37 ATTACK_FINISHED(self.owner) = time;
38 self.owner.switchweapon = w_getbestweapon(self.owner);
44 void W_Rocket_DoRemoteExplode ()
46 W_Rocket_Unregister();
48 self.event_damage = SUB_Null;
49 self.takedamage = DAMAGE_NO;
51 RadiusDamage (self, self.owner, cvar("g_balance_rocketlauncher_remote_damage"), cvar("g_balance_rocketlauncher_remote_edgedamage"), cvar("g_balance_rocketlauncher_remote_radius"), world, cvar("g_balance_rocketlauncher_remote_force"), self.projectiledeathtype | HITTYPE_BOUNCE, world);
53 if (self.owner.weapon == WEP_ROCKET_LAUNCHER)
55 if(self.owner.ammo_rockets < cvar("g_balance_rocketlauncher_ammo"))
57 self.owner.cnt = WEP_ROCKET_LAUNCHER;
58 ATTACK_FINISHED(self.owner) = time;
59 self.owner.switchweapon = w_getbestweapon(self.owner);
65 entity FindLaserTarget(entity e, float dist_variance, float dot_variance)
67 entity head, selected;
69 float dist, maxdist,// bestdist,
78 makevectors(e.angles);
80 head = find(world, classname, "laser_target");
84 dir = normalize(head.origin - self.origin);
85 dot = dir * v_forward;
86 dist = vlen(head.origin - self.origin);
90 // gain points for being in front
91 points = points + ((dot+1)*0.5) * 500
92 * (1 + crandom()*dot_variance);
93 // gain points for being close away
94 points = points + (1 - dist/maxdist) * 1000
95 * (1 + crandom()*dot_variance);
97 traceline(e.origin, head.origin, TRUE, self);
98 if(trace_fraction < 1)
103 if(points > bestpoints)//random() > 0.5)//
109 head = find(head, classname, "laser_target");
112 //bprint(selected.owner.netname);
117 void W_Rocket_RemoteExplode()
119 if(self.owner.deadflag == DEAD_NO)
120 if(self.owner.lastrocket)
122 if((self.spawnshieldtime >= 0)
123 ? (time >= self.spawnshieldtime) // timer
124 : (vlen(NearestPointOnBox(self.owner, self.origin) - self.origin) > cvar("g_balance_rocketlauncher_remote_radius")) // safety device
127 W_Rocket_DoRemoteExplode();
132 vector rocket_steerto(vector thisdir, vector goaldir, float maxturn_cos)
134 if(thisdir * goaldir > maxturn_cos)
139 // g = normalize(thisdir + goaldir * X)
140 // thisdir * g = maxturn
142 // gg = thisdir + goaldir * X
143 // (thisdir * gg)^2 = maxturn^2 * (gg * gg)
145 // (1 + (thisdir * goaldir) * X)^2 = maxturn^2 * (1 + X*X + 2 * X * thisdir * goaldir)
146 f = thisdir * goaldir;
147 // (1 + f * X)^2 = maxturn^2 * (1 + X*X + 2 * X * f)
148 // 0 = (m^2 - f^2) * x^2 + (2 * f * (m^2 - 1)) * x + (m^2 - 1)
149 m2 = maxturn_cos * maxturn_cos;
150 v = solve_quadratic(m2 - f * f, 2 * f * (m2 - 1), m2 - 1);
151 return normalize(thisdir + goaldir * v_y); // the larger solution!
154 void W_Rocket_Think (void)
156 vector desireddir, olddir, newdir, desiredorigin, goal;
158 float cosminang, cosmaxang, cosang;
161 self.nextthink = time;
165 self.projectiledeathtype |= HITTYPE_BOUNCE;
171 makevectors(self.angles_x * '-1 0 0' + self.angles_y * '0 1 0');
172 velspeed = cvar("g_balance_rocketlauncher_speed") * g_weaponspeedfactor - (self.velocity * v_forward);
174 self.velocity = self.velocity + v_forward * min(cvar("g_balance_rocketlauncher_speedaccel") * g_weaponspeedfactor * frametime, velspeed);
176 // laser guided, or remote detonation
177 if (self.owner.weapon == WEP_ROCKET_LAUNCHER)
179 if(self == self.owner.lastrocket)
180 if not(self.owner.rl_release)
181 if not(self.BUTTON_ATCK2)
182 if(cvar("g_balance_rocketlauncher_guiderate"))
183 if(time > self.pushltime)
184 if(self.owner.deadflag == DEAD_NO)
186 f = cvar("g_balance_rocketlauncher_guideratedelay");
188 f = bound(0, (time - self.pushltime) / f, 1);
192 velspeed = vlen(self.velocity);
194 makevectors(self.owner.v_angle);
195 desireddir = WarpZone_RefSys_TransformVelocity(self.owner, self, v_forward);
196 desiredorigin = WarpZone_RefSys_TransformOrigin(self.owner, self, self.owner.origin + self.owner.view_ofs);
197 olddir = normalize(self.velocity);
199 // now it gets tricky... we want to move like some curve to approximate the target direction
200 // but we are limiting the rate at which we can turn!
201 goal = desiredorigin + ((self.origin - desiredorigin) * desireddir + cvar("g_balance_rocketlauncher_guidegoal")) * desireddir;
202 newdir = rocket_steerto(olddir, normalize(goal - self.origin), cos(cvar("g_balance_rocketlauncher_guiderate") * f * frametime * DEG2RAD));
204 self.velocity = newdir * velspeed;
205 self.angles = vectoangles(self.velocity);
209 pointparticles(particleeffectnum("rocket_guide"), self.origin, self.velocity, 1);
210 // TODO add a better sound here
211 sound (self.owner, CHAN_WEAPON2, "weapons/rocket_mode.wav", VOL_BASE, ATTN_NORM);
216 if(self.rl_detonate_later)
217 W_Rocket_RemoteExplode();
220 if(self.csqcprojectile_clientanimate == 0)
221 UpdateCSQCProjectile(self);
224 void W_Rocket_Touch (void)
226 if(WarpZone_Projectile_Touch())
229 W_Rocket_Unregister();
232 W_Rocket_Unregister();
236 void W_Rocket_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
238 if (self.health <= 0)
240 self.health = self.health - damage;
241 self.angles = vectoangles(self.velocity);
242 if (self.health <= 0)
243 W_PrepareExplosionByDamage(attacker, W_Rocket_Explode);
246 void W_Rocket_Attack (void)
248 local entity missile;
251 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
252 self.ammo_rockets = self.ammo_rockets - cvar("g_balance_rocketlauncher_ammo");
254 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 5, "weapons/rocket_fire.wav", CHAN_WEAPON, cvar("g_balance_rocketlauncher_damage"));
255 pointparticles(particleeffectnum("rocketlauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
257 missile = WarpZone_RefSys_SpawnSameRefSys(self);
258 missile.owner = self;
259 self.lastrocket = missile;
260 if(cvar("g_balance_rocketlauncher_detonatedelay") >= 0)
261 missile.spawnshieldtime = time + cvar("g_balance_rocketlauncher_detonatedelay");
263 missile.spawnshieldtime = -1;
264 missile.pushltime = time + cvar("g_balance_rocketlauncher_guidedelay");
265 missile.classname = "rocket";
266 missile.bot_dodge = TRUE;
267 missile.bot_dodgerating = cvar("g_balance_rocketlauncher_damage") * 2; // * 2 because it can be detonated inflight which makes it even more dangerous
269 missile.takedamage = DAMAGE_YES;
270 missile.damageforcescale = cvar("g_balance_rocketlauncher_damageforcescale");
271 missile.health = cvar("g_balance_rocketlauncher_health");
272 missile.event_damage = W_Rocket_Damage;
274 missile.movetype = MOVETYPE_FLY;
275 PROJECTILE_MAKETRIGGER(missile);
276 missile.projectiledeathtype = WEP_ROCKET_LAUNCHER;
277 setsize (missile, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
279 setorigin (missile, w_shotorg - v_forward * 3); // move it back so it hits the wall at the right point
280 W_SetupProjectileVelocity(missile, cvar("g_balance_rocketlauncher_speedstart"), 0);
281 missile.angles = vectoangles (missile.velocity);
283 missile.touch = W_Rocket_Touch;
284 missile.think = W_Rocket_Think;
285 missile.nextthink = time;
286 missile.cnt = time + cvar("g_balance_rocketlauncher_lifetime");
287 missile.flags = FL_PROJECTILE;
289 CSQCProjectile(missile, cvar("g_balance_rocketlauncher_guiderate") == 0 && cvar("g_balance_rocketlauncher_speedaccel") == 0, PROJECTILE_ROCKET, FALSE); // because of fly sound
291 // muzzle flash for 1st person view
293 setmodel (flash, "models/flash.md3"); // precision set below
294 SUB_SetFade (flash, time, 0.1);
295 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
296 W_AttachToShotorg(flash, '5 0 0');
299 other = missile; MUTATOR_CALLHOOK(EditProjectile);
302 void spawnfunc_weapon_rocketlauncher (void); // defined in t_items.qc
304 float w_rlauncher(float req)
310 // aim and decide to fire if appropriate
311 self.BUTTON_ATCK = bot_aim(cvar("g_balance_rocketlauncher_speed"), 0, cvar("g_balance_rocketlauncher_lifetime"), FALSE);
312 if(skill >= 2) // skill 0 and 1 bots won't detonate rockets!
314 // decide whether to detonate rockets
315 local entity missile, targetlist, targ;
316 local float edgedamage, coredamage, edgeradius, recipricoledgeradius, d;
317 local float selfdamage, teamdamage, enemydamage;
318 edgedamage = cvar("g_balance_rocketlauncher_edgedamage");
319 coredamage = cvar("g_balance_rocketlauncher_damage");
320 edgeradius = cvar("g_balance_rocketlauncher_radius");
321 recipricoledgeradius = 1 / edgeradius;
325 targetlist = findchainfloat(bot_attack, TRUE);
326 missile = find(world, classname, "rocket");
329 if (missile.owner != self)
331 missile = find(missile, classname, "rocket");
337 d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - missile.origin);
338 d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000);
339 // count potential damage according to type of target
341 selfdamage = selfdamage + d;
342 else if (targ.team == self.team && teams_matter)
343 teamdamage = teamdamage + d;
344 else if (bot_shouldattack(targ))
345 enemydamage = enemydamage + d;
348 missile = find(missile, classname, "rocket");
350 local float desirabledamage;
351 desirabledamage = enemydamage;
352 if (autocvar_teamplay != 1 && time > self.invincible_finished && time > self.spawnshieldtime)
353 desirabledamage = desirabledamage - selfdamage * cvar("g_balance_selfdamagepercent");
354 if (self.team && autocvar_teamplay != 1)
355 desirabledamage = desirabledamage - teamdamage;
357 missile = find(world, classname, "rocket");
360 if (missile.owner != self)
362 missile = find(missile, classname, "rocket");
365 makevectors(missile.v_angle);
367 if (skill > 9) // normal players only do this for the target they are tracking
373 (v_forward * normalize(missile.origin - targ.origin)< 0.1)
374 && desirabledamage > 0.1*coredamage
375 )self.BUTTON_ATCK2 = TRUE;
379 local float distance; distance= bound(300,vlen(self.origin-self.enemy.origin),30000);
380 //As the distance gets larger, a correct detonation gets near imposible
381 //Bots are assumed to use the rocket spawnfunc_light to see if the rocket gets near a player
382 if(v_forward * normalize(missile.origin - self.enemy.origin)< 0.1)
383 if(self.enemy.classname == "player")
384 if(desirabledamage >= 0.1*coredamage)
385 if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1))
386 self.BUTTON_ATCK2 = TRUE;
387 // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n");
390 missile = find(missile, classname, "rocket");
392 // if we would be doing at X percent of the core damage, detonate it
393 // but don't fire a new shot at the same time!
394 if (desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events
395 self.BUTTON_ATCK2 = TRUE;
396 if ((skill > 6.5) && (selfdamage > self.health))
397 self.BUTTON_ATCK2 = FALSE;
398 //if(self.BUTTON_ATCK2 == TRUE)
399 // dprint(ftos(desirabledamage),"\n");
400 if (self.BUTTON_ATCK2 == TRUE) self.BUTTON_ATCK = FALSE;
403 else if (req == WR_THINK)
405 if (self.BUTTON_ATCK)
407 if(self.rl_release || cvar("g_balance_rocketlauncher_guidestop"))
408 if(weapon_prepareattack(0, cvar("g_balance_rocketlauncher_refire")))
411 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_rocketlauncher_animtime"), w_ready);
418 if (self.BUTTON_ATCK2)
421 for(rock = world; (rock = find(rock, classname, "rocket")); ) if(rock.owner == self)
423 if(!rock.rl_detonate_later)
425 rock.rl_detonate_later = TRUE;
430 sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
433 else if (req == WR_PRECACHE)
435 precache_model ("models/flash.md3");
436 precache_model ("models/weapons/g_rl.md3");
437 precache_model ("models/weapons/v_rl.md3");
438 precache_model ("models/weapons/h_rl.iqm");
439 precache_sound ("weapons/rocket_det.wav");
440 precache_sound ("weapons/rocket_fire.wav");
441 precache_sound ("weapons/rocket_mode.wav");
443 else if (req == WR_SETUP)
445 weapon_setup(WEP_ROCKET_LAUNCHER);
448 else if (req == WR_CHECKAMMO1)
450 // don't switch while guiding a missile
451 if ((ATTACK_FINISHED(self) <= time || self.weapon != WEP_ROCKET_LAUNCHER)
452 && self.ammo_rockets < cvar("g_balance_rocketlauncher_ammo"))
455 else if (req == WR_CHECKAMMO2)
457 else if (req == WR_RESETPLAYER)
465 float w_rlauncher(float req)
467 if(req == WR_IMPACTEFFECT)
470 org2 = w_org + w_backoff * 12;
471 pointparticles(particleeffectnum("rocket_explode"), org2, '0 0 0', 1);
473 sound(self, CHAN_PROJECTILE, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
475 else if(req == WR_PRECACHE)
477 precache_sound("weapons/rocket_impact.wav");
479 else if (req == WR_SUICIDEMESSAGE)
480 w_deathtypestring = "%s exploded";
481 else if (req == WR_KILLMESSAGE)
483 if(w_deathtype & HITTYPE_BOUNCE) // (remote detonation)
484 w_deathtypestring = "%s got too close to %s's rocket";
485 else if(w_deathtype & HITTYPE_SPLASH)
486 w_deathtypestring = "%s almost dodged %s's rocket";
488 w_deathtypestring = "%s ate %s's rocket";