3 /* ammotype */ ATTRIB(Hagar, ammo_field, .int, ammo_rockets)
4 /* impulse */ ATTRIB(Hagar, impulse, int, 8)
5 /* flags */ ATTRIB(Hagar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
6 /* rating */ ATTRIB(Hagar, bot_pickupbasevalue, float, BOT_PICKUP_RATING_MID);
7 /* color */ ATTRIB(Hagar, wpcolor, vector, '1 1 0.5');
8 /* modelname */ ATTRIB(Hagar, mdl, string, "hagar");
10 /* model */ ATTRIB(Hagar, m_model, Model, MDL_HAGAR_ITEM);
12 /* crosshair */ ATTRIB(Hagar, w_crosshair, string, "gfx/crosshairhagar");
13 /* crosshair */ ATTRIB(Hagar, w_crosshair_size, float, 0.8);
14 /* wepimg */ ATTRIB(Hagar, model2, string, "weaponhagar");
15 /* refname */ ATTRIB(Hagar, netname, string, "hagar");
16 /* wepname */ ATTRIB(Hagar, message, string, _("Hagar"));
18 REGISTER_WEAPON(HAGAR, NEW(Hagar));
20 #define HAGAR_SETTINGS(w_cvar,w_prop) HAGAR_SETTINGS_LIST(w_cvar, w_prop, HAGAR, hagar)
21 #define HAGAR_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
22 w_cvar(id, sn, BOTH, ammo) \
23 w_cvar(id, sn, BOTH, damage) \
24 w_cvar(id, sn, BOTH, edgedamage) \
25 w_cvar(id, sn, BOTH, force) \
26 w_cvar(id, sn, BOTH, radius) \
27 w_cvar(id, sn, BOTH, refire) \
28 w_cvar(id, sn, BOTH, speed) \
29 w_cvar(id, sn, BOTH, spread) \
30 w_cvar(id, sn, BOTH, damageforcescale) \
31 w_cvar(id, sn, BOTH, health) \
32 w_cvar(id, sn, PRI, lifetime) \
33 w_cvar(id, sn, SEC, load) \
34 w_cvar(id, sn, SEC, load_max) \
35 w_cvar(id, sn, SEC, load_abort) \
36 w_cvar(id, sn, SEC, load_animtime) \
37 w_cvar(id, sn, SEC, load_hold) \
38 w_cvar(id, sn, SEC, load_speed) \
39 w_cvar(id, sn, SEC, load_releasedeath) \
40 w_cvar(id, sn, SEC, load_spread) \
41 w_cvar(id, sn, SEC, load_spread_bias) \
42 w_cvar(id, sn, SEC, load_linkexplode) \
43 w_cvar(id, sn, SEC, lifetime_min) \
44 w_cvar(id, sn, SEC, lifetime_rand) \
45 w_cvar(id, sn, NONE, secondary) \
46 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
47 w_prop(id, sn, float, reloading_time, reload_time) \
48 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
49 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
50 w_prop(id, sn, string, weaponreplace, weaponreplace) \
51 w_prop(id, sn, float, weaponstart, weaponstart) \
52 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
53 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
56 HAGAR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
61 spawnfunc(weapon_hagar) { weapon_defaultspawnfunc(WEP_HAGAR.m_id); }
63 // NO bounce protection, as bounces are limited!
65 void W_Hagar_Explode(void)
67 self.event_damage = func_null;
68 RadiusDamage(self, self.realowner, WEP_CVAR_PRI(hagar, damage), WEP_CVAR_PRI(hagar, edgedamage), WEP_CVAR_PRI(hagar, radius), world, world, WEP_CVAR_PRI(hagar, force), self.projectiledeathtype, other);
73 void W_Hagar_Explode2(void)
75 self.event_damage = func_null;
76 RadiusDamage(self, self.realowner, WEP_CVAR_SEC(hagar, damage), WEP_CVAR_SEC(hagar, edgedamage), WEP_CVAR_SEC(hagar, radius), world, world, WEP_CVAR_SEC(hagar, force), self.projectiledeathtype, other);
81 void W_Hagar_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
86 float is_linkexplode = ( ((inflictor.owner != world) ? (inflictor.owner == self.owner) : true)
87 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY)
88 && (self.projectiledeathtype & HITTYPE_SECONDARY));
91 is_linkexplode = (is_linkexplode && WEP_CVAR_SEC(hagar, load_linkexplode));
93 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
95 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, is_linkexplode))
96 return; // g_projectiles_damage says to halt
98 self.health = self.health - damage;
99 self.angles = vectoangles(self.velocity);
102 W_PrepareExplosionByDamage(attacker, self.think);
105 void W_Hagar_Touch(void)
111 void W_Hagar_Touch2(void)
115 if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
119 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
120 self.angles = vectoangles(self.velocity);
122 self.projectiledeathtype |= HITTYPE_BOUNCE;
126 void W_Hagar_Attack(Weapon thiswep)
130 W_DecreaseAmmo(thiswep, self, WEP_CVAR_PRI(hagar, ammo));
132 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(hagar, damage));
134 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
137 missile.owner = missile.realowner = self;
138 missile.classname = "missile";
139 missile.bot_dodge = true;
140 missile.bot_dodgerating = WEP_CVAR_PRI(hagar, damage);
142 missile.takedamage = DAMAGE_YES;
143 missile.health = WEP_CVAR_PRI(hagar, health);
144 missile.damageforcescale = WEP_CVAR_PRI(hagar, damageforcescale);
145 missile.event_damage = W_Hagar_Damage;
146 missile.damagedbycontents = true;
148 missile.touch = W_Hagar_Touch;
149 missile.use = W_Hagar_Explode;
150 missile.think = adaptor_think2use_hittype_splash;
151 missile.nextthink = time + WEP_CVAR_PRI(hagar, lifetime);
152 PROJECTILE_MAKETRIGGER(missile);
153 missile.projectiledeathtype = WEP_HAGAR.m_id;
154 setorigin(missile, w_shotorg);
155 setsize(missile, '0 0 0', '0 0 0');
157 missile.movetype = MOVETYPE_FLY;
158 W_SetupProjVelocity_PRI(missile, hagar);
160 missile.angles = vectoangles(missile.velocity);
161 missile.flags = FL_PROJECTILE;
162 missile.missile_flags = MIF_SPLASH;
164 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
166 MUTATOR_CALLHOOK(EditProjectile, self, missile);
169 void W_Hagar_Attack2(Weapon thiswep)
173 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo));
175 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
177 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
180 missile.owner = missile.realowner = self;
181 missile.classname = "missile";
182 missile.bot_dodge = true;
183 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
185 missile.takedamage = DAMAGE_YES;
186 missile.health = WEP_CVAR_SEC(hagar, health);
187 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
188 missile.event_damage = W_Hagar_Damage;
189 missile.damagedbycontents = true;
191 missile.touch = W_Hagar_Touch2;
193 missile.use = W_Hagar_Explode2;
194 missile.think = adaptor_think2use_hittype_splash;
195 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
196 PROJECTILE_MAKETRIGGER(missile);
197 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
198 setorigin(missile, w_shotorg);
199 setsize(missile, '0 0 0', '0 0 0');
201 missile.movetype = MOVETYPE_BOUNCEMISSILE;
202 W_SetupProjVelocity_SEC(missile, hagar);
204 missile.angles = vectoangles(missile.velocity);
205 missile.flags = FL_PROJECTILE;
206 missile.missile_flags = MIF_SPLASH;
208 CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
210 MUTATOR_CALLHOOK(EditProjectile, self, missile);
213 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
214 void W_Hagar_Attack2_Load_Release(void)
216 // time to release the rockets we've loaded
219 float counter, shots, spread_pershot;
221 vector forward, right, up;
226 weapon_prepareattack_do(self, true, WEP_CVAR_SEC(hagar, refire));
228 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
229 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
235 shots = self.hagar_load;
237 for(counter = 0; counter < shots; ++counter)
240 missile.owner = missile.realowner = self;
241 missile.classname = "missile";
242 missile.bot_dodge = true;
243 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
245 missile.takedamage = DAMAGE_YES;
246 missile.health = WEP_CVAR_SEC(hagar, health);
247 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
248 missile.event_damage = W_Hagar_Damage;
249 missile.damagedbycontents = true;
251 missile.touch = W_Hagar_Touch; // not bouncy
252 missile.use = W_Hagar_Explode2;
253 missile.think = adaptor_think2use_hittype_splash;
254 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
255 PROJECTILE_MAKETRIGGER(missile);
256 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
257 setorigin(missile, w_shotorg);
258 setsize(missile, '0 0 0', '0 0 0');
259 missile.movetype = MOVETYPE_FLY;
260 missile.missile_flags = MIF_SPLASH;
262 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
263 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
264 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
265 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
267 // pattern spread calculation
273 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
277 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
279 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
281 missile.angles = vectoangles(missile.velocity);
282 missile.flags = FL_PROJECTILE;
284 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
286 MUTATOR_CALLHOOK(EditProjectile, self, missile);
289 weapon_thinkf(self, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
290 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor();
294 void W_Hagar_Attack2_Load(Weapon thiswep)
296 // loadable hagar secondary attack, must always run each frame
298 if(time < game_starttime)
301 bool loaded = self.hagar_load >= WEP_CVAR_SEC(hagar, load_max);
303 // this is different than WR_CHECKAMMO when it comes to reloading
305 if(self.items & IT_UNLIMITED_WEAPON_AMMO)
307 else if(autocvar_g_balance_hagar_reload_ammo)
308 enough_ammo = self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
310 enough_ammo = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
312 bool stopped = loaded || !enough_ammo;
314 if(self.BUTTON_ATCK2)
316 if(self.BUTTON_ATCK && WEP_CVAR_SEC(hagar, load_abort))
320 // if we pressed primary fire while loading, unload all rockets and abort
321 self.weaponentity.state = WS_READY;
322 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo
324 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
326 // pause until we can load rockets again, once we re-press the alt fire button
327 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
329 // require letting go of the alt fire button before we can load again
330 self.hagar_loadblock = true;
335 // check if we can attempt to load another rocket
338 if(!self.hagar_loadblock && self.hagar_loadstep < time)
340 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo));
341 self.weaponentity.state = WS_INUSE;
342 self.hagar_load += 1;
343 sound(self, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
345 if(self.hagar_load >= WEP_CVAR_SEC(hagar, load_max))
348 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
351 if(stopped && !self.hagar_loadbeep && self.hagar_load) // prevents the beep from playing each frame
353 // if this is the last rocket we can load, play a beep sound to notify the player
354 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
355 self.hagar_loadbeep = true;
356 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor();
360 else if(self.hagar_loadblock)
362 // the alt fire button has been released, so re-enable loading if blocked
363 self.hagar_loadblock = false;
368 // play warning sound if we're about to release
369 if(stopped && self.hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
371 if(!self.hagar_warning) // prevents the beep from playing each frame
373 // we're about to automatically release after holding time, play a beep sound to notify the player
374 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
375 self.hagar_warning = true;
379 // release if player let go of button or if they've held it in too long
380 if(!self.BUTTON_ATCK2 || (stopped && self.hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
382 self.weaponentity.state = WS_READY;
383 W_Hagar_Attack2_Load_Release();
388 self.hagar_loadbeep = false;
389 self.hagar_warning = false;
391 // we aren't checking ammo during an attack, so we must do it here
392 Weapon w = get_weaponinfo(self.weapon);
393 if(!(w.wr_checkammo1(w) + w.wr_checkammo2(w)))
394 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
396 // note: this doesn't force the switch
397 W_SwitchToOtherWeapon(self);
403 METHOD(Hagar, wr_aim, void(entity thiswep))
406 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
407 else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
408 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
410 METHOD(Hagar, wr_think, void(entity thiswep, entity actor, int slot, int fire))
412 float loadable_secondary;
413 loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
415 if(loadable_secondary)
416 W_Hagar_Attack2_Load(thiswep); // must always run each frame
417 if(autocvar_g_balance_hagar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload
418 Weapon w = get_weaponinfo(actor.weapon);
420 } else if((fire & 1) && !actor.hagar_load && !actor.hagar_loadblock) // not while secondary is loaded or awaiting reset
422 if(weapon_prepareattack(thiswep, actor, false, WEP_CVAR_PRI(hagar, refire)))
424 W_Hagar_Attack(thiswep);
425 weapon_thinkf(actor, WFRAME_FIRE1, WEP_CVAR_PRI(hagar, refire), w_ready);
428 else if((fire & 2) && !loadable_secondary && WEP_CVAR(hagar, secondary))
430 if(weapon_prepareattack(thiswep, actor, true, WEP_CVAR_SEC(hagar, refire)))
432 W_Hagar_Attack2(thiswep);
433 weapon_thinkf(actor, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
437 METHOD(Hagar, wr_gonethink, void(entity thiswep))
439 // we lost the weapon and want to prepare switching away
442 self.weaponentity.state = WS_READY;
443 W_Hagar_Attack2_Load_Release();
446 METHOD(Hagar, wr_init, void(entity thiswep))
448 HAGAR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
450 METHOD(Hagar, wr_setup, void(entity thiswep))
452 self.hagar_loadblock = false;
456 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo if necessary
460 METHOD(Hagar, wr_checkammo1, bool(entity thiswep))
462 float ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_PRI(hagar, ammo);
463 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
466 METHOD(Hagar, wr_checkammo2, bool(entity thiswep))
468 float ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
469 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
472 METHOD(Hagar, wr_config, void(entity thiswep))
474 HAGAR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
476 METHOD(Hagar, wr_resetplayer, void(entity thiswep))
480 METHOD(Hagar, wr_playerdeath, void(entity thiswep))
482 // if we have any rockets loaded when we die, release them
483 if(self.hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
484 W_Hagar_Attack2_Load_Release();
486 METHOD(Hagar, wr_reload, void(entity thiswep))
488 if(!self.hagar_load) // require releasing loaded rockets first
489 W_Reload(self, min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND(RELOAD));
491 METHOD(Hagar, wr_suicidemessage, int(entity thiswep))
493 return WEAPON_HAGAR_SUICIDE;
495 METHOD(Hagar, wr_killmessage, int(entity thiswep))
497 if(w_deathtype & HITTYPE_SECONDARY)
498 return WEAPON_HAGAR_MURDER_BURST;
500 return WEAPON_HAGAR_MURDER_SPRAY;
506 METHOD(Hagar, wr_impacteffect, void(entity thiswep))
509 org2 = w_org + w_backoff * 6;
510 pointparticles(particleeffectnum(EFFECT_HAGAR_EXPLODE), org2, '0 0 0', 1);
514 sound(self, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
515 else if(w_random<0.7)
516 sound(self, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
518 sound(self, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);