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, 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, 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, vector hitloc, vector force)
60 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
61 return; // g_projectiles_damage says to halt
63 this.health = this.health - damage;
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));
155 w_shotdir = v_forward; // no TrueAim for grenades please
157 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
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 = WEP_MORTAR.m_id;
168 setorigin(gren, w_shotorg);
169 setsize(gren, '-3 -3 -3', '3 3 3');
171 gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
172 gren.nextthink = time;
173 setthink(gren, W_Mortar_Grenade_Think1);
174 gren.use = W_Mortar_Grenade_Explode_use;
175 settouch(gren, W_Mortar_Grenade_Touch1);
177 gren.takedamage = DAMAGE_YES;
178 gren.health = WEP_CVAR_PRI(mortar, health);
179 gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
180 gren.event_damage = W_Mortar_Grenade_Damage;
181 gren.damagedbycontents = true;
182 IL_PUSH(g_damagedbycontents, gren);
183 gren.missile_flags = MIF_SPLASH | MIF_ARC;
184 W_SetupProjVelocity_UP_PRI(gren, mortar);
186 gren.angles = vectoangles(gren.velocity);
187 gren.flags = FL_PROJECTILE;
188 IL_PUSH(g_projectiles, gren);
189 IL_PUSH(g_bot_dodge, gren);
191 if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
192 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
194 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
196 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
199 void W_Mortar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
203 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(mortar, ammo), weaponentity);
205 W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(mortar, damage));
206 w_shotdir = v_forward; // no TrueAim for grenades please
208 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
211 gren.owner = gren.realowner = actor;
212 gren.bot_dodge = true;
213 gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
214 set_movetype(gren, MOVETYPE_BOUNCE);
215 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
216 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
217 PROJECTILE_MAKETRIGGER(gren);
218 gren.projectiledeathtype = WEP_MORTAR.m_id | HITTYPE_SECONDARY;
219 setorigin(gren, w_shotorg);
220 setsize(gren, '-3 -3 -3', '3 3 3');
222 gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
223 setthink(gren, adaptor_think2use_hittype_splash);
224 gren.use = W_Mortar_Grenade_Explode2_use;
225 settouch(gren, W_Mortar_Grenade_Touch2);
227 gren.takedamage = DAMAGE_YES;
228 gren.health = WEP_CVAR_SEC(mortar, health);
229 gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
230 gren.event_damage = W_Mortar_Grenade_Damage;
231 gren.damagedbycontents = true;
232 IL_PUSH(g_damagedbycontents, gren);
233 gren.missile_flags = MIF_SPLASH | MIF_ARC;
234 W_SetupProjVelocity_UP_SEC(gren, mortar);
236 gren.angles = vectoangles(gren.velocity);
237 gren.flags = FL_PROJECTILE;
238 IL_PUSH(g_projectiles, gren);
239 IL_PUSH(g_bot_dodge, gren);
241 if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
242 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
244 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
246 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
249 .float bot_secondary_grenademooth;
251 METHOD(Mortar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
253 PHYS_INPUT_BUTTON_ATCK(actor) = false;
254 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
255 if(actor.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
257 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
259 PHYS_INPUT_BUTTON_ATCK(actor) = true;
260 if(random() < 0.01) actor.bot_secondary_grenademooth = 1;
265 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
267 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
268 if(random() < 0.02) actor.bot_secondary_grenademooth = 0;
274 wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
275 wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
276 wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
278 // for the range calculation, closer to 1 is better
279 wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
280 wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
282 wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
283 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
285 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
288 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
290 if(autocvar_g_balance_mortar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
291 thiswep.wr_reload(thiswep, actor, weaponentity);
294 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
296 W_Mortar_Attack(thiswep, actor, weaponentity);
297 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
302 if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
304 bool nadefound = false;
305 IL_EACH(g_projectiles, it.realowner == actor && it.classname == "grenade",
307 if(!it.gl_detonate_later)
309 it.gl_detonate_later = true;
314 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
316 else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
318 W_Mortar_Attack2(thiswep, actor, weaponentity);
319 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
323 METHOD(Mortar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
325 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(mortar, ammo);
326 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
329 METHOD(Mortar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
331 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(mortar, ammo);
332 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
335 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
337 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
339 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
341 if(w_deathtype & HITTYPE_SECONDARY)
342 return WEAPON_MORTAR_SUICIDE_BOUNCE;
344 return WEAPON_MORTAR_SUICIDE_EXPLODE;
346 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
348 if(w_deathtype & HITTYPE_SECONDARY)
349 return WEAPON_MORTAR_MURDER_BOUNCE;
351 return WEAPON_MORTAR_MURDER_EXPLODE;
357 METHOD(Mortar, wr_impacteffect, void(entity thiswep, entity actor))
360 org2 = w_org + w_backoff * 12;
361 pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
363 sound(actor, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);