2019-10-17 12:33:25 +00:00
|
|
|
#ifndef CREATURELIB_BATTLESIDE_HPP
|
|
|
|
#define CREATURELIB_BATTLESIDE_HPP
|
|
|
|
|
2020-03-22 12:42:26 +00:00
|
|
|
#include <Arbutils/Assert.hpp>
|
2020-03-22 18:21:40 +00:00
|
|
|
#include <Arbutils/Collections/List.hpp>
|
2019-10-17 12:33:25 +00:00
|
|
|
#include <vector>
|
2019-10-29 10:19:25 +00:00
|
|
|
#include "../TurnChoices/BaseTurnChoice.hpp"
|
2019-11-28 11:55:22 +00:00
|
|
|
#include "Creature.hpp"
|
2019-10-17 12:33:25 +00:00
|
|
|
|
2020-03-22 18:21:40 +00:00
|
|
|
using namespace Arbutils::Collections;
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
namespace CreatureLib::Battling {
|
|
|
|
class BattleSide : public ScriptSource {
|
2019-12-07 11:13:12 +00:00
|
|
|
uint8_t _index;
|
2019-10-29 10:19:25 +00:00
|
|
|
uint8_t _creaturesPerSide;
|
2020-03-22 18:21:40 +00:00
|
|
|
List<Creature*> _creatures;
|
|
|
|
List<BaseTurnChoice*> _choices;
|
|
|
|
List<bool> _fillableSlots;
|
2019-11-06 17:08:21 +00:00
|
|
|
uint8_t _choicesSet = 0;
|
2019-11-10 13:32:05 +00:00
|
|
|
ScriptSet _volatile;
|
|
|
|
Battle* _battle;
|
2019-12-15 10:52:10 +00:00
|
|
|
bool _hasFled = false;
|
2019-11-28 11:55:22 +00:00
|
|
|
|
2019-10-29 10:19:25 +00:00
|
|
|
public:
|
2020-04-04 15:03:06 +00:00
|
|
|
BattleSide(uint8_t index, Battle* battle, uint8_t creaturesPerSide) noexcept
|
2020-03-22 12:42:26 +00:00
|
|
|
: _index(index), _creaturesPerSide(creaturesPerSide), _creatures(creaturesPerSide),
|
|
|
|
_choices(creaturesPerSide), _fillableSlots(creaturesPerSide), _battle(battle) {
|
2019-12-05 11:56:41 +00:00
|
|
|
for (size_t i = 0; i < creaturesPerSide; i++) {
|
|
|
|
_creatures[i] = nullptr;
|
|
|
|
_choices[i] = nullptr;
|
2019-12-07 20:56:29 +00:00
|
|
|
_fillableSlots[i] = true;
|
2019-12-05 11:56:41 +00:00
|
|
|
}
|
2019-10-29 10:19:25 +00:00
|
|
|
ResetChoices();
|
|
|
|
}
|
|
|
|
|
2019-12-05 11:56:41 +00:00
|
|
|
virtual ~BattleSide() = default;
|
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
[[nodiscard]] bool AllChoicesSet() const noexcept;
|
|
|
|
[[nodiscard]] const List<BaseTurnChoice*>& GetChoices() const noexcept;
|
2019-10-29 10:19:25 +00:00
|
|
|
|
2019-12-07 11:13:12 +00:00
|
|
|
[[nodiscard]] bool AllPossibleSlotsFilled() const;
|
|
|
|
|
2019-11-10 16:08:42 +00:00
|
|
|
void SetChoice(BaseTurnChoice* choice);
|
2020-04-04 15:03:06 +00:00
|
|
|
void ResetChoices() noexcept;
|
2019-10-29 10:19:25 +00:00
|
|
|
|
|
|
|
void SetCreature(Creature* creature, uint8_t index);
|
|
|
|
|
2019-11-02 12:57:43 +00:00
|
|
|
Creature* GetCreature(uint8_t index) const;
|
|
|
|
bool CreatureOnSide(const Creature* creature) const;
|
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override;
|
2019-12-07 20:56:29 +00:00
|
|
|
|
2020-03-22 18:21:40 +00:00
|
|
|
const List<Creature*>& GetCreatures() { return _creatures; }
|
2019-12-14 11:40:50 +00:00
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
uint8_t GetSideIndex() noexcept { return _index; }
|
2019-12-07 21:52:43 +00:00
|
|
|
uint8_t GetCreatureIndex(Creature* c) {
|
2020-03-22 18:21:40 +00:00
|
|
|
for (size_t i = 0; i < _creatures.Count(); i++) {
|
2019-12-07 21:52:43 +00:00
|
|
|
if (c == _creatures[i])
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
throw CreatureException("Unable to find creature on field.");
|
|
|
|
}
|
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
void MarkSlotAsUnfillable(Creature* creature) noexcept {
|
2019-12-07 21:52:43 +00:00
|
|
|
for (uint8_t i = 0; i < _creaturesPerSide; i++) {
|
|
|
|
if (_creatures[i] == creature) {
|
2020-03-22 18:21:40 +00:00
|
|
|
_fillableSlots.At(i) = false;
|
2019-12-07 20:56:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
bool IsDefeated() noexcept {
|
2019-12-07 21:52:43 +00:00
|
|
|
for (auto b : _fillableSlots) {
|
|
|
|
if (b)
|
|
|
|
return false;
|
2019-12-07 20:56:29 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-12-15 10:52:10 +00:00
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
bool HasFled() noexcept { return _hasFled; }
|
2019-12-15 10:52:10 +00:00
|
|
|
|
2020-04-04 15:03:06 +00:00
|
|
|
void MarkAsFled() noexcept { _hasFled = true; }
|
2020-03-22 09:30:45 +00:00
|
|
|
|
|
|
|
uint8_t GetRandomCreatureIndex();
|
2019-10-17 12:33:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
#endif // CREATURELIB_BATTLESIDE_HPP
|