diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..2c6fbf1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,121 @@ +# ClangFormatConfigureSource: 'LLVM' +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Merge +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 1 + - Regex: '.*' + Priority: 3 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +... diff --git a/src/Battling/Flow/ChoiceQueue.hpp b/src/Battling/Flow/ChoiceQueue.hpp index 475f4ae..78523a9 100644 --- a/src/Battling/Flow/ChoiceQueue.hpp +++ b/src/Battling/Flow/ChoiceQueue.hpp @@ -5,31 +5,26 @@ #include #include "../TurnChoices/BaseTurnChoice.hpp" -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { class ChoiceQueue { std::vector _queue; size_t _current = 0; + public: bool HasCompletedQueue = false; - explicit ChoiceQueue(std::vector queue) - :_queue(std::move(queue)){} + explicit ChoiceQueue(std::vector queue) : _queue(std::move(queue)) {} - BaseTurnChoice* Dequeue(){ + BaseTurnChoice* Dequeue() { auto b = _queue[_current]; _current++; return b; } - [[nodiscard]] bool HasNext() const{ - return _current < _queue.size(); - } + [[nodiscard]] bool HasNext() const { return _current < _queue.size(); } - std::vector& GetInnerQueue(){ - return _queue; - } + std::vector& GetInnerQueue() { return _queue; } }; } - -#endif //CREATURELIB_CHOICEQUEUE_HPP +#endif // CREATURELIB_CHOICEQUEUE_HPP diff --git a/src/Battling/Flow/TurnHandler.cpp b/src/Battling/Flow/TurnHandler.cpp index 0913a42..adbf909 100644 --- a/src/Battling/Flow/TurnHandler.cpp +++ b/src/Battling/Flow/TurnHandler.cpp @@ -1,16 +1,16 @@ #include "TurnHandler.hpp" -#include "../Models/Battle.hpp" #include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../Models/Battle.hpp" #include "../ScriptHandling/ScriptMacros.cpp" using namespace CreatureLib::Battling; void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) { - for (auto choice: queue->GetInnerQueue()){ + for (auto choice : queue->GetInnerQueue()) { HOOK(OnBeforeTurn, choice, choice); } - while (queue->HasNext()){ - if (!battle->HasRecalledSlots()){ + while (queue->HasNext()) { + if (!battle->HasRecalledSlots()) { return; } auto item = queue->Dequeue(); @@ -20,9 +20,8 @@ void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) { queue->HasCompletedQueue = true; } -void TurnHandler::ExecuteChoice(BaseTurnChoice *choice) { - if (choice == nullptr) - { +void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) { + if (choice == nullptr) { return; } auto choiceKind = choice->GetKind(); @@ -31,35 +30,33 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice *choice) { } auto user = choice->GetUser(); // If the user is fainted, we don't want to execute its choice. - if (user->IsFainted()){ + if (user->IsFainted()) { return; } auto battle = user->GetBattle(); // If the user is not in the field, we don't want to execute its choice. - if (!battle->CreatureInField(user)){ + if (!battle->CreatureInField(user)) { return; } // If the choice is not valid, we don't want to execute it. - if (!battle->CanUse(choice)){ + if (!battle->CanUse(choice)) { return; } - switch (choiceKind){ + switch (choiceKind) { case TurnChoiceKind::Pass: throw NotReachableException(); - case TurnChoiceKind::Attack: - return ExecuteAttackChoice(dynamic_cast(choice)); + case TurnChoiceKind::Attack: return ExecuteAttackChoice(dynamic_cast(choice)); case TurnChoiceKind::Item: case TurnChoiceKind::Switch: - case TurnChoiceKind::RunAway: - throw NotImplementedException(); + case TurnChoiceKind::RunAway: throw NotImplementedException(); } } -void TurnHandler::ExecuteAttackChoice(AttackTurnChoice *choice) { +void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) { auto attackName = choice->GetAttack()->GetAttack()->GetName(); HOOK(ChangeAttack, choice, choice, attackName); - if (attackName != choice->GetAttack()->GetAttack()->GetName()){ - //TODO: Change attack + if (attackName != choice->GetAttack()->GetAttack()->GetName()) { + // TODO: Change attack } // FIXME: Resolve all targets @@ -69,56 +66,57 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice *choice) { auto attack = new ExecutingAttack(targets, 1, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript()); bool prevented = false; HOOK(PreventAttack, attack, attack, prevented); - if (prevented){ + if (prevented) { return; } - //HOOK: override targets + // HOOK: override targets - if (!choice->GetAttack()->TryUse(1)){ + if (!choice->GetAttack()->TryUse(1)) { return; } - //HOOK: check if attack fails + // HOOK: check if attack fails bool fail = false; HOOK(FailAttack, attack, attack, fail); - if (fail){ - //TODO: Fail handling. + if (fail) { + // TODO: Fail handling. return; } HOOK(StopBeforeAttack, attack, attack); HOOK(OnBeforeAttack, attack, attack); - for (auto& kv: attack->GetTargets()){ + for (auto& kv : attack->GetTargets()) { HandleAttackForTarget(attack, kv.first, kv.second); } - //TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up. + // TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up. delete attack; } -void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *target, const ExecutingAttack::TargetData &targetData) { +void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target, + const ExecutingAttack::TargetData& targetData) { auto user = attack->GetUser(); - ScriptSource* targetSource = target; - ScriptSource* userSource = attack; + ScriptSource* targetSource = target; + ScriptSource* userSource = attack; bool fail = false; HOOK(FailIncomingAttack, targetSource, attack, target, fail); - if (fail){ - //TODO: Fail handling. + if (fail) { + // TODO: Fail handling. return; } bool invulnerable = fail; HOOK(IsInvulnerable, targetSource, attack, target, invulnerable); - if (invulnerable){ - //TODO: We should probably do something when a target is invulnerable. + if (invulnerable) { + // TODO: We should probably do something when a target is invulnerable. return; } - if (!targetData.IsHit()){ + if (!targetData.IsHit()) { HOOK(OnAttackMiss, targetSource, attack, target); return; } @@ -129,11 +127,11 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *targe auto attackData = attack->GetAttack()->GetAttack(); auto library = user->GetBattle()->GetLibrary(); auto dmgLibrary = library->GetDamageLibrary(); - for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++){ - if (user->IsFainted()){ + for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++) { + if (user->IsFainted()) { break; } - if (target->IsFainted()){ + if (target->IsFainted()) { // STOP, STOP! HE'S ALREADY DEAD ;_; break; } @@ -146,28 +144,27 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *targe hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex)); hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex)); - if (attackData->GetCategory() == Library::AttackCategory::Status){ + if (attackData->GetCategory() == Library::AttackCategory::Status) { HOOK(OnStatusMove, userSource, attack, target, hitIndex); - } - else{ + } else { auto damage = hit.GetDamage(); - if (damage > target->GetCurrentHealth()){ + if (damage > target->GetCurrentHealth()) { damage = target->GetCurrentHealth(); hit.SetDamage(damage); } - if (damage > 0){ + if (damage > 0) { target->Damage(damage, DamageSource::AttackDamage); bool preventSecondary = false; HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, preventSecondary); - if (!preventSecondary){ + if (!preventSecondary) { HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex); } } } } - if (!user->IsFainted()){ + if (!user->IsFainted()) { HOOK(OnAfterHits, userSource, attack, target); } } diff --git a/src/Battling/Flow/TurnHandler.hpp b/src/Battling/Flow/TurnHandler.hpp index 0ebd5b8..0e1be29 100644 --- a/src/Battling/Flow/TurnHandler.hpp +++ b/src/Battling/Flow/TurnHandler.hpp @@ -1,9 +1,9 @@ #ifndef CREATURELIB_TURNHANDLER_HPP #define CREATURELIB_TURNHANDLER_HPP -#include "ChoiceQueue.hpp" -#include "../TurnChoices/AttackTurnChoice.hpp" #include "../Models/ExecutingAttack.hpp" +#include "../TurnChoices/AttackTurnChoice.hpp" +#include "ChoiceQueue.hpp" namespace CreatureLib::Battling { class Battle; @@ -12,10 +12,12 @@ namespace CreatureLib::Battling { static void ExecuteChoice(BaseTurnChoice* choice); static void ExecuteAttackChoice(AttackTurnChoice* choice); - static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target, const ExecutingAttack::TargetData& targetData); + static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target, + const ExecutingAttack::TargetData& targetData); + public: static void RunTurn(Battle* battle, ChoiceQueue* queue); }; } -#endif //CREATURELIB_TURNHANDLER_HPP +#endif // CREATURELIB_TURNHANDLER_HPP diff --git a/src/Battling/Flow/TurnOrdering.cpp b/src/Battling/Flow/TurnOrdering.cpp index 75cc559..5f2c296 100644 --- a/src/Battling/Flow/TurnOrdering.cpp +++ b/src/Battling/Flow/TurnOrdering.cpp @@ -1,18 +1,17 @@ #include "TurnOrdering.hpp" -#include "../TurnChoices/AttackTurnChoice.hpp" -#include "../Models/Battle.hpp" - #include +#include "../Models/Battle.hpp" +#include "../TurnChoices/AttackTurnChoice.hpp" using namespace CreatureLib; using namespace Battling; -bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::Random& rand){ +bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core::Random& rand) { auto aKind = a->GetKind(); auto bKind = b->GetKind(); if (aKind != bKind) return aKind > bKind; - if (aKind == TurnChoiceKind::Attack){ + if (aKind == TurnChoiceKind::Attack) { auto aPriority = dynamic_cast(a)->GetPriority(); auto bPriority = dynamic_cast(b)->GetPriority(); if (aPriority != bPriority) @@ -27,9 +26,9 @@ bool ___ChoiceOrderFunc(const BaseTurnChoice* a, const BaseTurnChoice* b, Core:: return randomValue == 0; } -void TurnOrdering::OrderChoices(std::vector &vec, Core::Random& rand) { - auto comp = [&](const BaseTurnChoice * a,const BaseTurnChoice * b)-> bool { - return ___ChoiceOrderFunc(a,b,rand); +void TurnOrdering::OrderChoices(std::vector& vec, Core::Random& rand) { + auto comp = [&](const BaseTurnChoice* a, const BaseTurnChoice* b) -> bool { + return ___ChoiceOrderFunc(a, b, rand); }; std::sort(vec.begin(), vec.end(), comp); } diff --git a/src/Battling/Flow/TurnOrdering.hpp b/src/Battling/Flow/TurnOrdering.hpp index b84c452..45c221a 100644 --- a/src/Battling/Flow/TurnOrdering.hpp +++ b/src/Battling/Flow/TurnOrdering.hpp @@ -1,9 +1,9 @@ #ifndef CREATURELIB_TURNORDERING_HPP #define CREATURELIB_TURNORDERING_HPP -#include "../TurnChoices/BaseTurnChoice.hpp" -#include "../../Core/Random.hpp" #include +#include "../../Core/Random.hpp" +#include "../TurnChoices/BaseTurnChoice.hpp" namespace CreatureLib::Battling { class TurnOrdering { @@ -12,4 +12,4 @@ namespace CreatureLib::Battling { }; } -#endif //CREATURELIB_TURNORDERING_HPP +#endif // CREATURELIB_TURNORDERING_HPP diff --git a/src/Battling/Library/BattleLibrary.cpp b/src/Battling/Library/BattleLibrary.cpp index 6e5b083..92fea55 100644 --- a/src/Battling/Library/BattleLibrary.cpp +++ b/src/Battling/Library/BattleLibrary.cpp @@ -1,16 +1,13 @@ -#include #include "BattleLibrary.hpp" +#include using namespace CreatureLib::Battling; -BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary *staticLib, - BattleStatCalculator *statCalculator, - DamageLibrary* damageLibrary, - CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver) - : _staticLib(staticLib), _statCalculator(statCalculator), - _damageLibrary(damageLibrary), _criticalLibrary(criticalLibrary), - _scriptResolver(scriptResolver) - {} +BattleLibrary::BattleLibrary(CreatureLib::Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, + DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary, + ScriptResolver* scriptResolver) + : _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary), + _criticalLibrary(criticalLibrary), _scriptResolver(scriptResolver) {} BattleLibrary::~BattleLibrary() { delete _staticLib; @@ -20,40 +17,27 @@ BattleLibrary::~BattleLibrary() { delete _scriptResolver; } -const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const { - return _staticLib->GetSettings(); -} +const CreatureLib::Library::LibrarySettings& BattleLibrary::GetSettings() const { return _staticLib->GetSettings(); } -const BattleStatCalculator *BattleLibrary::GetStatCalculator() const { - return _statCalculator; -} +const BattleStatCalculator* BattleLibrary::GetStatCalculator() const { return _statCalculator; } const CreatureLib::Library::SpeciesLibrary* BattleLibrary::GetSpeciesLibrary() const { return _staticLib->GetSpeciesLibrary(); } -const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const { - return _staticLib->GetItemLibrary(); -} +const CreatureLib::Library::ItemLibrary* BattleLibrary::GetItemLibrary() const { return _staticLib->GetItemLibrary(); } -const CreatureLib::Library::AttackLibrary *BattleLibrary::GetAttackLibrary() const { +const CreatureLib::Library::AttackLibrary* BattleLibrary::GetAttackLibrary() const { return _staticLib->GetAttackLibrary(); } -const CreatureLib::Library::TypeLibrary *BattleLibrary::GetTypeLibrary() const { - return _staticLib->GetTypeLibrary(); -} +const CreatureLib::Library::TypeLibrary* BattleLibrary::GetTypeLibrary() const { return _staticLib->GetTypeLibrary(); } -const DamageLibrary *BattleLibrary::GetDamageLibrary() const { - return _damageLibrary; -} +const DamageLibrary* BattleLibrary::GetDamageLibrary() const { return _damageLibrary; } -const CriticalLibrary *BattleLibrary::GetCriticalLibrary() const { - return _criticalLibrary; -} +const CriticalLibrary* BattleLibrary::GetCriticalLibrary() const { return _criticalLibrary; } -Script* BattleLibrary::LoadScript(ScriptResolver::ScriptCategory category, const std::string &scriptName) { +Script* BattleLibrary::LoadScript(ScriptResolver::ScriptCategory category, const std::string& scriptName) { assert(this->_scriptResolver != nullptr); return _scriptResolver->LoadScript(category, scriptName); } - diff --git a/src/Battling/Library/BattleLibrary.hpp b/src/Battling/Library/BattleLibrary.hpp index 21ff797..8e6b1bb 100644 --- a/src/Battling/Library/BattleLibrary.hpp +++ b/src/Battling/Library/BattleLibrary.hpp @@ -1,11 +1,11 @@ #ifndef CREATURELIB_BATTLELIBRARY_HPP #define CREATURELIB_BATTLELIBRARY_HPP -#include "BattleStatCalculator.hpp" #include "../../Library/DataLibrary.hpp" -#include "DamageLibrary.hpp" -#include "CriticalLibrary.hpp" #include "../ScriptHandling/ScriptResolver.hpp" +#include "BattleStatCalculator.hpp" +#include "CriticalLibrary.hpp" +#include "DamageLibrary.hpp" namespace CreatureLib::Battling { class BattleLibrary { @@ -14,9 +14,10 @@ namespace CreatureLib::Battling { DamageLibrary* _damageLibrary; CriticalLibrary* _criticalLibrary; ScriptResolver* _scriptResolver; + public: - BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, DamageLibrary* damageLibrary, - CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver); + BattleLibrary(Library::DataLibrary* staticLib, BattleStatCalculator* statCalculator, + DamageLibrary* damageLibrary, CriticalLibrary* criticalLibrary, ScriptResolver* scriptResolver); ~BattleLibrary(); [[nodiscard]] const Library::LibrarySettings& GetSettings() const; @@ -33,4 +34,4 @@ namespace CreatureLib::Battling { }; } -#endif //CREATURELIB_BATTLELIBRARY_HPP +#endif // CREATURELIB_BATTLELIBRARY_HPP diff --git a/src/Battling/Library/BattleStatCalculator.cpp b/src/Battling/Library/BattleStatCalculator.cpp index 2a6a866..57456c6 100644 --- a/src/Battling/Library/BattleStatCalculator.cpp +++ b/src/Battling/Library/BattleStatCalculator.cpp @@ -1,54 +1,49 @@ #include "BattleStatCalculator.hpp" -#include "../Models/Creature.hpp" #include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../Models/Creature.hpp" using namespace CreatureLib; -Core::StatisticSet -Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature *creature) const { - return Core::StatisticSet( - CalculateFlatStat(creature, Core::Statistic::Health), - CalculateFlatStat(creature, Core::Statistic::PhysicalAttack), - CalculateFlatStat(creature, Core::Statistic::PhysicalDefense), - CalculateFlatStat(creature, Core::Statistic::MagicalAttack), - CalculateFlatStat(creature, Core::Statistic::MagicalDefense), - CalculateFlatStat(creature, Core::Statistic::Speed) - ); +Core::StatisticSet Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const { + return Core::StatisticSet(CalculateFlatStat(creature, Core::Statistic::Health), + CalculateFlatStat(creature, Core::Statistic::PhysicalAttack), + CalculateFlatStat(creature, Core::Statistic::PhysicalDefense), + CalculateFlatStat(creature, Core::Statistic::MagicalAttack), + CalculateFlatStat(creature, Core::Statistic::MagicalDefense), + CalculateFlatStat(creature, Core::Statistic::Speed)); } -Core::StatisticSet -Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature *creature) const { -return Core::StatisticSet( - CalculateBoostedStat(creature, Core::Statistic::Health), - CalculateBoostedStat(creature, Core::Statistic::PhysicalAttack), - CalculateBoostedStat(creature, Core::Statistic::PhysicalDefense), - CalculateBoostedStat(creature, Core::Statistic::MagicalAttack), - CalculateBoostedStat(creature, Core::Statistic::MagicalDefense), - CalculateBoostedStat(creature, Core::Statistic::Speed) -); +Core::StatisticSet Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const { + return Core::StatisticSet(CalculateBoostedStat(creature, Core::Statistic::Health), + CalculateBoostedStat(creature, Core::Statistic::PhysicalAttack), + CalculateBoostedStat(creature, Core::Statistic::PhysicalDefense), + CalculateBoostedStat(creature, Core::Statistic::MagicalAttack), + CalculateBoostedStat(creature, Core::Statistic::MagicalDefense), + CalculateBoostedStat(creature, Core::Statistic::Speed)); } -uint32_t CalculateHealthStat(Battling::Creature *creature){ +uint32_t CalculateHealthStat(Battling::Creature* creature) { auto level = creature->GetLevel(); - auto a = (creature->GetBaseStat(Core::Statistic::Health) + creature->GetStatPotential(Core::Statistic::Health)) * 2 + - floor(sqrt(creature->GetStatExperience(Core::Statistic::Health) / 4)) * level; + auto a = + (creature->GetBaseStat(Core::Statistic::Health) + creature->GetStatPotential(Core::Statistic::Health)) * 2 + + floor(sqrt(creature->GetStatExperience(Core::Statistic::Health) / 4)) * level; return floor(a / 100) + level + 10; } -uint32_t CalculateOtherStat(Battling::Creature *creature, Core::Statistic stat){ +uint32_t CalculateOtherStat(Battling::Creature* creature, Core::Statistic stat) { auto level = creature->GetLevel(); auto a = (creature->GetBaseStat(stat) + creature->GetStatPotential(stat)) * 2 + floor(sqrt(creature->GetStatExperience(stat) / 4)) * level; return floor(a / 100) + 10; } - -uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature *creature, Core::Statistic stat) const{ +uint32_t Battling::BattleStatCalculator::CalculateFlatStat(Battling::Creature* creature, Core::Statistic stat) const { if (stat == Core::Statistic::Health) return CalculateHealthStat(creature); return CalculateOtherStat(creature, stat); } -uint32_t Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature *creature, Core::Statistic stat) const{ +uint32_t Battling::BattleStatCalculator::CalculateBoostedStat(Battling::Creature* creature, + Core::Statistic stat) const { throw NotImplementedException(); } diff --git a/src/Battling/Library/BattleStatCalculator.hpp b/src/Battling/Library/BattleStatCalculator.hpp index 6b1ae01..01513b0 100644 --- a/src/Battling/Library/BattleStatCalculator.hpp +++ b/src/Battling/Library/BattleStatCalculator.hpp @@ -4,18 +4,18 @@ #include "../../Core/StatisticSet.hpp" namespace CreatureLib::Battling { - //predeclare BattleCreature class + // predeclare BattleCreature class class Creature; class BattleStatCalculator { public: virtual ~BattleStatCalculator() = default; - virtual Core::StatisticSet CalculateFlatStats(Creature* creature) const; - virtual Core::StatisticSet CalculateBoostedStats(Creature* creature) const; + virtual Core::StatisticSet CalculateFlatStats(Creature* creature) const; + virtual Core::StatisticSet CalculateBoostedStats(Creature* creature) const; virtual uint32_t CalculateFlatStat(Creature* creature, Core::Statistic stat) const; virtual uint32_t CalculateBoostedStat(Creature* creature, Core::Statistic stat) const; }; } -#endif //CREATURELIB_BATTLESTATCALCULATOR_HPP +#endif // CREATURELIB_BATTLESTATCALCULATOR_HPP diff --git a/src/Battling/Library/CriticalLibrary.cpp b/src/Battling/Library/CriticalLibrary.cpp index eb82f13..706bed5 100644 --- a/src/Battling/Library/CriticalLibrary.cpp +++ b/src/Battling/Library/CriticalLibrary.cpp @@ -1,9 +1,9 @@ #include "CriticalLibrary.hpp" #include "../Models/Battle.hpp" -bool CreatureLib::Battling::CriticalLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack *attack, - CreatureLib::Battling::Creature *target, uint8_t hit) const { +bool CreatureLib::Battling::CriticalLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack, + CreatureLib::Battling::Creature* target, uint8_t hit) const { auto rand = target->GetBattle()->GetRandom(); - //HOOK: Increase chance for critical hits. + // HOOK: Increase chance for critical hits. return rand.Get(10) <= 0; } diff --git a/src/Battling/Library/CriticalLibrary.hpp b/src/Battling/Library/CriticalLibrary.hpp index 125455f..ac91559 100644 --- a/src/Battling/Library/CriticalLibrary.hpp +++ b/src/Battling/Library/CriticalLibrary.hpp @@ -11,5 +11,4 @@ namespace CreatureLib::Battling { }; } - -#endif //CREATURELIB_CRITICALLIBRARY_HPP +#endif // CREATURELIB_CRITICALLIBRARY_HPP diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index c685027..6e50fbc 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -1,66 +1,64 @@ #include "DamageLibrary.hpp" using namespace CreatureLib::Battling; -int DamageLibrary::GetDamage(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{ +int DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { auto levelMod = static_cast(2 * attack->GetUser()->GetLevel()); auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); auto bp = hit.GetBasePower(); auto statMod = GetStatModifier(attack, target, hitIndex); - //HOOK: Modify stat modifier - int damage = static_cast((((levelMod * static_cast(bp) * statMod) / 50) + 2) - * GetDamageModifier(attack, target, hitIndex)); - //HOOK: Override damage + // HOOK: Modify stat modifier + int damage = static_cast((((levelMod * static_cast(bp) * statMod) / 50) + 2) * + GetDamageModifier(attack, target, hitIndex)); + // HOOK: Override damage return damage; } -int DamageLibrary::GetBasePower(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{ +int DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { auto bp = attack->GetAttack()->GetAttack()->GetBasePower(); - //HOOK: modify base power. + // HOOK: modify base power. return bp; } -float DamageLibrary::GetStatModifier(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{ +float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { auto user = attack->GetUser(); - //HOOK: allow overriding for which users stat we use. + // HOOK: allow overriding for which users stat we use. auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); Core::Statistic offensiveStat; Core::Statistic defensiveStat; - if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical){ + if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) { offensiveStat = Core::Statistic::PhysicalAttack; defensiveStat = Core::Statistic::PhysicalDefense; - } - else{ + } else { offensiveStat = Core::Statistic::MagicalAttack; defensiveStat = Core::Statistic::MagicalDefense; } auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0; - //HOOK: allow bypassing defensive stat modifiers. + // HOOK: allow bypassing defensive stat modifiers. auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0; - //HOOK: Allow bypassing offensive stat modifiers. + // HOOK: Allow bypassing offensive stat modifiers. float offensiveValue; float defensiveValue; - if (bypassOffensive){ + if (bypassOffensive) { offensiveValue = user->GetFlatStat(offensiveStat); - } else{ + } else { offensiveValue = user->GetBoostedStat(offensiveStat); } - if (bypassDefensive){ + if (bypassDefensive) { defensiveValue = target->GetFlatStat(defensiveStat); - } else{ + } else { defensiveValue = target->GetBoostedStat(defensiveStat); } return offensiveValue / defensiveValue; } -float DamageLibrary::GetDamageModifier(ExecutingAttack *attack, Creature *target, uint8_t hitIndex) const{ +float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const { float mod = 1; auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex); mod *= hit.GetEffectiveness(); - //HOOK: Modify damage modifier. + // HOOK: Modify damage modifier. return mod; } - diff --git a/src/Battling/Library/DamageLibrary.hpp b/src/Battling/Library/DamageLibrary.hpp index 999b9d7..ae52e31 100644 --- a/src/Battling/Library/DamageLibrary.hpp +++ b/src/Battling/Library/DamageLibrary.hpp @@ -4,7 +4,7 @@ #include "../Models/Creature.hpp" #include "../Models/ExecutingAttack.hpp" -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { class DamageLibrary { public: virtual ~DamageLibrary() = default; @@ -16,5 +16,4 @@ namespace CreatureLib::Battling{ }; } - -#endif //CREATURELIB_DAMAGELIBRARY_HPP +#endif // CREATURELIB_DAMAGELIBRARY_HPP diff --git a/src/Battling/Models/AttackLearnMethod.hpp b/src/Battling/Models/AttackLearnMethod.hpp index f467f38..371e8eb 100644 --- a/src/Battling/Models/AttackLearnMethod.hpp +++ b/src/Battling/Models/AttackLearnMethod.hpp @@ -2,10 +2,7 @@ #define CREATURELIB_ATTACKLEARNMETHOD_HPP namespace CreatureLib::Battling { - enum class AttackLearnMethod { - Unknown, - Level - }; + enum class AttackLearnMethod { Unknown, Level }; } -#endif //CREATURELIB_ATTACKLEARNMETHOD_HPP +#endif // CREATURELIB_ATTACKLEARNMETHOD_HPP diff --git a/src/Battling/Models/Battle.cpp b/src/Battling/Models/Battle.cpp index e657045..07758e6 100644 --- a/src/Battling/Models/Battle.cpp +++ b/src/Battling/Models/Battle.cpp @@ -1,25 +1,22 @@ #include "Battle.hpp" -#include "../Flow/TurnHandler.hpp" -#include "../TurnChoices/AttackTurnChoice.hpp" -#include "../Flow/TurnOrdering.hpp" #include "../../Core/Exceptions/NotImplementedException.hpp" +#include "../Flow/TurnHandler.hpp" +#include "../Flow/TurnOrdering.hpp" using namespace CreatureLib; using namespace CreatureLib::Battling; -const BattleLibrary *Battle::GetLibrary() const { - return _library; -} +const BattleLibrary* Battle::GetLibrary() const { return _library; } -bool Battle::CanUse(const BaseTurnChoice *choice) { - if (choice->GetKind() == TurnChoiceKind::Attack){ - //HOOK: change number of uses needed. +bool Battle::CanUse(const BaseTurnChoice* choice) { + if (choice->GetKind() == TurnChoiceKind::Attack) { + // HOOK: change number of uses needed. return dynamic_cast(choice)->GetAttack()->GetRemainingUses() > 1; } return true; } -bool Battle::TrySetChoice(BaseTurnChoice *choice) { +bool Battle::TrySetChoice(BaseTurnChoice* choice) { if (!CanUse(choice)) return false; choice->GetUser()->GetBattleSide()->SetChoice(choice); @@ -28,29 +25,29 @@ bool Battle::TrySetChoice(BaseTurnChoice *choice) { } void Battle::CheckChoicesSetAndRun() { - for (auto side: _sides){ - if (!side->AllChoicesSet()){ + for (auto side : _sides) { + if (!side->AllChoicesSet()) { return; } } auto choices = std::vector(_numberOfSides * _creaturesPerSide); auto i = 0; - for (auto side: _sides){ - for (BaseTurnChoice* choice: side->GetChoices()){ - if (choice->GetKind() == TurnChoiceKind::Attack){ - auto attack = dynamic_cast(choice)->GetAttack(); - uint8_t uses = 1; - //HOOK: change number of uses needed. - if (attack->GetRemainingUses() < uses){ - //TODO: Implement default move - throw NotImplementedException("Not enough remaining uses, change to default move."); - } - //HOOK: Check if we need to change the move - } - choices[i] = choice; - i++; - } - side->ResetChoices(); + for (auto side : _sides) { + for (BaseTurnChoice* choice : side->GetChoices()) { + if (choice->GetKind() == TurnChoiceKind::Attack) { + auto attack = dynamic_cast(choice)->GetAttack(); + uint8_t uses = 1; + // HOOK: change number of uses needed. + if (attack->GetRemainingUses() < uses) { + // TODO: Implement default move + throw NotImplementedException("Not enough remaining uses, change to default move."); + } + // HOOK: Check if we need to change the move + } + choices[i] = choice; + i++; + } + side->ResetChoices(); } TurnOrdering::OrderChoices(choices, _random); auto choiceQueue = new ChoiceQueue(choices); @@ -60,39 +57,31 @@ void Battle::CheckChoicesSetAndRun() { _currentTurnQueue = nullptr; } -ChoiceQueue* Battle::GetCurrentTurnQueue() const { - return _currentTurnQueue; -} +ChoiceQueue* Battle::GetCurrentTurnQueue() const { return _currentTurnQueue; } -Core::Random &Battle::GetRandom(){ - return _random; -} +Core::Random& Battle::GetRandom() { return _random; } -bool Battle::CreatureInField(const Creature *creature) const { - for (auto s: _sides){ +bool Battle::CreatureInField(const Creature* creature) const { + for (auto s : _sides) { if (s->CreatureOnSide(creature)) return true; } return false; } -bool Battle::HasRecalledSlots() const { - return _numberOfRecalledSlots > 0; -} +bool Battle::HasRecalledSlots() const { return _numberOfRecalledSlots > 0; } void Battle::ForceRecall(uint8_t side, uint8_t index) { _numberOfRecalledSlots++; - //TODO: Switch out. + // TODO: Switch out. } -void Battle::FillRecall(uint8_t side, uint8_t, Creature *c) { +void Battle::FillRecall(uint8_t side, uint8_t, Creature* c) { _numberOfRecalledSlots--; - //TODO: switch in. - if (_numberOfRecalledSlots == 0 && _currentTurnQueue != nullptr){ + // TODO: switch in. + if (_numberOfRecalledSlots == 0 && _currentTurnQueue != nullptr) { TurnHandler::RunTurn(this, _currentTurnQueue); } } -void Battle::GetActiveScripts(std::vector &scripts) { - scripts.emplace_back(&_volatile); -} +void Battle::GetActiveScripts(std::vector& scripts) { scripts.emplace_back(&_volatile); } diff --git a/src/Battling/Models/Battle.hpp b/src/Battling/Models/Battle.hpp index d49d129..a0274f4 100644 --- a/src/Battling/Models/Battle.hpp +++ b/src/Battling/Models/Battle.hpp @@ -2,14 +2,14 @@ #define CREATURELIB_BATTLE_HPP #include -#include "BattleSide.hpp" +#include "../Flow/ChoiceQueue.hpp" #include "../Library/BattleLibrary.hpp" #include "../TurnChoices/BaseTurnChoice.hpp" -#include "../Flow/ChoiceQueue.hpp" +#include "BattleSide.hpp" #include "Target.hpp" namespace CreatureLib::Battling { - class Battle : public ScriptSource{ + class Battle : public ScriptSource { const BattleLibrary* _library; uint8_t _numberOfSides; uint8_t _creaturesPerSide; @@ -19,6 +19,7 @@ namespace CreatureLib::Battling { uint8_t _numberOfRecalledSlots = 0; ScriptSet _volatile; + public: [[nodiscard]] const BattleLibrary* GetLibrary() const; @@ -32,7 +33,7 @@ namespace CreatureLib::Battling { bool CreatureInField(const Creature* creature) const; - Creature* GetTarget(const Target& target){ + Creature* GetTarget(const Target& target) { return _sides[target.GetSideIndex()]->GetCreature(target.GetCreatureIndex()); } @@ -42,9 +43,8 @@ namespace CreatureLib::Battling { void FillRecall(uint8_t side, uint8_t, Creature* c); - void GetActiveScripts(std::vector &scripts) override; + void GetActiveScripts(std::vector& scripts) override; }; } - -#endif //CREATURELIB_BATTLE_HPP +#endif // CREATURELIB_BATTLE_HPP diff --git a/src/Battling/Models/BattleSide.cpp b/src/Battling/Models/BattleSide.cpp index 10379c7..b2e07eb 100644 --- a/src/Battling/Models/BattleSide.cpp +++ b/src/Battling/Models/BattleSide.cpp @@ -1,47 +1,39 @@ #include "BattleSide.hpp" -#include "../../Core/Exceptions/CreatureException.hpp" #include +#include "../../Core/Exceptions/CreatureException.hpp" #include "Battle.hpp" using namespace CreatureLib::Battling; -bool BattleSide::AllChoicesSet() const { - return _choicesSet == _creaturesPerSide; -} +bool BattleSide::AllChoicesSet() const { return _choicesSet == _creaturesPerSide; } void BattleSide::ResetChoices() { _choicesSet = 0; - for (uint8_t i = 0; i < _creaturesPerSide; i++){ + for (uint8_t i = 0; i < _creaturesPerSide; i++) { _choices[i] = nullptr; } } -const std::vector& BattleSide::GetChoices() const{ - return _choices; -} +const std::vector& BattleSide::GetChoices() const { return _choices; } -void BattleSide::SetChoice(BaseTurnChoice *choice) { +void BattleSide::SetChoice(BaseTurnChoice* choice) { auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser()); - if (find ==_creatures.end()) + if (find == _creatures.end()) throw CreatureException("User not found"); - uint8_t index = std::distance(_creatures.begin(),find); + uint8_t index = std::distance(_creatures.begin(), find); _choices[index] = choice; _choicesSet++; } -void BattleSide::SetCreature(Creature *creature, uint8_t index) { - _creatures[index] = creature; -} +void BattleSide::SetCreature(Creature* creature, uint8_t index) { _creatures[index] = creature; } -bool BattleSide::CreatureOnSide(const Creature *creature) const { +bool BattleSide::CreatureOnSide(const Creature* creature) const { return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end(); } -Creature *BattleSide::GetCreature(uint8_t index) const { - return _creatures[index]; -} +Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; } -void BattleSide::GetActiveScripts(std::vector &scripts) { +void BattleSide::GetActiveScripts(std::vector& scripts) { scripts.emplace_back(&_volatile); _battle->GetActiveScripts(scripts); } diff --git a/src/Battling/Models/BattleSide.hpp b/src/Battling/Models/BattleSide.hpp index 1c10d31..bafa1fe 100644 --- a/src/Battling/Models/BattleSide.hpp +++ b/src/Battling/Models/BattleSide.hpp @@ -2,21 +2,22 @@ #define CREATURELIB_BATTLESIDE_HPP #include -#include "Creature.hpp" #include "../TurnChoices/BaseTurnChoice.hpp" +#include "Creature.hpp" -namespace CreatureLib::Battling{ - class BattleSide : public ScriptSource{ +namespace CreatureLib::Battling { + class BattleSide : public ScriptSource { uint8_t _creaturesPerSide; std::vector _creatures; std::vector _choices; uint8_t _choicesSet = 0; ScriptSet _volatile; Battle* _battle; + public: explicit BattleSide(Battle* battle, uint8_t creaturesPerSide) - : _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide), _battle(battle) - { + : _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide), _choices(creaturesPerSide), + _battle(battle) { ResetChoices(); } @@ -31,10 +32,8 @@ namespace CreatureLib::Battling{ Creature* GetCreature(uint8_t index) const; bool CreatureOnSide(const Creature* creature) const; - void GetActiveScripts(std::vector &scripts) override; - + void GetActiveScripts(std::vector& scripts) override; }; } - -#endif //CREATURELIB_BATTLESIDE_HPP +#endif // CREATURELIB_BATTLESIDE_HPP diff --git a/src/Battling/Models/BattleTeam.cpp b/src/Battling/Models/BattleTeam.cpp deleted file mode 100644 index 428a3fa..0000000 --- a/src/Battling/Models/BattleTeam.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BattleTeam.hpp" diff --git a/src/Battling/Models/BattleTeam.hpp b/src/Battling/Models/BattleTeam.hpp deleted file mode 100644 index 39e05e2..0000000 --- a/src/Battling/Models/BattleTeam.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef CREATURELIB_BATTLETEAM_HPP -#define CREATURELIB_BATTLETEAM_HPP - - -class BattleTeam { - -}; - - -#endif //CREATURELIB_BATTLETEAM_HPP diff --git a/src/Battling/Models/CreateCreature.cpp b/src/Battling/Models/CreateCreature.cpp index 6d0963c..c99d03a 100644 --- a/src/Battling/Models/CreateCreature.cpp +++ b/src/Battling/Models/CreateCreature.cpp @@ -1,7 +1,7 @@ + #include "CreateCreature.hpp" -#include "../../Core/Exceptions/CreatureException.hpp" -#include "../Library/BattleLibrary.hpp" #include +#include "../Library/BattleLibrary.hpp" using namespace CreatureLib::Battling; @@ -10,25 +10,25 @@ CreateCreature* CreateCreature::WithVariant(std::string variant) { return this; } -CreateCreature *CreateCreature::WithNickname(std::string nickname) { +CreateCreature* CreateCreature::WithNickname(std::string nickname) { this->_nickname = std::move(nickname); return this; } -CreateCreature *CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) { - switch (stat){ - case Core::Health:_healthPotential = value; +CreateCreature* CreateCreature::WithStatPotential(CreatureLib::Core::Statistic stat, uint32_t value) { + switch (stat) { + case Core::Health: _healthPotential = value; case Core::PhysicalAttack: _physAttackPotential = value; case Core::PhysicalDefense: _physDefensePotential = value; case Core::MagicalAttack: _magAttackPotential = value; - case Core::MagicalDefense:_magDefensePotential = value; + case Core::MagicalDefense: _magDefensePotential = value; case Core::Speed: _speedPotential = value; } return this; } -CreateCreature * CreateCreature::WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, - uint32_t magAttack, uint32_t magDefense, uint32_t speed) { +CreateCreature* CreateCreature::WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, + uint32_t magAttack, uint32_t magDefense, uint32_t speed) { _healthPotential = health; _physAttackPotential = physAttack; _physDefensePotential = physDefense; @@ -39,20 +39,19 @@ CreateCreature * CreateCreature::WithStatPotentials(uint32_t health, uint32_t ph } CreateCreature* CreateCreature::WithStatExperience(Core::Statistic stat, uint32_t value) { - switch (stat){ - case Core::Health:_healthExperience = value; + switch (stat) { + case Core::Health: _healthExperience = value; case Core::PhysicalAttack: _physAttackExperience = value; case Core::PhysicalDefense: _physDefenseExperience = value; case Core::MagicalAttack: _magAttackExperience = value; - case Core::MagicalDefense:_magDefenseExperience = value; + case Core::MagicalDefense: _magDefenseExperience = value; case Core::Speed: _speedExperience = value; } return this; } -CreateCreature * -CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack, - uint32_t magDefense, uint32_t speed) { +CreateCreature* CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, + uint32_t magAttack, uint32_t magDefense, uint32_t speed) { _healthExperience = health; _physAttackExperience = physAttack; _physDefenseExperience = physDefense; @@ -62,12 +61,12 @@ CreateCreature::WithStatExperiences(uint32_t health, uint32_t physAttack, uint32 return this; } -CreateCreature *CreateCreature::WithGender(Library::Gender gender) { +CreateCreature* CreateCreature::WithGender(Library::Gender gender) { this->_gender = gender; return this; } -CreateCreature *CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) { +CreateCreature* CreateCreature::WithAttack(const std::string& attackName, AttackLearnMethod learnMethod) { if (_attacks.size() >= _library->GetSettings().GetMaximalMoves()) throw CreatureException("You have already set the maximum amount of allowed moves."); @@ -76,44 +75,42 @@ CreateCreature *CreateCreature::WithAttack(const std::string& attackName, Attack return this; } -Creature *CreateCreature::Create() { +Creature* CreateCreature::Create() { _hasCreated = true; auto rand = Core::Random(); auto species = this->_library->GetSpeciesLibrary()->GetSpecies(this->_species); auto variant = species->GetVariant(this->_variant); int8_t talent; - if (this->_talent.empty()){ + if (this->_talent.empty()) { talent = variant->GetRandomTalent(&rand); - } - else{ + } else { talent = variant->GetTalentIndex(this->_talent); } auto identifier = this->_identifier; - if (identifier == 0){ + if (identifier == 0) { identifier = rand.Get(); } auto gender = this->_gender; - if (gender == static_cast(-1)){ + if (gender == static_cast(-1)) { gender = species->GetRandomGender(rand); } const Library::Item* heldItem = nullptr; - if (!this->_heldItem.empty()){ + if (!this->_heldItem.empty()) { heldItem = _library->GetItemLibrary()->GetItem(this->_heldItem); } - //FIXME: implement experience + // FIXME: implement experience auto experience = 0; - auto statExperience = Core::StatisticSet(_healthExperience, _physAttackExperience,_physDefenseExperience, _magAttackExperience, - _magDefenseExperience, _speedExperience); - auto statPotential = Core::StatisticSet(_healthPotential, _physAttackPotential,_physDefensePotential, _magAttackPotential, - _magDefensePotential, _speedPotential); + auto statExperience = Core::StatisticSet(_healthExperience, _physAttackExperience, _physDefenseExperience, + _magAttackExperience, _magDefenseExperience, _speedExperience); + auto statPotential = Core::StatisticSet(_healthPotential, _physAttackPotential, _physDefensePotential, + _magAttackPotential, _magDefensePotential, _speedPotential); auto attacks = std::vector(_attacks.size()); - for (auto kv: _attacks){ + for (auto kv : _attacks) { attacks.push_back(new LearnedAttack(std::get<0>(kv), std::get<1>(kv))); } - return new Creature(species, variant, _level, experience, statExperience,statPotential, identifier,gender, _coloring, - heldItem, _nickname, talent, attacks); + return new Creature(species, variant, _level, experience, statExperience, statPotential, identifier, gender, + _coloring, heldItem, _nickname, talent, attacks); } - diff --git a/src/Battling/Models/CreateCreature.hpp b/src/Battling/Models/CreateCreature.hpp index af9bd5a..99ef0b5 100644 --- a/src/Battling/Models/CreateCreature.hpp +++ b/src/Battling/Models/CreateCreature.hpp @@ -1,13 +1,12 @@ #ifndef CREATURELIB_CREATECREATURE_HPP #define CREATURELIB_CREATECREATURE_HPP - #include "../../Library/DataLibrary.hpp" #include "Creature.hpp" namespace CreatureLib::Battling { class CreateCreature { - const BattleLibrary *_library; + const BattleLibrary* _library; std::string _species; std::string _variant = "default"; uint8_t _level; @@ -28,7 +27,7 @@ namespace CreatureLib::Battling { uint8_t _speedExperience = 0; std::string _talent = ""; - Library::Gender _gender = static_cast(-1); + Library::Gender _gender = static_cast(-1); uint8_t _coloring = 0; std::string _heldItem = ""; uint32_t _identifier = 0; @@ -37,26 +36,22 @@ namespace CreatureLib::Battling { bool _hasCreated; public: - CreateCreature(const BattleLibrary *library, std::string species, uint8_t level) - : _library(library), _species(std::move(species)), _level(level) - { - } + CreateCreature(const BattleLibrary* library, std::string species, uint8_t level) + : _library(library), _species(std::move(species)), _level(level) {} CreateCreature* WithVariant(std::string variant); CreateCreature* WithNickname(std::string nickname); CreateCreature* WithStatPotential(Core::Statistic stat, uint32_t value); - CreateCreature* WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack, - uint32_t magDefense,uint32_t speed); + CreateCreature* WithStatPotentials(uint32_t health, uint32_t physAttack, uint32_t physDefense, + uint32_t magAttack, uint32_t magDefense, uint32_t speed); CreateCreature* WithStatExperience(Core::Statistic stat, uint32_t value); - CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, uint32_t magAttack, - uint32_t magDefense,uint32_t speed); + CreateCreature* WithStatExperiences(uint32_t health, uint32_t physAttack, uint32_t physDefense, + uint32_t magAttack, uint32_t magDefense, uint32_t speed); CreateCreature* WithGender(Library::Gender gender); CreateCreature* WithAttack(const std::string& attackName, AttackLearnMethod learnMethod); - Creature* Create(); }; } - -#endif //CREATURELIB_CREATECREATURE_HPP +#endif // CREATURELIB_CREATECREATURE_HPP diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index 509e703..7699418 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -1,6 +1,6 @@ +#include "Creature.hpp" #include #include -#include "Creature.hpp" #include "../Models/Battle.hpp" using namespace CreatureLib; @@ -8,64 +8,48 @@ using namespace CreatureLib; Battling::Creature::Creature(const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant, uint8_t level, uint32_t experience, Core::StatisticSet statExp, Core::StatisticSet statPotential, uint32_t uid, Library::Gender gender, - uint8_t coloring, const Library::Item *heldItem, std::string nickname, int8_t talent, - std::vector attacks) - : - __Species(species), - __Variant(variant), - __Level(level), - __Experience(experience), - __StatExperience(statExp), - __StatPotential(statPotential), - __UniqueIdentifier(uid), - __Gender(gender), - __Coloring(coloring), - __HeldItem(heldItem), - _nickname(std::move(nickname)), - _talentIndex(talent), - _hasOverridenTalent(false), - _attacks(std::move(attacks)) -{ + uint8_t coloring, const Library::Item* heldItem, std::string nickname, int8_t talent, + std::vector attacks) + : __Species(species), __Variant(variant), __Level(level), __Experience(experience), __StatExperience(statExp), + __StatPotential(statPotential), __UniqueIdentifier(uid), __Gender(gender), __Coloring(coloring), + __HeldItem(heldItem), _nickname(std::move(nickname)), _talentIndex(talent), _hasOverridenTalent(false), + _attacks(std::move(attacks)) { __CurrentHealth = GetBoostedStat(Core::Statistic::Health); } - - void Battling::Creature::ChangeLevel(int8_t amount) { this->__Level += amount; RecalculateFlatStats(); } -void Battling::Creature::SetBattle(Battling::Battle *battle) { - this->_battle = battle; -} +void Battling::Creature::SetBattle(Battling::Battle* battle) { this->_battle = battle; } -void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary *library) { +void Battling::Creature::SetBattleLibrary(Battling::BattleLibrary* library) { this->_library = library; _activeTalent = _library->LoadScript(ScriptResolver::ScriptCategory::Talent, GetActiveTalent()); } -const std::string &Battling::Creature::GetNickname() const { +const std::string& Battling::Creature::GetNickname() const { if (_nickname.empty()) return __Species->GetName(); return _nickname; } -const std::string &Battling::Creature::GetActiveTalent() const { - if (_hasOverridenTalent){ +const std::string& Battling::Creature::GetActiveTalent() const { + if (_hasOverridenTalent) { return _overridenTalentName; } return __Variant->GetTalent(_talentIndex); } -void Battling::Creature::SetBattleData(Battling::Battle *battle, Battling::BattleSide *side) { +void Battling::Creature::SetBattleData(Battling::Battle* battle, Battling::BattleSide* side) { _battle = battle; _side = side; } -//region Stat APIs +// region Stat APIs -void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount){ +void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount) { if (diffAmount > 0) this->_statBoost.IncreaseStatBy(stat, diffAmount); else @@ -73,29 +57,17 @@ void Battling::Creature::ChangeStatBoost(Core::Statistic stat, int8_t diffAmount this->RecalculateBoostedStat(stat); } -uint32_t Battling::Creature::GetFlatStat(Core::Statistic stat) const{ - return _flatStats.GetStat(stat); -} +uint32_t Battling::Creature::GetFlatStat(Core::Statistic stat) const { return _flatStats.GetStat(stat); } -uint32_t Battling::Creature::GetBoostedStat(Core::Statistic stat) const{ - return _boostedStats.GetStat(stat); -} +uint32_t Battling::Creature::GetBoostedStat(Core::Statistic stat) const { return _boostedStats.GetStat(stat); } -uint32_t Battling::Creature::GetBaseStat(Core::Statistic stat) const { - return __Variant->GetStatistic(stat); -} +uint32_t Battling::Creature::GetBaseStat(Core::Statistic stat) const { return __Variant->GetStatistic(stat); } -uint32_t Battling::Creature::GetStatPotential(Core::Statistic stat) const { - return __StatPotential.GetStat(stat); -} +uint32_t Battling::Creature::GetStatPotential(Core::Statistic stat) const { return __StatPotential.GetStat(stat); } -uint32_t Battling::Creature::GetStatExperience(Core::Statistic stat) const { - return __StatExperience.GetStat(stat); -} +uint32_t Battling::Creature::GetStatExperience(Core::Statistic stat) const { return __StatExperience.GetStat(stat); } -int8_t Battling::Creature::GetStatBoost(Core::Statistic stat) const { - return _statBoost.GetStat(stat); -} +int8_t Battling::Creature::GetStatBoost(Core::Statistic stat) const { return _statBoost.GetStat(stat); } void Battling::Creature::RecalculateFlatStats() { this->_flatStats = this->_library->GetStatCalculator()->CalculateFlatStats(this); @@ -116,36 +88,30 @@ void Battling::Creature::RecalculateBoostedStat(Core::Statistic stat) { this->_boostedStats.SetStat(stat, s); } -//endregion +// endregion -Battling::Battle *Battling::Creature::GetBattle() const{ - return _battle; -} +Battling::Battle* Battling::Creature::GetBattle() const { return _battle; } -Battling::BattleSide *Battling::Creature::GetBattleSide() const { - return _side; -} +Battling::BattleSide* Battling::Creature::GetBattleSide() const { return _side; } -bool Battling::Creature::IsFainted() const { - return this->__CurrentHealth <= 0; -} +bool Battling::Creature::IsFainted() const { return this->__CurrentHealth <= 0; } void Battling::Creature::Damage(uint32_t damage, Battling::DamageSource source) { - if (damage > __CurrentHealth){ + if (damage > __CurrentHealth) { damage = __CurrentHealth; } // HOOK: On Damage __CurrentHealth -= damage; } -void Battling::Creature::OverrideActiveTalent(const std::string& talent){ +void Battling::Creature::OverrideActiveTalent(const std::string& talent) { _hasOverridenTalent = true; _overridenTalentName = talent; _activeTalent = this->_library->LoadScript(ScriptResolver::ScriptCategory::Talent, talent); } const std::vector& Battling::Creature::GetTypes() const { - //HOOK: override types. + // HOOK: override types. return this->__Variant->GetTypes(); } @@ -154,7 +120,7 @@ bool Battling::Creature::HasType(uint8_t type) const { return std::find(t.begin(), t.end(), type) != t.end(); } -void Battling::Creature::GetActiveScripts(std::vector &scripts) { +void Battling::Creature::GetActiveScripts(std::vector& scripts) { scripts.emplace_back(&_activeTalent); scripts.emplace_back(&_status); scripts.emplace_back(&_volatile); diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 358b4f6..92b29d8 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -4,37 +4,36 @@ #include "../../GenericTemplates.cpp" #include "../../Library/CreatureData/CreatureSpecies.hpp" #include "../../Library/Items/Item.hpp" -#include "LearnedAttack.hpp" -#include "DamageSource.hpp" -#include "../ScriptHandling/ScriptSet.hpp" #include "../ScriptHandling/ScriptAggregator.hpp" +#include "../ScriptHandling/ScriptSet.hpp" #include "../ScriptHandling/ScriptSource.hpp" +#include "DamageSource.hpp" +#include "LearnedAttack.hpp" -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { // Forward declare battle class class Battle; class BattleSide; class BattleLibrary; - class Creature : public ScriptSource{ + class Creature : public ScriptSource { GetProperty(const Library::CreatureSpecies*, Species); - GetProperty(const Library::SpeciesVariant*, Variant) + GetProperty(const Library::SpeciesVariant*, Variant); GetProperty(uint8_t, Level); GetProperty(uint32_t, Experience); - GetProperty(Core::StatisticSet, StatExperience); - GetProperty(Core::StatisticSet, StatPotential); + GetProperty(Core::StatisticSet, StatExperience); + GetProperty(Core::StatisticSet, StatPotential); GetProperty(uint32_t, UniqueIdentifier); GetProperty(Library::Gender, Gender); GetProperty(uint8_t, Coloring); GetProperty(const Library::Item*, HeldItem); GetProperty(uint32_t, CurrentHealth); - private: - Core::StatisticSet _statBoost; - Core::StatisticSet _flatStats; - Core::StatisticSet _boostedStats; + Core::StatisticSet _statBoost; + Core::StatisticSet _flatStats; + Core::StatisticSet _boostedStats; Battle* _battle; BattleSide* _side; @@ -54,9 +53,9 @@ namespace CreatureLib::Battling{ public: Creature(const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant, uint8_t level, - uint32_t experience, Core::StatisticSet statExp, Core::StatisticSet statPotential, - uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname, - int8_t talent, std::vector attacks); + uint32_t experience, Core::StatisticSet statExp, Core::StatisticSet statPotential, + uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, + std::string nickname, int8_t talent, std::vector attacks); virtual ~Creature() = default; @@ -75,10 +74,9 @@ namespace CreatureLib::Battling{ void Damage(uint32_t damage, DamageSource source); void OverrideActiveTalent(const std::string& talent); + void GetActiveScripts(std::vector& scripts) override; - void GetActiveScripts(std::vector &scripts) override; - - //region Stat APIs + // region Stat APIs void SetBattle(Battle* battle); void SetBattleLibrary(BattleLibrary* library); @@ -95,11 +93,8 @@ namespace CreatureLib::Battling{ void RecalculateFlatStat(Core::Statistic); void RecalculateBoostedStat(Core::Statistic); - //endregion - - + // endregion }; } - -#endif //CREATURELIB_CREATURE_HPP +#endif // CREATURELIB_CREATURE_HPP diff --git a/src/Battling/Models/CreatureParty.hpp b/src/Battling/Models/CreatureParty.hpp index ad06f24..5cdc11d 100644 --- a/src/Battling/Models/CreatureParty.hpp +++ b/src/Battling/Models/CreatureParty.hpp @@ -4,29 +4,27 @@ #include #include "Creature.hpp" -namespace CreatureLib::Battling{ - template - class CreatureParty { +namespace CreatureLib::Battling { + template class CreatureParty { std::array _party; public: - CreatureParty(std::array party) : _party(party){ - } + CreatureParty(std::array party) : _party(party) {} - Creature* GetAtIndex(int index) const{ - return _party[index]; - } + Creature* GetAtIndex(int index) const { return _party[index]; } - void Switch(int a, int b){ + void Switch(int a, int b) { auto ca = _party[a]; _party[a] = _party[b]; _party[b] = ca; } - bool HasAvailableCreatures() const{ - for (Creature* c: _party){ - if (c == nullptr) continue; - if (c->IsFainted()) continue; + bool HasAvailableCreatures() const { + for (Creature* c : _party) { + if (c == nullptr) + continue; + if (c->IsFainted()) + continue; return true; } return false; @@ -34,5 +32,4 @@ namespace CreatureLib::Battling{ }; } - -#endif //CREATURELIB_CREATUREPARTY_HPP +#endif // CREATURELIB_CREATUREPARTY_HPP diff --git a/src/Battling/Models/DamageSource.hpp b/src/Battling/Models/DamageSource.hpp index 0e02b6c..81cf7b7 100644 --- a/src/Battling/Models/DamageSource.hpp +++ b/src/Battling/Models/DamageSource.hpp @@ -9,4 +9,4 @@ namespace CreatureLib::Battling { }; } -#endif //CREATURELIB_DAMAGESOURCE_HPP +#endif // CREATURELIB_DAMAGESOURCE_HPP diff --git a/src/Battling/Models/ExecutingAttack.hpp b/src/Battling/Models/ExecutingAttack.hpp index d871f9d..d69d172 100644 --- a/src/Battling/Models/ExecutingAttack.hpp +++ b/src/Battling/Models/ExecutingAttack.hpp @@ -2,63 +2,55 @@ #define CREATURELIB_EXECUTINGATTACK_HPP #include -#include #include +#include #include "Creature.hpp" namespace CreatureLib::Battling { class ExecutingAttack : public ScriptSource { public: - class HitData{ + class HitData { bool _critical = false; uint8_t _basePower = 0; float _effectiveness = 1; uint32_t _damage = 0; uint8_t _type = 0; + public: - HitData(){} + HitData() {} - [[nodiscard]] inline bool IsCritical() const{ return _critical;} - [[nodiscard]] inline uint8_t GetBasePower() const{ return _basePower;} - [[nodiscard]] inline float GetEffectiveness() const{ return _effectiveness;} - [[nodiscard]] inline uint32_t GetDamage() const{ return _damage;} - [[nodiscard]] inline uint8_t GetType() const {return _type;} + [[nodiscard]] inline bool IsCritical() const { return _critical; } + [[nodiscard]] inline uint8_t GetBasePower() const { return _basePower; } + [[nodiscard]] inline float GetEffectiveness() const { return _effectiveness; } + [[nodiscard]] inline uint32_t GetDamage() const { return _damage; } + [[nodiscard]] inline uint8_t GetType() const { return _type; } - inline void SetCritical(bool value) {_critical = value;} + inline void SetCritical(bool value) { _critical = value; } inline void SetBasePower(uint8_t value) { _basePower = value; } - inline void SetEffectiveness(float value) {_effectiveness = value;} - inline void SetDamage(uint32_t value) { _damage = value;} - inline void SetType(uint8_t value) {_type = value;} + inline void SetEffectiveness(float value) { _effectiveness = value; } + inline void SetDamage(uint32_t value) { _damage = value; } + inline void SetType(uint8_t value) { _type = value; } }; class TargetData { bool _isHit = true; std::vector _hits; + public: - explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) - { - for (uint8_t i = 0; i < numberOfHits; i++){ + explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { + for (uint8_t i = 0; i < numberOfHits; i++) { _hits[i] = HitData(); } } - TargetData()= default; + TargetData() = default; - const HitData& GetHit(uint8_t index) const{ - return _hits[index]; - } + const HitData& GetHit(uint8_t index) const { return _hits[index]; } - HitData* GetHitPtr(uint8_t index){ - return &_hits[index]; - } + HitData* GetHitPtr(uint8_t index) { return &_hits[index]; } - uint8_t GetNumberOfHits() const{ - return _hits.size(); - } - - bool IsHit() const{ - return _isHit; - } + uint8_t GetNumberOfHits() const { return _hits.size(); } + bool IsHit() const { return _isHit; } }; private: @@ -66,45 +58,35 @@ namespace CreatureLib::Battling { Creature* _user; LearnedAttack* _attack; Script* _script; + public: - ExecutingAttack(const std::vector& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack, - Script* script) - : _user(user), _attack(attack), _script(script) - { + ExecutingAttack(const std::vector& targets, uint8_t numberHits, Creature* user, + LearnedAttack* attack, Script* script) + : _user(user), _attack(attack), _script(script) { _targets.reserve(targets.size()); - for (auto target: targets){ + for (auto target : targets) { _targets.insert({target, TargetData(numberHits)}); } } virtual ~ExecutingAttack() = default; - TargetData& GetAttackDataForTarget(Creature* creature){ - return _targets[creature]; - } + TargetData& GetAttackDataForTarget(Creature* creature) { return _targets[creature]; } - bool IsCreatureTarget(Creature* creature){ - return _targets.find(creature) != _targets.end(); - } + bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); } - const std::unordered_map& GetTargets(){ - return _targets; - } + const std::unordered_map& GetTargets() { return _targets; } - Creature* GetUser(){ - return _user; - } + Creature* GetUser() { return _user; } - LearnedAttack* GetAttack(){ - return _attack; - } + LearnedAttack* GetAttack() { return _attack; } protected: - void GetActiveScripts(std::vector &scripts) override { + void GetActiveScripts(std::vector& scripts) override { scripts.emplace_back(&_script); GetUser()->GetActiveScripts(scripts); } }; } -#endif //CREATURELIB_EXECUTINGATTACK_HPP +#endif // CREATURELIB_EXECUTINGATTACK_HPP diff --git a/src/Battling/Models/LearnedAttack.cpp b/src/Battling/Models/LearnedAttack.cpp index 6a66cc9..ab97e49 100644 --- a/src/Battling/Models/LearnedAttack.cpp +++ b/src/Battling/Models/LearnedAttack.cpp @@ -1,48 +1,32 @@ #include "LearnedAttack.hpp" -CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData *attack, uint8_t maxUses, AttackLearnMethod learnMethod) - :_attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) -{ +CreatureLib::Battling::LearnedAttack::LearnedAttack(CreatureLib::Library::AttackData* attack, uint8_t maxUses, + AttackLearnMethod learnMethod) + : _attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) {} -} +CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData* attack, + AttackLearnMethod learnMethod) + : _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {} -CreatureLib::Battling::LearnedAttack::LearnedAttack(const CreatureLib::Library::AttackData *attack, AttackLearnMethod learnMethod) - : _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) -{} +const CreatureLib::Library::AttackData* CreatureLib::Battling::LearnedAttack::GetAttack() const { return _attack; } +uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const { return _maxUses; } -const CreatureLib::Library::AttackData *CreatureLib::Battling::LearnedAttack::GetAttack() const { - return _attack; -} - -uint8_t CreatureLib::Battling::LearnedAttack::GetMaxUses() const { - return _maxUses; -} - -uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const { - return _remainingUses; -} +uint8_t CreatureLib::Battling::LearnedAttack::GetRemainingUses() const { return _remainingUses; } CreatureLib::Battling::AttackLearnMethod CreatureLib::Battling::LearnedAttack::GetLearnMethod() const { return _learnMethod; } - bool CreatureLib::Battling::LearnedAttack::TryUse(uint8_t uses) { - if (uses > _remainingUses) return false; + if (uses > _remainingUses) + return false; _remainingUses -= uses; return true; } -void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) { - _remainingUses -= amount; -} +void CreatureLib::Battling::LearnedAttack::DecreaseUses(uint8_t amount) { _remainingUses -= amount; } -void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) { - _remainingUses += amount; -} - -void CreatureLib::Battling::LearnedAttack::RestoreUses() { - _remainingUses = _maxUses; -} +void CreatureLib::Battling::LearnedAttack::RestoreUses(uint8_t amount) { _remainingUses += amount; } +void CreatureLib::Battling::LearnedAttack::RestoreUses() { _remainingUses = _maxUses; } diff --git a/src/Battling/Models/LearnedAttack.hpp b/src/Battling/Models/LearnedAttack.hpp index 5392ce3..db523d5 100644 --- a/src/Battling/Models/LearnedAttack.hpp +++ b/src/Battling/Models/LearnedAttack.hpp @@ -4,12 +4,13 @@ #include "../../Library/Attacks/AttackData.hpp" #include "AttackLearnMethod.hpp" -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { class LearnedAttack { const Library::AttackData* _attack; uint8_t _maxUses; uint8_t _remainingUses; AttackLearnMethod _learnMethod; + public: LearnedAttack(Library::AttackData* attack, uint8_t maxUses, AttackLearnMethod learnMethod); LearnedAttack(const Library::AttackData* attack, AttackLearnMethod learnMethod); @@ -26,5 +27,4 @@ namespace CreatureLib::Battling{ }; } - -#endif //CREATURELIB_LEARNEDATTACK_HPP +#endif // CREATURELIB_LEARNEDATTACK_HPP diff --git a/src/Battling/Models/Target.hpp b/src/Battling/Models/Target.hpp index 81acf42..e76a945 100644 --- a/src/Battling/Models/Target.hpp +++ b/src/Battling/Models/Target.hpp @@ -8,17 +8,14 @@ namespace CreatureLib::Battling { class Target { uint8_t _side; uint8_t _creature; + public: - Target(uint8_t side, uint8_t creature) : _side(side), _creature(creature){} + Target(uint8_t side, uint8_t creature) : _side(side), _creature(creature) {} - uint8_t GetSideIndex() const{ - return _side; - } + uint8_t GetSideIndex() const { return _side; } - uint8_t GetCreatureIndex() const{ - return _creature; - } + uint8_t GetCreatureIndex() const { return _creature; } }; } -#endif //CREATURELIB_TARGET_HPP +#endif // CREATURELIB_TARGET_HPP diff --git a/src/Battling/ScriptHandling/Script.hpp b/src/Battling/ScriptHandling/Script.hpp index e17f2f9..c10384b 100644 --- a/src/Battling/ScriptHandling/Script.hpp +++ b/src/Battling/ScriptHandling/Script.hpp @@ -6,43 +6,42 @@ #include #include -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { class BaseTurnChoice; class AttackTurnChoice; class ExecutingAttack; class Creature; - class Script{ + class Script { const std::string _name; public: - explicit Script(std::string name) :_name(std::move(name)){} + explicit Script(std::string name) : _name(std::move(name)) {} virtual ~Script() = default; virtual void Stack(){}; - const std::string& GetName(){ - return _name; - } + const std::string& GetName() { return _name; } virtual void OnBeforeTurn(const BaseTurnChoice* choice){}; virtual void ChangeAttack(AttackTurnChoice* choice, std::string& attack){}; - virtual void PreventAttack(ExecutingAttack* attack,bool& result){}; + virtual void PreventAttack(ExecutingAttack* attack, bool& result){}; virtual void FailAttack(ExecutingAttack* attack, bool& failed){}; virtual void StopBeforeAttack(ExecutingAttack* attack){}; virtual void OnBeforeAttack(ExecutingAttack* attack){}; virtual void FailIncomingAttack(ExecutingAttack* attack, Creature* target, bool& result){}; - virtual void IsInvulnerable(ExecutingAttack* attack, Creature* target , bool& result){}; + virtual void IsInvulnerable(ExecutingAttack* attack, Creature* target, bool& result){}; virtual void OnAttackMiss(ExecutingAttack* attack, Creature* target){}; virtual void ChangeAttackType(ExecutingAttack* attack, Creature* target, uint8_t hitNumber, uint8_t& type){}; virtual void OnStatusMove(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){}; - virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber, bool& result){}; + virtual void PreventSecondaryEffects(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber, + bool& result){}; virtual void OnSecondaryEffect(const ExecutingAttack* attack, Creature* target, uint8_t hitNumber){}; virtual void OnAfterHits(const ExecutingAttack* attack, Creature* target){}; }; } -#endif //CREATURELIB_SCRIPT_HPP +#endif // CREATURELIB_SCRIPT_HPP diff --git a/src/Battling/ScriptHandling/ScriptAggregator.hpp b/src/Battling/ScriptHandling/ScriptAggregator.hpp index 8b195ec..43cb02e 100644 --- a/src/Battling/ScriptHandling/ScriptAggregator.hpp +++ b/src/Battling/ScriptHandling/ScriptAggregator.hpp @@ -3,36 +3,34 @@ #include #include +#include "../../Core/Exceptions/NotReachableException.hpp" #include "Script.hpp" #include "ScriptSet.hpp" -#include "../../Core/Exceptions/NotReachableException.hpp" #include "ScriptWrapper.hpp" -namespace CreatureLib::Battling{ - class ScriptAggregator{ +namespace CreatureLib::Battling { + class ScriptAggregator { std::vector _scripts; int _index = 0; bool _isSetSet = false; const std::vector* _setScripts; int _setIndex; + public: - ScriptAggregator(std::vector scripts) : _scripts(std::move(scripts)){ - }; + ScriptAggregator(std::vector scripts) : _scripts(std::move(scripts)){}; - bool HasNext(){ - return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size()); - } + bool HasNext() { return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size()); } - Script* GetNext(){ + Script* GetNext() { // We can probably do this in a cleaner version once C++ 20 drops with Coroutine support. - if (_isSetSet){ - if (_setIndex >= _setScripts->size()){ + if (_isSetSet) { + if (_setIndex >= _setScripts->size()) { _isSetSet = false; return GetNext(); } auto s = _setScripts->at(_setIndex); _setIndex++; - if (_setIndex >= _setScripts->size()){ + if (_setIndex >= _setScripts->size()) { _isSetSet = false; } return s; @@ -41,13 +39,12 @@ namespace CreatureLib::Battling{ return nullptr; auto next = _scripts[_index]; _index++; - if (!next.IsSet()){ + if (!next.IsSet()) { auto scriptPtr = next.GetScript(); if (scriptPtr == nullptr) return GetNext(); return *scriptPtr; - } - else{ + } else { auto set = next.GetScriptSet(); if (set->Count() == 0) return GetNext(); @@ -61,4 +58,4 @@ namespace CreatureLib::Battling{ }; } -#endif //CREATURELIB_SCRIPTAGGREGATOR_HPP +#endif // CREATURELIB_SCRIPTAGGREGATOR_HPP diff --git a/src/Battling/ScriptHandling/ScriptMacros.cpp b/src/Battling/ScriptHandling/ScriptMacros.cpp index ca5b288..29b2f43 100644 --- a/src/Battling/ScriptHandling/ScriptMacros.cpp +++ b/src/Battling/ScriptHandling/ScriptMacros.cpp @@ -1,11 +1,10 @@ -#define HOOK(hookName, source, ... ) \ -{ \ -auto aggregator = source -> GetScriptIterator(); \ -while (aggregator.HasNext()){ \ -auto next = aggregator.GetNext(); \ -if (next == nullptr) continue; \ -next->hookName(__VA_ARGS__); \ -} \ -} - - +#define HOOK(hookName, source, ...) \ + { \ + auto aggregator = source->GetScriptIterator(); \ + while (aggregator.HasNext()) { \ + auto next = aggregator.GetNext(); \ + if (next == nullptr) \ + continue; \ + next->hookName(__VA_ARGS__); \ + } \ + } diff --git a/src/Battling/ScriptHandling/ScriptResolver.cpp b/src/Battling/ScriptHandling/ScriptResolver.cpp index 4cf99cc..af0d96b 100644 --- a/src/Battling/ScriptHandling/ScriptResolver.cpp +++ b/src/Battling/ScriptHandling/ScriptResolver.cpp @@ -1,3 +1 @@ - - #include "ScriptResolver.hpp" diff --git a/src/Battling/ScriptHandling/ScriptResolver.hpp b/src/Battling/ScriptHandling/ScriptResolver.hpp index dd24827..e232741 100644 --- a/src/Battling/ScriptHandling/ScriptResolver.hpp +++ b/src/Battling/ScriptHandling/ScriptResolver.hpp @@ -4,12 +4,12 @@ #include #include "Script.hpp" -namespace CreatureLib::Battling{ +namespace CreatureLib::Battling { class ScriptResolver { public: virtual ~ScriptResolver() = default; - enum class ScriptCategory{ + enum class ScriptCategory { Attack, Talent, Status, @@ -19,11 +19,8 @@ namespace CreatureLib::Battling{ }; - virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName){ - return nullptr; - }; + virtual Script* LoadScript(ScriptCategory category, const std::string& scriptName) { return nullptr; }; }; } - -#endif //CREATURELIB_SCRIPTRESOLVER_HPP +#endif // CREATURELIB_SCRIPTRESOLVER_HPP diff --git a/src/Battling/ScriptHandling/ScriptSet.hpp b/src/Battling/ScriptHandling/ScriptSet.hpp index 78b537e..959b3df 100644 --- a/src/Battling/ScriptHandling/ScriptSet.hpp +++ b/src/Battling/ScriptHandling/ScriptSet.hpp @@ -5,14 +5,15 @@ #include #include "Script.hpp" -namespace CreatureLib::Battling{ - class ScriptSet{ +namespace CreatureLib::Battling { + class ScriptSet { std::vector _scripts; std::unordered_map _lookup; + public: - void Add(Script* script){ + void Add(Script* script) { auto f = _lookup.find(script->GetName()); - if (f != _lookup.end()){ + if (f != _lookup.end()) { _scripts[f.operator*().second]->Stack(); return; } @@ -20,22 +21,18 @@ namespace CreatureLib::Battling{ _lookup.insert({script->GetName(), _scripts.size() - 1}); } - void Remove(const std::string& key){ + void Remove(const std::string& key) { auto find = _lookup.find(key); - if (find != _lookup.end()){ + if (find != _lookup.end()) { _scripts.erase(_scripts.begin() + find.operator*().second); _lookup.erase(key); } } - size_t Count() const{ - return _scripts.size(); - } + size_t Count() const { return _scripts.size(); } - const std::vector