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, m_name, 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(this, WEP_HAGAR); }
63 // NO bounce protection, as bounces are limited!
65 void W_Hagar_Explode()
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()
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);
111 void W_Hagar_Touch2()
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);
136 missile = new(missile);
137 missile.owner = missile.realowner = self;
138 missile.bot_dodge = true;
139 missile.bot_dodgerating = WEP_CVAR_PRI(hagar, damage);
141 missile.takedamage = DAMAGE_YES;
142 missile.health = WEP_CVAR_PRI(hagar, health);
143 missile.damageforcescale = WEP_CVAR_PRI(hagar, damageforcescale);
144 missile.event_damage = W_Hagar_Damage;
145 missile.damagedbycontents = true;
147 missile.touch = W_Hagar_Touch;
148 missile.use = W_Hagar_Explode;
149 missile.think = adaptor_think2use_hittype_splash;
150 missile.nextthink = time + WEP_CVAR_PRI(hagar, lifetime);
151 PROJECTILE_MAKETRIGGER(missile);
152 missile.projectiledeathtype = WEP_HAGAR.m_id;
153 setorigin(missile, w_shotorg);
154 setsize(missile, '0 0 0', '0 0 0');
156 missile.movetype = MOVETYPE_FLY;
157 W_SetupProjVelocity_PRI(missile, hagar);
159 missile.angles = vectoangles(missile.velocity);
160 missile.flags = FL_PROJECTILE;
161 missile.missile_flags = MIF_SPLASH;
163 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
165 MUTATOR_CALLHOOK(EditProjectile, self, missile);
168 void W_Hagar_Attack2(Weapon thiswep)
172 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo));
174 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
176 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
178 missile = new(missile);
179 missile.owner = missile.realowner = self;
180 missile.bot_dodge = true;
181 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
183 missile.takedamage = DAMAGE_YES;
184 missile.health = WEP_CVAR_SEC(hagar, health);
185 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
186 missile.event_damage = W_Hagar_Damage;
187 missile.damagedbycontents = true;
189 missile.touch = W_Hagar_Touch2;
191 missile.use = W_Hagar_Explode2;
192 missile.think = adaptor_think2use_hittype_splash;
193 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
194 PROJECTILE_MAKETRIGGER(missile);
195 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
196 setorigin(missile, w_shotorg);
197 setsize(missile, '0 0 0', '0 0 0');
199 missile.movetype = MOVETYPE_BOUNCEMISSILE;
200 W_SetupProjVelocity_SEC(missile, hagar);
202 missile.angles = vectoangles(missile.velocity);
203 missile.flags = FL_PROJECTILE;
204 missile.missile_flags = MIF_SPLASH;
206 CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
208 MUTATOR_CALLHOOK(EditProjectile, self, missile);
211 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
212 void W_Hagar_Attack2_Load_Release(.entity weaponentity)
214 // time to release the rockets we've loaded
217 float counter, shots, spread_pershot;
219 vector forward, right, up;
224 weapon_prepareattack_do(self, weaponentity, true, WEP_CVAR_SEC(hagar, refire));
226 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
227 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
233 shots = self.hagar_load;
235 for(counter = 0; counter < shots; ++counter)
237 missile = new(missile);
238 missile.owner = missile.realowner = self;
239 missile.bot_dodge = true;
240 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
242 missile.takedamage = DAMAGE_YES;
243 missile.health = WEP_CVAR_SEC(hagar, health);
244 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
245 missile.event_damage = W_Hagar_Damage;
246 missile.damagedbycontents = true;
248 missile.touch = W_Hagar_Touch; // not bouncy
249 missile.use = W_Hagar_Explode2;
250 missile.think = adaptor_think2use_hittype_splash;
251 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
252 PROJECTILE_MAKETRIGGER(missile);
253 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
254 setorigin(missile, w_shotorg);
255 setsize(missile, '0 0 0', '0 0 0');
256 missile.movetype = MOVETYPE_FLY;
257 missile.missile_flags = MIF_SPLASH;
259 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
260 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
261 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
262 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
264 // pattern spread calculation
270 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
274 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
276 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
278 missile.angles = vectoangles(missile.velocity);
279 missile.flags = FL_PROJECTILE;
281 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
283 MUTATOR_CALLHOOK(EditProjectile, self, missile);
286 weapon_thinkf(self, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
287 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor();
291 void W_Hagar_Attack2_Load(Weapon thiswep, .entity weaponentity)
293 // loadable hagar secondary attack, must always run each frame
295 if(time < game_starttime)
298 bool loaded = self.hagar_load >= WEP_CVAR_SEC(hagar, load_max);
300 // this is different than WR_CHECKAMMO when it comes to reloading
302 if(self.items & IT_UNLIMITED_WEAPON_AMMO)
304 else if(autocvar_g_balance_hagar_reload_ammo)
305 enough_ammo = self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
307 enough_ammo = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
309 bool stopped = loaded || !enough_ammo;
311 if(self.BUTTON_ATCK2)
313 if(self.BUTTON_ATCK && WEP_CVAR_SEC(hagar, load_abort))
317 // if we pressed primary fire while loading, unload all rockets and abort
318 self.(weaponentity).state = WS_READY;
319 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo
321 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
323 // pause until we can load rockets again, once we re-press the alt fire button
324 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
326 // require letting go of the alt fire button before we can load again
327 self.hagar_loadblock = true;
332 // check if we can attempt to load another rocket
335 if(!self.hagar_loadblock && self.hagar_loadstep < time)
337 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo));
338 self.(weaponentity).state = WS_INUSE;
339 self.hagar_load += 1;
340 sound(self, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
342 if(self.hagar_load >= WEP_CVAR_SEC(hagar, load_max))
345 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
348 if(stopped && !self.hagar_loadbeep && self.hagar_load) // prevents the beep from playing each frame
350 // if this is the last rocket we can load, play a beep sound to notify the player
351 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
352 self.hagar_loadbeep = true;
353 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor();
357 else if(self.hagar_loadblock)
359 // the alt fire button has been released, so re-enable loading if blocked
360 self.hagar_loadblock = false;
365 // play warning sound if we're about to release
366 if(stopped && self.hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
368 if(!self.hagar_warning) // prevents the beep from playing each frame
370 // we're about to automatically release after holding time, play a beep sound to notify the player
371 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
372 self.hagar_warning = true;
376 // release if player let go of button or if they've held it in too long
377 if(!self.BUTTON_ATCK2 || (stopped && self.hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
379 self.(weaponentity).state = WS_READY;
380 W_Hagar_Attack2_Load_Release(weaponentity);
385 self.hagar_loadbeep = false;
386 self.hagar_warning = false;
388 // we aren't checking ammo during an attack, so we must do it here
389 Weapon w = get_weaponinfo(self.weapon);
390 if(!(w.wr_checkammo1(w) + w.wr_checkammo2(w)))
391 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
393 // note: this doesn't force the switch
394 W_SwitchToOtherWeapon(self);
400 METHOD(Hagar, wr_aim, void(entity thiswep))
403 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
404 else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
405 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
407 METHOD(Hagar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
409 float loadable_secondary;
410 loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
412 if(loadable_secondary)
413 W_Hagar_Attack2_Load(thiswep, weaponentity); // must always run each frame
414 if(autocvar_g_balance_hagar_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload
415 Weapon w = get_weaponinfo(actor.weapon);
417 } else if((fire & 1) && !actor.hagar_load && !actor.hagar_loadblock) // not while secondary is loaded or awaiting reset
419 if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(hagar, refire)))
421 W_Hagar_Attack(thiswep);
422 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(hagar, refire), w_ready);
425 else if((fire & 2) && !loadable_secondary && WEP_CVAR(hagar, secondary))
427 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire)))
429 W_Hagar_Attack2(thiswep);
430 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
434 METHOD(Hagar, wr_gonethink, void(entity thiswep))
436 // we lost the weapon and want to prepare switching away
439 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
440 self.(weaponentity).state = WS_READY;
441 W_Hagar_Attack2_Load_Release(weaponentity);
444 METHOD(Hagar, wr_init, void(entity thiswep))
446 HAGAR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
448 METHOD(Hagar, wr_setup, void(entity thiswep))
450 self.hagar_loadblock = false;
454 W_DecreaseAmmo(thiswep, self, WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo if necessary
458 METHOD(Hagar, wr_checkammo1, bool(entity thiswep))
460 float ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_PRI(hagar, ammo);
461 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
464 METHOD(Hagar, wr_checkammo2, bool(entity thiswep))
466 float ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
467 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
470 METHOD(Hagar, wr_config, void(entity thiswep))
472 HAGAR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
474 METHOD(Hagar, wr_resetplayer, void(entity thiswep))
478 METHOD(Hagar, wr_playerdeath, void(entity thiswep))
480 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
481 // if we have any rockets loaded when we die, release them
482 if(self.hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
483 W_Hagar_Attack2_Load_Release(weaponentity);
485 METHOD(Hagar, wr_reload, void(entity thiswep))
487 if(!self.hagar_load) // require releasing loaded rockets first
488 W_Reload(self, min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND(RELOAD));
490 METHOD(Hagar, wr_suicidemessage, int(entity thiswep))
492 return WEAPON_HAGAR_SUICIDE;
494 METHOD(Hagar, wr_killmessage, int(entity thiswep))
496 if(w_deathtype & HITTYPE_SECONDARY)
497 return WEAPON_HAGAR_MURDER_BURST;
499 return WEAPON_HAGAR_MURDER_SPRAY;
505 METHOD(Hagar, wr_impacteffect, void(entity thiswep))
508 org2 = w_org + w_backoff * 6;
509 pointparticles(EFFECT_HAGAR_EXPLODE, org2, '0 0 0', 1);
513 sound(self, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
514 else if(w_random<0.7)
515 sound(self, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
517 sound(self, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);