void W_SwitchWeapon_Force(entity e, float w)
{
+ // don't switch to another weapon if we're not allowed to
+ if(e.weapon_forbidchange)
+ return;
+
e.cnt = e.switchweapon;
e.switchweapon = w;
e.selectweapon = w;
.float hasweapon_complain_spam;
-float W_Reload_AllowSwitching(float wpn);
float client_hasweapon(entity cl, float wpn, float andammo, float complain)
{
local float weaponbit, f;
f = weapon_action(wpn, WR_CHECKAMMO1);
f = f + weapon_action(wpn, WR_CHECKAMMO2);
- // allow switching to reloadable weapons, even if we're out of ammo, since the weapon itself
- // might still be loaded. The reload code takes care of complaining and forced switching
- entity e;
- e = get_weaponinfo(wpn);
- if(wpn != WEP_TUBA && wpn != WEP_PORTO && wpn != WEP_HOOK) // skip non-reloadable weapons, or we access undefined cvars
- if(cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
- {
- if(W_Reload_AllowSwitching(wpn))
- f = 1;
- else
- f = 0; // necessary to avoid switching back and forth
- }
-
// always allow selecting the Mine Layer if we placed mines, so that we can detonate them
local entity mine;
if(wpn == WEP_MINE_LAYER)
if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
if (!weapon_action(self.weapon, WR_CHECKAMMO1 + secondary))
{
- // allow switching to reloadable weapons, even if we're out of ammo, since the weapon itself
- // might still be loaded. The reload code takes care of complaining and forced switching
- entity e;
- e = get_weaponinfo(self.weapon);
- if(self.weapon != WEP_TUBA && self.weapon != WEP_PORTO && self.weapon != WEP_HOOK) // skip non-reloadable weapons, or we access undefined cvars
- if(cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
- if(W_Reload_AllowSwitching(self.weapon))
- return FALSE;
-
// always keep the Mine Layer if we placed mines, so that we can detonate them
local entity mine;
if(self.weapon == WEP_MINE_LAYER)
self.weapon_think = func;
//dprint("next ", ftos(self.weapon_nextthink), "\n");
+ // The shoot animation looks TERRIBLE without animation blending! Yay for moonwalking while shooting!
+ /*
if (restartanim)
if (t)
if (!self.crouch) // shoot anim stands up, this looks bad
{
local vector anim;
- anim = self.anim_shoot;
+ if(self.weapon == WEP_SHOTGUN && self.BUTTON_ATCK2)
+ anim = self.anim_melee;
+ else
+ anim = self.anim_shoot;
anim_z = anim_y / (t + sys_frametime);
setanim(self, anim, FALSE, TRUE, TRUE);
}
+ */
};
void weapon_boblayer1(float spd, vector org)
#define W_SETUPPROJECTILEVELOCITY_UP(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), cvar(#s "_speed_up"), cvar(#s "_speed_z"), cvar(#s "_spread"), FALSE)
#define W_SETUPPROJECTILEVELOCITY(m,s) W_SetupProjectileVelocityEx(m, w_shotdir, v_up, cvar(#s "_speed"), 0, 0, cvar(#s "_spread"), FALSE)
-// shared weapon reload code
-float W_Reload_AllowSwitching(float wpn)
+void W_DecreaseAmmo(.float ammo_type, float ammo_use, float ammo_reload)
{
- // check each reloadable weapon's load to see if we can switch to it
- // since each self.*_load cvar is a fixed float, there's no way to check these but listing them here
- switch(wpn)
- {
- case WEP_SHOTGUN:
- return self.shotgun_load >= autocvar_g_balance_shotgun_primary_ammo;
- case WEP_UZI:
- return self.uzi_load >= min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo);
- case WEP_GRENADE_LAUNCHER:
- return self.grenadelauncher_load >= min(autocvar_g_balance_grenadelauncher_primary_ammo, autocvar_g_balance_grenadelauncher_secondary_ammo);
- case WEP_MINE_LAYER:
- return self.minelayer_load >= autocvar_g_balance_minelayer_ammo;
- case WEP_ELECTRO:
- return self.electro_load >= min(autocvar_g_balance_electro_primary_ammo, autocvar_g_balance_electro_secondary_ammo);
- case WEP_CRYLINK:
- return self.crylink_load >= min(autocvar_g_balance_crylink_primary_ammo, autocvar_g_balance_crylink_secondary_ammo);
- case WEP_HLAC:
- return self.hlac_load >= min(autocvar_g_balance_hlac_primary_ammo, autocvar_g_balance_hlac_secondary_ammo);
- case WEP_NEX:
- return self.nex_load >= min(autocvar_g_balance_nex_primary_ammo, autocvar_g_balance_nex_secondary_ammo);
- case WEP_MINSTANEX:
- float minsta_ammo;
- if(g_minstagib)
- minsta_ammo = 1;
- else
- minsta_ammo = autocvar_g_balance_minstanex_ammo;
+ if((self.items & IT_UNLIMITED_WEAPON_AMMO) && !ammo_reload)
+ return;
- if(autocvar_g_balance_minstanex_laser_ammo)
- return self.minstanex_load >= min(minsta_ammo, autocvar_g_balance_minstanex_laser_ammo);
- else
- return self.minstanex_load >= minsta_ammo;
- case WEP_SNIPERRIFLE:
- return self.sniperrifle_load >= min(autocvar_g_balance_sniperrifle_primary_ammo, autocvar_g_balance_sniperrifle_secondary_ammo);
- case WEP_SEEKER:
- return self.seeker_load >= min(autocvar_g_balance_seeker_missile_ammo, autocvar_g_balance_seeker_tag_ammo);
- case WEP_HAGAR:
- return self.hagar_load >= min(autocvar_g_balance_hagar_primary_ammo, autocvar_g_balance_hagar_secondary_ammo);
- case WEP_FIREBALL:
- return self.fireball_load >= min(autocvar_g_balance_fireball_primary_ammo, autocvar_g_balance_fireball_secondary_ammo);
- case WEP_ROCKET_LAUNCHER:
- return self.rocketlauncher_load >= autocvar_g_balance_rocketlauncher_ammo;
- default:
- return TRUE;
+ // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
+ if(ammo_reload)
+ {
+ self.clip_load -= ammo_use;
+ self.weapon_load[self.weapon] = self.clip_load;
}
+ else
+ self.(self.current_ammo) -= ammo_use;
}
+// weapon reloading code
+
+.float reload_ammo_amount, reload_ammo_min, reload_time;
.float reload_complain;
-float W_ReloadCheck(float ammo_amount, float ammo_shot)
+.string reload_sound;
+
+void W_ReloadedAndReady()
{
+ // finish the reloading process, and do the ammo transfer
+
+ self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
+
+ // if the gun uses no ammo, max out weapon load, else decrease ammo as we increase weapon load
+ if(!self.reload_ammo_min || self.items & IT_UNLIMITED_WEAPON_AMMO)
+ self.clip_load = self.reload_ammo_amount;
+ else
+ {
+ while(self.clip_load < self.reload_ammo_amount && self.(self.current_ammo)) // make sure we don't add more ammo than we have
+ {
+ self.clip_load += 1;
+ self.(self.current_ammo) -= 1;
+ }
+ }
+ self.weapon_load[self.weapon] = self.clip_load;
+
+ // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
+ // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
+ // so your weapon is disabled for a few seconds without reason
+
+ //ATTACK_FINISHED(self) -= self.reload_time - 1;
+
+ w_ready();
+}
+
+void W_Reload(float sent_ammo_min, float sent_ammo_amount, float sent_time, string sent_sound)
+{
+ // set global values to work with
+
+ self.reload_ammo_min = sent_ammo_min;
+ self.reload_ammo_amount = sent_ammo_amount;
+ self.reload_time = sent_time;
+ self.reload_sound = sent_sound;
+
+ // check if we meet the necessary conditions to reload
+
entity e;
e = get_weaponinfo(self.weapon);
+ // don't reload weapons that don't have the RELOADABLE flag
+ if not(e.spawnflags & WEP_FLAG_RELOADABLE)
+ {
+ dprint("Warning: Attempted to reload a weapon that does not have the WEP_FLAG_RELOADABLE flag. Fix your code!\n");
+ return;
+ }
+
+ // return if reloading is disabled for this weapon
+ if(!self.reload_ammo_amount)
+ return;
+
// our weapon is fully loaded, no need to reload
- if (self.clip_load >= cvar(strcat("g_balance_", e.netname, "_reload_ammo")))
- return 0;
+ if (self.clip_load >= self.reload_ammo_amount)
+ return;
// no ammo, so nothing to load
- if(!ammo_amount)
+ if(!self.(self.current_ammo) && self.reload_ammo_min)
+ if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
{
if(clienttype(self) == CLIENTTYPE_REAL && self.reload_complain < time)
{
sprint(self, strcat("You don't have enough ammo to reload the ^2", W_Name(self.weapon), "\n"));
self.reload_complain = time + 1;
}
- // switch away if the loaded amount of ammo is not enough to keep using this weapon
- if(self.clip_load < ammo_shot)
+ // switch away if the amount of ammo is not enough to keep using this weapon
+ if not(weapon_action(self.weapon, WR_CHECKAMMO1) + weapon_action(self.weapon, WR_CHECKAMMO2))
{
self.clip_load = -1; // reload later
W_SwitchToOtherWeapon(self);
}
- return 0;
+ return;
}
if (self.weaponentity)
{
if (self.weaponentity.wframe == WFRAME_RELOAD)
- return 0;
+ return;
// allow switching away while reloading, but this will cause a new reload!
self.weaponentity.state = WS_READY;
}
- return 1;
-}
\ No newline at end of file
+ // now begin the reloading process
+
+ sound (self, CHAN_WEAPON2, self.reload_sound, VOL_BASE, ATTN_NORM);
+
+ // do not set ATTACK_FINISHED in reload code any more. This causes annoying delays if eg: You start reloading a weapon,
+ // then quickly switch to another weapon and back. Reloading is canceled, but the reload delay is still there,
+ // so your weapon is disabled for a few seconds without reason
+
+ //ATTACK_FINISHED(self) = max(time, ATTACK_FINISHED(self)) + self.reload_time + 1;
+
+ weapon_thinkf(WFRAME_RELOAD, self.reload_time, W_ReloadedAndReady);
+
+ if(self.clip_load < 0)
+ self.clip_load = 0;
+ self.old_clip_load = self.clip_load;
+ self.clip_load = self.weapon_load[self.weapon] = -1;
+}