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.owner, other))
13 if(other.deadflag == DEAD_NO)
15 AnnounceTo(self.owner, "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.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);
28 void W_Grenade_Explode2 (void)
30 if(other.takedamage == DAMAGE_AIM)
31 if(other.classname == "player")
32 if(IsDifferentTeam(self.owner, other))
33 if(other.deadflag == DEAD_NO)
35 AnnounceTo(self.owner, "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.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);
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, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
87 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
89 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
91 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
93 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
95 spamsound (self, CHAN_PROJECTILE, "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, CHAN_PROJECTILE, "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_lifetime2);
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, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
131 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
133 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
135 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
137 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
139 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
140 self.projectiledeathtype |= HITTYPE_BOUNCE;
141 self.gl_bouncecnt += 1;
143 else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
145 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
147 // let it stick whereever it is
148 self.oldvelocity = self.velocity;
149 self.velocity = '0 0 0';
150 self.movetype = MOVETYPE_NONE; // also disables gravity
151 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
152 UpdateCSQCProjectile(self);
154 // do not respond to any more touches
155 self.solid = SOLID_NOT;
157 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime2);
161 void W_Grenade_Attack (void)
165 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
167 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_primary_damage);
168 w_shotdir = v_forward; // no TrueAim for grenades please
170 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
174 gren.classname = "grenade";
175 gren.bot_dodge = TRUE;
176 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
177 gren.movetype = MOVETYPE_BOUNCE;
178 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
179 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
180 PROJECTILE_MAKETRIGGER(gren);
181 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
182 setorigin(gren, w_shotorg);
183 setsize(gren, '-3 -3 -3', '3 3 3');
185 gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
186 gren.nextthink = time;
187 gren.think = W_Grenade_Think1;
188 gren.use = W_Grenade_Explode;
189 gren.touch = W_Grenade_Touch1;
191 gren.takedamage = DAMAGE_YES;
192 gren.health = autocvar_g_balance_grenadelauncher_primary_health;
193 gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
194 gren.event_damage = W_Grenade_Damage;
195 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
197 gren.angles = vectoangles (gren.velocity);
198 gren.flags = FL_PROJECTILE;
200 if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
201 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
203 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
205 other = gren; MUTATOR_CALLHOOK(EditProjectile);
208 void W_Grenade_Attack2 (void)
212 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_secondary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
214 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_secondary_damage);
215 w_shotdir = v_forward; // no TrueAim for grenades please
217 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
221 gren.classname = "grenade";
222 gren.bot_dodge = TRUE;
223 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
224 gren.movetype = MOVETYPE_BOUNCE;
225 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
226 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
227 PROJECTILE_MAKETRIGGER(gren);
228 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
229 setorigin(gren, w_shotorg);
230 setsize(gren, '-3 -3 -3', '3 3 3');
232 gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
233 gren.think = adaptor_think2use_hittype_splash;
234 gren.use = W_Grenade_Explode2;
235 gren.touch = W_Grenade_Touch2;
237 gren.takedamage = DAMAGE_YES;
238 gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
239 gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
240 gren.event_damage = W_Grenade_Damage;
241 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
243 gren.angles = vectoangles (gren.velocity);
244 gren.flags = FL_PROJECTILE;
246 if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
247 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
249 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
251 other = gren; MUTATOR_CALLHOOK(EditProjectile);
254 void spawnfunc_weapon_grenadelauncher (void)
256 weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
259 .float bot_secondary_grenademooth;
260 float w_glauncher(float req)
268 self.BUTTON_ATCK = FALSE;
269 self.BUTTON_ATCK2 = FALSE;
270 if (self.bot_secondary_grenademooth == 0)
272 if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
274 self.BUTTON_ATCK = TRUE;
275 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
280 if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
282 self.BUTTON_ATCK2 = TRUE;
283 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
287 else if (req == WR_THINK)
289 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
290 weapon_action(self.weapon, WR_RELOAD);
291 else if (self.BUTTON_ATCK)
293 if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
296 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
299 else if (self.BUTTON_ATCK2)
301 if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
304 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
306 if(!nade.gl_detonate_later)
308 nade.gl_detonate_later = TRUE;
313 sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
315 else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
318 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
322 else if (req == WR_PRECACHE)
324 precache_model ("models/weapons/g_gl.md3");
325 precache_model ("models/weapons/v_gl.md3");
326 precache_model ("models/weapons/h_gl.iqm");
327 precache_sound ("weapons/grenade_bounce1.wav");
328 precache_sound ("weapons/grenade_bounce2.wav");
329 precache_sound ("weapons/grenade_bounce3.wav");
330 precache_sound ("weapons/grenade_bounce4.wav");
331 precache_sound ("weapons/grenade_bounce5.wav");
332 precache_sound ("weapons/grenade_bounce6.wav");
333 precache_sound ("weapons/grenade_stick.wav");
334 precache_sound ("weapons/grenade_fire.wav");
335 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
337 else if (req == WR_SETUP)
339 weapon_setup(WEP_GRENADE_LAUNCHER);
340 self.current_ammo = ammo_rockets;
342 else if (req == WR_CHECKAMMO1)
344 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
345 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_primary_ammo;
348 else if (req == WR_CHECKAMMO2)
350 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
351 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_secondary_ammo;
354 else if (req == WR_RELOAD)
356 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");
362 float w_glauncher(float req)
364 if(req == WR_IMPACTEFFECT)
367 org2 = w_org + w_backoff * 12;
368 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
370 sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
372 else if(req == WR_PRECACHE)
374 precache_sound("weapons/grenade_impact.wav");
376 else if (req == WR_SUICIDEMESSAGE)
378 if(w_deathtype & HITTYPE_SECONDARY)
379 w_deathtypestring = _("%s tried out his own grenade");
381 w_deathtypestring = _("%s detonated");
383 else if (req == WR_KILLMESSAGE)
385 if(w_deathtype & HITTYPE_SPLASH)
386 if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
387 w_deathtypestring = _("%s didn't see %s's grenade");
388 else // unchecked: SECONDARY
389 w_deathtypestring = _("%s almost dodged %s's grenade");
390 else // unchecked: SECONDARY, BOUNCE
391 w_deathtypestring = _("%s ate %s's grenade");