From 7435a2a678f1b2bb19bf236753465fd8269cff96 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 11 Mar 2020 12:22:13 +0100 Subject: [PATCH] Turnchoices C Interface. --- CInterface/Battling/TurnChoices.cpp | 39 +++++++++++++++++++ src/Battling/TurnChoices/AttackTurnChoice.hpp | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 CInterface/Battling/TurnChoices.cpp diff --git a/CInterface/Battling/TurnChoices.cpp b/CInterface/Battling/TurnChoices.cpp new file mode 100644 index 0000000..02e5431 --- /dev/null +++ b/CInterface/Battling/TurnChoices.cpp @@ -0,0 +1,39 @@ +#include "../../src/Battling/TurnChoices/AttackTurnChoice.hpp" +#include "../../src/Battling/TurnChoices/FleeTurnChoice.hpp" +#include "../../src/Battling/TurnChoices/PassTurnChoice.hpp" +#include "../../src/Battling/TurnChoices/SwitchTurnChoice.hpp" +#define export extern "C" +using namespace CreatureLib::Battling; + +export AttackTurnChoice* CreatureLib_AttackTurnChoice_Construct(Creature* user, LearnedAttack* attack, + uint8_t sideIndex, uint8_t targetIndex) { + return new AttackTurnChoice(user, attack, CreatureIndex(sideIndex, targetIndex)); +} +export FleeTurnChoice* CreatureLib_FleeTurnChoice_Construct(Creature* user) { return new FleeTurnChoice(user); } +export PassTurnChoice* CreatureLib_PassTurnChoice_Construct(Creature* user) { return new PassTurnChoice(user); } +export SwitchTurnChoice* CreatureLib_SwitchTurnChoice_Construct(Creature* user, Creature* newCreature) { + return new SwitchTurnChoice(user, newCreature); +} + +export void CreatureLib_BaseTurnChoice_Destruct(const BaseTurnChoice* p) { delete p; } + +#define SIMPLE_GET_FUNC(type, name, returnType) \ + export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); } + +SIMPLE_GET_FUNC(BaseTurnChoice, GetKind, TurnChoiceKind) +SIMPLE_GET_FUNC(BaseTurnChoice, GetUser, Creature*) + +SIMPLE_GET_FUNC(AttackTurnChoice, GetAttack, LearnedAttack*) +SIMPLE_GET_FUNC(AttackTurnChoice, GetKind, TurnChoiceKind) +SIMPLE_GET_FUNC(AttackTurnChoice, GetPriority, int8_t) +SIMPLE_GET_FUNC(AttackTurnChoice, GetAttackScript, Script*) +export uint8_t CreatureLib_BaseTurnChoice_GetTargetSideIndex(const AttackTurnChoice* p) { + return p->GetTarget().GetSideIndex(); +} +export uint8_t CreatureLib_BaseTurnChoice_GetTargetCreatureIndex(const AttackTurnChoice* p) { + return p->GetTarget().GetCreatureIndex(); +} + +SIMPLE_GET_FUNC(SwitchTurnChoice, GetNewCreature, Creature*) + +#undef SIMPLE_GET_FUNC \ No newline at end of file diff --git a/src/Battling/TurnChoices/AttackTurnChoice.hpp b/src/Battling/TurnChoices/AttackTurnChoice.hpp index f144868..4cb95f8 100644 --- a/src/Battling/TurnChoices/AttackTurnChoice.hpp +++ b/src/Battling/TurnChoices/AttackTurnChoice.hpp @@ -26,7 +26,7 @@ namespace CreatureLib::Battling { const CreatureIndex& GetTarget() const { return _target; } - Script* GetAttackScript() { return _attackScript; } + Script* GetAttackScript() const { return _attackScript; } protected: void GetActiveScripts(std::vector& scripts) override {