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 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
14 this.event_damage = func_null;
15 this.takedamage = DAMAGE_NO;
17 if(this.move_movetype == MOVETYPE_NONE)
18 this.velocity = this.oldvelocity;
20 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);
25 void W_Mortar_Grenade_Explode_use(entity this, entity actor, entity trigger)
27 W_Mortar_Grenade_Explode(this, trigger);
30 void W_Mortar_Grenade_Explode2(entity this, entity directhitentity)
32 if(directhitentity.takedamage == DAMAGE_AIM)
33 if(IS_PLAYER(directhitentity))
34 if(DIFF_TEAM(this.realowner, directhitentity))
35 if(!IS_DEAD(directhitentity))
36 if(IsFlying(directhitentity))
37 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
39 this.event_damage = func_null;
40 this.takedamage = DAMAGE_NO;
42 if(this.move_movetype == MOVETYPE_NONE)
43 this.velocity = this.oldvelocity;
45 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);
50 void W_Mortar_Grenade_Explode2_use(entity this, entity actor, entity trigger)
52 W_Mortar_Grenade_Explode2(this, trigger);
55 void W_Mortar_Grenade_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
57 if(GetResource(this, RES_HEALTH) <= 0)
60 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
61 return; // g_projectiles_damage says to halt
63 TakeResource(this, RES_HEALTH, damage);
65 if(GetResource(this, RES_HEALTH) <= 0)
66 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
69 void W_Mortar_Grenade_Think1(entity this)
71 this.nextthink = time;
74 this.projectiledeathtype |= HITTYPE_BOUNCE;
75 W_Mortar_Grenade_Explode(this, NULL);
78 if(this.gl_detonate_later && this.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
79 W_Mortar_Grenade_Explode(this, NULL);
82 void W_Mortar_Grenade_Touch1(entity this, entity toucher)
84 PROJECTILE_TOUCH(this, toucher);
85 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
87 this.use(this, NULL, toucher);
89 else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
91 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
92 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
93 this.projectiledeathtype |= HITTYPE_BOUNCE;
94 this.gl_bouncecnt += 1;
96 else if(WEP_CVAR_PRI(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
98 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
100 // let it stick whereever it is
101 this.oldvelocity = this.velocity;
102 this.velocity = '0 0 0';
103 set_movetype(this, MOVETYPE_NONE); // also disables gravity
104 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
105 UpdateCSQCProjectile(this);
107 // do not respond to any more touches
108 this.solid = SOLID_NOT;
110 this.nextthink = min(this.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
114 void W_Mortar_Grenade_Touch2(entity this, entity toucher)
116 PROJECTILE_TOUCH(this, toucher);
117 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
119 this.use(this, NULL, toucher);
121 else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
123 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
124 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
125 this.projectiledeathtype |= HITTYPE_BOUNCE;
126 this.gl_bouncecnt += 1;
128 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && this.gl_bouncecnt == 1)
129 this.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
132 else if(WEP_CVAR_SEC(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
134 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
136 // let it stick whereever it is
137 this.oldvelocity = this.velocity;
138 this.velocity = '0 0 0';
139 set_movetype(this, MOVETYPE_NONE); // also disables gravity
140 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
141 UpdateCSQCProjectile(this);
143 // do not respond to any more touches
144 this.solid = SOLID_NOT;
146 this.nextthink = min(this.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
150 void W_Mortar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
152 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(mortar, ammo), weaponentity);
154 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);
155 w_shotdir = v_forward; // no TrueAim for grenades please
157 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
159 entity gren = new(grenade);
160 gren.owner = gren.realowner = actor;
161 gren.bot_dodge = true;
162 gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
163 set_movetype(gren, MOVETYPE_BOUNCE);
164 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
165 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
166 PROJECTILE_MAKETRIGGER(gren);
167 gren.projectiledeathtype = thiswep.m_id;
168 gren.weaponentity_fld = weaponentity;
169 setorigin(gren, w_shotorg);
170 setsize(gren, '-3 -3 -3', '3 3 3');
172 gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
173 gren.nextthink = time;
174 setthink(gren, W_Mortar_Grenade_Think1);
175 gren.use = W_Mortar_Grenade_Explode_use;
176 settouch(gren, W_Mortar_Grenade_Touch1);
178 gren.takedamage = DAMAGE_YES;
179 SetResourceExplicit(gren, RES_HEALTH, WEP_CVAR_PRI(mortar, health));
180 gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
181 gren.event_damage = W_Mortar_Grenade_Damage;
182 gren.damagedbycontents = true;
183 IL_PUSH(g_damagedbycontents, gren);
184 gren.missile_flags = MIF_SPLASH | MIF_ARC;
185 W_SetupProjVelocity_UP_PRI(gren, mortar);
187 gren.angles = vectoangles(gren.velocity);
188 gren.flags = FL_PROJECTILE;
189 IL_PUSH(g_projectiles, gren);
190 IL_PUSH(g_bot_dodge, gren);
192 if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
193 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
195 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
197 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
200 void W_Mortar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
204 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(mortar, ammo), weaponentity);
206 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);
207 w_shotdir = v_forward; // no TrueAim for grenades please
209 W_MuzzleFlash(thiswep, actor, weaponentity, w_shotorg, w_shotdir);
212 gren.owner = gren.realowner = actor;
213 gren.bot_dodge = true;
214 gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
215 set_movetype(gren, MOVETYPE_BOUNCE);
216 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
217 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
218 PROJECTILE_MAKETRIGGER(gren);
219 gren.projectiledeathtype = thiswep.m_id | HITTYPE_SECONDARY;
220 gren.weaponentity_fld = weaponentity;
221 setorigin(gren, w_shotorg);
222 setsize(gren, '-3 -3 -3', '3 3 3');
224 gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
225 setthink(gren, adaptor_think2use_hittype_splash);
226 gren.use = W_Mortar_Grenade_Explode2_use;
227 settouch(gren, W_Mortar_Grenade_Touch2);
229 gren.takedamage = DAMAGE_YES;
230 SetResourceExplicit(gren, RES_HEALTH, WEP_CVAR_SEC(mortar, health));
231 gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
232 gren.event_damage = W_Mortar_Grenade_Damage;
233 gren.damagedbycontents = true;
234 IL_PUSH(g_damagedbycontents, gren);
235 gren.missile_flags = MIF_SPLASH | MIF_ARC;
236 W_SetupProjVelocity_UP_SEC(gren, mortar);
238 gren.angles = vectoangles(gren.velocity);
239 gren.flags = FL_PROJECTILE;
240 IL_PUSH(g_projectiles, gren);
241 IL_PUSH(g_bot_dodge, gren);
243 if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
244 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
246 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
248 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
251 .float bot_secondary_grenademooth;
253 METHOD(Mortar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
255 PHYS_INPUT_BUTTON_ATCK(actor) = false;
256 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
257 if(actor.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
259 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
261 PHYS_INPUT_BUTTON_ATCK(actor) = true;
262 if(random() < 0.01) actor.bot_secondary_grenademooth = 1;
267 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
269 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
270 if(random() < 0.02) actor.bot_secondary_grenademooth = 0;
276 wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
277 wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
278 wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
280 // for the range calculation, closer to 1 is better
281 wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
282 wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
284 wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
285 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
287 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
290 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
292 if(autocvar_g_balance_mortar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
293 thiswep.wr_reload(thiswep, actor, weaponentity);
296 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
298 W_Mortar_Attack(thiswep, actor, weaponentity);
299 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
304 if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
306 bool nadefound = false;
307 IL_EACH(g_projectiles, it.realowner == actor && it.classname == "grenade",
309 if(!it.gl_detonate_later)
311 it.gl_detonate_later = true;
316 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
318 else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
320 W_Mortar_Attack2(thiswep, actor, weaponentity);
321 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
325 METHOD(Mortar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
327 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(mortar, ammo);
328 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
331 METHOD(Mortar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
333 float ammo_amount = GetResource(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(mortar, ammo);
334 ammo_amount += actor.(weaponentity).(weapon_load[thiswep.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
337 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
339 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
341 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
343 if(w_deathtype & HITTYPE_SECONDARY)
344 return WEAPON_MORTAR_SUICIDE_BOUNCE;
346 return WEAPON_MORTAR_SUICIDE_EXPLODE;
348 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
350 if(w_deathtype & HITTYPE_SECONDARY)
351 return WEAPON_MORTAR_MURDER_BOUNCE;
353 return WEAPON_MORTAR_MURDER_EXPLODE;
359 METHOD(Mortar, wr_impacteffect, void(entity thiswep, entity actor))
362 org2 = w_org + w_backoff * 12;
363 pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
365 sound(actor, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);