3 /* ammotype */ ATTRIB(Mortar, ammo_field, .int, ammo_rockets)
4 /* impulse */ ATTRIB(Mortar, impulse, int, 4)
5 /* flags */ ATTRIB(Mortar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(Mortar, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color */ ATTRIB(Mortar, wpcolor, vector, '1 0 0');
8 /* modelname */ ATTRIB(Mortar, mdl, string, "gl");
10 /* model */ ATTRIB(Mortar, m_model, Model, MDL_MORTAR_ITEM);
12 /* crosshair */ ATTRIB(Mortar, w_crosshair, string, "gfx/crosshairgrenadelauncher");
13 /* crosshair */ ATTRIB(Mortar, w_crosshair_size, float, 0.7);
14 /* wepimg */ ATTRIB(Mortar, model2, string, "weapongrenadelauncher");
15 /* refname */ ATTRIB(Mortar, netname, string, "mortar");
16 /* wepname */ ATTRIB(Mortar, message, string, _("Mortar"));
18 REGISTER_WEAPON(MORTAR, NEW(Mortar));
20 #define MORTAR_SETTINGS(w_cvar,w_prop) MORTAR_SETTINGS_LIST(w_cvar, w_prop, MORTAR, mortar)
21 #define MORTAR_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, BOTH, ammo) \
23 w_cvar(id, sn, BOTH, animtime) \
24 w_cvar(id, sn, NONE, bouncefactor) \
25 w_cvar(id, sn, NONE, bouncestop) \
26 w_cvar(id, sn, BOTH, damage) \
27 w_cvar(id, sn, BOTH, damageforcescale) \
28 w_cvar(id, sn, BOTH, edgedamage) \
29 w_cvar(id, sn, BOTH, force) \
30 w_cvar(id, sn, BOTH, health) \
31 w_cvar(id, sn, BOTH, lifetime) \
32 w_cvar(id, sn, SEC, lifetime_bounce) \
33 w_cvar(id, sn, BOTH, lifetime_stick) \
34 w_cvar(id, sn, BOTH, radius) \
35 w_cvar(id, sn, BOTH, refire) \
36 w_cvar(id, sn, SEC, remote_detonateprimary) \
37 w_cvar(id, sn, PRI, remote_minbouncecnt) \
38 w_cvar(id, sn, BOTH, speed) \
39 w_cvar(id, sn, BOTH, speed_up) \
40 w_cvar(id, sn, BOTH, speed_z) \
41 w_cvar(id, sn, BOTH, spread) \
42 w_cvar(id, sn, BOTH, type) \
43 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
44 w_prop(id, sn, float, reloading_time, reload_time) \
45 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
46 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
47 w_prop(id, sn, string, weaponreplace, weaponreplace) \
48 w_prop(id, sn, float, weaponstart, weaponstart) \
49 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
50 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
53 MORTAR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
54 .float gl_detonate_later;
61 void spawnfunc_weapon_mortar(void) { weapon_defaultspawnfunc(WEP_MORTAR.m_id); }
62 void spawnfunc_weapon_grenadelauncher(void) { spawnfunc_weapon_mortar(); }
64 void W_Mortar_Grenade_Explode(void)
66 if(other.takedamage == DAMAGE_AIM)
68 if(DIFF_TEAM(self.realowner, other))
69 if(other.deadflag == DEAD_NO)
71 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
73 self.event_damage = func_null;
74 self.takedamage = DAMAGE_NO;
76 if(self.movetype == MOVETYPE_NONE)
77 self.velocity = self.oldvelocity;
79 RadiusDamage(self, self.realowner, WEP_CVAR_PRI(mortar, damage), WEP_CVAR_PRI(mortar, edgedamage), WEP_CVAR_PRI(mortar, radius), world, world, WEP_CVAR_PRI(mortar, force), self.projectiledeathtype, other);
84 void W_Mortar_Grenade_Explode2(void)
86 if(other.takedamage == DAMAGE_AIM)
88 if(DIFF_TEAM(self.realowner, other))
89 if(other.deadflag == DEAD_NO)
91 Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
93 self.event_damage = func_null;
94 self.takedamage = DAMAGE_NO;
96 if(self.movetype == MOVETYPE_NONE)
97 self.velocity = self.oldvelocity;
99 RadiusDamage(self, self.realowner, WEP_CVAR_SEC(mortar, damage), WEP_CVAR_SEC(mortar, edgedamage), WEP_CVAR_SEC(mortar, radius), world, world, WEP_CVAR_SEC(mortar, force), self.projectiledeathtype, other);
105 void W_Mortar_Grenade_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
110 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, -1)) // no exceptions
111 return; // g_projectiles_damage says to halt
113 self.health = self.health - damage;
116 W_PrepareExplosionByDamage(attacker, self.use);
119 void W_Mortar_Grenade_Think1(void)
121 self.nextthink = time;
125 self.projectiledeathtype |= HITTYPE_BOUNCE;
126 W_Mortar_Grenade_Explode();
129 if(self.gl_detonate_later && self.gl_bouncecnt >= WEP_CVAR_PRI(mortar, remote_minbouncecnt))
130 W_Mortar_Grenade_Explode();
133 void W_Mortar_Grenade_Touch1(void)
136 if(other.takedamage == DAMAGE_AIM || WEP_CVAR_PRI(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
140 else if(WEP_CVAR_PRI(mortar, type) == 1) // bounce
142 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
143 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
144 self.projectiledeathtype |= HITTYPE_BOUNCE;
145 self.gl_bouncecnt += 1;
147 else if(WEP_CVAR_PRI(mortar, type) == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
149 spamsound(self, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
151 // let it stick whereever it is
152 self.oldvelocity = self.velocity;
153 self.velocity = '0 0 0';
154 self.movetype = MOVETYPE_NONE; // also disables gravity
155 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
156 UpdateCSQCProjectile(self);
158 // do not respond to any more touches
159 self.solid = SOLID_NOT;
161 self.nextthink = min(self.nextthink, time + WEP_CVAR_PRI(mortar, lifetime_stick));
165 void W_Mortar_Grenade_Touch2(void)
168 if(other.takedamage == DAMAGE_AIM || WEP_CVAR_SEC(mortar, type) == 0) // always explode when hitting a player, or if normal mortar projectile
172 else if(WEP_CVAR_SEC(mortar, type) == 1) // bounce
174 spamsound(self, CH_SHOTS, SND(GRENADE_BOUNCE_RANDOM()), VOL_BASE, ATTN_NORM);
175 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
176 self.projectiledeathtype |= HITTYPE_BOUNCE;
177 self.gl_bouncecnt += 1;
179 if(WEP_CVAR_SEC(mortar, lifetime_bounce) && self.gl_bouncecnt == 1)
180 self.nextthink = time + WEP_CVAR_SEC(mortar, lifetime_bounce);
183 else if(WEP_CVAR_SEC(mortar, type) == 2 && (!other || (other.takedamage != DAMAGE_AIM && other.movetype == MOVETYPE_NONE))) // stick
185 spamsound(self, CH_SHOTS, SND(GRENADE_STICK), VOL_BASE, ATTN_NORM);
187 // let it stick whereever it is
188 self.oldvelocity = self.velocity;
189 self.velocity = '0 0 0';
190 self.movetype = MOVETYPE_NONE; // also disables gravity
191 self.gravity = 0; // nope, it does NOT! maybe a bug in CSQC code? TODO
192 UpdateCSQCProjectile(self);
194 // do not respond to any more touches
195 self.solid = SOLID_NOT;
197 self.nextthink = min(self.nextthink, time + WEP_CVAR_SEC(mortar, lifetime_stick));
201 void W_Mortar_Attack(Weapon thiswep)
205 W_DecreaseAmmo(thiswep, WEP_CVAR_PRI(mortar, ammo));
207 W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 4, SND(GRENADE_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(mortar, damage));
208 w_shotdir = v_forward; // no TrueAim for grenades please
210 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
213 gren.owner = gren.realowner = self;
214 gren.classname = "grenade";
215 gren.bot_dodge = true;
216 gren.bot_dodgerating = WEP_CVAR_PRI(mortar, damage);
217 gren.movetype = 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;
222 setorigin(gren, w_shotorg);
223 setsize(gren, '-3 -3 -3', '3 3 3');
225 gren.cnt = time + WEP_CVAR_PRI(mortar, lifetime);
226 gren.nextthink = time;
227 gren.think = W_Mortar_Grenade_Think1;
228 gren.use = W_Mortar_Grenade_Explode;
229 gren.touch = W_Mortar_Grenade_Touch1;
231 gren.takedamage = DAMAGE_YES;
232 gren.health = WEP_CVAR_PRI(mortar, health);
233 gren.damageforcescale = WEP_CVAR_PRI(mortar, damageforcescale);
234 gren.event_damage = W_Mortar_Grenade_Damage;
235 gren.damagedbycontents = true;
236 gren.missile_flags = MIF_SPLASH | MIF_ARC;
237 W_SetupProjVelocity_UP_PRI(gren, mortar);
239 gren.angles = vectoangles(gren.velocity);
240 gren.flags = FL_PROJECTILE;
242 if(WEP_CVAR_PRI(mortar, type) == 0 || WEP_CVAR_PRI(mortar, type) == 2)
243 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
245 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
247 MUTATOR_CALLHOOK(EditProjectile, self, gren);
250 void W_Mortar_Attack2(Weapon thiswep)
254 W_DecreaseAmmo(thiswep, WEP_CVAR_SEC(mortar, ammo));
256 W_SetupShot_ProjectileSize(self, '-3 -3 -3', '3 3 3', false, 4, SND(GRENADE_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(mortar, damage));
257 w_shotdir = v_forward; // no TrueAim for grenades please
259 Send_Effect(EFFECT_GRENADE_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
262 gren.owner = gren.realowner = self;
263 gren.classname = "grenade";
264 gren.bot_dodge = true;
265 gren.bot_dodgerating = WEP_CVAR_SEC(mortar, damage);
266 gren.movetype = MOVETYPE_BOUNCE;
267 gren.bouncefactor = WEP_CVAR(mortar, bouncefactor);
268 gren.bouncestop = WEP_CVAR(mortar, bouncestop);
269 PROJECTILE_MAKETRIGGER(gren);
270 gren.projectiledeathtype = WEP_MORTAR.m_id | HITTYPE_SECONDARY;
271 setorigin(gren, w_shotorg);
272 setsize(gren, '-3 -3 -3', '3 3 3');
274 gren.nextthink = time + WEP_CVAR_SEC(mortar, lifetime);
275 gren.think = adaptor_think2use_hittype_splash;
276 gren.use = W_Mortar_Grenade_Explode2;
277 gren.touch = W_Mortar_Grenade_Touch2;
279 gren.takedamage = DAMAGE_YES;
280 gren.health = WEP_CVAR_SEC(mortar, health);
281 gren.damageforcescale = WEP_CVAR_SEC(mortar, damageforcescale);
282 gren.event_damage = W_Mortar_Grenade_Damage;
283 gren.damagedbycontents = true;
284 gren.missile_flags = MIF_SPLASH | MIF_ARC;
285 W_SetupProjVelocity_UP_SEC(gren, mortar);
287 gren.angles = vectoangles(gren.velocity);
288 gren.flags = FL_PROJECTILE;
290 if(WEP_CVAR_SEC(mortar, type) == 0 || WEP_CVAR_SEC(mortar, type) == 2)
291 CSQCProjectile(gren, true, PROJECTILE_GRENADE, true);
293 CSQCProjectile(gren, true, PROJECTILE_GRENADE_BOUNCING, true);
295 MUTATOR_CALLHOOK(EditProjectile, self, gren);
298 .float bot_secondary_grenademooth;
300 METHOD(Mortar, wr_aim, bool(entity thiswep))
302 self.BUTTON_ATCK = false;
303 self.BUTTON_ATCK2 = false;
304 if(self.bot_secondary_grenademooth == 0) // WEAPONTODO: merge this into using WEP_CVAR_BOTH
306 if(bot_aim(WEP_CVAR_PRI(mortar, speed), WEP_CVAR_PRI(mortar, speed_up), WEP_CVAR_PRI(mortar, lifetime), true))
308 self.BUTTON_ATCK = true;
309 if(random() < 0.01) self.bot_secondary_grenademooth = 1;
314 if(bot_aim(WEP_CVAR_SEC(mortar, speed), WEP_CVAR_SEC(mortar, speed_up), WEP_CVAR_SEC(mortar, lifetime), true))
316 self.BUTTON_ATCK2 = true;
317 if(random() < 0.02) self.bot_secondary_grenademooth = 0;
325 wepinfo_pri_refire = max3(sys_frametime, WEP_CVAR_PRI(mortar, refire), WEP_CVAR_PRI(mortar, animtime));
326 wepinfo_pri_dps = (WEP_CVAR_PRI(mortar, damage) * (1 / wepinfo_pri_refire));
327 wepinfo_pri_speed = (1 / max(1, (10000 / max(1, WEP_CVAR_PRI(mortar, speed)))));
329 // for the range calculation, closer to 1 is better
330 wepinfo_pri_range_max = 2000 * wepinfo_pri_speed;
331 wepinfo_pri_range = wepinfo_pri_speed * WEP_CVAR_PRI(mortar,
333 wepinfo_sec_refire = max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime));
334 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / wepinfo_sec_refire));
336 wepinfo_sec_dps = (WEP_CVAR_SEC(mortar, damage) * (1 / max3(sys_frametime, WEP_CVAR_SEC(mortar, refire), WEP_CVAR_SEC(mortar, animtime))));
339 METHOD(Mortar, wr_think, bool(entity thiswep, bool fire1, bool fire2))
341 if(autocvar_g_balance_mortar_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo))) // forced reload
342 _WEP_ACTION(self.weapon, WR_RELOAD);
345 if(weapon_prepareattack(0, WEP_CVAR_PRI(mortar, refire)))
347 W_Mortar_Attack(thiswep);
348 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(mortar, animtime), w_ready);
353 if(WEP_CVAR_SEC(mortar, remote_detonateprimary))
355 bool nadefound = false;
357 for(nade = world; (nade = find(nade, classname, "grenade")); ) if(nade.realowner == self)
359 if(!nade.gl_detonate_later)
361 nade.gl_detonate_later = true;
366 sound(self, CH_WEAPON_B, SND_ROCKET_DET, VOL_BASE, ATTN_NORM);
368 else if(weapon_prepareattack(1, WEP_CVAR_SEC(mortar, refire)))
370 W_Mortar_Attack2(thiswep);
371 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(mortar, animtime), w_ready);
377 METHOD(Mortar, wr_init, bool(entity thiswep))
379 MORTAR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
382 METHOD(Mortar, wr_checkammo1, bool(entity thiswep))
384 float ammo_amount = self.WEP_AMMO(MORTAR) >= WEP_CVAR_PRI(mortar, ammo);
385 ammo_amount += self.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_PRI(mortar, ammo);
388 METHOD(Mortar, wr_checkammo2, bool(entity thiswep))
390 float ammo_amount = self.WEP_AMMO(MORTAR) >= WEP_CVAR_SEC(mortar, ammo);
391 ammo_amount += self.(weapon_load[WEP_MORTAR.m_id]) >= WEP_CVAR_SEC(mortar, ammo);
394 METHOD(Mortar, wr_config, bool(entity thiswep))
396 MORTAR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
399 METHOD(Mortar, wr_reload, bool(entity thiswep))
401 W_Reload(min(WEP_CVAR_PRI(mortar, ammo), WEP_CVAR_SEC(mortar, ammo)), SND(RELOAD)); // WEAPONTODO
404 METHOD(Mortar, wr_suicidemessage, bool(entity thiswep))
406 if(w_deathtype & HITTYPE_SECONDARY)
407 return WEAPON_MORTAR_SUICIDE_BOUNCE;
409 return WEAPON_MORTAR_SUICIDE_EXPLODE;
411 METHOD(Mortar, wr_killmessage, bool(entity thiswep))
413 if(w_deathtype & HITTYPE_SECONDARY)
414 return WEAPON_MORTAR_MURDER_BOUNCE;
416 return WEAPON_MORTAR_MURDER_EXPLODE;
422 METHOD(Mortar, wr_impacteffect, bool(entity thiswep))
425 org2 = w_org + w_backoff * 12;
426 pointparticles(particleeffectnum(EFFECT_GRENADE_EXPLODE), org2, '0 0 0', 1);
428 sound(self, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTN_NORM);
432 METHOD(Mortar, wr_init, bool(entity thiswep))
436 METHOD(Mortar, wr_zoomreticle, bool(entity thiswep))
438 // no weapon specific image for this weapon