More work on exceptions.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-07-31 14:17:38 +02:00
parent 9c93ca6995
commit bd7ecb6b33
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 18 additions and 4 deletions

View File

@ -155,7 +155,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
break;
}
auto& hit = hitIterator[hitIndex];
uint8_t hitType = hit.GetType();
uint8_t hitType = attack->GetAttack()->GetAttack()->GetType();
HOOK(ChangeAttackType, targetSource, attack, target.GetRaw(), hitIndex, &hitType);
hit.SetType(hitType);
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());

View File

@ -5,7 +5,11 @@
auto next = aggregator.GetNext(); \
if (next == nullptr) \
continue; \
next->hookName(__VA_ARGS__); \
try { \
next->hookName(__VA_ARGS__); \
} catch (const std::exception& e) { \
THROW_CREATURE("Exception running script hook '" #hookName "': " << e.what()) \
} \
} \
}
@ -16,6 +20,10 @@
auto next = aggregator.GetNext(); \
if (next == nullptr) \
continue; \
next->hookName(__VA_ARGS__); \
try { \
next->hookName(__VA_ARGS__); \
} catch (const std::exception& e) { \
THROW_CREATURE("Exception running script hook '" #hookName "': " << e.what()) \
} \
} \
}

View File

@ -7,6 +7,7 @@
#include <numeric>
#include <unordered_set>
#include <vector>
#include "Exceptions/CreatureException.hpp"
namespace CreatureLib::Library {
class TypeLibrary {
@ -19,7 +20,12 @@ namespace CreatureLib::Library {
inline uint8_t GetTypeId(const ArbUt::BasicStringView& key) const { return _types.Get(key); }
inline uint8_t GetTypeId(uint32_t s) const { return _types.Get(s); }
[[nodiscard]] inline float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const {
return _effectiveness[attacking][defensive];
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);
}
}
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking,
const std::unordered_set<uint8_t>& defensive) const {