Use smart pointers for BattleSide.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-06-02 13:06:24 +02:00
parent 49e8ff055d
commit f898698f49
20 changed files with 86 additions and 107 deletions

View File

@@ -26,15 +26,13 @@ void BattleSide::ResetChoices() noexcept {
}
}
const ArbUt::List<BaseTurnChoice*>& BattleSide::GetChoices() const noexcept { return _choices; }
void BattleSide::SetChoice(BaseTurnChoice* choice) {
AssertNotNull(choice)
auto find = std::find(_creatures.begin(), _creatures.end(), choice->GetUser());
if (find == _creatures.end())
throw CreatureException("User not found");
uint8_t index = std::distance(_creatures.begin(), find);
_choices[index] = choice;
_choices[index] = std::shared_ptr<BaseTurnChoice>(choice);
_choicesSet++;
}
@@ -56,18 +54,18 @@ void BattleSide::SetCreature(Creature* creature, uint8_t index) {
for (auto c : side->GetCreatures()) {
if (c != nullptr) {
c->MarkOpponentAsSeen(creature);
creature->MarkOpponentAsSeen(c);
creature->MarkOpponentAsSeen(c.GetRaw());
}
}
}
}
bool BattleSide::CreatureOnSide(const Creature* creature) const {
bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const {
AssertNotNull(creature)
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
}
Creature* BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
const ArbUt::BorrowedPtr<Creature>& BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
void BattleSide::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
scripts.Append(ScriptWrapper::FromSet(&_volatile));