Skip to content

Commit

Permalink
Fix bug and made function more permissive
Browse files Browse the repository at this point in the history
# Conflicts:
#	Extended.txt
  • Loading branch information
Yankes authored and MeridianOXC committed Jul 11, 2017
1 parent 363e3f8 commit 4e687b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
33 changes: 13 additions & 20 deletions src/Savegame/BattleItem.cpp
Expand Up @@ -546,7 +546,7 @@ bool BattleItem::setAmmoPreMission(BattleItem *item)
* @param action Action type.
* @return Return config of item action or nullptr for wrong action type or item.
*/
const RuleItemAction *BattleItem::getActionConfNullable(BattleActionType action) const
const RuleItemAction *BattleItem::getActionConf(BattleActionType action) const
{
switch (action)
{
Expand All @@ -559,27 +559,12 @@ const RuleItemAction *BattleItem::getActionConfNullable(BattleActionType action)
}
}

/**
* Get configuration of action on that item.
* @param action Action type.
* @return Return config of item action.
*/
const RuleItemAction *BattleItem::getActionConf(BattleActionType action) const
{
auto rule = getActionConfNullable(action);
if (!rule)
{
throw Exception("Unsupported action (val: " + std::to_string((int)action) + ") for item " + _rules->getType());
}
return rule;
}

/**
* Determines if this item uses ammo.
*/
bool BattleItem::needsAmmoForAction(BattleActionType action) const
{
auto conf = getActionConfNullable(action);
auto conf = getActionConf(action);
if (!conf || conf->ammoSlot == -1)
{
return false;
Expand All @@ -596,6 +581,10 @@ bool BattleItem::needsAmmoForAction(BattleActionType action) const
const BattleItem *BattleItem::getAmmoForAction(BattleActionType action) const
{
auto conf = getActionConf(action);
if (!conf)
{
return nullptr;
}
if (conf->ammoSlot == -1)
{
return this;
Expand All @@ -618,6 +607,10 @@ const BattleItem *BattleItem::getAmmoForAction(BattleActionType action) const
BattleItem *BattleItem::getAmmoForAction(BattleActionType action, std::string* message)
{
auto conf = getActionConf(action);
if (!conf)
{
return nullptr;
}
if (conf->ammoSlot == -1)
{
return this;
Expand Down Expand Up @@ -678,7 +671,7 @@ void BattleItem::spendAmmoForAction(BattleActionType action, SavedBattleGame* sa
*/
bool BattleItem::haveNextShotsForAction(BattleActionType action, int shotCount) const
{
auto conf = getActionConfNullable(action);
auto conf = getActionConf(action);
if (conf)
{
return shotCount < conf->shots;
Expand Down Expand Up @@ -1041,7 +1034,7 @@ struct getAmmoForActionScript
static RetEnum func(BattleItem *weapon, BattleItem *&ammo, int action)
{
BattleActionType bat = (BattleActionType)action;
if (weapon && weapon->getActionConfNullable(bat))
if (weapon)
{
ammo = weapon->getAmmoForAction(bat);
}
Expand All @@ -1058,7 +1051,7 @@ struct getAmmoForActionConstScript
static RetEnum func(const BattleItem *weapon, const BattleItem *&ammo, int action)
{
BattleActionType bat = (BattleActionType)action;
if (weapon && weapon->getActionConfNullable(bat))
if (weapon)
{
ammo = weapon->getAmmoForAction(bat);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Savegame/BattleItem.h
Expand Up @@ -135,8 +135,6 @@ class BattleItem
/// Sets the item's ammo item based on it type.
bool setAmmoPreMission(BattleItem *item);
/// Get ammo slot for action.
const RuleItemAction *getActionConfNullable(BattleActionType action) const;
/// Get ammo slot for action.
const RuleItemAction *getActionConf(BattleActionType action) const;
/// Determines if this item uses ammo.
bool needsAmmoForAction(BattleActionType action) const;
Expand Down

0 comments on commit 4e687b6

Please sign in to comment.