Used ClangFormat style guide I'm happy with.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-11-28 12:55:22 +01:00
parent 3b685ae782
commit a8730d983f
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
91 changed files with 946 additions and 1121 deletions

121
.clang-format Normal file
View File

@ -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
...

View File

@ -9,11 +9,11 @@ namespace CreatureLib::Battling{
class ChoiceQueue {
std::vector<BaseTurnChoice*> _queue;
size_t _current = 0;
public:
bool HasCompletedQueue = false;
explicit ChoiceQueue(std::vector<BaseTurnChoice*> queue)
:_queue(std::move(queue)){}
explicit ChoiceQueue(std::vector<BaseTurnChoice*> queue) : _queue(std::move(queue)) {}
BaseTurnChoice* Dequeue() {
auto b = _queue[_current];
@ -21,15 +21,10 @@ namespace CreatureLib::Battling{
return b;
}
[[nodiscard]] bool HasNext() const{
return _current < _queue.size();
}
[[nodiscard]] bool HasNext() const { return _current < _queue.size(); }
std::vector<BaseTurnChoice*>& GetInnerQueue(){
return _queue;
}
std::vector<BaseTurnChoice*>& GetInnerQueue() { return _queue; }
};
}
#endif // CREATURELIB_CHOICEQUEUE_HPP

View File

@ -1,6 +1,6 @@
#include "TurnHandler.hpp"
#include "../Models/Battle.hpp"
#include "../../Core/Exceptions/NotImplementedException.hpp"
#include "../Models/Battle.hpp"
#include "../ScriptHandling/ScriptMacros.cpp"
using namespace CreatureLib::Battling;
@ -21,8 +21,7 @@ void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) {
}
void TurnHandler::ExecuteChoice(BaseTurnChoice* choice) {
if (choice == nullptr)
{
if (choice == nullptr) {
return;
}
auto choiceKind = choice->GetKind();
@ -46,12 +45,10 @@ void TurnHandler::ExecuteChoice(BaseTurnChoice *choice) {
switch (choiceKind) {
case TurnChoiceKind::Pass: throw NotReachableException();
case TurnChoiceKind::Attack:
return ExecuteAttackChoice(dynamic_cast<AttackTurnChoice*>(choice));
case TurnChoiceKind::Attack: return ExecuteAttackChoice(dynamic_cast<AttackTurnChoice*>(choice));
case TurnChoiceKind::Item:
case TurnChoiceKind::Switch:
case TurnChoiceKind::RunAway:
throw NotImplementedException();
case TurnChoiceKind::RunAway: throw NotImplementedException();
}
}
@ -98,7 +95,8 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice *choice) {
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;
@ -148,8 +146,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *targe
if (attackData->GetCategory() == Library::AttackCategory::Status) {
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
}
else{
} else {
auto damage = hit.GetDamage();
if (damage > target->GetCurrentHealth()) {
damage = target->GetCurrentHealth();

View File

@ -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,7 +12,9 @@ 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);
};

View File

@ -1,8 +1,7 @@
#include "TurnOrdering.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
#include "../Models/Battle.hpp"
#include <algorithm>
#include "../Models/Battle.hpp"
#include "../TurnChoices/AttackTurnChoice.hpp"
using namespace CreatureLib;
using namespace Battling;

View File

@ -1,9 +1,9 @@
#ifndef CREATURELIB_TURNORDERING_HPP
#define CREATURELIB_TURNORDERING_HPP
#include "../TurnChoices/BaseTurnChoice.hpp"
#include "../../Core/Random.hpp"
#include <vector>
#include "../../Core/Random.hpp"
#include "../TurnChoices/BaseTurnChoice.hpp"
namespace CreatureLib::Battling {
class TurnOrdering {

View File

@ -1,16 +1,13 @@
#include <cassert>
#include "BattleLibrary.hpp"
#include <cassert>
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 {
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) {
assert(this->_scriptResolver != nullptr);
return _scriptResolver->LoadScript(category, scriptName);
}

View File

@ -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;

View File

@ -1,36 +1,31 @@
#include "BattleStatCalculator.hpp"
#include "../Models/Creature.hpp"
#include "../../Core/Exceptions/NotImplementedException.hpp"
#include "../Models/Creature.hpp"
using namespace CreatureLib;
Core::StatisticSet<uint32_t>
Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature *creature) const {
return Core::StatisticSet<uint32_t>(
CalculateFlatStat(creature, Core::Statistic::Health),
Core::StatisticSet<uint32_t> Battling::BattleStatCalculator::CalculateFlatStats(Battling::Creature* creature) const {
return Core::StatisticSet<uint32_t>(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)
);
CalculateFlatStat(creature, Core::Statistic::Speed));
}
Core::StatisticSet<uint32_t>
Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature *creature) const {
return Core::StatisticSet<uint32_t>(
CalculateBoostedStat(creature, Core::Statistic::Health),
Core::StatisticSet<uint32_t> Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creature) const {
return Core::StatisticSet<uint32_t>(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)
);
CalculateBoostedStat(creature, Core::Statistic::Speed));
}
uint32_t CalculateHealthStat(Battling::Creature* creature) {
auto level = creature->GetLevel();
auto a = (creature->GetBaseStat(Core::Statistic::Health) + creature->GetStatPotential(Core::Statistic::Health)) * 2 +
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;
}
@ -42,13 +37,13 @@ uint32_t CalculateOtherStat(Battling::Creature *creature, Core::Statistic stat){
return floor(a / 100) + 10;
}
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();
}

View File

@ -11,5 +11,4 @@ namespace CreatureLib::Battling {
};
}
#endif // CREATURELIB_CRITICALLIBRARY_HPP

View File

@ -7,8 +7,8 @@ int DamageLibrary::GetDamage(ExecutingAttack *attack, Creature *target, uint8_t
auto bp = hit.GetBasePower();
auto statMod = GetStatModifier(attack, target, hitIndex);
// HOOK: Modify stat modifier
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2)
* GetDamageModifier(attack, target, hitIndex));
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
GetDamageModifier(attack, target, hitIndex));
// HOOK: Override damage
return damage;
}
@ -28,8 +28,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack *attack, Creature *target,
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;
}
@ -63,4 +62,3 @@ float DamageLibrary::GetDamageModifier(ExecutingAttack *attack, Creature *target
// HOOK: Modify damage modifier.
return mod;
}

View File

@ -16,5 +16,4 @@ namespace CreatureLib::Battling{
};
}
#endif // CREATURELIB_DAMAGELIBRARY_HPP

View File

@ -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

View File

@ -1,15 +1,12 @@
#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) {
@ -60,13 +57,9 @@ 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) {
@ -76,9 +69,7 @@ bool Battle::CreatureInField(const Creature *creature) const {
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++;
@ -93,6 +84,4 @@ void Battle::FillRecall(uint8_t side, uint8_t, Creature *c) {
}
}
void Battle::GetActiveScripts(std::vector<ScriptWrapper> &scripts) {
scripts.emplace_back(&_volatile);
}
void Battle::GetActiveScripts(std::vector<ScriptWrapper>& scripts) { scripts.emplace_back(&_volatile); }

View File

@ -2,10 +2,10 @@
#define CREATURELIB_BATTLE_HPP
#include <vector>
#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 {
@ -19,6 +19,7 @@ namespace CreatureLib::Battling {
uint8_t _numberOfRecalledSlots = 0;
ScriptSet _volatile;
public:
[[nodiscard]] const BattleLibrary* GetLibrary() const;
@ -46,5 +47,4 @@ namespace CreatureLib::Battling {
};
}
#endif // CREATURELIB_BATTLE_HPP

View File

@ -1,13 +1,11 @@
#include "BattleSide.hpp"
#include "../../Core/Exceptions/CreatureException.hpp"
#include <algorithm>
#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;
@ -16,9 +14,7 @@ void BattleSide::ResetChoices() {
}
}
const std::vector<BaseTurnChoice *>& BattleSide::GetChoices() const{
return _choices;
}
const std::vector<BaseTurnChoice*>& BattleSide::GetChoices() const { return _choices; }
void BattleSide::SetChoice(BaseTurnChoice* choice) {
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
@ -29,17 +25,13 @@ void BattleSide::SetChoice(BaseTurnChoice *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 {
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<ScriptWrapper>& scripts) {
scripts.emplace_back(&_volatile);

View File

@ -2,8 +2,8 @@
#define CREATURELIB_BATTLESIDE_HPP
#include <vector>
#include "Creature.hpp"
#include "../TurnChoices/BaseTurnChoice.hpp"
#include "Creature.hpp"
namespace CreatureLib::Battling {
class BattleSide : public ScriptSource {
@ -13,10 +13,11 @@ namespace CreatureLib::Battling{
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();
}
@ -32,9 +33,7 @@ namespace CreatureLib::Battling{
bool CreatureOnSide(const Creature* creature) const;
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
};
}
#endif // CREATURELIB_BATTLESIDE_HPP

View File

@ -1 +0,0 @@
#include "BattleTeam.hpp"

View File

@ -1,10 +0,0 @@
#ifndef CREATURELIB_BATTLETEAM_HPP
#define CREATURELIB_BATTLETEAM_HPP
class BattleTeam {
};
#endif //CREATURELIB_BATTLETEAM_HPP

View File

@ -1,7 +1,7 @@
#include "CreateCreature.hpp"
#include "../../Core/Exceptions/CreatureException.hpp"
#include "../Library/BattleLibrary.hpp"
#include <utility>
#include "../Library/BattleLibrary.hpp"
using namespace CreatureLib::Battling;
@ -50,9 +50,8 @@ CreateCreature* CreateCreature::WithStatExperience(Core::Statistic stat, uint32_
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;
@ -84,8 +83,7 @@ Creature *CreateCreature::Create() {
int8_t talent;
if (this->_talent.empty()) {
talent = variant->GetRandomTalent(&rand);
}
else{
} else {
talent = variant->GetTalentIndex(this->_talent);
}
auto identifier = this->_identifier;
@ -103,17 +101,16 @@ Creature *CreateCreature::Create() {
// 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<LearnedAttack*>(_attacks.size());
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);
}

View File

@ -1,7 +1,6 @@
#ifndef CREATURELIB_CREATECREATURE_HPP
#define CREATURELIB_CREATECREATURE_HPP
#include "../../Library/DataLibrary.hpp"
#include "Creature.hpp"
@ -38,25 +37,21 @@ namespace CreatureLib::Battling {
public:
CreateCreature(const BattleLibrary* library, std::string species, uint8_t level)
: _library(library), _species(std::move(species)), _level(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

View File

@ -1,6 +1,6 @@
#include "Creature.hpp"
#include <algorithm>
#include <utility>
#include "Creature.hpp"
#include "../Models/Battle.hpp"
using namespace CreatureLib;
@ -10,35 +10,19 @@ Battling::Creature::Creature(const Library::CreatureSpecies* species, const Libr
Core::StatisticSet<uint8_t> statPotential, uint32_t uid, Library::Gender gender,
uint8_t coloring, const Library::Item* heldItem, std::string nickname, int8_t talent,
std::vector<LearnedAttack*> 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))
{
: __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) {
this->_library = library;
@ -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);
@ -118,17 +90,11 @@ void Battling::Creature::RecalculateBoostedStat(Core::Statistic stat) {
// 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) {

View File

@ -4,11 +4,11 @@
#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 {
// Forward declare battle class
@ -18,7 +18,7 @@ namespace CreatureLib::Battling{
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);
@ -30,7 +30,6 @@ namespace CreatureLib::Battling{
GetProperty(const Library::Item*, HeldItem);
GetProperty(uint32_t, CurrentHealth);
private:
Core::StatisticSet<int8_t> _statBoost;
Core::StatisticSet<uint32_t> _flatStats;
@ -55,8 +54,8 @@ namespace CreatureLib::Battling{
public:
Creature(const Library::CreatureSpecies* species, const Library::SpeciesVariant* variant, uint8_t level,
uint32_t experience, Core::StatisticSet<uint8_t> statExp, Core::StatisticSet<uint8_t> statPotential,
uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem, std::string nickname,
int8_t talent, std::vector<LearnedAttack*> attacks);
uint32_t uid, Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
std::string nickname, int8_t talent, std::vector<LearnedAttack*> attacks);
virtual ~Creature() = default;
@ -75,7 +74,6 @@ namespace CreatureLib::Battling{
void Damage(uint32_t damage, DamageSource source);
void OverrideActiveTalent(const std::string& talent);
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override;
// region Stat APIs
@ -96,10 +94,7 @@ namespace CreatureLib::Battling{
void RecalculateBoostedStat(Core::Statistic);
// endregion
};
}
#endif // CREATURELIB_CREATURE_HPP

View File

@ -5,17 +5,13 @@
#include "Creature.hpp"
namespace CreatureLib::Battling {
template <int max>
class CreatureParty {
template <int max> class CreatureParty {
std::array<Creature*, max> _party;
public:
CreatureParty(std::array<Creature*, max> party) : _party(party){
}
CreatureParty(std::array<Creature*, max> 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) {
auto ca = _party[a];
@ -25,8 +21,10 @@ namespace CreatureLib::Battling{
bool HasAvailableCreatures() const {
for (Creature* c : _party) {
if (c == nullptr) continue;
if (c->IsFainted()) continue;
if (c == nullptr)
continue;
if (c->IsFainted())
continue;
return true;
}
return false;
@ -34,5 +32,4 @@ namespace CreatureLib::Battling{
};
}
#endif // CREATURELIB_CREATUREPARTY_HPP

View File

@ -2,8 +2,8 @@
#define CREATURELIB_EXECUTINGATTACK_HPP
#include <cstdint>
#include <vector>
#include <unordered_map>
#include <vector>
#include "Creature.hpp"
namespace CreatureLib::Battling {
@ -15,6 +15,7 @@ namespace CreatureLib::Battling {
float _effectiveness = 1;
uint32_t _damage = 0;
uint8_t _type = 0;
public:
HitData() {}
@ -34,31 +35,22 @@ namespace CreatureLib::Battling {
class TargetData {
bool _isHit = true;
std::vector<HitData> _hits;
public:
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits)
{
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) {
for (uint8_t i = 0; i < numberOfHits; i++) {
_hits[i] = HitData();
}
}
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,11 +58,11 @@ namespace CreatureLib::Battling {
Creature* _user;
LearnedAttack* _attack;
Script* _script;
public:
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user, LearnedAttack* attack,
Script* script)
: _user(user), _attack(attack), _script(script)
{
ExecutingAttack(const std::vector<Creature*>& targets, uint8_t numberHits, Creature* user,
LearnedAttack* attack, Script* script)
: _user(user), _attack(attack), _script(script) {
_targets.reserve(targets.size());
for (auto target : targets) {
_targets.insert({target, TargetData(numberHits)});
@ -79,25 +71,15 @@ namespace CreatureLib::Battling {
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<Creature*, TargetData>& GetTargets(){
return _targets;
}
const std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
Creature* GetUser(){
return _user;
}
Creature* GetUser() { return _user; }
LearnedAttack* GetAttack(){
return _attack;
}
LearnedAttack* GetAttack() { return _attack; }
protected:
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {

View File

@ -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; }

View File

@ -10,6 +10,7 @@ namespace CreatureLib::Battling{
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

View File

@ -8,16 +8,13 @@ namespace CreatureLib::Battling {
class Target {
uint8_t _side;
uint8_t _creature;
public:
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; }
};
}

View File

@ -21,9 +21,7 @@ namespace CreatureLib::Battling{
virtual void Stack(){};
const std::string& GetName(){
return _name;
}
const std::string& GetName() { return _name; }
virtual void OnBeforeTurn(const BaseTurnChoice* choice){};
@ -38,7 +36,8 @@ namespace CreatureLib::Battling{
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){};

View File

@ -3,9 +3,9 @@
#include <any>
#include <queue>
#include "../../Core/Exceptions/NotReachableException.hpp"
#include "Script.hpp"
#include "ScriptSet.hpp"
#include "../../Core/Exceptions/NotReachableException.hpp"
#include "ScriptWrapper.hpp"
namespace CreatureLib::Battling {
@ -15,13 +15,11 @@ namespace CreatureLib::Battling{
bool _isSetSet = false;
const std::vector<Script*>* _setScripts;
int _setIndex;
public:
ScriptAggregator(std::vector<ScriptWrapper> scripts) : _scripts(std::move(scripts)){
};
bool HasNext(){
return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size());
}
public:
ScriptAggregator(std::vector<ScriptWrapper> scripts) : _scripts(std::move(scripts)){};
bool HasNext() { return _index < _scripts.size() || (_isSetSet && _setIndex < _setScripts->size()); }
Script* GetNext() {
// We can probably do this in a cleaner version once C++ 20 drops with Coroutine support.
@ -46,8 +44,7 @@ namespace CreatureLib::Battling{
if (scriptPtr == nullptr)
return GetNext();
return *scriptPtr;
}
else{
} else {
auto set = next.GetScriptSet();
if (set->Count() == 0)
return GetNext();

View File

@ -3,9 +3,8 @@
auto aggregator = source->GetScriptIterator(); \
while (aggregator.HasNext()) { \
auto next = aggregator.GetNext(); \
if (next == nullptr) continue; \
if (next == nullptr) \
continue; \
next->hookName(__VA_ARGS__); \
} \
}

View File

@ -1,3 +1 @@
#include "ScriptResolver.hpp"

View File

@ -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

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Battling{
class ScriptSet {
std::vector<Script*> _scripts;
std::unordered_map<std::string, size_t> _lookup;
public:
void Add(Script* script) {
auto f = _lookup.find(script->GetName());
@ -28,13 +29,9 @@ namespace CreatureLib::Battling{
}
}
size_t Count() const{
return _scripts.size();
}
size_t Count() const { return _scripts.size(); }
const std::vector<Script *> * GetIterator() const{
return &_scripts;
}
const std::vector<Script*>* GetIterator() const { return &_scripts; }
};
}

View File

@ -9,8 +9,10 @@ namespace CreatureLib::Battling{
class ScriptSource {
bool _areScriptsInitialized = false;
std::vector<ScriptWrapper> _scripts;
protected:
virtual void GetActiveScripts(std::vector<ScriptWrapper>& scripts) = 0;
public:
ScriptAggregator GetScriptIterator() {
if (!_areScriptsInitialized) {

View File

@ -1,3 +1 @@
#include "ScriptWrapper.hpp"

View File

@ -1,5 +1,3 @@
#ifndef CREATURELIB_SCRIPTWRAPPER_HPP
#define CREATURELIB_SCRIPTWRAPPER_HPP
@ -11,23 +9,17 @@ namespace CreatureLib::Battling{
class ScriptWrapper {
std::variant<Script**, ScriptSet*> _value;
bool _isSet;
public:
ScriptWrapper(Script** s) : _value(s), _isSet(false) {}
ScriptWrapper(ScriptSet* s) : _value(s), _isSet(true) {}
bool IsSet() const{
return _isSet;
}
bool IsSet() const { return _isSet; }
Script** GetScript() const{
return std::get<Script**>(_value);
}
Script** GetScript() const { return std::get<Script**>(_value); }
ScriptSet* GetScriptSet() const{
return std::get<ScriptSet*>(_value);
}
ScriptSet* GetScriptSet() const { return std::get<ScriptSet*>(_value); }
};
}
#endif // CREATURELIB_SCRIPTWRAPPER_HPP

View File

@ -1,48 +1,39 @@
#ifndef CREATURELIB_ATTACKTURNCHOICE_HPP
#define CREATURELIB_ATTACKTURNCHOICE_HPP
#include "BaseTurnChoice.hpp"
#include "../Models/LearnedAttack.hpp"
#include "../Models/Target.hpp"
#include "BaseTurnChoice.hpp"
namespace CreatureLib::Battling {
class AttackTurnChoice : public BaseTurnChoice {
LearnedAttack* _attack;
Target _target;
Script* _attackScript;
public:
AttackTurnChoice(Creature* user, LearnedAttack* attack, const Target& target)
: BaseTurnChoice(user), _attack(attack), _target(target) {}
inline LearnedAttack* GetAttack() const{
return _attack;
}
inline LearnedAttack* GetAttack() const { return _attack; }
TurnChoiceKind GetKind() const override {
return TurnChoiceKind ::Attack;
}
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Attack; }
int8_t GetPriority() const {
// HOOK: Change priority
return _attack->GetAttack()->GetPriority();
}
const Target& GetTarget() const{
return _target;
}
const Target& GetTarget() const { return _target; }
Script* GetAttackScript(){
return _attackScript;
}
Script* GetAttackScript() { return _attackScript; }
protected:
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override {
scripts.emplace_back(&_attackScript);
GetUser()->GetActiveScripts(scripts);
}
};
}
#endif // CREATURELIB_ATTACKTURNCHOICE_HPP

View File

@ -1,24 +1,23 @@
#ifndef CREATURELIB_BASETURNCHOICE_HPP
#define CREATURELIB_BASETURNCHOICE_HPP
#include "TurnChoiceKind.hpp"
#include "../ScriptHandling/ScriptSource.hpp"
#include "TurnChoiceKind.hpp"
namespace CreatureLib::Battling {
class Creature;
class BaseTurnChoice : public ScriptSource {
Creature* _user;
protected:
BaseTurnChoice(Creature* user) : _user(user){};
public:
virtual ~BaseTurnChoice() = default;
[[nodiscard]] virtual TurnChoiceKind GetKind() const = 0;
[[nodiscard]] inline Creature* GetUser() const{
return _user;
}
[[nodiscard]] inline Creature* GetUser() const { return _user; }
};
}
#endif // CREATURELIB_BASETURNCHOICE_HPP

View File

@ -8,14 +8,10 @@ namespace CreatureLib::Battling {
public:
PassTurnChoice(Creature* c) : BaseTurnChoice(c) {}
TurnChoiceKind GetKind() const override {
return TurnChoiceKind ::Pass;
}
TurnChoiceKind GetKind() const override { return TurnChoiceKind ::Pass; }
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
GetUser()->GetActiveScripts(scripts);
}
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { GetUser()->GetActiveScripts(scripts); }
};
}

View File

@ -4,12 +4,6 @@
#include <cstdint>
namespace CreatureLib::Battling {
enum class TurnChoiceKind : uint8_t {
Pass,
Attack,
Item,
Switch,
RunAway
};
enum class TurnChoiceKind : uint8_t { Pass, Attack, Item, Switch, RunAway };
}
#endif // CREATURELIB_TURNCHOICEKIND_HPP

View File

@ -6,13 +6,11 @@
class CreatureException : std::exception {
std::string _error;
public:
CreatureException(std::string error) {}
const char *what() const noexcept override {
return _error.c_str();
}
const char* what() const noexcept override { return _error.c_str(); }
};
#endif // CREATURELIB_CREATUREEXCEPTION_HPP

View File

@ -2,7 +2,8 @@
#include <limits>
// Seed parameterless constructor with current milliseconds since epoch.
CreatureLib::Core::Random::Random() : _rng(std::mt19937(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count())){}
CreatureLib::Core::Random::Random()
: _rng(std::mt19937(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count())) {}
float CreatureLib::Core::Random::GetFloat() {
return static_cast<float>(_rng()) / (static_cast<float>(std::mt19937::max() - std::mt19937::min()) - 0.5f);
@ -23,8 +24,3 @@ int32_t CreatureLib::Core::Random::Get(int32_t max) {
int32_t CreatureLib::Core::Random::Get(int32_t min, int32_t max) {
return static_cast<int32_t>(GetDouble() * static_cast<float>(max - min) + min);
}

View File

@ -1,13 +1,14 @@
#ifndef CREATURELIB_RANDOM_HPP
#define CREATURELIB_RANDOM_HPP
#include <cstdint>
#include <chrono>
#include <cstdint>
#include <random>
using namespace std::chrono;
namespace CreatureLib::Core {
class Random {
private:
std::mt19937 _rng;
public:
Random();
explicit Random(int32_t seed) : _rng(seed){};

View File

@ -1,10 +1,10 @@
#ifndef CREATURELIB_STATISTICSET_HPP
#define CREATURELIB_STATISTICSET_HPP
#include <stdint.h>
#include <exception>
#include "Statistic.hpp"
#include <stdint.h>
#include "../GenericTemplates.cpp"
#include "Exceptions/NotReachableException.hpp"
#include "Statistic.hpp"
namespace CreatureLib::Core {
template <class T>
@ -16,14 +16,13 @@ namespace CreatureLib::Core{
T _magicalAttack;
T _magicalDefense;
T _speed;
public:
StatisticSet(T health, T physicalAttack, T physicalDefense, T magicalAttack, T magicalDefense, T speed)
: _health(health), _physicalAttack(physicalAttack),
_physicalDefense(physicalDefense), _magicalAttack(magicalAttack),
_magicalDefense(magicalDefense), _speed(speed){}
: _health(health), _physicalAttack(physicalAttack), _physicalDefense(physicalDefense),
_magicalAttack(magicalAttack), _magicalDefense(magicalDefense), _speed(speed) {}
StatisticSet()
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0)
{}
: _health(0), _physicalAttack(0), _physicalDefense(0), _magicalAttack(0), _magicalDefense(0), _speed(0) {}
inline T GetHealth() const { return _health; }
inline T GetPhysicalAttack() const { return _physicalAttack; }
@ -32,7 +31,6 @@ namespace CreatureLib::Core{
inline T GetMagicalDefense() const { return _magicalDefense; }
inline T GetSpeed() const { return _speed; }
[[nodiscard]] inline T GetStat(Statistic stat) const {
switch (stat) {
case Health: return _health;
@ -82,5 +80,4 @@ namespace CreatureLib::Core{
};
}
#endif //CREATURELIB_STATISTICSET_HPP

View File

@ -2,15 +2,22 @@
\brief GetProperty creates a simple wrapper for a field, creating a private field, and a public getter method.
*/
#define GetProperty(type, name) \
private: type __##name; \
public: [[nodiscard]] inline type Get##name() const{ return __##name; };
private: \
type __##name; \
\
public: \
[[nodiscard]] inline type Get##name() const { return __##name; };
/*!
\brief GetProperty creates a simple wrapper for a field, creating a private field, a public getter method, and a public
setter method.
*/
#define GetSetProperty(type, name) \
private: type __##name; \
public: [[nodiscard]] inline type Get##name() const{ return __##name; }; \
public: inline void Set##name(type value) { __##name = value; };
private: \
type __##name; \
\
public: \
[[nodiscard]] inline type Get##name() const { return __##name; }; \
\
public: \
inline void Set##name(type value) { __##name = value; };

View File

@ -13,8 +13,4 @@ void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string &name,
this->_attacks.insert({name, attack});
}
void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string &name) {
this->_attacks.erase(name);
}
void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string& name) { this->_attacks.erase(name); }

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Library {
class AttackLibrary {
private:
std::unordered_map<std::string, const AttackData*> _attacks;
public:
AttackLibrary() = default;

View File

@ -4,11 +4,7 @@
#include <cstdint>
namespace CreatureLib::Library {
enum class AttackCategory : uint8_t {
Physical,
Magical,
Status
};
enum class AttackCategory : uint8_t { Physical, Magical, Status };
}
#endif // CREATURELIB_ATTACKCATEGORY_HPP

View File

@ -1,5 +1,4 @@
#include "AttackData.hpp"
#include <utility>
CreatureLib::Library::AttackData::AttackData(std::string name, std::string type,
@ -7,19 +6,9 @@ CreatureLib::Library::AttackData::AttackData(std::string name, std::string type,
uint8_t accuracy, uint8_t baseUsage,
CreatureLib::Library::AttackTarget target, uint8_t priority,
std::unordered_set<std::string> flags)
:
__Name(std::move(name)),
__Type(std::move(type)),
__Category(category),
__BasePower(power),
__Accuracy(accuracy),
__BaseUsages(baseUsage),
__Target(target),
__Priority(priority),
_flags(std::move(flags))
{}
: __Name(std::move(name)), __Type(std::move(type)), __Category(category), __BasePower(power), __Accuracy(accuracy),
__BaseUsages(baseUsage), __Target(target), __Priority(priority), _flags(std::move(flags)) {}
bool CreatureLib::Library::AttackData::HasFlag(const std::string& key) const {
return this->_flags.find(key) != this->_flags.end();
}

View File

@ -3,11 +3,10 @@
#include <string>
#include <unordered_set>
#include "../../GenericTemplates.cpp"
#include "AttackCategory.hpp"
#include "AttackTarget.hpp"
#include "../../GenericTemplates.cpp"
namespace CreatureLib::Library {
class AttackData {
GetProperty(std::string, Name);
@ -18,8 +17,10 @@ namespace CreatureLib::Library {
GetProperty(uint8_t, BaseUsages);
GetProperty(AttackTarget, Target);
GetProperty(uint8_t, Priority);
private:
std::unordered_set<std::string> _flags;
public:
AttackData(std::string name, std::string type, AttackCategory category, uint8_t power, uint8_t accuracy,
uint8_t baseUsage, AttackTarget target, uint8_t priority, std::unordered_set<std::string> flags);
@ -28,5 +29,4 @@ namespace CreatureLib::Library {
};
}
#endif // CREATURELIB_ATTACKDATA_HPP

View File

@ -1,16 +1,8 @@
#include "CreatureMoves.hpp"
#include <utility>
CreatureLib::Library::LevelMove::LevelMove(uint8_t level, std::string name)
:_level(level),
_name(std::move(name))
{}
CreatureLib::Library::LevelMove::LevelMove(uint8_t level, std::string name) : _level(level), _name(std::move(name)) {}
uint8_t CreatureLib::Library::LevelMove::GetLevel() const {
return this->_level;
}
std::string CreatureLib::Library::LevelMove::GetName() const {
return this->_name;
}
uint8_t CreatureLib::Library::LevelMove::GetLevel() const { return this->_level; }
std::string CreatureLib::Library::LevelMove::GetName() const { return this->_name; }

View File

@ -10,6 +10,7 @@ namespace CreatureLib::Library{
private:
uint8_t _level;
std::string _name;
public:
LevelMove(uint8_t level, std::string name);
[[nodiscard]] inline uint8_t GetLevel() const;
@ -23,10 +24,10 @@ namespace CreatureLib::Library{
std::vector<std::string> _machineMoves;
std::vector<std::string> _tutorMoves;
std::vector<std::string> _variantDependentMoves;
public:
// TODO: Public API funcs
};
}
#endif // CREATURELIB_CREATUREMOVES_HPP

View File

@ -2,30 +2,19 @@
using namespace CreatureLib::Library;
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness)
:
__Id(id),
__GenderRate(genderRatio),
__GrowthRate(std::move(growthRate)),
__CaptureRate(captureRate),
__BaseHappiness(baseHappiness),
_variants({{"default", defaultVariant}}),
_name(std::move(name))
{}
CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
std::string growthRate, uint8_t captureRate, uint8_t baseHappiness)
: __Id(id), __GenderRate(genderRatio), __GrowthRate(std::move(growthRate)), __CaptureRate(captureRate),
__BaseHappiness(baseHappiness), _variants({{"default", defaultVariant}}), _name(std::move(name)) {}
const SpeciesVariant *CreatureSpecies::GetVariant(const std::string& key) const {
return _variants.at(key);
}
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& key) const { return _variants.at(key); }
Gender CreatureSpecies::GetRandomGender(CreatureLib::Core::Random& rand) const {
// TODO: Genderless creatures
auto val = rand.GetDouble();
if (val >= this->__GenderRate) return Gender ::Female;
if (val >= this->__GenderRate)
return Gender ::Female;
return Gender ::Male;
}
const std::string &CreatureSpecies::GetName() const {
return _name;
}
const std::string& CreatureSpecies::GetName() const { return _name; }

View File

@ -3,12 +3,13 @@
#include <string>
#include <unordered_map>
#include "SpeciesVariant.hpp"
#include "../Gender.hpp"
#include "SpeciesVariant.hpp"
namespace CreatureLib::Library {
/*!
\brief This holds the data required for a species of a creature, so the general data we can describe different creatures with.
\brief This holds the data required for a species of a creature, so the general data we can describe different
creatures with.
*/
class CreatureSpecies {
GetProperty(uint16_t, Id);
@ -16,12 +17,14 @@ namespace CreatureLib::Library {
GetProperty(std::string, GrowthRate);
GetProperty(uint8_t, CaptureRate);
GetProperty(uint8_t, BaseHappiness);
private:
std::unordered_map<std::string, const SpeciesVariant*> _variants;
std::string _name;
public:
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant,
float genderRatio, std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
CreatureSpecies(uint16_t id, std::string name, const SpeciesVariant* defaultVariant, float genderRatio,
std::string growthRate, uint8_t captureRate, uint8_t baseHappiness);
~CreatureSpecies() {
for (auto v : _variants)

View File

@ -2,9 +2,7 @@
using namespace CreatureLib::Library;
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData *attack) {
_learnedByLevel[level].push_back(attack);
}
void LearnableAttacks::AddLevelMove(uint8_t level, AttackData* attack) { _learnedByLevel[level].push_back(attack); }
const std::vector<const AttackData*>& LearnableAttacks::GetMovesForLevel(uint8_t level) const {
return _learnedByLevel[level];

View File

@ -7,9 +7,9 @@
namespace CreatureLib::Library {
class LearnableAttacks {
std::vector<std::vector<const AttackData*>> _learnedByLevel;
public:
LearnableAttacks(uint8_t maxLevel)
:_learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)){}
LearnableAttacks(uint8_t maxLevel) : _learnedByLevel(std::vector<std::vector<const AttackData*>>(maxLevel)) {}
void AddLevelMove(uint8_t level, AttackData* attack);
@ -17,5 +17,4 @@ namespace CreatureLib::Library {
};
}
#endif // CREATURELIB_LEARNABLEATTACKS_HPP

View File

@ -2,17 +2,11 @@
#include <algorithm>
#include <utility>
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const {
return _types;
}
const std::vector<uint8_t>& CreatureLib::Library::SpeciesVariant::GetTypes() const { return _types; }
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const {
return _types.size();
}
size_t CreatureLib::Library::SpeciesVariant::GetTypeCount() const { return _types.size(); }
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const {
return _types[index];
}
uint8_t CreatureLib::Library::SpeciesVariant::GetType(size_t index) const { return _types[index]; }
uint32_t CreatureLib::Library::SpeciesVariant::GetStatistic(CreatureLib::Core::Statistic stat) const {
return _baseStatistics.GetStat(stat);
@ -54,18 +48,10 @@ CreatureLib::Library::SpeciesVariant::SpeciesVariant(std::string name, float hei
uint32_t baseExperience, std::vector<uint8_t> types,
CreatureLib::Core::StatisticSet<uint16_t> baseStats,
std::vector<std::string> talents,
std::vector<std::string> secretTalents, const LearnableAttacks* attacks)
: __Name(std::move(name)),
__Height(height),
__Weight(weight),
__BaseExperience(baseExperience),
_types(std::move(types)),
_baseStatistics(baseStats),
_talents(std::move(talents)),
_secretTalents(std::move(secretTalents)),
_attacks(attacks)
{}
std::vector<std::string> secretTalents,
const LearnableAttacks* attacks)
: __Name(std::move(name)), __Height(height), __Weight(weight), __BaseExperience(baseExperience),
_types(std::move(types)), _baseStatistics(baseStats), _talents(std::move(talents)),
_secretTalents(std::move(secretTalents)), _attacks(attacks) {}
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() {
delete _attacks;
}
CreatureLib::Library::SpeciesVariant::~SpeciesVariant() { delete _attacks; }

View File

@ -3,10 +3,10 @@
#include <string>
#include <vector>
#include "CreatureMoves.hpp"
#include "../../Core/Random.hpp"
#include "../../Core/StatisticSet.hpp"
#include "../../GenericTemplates.cpp"
#include "../../Core/Random.hpp"
#include "CreatureMoves.hpp"
#include "LearnableAttacks.hpp"
namespace CreatureLib::Library {
@ -18,16 +18,19 @@ namespace CreatureLib::Library {
GetProperty(float, Height);
GetProperty(float, Weight);
GetProperty(uint32_t, BaseExperience);
private:
std::vector<uint8_t> _types;
const Core::StatisticSet<uint16_t> _baseStatistics;
std::vector<std::string> _talents;
std::vector<std::string> _secretTalents;
const LearnableAttacks* _attacks;
public:
SpeciesVariant(std::string name, float height, float weight, uint32_t baseExperience,
std::vector<uint8_t> types, Core::StatisticSet<uint16_t > baseStats, std::vector<std::string> talents,
std::vector<std::string> secretTalents, const LearnableAttacks* attacks);
std::vector<uint8_t> types, Core::StatisticSet<uint16_t> baseStats,
std::vector<std::string> talents, std::vector<std::string> secretTalents,
const LearnableAttacks* attacks);
~SpeciesVariant();

View File

@ -1,15 +1,12 @@
#include "DataLibrary.hpp"
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings,
CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks,
CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates,
TypeLibrary* typeLibrary)
: _settings(settings), _species(species), _attacks(attacks), _items(items),
_growthRates(growthRates), _typeLibrary(typeLibrary){
}
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
_typeLibrary(typeLibrary) {}
const CreatureLib::Library::LibrarySettings& CreatureLib::Library::DataLibrary::GetSettings() const {
return _settings;
@ -23,9 +20,7 @@ const CreatureLib::Library::AttackLibrary *CreatureLib::Library::DataLibrary::Ge
return _attacks;
}
const CreatureLib::Library::ItemLibrary *CreatureLib::Library::DataLibrary::GetItemLibrary() const {
return _items;
}
const CreatureLib::Library::ItemLibrary* CreatureLib::Library::DataLibrary::GetItemLibrary() const { return _items; }
const CreatureLib::Library::GrowthRateLibrary* CreatureLib::Library::DataLibrary::GetGrowthRates() const {
return _growthRates;
@ -34,6 +29,3 @@ const CreatureLib::Library::GrowthRateLibrary *CreatureLib::Library::DataLibrary
const CreatureLib::Library::TypeLibrary* CreatureLib::Library::DataLibrary::GetTypeLibrary() const {
return _typeLibrary;
}

View File

@ -1,11 +1,11 @@
#ifndef CREATURELIB_DATALIBRARY_HPP
#define CREATURELIB_DATALIBRARY_HPP
#include "SpeciesLibrary.hpp"
#include "AttackLibrary.hpp"
#include "ItemLibrary.hpp"
#include "GrowthRates/GrowthRateLibrary.hpp"
#include "ItemLibrary.hpp"
#include "LibrarySettings.hpp"
#include "SpeciesLibrary.hpp"
#include "TypeLibrary.hpp"
namespace CreatureLib::Library {
@ -20,14 +20,11 @@ namespace CreatureLib::Library {
const ItemLibrary* _items;
const GrowthRateLibrary* _growthRates;
const TypeLibrary* _typeLibrary;
public:
DataLibrary(LibrarySettings settings,
CreatureLib::Library::SpeciesLibrary *species,
CreatureLib::Library::AttackLibrary *attacks,
CreatureLib::Library::ItemLibrary *items,
CreatureLib::Library::GrowthRateLibrary *growthRates,
TypeLibrary* typeLibrary
);
DataLibrary(LibrarySettings settings, CreatureLib::Library::SpeciesLibrary* species,
CreatureLib::Library::AttackLibrary* attacks, CreatureLib::Library::ItemLibrary* items,
CreatureLib::Library::GrowthRateLibrary* growthRates, TypeLibrary* typeLibrary);
~DataLibrary() {
delete _species;
@ -46,5 +43,4 @@ namespace CreatureLib::Library {
};
}
#endif // CREATURELIB_DATALIBRARY_HPP

View File

@ -8,11 +8,7 @@ namespace CreatureLib::Library{
\brief Might be somewhat controversial nowadays, but as many creature battling games only have two genders, we'll
hardcode those.
*/
enum class Gender : uint8_t {
Male,
Female,
Genderless
};
enum class Gender : uint8_t { Male, Female, Genderless };
}
#endif // CREATURELIB_GENDER_HPP

View File

@ -1,9 +1,11 @@
#include "GrowthRateLibrary.hpp"
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string &growthRate, uint32_t experience) const {
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
uint32_t experience) const {
return _growthRates.at(growthRate)->CalculateLevel(experience);
}
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string &growthRate, uint8_t level) const {
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
uint8_t level) const {
return _growthRates.at(growthRate)->CalculateExperience(level);
}

View File

@ -10,6 +10,7 @@ namespace CreatureLib::Library{
class GrowthRateLibrary {
private:
std::unordered_map<std::string, GrowthRate*> _growthRates;
public:
[[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const;
[[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;

View File

@ -12,6 +12,4 @@ void CreatureLib::Library::ItemLibrary::LoadItem(const std::string &name, const
this->_items.insert({name, item});
}
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string &name) {
this->_items.erase(name);
}
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string& name) { this->_items.erase(name); }

View File

@ -9,20 +9,17 @@ namespace CreatureLib::Library {
class ItemLibrary {
private:
std::unordered_map<std::string, const Item*> _items;
public:
ItemLibrary() = default;
~ItemLibrary(){
_items.clear();
}
~ItemLibrary() { _items.clear(); }
[[nodiscard]] const Item* GetItem(const std::string& name) const;
[[nodiscard]] const Item* operator[](const std::string& name) const;
void LoadItem(const std::string& name, const Item* item);
void DeleteItem(const std::string& name);
};
}
#endif // CREATURELIB_ITEMLIBRARY_HPP

View File

@ -4,13 +4,7 @@
#include <cstdint>
namespace CreatureLib::Library {
enum class BattleItemCategory : uint8_t {
None,
Healing,
StatusHealing,
CaptureDevice,
MiscBattleItem
};
enum class BattleItemCategory : uint8_t { None, Healing, StatusHealing, CaptureDevice, MiscBattleItem };
}
#endif // CREATURELIB_BATTLEITEMCATEGORY_HPP

View File

@ -3,9 +3,9 @@
#include <string>
#include <unordered_set>
#include "ItemCategory.hpp"
#include "BattleItemCategory.hpp"
#include "../../GenericTemplates.cpp"
#include "BattleItemCategory.hpp"
#include "ItemCategory.hpp"
namespace CreatureLib::Library {
class Item {
@ -13,8 +13,10 @@ namespace CreatureLib::Library {
GetProperty(ItemCategory, Category);
GetProperty(BattleItemCategory, BattleCategory);
GetProperty(int32_t, Price);
private:
std::unordered_set<std::string> _flags;
public:
Item(std::string name, ItemCategory category, BattleItemCategory battleCategory, int32_t price,
std::unordered_set<std::string> flags);

View File

@ -7,17 +7,14 @@ namespace CreatureLib::Library {
class LibrarySettings {
uint8_t _maximalLevel;
uint8_t _maximalMoves;
public:
LibrarySettings(uint8_t maximalLevel, uint8_t maximalMoves)
: _maximalLevel(maximalLevel), _maximalMoves(maximalMoves) {}
inline uint8_t GetMaximalLevel() const{
return _maximalLevel;
}
inline uint8_t GetMaximalLevel() const { return _maximalLevel; }
inline uint8_t GetMaximalMoves() const{
return _maximalMoves;
}
inline uint8_t GetMaximalMoves() const { return _maximalMoves; }
};
}

View File

@ -1,10 +1,12 @@
#include "SpeciesLibrary.hpp"
const CreatureLib::Library::CreatureSpecies *CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const{
const CreatureLib::Library::CreatureSpecies*
CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const {
return _species.at(name);
}
const CreatureLib::Library::CreatureSpecies* CreatureLib::Library::SpeciesLibrary::operator[](const std::string &name) const{
const CreatureLib::Library::CreatureSpecies*
CreatureLib::Library::SpeciesLibrary::operator[](const std::string& name) const {
return GetSpecies(name);
}
@ -13,7 +15,4 @@ void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string &name,
_species.insert({name, species});
}
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string &name) {
_species.erase(name);
}
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string& name) { _species.erase(name); }

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Library {
class SpeciesLibrary {
private:
std::unordered_map<std::string, const CreatureSpecies*> _species;
public:
SpeciesLibrary() = default;
@ -26,5 +27,4 @@ namespace CreatureLib::Library {
};
}
#endif // CREATURELIB_SPECIESLIBRARY_HPP

View File

@ -14,9 +14,7 @@ float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive)
return _effectiveness[attacking][defensive];
}
uint8_t TypeLibrary::GetTypeId(const std::string &s) const {
return _types.at(s);
}
uint8_t TypeLibrary::GetTypeId(const std::string& s) const { return _types.at(s); }
uint8_t TypeLibrary::RegisterType(const std::string& typeName) {
_types.insert({typeName, _types.size()});

View File

@ -8,6 +8,7 @@ namespace CreatureLib::Library{
class TypeLibrary {
std::unordered_map<std::string, uint8_t> _types;
std::vector<std::vector<float>> _effectiveness;
public:
uint8_t GetTypeId(const std::string& s) const;
float GetSingleEffectiveness(uint8_t attacking, uint8_t defensive) const;
@ -18,5 +19,4 @@ namespace CreatureLib::Library{
};
}
#endif // CREATURELIB_TYPELIBRARY_HPP

View File

@ -1,9 +1,9 @@
#ifdef TESTS_BUILD
#include "../TestLibrary/TestLibrary.cpp"
#include "../../src/Battling/Models/BattleSide.hpp"
#include "../../src/Battling/Models/CreateCreature.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib::Battling;
@ -64,5 +64,4 @@ TEST_CASE( "Set Choice two-sized side, validate all choices set", "[Battling]" )
delete c2;
}
#endif

View File

@ -1,12 +1,9 @@
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptAggregator.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
@ -14,10 +11,7 @@ class TestScript : public Script{
public:
explicit TestScript(std::string name) : Script(std::move(name)){};
void TestMethod(int& runCount) {
runCount++;
}
void TestMethod(int& runCount) { runCount++; }
};
TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling, Scripting]") {
@ -162,8 +156,4 @@ TEST_CASE( "Script Aggregator properly iterates empty Script Set.", "[Battling,
CHECK(ran == 1);
}
#endif

View File

@ -1,14 +1,12 @@
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
auto set = ScriptSet();
REQUIRE(set.Count() == 0);
@ -85,9 +83,4 @@ TEST_CASE( "Add two scripts to script set, then remove them", "[Battling, Script
delete s2;
}
#endif

View File

@ -1,9 +1,8 @@
#ifdef TESTS_BUILD
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptSource.hpp"
#include <utility>
#include "../../../extern/catch.hpp"
#include "../../../src/Battling/ScriptHandling/ScriptAggregator.hpp"
using namespace CreatureLib;
@ -13,29 +12,24 @@ class TestScript : public Script{
public:
explicit TestScript(std::string name) : Script(std::move(name)){};
void TestMethod(int& runCount) {
runCount++;
}
void TestMethod(int& runCount) { runCount++; }
};
class ScriptSourceWithScriptPtr : public ScriptSource {
public:
Script* ScriptPtr = nullptr;
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
scripts.emplace_back(&ScriptPtr);
}
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&ScriptPtr); }
};
class ScriptSourceWithScriptSet : public ScriptSource {
public:
ScriptSet Set;
protected:
void GetActiveScripts(std::vector<ScriptWrapper> &scripts) override {
scripts.emplace_back(&Set);
}
};
protected:
void GetActiveScripts(std::vector<ScriptWrapper>& scripts) override { scripts.emplace_back(&Set); }
};
TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptPtr();
@ -100,6 +94,4 @@ TEST_CASE( "Script source with multiple item script set.", "[Battling, Scripting
delete s2;
}
#endif

View File

@ -1,9 +1,9 @@
#ifdef TESTS_BUILD
#include "../TestLibrary/TestLibrary.cpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/Flow/TurnOrdering.hpp"
#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp"
#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp"
#include "../TestLibrary/TestLibrary.cpp"
using namespace CreatureLib;
using namespace CreatureLib::Battling;
@ -113,6 +113,4 @@ TEST_CASE( "Turn ordering: No priority goes before low priority", "[Battling]" )
delete a2;
}
#endif

View File

@ -1,7 +1,7 @@
#ifdef TESTS_BUILD
#include "../extern/catch.hpp"
#include "../src/Core/Random.hpp"
#include "../src/Core/Exceptions/CreatureException.hpp"
#include "../src/Core/Random.hpp"
TEST_CASE("Random ints", "[Utilities]") {
auto rand = CreatureLib::Core::Random(10);
@ -39,7 +39,6 @@ TEST_CASE( "Random ints with limit", "[Utilities]" ) {
CHECK(rand.Get(2) == 0);
CHECK(rand.Get(2) == 0);
CHECK(rand.Get(2) == 0);
}
TEST_CASE("Random ints with upper and bottom", "[Utilities]") {
@ -81,8 +80,10 @@ TEST_CASE( "Random distribution (max 0, min 2)", "[Utilities]" ) {
for (size_t i = 0; i < size; i++) {
if (arr[i] != 0 && arr[i] != 1)
throw CreatureException("We expected a value of 0 or 1 here, but got a " + std::to_string(arr[i]));
if (arr[i] == 0) numZeros++;
else numOnes++;
if (arr[i] == 0)
numZeros++;
else
numOnes++;
}
auto div = static_cast<float>(numZeros) / static_cast<float>(numOnes);
INFO("Distribution: " << numZeros << "/" << numOnes);
@ -102,9 +103,12 @@ TEST_CASE( "Random distribution (max 0, min 3)", "[Utilities]" ) {
for (size_t i = 0; i < size; i++) {
if (arr[i] != 0 && arr[i] != 1 && arr[i] != 2)
throw CreatureException("We expected a value between 0 and 2 here, but got a " + std::to_string(arr[i]));
if (arr[i] == 0) numZeros++;
else if (arr[i] == 1) numOnes++;
else numTwos++;
if (arr[i] == 0)
numZeros++;
else if (arr[i] == 1)
numOnes++;
else
numTwos++;
}
INFO("Distribution: " << numZeros << "/" << numOnes << "/" << numTwos);
CHECK(Approx(static_cast<float>(numZeros) / static_cast<float>(numOnes)).margin(0.01) == 1);
@ -112,6 +116,4 @@ TEST_CASE( "Random distribution (max 0, min 3)", "[Utilities]" ) {
CHECK(Approx(static_cast<float>(numOnes) / static_cast<float>(numTwos)).margin(0.01) == 1);
}
#endif

View File

@ -9,25 +9,25 @@ static BattleLibrary* __library = nullptr;
static SpeciesLibrary* BuildSpeciesLibrary() {
auto l = new SpeciesLibrary();
l->LoadSpecies("testSpecies1", new CreatureSpecies(0, "testSpecies1",
new SpeciesVariant("default", 1,1, 10, {0, 1},
StatisticSet<uint16_t >(10,10,10,10,10,10),
{"testTalent"}, {"testSecretTalent"},
new LearnableAttacks(100)),
l->LoadSpecies("testSpecies1",
new CreatureSpecies(
0, "testSpecies1",
new SpeciesVariant("default", 1, 1, 10, {0, 1}, StatisticSet<uint16_t>(10, 10, 10, 10, 10, 10),
{"testTalent"}, {"testSecretTalent"}, new LearnableAttacks(100)),
0.5f, "testGrowthRate", 5, 100));
return l;
}
static AttackLibrary* BuildAttackLibrary() {
auto l = new AttackLibrary();
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,0, {}));
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,1, {}));
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,2, {}));
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical,
20, 100, 30, AttackTarget::AdjacentOpponent,-1, {}));
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 0, {}));
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 1, {}));
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 2, {}));
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, -1, {}));
return l;
}
@ -50,15 +50,14 @@ static TypeLibrary* BuildTypeLibrary(){
}
static BattleLibrary* BuildLibrary() {
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(),
BuildItemLibrary(), BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(),
new CriticalLibrary(), new ScriptResolver());
auto l = new DataLibrary(LibrarySettings(100, 4), BuildSpeciesLibrary(), BuildAttackLibrary(), BuildItemLibrary(),
BuildGrowthRateLibrary(), BuildTypeLibrary());
auto battleLib = new BattleLibrary(l, new BattleStatCalculator(), new DamageLibrary(), new CriticalLibrary(),
new ScriptResolver());
return battleLib;
}
[[maybe_unused]]
static BattleLibrary* GetLibrary(){
[[maybe_unused]] static BattleLibrary* GetLibrary() {
if (__library == nullptr) {
__library = BuildLibrary();
}