5 spawnfunc(weapon_mortar) { weapon_defaultspawnfunc(this, WEP_MORTAR); }
6 spawnfunc(weapon_grenadelauncher) { spawnfunc_weapon_mortar(this); }
8 void W_Mortar_Grenade_Explode(entity this, entity directhitentity)
10 if(directhitentity.takedamage == DAMAGE_AIM)
11 if(IS_PLAYER(directhitentity))
12 if(DIFF_TEAM(this.realowner, directhitentity))
13 if(!IS_DEAD(directhitentity))
14 if(IsFlying(directhitentity))
15 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
17 this.event_damage = func_null;
18 this.takedamage = DAMAGE_NO;
20 if(this.move_movetype == MOVETYPE_NONE)
21 this.velocity = this.oldvelocity;
23 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);
28 void W_Mortar_Grenade_Explode_use(entity this, entity actor, entity trigger)
30 W_Mortar_Grenade_Explode(this, trigger);
33 void W_Mortar_Grenade_Explode2(entity this, entity directhitentity)
35 if(directhitentity.takedamage == DAMAGE_AIM)
36 if(IS_PLAYER(directhitentity))
37 if(DIFF_TEAM(this.realowner, directhitentity))
38 if(!IS_DEAD(directhitentity))
39 if(IsFlying(directhitentity))
40 Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
42 this.event_damage = func_null;
43 this.takedamage = DAMAGE_NO;
45 if(this.move_movetype == MOVETYPE_NONE)
46 this.velocity = this.oldvelocity;
48 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);
53 void W_Mortar_Grenade_Explode2_use(entity this, entity actor, entity trigger)
55 W_Mortar_Grenade_Explode2(this, trigger);
58 void W_Mortar_Grenade_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
63 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, -1)) // no exceptions
64 return; // g_projectiles_damage says to halt
66 this.health = this.health - damage;
69 W_PrepareExplosionByDamage(this, attacker, adaptor_think2use);
72 void W_Mortar_Grenade_Think1(entity this)
74 this.nextthink = time;
77 this.projectiledeathtype |= HITTYPE_BOUNCE;
78 W_Mortar_Grenade_Explode(this, NULL);
81 if(this.gl_detonate_later && this.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
82 W_Mortar_Grenade_Explode(this, NULL);
85 void W_Mortar_Grenade_Touch1(entity this, entity toucher)
87 PROJECTILE_TOUCH(this, toucher);
88 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
90 this.use(this, NULL, toucher);
92 else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
94 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
95 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
96 this.projectiledeathtype |= HITTYPE_BOUNCE;
97 this.gl_bouncecnt += 1;
99 else if(WEP_CVAR_PRI(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
101 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
103 // let it stick whereever it is
104 this.oldvelocity = this.velocity;
105 this.velocity = '0 0 0';
106 set_movetype(this, MOVETYPE_NONE); // also disables gravity
107 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
108 UpdateCSQCProjectile(this);
110 // do not respond to any more touches
111 this.solid = SOLID_NOT;
113 this.nextthink = min(this.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
117 void W_Mortar_Grenade_Touch2(entity this, entity toucher)
119 PROJECTILE_TOUCH(this, toucher);
120 if(toucher.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
122 this.use(this, NULL, toucher);
124 else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
126 spamsound(this, CH_SHOTS, SND_GRENADE_BOUNCE_RANDOM(), VOL_BASE, ATTN_NORM);
127 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
128 this.projectiledeathtype |= HITTYPE_BOUNCE;
129 this.gl_bouncecnt += 1;
131 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && this.gl_bouncecnt == 1)
132 this.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
135 else if(WEP_CVAR_SEC(mortar, type) == 2 && (!toucher || (toucher.takedamage != DAMAGE_AIM && toucher.move_movetype == MOVETYPE_NONE))) // stick
137 spamsound(this, CH_SHOTS, SND_GRENADE_STICK, VOL_BASE, ATTN_NORM);
139 // let it stick whereever it is
140 this.oldvelocity = this.velocity;
141 this.velocity = '0 0 0';
142 set_movetype(this, MOVETYPE_NONE); // also disables gravity
143 this.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
144 UpdateCSQCProjectile(this);
146 // do not respond to any more touches
147 this.solid = SOLID_NOT;
149 this.nextthink = min(this.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
153 void W_Mortar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
155 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(mortar, ammo), weaponentity);
157 W_SetupShot_ProjectileSize(actor, weaponentity, '-3 -3 -3', '3 3 3', false, 4, SND_GRENADE_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(mortar, damage));
158 w_shotdir = v_forward; // no TrueAim for grenades please
160 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
162 entity gren = new(grenade);
163 gren.owner = gren.realowner = actor;
164 gren.bot_dodge = true;
165 gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
166 set_movetype(gren, MOVETYPE_BOUNCE);
167 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
168 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
169 PROJECTILE_MAKETRIGGER(gren);
170 gren.projectiledeathtype = WEP_MORTAR.m_id;
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 gren.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));
209 w_shotdir = v_forward; // no TrueAim for grenades please
211 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
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 = WEP_MORTAR.m_id | HITTYPE_SECONDARY;
222 setorigin(gren, w_shotorg);
223 setsize(gren, '-3 -3 -3', '3 3 3');
225 gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
226 setthink(gren, adaptor_think2use_hittype_splash);
227 gren.use = W_Mortar_Grenade_Explode2_use;
228 settouch(gren, W_Mortar_Grenade_Touch2);
230 gren.takedamage = DAMAGE_YES;
231 gren.health = WEP_CVAR_SEC(mortar, health);
232 gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
233 gren.event_damage = W_Mortar_Grenade_Damage;
234 gren.damagedbycontents = true;
235 IL_PUSH(g_damagedbycontents, gren);
236 gren.missile_flags = MIF_SPLASH | MIF_ARC;
237 W_SetupProjVelocity_UP_SEC(gren, mortar);
239 gren.angles = vectoangles(gren.velocity);
240 gren.flags = FL_PROJECTILE;
241 IL_PUSH(g_projectiles, gren);
242 IL_PUSH(g_bot_dodge, gren);
244 if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
245 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
247 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
249 MUTATOR_CALLHOOK(EditProjectile, actor, gren);
252 .float bot_secondary_grenademooth;
254 METHOD(Mortar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
256 PHYS_INPUT_BUTTON_ATCK(actor) = false;
257 PHYS_INPUT_BUTTON_ATCK2(actor) = false;
258 if(actor.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
260 if(bot_aim(actor, weaponentity, WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
262 PHYS_INPUT_BUTTON_ATCK(actor) = true;
263 if(random() < 0.01) actor.bot_secondary_grenademooth = 1;
268 if(bot_aim(actor, weaponentity, WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
270 PHYS_INPUT_BUTTON_ATCK2(actor) = true;
271 if(random() < 0.02) actor.bot_secondary_grenademooth = 0;
277 wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
278 wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
279 wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
281 // for the range calculation, closer to 1 is better
282 wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
283 wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
285 wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
286 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
288 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
291 METHOD(Mortar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
293 if(autocvar_g_balance_mortar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) { // forced reload
294 thiswep.wr_reload(thiswep, actor, weaponentity);
297 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(mortar, refire)))
299 W_Mortar_Attack(thiswep, actor, weaponentity);
300 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
305 if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
307 bool nadefound = false;
308 IL_EACH(g_projectiles, it.realowner == actor && it.classname == "grenade",
310 if(!it.gl_detonate_later)
312 it.gl_detonate_later = true;
317 sound(actor, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
319 else if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(mortar, refire)))
321 W_Mortar_Attack2(thiswep, actor, weaponentity);
322 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
326 METHOD(Mortar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
328 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_PRI(mortar, ammo);
329 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
332 METHOD(Mortar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
334 float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR_SEC(mortar, ammo);
335 ammo_amount += actor.(weaponentity).(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
338 METHOD(Mortar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
340 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND_RELOAD); // WEAPONTODO
342 METHOD(Mortar, wr_suicidemessage, Notification(entity thiswep))
344 if(w_deathtype & HITTYPE_SECONDARY)
345 return WEAPON_MORTAR_SUICIDE_BOUNCE;
347 return WEAPON_MORTAR_SUICIDE_EXPLODE;
349 METHOD(Mortar, wr_killmessage, Notification(entity thiswep))
351 if(w_deathtype & HITTYPE_SECONDARY)
352 return WEAPON_MORTAR_MURDER_BOUNCE;
354 return WEAPON_MORTAR_MURDER_EXPLODE;
360 METHOD(Mortar, wr_impacteffect, void(entity thiswep, entity actor))
363 org2 = w_org + w_backoff * 12;
364 pointparticles(EFFECT_GRENADE_EXPLODE, org2, '0 0 0', 1);
366 sound(actor, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);