Overhaul memory model to new Arbutils memory.
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-12-12 12:22:48 +01:00
parent 1dc3aafd33
commit 5c39694f19
33 changed files with 279 additions and 211 deletions

View File

@@ -11,7 +11,7 @@ bool BattleSide::AllPossibleSlotsFilled() const {
try {
for (size_t i = 0; i < _creatures.Count(); i++) {
auto c = _creatures[i];
if (c == nullptr || c->IsFainted()) {
if (!c.HasValue() || c.GetValue()->IsFainted()) {
if (_battle->CanSlotBeFilled(_index, i))
return false;
}
@@ -34,7 +34,10 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
try {
for (size_t i = 0; i < _creatures.Count(); i++) {
auto& c = _creatures[i];
if (c == choice->GetUser()) {
if (!c.HasValue()) {
continue;
}
if (c.GetValue() == choice->GetUser()) {
_choices[i] = std::shared_ptr<BaseTurnChoice>(choice);
_choicesSet++;
return;
@@ -46,37 +49,39 @@ void BattleSide::SetChoice(BaseTurnChoice* choice) {
THROW("User not found");
}
void BattleSide::SetCreature(ArbUt::BorrowedPtr<Creature> creature, uint8_t index) {
void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint8_t index) {
auto old = _creatures[index];
if (old != nullptr) {
old->SetOnBattleField(false);
if (old.HasValue()) {
old.GetValue()->SetOnBattleField(false);
}
_creatures[index] = creature;
if (creature != nullptr) {
creature->SetBattleData(_battle, this);
creature->SetOnBattleField(true);
}
if (_battle == nullptr)
_creatures[index] = creature.GetValue();
if (!creature.HasValue()) {
return;
for (auto side : _battle->GetSides()) {
if (side == this)
}
creature.GetValue()->SetBattleData(_battle, this);
creature.GetValue()->SetOnBattleField(true);
if (_battle == nullptr) {
return;
}
for (auto* side : _battle->GetSides()) {
if (side == this) {
continue;
}
for (const auto& c : side->GetCreatures()) {
if (c != nullptr) {
c->MarkOpponentAsSeen(creature);
creature->MarkOpponentAsSeen(c.GetRaw());
if (c.HasValue()) {
c.GetValue()->MarkOpponentAsSeen(creature.GetValue());
creature.GetValue()->MarkOpponentAsSeen(c.GetValue());
}
}
}
_battle->TriggerEventListener<SwitchEvent>(CreatureIndex(this->_index, index), creature);
_battle->TriggerEventListener<SwitchEvent>(CreatureIndex(this->_index, index), creature.GetValue());
}
bool BattleSide::CreatureOnSide(const ArbUt::BorrowedPtr<Creature>& creature) const {
AssertNotNull(creature)
return std::find(_creatures.begin(), _creatures.end(), creature) != _creatures.end();
return std::find(_creatures.begin(), _creatures.end(), creature.GetRaw()) != _creatures.end();
}
const ArbUt::BorrowedPtr<Creature>& BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
const ArbUt::OptionalBorrowedPtr<Creature>& BattleSide::GetCreature(uint8_t index) const { return _creatures[index]; }
void BattleSide::GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) {
scripts.Append(ScriptWrapper::FromSet(&_volatile));