4 /* function */ W_Hagar,
5 /* ammotype */ ammo_rockets,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* modelname */ "hagar",
11 /* model */ MDL_HAGAR_ITEM,
12 /* simplemdl */ "foobar",
13 /* crosshair */ "gfx/crosshairhagar 0.8",
14 /* wepimg */ "weaponhagar",
15 /* refname */ "hagar",
16 /* wepname */ _("Hagar")
19 #define HAGAR_SETTINGS(w_cvar,w_prop) HAGAR_SETTINGS_LIST(w_cvar, w_prop, HAGAR, hagar)
20 #define HAGAR_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
21 w_cvar(id, sn, BOTH, ammo) \
22 w_cvar(id, sn, BOTH, damage) \
23 w_cvar(id, sn, BOTH, edgedamage) \
24 w_cvar(id, sn, BOTH, force) \
25 w_cvar(id, sn, BOTH, radius) \
26 w_cvar(id, sn, BOTH, refire) \
27 w_cvar(id, sn, BOTH, speed) \
28 w_cvar(id, sn, BOTH, spread) \
29 w_cvar(id, sn, BOTH, damageforcescale) \
30 w_cvar(id, sn, BOTH, health) \
31 w_cvar(id, sn, PRI, lifetime) \
32 w_cvar(id, sn, SEC, load) \
33 w_cvar(id, sn, SEC, load_max) \
34 w_cvar(id, sn, SEC, load_abort) \
35 w_cvar(id, sn, SEC, load_animtime) \
36 w_cvar(id, sn, SEC, load_hold) \
37 w_cvar(id, sn, SEC, load_speed) \
38 w_cvar(id, sn, SEC, load_releasedeath) \
39 w_cvar(id, sn, SEC, load_spread) \
40 w_cvar(id, sn, SEC, load_spread_bias) \
41 w_cvar(id, sn, SEC, load_linkexplode) \
42 w_cvar(id, sn, SEC, lifetime_min) \
43 w_cvar(id, sn, SEC, lifetime_rand) \
44 w_cvar(id, sn, NONE, secondary) \
45 w_prop(id, sn, float, reloading_ammo, reload_ammo) \
46 w_prop(id, sn, float, reloading_time, reload_time) \
47 w_prop(id, sn, float, switchdelay_raise, switchdelay_raise) \
48 w_prop(id, sn, float, switchdelay_drop, switchdelay_drop) \
49 w_prop(id, sn, string, weaponreplace, weaponreplace) \
50 w_prop(id, sn, float, weaponstart, weaponstart) \
51 w_prop(id, sn, float, weaponstartoverride, weaponstartoverride) \
52 w_prop(id, sn, float, weaponthrowable, weaponthrowable)
55 HAGAR_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
60 void spawnfunc_weapon_hagar(void) { weapon_defaultspawnfunc(WEP_HAGAR.m_id); }
62 // NO bounce protection, as bounces are limited!
64 void W_Hagar_Explode(void)
66 self.event_damage = func_null;
67 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);
72 void W_Hagar_Explode2(void)
74 self.event_damage = func_null;
75 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);
80 void W_Hagar_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
85 float is_linkexplode = ( ((inflictor.owner != world) ? (inflictor.owner == self.owner) : true)
86 && (inflictor.projectiledeathtype & HITTYPE_SECONDARY)
87 && (self.projectiledeathtype & HITTYPE_SECONDARY));
90 is_linkexplode = (is_linkexplode && WEP_CVAR_SEC(hagar, load_linkexplode));
92 is_linkexplode = -1; // not secondary load, so continue as normal without exception.
94 if(!W_CheckProjectileDamage(inflictor.realowner, self.realowner, deathtype, is_linkexplode))
95 return; // g_projectiles_damage says to halt
97 self.health = self.health - damage;
98 self.angles = vectoangles(self.velocity);
101 W_PrepareExplosionByDamage(attacker, self.think);
104 void W_Hagar_Touch(void)
110 void W_Hagar_Touch2(void)
114 if(self.cnt > 0 || other.takedamage == DAMAGE_AIM) {
118 Send_Effect(EFFECT_HAGAR_BOUNCE, self.origin, self.velocity, 1);
119 self.angles = vectoangles(self.velocity);
121 self.projectiledeathtype |= HITTYPE_BOUNCE;
125 void W_Hagar_Attack(void)
129 W_DecreaseAmmo(WEP_CVAR_PRI(hagar, ammo));
131 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_PRI(hagar, damage));
133 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
136 missile.owner = missile.realowner = self;
137 missile.classname = "missile";
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(void)
172 W_DecreaseAmmo(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);
179 missile.owner = missile.realowner = self;
180 missile.classname = "missile";
181 missile.bot_dodge = true;
182 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
184 missile.takedamage = DAMAGE_YES;
185 missile.health = WEP_CVAR_SEC(hagar, health);
186 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
187 missile.event_damage = W_Hagar_Damage;
188 missile.damagedbycontents = true;
190 missile.touch = W_Hagar_Touch2;
192 missile.use = W_Hagar_Explode2;
193 missile.think = adaptor_think2use_hittype_splash;
194 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
195 PROJECTILE_MAKETRIGGER(missile);
196 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
197 setorigin(missile, w_shotorg);
198 setsize(missile, '0 0 0', '0 0 0');
200 missile.movetype = MOVETYPE_BOUNCEMISSILE;
201 W_SetupProjVelocity_SEC(missile, hagar);
203 missile.angles = vectoangles(missile.velocity);
204 missile.flags = FL_PROJECTILE;
205 missile.missile_flags = MIF_SPLASH;
207 CSQCProjectile(missile, true, PROJECTILE_HAGAR_BOUNCING, true);
209 MUTATOR_CALLHOOK(EditProjectile, self, missile);
212 .float hagar_loadstep, hagar_loadblock, hagar_loadbeep, hagar_warning;
213 void W_Hagar_Attack2_Load_Release(void)
215 // time to release the rockets we've loaded
218 float counter, shots, spread_pershot;
220 vector forward, right, up;
225 weapon_prepareattack_do(1, WEP_CVAR_SEC(hagar, refire));
227 W_SetupShot(self, false, 2, SND(HAGAR_FIRE), CH_WEAPON_A, WEP_CVAR_SEC(hagar, damage));
228 Send_Effect(EFFECT_HAGAR_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1);
234 shots = self.hagar_load;
236 for(counter = 0; counter < shots; ++counter)
239 missile.owner = missile.realowner = self;
240 missile.classname = "missile";
241 missile.bot_dodge = true;
242 missile.bot_dodgerating = WEP_CVAR_SEC(hagar, damage);
244 missile.takedamage = DAMAGE_YES;
245 missile.health = WEP_CVAR_SEC(hagar, health);
246 missile.damageforcescale = WEP_CVAR_SEC(hagar, damageforcescale);
247 missile.event_damage = W_Hagar_Damage;
248 missile.damagedbycontents = true;
250 missile.touch = W_Hagar_Touch; // not bouncy
251 missile.use = W_Hagar_Explode2;
252 missile.think = adaptor_think2use_hittype_splash;
253 missile.nextthink = time + WEP_CVAR_SEC(hagar, lifetime_min) + random() * WEP_CVAR_SEC(hagar, lifetime_rand);
254 PROJECTILE_MAKETRIGGER(missile);
255 missile.projectiledeathtype = WEP_HAGAR.m_id | HITTYPE_SECONDARY;
256 setorigin(missile, w_shotorg);
257 setsize(missile, '0 0 0', '0 0 0');
258 missile.movetype = MOVETYPE_FLY;
259 missile.missile_flags = MIF_SPLASH;
261 // per-shot spread calculation: the more shots there are, the less spread is applied (based on the bias cvar)
262 spread_pershot = ((shots - 1) / (WEP_CVAR_SEC(hagar, load_max) - 1));
263 spread_pershot = (1 - (spread_pershot * WEP_CVAR_SEC(hagar, load_spread_bias)));
264 spread_pershot = (WEP_CVAR_SEC(hagar, spread) * spread_pershot * g_weaponspreadfactor);
266 // pattern spread calculation
272 makevectors('0 360 0' * (0.75 + (counter - 0.5) / (shots - 1)));
276 s = s * WEP_CVAR_SEC(hagar, load_spread) * g_weaponspreadfactor;
278 W_SetupProjVelocity_Explicit(missile, w_shotdir + right * s.y + up * s.z, v_up, WEP_CVAR_SEC(hagar, speed), 0, 0, spread_pershot, false);
280 missile.angles = vectoangles(missile.velocity);
281 missile.flags = FL_PROJECTILE;
283 CSQCProjectile(missile, true, PROJECTILE_HAGAR, true);
285 MUTATOR_CALLHOOK(EditProjectile, self, missile);
288 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hagar, load_animtime), w_ready);
289 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, refire) * W_WeaponRateFactor();
293 void W_Hagar_Attack2_Load(void)
295 // loadable hagar secondary attack, must always run each frame
297 if(time < game_starttime)
300 bool loaded = self.hagar_load >= WEP_CVAR_SEC(hagar, load_max);
302 // this is different than WR_CHECKAMMO when it comes to reloading
304 if(self.items & IT_UNLIMITED_WEAPON_AMMO)
306 else if(autocvar_g_balance_hagar_reload_ammo)
307 enough_ammo = self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
309 enough_ammo = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
311 bool stopped = loaded || !enough_ammo;
313 if(self.BUTTON_ATCK2)
315 if(self.BUTTON_ATCK && WEP_CVAR_SEC(hagar, load_abort))
319 // if we pressed primary fire while loading, unload all rockets and abort
320 self.weaponentity.state = WS_READY;
321 W_DecreaseAmmo(WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo
323 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
325 // pause until we can load rockets again, once we re-press the alt fire button
326 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
328 // require letting go of the alt fire button before we can load again
329 self.hagar_loadblock = true;
334 // check if we can attempt to load another rocket
337 if(!self.hagar_loadblock && self.hagar_loadstep < time)
339 W_DecreaseAmmo(WEP_CVAR_SEC(hagar, ammo));
340 self.weaponentity.state = WS_INUSE;
341 self.hagar_load += 1;
342 sound(self, CH_WEAPON_B, SND_HAGAR_LOAD, VOL_BASE * 0.8, ATTN_NORM); // sound is too loud according to most
344 if(self.hagar_load >= WEP_CVAR_SEC(hagar, load_max))
347 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_speed) * W_WeaponRateFactor();
350 if(stopped && !self.hagar_loadbeep && self.hagar_load) // prevents the beep from playing each frame
352 // if this is the last rocket we can load, play a beep sound to notify the player
353 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
354 self.hagar_loadbeep = true;
355 self.hagar_loadstep = time + WEP_CVAR_SEC(hagar, load_hold) * W_WeaponRateFactor();
359 else if(self.hagar_loadblock)
361 // the alt fire button has been released, so re-enable loading if blocked
362 self.hagar_loadblock = false;
367 // play warning sound if we're about to release
368 if(stopped && self.hagar_loadstep - 0.5 < time && WEP_CVAR_SEC(hagar, load_hold) >= 0)
370 if(!self.hagar_warning) // prevents the beep from playing each frame
372 // we're about to automatically release after holding time, play a beep sound to notify the player
373 sound(self, CH_WEAPON_A, SND_HAGAR_BEEP, VOL_BASE, ATTN_NORM);
374 self.hagar_warning = true;
378 // release if player let go of button or if they've held it in too long
379 if(!self.BUTTON_ATCK2 || (stopped && self.hagar_loadstep < time && WEP_CVAR_SEC(hagar, load_hold) >= 0))
381 self.weaponentity.state = WS_READY;
382 W_Hagar_Attack2_Load_Release();
387 self.hagar_loadbeep = false;
388 self.hagar_warning = false;
390 // we aren't checking ammo during an attack, so we must do it here
391 if(!(_WEP_ACTION(self.weapon, WR_CHECKAMMO1) + _WEP_ACTION(self.weapon, WR_CHECKAMMO2)))
392 if(!(self.items & IT_UNLIMITED_WEAPON_AMMO))
394 // note: this doesn't force the switch
395 W_SwitchToOtherWeapon(self);
401 bool W_Hagar(entity thiswep, int req)
409 self.BUTTON_ATCK = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
410 else // not using secondary_speed since these are only 15% and should cause some ricochets without re-aiming
411 self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_PRI(hagar, speed), 0, WEP_CVAR_PRI(hagar, lifetime), false);
417 float loadable_secondary;
418 loadable_secondary = (WEP_CVAR_SEC(hagar, load) && WEP_CVAR(hagar, secondary));
420 if(loadable_secondary)
421 W_Hagar_Attack2_Load(); // must always run each frame
422 if(autocvar_g_balance_hagar_reload_ammo && self.clip_load < min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo))) // forced reload
423 _WEP_ACTION(self.weapon, WR_RELOAD);
424 else if(self.BUTTON_ATCK && !self.hagar_load && !self.hagar_loadblock) // not while secondary is loaded or awaiting reset
426 if(weapon_prepareattack(0, WEP_CVAR_PRI(hagar, refire)))
429 weapon_thinkf(WFRAME_FIRE1, WEP_CVAR_PRI(hagar, refire), w_ready);
432 else if(self.BUTTON_ATCK2 && !loadable_secondary && WEP_CVAR(hagar, secondary))
434 if(weapon_prepareattack(1, WEP_CVAR_SEC(hagar, refire)))
437 weapon_thinkf(WFRAME_FIRE2, WEP_CVAR_SEC(hagar, refire), w_ready);
444 // we lost the weapon and want to prepare switching away
447 self.weaponentity.state = WS_READY;
448 W_Hagar_Attack2_Load_Release();
455 HAGAR_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
460 self.hagar_loadblock = false;
464 W_DecreaseAmmo(WEP_CVAR_SEC(hagar, ammo) * self.hagar_load * -1); // give back ammo if necessary
472 ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_PRI(hagar, ammo);
473 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_PRI(hagar, ammo);
478 ammo_amount = self.WEP_AMMO(HAGAR) >= WEP_CVAR_SEC(hagar, ammo);
479 ammo_amount += self.(weapon_load[WEP_HAGAR.m_id]) >= WEP_CVAR_SEC(hagar, ammo);
484 HAGAR_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
494 // if we have any rockets loaded when we die, release them
495 if(self.hagar_load && WEP_CVAR_SEC(hagar, load_releasedeath))
496 W_Hagar_Attack2_Load_Release();
502 if(!self.hagar_load) // require releasing loaded rockets first
503 W_Reload(min(WEP_CVAR_PRI(hagar, ammo), WEP_CVAR_SEC(hagar, ammo)), SND(RELOAD));
507 case WR_SUICIDEMESSAGE:
509 return WEAPON_HAGAR_SUICIDE;
513 if(w_deathtype & HITTYPE_SECONDARY)
514 return WEAPON_HAGAR_MURDER_BURST;
516 return WEAPON_HAGAR_MURDER_SPRAY;
523 bool W_Hagar(entity thiswep, int req)
527 case WR_IMPACTEFFECT:
530 org2 = w_org + w_backoff * 6;
531 pointparticles(particleeffectnum(EFFECT_HAGAR_EXPLODE), org2, '0 0 0', 1);
535 sound(self, CH_SHOTS, SND_HAGEXP1, VOL_BASE, ATTN_NORM);
536 else if(w_random<0.7)
537 sound(self, CH_SHOTS, SND_HAGEXP2, VOL_BASE, ATTN_NORM);
539 sound(self, CH_SHOTS, SND_HAGEXP3, VOL_BASE, ATTN_NORM);
550 // no weapon specific image for this weapon