Use Arbutils exception Macros, instead of own ones.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -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<uint8_t*>(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<uint8_t*>(newPtr);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
<< "'.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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() << ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<uint8_t*>(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<uint8_t*>(newPtr);
|
||||
}
|
||||
|
||||
@@ -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<std::shared_ptr<BaseTurnChoice>>(_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<ChoiceQueue>(choices);
|
||||
TriggerEventListener<TurnStartEvent>();
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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> creature, uint8_t index) {
|
||||
|
||||
@@ -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>& creature) noexcept {
|
||||
|
||||
@@ -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<const Library::Item> 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);
|
||||
|
||||
@@ -274,14 +274,14 @@ namespace CreatureLib::Battling {
|
||||
void Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
|
||||
ArbUt::BorrowedPtr<const Library::Item> 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<const Library::Item> 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);
|
||||
}
|
||||
|
||||
@@ -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> 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> creature) noexcept {
|
||||
|
||||
@@ -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()) \
|
||||
} \
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user