5 void W_Mortar_Grenade_Explode(entity this, entity directhitentity)
7 if(directhitentity.takedamage == DAMAGE_AIM)
8 if(IS_PLAYER(directhitentity))
9 if(DIFF_TEAM(this.realowner, directhitentity))
10 if(!IS_DEAD(directhitentity))
11 if(IsFlying(directhitentity)) {
12 Give_Medal(this.realowner, AIRSHOT);
15 this.event_damage = func_null;
16 this.takedamage = DAMAGE_NO;
18 if(this.move_movetype == MOVETYPE_NONE)
19 this.velocity = this.oldvelocity;
21 RadiusDamage(this, this.realowner, WEP_CVAR_PRI(mortar, damage), WEP_CVAR_PRI(mortar, edgedamage), WEP_CVAR_PRI(mortar, radius), NULL, NULL, WEP_CVAR_PRI(mortar, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
26 void W_Mortar_Grenade_Explode_use(entity this, entity actor, entity trigger)
28 W_Mortar_Grenade_Explode(this, trigger);
31 void W_Mortar_Grenade_Explode2(entity this, entity directhitentity)
33 if(directhitentity.takedamage == DAMAGE_AIM)
34 if(IS_PLAYER(directhitentity))
35 if(DIFF_TEAM(this.realowner, directhitentity))
36 if(!IS_DEAD(directhitentity))
37 if(IsFlying(directhitentity)) {
38 Give_Medal(this.realowner, AIRSHOT);
41 this.event_damage = func_null;
42 this.takedamage = DAMAGE_NO;
44 if(this.move_movetype == MOVETYPE_NONE)
45 this.velocity = this.oldvelocity;
47 RadiusDamage(this, this.realowner, WEP_CVAR_SEC(mortar, damage), WEP_CVAR_SEC(mortar, edgedamage), WEP_CVAR_SEC(mortar, radius), NULL, NULL, WEP_CVAR_SEC(mortar, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
52 void W_Mortar_Grenade_Explode2_use(entity this, entity actor, entity trigger)
54 W_Mortar_Grenade_Explode2(this, trigger);
57 void W_Mortar_Grenade_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
59 if(GetResource(this, RES_HEALTH) <= 0)
62 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
63 return; // g_projectiles_damage says to halt
65 TakeResource(this, RES_HEALTH, damage);
67 if(GetResource(this, RES_HEALTH) <= 0)
68 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
71 void W_Mortar_Grenade_Think1(entity this)
73 this.nextthink = time;
76 this.projectiledeathtype |= HITTYPE_BOUNCE;
77 W_Mortar_Grenade_Explode(this, NULL);
80 if(this.gl_detonate_later && this.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
81 W_Mortar_Grenade_Explode(this, NULL);
84 void W_Mortar_Grenade_Touch1(entity this, entity toucher)
86 PROJECTILE_TOUCH(this, toucher);
87 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
89 this.use(this, NULL, toucher);
91 else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
93 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
94 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
95 this.projectiledeathtype |= HITTYPE_BOUNCE;
96 this.gl_bouncecnt += 1;
98 else if(WEP_CVAR_PRI(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
100 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
102 // let it stick whereever it is
103 this.oldvelocity = this.velocity;
104 this.velocity = '0 0 0';
105 set_movetype(this, MOVETYPE_NONE); // also disables gravity
106 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
107 UpdateCSQCProjectile(this);
109 // do not respond to any more touches
110 this.solid = SOLID_NOT;
112 this.nextthink = min(this.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
116 void W_Mortar_Grenade_Touch2(entity this, entity toucher)
118 PROJECTILE_TOUCH(this, toucher);
119 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
121 this.use(this, NULL, toucher);
123 else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
125 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
126 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
127 this.projectiledeathtype |= HITTYPE_BOUNCE;
128 this.gl_bouncecnt += 1;
130 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && this.gl_bouncecnt == 1)
131 this.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
134 else if(WEP_CVAR_SEC(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
136 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
138 // let it stick whereever it is
139 this.oldvelocity = this.velocity;
140 this.velocity = '0 0 0';
141 set_movetype(this, MOVETYPE_NONE); // also disables gravity
142 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
143 UpdateCSQCProjectile(this);
145 // do not respond to any more touches
146 this.solid = SOLID_NOT;
148 this.nextthink = min(this.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
152 void W_Mortar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
154 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(mortar, ammo), weaponentity);
156 W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(mortar, damage), thiswep.m_id);
157 w_shotdir = v_forward; // no TrueAim for grenades please
159 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
161 entity gren = new(grenade);
162 gren.owner = gren.realowner = actor;
163 gren.bot_dodge = true;
164 gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
165 set_movetype(gren, MOVETYPE_BOUNCE);
166 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
167 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
168 PROJECTILE_MAKETRIGGER(gren);
169 gren.projectiledeathtype = thiswep.m_id;
170 gren.weaponentity_fld = weaponentity;
171 setorigin(gren, w_shotorg);
172 setsize(gren, '-3 -3 -3', '3 3 3');
174 gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
175 gren.nextthink = time;
176 setthink(gren, W_Mortar_Grenade_Think1);
177 gren.use = W_Mortar_Grenade_Explode_use;
178 settouch(gren, W_Mortar_Grenade_Touch1);
180 gren.takedamage = DAMAGE_YES;
181 SetResourceExplicit(gren, RES_HEALTH, WEP_CVAR_PRI(mortar, health));
182 gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
183 gren.event_damage = W_Mortar_Grenade_Damage;
184 gren.damagedbycontents = true;
185 IL_PUSH(g_damagedbycontents, gren);
186 gren.missile_flags = MIF_SPLASH | MIF_ARC;
187 W_SetupProjVelocity_UP_PRI(gren, mortar);
189 gren.angles = vectoangles(gren.velocity);
190 gren.flags = FL_PROJECTILE;
191 IL_PUSH(g_projectiles, gren);
192 IL_PUSH(g_bot_dodge, gren);
194 if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
195 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
197 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
199 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
202 void W_Mortar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
206 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(mortar, ammo), weaponentity);
208 W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(mortar, damage), thiswep.m_id | HITTYPE_SECONDARY);
209 w_shotdir = v_forward; // no TrueAim for grenades please
211 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
214 gren.owner = gren.realowner = actor;
215 gren.bot_dodge = true;
216 gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
217 set_movetype(gren, MOVETYPE_BOUNCE);
218 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
219 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
220 PROJECTILE_MAKETRIGGER(gren);
221 gren.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
222 gren.weaponentity_fld = weaponentity;
223 setorigin(gren, w_shotorg);
224 setsize(gren, '-3 -3 -3', '3 3 3');
226 gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
227 setthink(gren, adaptor_think2use_hittype_splash);
228 gren.use = W_Mortar_Grenade_Explode2_use;
229 settouch(gren, W_Mortar_Grenade_Touch2);
231 gren.takedamage = DAMAGE_YES;
232 SetResourceExplicit(gren, RES_HEALTH, WEP_CVAR_SEC(mortar, health));
233 gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
234 gren.event_damage = W_Mortar_Grenade_Damage;
235 gren.damagedbycontents = true;
236 IL_PUSH(g_damagedbycontents, gren);
237 gren.missile_flags = MIF_SPLASH | MIF_ARC;
238 W_SetupProjVelocity_UP_SEC(gren, mortar);
240 gren.angles = vectoangles(gren.velocity);
241 gren.flags = FL_PROJECTILE;
242 IL_PUSH(g_projectiles, gren);
243 IL_PUSH(g_bot_dodge, gren);
245 if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
246 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
248 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
250 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
253 .float bot_secondary_grenademooth;
255 METHOD(Mortar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
257 PHYS_INPUT_BUTTON_ATCK(actor) = false;
258 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
259 if(actor.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
261 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
263 PHYS_INPUT_BUTTON_ATCK(actor) = true;
264 if(random() < 0.01) actor.bot_secondary_grenademooth = 1;
269 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
271 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
272 if(random() < 0.02) actor.bot_secondary_grenademooth = 0;
278 wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
279 wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
280 wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
282 // for the range calculation, closer to 1 is better
283 wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
284 wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
286 wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
287 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
289 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
292 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
294 if(autocvar_g_balance_mortar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
295 thiswep.wr_reload(thiswep, actor, weaponentity);
298 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
300 W_Mortar_Attack(thiswep, actor, weaponentity);
301 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
306 if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
308 bool nadefound = false;
309 IL_EACH(g_projectiles, it.realowner == actor && it.classname == "grenade",
311 if(!it.gl_detonate_later)
313 it.gl_detonate_later = true;
318 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
320 else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
322 W_Mortar_Attack2(thiswep, actor, weaponentity);
323 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
327 METHOD(Mortar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
329 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(mortar, ammo);
330 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
333 METHOD(Mortar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
335 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(mortar, ammo);
336 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
339 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
341 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
343 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
345 if(w_deathtype & HITTYPE_SECONDARY)
346 return WEAPON_MORTAR_SUICIDE_BOUNCE;
348 return WEAPON_MORTAR_SUICIDE_EXPLODE;
350 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
352 if(w_deathtype & HITTYPE_SECONDARY)
353 return WEAPON_MORTAR_MURDER_BOUNCE;
355 return WEAPON_MORTAR_MURDER_EXPLODE;
361 METHOD(Mortar, wr_impacteffect, void(entity thiswep, entity actor))
364 org2 = w_org + w_backoff * 12;
365 pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
367 sound(actor, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);