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))
34 AnnounceTo(self.owner, "airshot");
36 self.event_damage = SUB_Null;
37 self.takedamage = DAMAGE_NO;
39 if(self.movetype == MOVETYPE_NONE)
40 self.velocity = self.oldvelocity;
42 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);
47 void W_Grenade_Damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
51 self.health = self.health - damage;
54 W_PrepareExplosionByDamage(attacker, self.think);
58 void W_Grenade_Think1 (void)
60 self.nextthink = time;
64 self.projectiledeathtype |= HITTYPE_BOUNCE;
68 if(self.gl_detonate_later && self.gl_bouncecnt >= autocvar_g_balance_grenadelauncher_primary_remote_minbouncecnt)
72 void W_Grenade_Touch1 (void)
75 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_primary_type == 0) // always explode when hitting a player, or if normal mortar projectile
79 else if (autocvar_g_balance_grenadelauncher_primary_type == 1) // bounce
84 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
86 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
88 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
90 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
92 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
94 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
95 self.projectiledeathtype |= HITTYPE_BOUNCE;
96 self.gl_bouncecnt += 1;
98 else if(autocvar_g_balance_grenadelauncher_primary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
100 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
102 // let it stick whereever it is
103 self.oldvelocity = self.velocity;
104 self.velocity = '0 0 0';
105 self.movetype = MOVETYPE_NONE; // also disables gravity
106 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
107 UpdateCSQCProjectile(self);
109 // do not respond to any more touches
110 self.solid = SOLID_NOT;
112 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_primary_lifetime2);
116 void W_Grenade_Touch2 (void)
119 if (other.takedamage == DAMAGE_AIM || autocvar_g_balance_grenadelauncher_secondary_type == 0) // always explode when hitting a player, or if normal mortar projectile
123 else if (autocvar_g_balance_grenadelauncher_secondary_type == 1) // bounce
128 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce1.wav", VOL_BASE, ATTN_NORM);
130 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce2.wav", VOL_BASE, ATTN_NORM);
132 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce3.wav", VOL_BASE, ATTN_NORM);
134 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce4.wav", VOL_BASE, ATTN_NORM);
136 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce5.wav", VOL_BASE, ATTN_NORM);
138 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_bounce6.wav", VOL_BASE, ATTN_NORM);
139 self.projectiledeathtype |= HITTYPE_BOUNCE;
140 self.gl_bouncecnt += 1;
142 else if(autocvar_g_balance_grenadelauncher_secondary_type == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
144 spamsound (self, CHAN_PROJECTILE, "weapons/grenade_stick.wav", VOL_BASE, ATTN_NORM);
146 // let it stick whereever it is
147 self.oldvelocity = self.velocity;
148 self.velocity = '0 0 0';
149 self.movetype = MOVETYPE_NONE; // also disables gravity
150 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
151 UpdateCSQCProjectile(self);
153 // do not respond to any more touches
154 self.solid = SOLID_NOT;
156 self.nextthink = min(self.nextthink, time + autocvar_g_balance_grenadelauncher_secondary_lifetime2);
160 void W_Grenade_Attack (void)
164 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
166 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_primary_damage);
167 w_shotdir = v_forward; // no TrueAim for grenades please
169 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
173 gren.classname = "grenade";
174 gren.bot_dodge = TRUE;
175 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_primary_damage;
176 gren.movetype = MOVETYPE_BOUNCE;
177 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
178 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
179 PROJECTILE_MAKETRIGGER(gren);
180 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER;
181 setorigin(gren, w_shotorg);
182 setsize(gren, '-3 -3 -3', '3 3 3');
184 gren.cnt = time + autocvar_g_balance_grenadelauncher_primary_lifetime;
185 gren.nextthink = time;
186 gren.think = W_Grenade_Think1;
187 gren.use = W_Grenade_Explode;
188 gren.touch = W_Grenade_Touch1;
190 gren.takedamage = DAMAGE_YES;
191 gren.health = autocvar_g_balance_grenadelauncher_primary_health;
192 gren.damageforcescale = autocvar_g_balance_grenadelauncher_primary_damageforcescale;
193 gren.event_damage = W_Grenade_Damage;
194 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_primary);
196 gren.angles = vectoangles (gren.velocity);
197 gren.flags = FL_PROJECTILE;
199 if(autocvar_g_balance_grenadelauncher_primary_type == 0 || autocvar_g_balance_grenadelauncher_primary_type == 2)
200 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
202 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
204 other = gren; MUTATOR_CALLHOOK(EditProjectile);
207 void W_Grenade_Attack2 (void)
211 W_DecreaseAmmo(ammo_rockets, autocvar_g_balance_grenadelauncher_secondary_ammo, autocvar_g_balance_grenadelauncher_reload_ammo);
213 W_SetupShot_ProjectileSize (self, '-3 -3 -3', '3 3 3', FALSE, 4, "weapons/grenade_fire.wav", CHAN_WEAPON, autocvar_g_balance_grenadelauncher_secondary_damage);
214 w_shotdir = v_forward; // no TrueAim for grenades please
216 pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
220 gren.classname = "grenade";
221 gren.bot_dodge = TRUE;
222 gren.bot_dodgerating = autocvar_g_balance_grenadelauncher_secondary_damage;
223 gren.movetype = MOVETYPE_BOUNCE;
224 gren.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
225 gren.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
226 PROJECTILE_MAKETRIGGER(gren);
227 gren.projectiledeathtype = WEP_GRENADE_LAUNCHER | HITTYPE_SECONDARY;
228 setorigin(gren, w_shotorg);
229 setsize(gren, '-3 -3 -3', '3 3 3');
231 gren.nextthink = time + autocvar_g_balance_grenadelauncher_secondary_lifetime;
232 gren.think = adaptor_think2use_hittype_splash;
233 gren.use = W_Grenade_Explode2;
234 gren.touch = W_Grenade_Touch2;
236 gren.takedamage = DAMAGE_YES;
237 gren.health = autocvar_g_balance_grenadelauncher_secondary_health;
238 gren.damageforcescale = autocvar_g_balance_grenadelauncher_secondary_damageforcescale;
239 gren.event_damage = W_Grenade_Damage;
240 W_SETUPPROJECTILEVELOCITY_UP(gren, g_balance_grenadelauncher_secondary);
242 gren.angles = vectoangles (gren.velocity);
243 gren.flags = FL_PROJECTILE;
245 if(autocvar_g_balance_grenadelauncher_secondary_type == 0 || autocvar_g_balance_grenadelauncher_secondary_type == 2)
246 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE, TRUE);
248 CSQCProjectile(gren, TRUE, PROJECTILE_GRENADE_BOUNCING, TRUE);
250 other = gren; MUTATOR_CALLHOOK(EditProjectile);
253 void spawnfunc_weapon_grenadelauncher (void)
255 weapon_defaultspawnfunc(WEP_GRENADE_LAUNCHER);
258 .float bot_secondary_grenademooth;
259 float w_glauncher(float req)
267 self.BUTTON_ATCK = FALSE;
268 self.BUTTON_ATCK2 = FALSE;
269 if (self.bot_secondary_grenademooth == 0)
271 if(bot_aim(autocvar_g_balance_grenadelauncher_primary_speed, autocvar_g_balance_grenadelauncher_primary_speed_up, autocvar_g_balance_grenadelauncher_primary_lifetime, TRUE))
273 self.BUTTON_ATCK = TRUE;
274 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
279 if(bot_aim(autocvar_g_balance_grenadelauncher_secondary_speed, autocvar_g_balance_grenadelauncher_secondary_speed_up, autocvar_g_balance_grenadelauncher_secondary_lifetime, TRUE))
281 self.BUTTON_ATCK2 = TRUE;
282 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
286 else if (req == WR_THINK)
288 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
289 weapon_action(self.weapon, WR_RELOAD);
290 else if (self.BUTTON_ATCK)
292 if (weapon_prepareattack(0, autocvar_g_balance_grenadelauncher_primary_refire))
295 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_grenadelauncher_primary_animtime, w_ready);
298 else if (self.BUTTON_ATCK2)
300 if (cvar("g_balance_grenadelauncher_secondary_remote_detonateprimary"))
303 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.owner == self)
305 if(!nade.gl_detonate_later)
307 nade.gl_detonate_later = TRUE;
312 sound (self, CHAN_WEAPON2, "weapons/rocket_det.wav", VOL_BASE, ATTN_NORM);
314 else if (weapon_prepareattack(1, autocvar_g_balance_grenadelauncher_secondary_refire))
317 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_grenadelauncher_secondary_animtime, w_ready);
321 else if (req == WR_PRECACHE)
323 precache_model ("models/weapons/g_gl.md3");
324 precache_model ("models/weapons/v_gl.md3");
325 precache_model ("models/weapons/h_gl.iqm");
326 precache_sound ("weapons/grenade_bounce1.wav");
327 precache_sound ("weapons/grenade_bounce2.wav");
328 precache_sound ("weapons/grenade_bounce3.wav");
329 precache_sound ("weapons/grenade_bounce4.wav");
330 precache_sound ("weapons/grenade_bounce5.wav");
331 precache_sound ("weapons/grenade_bounce6.wav");
332 precache_sound ("weapons/grenade_stick.wav");
333 precache_sound ("weapons/grenade_fire.wav");
334 precache_sound ("weapons/reload.wav");
336 else if (req == WR_SETUP)
338 weapon_setup(WEP_GRENADE_LAUNCHER);
339 self.current_ammo = ammo_rockets;
341 else if (req == WR_CHECKAMMO1)
343 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_primary_ammo;
344 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_primary_ammo;
347 else if (req == WR_CHECKAMMO2)
349 ammo_amount = self.ammo_rockets >= autocvar_g_balance_grenadelauncher_secondary_ammo;
350 ammo_amount += self.weapon_load[WEP_GRENADE_LAUNCHER] >= autocvar_g_balance_grenadelauncher_secondary_ammo;
353 else if (req == WR_RELOAD)
355 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");
361 float w_glauncher(float req)
363 if(req == WR_IMPACTEFFECT)
366 org2 = w_org + w_backoff * 12;
367 pointparticles(particleeffectnum("grenade_explode"), org2, '0 0 0', 1);
369 sound(self, CHAN_PROJECTILE, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
371 else if(req == WR_PRECACHE)
373 precache_sound("weapons/grenade_impact.wav");
375 else if (req == WR_SUICIDEMESSAGE)
377 if(w_deathtype & HITTYPE_SECONDARY)
378 w_deathtypestring = _("%s tried out his own grenade");
380 w_deathtypestring = _("%s detonated");
382 else if (req == WR_KILLMESSAGE)
384 if(w_deathtype & HITTYPE_SPLASH)
385 if(w_deathtype & HITTYPE_BOUNCE) // (must be secondary then)
386 w_deathtypestring = _("%s didn't see %s's grenade");
387 else // unchecked: SECONDARY
388 w_deathtypestring = _("%s almost dodged %s's grenade");
389 else // unchecked: SECONDARY, BOUNCE
390 w_deathtypestring = _("%s ate %s's grenade");