Update to new THROW macro.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
54eddba913
commit
f1d706b356
|
@ -95,7 +95,7 @@ TargetList TargetResolver::ResolveTargets(const CreatureIndex& index, AttackTarg
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW("Unknown attack target kind: '" << AttackTargetHelper::ToString(target) << "'.")
|
THROW("Unknown attack target kind: '", AttackTargetHelper::ToString(target), "'.")
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TargetResolver::IsValidTarget(const CreatureIndex& index, CreatureLib::Library::AttackTarget target,
|
bool TargetResolver::IsValidTarget(const CreatureIndex& index, CreatureLib::Library::AttackTarget target,
|
||||||
|
@ -149,5 +149,5 @@ bool TargetResolver::IsValidTarget(const CreatureIndex& index, CreatureLib::Libr
|
||||||
return index == userIndex;
|
return index == userIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW("Unknown attack target kind: '" << AttackTargetHelper::ToString(target) << "'.")
|
THROW("Unknown attack target kind: '", AttackTargetHelper::ToString(target), "'.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,7 @@ void TurnHandler::RunTurn(const ArbUt::BorrowedPtr<ChoiceQueue>& queue, const Ar
|
||||||
EnsureNotNull(item)
|
EnsureNotNull(item)
|
||||||
Ensure(item->GetUser()->GetBattle().HasValue())
|
Ensure(item->GetUser()->GetBattle().HasValue())
|
||||||
Ensure(item->GetUser()->GetBattleSide().HasValue())
|
Ensure(item->GetUser()->GetBattleSide().HasValue())
|
||||||
auto index = (uint32_t)item->GetUser()->GetBattleSide().GetValue()->GetCreatureIndex(item->GetUser());
|
ExecuteChoice(item.get());
|
||||||
|
|
||||||
try_creature(ExecuteChoice(item.get()),
|
|
||||||
"Executing choice failed for choice by mon on side "
|
|
||||||
<< ((uint32_t)item->GetUser()->GetBattleSide().GetValue()->GetSideIndex()) << " and index "
|
|
||||||
<< index << ". Choice had choice kind "
|
|
||||||
<< CreatureLib::Battling::TurnChoiceKindHelper::ToString(item->GetKind()) << " "
|
|
||||||
<< " with message");
|
|
||||||
}
|
}
|
||||||
if (!battle->HasEnded()) {
|
if (!battle->HasEnded()) {
|
||||||
ArbUt::List<ScriptWrapper> scripts;
|
ArbUt::List<ScriptWrapper> scripts;
|
||||||
|
@ -250,7 +243,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during status attack effect handling: " << e.what() << ".");
|
THROW("Exception during status attack effect handling: ", e.what(), ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -282,7 +275,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during offensive attack secondary effect handling: " << e.what() << ".");
|
THROW("Exception during offensive attack secondary effect handling: ", e.what(), ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ void Battle::CheckChoicesSetAndRun() {
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during choices set validation: '" << e.what() << "'.")
|
THROW("Exception during choices set validation: '", e.what(), "'.")
|
||||||
}
|
}
|
||||||
|
|
||||||
auto begin = std::chrono::steady_clock::now();
|
auto begin = std::chrono::steady_clock::now();
|
||||||
|
@ -77,13 +77,13 @@ void Battle::CheckChoicesSetAndRun() {
|
||||||
side->ResetChoices();
|
side->ResetChoices();
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during turn initialization: '" << e.what() << "'.")
|
THROW("Exception during turn initialization: '", e.what(), "'.")
|
||||||
}
|
}
|
||||||
_currentTurn++;
|
_currentTurn++;
|
||||||
try {
|
try {
|
||||||
TurnOrdering::OrderChoices(choices);
|
TurnOrdering::OrderChoices(choices);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during turn ordering: '" << e.what() << "'.")
|
THROW("Exception during turn ordering: '", e.what(), "'.")
|
||||||
}
|
}
|
||||||
this->_currentTurnQueue = std::make_unique<ChoiceQueue>(choices);
|
this->_currentTurnQueue = std::make_unique<ChoiceQueue>(choices);
|
||||||
TriggerEventListener<TurnStartEvent>();
|
TriggerEventListener<TurnStartEvent>();
|
||||||
|
@ -92,7 +92,7 @@ void Battle::CheckChoicesSetAndRun() {
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Error during running a turn: '" << e.what() << "'.");
|
THROW("Error during running a turn: '", e.what(), "'.");
|
||||||
}
|
}
|
||||||
if (this->_currentTurnQueue->HasCompletedQueue) {
|
if (this->_currentTurnQueue->HasCompletedQueue) {
|
||||||
this->_currentTurnQueue = nullptr;
|
this->_currentTurnQueue = nullptr;
|
||||||
|
@ -169,7 +169,7 @@ BattleScript* Battle::AddVolatileScript(const ArbUt::StringView& key) {
|
||||||
}
|
}
|
||||||
script = _library->LoadScript(this, ScriptCategory::Battle, key);
|
script = _library->LoadScript(this, ScriptCategory::Battle, key);
|
||||||
if (!script.HasValue()) {
|
if (!script.HasValue()) {
|
||||||
THROW("Invalid volatile script requested for battle: '" << key.c_str() << "'.");
|
THROW("Invalid volatile script requested for battle: '", key.c_str(), "'.");
|
||||||
}
|
}
|
||||||
return _volatile.Add(script.GetValue());
|
return _volatile.Add(script.GetValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ bool BattleSide::AllPossibleSlotsFilled() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Exception during AllPossibleSlotsFilled check: '" << e.what() << "'.");
|
THROW("Exception during AllPossibleSlotsFilled check: '", e.what(), "'.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Error during setting choice: '" << e.what() << "'.");
|
THROW("Error during setting choice: '", e.what(), "'.");
|
||||||
}
|
}
|
||||||
THROW("User not found");
|
THROW("User not found");
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ BattleScript* BattleSide::AddVolatileScript(const ArbUt::StringView& key) {
|
||||||
}
|
}
|
||||||
script = _battle->GetLibrary()->LoadScript(this, ScriptCategory::Side, key);
|
script = _battle->GetLibrary()->LoadScript(this, ScriptCategory::Side, key);
|
||||||
if (!script.HasValue()) {
|
if (!script.HasValue()) {
|
||||||
THROW("Invalid volatile script requested for battleside: '" << key.c_str() << "'.");
|
THROW("Invalid volatile script requested for battleside: '", key.c_str(), "'.");
|
||||||
}
|
}
|
||||||
return _volatile.Add(script.GetValue());
|
return _volatile.Add(script.GetValue());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ Creature* CreateCreature::Create() {
|
||||||
if (!this->_heldItem.IsEmpty()) {
|
if (!this->_heldItem.IsEmpty()) {
|
||||||
auto val = _library->GetItemLibrary()->TryGet(this->_heldItem.GetHash());
|
auto val = _library->GetItemLibrary()->TryGet(this->_heldItem.GetHash());
|
||||||
if (!val.has_value()) {
|
if (!val.has_value()) {
|
||||||
THROW("Invalid held item '" << this->_heldItem.c_str() << "'.");
|
THROW("Invalid held item '", this->_heldItem.c_str(), "'.");
|
||||||
}
|
}
|
||||||
heldItem = val.value();
|
heldItem = val.value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,7 @@ namespace CreatureLib::Battling {
|
||||||
void Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
|
void Creature::SetHeldItem(const ArbUt::BasicStringView& itemName) {
|
||||||
auto v = _library->GetItemLibrary()->TryGet(itemName.GetHash());
|
auto v = _library->GetItemLibrary()->TryGet(itemName.GetHash());
|
||||||
if (!v.has_value()) {
|
if (!v.has_value()) {
|
||||||
THROW("Item not found '" << itemName.c_str() << "'.");
|
THROW("Item not found '", itemName.c_str(), "'.");
|
||||||
}
|
}
|
||||||
_heldItem = v.value();
|
_heldItem = v.value();
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
script = this->_library->LoadScript(this, ScriptCategory::Creature, name);
|
script = this->_library->LoadScript(this, ScriptCategory::Creature, name);
|
||||||
if (!script.HasValue()) {
|
if (!script.HasValue()) {
|
||||||
THROW("Invalid volatile script requested for creature: '" << name.c_str() << "'.");
|
THROW("Invalid volatile script requested for creature: '", name.c_str(), "'.");
|
||||||
}
|
}
|
||||||
return _volatile.Add(script.GetValue());
|
return _volatile.Add(script.GetValue());
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ namespace CreatureLib::Battling {
|
||||||
if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) {
|
if (_attacks.Count() < _library->GetStaticLib()->GetSettings()->GetMaximalAttacks()) {
|
||||||
_attacks.Append(attack);
|
_attacks.Append(attack);
|
||||||
}
|
}
|
||||||
THROW("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);
|
_attacks.Set(index, attack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
try { \
|
try { \
|
||||||
next->hookName(__VA_ARGS__); \
|
next->hookName(__VA_ARGS__); \
|
||||||
} catch (const std::exception& e) { \
|
} catch (const std::exception& e) { \
|
||||||
THROW("Exception running script hook '" #hookName "': " << e.what()) \
|
THROW("Exception running script hook '" #hookName "': ", e.what()) \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} catch (const ArbUt::Exception& e) { \
|
} catch (const ArbUt::Exception& e) { \
|
||||||
throw e; \
|
throw e; \
|
||||||
} catch (const std::exception& e) { \
|
} catch (const std::exception& e) { \
|
||||||
THROW("Exception setting up script hook '" #hookName "': " << e.what()) \
|
THROW("Exception setting up script hook '" #hookName "': ", e.what()) \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,6 @@
|
||||||
} catch (const ArbUt::Exception& e) { \
|
} catch (const ArbUt::Exception& e) { \
|
||||||
throw e; \
|
throw e; \
|
||||||
} catch (const std::exception& e) { \
|
} catch (const std::exception& e) { \
|
||||||
THROW("Exception setting up script hook '" #hookName "': " << e.what()) \
|
THROW("Exception setting up script hook '" #hookName "': ", e.what()) \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace CreatureLib::Library {
|
||||||
inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); }
|
inline bool HasAttacksForLevel(level_int_t level) const noexcept { return _learnedByLevel.Has(level); }
|
||||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const {
|
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(level_int_t level) const {
|
||||||
if (!_learnedByLevel.Has(level)) {
|
if (!_learnedByLevel.Has(level)) {
|
||||||
THROW("No attacks found for level " << (uint32_t)level << ".");
|
THROW("No attacks found for level ", (uint32_t)level, ".");
|
||||||
}
|
}
|
||||||
return _learnedByLevel.Get(level);
|
return _learnedByLevel.Get(level);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace CreatureLib::Library {
|
||||||
inline EffectParameterType GetType() const noexcept { return _type; }
|
inline EffectParameterType GetType() const noexcept { return _type; }
|
||||||
bool AsBool() const {
|
bool AsBool() const {
|
||||||
if (_type != EffectParameterType::Bool) {
|
if (_type != EffectParameterType::Bool) {
|
||||||
THROW("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type));
|
THROW("Cast effect parameter to bool, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||||
}
|
}
|
||||||
return std::get<bool>(_value);
|
return std::get<bool>(_value);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace CreatureLib::Library {
|
||||||
if (_type == EffectParameterType::Float) {
|
if (_type == EffectParameterType::Float) {
|
||||||
return static_cast<int64_t>(std::get<float>(_value));
|
return static_cast<int64_t>(std::get<float>(_value));
|
||||||
}
|
}
|
||||||
THROW("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type));
|
THROW("Cast effect parameter to int, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||||
}
|
}
|
||||||
return std::get<int64_t>(_value);
|
return std::get<int64_t>(_value);
|
||||||
}
|
}
|
||||||
|
@ -44,13 +44,13 @@ namespace CreatureLib::Library {
|
||||||
if (_type == EffectParameterType::Int) {
|
if (_type == EffectParameterType::Int) {
|
||||||
return static_cast<float>(std::get<int64_t>(_value));
|
return static_cast<float>(std::get<int64_t>(_value));
|
||||||
}
|
}
|
||||||
THROW("Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type));
|
THROW("Cast effect parameter to float, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||||
}
|
}
|
||||||
return std::get<float>(_value);
|
return std::get<float>(_value);
|
||||||
}
|
}
|
||||||
const ArbUt::StringView& AsString() const {
|
const ArbUt::StringView& AsString() const {
|
||||||
if (_type != EffectParameterType::String) {
|
if (_type != EffectParameterType::String) {
|
||||||
THROW("Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type));
|
THROW("Cast effect parameter to string, but was ", EffectParameterTypeHelper::ToString(_type));
|
||||||
}
|
}
|
||||||
return std::get<ArbUt::StringView>(_value);
|
return std::get<ArbUt::StringView>(_value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
} catch (const ArbUt::Exception& e) { \
|
} catch (const ArbUt::Exception& e) { \
|
||||||
throw e; \
|
throw e; \
|
||||||
} catch (const std::exception& e) { \
|
} catch (const std::exception& e) { \
|
||||||
THROW(msg << ": '" << e.what() << "'."); \
|
THROW(msg, ": '", e.what(), "'."); \
|
||||||
}
|
}
|
||||||
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
#endif // CREATURELIB_CREATUREEXCEPTION_HPP
|
||||||
|
|
|
@ -20,5 +20,5 @@ const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const {
|
||||||
return kv.first;
|
return kv.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
THROW("Name requested for unknown type: " << (uint32_t)type);
|
THROW("Name requested for unknown type: ", (uint32_t)type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace CreatureLib::Library {
|
||||||
try {
|
try {
|
||||||
return _effectiveness[attacking][defensive];
|
return _effectiveness[attacking][defensive];
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
THROW("Unknown type indices were requested for effectiveness: " << (uint32_t)attacking << " and "
|
THROW("Unknown type indices were requested for effectiveness: ", (uint32_t)attacking, " and ",
|
||||||
<< (uint32_t)defensive);
|
(uint32_t)defensive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking, const std::vector<u8>& defensive) const {
|
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking, const std::vector<u8>& defensive) const {
|
||||||
|
|
|
@ -10,7 +10,7 @@ TEST_CASE("When throwing exception, what() is readable") {
|
||||||
} catch (const ArbUt::Exception& e) {
|
} catch (const ArbUt::Exception& e) {
|
||||||
hasCaught = true;
|
hasCaught = true;
|
||||||
INFO(e.what());
|
INFO(e.what());
|
||||||
REQUIRE(std::string(e.what()) == "[ExceptionTests.cpp:9] foobar");
|
REQUIRE(std::string(e.what()) == "[ExceptionTests.cpp:9] \"foobar\"");
|
||||||
}
|
}
|
||||||
REQUIRE(hasCaught);
|
REQUIRE(hasCaught);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue