diff --git a/src/Battling/EventHooks/EventHook.hpp b/src/Battling/EventHooks/EventHook.hpp index db1527e..50d2a05 100644 --- a/src/Battling/EventHooks/EventHook.hpp +++ b/src/Battling/EventHooks/EventHook.hpp @@ -29,7 +29,7 @@ namespace CreatureLib::Battling { EventHook() : _offset(0), _capacity(2048) { auto ptr = malloc(_capacity); if (ptr == nullptr) { - THROW_CREATURE("Out of memory."); + THROW("Out of memory."); } _memory = static_cast(ptr); } @@ -49,7 +49,7 @@ namespace CreatureLib::Battling { _capacity += stepSize; auto newPtr = realloc(_memory, _capacity); if (newPtr == nullptr) { - THROW_CREATURE("Out of memory."); + THROW("Out of memory."); } _memory = static_cast(newPtr); } diff --git a/src/Battling/Flow/ResolveTarget.hpp b/src/Battling/Flow/ResolveTarget.hpp index e8c3d29..7916101 100644 --- a/src/Battling/Flow/ResolveTarget.hpp +++ b/src/Battling/Flow/ResolveTarget.hpp @@ -105,8 +105,8 @@ namespace CreatureLib::Battling { return {battle->GetCreature(index)}; }; } - THROW_CREATURE("Unknown attack target kind: '" << CreatureLib::Library::AttackTargetHelper::ToString(target) - << "'."); + THROW("Unknown attack target kind: '" << CreatureLib::Library::AttackTargetHelper::ToString(target) + << "'."); } }; } diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 212ed81..b199b76 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -203,7 +203,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo } catch (const ArbUt::Exception& e) { throw e; } catch (const std::exception& e) { - THROW_CREATURE("Exception during status attack effect handling: " << e.what() << "."); + THROW("Exception during status attack effect handling: " << e.what() << "."); } } } else { @@ -235,8 +235,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo } catch (const ArbUt::Exception& e) { throw e; } catch (const std::exception& e) { - THROW_CREATURE("Exception during offensive attack secondary effect handling: " << e.what() - << "."); + THROW("Exception during offensive attack secondary effect handling: " << e.what() << "."); } } } diff --git a/src/Battling/History/HistoryHolder.hpp b/src/Battling/History/HistoryHolder.hpp index 4875bfd..f91fcdb 100644 --- a/src/Battling/History/HistoryHolder.hpp +++ b/src/Battling/History/HistoryHolder.hpp @@ -22,7 +22,7 @@ namespace CreatureLib::Battling { HistoryHolder() : _offset(0), _capacity(2048) { auto ptr = malloc(_capacity); if (ptr == nullptr) { - THROW_CREATURE("Out of memory."); + THROW("Out of memory."); } _memory = static_cast(ptr); } @@ -40,7 +40,7 @@ namespace CreatureLib::Battling { _capacity += stepSize; auto newPtr = realloc(_memory, _capacity); if (newPtr == nullptr) { - THROW_CREATURE("Out of memory."); + THROW("Out of memory."); } _memory = static_cast(newPtr); } diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index 69d7036..d42bf64 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -43,7 +43,7 @@ void Battle::CheckChoicesSetAndRun() { } catch (const ArbUt::Exception& e) { throw e; } catch (const std::exception& e) { - THROW_CREATURE("Exception during choices set validation: '" << e.what() << "'.") + THROW("Exception during choices set validation: '" << e.what() << "'.") } auto choices = std::vector>(_numberOfSides * _creaturesPerSide); @@ -69,13 +69,13 @@ void Battle::CheckChoicesSetAndRun() { side->ResetChoices(); } } catch (const std::exception& e) { - THROW_CREATURE("Exception during turn initialization: '" << e.what() << "'.") + THROW("Exception during turn initialization: '" << e.what() << "'.") } _currentTurn++; try { TurnOrdering::OrderChoices(choices, _random.GetRNG()); } catch (const std::exception& e) { - THROW_CREATURE("Exception during turn ordering: '" << e.what() << "'.") + THROW("Exception during turn ordering: '" << e.what() << "'.") } this->_currentTurnQueue = std::make_unique(choices); TriggerEventListener(); @@ -84,7 +84,7 @@ void Battle::CheckChoicesSetAndRun() { } catch (const ArbUt::Exception& e) { throw e; } catch (const std::exception& e) { - THROW_CREATURE("Error during running a turn: '" << e.what() << "'."); + THROW("Error during running a turn: '" << e.what() << "'."); } if (this->_currentTurnQueue->HasCompletedQueue) { this->_currentTurnQueue = nullptr; @@ -160,7 +160,7 @@ void Battle::AddVolatileScript(const ArbUt::StringView& key) { } script = _library->LoadScript(ScriptCategory::Battle, key); if (script == nullptr) { - THROW_CREATURE("Invalid volatile script requested for battle: '" << key.c_str() << "'."); + THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'."); } return _volatile.Add(script.GetRaw()); } diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index 311525c..4ffb906 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -18,7 +18,7 @@ bool BattleSide::AllPossibleSlotsFilled() const { } } } catch (const std::exception& e) { - THROW_CREATURE("Exception during AllPossibleSlotsFilled check: '" << e.what() << "'."); + THROW("Exception during AllPossibleSlotsFilled check: '" << e.what() << "'."); } return true; } @@ -42,9 +42,9 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) { } } } catch (const std::exception& e) { - THROW_CREATURE("Error during setting choice: '" << e.what() << "'."); + THROW("Error during setting choice: '" << e.what() << "'."); } - THROW_CREATURE("User not found"); + THROW("User not found"); } void BattleSide::SetCreature(ArbUt::BorrowedPtr creature, uint8_t index) { diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index c76b5be..524ab1c 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -59,7 +59,7 @@ namespace CreatureLib::Battling { if (_creatures[i] == c) return i; } - THROW_CREATURE("Unable to find creature on field."); + THROW("Unable to find creature on field."); } void MarkSlotAsUnfillable(const ArbUt::BorrowedPtr& creature) noexcept { diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index 23da5cd..b957fab 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -23,7 +23,7 @@ CreateCreature CreateCreature::WithGender(Library::Gender gender) { CreateCreature CreateCreature::WithAttack(const ArbUt::StringView& attackName, AttackLearnMethod learnMethod) { if (_attacks.Count() >= _library->GetSettings()->GetMaximalAttacks()) { - THROW_CREATURE("You have already set the maximum amount of allowed moves."); + THROW("You have already set the maximum amount of allowed moves."); } auto attackData = _library->GetAttackLibrary()->Get(attackName.GetHash()); @@ -52,7 +52,7 @@ Creature* CreateCreature::Create() { ArbUt::BorrowedPtr heldItem; if (!this->_heldItem.IsEmpty()) { if (!_library->GetItemLibrary()->TryGet(this->_heldItem.GetHash(), heldItem)) { - THROW_CREATURE("Invalid held item '" << this->_heldItem.c_str() << "'."); + THROW("Invalid held item '" << this->_heldItem.c_str() << "'."); } } auto experience = _library->GetGrowthRateLibrary()->CalculateExperience(species->GetGrowthRate(), _level); diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index f50c3a2..75618bb 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -274,14 +274,14 @@ namespace CreatureLib::Battling { void Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) { ArbUt::BorrowedPtr item; if (!_library->GetItemLibrary()->TryGet(itemName.GetHash(), item)) { - THROW_CREATURE("Item not found '" << itemName.c_str() << "'."); + THROW("Item not found '" << itemName.c_str() << "'."); } _heldItem = item; } void Creature::SetHeldItem(uint32_t itemNameHash) { ArbUt::BorrowedPtr item; if (!_library->GetItemLibrary()->TryGet(itemNameHash, item)) { - THROW_CREATURE("Item not found."); + THROW("Item not found."); } _heldItem = item; } @@ -294,7 +294,7 @@ namespace CreatureLib::Battling { } script = this->_library->LoadScript(ScriptCategory::Creature, name); if (script == nullptr) { - THROW_CREATURE("Invalid volatile script requested for creature: '" << name.c_str() << "'."); + THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'."); } _volatile.Add(script.GetRaw()); } @@ -313,7 +313,7 @@ namespace CreatureLib::Battling { if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) { _attacks.Append(attack); } - THROW_CREATURE("Can't add attack. The creature already has the maximum amount of attacks."); + THROW("Can't add attack. The creature already has the maximum amount of attacks."); } uint8_t Creature::GetAvailableAttackSlot() const noexcept { for (uint8_t i = 0; i < (uint8_t)_attacks.Count(); i++) { @@ -331,8 +331,7 @@ namespace CreatureLib::Battling { if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) { _attacks.Append(attack); } - THROW_CREATURE("Can't replace attack at index " << index << ". Number of attacks is " << _attacks.Count() - << "."); + THROW("Can't replace attack at index " << index << ". Number of attacks is " << _attacks.Count() << "."); } _attacks.Set(index, attack); } diff --git a/src/Battling/Models/ExecutingAttack.hpp b/src/Battling/Models/ExecutingAttack.hpp index 9025609..1100d25 100644 --- a/src/Battling/Models/ExecutingAttack.hpp +++ b/src/Battling/Models/ExecutingAttack.hpp @@ -65,7 +65,7 @@ namespace CreatureLib::Battling { return _hits[i * _numberHits + hit]; } } - THROW_CREATURE("Invalid target requested."); + THROW("Invalid target requested."); } HitData* GetTargetIteratorBegin(ArbUt::BorrowedPtr creature) { @@ -74,7 +74,7 @@ namespace CreatureLib::Battling { return &_hits[i * _numberHits]; } } - THROW_CREATURE("Invalid target requested."); + THROW("Invalid target requested."); } bool IsCreatureTarget(ArbUt::BorrowedPtr creature) noexcept { diff --git a/src/Battling/ScriptHandling/ScriptMacros.hpp b/src/Battling/ScriptHandling/ScriptMacros.hpp index 59c8169..af4ce52 100644 --- a/src/Battling/ScriptHandling/ScriptMacros.hpp +++ b/src/Battling/ScriptHandling/ScriptMacros.hpp @@ -9,12 +9,12 @@ try { \ next->hookName(__VA_ARGS__); \ } catch (const std::exception& e) { \ - THROW_CREATURE("Exception running script hook '" #hookName "': " << e.what()) \ + THROW("Exception running script hook '" #hookName "': " << e.what()) \ } \ } \ } catch (const ArbUt::Exception& e) { \ throw e; \ } catch (const std::exception& e) { \ - THROW_CREATURE("Exception setting up script hook '" #hookName "': " << e.what()) \ + THROW("Exception setting up script hook '" #hookName "': " << e.what()) \ } \ } diff --git a/src/Library/CreatureData/LearnableAttacks.hpp b/src/Library/CreatureData/LearnableAttacks.hpp index f6d47c8..94eb454 100644 --- a/src/Library/CreatureData/LearnableAttacks.hpp +++ b/src/Library/CreatureData/LearnableAttacks.hpp @@ -27,7 +27,7 @@ namespace CreatureLib::Library { inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); } inline const ArbUt::List>& GetAttacksForLevel(uint8_t level) const { if (!_learnedByLevel.Has(level)) { - THROW_CREATURE("No attacks found for level " << (uint32_t)level << "."); + THROW("No attacks found for level " << (uint32_t)level << "."); } return _learnedByLevel.Get(level); } diff --git a/src/Library/CreatureData/SpeciesVariant.cpp b/src/Library/CreatureData/SpeciesVariant.cpp index 3f5c95c..a05350e 100644 --- a/src/Library/CreatureData/SpeciesVariant.cpp +++ b/src/Library/CreatureData/SpeciesVariant.cpp @@ -13,5 +13,5 @@ CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::StringView& ta return TalentIndex(true, i); } } - THROW_CREATURE("The given talent is not a valid talent for this creature."); + THROW("The given talent is not a valid talent for this creature."); } \ No newline at end of file diff --git a/src/Library/EffectParameter.hpp b/src/Library/EffectParameter.hpp index fb12271..ba7734b 100644 --- a/src/Library/EffectParameter.hpp +++ b/src/Library/EffectParameter.hpp @@ -25,7 +25,7 @@ namespace CreatureLib::Library { inline EffectParameterType GetType() const noexcept { return _type; } bool AsBool() const { if (_type != EffectParameterType::Bool) { - THROW_CREATURE("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type)); + THROW("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type)); } return std::get(_value); } @@ -34,7 +34,7 @@ namespace CreatureLib::Library { if (_type == EffectParameterType::Float) { return static_cast(std::get(_value)); } - THROW_CREATURE("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type)); + THROW("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type)); } return std::get(_value); } @@ -43,15 +43,13 @@ namespace CreatureLib::Library { if (_type == EffectParameterType::Int) { return static_cast(std::get(_value)); } - THROW_CREATURE("Cast effect parameter to float, but was " - << EffectParameterTypeHelper::ToString(_type)); + THROW("Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type)); } return std::get(_value); } const ArbUt::StringView& AsString() const { if (_type != EffectParameterType::String) { - THROW_CREATURE("Cast effect parameter to string, but was " - << EffectParameterTypeHelper::ToString(_type)); + THROW("Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type)); } return std::get(_value); } diff --git a/src/Library/Exceptions/CreatureException.hpp b/src/Library/Exceptions/CreatureException.hpp index ca89b09..5c4c887 100644 --- a/src/Library/Exceptions/CreatureException.hpp +++ b/src/Library/Exceptions/CreatureException.hpp @@ -2,18 +2,6 @@ #define CREATURELIB_CREATUREEXCEPTION_HPP #include -#include -#include -#include -#include -#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) - -#define THROW_CREATURE(message) \ - std::stringstream ___ss; \ - ___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \ - throw ArbUt::Exception(___ss.str()); -#define NOT_REACHABLE THROW_CREATURE("Not reachable"); -#define NOT_IMPLEMENTED THROW_CREATURE("Not implemented"); #define try_creature(data, msg) \ try { \ @@ -21,6 +9,6 @@ } catch (const ArbUt::Exception& e) { \ throw e; \ } catch (const std::exception& e) { \ - THROW_CREATURE(msg << ": '" << e.what() << "'."); \ + THROW(msg << ": '" << e.what() << "'."); \ } #endif // CREATURELIB_CREATUREEXCEPTION_HPP diff --git a/src/Library/GrowthRates/GrowthRateLibrary.cpp b/src/Library/GrowthRates/GrowthRateLibrary.cpp index f07e0d1..8af9622 100644 --- a/src/Library/GrowthRates/GrowthRateLibrary.cpp +++ b/src/Library/GrowthRates/GrowthRateLibrary.cpp @@ -5,7 +5,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas uint32_t experience) const { auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { - THROW_CREATURE("Invalid growth rate was requested."); + THROW("Invalid growth rate was requested."); } return find->second->CalculateLevel(experience); } @@ -13,7 +13,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const { auto find = _growthRates.find(hash); if (find == _growthRates.end()) { - THROW_CREATURE("Invalid growth rate was requested."); + THROW("Invalid growth rate was requested."); } return find->second->CalculateLevel(experience); } @@ -22,7 +22,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU uint8_t level) const { auto find = _growthRates.find(growthRate); if (find == _growthRates.end()) { - THROW_CREATURE("Invalid growth rate was requested."); + THROW("Invalid growth rate was requested."); } return find->second->CalculateExperience(level); } @@ -30,7 +30,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, uint8_t level) const { auto find = _growthRates.find(hash); if (find == _growthRates.end()) { - THROW_CREATURE("Invalid growth rate was requested."); + THROW("Invalid growth rate was requested."); } return find->second->CalculateExperience(level); } diff --git a/src/Library/TypeLibrary.cpp b/src/Library/TypeLibrary.cpp index 5ae1bbe..b11d102 100644 --- a/src/Library/TypeLibrary.cpp +++ b/src/Library/TypeLibrary.cpp @@ -21,5 +21,5 @@ const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const { return kv.first; } } - THROW_CREATURE("Name requested for unknown type: " << (uint32_t)type); + THROW("Name requested for unknown type: " << (uint32_t)type); } diff --git a/src/Library/TypeLibrary.hpp b/src/Library/TypeLibrary.hpp index c7c6d6c..3efba16 100644 --- a/src/Library/TypeLibrary.hpp +++ b/src/Library/TypeLibrary.hpp @@ -23,8 +23,8 @@ namespace CreatureLib::Library { try { return _effectiveness[attacking][defensive]; } catch (const std::exception& e) { - THROW_CREATURE("Unknown type indices were requested for effectiveness: " - << (uint32_t)attacking << " and " << (uint32_t)defensive); + THROW("Unknown type indices were requested for effectiveness: " << (uint32_t)attacking << " and " + << (uint32_t)defensive); } } [[nodiscard]] inline float GetEffectiveness(uint8_t attacking, diff --git a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp index fcb84ba..710e985 100644 --- a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp @@ -133,7 +133,7 @@ TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripti auto vec = ArbUt::List{}; auto aggr = ScriptAggregator(vec); while (aggr.HasNext()) { - THROW_CREATURE("Aggregator returned a script, but should have been empty."); + THROW("Aggregator returned a script, but should have been empty."); } CHECK(ran == 0); } diff --git a/tests/ExceptionTests.cpp b/tests/ExceptionTests.cpp index a17ae4c..265b842 100644 --- a/tests/ExceptionTests.cpp +++ b/tests/ExceptionTests.cpp @@ -7,7 +7,7 @@ TEST_CASE("When throwing exception, what() is readable", "[Utilities][Exception]") { bool hasCaught = false; try { - THROW_CREATURE("foobar"); + THROW("foobar"); } catch (const ArbUt::Exception& e) { hasCaught = true; INFO(e.what());