2 REGISTER_WEAPON(GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "gl", "grenadelauncher", _("Mortar"))
5 .float gl_detonate_later;
8 // weapon load persistence, for weapons that support reloading
9 .float grenadelauncher_load;
11 void W_GrenadeLauncher_SetAmmoCounter()
13 // set clip_load to the weapon we have switched to, if the gun uses reloading
14 if(!autocvar_g_balance_grenadelauncher_reload_ammo)
15 self.clip_load = 0; // also keeps crosshair ammo from displaying
18 self.clip_load = self.grenadelauncher_load;
19 self.clip_size = autocvar_g_balance_grenadelauncher_reload_ammo; // for the crosshair ammo display
23 void W_GrenadeLauncher_ReloadedAndReady()
27 // now do the ammo transfer
28 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
29 while(self.clip_load < autocvar_g_balance_grenadelauncher_reload_ammo && self.ammo_rockets) // make sure we don't add more ammo than we have
32 self.ammo_rockets -= 1;
34 self.grenadelauncher_load = self.clip_load;
36 t = ATTACK_FINISHED(self) - autocvar_g_balance_grenadelauncher_reload_time - 1;
37 ATTACK_FINISHED(self) = t;
41 void W_GrenadeLauncher_Reload()
43 // return if reloading is disabled for this weapon
44 if(!autocvar_g_balance_grenadelauncher_reload_ammo)
47 if(!W_ReloadCheck(self.ammo_rockets, min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo)))
52 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
54 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_grenadelauncher_reload_time + 1;
55 ATTACK_FINISHED(self) = t;
57 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_grenadelauncher_reload_time, W_GrenadeLauncher_ReloadedAndReady);
59 self.old_clip_load = self.clip_load;
63 void W_Grenade_Explode (void)
65 if(other.takedamage == DAMAGE_AIM)
66 if(other.classname == "player")
67 if(IsDifferentTeam(self.owner, other))
68 if(other.deadflag == DEAD_NO)
70 AnnounceTo(self.owner, "airshot");
72 self.event_damage = SUB_Null;
73 self.takedamage = DAMAGE_NO;
75 if(self.movetype == MOVETYPE_NONE)
76 self.velocity = self.oldvelocity;
78 RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_primary_damage, autocvar_g_balance_grenadelauncher_primary_edgedamage, autocvar_g_balance_grenadelauncher_primary_radius, world, autocvar_g_balance_grenadelauncher_primary_force, self.projectiledeathtype, other);
83 void W_Grenade_Explode2 (void)
85 if(other.takedamage == DAMAGE_AIM)
86 if(other.classname == "player")
87 if(IsDifferentTeam(self.owner, other))
89 AnnounceTo(self.owner, "airshot");
91 self.event_damage = SUB_Null;
92 self.takedamage = DAMAGE_NO;
94 if(self.movetype == MOVETYPE_NONE)
95 self.velocity = self.oldvelocity;
97 RadiusDamage (self, self.owner, autocvar_g_balance_grenadelauncher_secondary_damage, autocvar_g_balance_grenadelauncher_secondary_edgedamage, autocvar_g_balance_grenadelauncher_secondary_radius, world, autocvar_g_balance_grenadelauncher_secondary_force, self.projectiledeathtype, other);
102 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
104 if (self.health <= 0)
106 self.health = self.health - damage;
107 if (self.health <= 0)
109 W_PrepareExplosionByDamage(attacker, self.think);
113 void W_Grenade_Think1 (void)
115 self.nextthink = time;
119 self.projectiledeathtype |= HITTYPE_BOUNCE;
120 W_Grenade_Explode ();
123 if(self.gl_detonate_later && self.gl_bouncecnt >= autocvar_g_balance_grenadelauncher_primary_remote_minbouncecnt)
127 void W_Grenade_Touch1 (void)
130 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_primary_type == 0) // always explode when hitting a player, or if normal mortar projectile
134 else if (autocvar_g_balance_grenadelauncher_primary_type == 1) // bounce
139 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
141 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
143 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
145 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
147 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
149 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
150 self.projectiledeathtype |= HITTYPE_BOUNCE;
151 self.gl_bouncecnt += 1;
153 else if(autocvar_g_balance_grenadelauncher_primary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
155 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
157 // let it stick whereever it is
158 self.oldvelocity = self.velocity;
159 self.velocity = '0 0 0';
160 self.movetype = MOVETYPE_NONE; // also disables gravity
161 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
162 UpdateCSQCProjectile(self);
164 // do not respond to any more touches
165 self.solid = SOLID_NOT;
167 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_primary_lifetime2);
171 void W_Grenade_Touch2 (void)
174 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_secondary_type == 0) // always explode when hitting a player, or if normal mortar projectile
178 else if (autocvar_g_balance_grenadelauncher_secondary_type == 1) // bounce
183 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
185 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
187 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
189 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
191 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
193 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
194 self.projectiledeathtype |= HITTYPE_BOUNCE;
195 self.gl_bouncecnt += 1;
197 else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
199 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
201 // let it stick whereever it is
202 self.oldvelocity = self.velocity;
203 self.velocity = '0 0 0';
204 self.movetype = MOVETYPE_NONE; // also disables gravity
205 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
206 UpdateCSQCProjectile(self);
208 // do not respond to any more touches
209 self.solid = SOLID_NOT;
211 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime2);
215 void W_Grenade_Attack (void)
219 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
220 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
222 if(autocvar_g_balance_grenadelauncher_reload_ammo)
224 self.clip_load -= autocvar_g_balance_grenadelauncher_primary_ammo;
225 self.grenadelauncher_load = self.clip_load;
228 self.ammo_rockets -= autocvar_g_balance_grenadelauncher_primary_ammo;
231 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_primary_damage);
232 w_shotdir = v_forward; // no TrueAim for grenades please
234 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
238 gren.classname = "grenade";
239 gren.bot_dodge = TRUE;
240 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
241 gren.movetype = MOVETYPE_BOUNCE;
242 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
243 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
244 PROJECTILE_MAKETRIGGER(gren);
245 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
246 setorigin(gren, w_shotorg);
247 setsize(gren, '-3 -3 -3', '3 3 3');
249 gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
250 gren.nextthink = time;
251 gren.think = W_Grenade_Think1;
252 gren.use = W_Grenade_Explode;
253 gren.touch = W_Grenade_Touch1;
255 gren.takedamage = DAMAGE_YES;
256 gren.health = autocvar_g_balance_grenadelauncher_primary_health;
257 gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
258 gren.event_damage = W_Grenade_Damage;
259 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
261 gren.angles = vectoangles (gren.velocity);
262 gren.flags = FL_PROJECTILE;
264 if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
265 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
267 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
269 other = gren; MUTATOR_CALLHOOK(EditProjectile);
272 void W_Grenade_Attack2 (void)
276 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
277 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
279 if(autocvar_g_balance_grenadelauncher_reload_ammo)
281 self.clip_load -= autocvar_g_balance_grenadelauncher_secondary_ammo;
282 self.grenadelauncher_load = self.clip_load;
285 self.ammo_rockets -= autocvar_g_balance_grenadelauncher_secondary_ammo;
288 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_secondary_damage);
289 w_shotdir = v_forward; // no TrueAim for grenades please
291 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
295 gren.classname = "grenade";
296 gren.bot_dodge = TRUE;
297 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
298 gren.movetype = MOVETYPE_BOUNCE;
299 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
300 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
301 PROJECTILE_MAKETRIGGER(gren);
302 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
303 setorigin(gren, w_shotorg);
304 setsize(gren, '-3 -3 -3', '3 3 3');
306 gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
307 gren.think = adaptor_think2use_hittype_splash;
308 gren.use = W_Grenade_Explode2;
309 gren.touch = W_Grenade_Touch2;
311 gren.takedamage = DAMAGE_YES;
312 gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
313 gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
314 gren.event_damage = W_Grenade_Damage;
315 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
317 gren.angles = vectoangles (gren.velocity);
318 gren.flags = FL_PROJECTILE;
320 if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
321 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
323 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
325 other = gren; MUTATOR_CALLHOOK(EditProjectile);
328 void spawnfunc_weapon_grenadelauncher (void)
330 weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
333 .float bot_secondary_grenademooth;
334 float w_glauncher(float req)
342 self.BUTTON_ATCK = FALSE;
343 self.BUTTON_ATCK2 = FALSE;
344 if (self.bot_secondary_grenademooth == 0)
346 if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
348 self.BUTTON_ATCK = TRUE;
349 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
354 if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
356 self.BUTTON_ATCK2 = TRUE;
357 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
361 else if (req == WR_THINK)
363 if(autocvar_g_balance_grenadelauncher_reload_ammo && self.clip_load < min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo)) // forced reload
364 W_GrenadeLauncher_Reload();
365 else if (self.BUTTON_ATCK)
367 if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
370 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
373 else if (self.BUTTON_ATCK2)
375 if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
378 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
380 if(!nade.gl_detonate_later)
382 nade.gl_detonate_later = TRUE;
387 sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
389 else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
392 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
396 else if (req == WR_PRECACHE)
398 precache_model ("models/weapons/g_gl.md3");
399 precache_model ("models/weapons/v_gl.md3");
400 precache_model ("models/weapons/h_gl.iqm");
401 precache_sound ("weapons/grenade_bounce1.wav");
402 precache_sound ("weapons/grenade_bounce2.wav");
403 precache_sound ("weapons/grenade_bounce3.wav");
404 precache_sound ("weapons/grenade_bounce4.wav");
405 precache_sound ("weapons/grenade_bounce5.wav");
406 precache_sound ("weapons/grenade_bounce6.wav");
407 precache_sound ("weapons/grenade_stick.wav");
408 precache_sound ("weapons/grenade_fire.wav");
409 precache_sound ("weapons/reload.wav");
411 else if (req == WR_SETUP)
413 weapon_setup(WEP_GRENADE_LAUNCHER);
414 W_GrenadeLauncher_SetAmmoCounter();
416 else if (req == WR_CHECKAMMO1)
418 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
419 ammo_amount += (autocvar_g_balance_grenadelauncher_reload_ammo && self.grenadelauncher_load >= autocvar_g_balance_grenadelauncher_primary_ammo);
422 else if (req == WR_CHECKAMMO2)
424 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
425 ammo_amount += (autocvar_g_balance_grenadelauncher_reload_ammo && self.grenadelauncher_load >= autocvar_g_balance_grenadelauncher_secondary_ammo);
428 else if (req == WR_RESETPLAYER)
430 // all weapons must be fully loaded when we spawn
431 self.grenadelauncher_load = autocvar_g_balance_grenadelauncher_reload_ammo;
433 else if (req == WR_RELOAD)
435 W_GrenadeLauncher_Reload();
441 float w_glauncher(float req)
443 if(req == WR_IMPACTEFFECT)
446 org2 = w_org + w_backoff * 12;
447 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
449 sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
451 else if(req == WR_PRECACHE)
453 precache_sound("weapons/grenade_impact.wav");
455 else if (req == WR_SUICIDEMESSAGE)
457 if(w_deathtype & HITTYPE_SECONDARY)
458 w_deathtypestring = "%s tried out his own grenade";
460 w_deathtypestring = "%s detonated";
462 else if (req == WR_KILLMESSAGE)
464 if(w_deathtype & HITTYPE_SPLASH)
465 if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
466 w_deathtypestring = "%s didn't see %s's grenade";
467 else // unchecked: SECONDARY
468 w_deathtypestring = "%s almost dodged %s's grenade";
469 else // unchecked: SECONDARY, BOUNCE
470 w_deathtypestring = "%s ate %s's grenade";