From e89d2a9e0cc5017625742acd08ead085bf779747 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 10 Apr 2020 16:35:24 +0200 Subject: [PATCH] Adds secondary effect parameter system. --- .clang-format | 1 + CInterface/Library/AttackData.cpp | 22 ++++++++++++++++------ src/Library/Attacks/SecondaryEffect.hpp | 11 +++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.clang-format b/.clang-format index 965124f..7d012b8 100644 --- a/.clang-format +++ b/.clang-format @@ -118,6 +118,7 @@ StatementMacros: - QT_REQUIRE_VERSION - Assert - AssertNotNull + - Try TabWidth: 8 UseTab: Never ... diff --git a/CInterface/Library/AttackData.cpp b/CInterface/Library/AttackData.cpp index fba717e..f83ba6a 100644 --- a/CInterface/Library/AttackData.cpp +++ b/CInterface/Library/AttackData.cpp @@ -5,14 +5,24 @@ using namespace CreatureLib::Library; export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy, uint8_t baseUsage, AttackTarget target, int8_t priority, - float effectChance, const char* effectName, const char* flags[], - size_t flagsCount) { - Try(std::unordered_set conversedFlags(flagsCount); for (size_t i = 0; i < flagsCount; i++) { - conversedFlags.insert(ConstString::GetHash(flags[i])); - } auto effect = SecondaryEffect(effectChance, Arbutils::CaseInsensitiveConstString(effectName)); + float effectChance, const char* effectName, void* effectParameters[], + size_t effectParameterCount, const char* flags[], size_t flagsCount) { + Try({ + std::unordered_set conversedFlags(flagsCount); + for (size_t i = 0; i < flagsCount; i++) { + conversedFlags.insert(ConstString::GetHash(flags[i])); + } + Arbutils::Collections::List effectParameterList(effectParameterCount); + for (size_t i = 0; i < effectParameterCount; i++) { + effectParameterList[i] = effectParameters[i]; + } + + auto effect = + SecondaryEffect(effectChance, Arbutils::CaseInsensitiveConstString(effectName), effectParameterList); out = new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority, effect, - conversedFlags);) + conversedFlags); + }) }; export void CreatureLib_AttackData_Destruct(const AttackData* p) { delete p; } diff --git a/src/Library/Attacks/SecondaryEffect.hpp b/src/Library/Attacks/SecondaryEffect.hpp index 94c9754..44bbf28 100644 --- a/src/Library/Attacks/SecondaryEffect.hpp +++ b/src/Library/Attacks/SecondaryEffect.hpp @@ -1,20 +1,27 @@ #ifndef CREATURELIB_SECONDARYEFFECT_HPP #define CREATURELIB_SECONDARYEFFECT_HPP +#include #include +#include + +using namespace Arbutils::Collections; namespace CreatureLib::Library { class SecondaryEffect { private: float _chance; Arbutils::CaseInsensitiveConstString _effectName; + List _parameters; public: SecondaryEffect() noexcept : _chance(0), _effectName(Arbutils::CaseInsensitiveConstString("")) {} - SecondaryEffect(float chance, const Arbutils::CaseInsensitiveConstString& effectName) noexcept - : _chance(chance), _effectName(effectName) {} + SecondaryEffect(float chance, const Arbutils::CaseInsensitiveConstString& effectName, + const List& parameters) noexcept + : _chance(chance), _effectName(effectName), _parameters(parameters) {} constexpr float GetChance() const noexcept { return _chance; } constexpr const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; } + const List& GetParameters() const noexcept { return _parameters; } }; }