4 spawnfunc(weapon_hagar) { weapon_defaultspawnfunc(this, WEP_HAGAR); }
6 // NO bounce protection, as bounces are limited!
8 void W_Hagar_Explode(entity this, entity directhitentity)
10 this.event_damage = func_null;
11 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, directhitentity);
16 void W_Hagar_Explode_use(entity this, entity actor, entity trigger)
18 W_Hagar_Explode(this, trigger);
21 void W_Hagar_Explode2(entity this, entity directhitentity)
23 this.event_damage = func_null;
24 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, directhitentity);
29 void W_Hagar_Explode2_use(entity this, entity actor, entity trigger)
31 W_Hagar_Explode2(this, trigger);
34 void W_Hagar_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
39 float is_linkexplode = ( ((inflictor.owner != NULL) ? (inflictor.owner == this.owner) : true)
40 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY)
41 && (this.projectiledeathtype & HITTYPE_SECONDARY));
44 is_linkexplode = (is_linkexplode && WEP_CVAR_SEC(hagar, load_linkexplode));
46 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
48 if(!W_CheckProjectileDamage(inflictor.realowner, this.realowner, deathtype, is_linkexplode))
49 return; // g_projectiles_damage says to halt
51 this.health = this.health - damage;
52 this.angles = vectoangles(this.velocity);
55 W_PrepareExplosionByDamage(this, attacker, getthink(this));
58 void W_Hagar_Touch(entity this, entity toucher)
60 PROJECTILE_TOUCH(this, toucher);
61 this.use(this, NULL, toucher);
64 void W_Hagar_Touch2(entity this, entity toucher)
66 PROJECTILE_TOUCH(this, toucher);
68 if(this.cnt > 0 || toucher.takedamage == DAMAGE_AIM) {
69 this.use(this, NULL, toucher);
72 Send_Effect(EFFECT_HAGAR_BOUNCE, this.origin, this.velocity, 1);
73 this.angles = vectoangles(this.velocity);
75 this.projectiledeathtype |= HITTYPE_BOUNCE;
79 void W_Hagar_Attack(Weapon thiswep, entity actor, .entity weaponentity)
83 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_PRI(hagar, ammo), weaponentity);
85 W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_PRI(hagar, damage));
87 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
89 missile = new(missile);
90 missile.owner = missile.realowner = actor;
91 missile.bot_dodge = true;
92 missile.bot_dodgerating = WEP_CVAR_PRI(hagar, damage);
94 missile.takedamage = DAMAGE_YES;
95 missile.health = WEP_CVAR_PRI(hagar, health);
96 missile.damageforcescale = WEP_CVAR_PRI(hagar, damageforcescale);
97 missile.event_damage = W_Hagar_Damage;
98 missile.damagedbycontents = true;
99 IL_PUSH(g_damagedbycontents, missile);
101 settouch(missile, W_Hagar_Touch);
102 missile.use = W_Hagar_Explode_use;
103 setthink(missile, adaptor_think2use_hittype_splash);
104 missile.nextthink = time + WEP_CVAR_PRI(hagar, lifetime);
105 PROJECTILE_MAKETRIGGER(missile);
106 missile.projectiledeathtype = WEP_HAGAR.m_id;
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 setorigin(missile, w_shotorg);
154 setsize(missile, '0 0 0', '0 0 0');
156 set_movetype(missile, MOVETYPE_BOUNCEMISSILE);
157 W_SetupProjVelocity_SEC(missile, hagar);
159 missile.angles = vectoangles(missile.velocity);
160 missile.flags = FL_PROJECTILE;
161 IL_PUSH(g_projectiles, missile);
162 IL_PUSH(g_bot_dodge, missile);
163 missile.missile_flags = MIF_SPLASH;
165 CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
167 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
170 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
171 void W_Hagar_Attack2_Load_Release(entity actor, .entity weaponentity)
173 // time to release the rockets we've loaded
176 float counter, shots, spread_pershot;
178 vector forward, right, up;
180 if(!actor.(weaponentity).hagar_load)
183 weapon_prepareattack_do(actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire));
185 W_SetupShot(actor, weaponentity, false, 2, SND_HAGAR_FIRE, CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
186 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
192 shots = actor.(weaponentity).hagar_load;
194 for(counter = 0; counter < shots; ++counter)
196 missile = new(missile);
197 missile.owner = missile.realowner = actor;
198 missile.bot_dodge = true;
199 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
201 missile.takedamage = DAMAGE_YES;
202 missile.health = WEP_CVAR_SEC(hagar, health);
203 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
204 missile.event_damage = W_Hagar_Damage;
205 missile.damagedbycontents = true;
206 IL_PUSH(g_damagedbycontents, missile);
208 settouch(missile, W_Hagar_Touch); // not bouncy
209 missile.use = W_Hagar_Explode2_use;
210 setthink(missile, adaptor_think2use_hittype_splash);
211 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
212 PROJECTILE_MAKETRIGGER(missile);
213 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
214 setorigin(missile, w_shotorg);
215 setsize(missile, '0 0 0', '0 0 0');
216 set_movetype(missile, MOVETYPE_FLY);
217 missile.missile_flags = MIF_SPLASH;
219 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
220 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
221 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
222 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
224 // pattern spread calculation
230 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
234 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
236 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
238 missile.angles = vectoangles(missile.velocity);
239 missile.flags = FL_PROJECTILE;
240 IL_PUSH(g_projectiles, missile);
241 IL_PUSH(g_bot_dodge, missile);
243 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
245 MUTATOR_CALLHOOK(EditProjectile, actor, missile);
248 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
249 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor(actor);
250 actor.(weaponentity).hagar_load = 0;
252 if(weaponslot(weaponentity) == 0)
253 actor.hagar_load = 0;
256 void W_Hagar_Attack2_Load(Weapon thiswep, entity actor, .entity weaponentity)
258 // loadable hagar secondary attack, must always run each frame
259 if(round_handler_IsActive() && !round_handler_IsRoundStarted())
261 if(time < game_starttime)
264 bool loaded = actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max);
266 // this is different than WR_CHECKAMMO when it comes to reloading
268 if(actor.items & IT_UNLIMITED_WEAPON_AMMO)
270 else if(autocvar_g_balance_hagar_reload_ammo)
271 enough_ammo = actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
273 enough_ammo = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(hagar, ammo);
275 bool stopped = loaded || !enough_ammo;
277 if(PHYS_INPUT_BUTTON_ATCK2(actor))
279 if(PHYS_INPUT_BUTTON_ATCK(actor) && WEP_CVAR_SEC(hagar, load_abort))
281 if(actor.(weaponentity).hagar_load)
283 // if we pressed primary fire while loading, unload all rockets and abort
284 actor.(weaponentity).state = WS_READY;
285 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo
286 actor.(weaponentity).hagar_load = 0;
287 if(weaponslot(weaponentity) == 0)
288 actor.hagar_load = 0;
289 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
291 // pause until we can load rockets again, once we re-press the alt fire button
292 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
294 // require letting go of the alt fire button before we can load again
295 actor.(weaponentity).hagar_loadblock = true;
300 // check if we can attempt to load another rocket
303 if(!actor.(weaponentity).hagar_loadblock && actor.(weaponentity).hagar_loadstep < time)
305 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo), weaponentity);
306 actor.(weaponentity).state = WS_INUSE;
307 actor.(weaponentity).hagar_load += 1;
308 sound(actor, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
310 if(actor.(weaponentity).hagar_load >= WEP_CVAR_SEC(hagar, load_max))
313 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor(actor);
316 if(stopped && !actor.(weaponentity).hagar_loadbeep && actor.(weaponentity).hagar_load) // prevents the beep from playing each frame
318 // if this is the last rocket we can load, play a beep sound to notify the player
319 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
320 actor.(weaponentity).hagar_loadbeep = true;
321 actor.(weaponentity).hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor(actor);
325 else if(actor.(weaponentity).hagar_loadblock)
327 // the alt fire button has been released, so re-enable loading if blocked
328 actor.(weaponentity).hagar_loadblock = false;
331 if(actor.(weaponentity).hagar_load)
333 // play warning sound if we're about to release
334 if(stopped && actor.(weaponentity).hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
336 if(!actor.(weaponentity).hagar_warning) // prevents the beep from playing each frame
338 // we're about to automatically release after holding time, play a beep sound to notify the player
339 sound(actor, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
340 actor.(weaponentity).hagar_warning = true;
344 // release if player let go of button or if they've held it in too long
345 if(!PHYS_INPUT_BUTTON_ATCK2(actor) || (stopped && actor.(weaponentity).hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
347 actor.(weaponentity).state = WS_READY;
348 W_Hagar_Attack2_Load_Release(actor, weaponentity);
353 actor.(weaponentity).hagar_loadbeep = false;
354 actor.(weaponentity).hagar_warning = false;
356 // we aren't checking ammo during an attack, so we must do it here
357 if(!(thiswep.wr_checkammo1(thiswep, actor, weaponentity) + thiswep.wr_checkammo2(thiswep, actor, weaponentity)))
358 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
360 // note: this doesn't force the switch
361 W_SwitchToOtherWeapon(actor, weaponentity);
367 void W_Hagar_Attack_Auto(Weapon thiswep, entity actor, .entity weaponentity, int fire)
369 if(!(fire & 1) || actor.(weaponentity).hagar_load || actor.(weaponentity).hagar_loadblock || actor.(weaponentity).m_switchweapon != WEP_HAGAR)
371 w_ready(thiswep, actor, weaponentity, fire);
375 if(!thiswep.wr_checkammo1(thiswep, actor, weaponentity))
376 if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO))
378 W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity);
379 w_ready(thiswep, actor, weaponentity, fire);
383 W_Hagar_Attack(thiswep, actor, weaponentity);
385 int slot = weaponslot(weaponentity);
386 ATTACK_FINISHED(actor, slot) = time + WEP_CVAR_PRI(hagar, refire) * W_WeaponRateFactor(actor);
387 int theframe = WFRAME_FIRE1;
388 entity this = actor.(weaponentity);
391 if(this.wframe == WFRAME_FIRE1)
392 theframe = WFRAME_DONTCHANGE;
394 weapon_thinkf(actor, weaponentity, theframe, WEP_CVAR_PRI(hagar, refire), W_Hagar_Attack_Auto);
397 METHOD(Hagar, wr_aim, void(entity thiswep, entity actor, .entity weaponentity))
400 PHYS_INPUT_BUTTON_ATCK(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
401 else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
402 PHYS_INPUT_BUTTON_ATCK2(actor) = bot_aim(actor, weaponentity, WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
404 METHOD(Hagar, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
406 float loadable_secondary;
407 loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
408 if(weaponslot(weaponentity) == 0)
409 actor.hagar_load = actor.(weaponentity).hagar_load;
411 if(loadable_secondary)
412 W_Hagar_Attack2_Load(thiswep, actor, weaponentity); // must always run each frame
413 if(autocvar_g_balance_hagar_reload_ammo && actor.(weaponentity).clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) { // forced reload
414 thiswep.wr_reload(thiswep, actor, weaponentity);
416 else if((fire & 1) && !actor.(weaponentity).hagar_load && !actor.(weaponentity).hagar_loadblock) // not while secondary is loaded or awaiting reset
418 if(weapon_prepareattack(thiswep, actor, weaponentity, false, 0))
419 W_Hagar_Attack_Auto(thiswep, actor, weaponentity, fire);
421 else if((fire & 2) && !loadable_secondary && WEP_CVAR(hagar, secondary))
423 if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(hagar, refire)))
425 W_Hagar_Attack2(thiswep, actor, weaponentity);
426 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
430 METHOD(Hagar, wr_gonethink, void(entity thiswep, entity actor, .entity weaponentity))
432 // we lost the weapon and want to prepare switching away
433 if(actor.(weaponentity).hagar_load)
435 actor.(weaponentity).state = WS_READY;
436 W_Hagar_Attack2_Load_Release(actor, weaponentity);
439 METHOD(Hagar, wr_setup, void(entity thiswep, entity actor, .entity weaponentity))
441 actor.hagar_load = 0;
442 actor.(weaponentity).hagar_loadblock = false;
443 if(actor.(weaponentity).hagar_load)
445 W_DecreaseAmmo(thiswep, actor, WEP_CVAR_SEC(hagar, ammo) * actor.(weaponentity).hagar_load * -1, weaponentity); // give back ammo if necessary
446 actor.(weaponentity).hagar_load = 0;
449 METHOD(Hagar, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity))
451 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_PRI(hagar, ammo);
452 ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
455 METHOD(Hagar, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity))
457 float ammo_amount = GetResourceAmount(actor, thiswep.ammo_type) >= WEP_CVAR_SEC(hagar, ammo);
458 ammo_amount += actor.(weaponentity).(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
461 METHOD(Hagar, wr_resetplayer, void(entity thiswep, entity actor))
463 actor.hagar_load = 0;
464 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
466 .entity weaponentity = weaponentities[slot];
467 actor.(weaponentity).hagar_load = 0;
470 METHOD(Hagar, wr_playerdeath, void(entity thiswep, entity actor, .entity weaponentity))
472 // if we have any rockets loaded when we die, release them
473 if(actor.(weaponentity).hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
474 W_Hagar_Attack2_Load_Release(actor, weaponentity);
476 METHOD(Hagar, wr_reload, void(entity thiswep, entity actor, .entity weaponentity))
478 if(!actor.(weaponentity).hagar_load) // require releasing loaded rockets first
479 W_Reload(actor, weaponentity, min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND_RELOAD);
481 METHOD(Hagar, wr_suicidemessage, Notification(entity thiswep))
483 return WEAPON_HAGAR_SUICIDE;
485 METHOD(Hagar, wr_killmessage, Notification(entity thiswep))
487 if(w_deathtype & HITTYPE_SECONDARY)
488 return WEAPON_HAGAR_MURDER_BURST;
490 return WEAPON_HAGAR_MURDER_SPRAY;
496 METHOD(Hagar, wr_impacteffect, void(entity thiswep, entity actor))
499 org2 = w_org + w_backoff * 6;
500 pointparticles(EFFECT_HAGAR_EXPLODE, org2, '0 0 0', 1);
504 sound(actor, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
505 else if(w_random<0.7)
506 sound(actor, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
508 sound(actor, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);