5 // NO bounce protection, as bounces are limited!
7 void W_Hagar_Explode(entity this, entity directhitentity)
9 this.event_damage = func_null;
10 RadiusDamage(this, this.realowner, WEP_CVAR_PRI(hagar, damage), WEP_CVAR_PRI(hagar, edgedamage), WEP_CVAR_PRI(hagar, radius), NULL, NULL, WEP_CVAR_PRI(hagar, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
15 void W_Hagar_Explode_use(entity this, entity actor, entity trigger)
17 W_Hagar_Explode(this, trigger);
20 void W_Hagar_Explode2(entity this, entity directhitentity)
22 this.event_damage = func_null;
23 RadiusDamage(this, this.realowner, WEP_CVAR_SEC(hagar, damage), WEP_CVAR_SEC(hagar, edgedamage), WEP_CVAR_SEC(hagar, radius), NULL, NULL, WEP_CVAR_SEC(hagar, force), this.projectiledeathtype, this.weaponentity_fld, directhitentity);
28 void W_Hagar_Explode2_use(entity this, entity actor, entity trigger)
30 W_Hagar_Explode2(this, trigger);
33 void W_Hagar_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
38 float is_linkexplode = ( ((inflictor.owner != NULL) ? (inflictor.owner == this.owner) : true)
39 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY)
40 && (this.projectiledeathtype & HITTYPE_SECONDARY));
43 is_linkexplode = (is_linkexplode && WEP_CVAR_SEC(hagar, load_linkexplode));
45 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
47 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, is_linkexplode))
48 return; // g_projectiles_damage says to halt
50 this.health = this.health - damage;
51 this.angles = vectoangles(this.velocity);
54 W_PrepareExplosionByDamage(this, attacker, getthink(this));
57 void W_Hagar_Touch(entity this, entity toucher)
59 PROJECTILE_TOUCH(this, toucher);
60 this.use(this, NULL, toucher);
63 void W_Hagar_Touch2(entity this, entity toucher)
65 PROJECTILE_TOUCH(this, toucher);
67 if(this.cnt > 0 || toucher.takedamage == DAMAGE_AIM) {
68 this.use(this, NULL, toucher);
71 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
72 this.angles = vectoangles(this.velocity);
74 this.projectiledeathtype |= HITTYPE_BOUNCE;
78 void W_Hagar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
82 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hagar, ammo), weaponentity);
84 W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(hagar, damage));
86 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
88 missile = new(missile);
89 missile.owner = missile.realowner = actor;
90 missile.bot_dodge = true;
91 missile.bot_dodgerating = WEP_CVAR_PRI(hagar, damage);
93 missile.takedamage = DAMAGE_YES;
94 missile.health = WEP_CVAR_PRI(hagar, health);
95 missile.damageforcescale = WEP_CVAR_PRI(hagar, damageforcescale);
96 missile.event_damage = W_Hagar_Damage;
97 missile.damagedbycontents = true;
98 IL_PUSH(g_damagedbycontents, missile);
100 settouch(missile, W_Hagar_Touch);
101 missile.use = W_Hagar_Explode_use;
102 setthink(missile, adaptor_think2use_hittype_splash);
103 missile.nextthink = time + WEP_CVAR_PRI(hagar, lifetime);
104 PROJECTILE_MAKETRIGGER(missile);
105 missile.projectiledeathtype = WEP_HAGAR.m_id;
106 missile.weaponentity_fld = weaponentity;
107 setorigin(missile, w_shotorg);
108 setsize(missile, '0 0 0', '0 0 0');
110 set_movetype(missile, MOVETYPE_FLY);
111 W_SetupProjVelocity_PRI(missile, hagar);
113 missile.angles = vectoangles(missile.velocity);
114 missile.flags = FL_PROJECTILE;
115 IL_PUSH(g_projectiles, missile);
116 IL_PUSH(g_bot_dodge, missile);
117 missile.missile_flags = MIF_SPLASH;
119 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
121 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
124 void W_Hagar_Attack2(Weapon thiswep, entity actor, .entity weaponentity)
128 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo), weaponentity);
130 W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
132 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
134 missile = new(missile);
135 missile.owner = missile.realowner = actor;
136 missile.bot_dodge = true;
137 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
139 missile.takedamage = DAMAGE_YES;
140 missile.health = WEP_CVAR_SEC(hagar, health);
141 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
142 missile.event_damage = W_Hagar_Damage;
143 missile.damagedbycontents = true;
144 IL_PUSH(g_damagedbycontents, missile);
146 settouch(missile, W_Hagar_Touch2);
148 missile.use = W_Hagar_Explode2_use;
149 setthink(missile, adaptor_think2use_hittype_splash);
150 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
151 PROJECTILE_MAKETRIGGER(missile);
152 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
153 missile.weaponentity_fld = weaponentity;
154 setorigin(missile, w_shotorg);
155 setsize(missile, '0 0 0', '0 0 0');
157 set_movetype(missile, MOVETYPE_BOUNCEMISSILE);
158 W_SetupProjVelocity_SEC(missile, hagar);
160 missile.angles = vectoangles(missile.velocity);
161 missile.flags = FL_PROJECTILE;
162 IL_PUSH(g_projectiles, missile);
163 IL_PUSH(g_bot_dodge, missile);
164 missile.missile_flags = MIF_SPLASH;
166 CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
168 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
171 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
172 void W_Hagar_Attack2_Load_Release(entity actor, .entity weaponentity)
174 // time to release the rockets we've loaded
177 float counter, shots, spread_pershot;
179 vector forward, right, up;
181 if(!actor.(weaponentity).hagar_load)
184 weapon_prepareattack_do(actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire));
186 W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
187 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
193 shots = actor.(weaponentity).hagar_load;
195 for(counter = 0; counter < shots; ++counter)
197 missile = new(missile);
198 missile.owner = missile.realowner = actor;
199 missile.bot_dodge = true;
200 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
202 missile.takedamage = DAMAGE_YES;
203 missile.health = WEP_CVAR_SEC(hagar, health);
204 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
205 missile.event_damage = W_Hagar_Damage;
206 missile.damagedbycontents = true;
207 IL_PUSH(g_damagedbycontents, missile);
209 settouch(missile, W_Hagar_Touch); // not bouncy
210 missile.use = W_Hagar_Explode2_use;
211 setthink(missile, adaptor_think2use_hittype_splash);
212 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
213 PROJECTILE_MAKETRIGGER(missile);
214 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
215 setorigin(missile, w_shotorg);
216 setsize(missile, '0 0 0', '0 0 0');
217 set_movetype(missile, MOVETYPE_FLY);
218 missile.missile_flags = MIF_SPLASH;
220 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
221 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
222 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
223 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
225 // pattern spread calculation
231 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
235 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
237 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
239 missile.angles = vectoangles(missile.velocity);
240 missile.flags = FL_PROJECTILE;
241 IL_PUSH(g_projectiles, missile);
242 IL_PUSH(g_bot_dodge, missile);
244 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
246 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
249 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
250 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor(actor);
251 actor.(weaponentity).hagar_load = 0;
254 void W_Hagar_Attack2_Load(Weapon thiswep, entity actor, .entity weaponentity)
256 // loadable hagar secondary attack, must always run each frame
257 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
259 if(time < game_starttime)
262 bool loaded = actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max);
264 // this is different than WR_CHECKAMMO when it comes to reloading
266 if(actor.items & IT_UNLIMITED_WEAPON_AMMO)
268 else if(autocvar_g_balance_hagar_reload_ammo)
269 enough_ammo = actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
271 enough_ammo = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(hagar, ammo);
273 bool stopped = loaded || !enough_ammo;
275 if(PHYS_INPUT_BUTTON_ATCK2(actor))
277 if(PHYS_INPUT_BUTTON_ATCK(actor) && WEP_CVAR_SEC(hagar, load_abort))
279 if(actor.(weaponentity).hagar_load)
281 // if we pressed primary fire while loading, unload all rockets and abort
282 actor.(weaponentity).state = WS_READY;
283 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo
284 actor.(weaponentity).hagar_load = 0;
285 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
287 // pause until we can load rockets again, once we re-press the alt fire button
288 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
290 // require letting go of the alt fire button before we can load again
291 actor.(weaponentity).hagar_loadblock = true;
296 // check if we can attempt to load another rocket
299 if(!actor.(weaponentity).hagar_loadblock && actor.(weaponentity).hagar_loadstep < time)
301 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo), weaponentity);
302 actor.(weaponentity).state = WS_INUSE;
303 actor.(weaponentity).hagar_load += 1;
304 sound(actor, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
306 if(actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max))
309 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
312 if(stopped && !actor.(weaponentity).hagar_loadbeep && actor.(weaponentity).hagar_load) // prevents the beep from playing each frame
314 // if this is the last rocket we can load, play a beep sound to notify the player
315 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
316 actor.(weaponentity).hagar_loadbeep = true;
317 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor(actor);
321 else if(actor.(weaponentity).hagar_loadblock)
323 // the alt fire button has been released, so re-enable loading if blocked
324 actor.(weaponentity).hagar_loadblock = false;
327 if(actor.(weaponentity).hagar_load)
329 // play warning sound if we're about to release
330 if(stopped && actor.(weaponentity).hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
332 if(!actor.(weaponentity).hagar_warning) // prevents the beep from playing each frame
334 // we're about to automatically release after holding time, play a beep sound to notify the player
335 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
336 actor.(weaponentity).hagar_warning = true;
340 // release if player let go of button or if they've held it in too long
341 if(!PHYS_INPUT_BUTTON_ATCK2(actor) || (stopped && actor.(weaponentity).hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
343 actor.(weaponentity).state = WS_READY;
344 W_Hagar_Attack2_Load_Release(actor, weaponentity);
349 actor.(weaponentity).hagar_loadbeep = false;
350 actor.(weaponentity).hagar_warning = false;
352 // we aren't checking ammo during an attack, so we must do it here
353 if(!(thiswep.wr_checkammo1(thiswep, actor, weaponentity) + thiswep.wr_checkammo2(thiswep, actor, weaponentity)))
354 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
356 // note: this doesn't force the switch
357 W_SwitchToOtherWeapon(actor, weaponentity);
363 void W_Hagar_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
365 if(!(fire & 1) || actor.(weaponentity).hagar_load || actor.(weaponentity).hagar_loadblock || actor.(weaponentity).m_switchweapon != WEP_HAGAR)
367 w_ready(thiswep, actor, weaponentity, fire);
371 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
372 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
374 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
375 w_ready(thiswep, actor, weaponentity, fire);
379 W_Hagar_Attack(thiswep, actor, weaponentity);
381 int slot = weaponslot(weaponentity);
382 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hagar, refire) * W_WeaponRateFactor(actor);
383 int theframe = WFRAME_FIRE1;
384 entity this = actor.(weaponentity);
387 if(this.wframe == WFRAME_FIRE1)
388 theframe = WFRAME_DONTCHANGE;
390 weapon_thinkf(actor, weaponentity, theframe, WEP_CVAR_PRI(hagar, refire), W_Hagar_Attack_Auto);
393 METHOD(Hagar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
396 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
397 else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
398 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
400 METHOD(Hagar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
402 float loadable_secondary;
403 loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
405 if(loadable_secondary)
406 W_Hagar_Attack2_Load(thiswep, actor, weaponentity); // must always run each frame
407 if(autocvar_g_balance_hagar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload
408 thiswep.wr_reload(thiswep, actor, weaponentity);
410 else if((fire & 1) && !actor.(weaponentity).hagar_load && !actor.(weaponentity).hagar_loadblock) // not while secondary is loaded or awaiting reset
412 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
413 W_Hagar_Attack_Auto(thiswep, actor, weaponentity, fire);
415 else if((fire & 2) && !loadable_secondary && WEP_CVAR(hagar, secondary))
417 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire)))
419 W_Hagar_Attack2(thiswep, actor, weaponentity);
420 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
424 METHOD(Hagar, wr_gonethink, void(entity thiswep, entity actor, .entity weaponentity))
426 // we lost the weapon and want to prepare switching away
427 if(actor.(weaponentity).hagar_load)
429 actor.(weaponentity).state = WS_READY;
430 W_Hagar_Attack2_Load_Release(actor, weaponentity);
433 METHOD(Hagar, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
435 actor.(weaponentity).hagar_loadblock = false;
436 if(actor.(weaponentity).hagar_load)
438 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo if necessary
439 actor.(weaponentity).hagar_load = 0;
442 METHOD(Hagar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
444 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(hagar, ammo);
445 ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
448 METHOD(Hagar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
450 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(hagar, ammo);
451 ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
454 METHOD(Hagar, wr_resetplayer, void(entity thiswep, entity actor))
456 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
458 .entity weaponentity = weaponentities[slot];
459 actor.(weaponentity).hagar_load = 0;
462 METHOD(Hagar, wr_playerdeath, void(entity thiswep, entity actor, .entity weaponentity))
464 // if we have any rockets loaded when we die, release them
465 if(actor.(weaponentity).hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
466 W_Hagar_Attack2_Load_Release(actor, weaponentity);
468 METHOD(Hagar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
470 if(!actor.(weaponentity).hagar_load) // require releasing loaded rockets first
471 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND_RELOAD);
473 METHOD(Hagar, wr_suicidemessage, Notification(entity thiswep))
475 return WEAPON_HAGAR_SUICIDE;
477 METHOD(Hagar, wr_killmessage, Notification(entity thiswep))
479 if(w_deathtype & HITTYPE_SECONDARY)
480 return WEAPON_HAGAR_MURDER_BURST;
482 return WEAPON_HAGAR_MURDER_SPRAY;
488 METHOD(Hagar, wr_impacteffect, void(entity thiswep, entity actor))
491 org2 = w_org + w_backoff * 6;
492 pointparticles(EFFECT_HAGAR_EXPLODE, org2, '0 0 0', 1);
496 sound(actor, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
497 else if(w_random<0.7)
498 sound(actor, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
500 sound(actor, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);