Store CreatureIndex on Creature, includes helper function to get a creatures party from a battle.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
parent
305eb5efb2
commit
188e88ab80
|
@ -209,3 +209,23 @@ Battle* Battle::Clone() const {
|
|||
|
||||
return battle;
|
||||
}
|
||||
ArbUt::OptionalBorrowedPtr<BattleParty> Battle::FindPartyForCreature(const ArbUt::BorrowedPtr<Creature>& creature) {
|
||||
if (creature->IsOnBattleField()) {
|
||||
auto index = creature->GetBattleIndex();
|
||||
for (auto& party : _parties) {
|
||||
if (!party->IsResponsibleForIndex(index)) {
|
||||
continue;
|
||||
}
|
||||
if (party->GetParty()->HasCreature(creature)) {
|
||||
return party;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto& party : _parties) {
|
||||
if (party->GetParty()->HasCreature(creature)) {
|
||||
return party;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
|
@ -85,6 +85,8 @@ namespace CreatureLib::Battling {
|
|||
inline const BattleResult& GetResult() const noexcept { return _battleResult; }
|
||||
|
||||
const ArbUt::UniquePtrList<BattleParty>& GetParties() const noexcept { return _parties; }
|
||||
ArbUt::OptionalBorrowedPtr<BattleParty> FindPartyForCreature(const ArbUt::BorrowedPtr<Creature>&);
|
||||
|
||||
const ArbUt::UniquePtrList<BattleSide>& GetSides() const noexcept { return _sides; }
|
||||
ArbUt::OptionalBorrowedPtr<BattleScript> GetVolatileScript(const ArbUt::StringView& key) const {
|
||||
return _volatile.Get(key);
|
||||
|
|
|
@ -60,6 +60,7 @@ void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint
|
|||
}
|
||||
creature.GetValue()->SetBattleData(_battle, this);
|
||||
creature.GetValue()->SetOnBattleField(true);
|
||||
creature.GetValue()->SetBattleIndex(CreatureIndex(_index, index));
|
||||
for (auto* side : _battle->GetSides()) {
|
||||
if (side == this) {
|
||||
continue;
|
||||
|
|
|
@ -353,6 +353,7 @@ namespace CreatureLib::Battling {
|
|||
c->_battleData.Battle = _battleData.Battle;
|
||||
c->_battleData.Side = _battleData.Side;
|
||||
c->_battleData.OnBattleField = _battleData.OnBattleField;
|
||||
c->_battleData.Index = _battleData.Index;
|
||||
if (_activeTalent != nullptr) {
|
||||
c->_activeTalent = std::unique_ptr<BattleScript>(_activeTalent->Clone());
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "../ScriptHandling/ScriptAggregator.hpp"
|
||||
#include "../ScriptHandling/ScriptSet.hpp"
|
||||
#include "../ScriptHandling/ScriptSource.hpp"
|
||||
#include "CreatureIndex.hpp"
|
||||
#include "DamageSource.hpp"
|
||||
#include "LearnedAttack.hpp"
|
||||
|
||||
|
@ -40,12 +41,12 @@ namespace CreatureLib::Battling {
|
|||
Library::StatisticSet<uint32_t> _boostedStats;
|
||||
|
||||
struct BattleData {
|
||||
bool OnBattleField = false;
|
||||
ArbUt::OptionalBorrowedPtr<Battle> Battle = nullptr;
|
||||
ArbUt::OptionalBorrowedPtr<BattleSide> Side = nullptr;
|
||||
bool OnBattleField = false;
|
||||
CreatureIndex Index = {};
|
||||
std::unordered_set<ArbUt::BorrowedPtr<Creature>> SeenOpponents;
|
||||
};
|
||||
BattleData _battleData = {};
|
||||
} _battleData = {};
|
||||
|
||||
std::string _nickname = {};
|
||||
CreatureLib::Library::TalentIndex _talentIndex = {};
|
||||
|
@ -112,6 +113,8 @@ namespace CreatureLib::Battling {
|
|||
inline const ArbUt::OptionalBorrowedPtr<Battle>& GetBattle() const { return _battleData.Battle; }
|
||||
inline const ArbUt::OptionalBorrowedPtr<BattleSide>& GetBattleSide() const { return _battleData.Side; }
|
||||
inline void SetOnBattleField(bool value) { _battleData.OnBattleField = value; }
|
||||
inline void SetBattleIndex(const CreatureIndex& index) { _battleData.Index = index; }
|
||||
inline const CreatureIndex& GetBattleIndex() const noexcept { return _battleData.Index; }
|
||||
inline bool IsOnBattleField() const { return _battleData.OnBattleField; }
|
||||
|
||||
inline std::string_view GetNickname() const noexcept { return _nickname; }
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CREATURELIB_CREATUREINDEX_HPP
|
||||
#define CREATURELIB_CREATUREINDEX_HPP
|
||||
|
||||
#include "Creature.hpp"
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
class CreatureIndex {
|
||||
uint8_t _side;
|
||||
|
|
|
@ -63,6 +63,9 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
}
|
||||
}
|
||||
inline bool HasCreature(ArbUt::BorrowedPtr<Creature> creature) const noexcept {
|
||||
return _party.Contains(creature);
|
||||
}
|
||||
|
||||
virtual CreatureParty* Clone() const {
|
||||
auto party = new CreatureParty(_party.Count());
|
||||
|
|
Loading…
Reference in New Issue