2 REGISTER_WEAPON(GRENADE_LAUNCHER, w_glauncher, IT_ROCKETS, 4, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH, BOT_PICKUP_RATING_MID, "gl", "grenadelauncher", _("Mortar"))
5 .float gl_detonate_later;
8 void W_Grenade_Explode (void)
10 if(other.takedamage == DAMAGE_AIM)
11 if(other.classname == "player")
12 if(IsDifferentTeam(self.realowner, other))
13 if(other.deadflag == DEAD_NO)
15 AnnounceTo(self.realowner, "airshot");
17 self.event_damage = SUB_Null;
18 self.takedamage = DAMAGE_NO;
20 if(self.movetype == MOVETYPE_NONE)
21 self.velocity = self.oldvelocity;
23 RadiusDamage (self, self.realowner, 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);
28 void W_Grenade_Explode2 (void)
30 if(other.takedamage == DAMAGE_AIM)
31 if(other.classname == "player")
32 if(IsDifferentTeam(self.realowner, other))
33 if(other.deadflag == DEAD_NO)
35 AnnounceTo(self.realowner, "airshot");
37 self.event_damage = SUB_Null;
38 self.takedamage = DAMAGE_NO;
40 if(self.movetype == MOVETYPE_NONE)
41 self.velocity = self.oldvelocity;
43 RadiusDamage (self, self.realowner, 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);
48 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
52 self.health = self.health - damage;
55 W_PrepareExplosionByDamage(attacker, self.think);
59 void W_Grenade_Think1 (void)
61 self.nextthink = time;
65 self.projectiledeathtype |= HITTYPE_BOUNCE;
69 if(self.gl_detonate_later && self.gl_bouncecnt >= autocvar_g_balance_grenadelauncher_primary_remote_minbouncecnt)
73 void W_Grenade_Touch1 (void)
76 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_primary_type == 0) // always explode when hitting a player, or if normal mortar projectile
80 else if (autocvar_g_balance_grenadelauncher_primary_type == 1) // bounce
85 spamsound (self, CH_SHOTS, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
87 spamsound (self, CH_SHOTS, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
89 spamsound (self, CH_SHOTS, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
91 spamsound (self, CH_SHOTS, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
93 spamsound (self, CH_SHOTS, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
95 spamsound (self, CH_SHOTS, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
96 self.projectiledeathtype |= HITTYPE_BOUNCE;
97 self.gl_bouncecnt += 1;
99 else if(autocvar_g_balance_grenadelauncher_primary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
101 spamsound (self, CH_SHOTS, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
103 // let it stick whereever it is
104 self.oldvelocity = self.velocity;
105 self.velocity = '0 0 0';
106 self.movetype = MOVETYPE_NONE; // also disables gravity
107 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
108 UpdateCSQCProjectile(self);
110 // do not respond to any more touches
111 self.solid = SOLID_NOT;
113 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_primary_lifetime_stick);
117 void W_Grenade_Touch2 (void)
120 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_secondary_type == 0) // always explode when hitting a player, or if normal mortar projectile
124 else if (autocvar_g_balance_grenadelauncher_secondary_type == 1) // bounce
129 spamsound (self, CH_SHOTS, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
131 spamsound (self, CH_SHOTS, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
133 spamsound (self, CH_SHOTS, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
135 spamsound (self, CH_SHOTS, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
137 spamsound (self, CH_SHOTS, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
139 spamsound (self, CH_SHOTS, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
140 self.projectiledeathtype |= HITTYPE_BOUNCE;
141 self.gl_bouncecnt += 1;
143 if (autocvar_g_balance_grenadelauncher_secondary_lifetime_bounce && self.gl_bouncecnt == 1)
144 self.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime_bounce;
147 else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
149 spamsound (self, CH_SHOTS, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
151 // let it stick whereever it is
152 self.oldvelocity = self.velocity;
153 self.velocity = '0 0 0';
154 self.movetype = MOVETYPE_NONE; // also disables gravity
155 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
156 UpdateCSQCProjectile(self);
158 // do not respond to any more touches
159 self.solid = SOLID_NOT;
161 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime_stick);
165 void W_Grenade_Attack (void)
169 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
171 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CH_WEAPON_A, autocvar_g_balance_grenadelauncher_primary_damage);
172 w_shotdir = v_forward; // no TrueAim for grenades please
174 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
177 gren.owner = gren.realowner = self;
178 gren.classname = "grenade";
179 gren.bot_dodge = TRUE;
180 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
181 gren.movetype = MOVETYPE_BOUNCE;
182 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
183 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
184 PROJECTILE_MAKETRIGGER(gren);
185 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
186 setorigin(gren, w_shotorg);
187 setsize(gren, '-3 -3 -3', '3 3 3');
189 gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
190 gren.nextthink = time;
191 gren.think = W_Grenade_Think1;
192 gren.use = W_Grenade_Explode;
193 gren.touch = W_Grenade_Touch1;
195 gren.takedamage = DAMAGE_YES;
196 gren.health = autocvar_g_balance_grenadelauncher_primary_health;
197 gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
198 gren.event_damage = W_Grenade_Damage;
199 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
201 gren.angles = vectoangles (gren.velocity);
202 gren.flags = FL_PROJECTILE;
204 if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
205 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
207 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
209 other = gren; MUTATOR_CALLHOOK(EditProjectile);
212 void W_Grenade_Attack2 (void)
216 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_secondary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
218 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CH_WEAPON_A, autocvar_g_balance_grenadelauncher_secondary_damage);
219 w_shotdir = v_forward; // no TrueAim for grenades please
221 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
224 gren.owner = gren.realowner = self;
225 gren.classname = "grenade";
226 gren.bot_dodge = TRUE;
227 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
228 gren.movetype = MOVETYPE_BOUNCE;
229 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
230 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
231 PROJECTILE_MAKETRIGGER(gren);
232 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
233 setorigin(gren, w_shotorg);
234 setsize(gren, '-3 -3 -3', '3 3 3');
236 gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
237 gren.think = adaptor_think2use_hittype_splash;
238 gren.use = W_Grenade_Explode2;
239 gren.touch = W_Grenade_Touch2;
241 gren.takedamage = DAMAGE_YES;
242 gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
243 gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
244 gren.event_damage = W_Grenade_Damage;
245 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
247 gren.angles = vectoangles (gren.velocity);
248 gren.flags = FL_PROJECTILE;
250 if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
251 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
253 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
255 other = gren; MUTATOR_CALLHOOK(EditProjectile);
258 void spawnfunc_weapon_grenadelauncher (void)
260 weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
263 .float bot_secondary_grenademooth;
264 float w_glauncher(float req)
272 self.BUTTON_ATCK = FALSE;
273 self.BUTTON_ATCK2 = FALSE;
274 if (self.bot_secondary_grenademooth == 0)
276 if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
278 self.BUTTON_ATCK = TRUE;
279 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
284 if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
286 self.BUTTON_ATCK2 = TRUE;
287 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
291 else if (req == WR_THINK)
293 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
294 weapon_action(self.weapon, WR_RELOAD);
295 else if (self.BUTTON_ATCK)
297 if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
300 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
303 else if (self.BUTTON_ATCK2)
305 if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
308 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.realowner == self)
310 if(!nade.gl_detonate_later)
312 nade.gl_detonate_later = TRUE;
317 sound (self, CH_WEAPON_B, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
319 else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
322 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
326 else if (req == WR_PRECACHE)
328 precache_model ("models/weapons/g_gl.md3");
329 precache_model ("models/weapons/v_gl.md3");
330 precache_model ("models/weapons/h_gl.iqm");
331 precache_sound ("weapons/grenade_bounce1.wav");
332 precache_sound ("weapons/grenade_bounce2.wav");
333 precache_sound ("weapons/grenade_bounce3.wav");
334 precache_sound ("weapons/grenade_bounce4.wav");
335 precache_sound ("weapons/grenade_bounce5.wav");
336 precache_sound ("weapons/grenade_bounce6.wav");
337 precache_sound ("weapons/grenade_stick.wav");
338 precache_sound ("weapons/grenade_fire.wav");
339 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
341 else if (req == WR_SETUP)
343 weapon_setup(WEP_GRENADE_LAUNCHER);
344 self.current_ammo = ammo_rockets;
346 else if (req == WR_CHECKAMMO1)
348 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
349 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_primary_ammo;
352 else if (req == WR_CHECKAMMO2)
354 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
355 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_secondary_ammo;
358 else if (req == WR_RELOAD)
360 W_Reload(min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo), autocvar_g_balance_grenadelauncher_reload_ammo, autocvar_g_balance_grenadelauncher_reload_time, "weapons/reload.wav");
366 float w_glauncher(float req)
368 if(req == WR_IMPACTEFFECT)
371 org2 = w_org + w_backoff * 12;
372 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
374 sound(self, CH_SHOTS, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
376 else if(req == WR_PRECACHE)
378 precache_sound("weapons/grenade_impact.wav");
380 else if (req == WR_SUICIDEMESSAGE)
382 if(w_deathtype & HITTYPE_SECONDARY)
383 w_deathtypestring = _("%s tried out his own grenade");
385 w_deathtypestring = _("%s detonated");
387 else if (req == WR_KILLMESSAGE)
389 if(w_deathtype & HITTYPE_SPLASH)
390 if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
391 w_deathtypestring = _("%s didn't see %s's grenade");
392 else // unchecked: SECONDARY
393 w_deathtypestring = _("%s almost dodged %s's grenade");
394 else // unchecked: SECONDARY, BOUNCE
395 w_deathtypestring = _("%s ate %s's grenade");