Skip to content

Commit

Permalink
Feature OpenMW#50: Don't allow ranged weapon attack when ammunition i…
Browse files Browse the repository at this point in the history
…s empty
  • Loading branch information
scrawl committed Feb 5, 2014
1 parent a07eaa0 commit 8b8fb93
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion apps/openmw/mwmechanics/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,19 @@ bool CharacterController::updateWeaponState()
if(isWeapon)
weapSpeed = weapon->get<ESM::Weapon>()->mBase->mData.mSpeed;

// Cancel attack if we no longer have ammunition
bool ammunition = true;
MWWorld::ContainerStoreIterator ammo = inv.getSlot(MWWorld::InventoryStore::Slot_Ammunition);
if (mWeaponType == WeapType_Crossbow)
ammunition = (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Bolt);
else if (mWeaponType == WeapType_BowAndArrow)
ammunition = (ammo != inv.end() && ammo->get<ESM::Weapon>()->mBase->mData.mType == ESM::Weapon::Arrow);
if (!ammunition && mUpperBodyState > UpperCharState_WeapEquiped)
{
mAnimation->disable(mCurrentWeapon);
mUpperBodyState = UpperCharState_WeapEquiped;
}

float complete;
bool animPlaying;
if(stats.getAttackingOrSpell())
Expand Down Expand Up @@ -706,7 +719,7 @@ bool CharacterController::updateWeaponState()
if(item.getRefData().getCount())
MWBase::Environment::get().getWindowManager()->setSelectedWeapon(item);
}
else
else if (ammunition)
{
if(mWeaponType == WeapType_Crossbow || mWeaponType == WeapType_BowAndArrow ||
mWeaponType == WeapType_Thrown)
Expand Down

0 comments on commit 8b8fb93

Please sign in to comment.