Made Battle take battleparties as a pointer instead of value for external use.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-07 11:00:48 +01:00
parent e990c13109
commit 1d18066bcc
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
4 changed files with 30 additions and 27 deletions

View File

@ -90,8 +90,8 @@ void Battle::SwitchCreature(uint8_t sideIndex, uint8_t index, Creature* c) {
bool Battle::CanSlotBeFilled(uint8_t side, uint8_t index) const {
for (const auto& party : _parties) {
if (party.IsResponsibleForIndex(side, index)) {
if (party.HasCreaturesNotInField())
if (party->IsResponsibleForIndex(side, index)) {
if (party->HasCreaturesNotInField())
return true;
}
}

View File

@ -15,7 +15,7 @@
namespace CreatureLib::Battling {
class Battle : public ScriptSource {
const BattleLibrary* _library;
std::vector<BattleParty> _parties;
std::vector<BattleParty*> _parties;
bool _canFlee;
uint8_t _numberOfSides;
uint8_t _creaturesPerSide;
@ -29,7 +29,7 @@ namespace CreatureLib::Battling {
ScriptSet _volatile;
public:
Battle(const BattleLibrary* library, std::vector<BattleParty> parties, bool canFlee = true,
Battle(const BattleLibrary* library, std::vector<BattleParty*> parties, bool canFlee = true,
uint8_t numberOfSides = 2, uint8_t creaturesPerSide = 1)
: _library(library), _parties(parties), _canFlee(canFlee), _numberOfSides(numberOfSides),
_creaturesPerSide(creaturesPerSide) {
@ -43,6 +43,9 @@ namespace CreatureLib::Battling {
for (auto s : _sides) {
delete s;
}
for (auto party : _parties) {
delete party;
}
delete _currentTurnQueue;
}

View File

@ -13,10 +13,10 @@ namespace CreatureLib::Battling {
BattleParty(CreatureParty* party, std::vector<CreatureIndex> responsibleIndices)
: _party(party), _responsibleIndices(responsibleIndices) {}
CreatureParty* GetParty() { return _party; }
const std::vector<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
inline CreatureParty* GetParty() const { return _party; }
inline const std::vector<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
bool IsResponsibleForIndex(const CreatureIndex& index) const {
inline bool IsResponsibleForIndex(const CreatureIndex& index) const {
for (const auto& i : _responsibleIndices) {
if (i == index)
return true;
@ -24,7 +24,7 @@ namespace CreatureLib::Battling {
return false;
}
bool IsResponsibleForIndex(uint8_t side, uint8_t index) const {
inline bool IsResponsibleForIndex(uint8_t side, uint8_t index) const {
for (const auto& i : _responsibleIndices) {
if (i.GetSideIndex() == side && i.GetCreatureIndex() == index)
return true;
@ -32,7 +32,7 @@ namespace CreatureLib::Battling {
return false;
}
bool HasCreaturesNotInField() const {
inline bool HasCreaturesNotInField() const {
auto p = _party->GetParty();
for (const auto& creature : p) {
if (creature == nullptr)

View File

@ -25,11 +25,11 @@ TEST_CASE("Create Battle", "[Integrations]") {
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
}
@ -39,11 +39,11 @@ TEST_CASE("Use damaging move", "[Integrations]") {
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -61,11 +61,11 @@ TEST_CASE("Finish battle when all battle of one side have fainted", "[Integratio
auto c1 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -96,11 +96,11 @@ TEST_CASE("When creature is dealt enough damage, faint it and mark battle as end
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -125,13 +125,13 @@ TEST_CASE("When another creature is available on faint, make sure the battle has
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2, c3};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -165,11 +165,11 @@ TEST_CASE("Switch Creature in", "[Integrations]") {
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -191,11 +191,11 @@ TEST_CASE("Switch Creature in, but have attack aimed at it. Attack should hit ne
auto c2 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 50).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -216,11 +216,11 @@ TEST_CASE("Switch Creature in, mark as seen opponent for opponent", "[Integratio
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1, c2};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c3 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c3};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});
@ -253,11 +253,11 @@ TEST_CASE("Flee Battle", "[Integrations]") {
auto c1 =
CreateCreature(library, "testSpecies1", 100).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party1{c1};
auto battleParty1 = BattleParty(&party1, {CreatureIndex(0, 0)});
auto battleParty1 = new BattleParty(&party1, {CreatureIndex(0, 0)});
auto c2 =
CreateCreature(library, "testSpecies1", 1).WithAttack("standard"_cnc, AttackLearnMethod::Unknown)->Create();
CreatureParty party2{c2};
auto battleParty2 = BattleParty(&party2, {CreatureIndex(1, 0)});
auto battleParty2 = new BattleParty(&party2, {CreatureIndex(1, 0)});
auto battle = Battle(library, {battleParty1, battleParty2});