Update to latest Arbutils.
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
2055837980
commit
e642f374b9
|
@ -116,8 +116,8 @@ Standard: Cpp11
|
|||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
- Assert
|
||||
- AssertNotNull
|
||||
- Ensure
|
||||
- EnsureNotNull
|
||||
- Try
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "ChoiceQueue.hpp"
|
||||
|
||||
bool CreatureLib::Battling::ChoiceQueue::MoveCreatureChoiceNext(CreatureLib::Battling::Creature* creature) {
|
||||
AssertNotNull(creature)
|
||||
EnsureNotNull(creature)
|
||||
// Find which index the creature choice is at.
|
||||
size_t choiceIndex = SIZE_MAX;
|
||||
for (size_t index = _current; index < _queue.size(); index++) {
|
||||
|
|
|
@ -7,16 +7,14 @@
|
|||
using namespace CreatureLib::Battling;
|
||||
|
||||
void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
|
||||
AssertNotNull(queue)
|
||||
for (auto choice : queue->GetInnerQueue()) {
|
||||
HOOK(OnBeforeTurn, choice, choice.get());
|
||||
}
|
||||
while (queue->HasNext()) {
|
||||
auto item = queue->Dequeue();
|
||||
AssertNotNull(item)
|
||||
AssertNotNull(item->GetUser())
|
||||
Assert(item->GetUser()->GetBattle().HasValue())
|
||||
Assert(item->GetUser()->GetBattleSide().HasValue())
|
||||
EnsureNotNull(item)
|
||||
Ensure(item->GetUser()->GetBattle().HasValue())
|
||||
Ensure(item->GetUser()->GetBattleSide().HasValue())
|
||||
auto index = (uint32_t)item->GetUser()->GetBattleSide().GetValue()->GetCreatureIndex(item->GetUser());
|
||||
|
||||
try_creature(ExecuteChoice(item.get()),
|
||||
|
@ -30,13 +28,11 @@ void TurnHandler::RunTurn(ArbUt::BorrowedPtr<ChoiceQueue> queue) {
|
|||
}
|
||||
|
||||
void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
|
||||
AssertNotNull(choice)
|
||||
auto choiceKind = choice->GetKind();
|
||||
if (choiceKind == TurnChoiceKind::Pass) {
|
||||
return;
|
||||
}
|
||||
auto user = choice->GetUser();
|
||||
AssertNotNull(user)
|
||||
if (!user->GetBattle().HasValue())
|
||||
return;
|
||||
auto battle = user->GetBattle().GetValue();
|
||||
|
@ -68,7 +64,6 @@ void TurnHandler::ExecuteChoice(ArbUt::BorrowedPtr<BaseTurnChoice> choice) {
|
|||
}
|
||||
|
||||
void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>& choice) {
|
||||
AssertNotNull(choice)
|
||||
auto battle = choice->GetUser()->GetBattle();
|
||||
auto attackName = choice->GetAttack()->GetAttack()->GetName();
|
||||
HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName);
|
||||
|
@ -78,7 +73,7 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
|
|||
|
||||
auto targetType = choice->GetAttack()->GetAttack()->GetTarget();
|
||||
ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> targets;
|
||||
Assert(battle.HasValue());
|
||||
Ensure(battle.HasValue());
|
||||
try_creature(targets = TargetResolver::ResolveTargets(choice->GetTarget(), targetType, battle.GetValue());
|
||||
, "Exception during target determination");
|
||||
|
||||
|
@ -124,12 +119,10 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
|
|||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target) {
|
||||
AssertNotNull(attack)
|
||||
EnsureNotNull(attack)
|
||||
auto& user = attack->GetUser();
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(target)
|
||||
auto& battle = user->GetBattle();
|
||||
Assert(battle.HasValue())
|
||||
Ensure(battle.HasValue())
|
||||
if (battle.GetValue()->HasEnded())
|
||||
return;
|
||||
|
||||
|
@ -155,18 +148,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
|||
}
|
||||
|
||||
auto& learnedAttack = attack->GetAttack();
|
||||
AssertNotNull(learnedAttack);
|
||||
auto& attackData = learnedAttack->GetAttack();
|
||||
AssertNotNull(attackData);
|
||||
|
||||
auto& library = battle.GetValue()->GetLibrary();
|
||||
AssertNotNull(library)
|
||||
auto& dmgLibrary = library->GetDamageLibrary();
|
||||
auto& typeLibrary = library->GetTypeLibrary();
|
||||
auto& miscLibrary = library->GetMiscLibrary();
|
||||
AssertNotNull(dmgLibrary)
|
||||
AssertNotNull(typeLibrary)
|
||||
AssertNotNull(miscLibrary)
|
||||
EnsureNotNull(dmgLibrary)
|
||||
EnsureNotNull(typeLibrary)
|
||||
EnsureNotNull(miscLibrary)
|
||||
|
||||
auto hitIterator = attack->GetTargetIteratorBegin(target);
|
||||
for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
|
||||
|
@ -229,7 +219,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
|||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
auto random = battle.GetValue()->GetRandom();
|
||||
AssertNotNull(random);
|
||||
EnsureNotNull(random);
|
||||
hasSecondaryEffect = random->EffectChance(effect->GetChance(), attack, target.GetRaw());
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
|
|
|
@ -15,8 +15,8 @@ public:
|
|||
if (aKind == TurnChoiceKind::Attack) {
|
||||
auto aAttack = std::dynamic_pointer_cast<AttackTurnChoice>(a);
|
||||
auto bAttack = std::dynamic_pointer_cast<AttackTurnChoice>(b);
|
||||
AssertNotNull(aAttack);
|
||||
AssertNotNull(bAttack);
|
||||
EnsureNotNull(aAttack);
|
||||
EnsureNotNull(bAttack);
|
||||
auto aPriority = aAttack->GetPriority();
|
||||
auto bPriority = bAttack->GetPriority();
|
||||
if (aPriority != bPriority)
|
||||
|
@ -24,8 +24,6 @@ public:
|
|||
}
|
||||
auto aUser = a->GetUser();
|
||||
auto bUser = b->GetUser();
|
||||
AssertNotNull(aUser);
|
||||
AssertNotNull(bUser);
|
||||
auto aSpeed = aUser->GetBoostedStat(Library::Statistic::Speed);
|
||||
auto bSpeed = bUser->GetBoostedStat(Library::Statistic::Speed);
|
||||
if (aSpeed != bSpeed)
|
||||
|
@ -37,10 +35,10 @@ public:
|
|||
|
||||
void TurnOrdering::OrderChoices(std::vector<std::shared_ptr<BaseTurnChoice>>& vec) {
|
||||
for (const auto& item : vec) {
|
||||
AssertNotNull(item);
|
||||
EnsureNotNull(item);
|
||||
if (item->GetKind() == TurnChoiceKind::Attack) {
|
||||
auto attackChoice = std::dynamic_pointer_cast<AttackTurnChoice>(item);
|
||||
AssertNotNull(attackChoice);
|
||||
EnsureNotNull(attackChoice);
|
||||
auto priority = attackChoice->GetPriority();
|
||||
HOOK(ChangePriority, attackChoice, attackChoice.get(), &priority);
|
||||
attackChoice->SetPriority(priority);
|
||||
|
|
|
@ -7,12 +7,12 @@ BattleLibrary::BattleLibrary(const CreatureLib::Library::DataLibrary* staticLib,
|
|||
ScriptResolver* scriptResolver, MiscLibrary* miscLibrary)
|
||||
: _staticLib(staticLib), _statCalculator(statCalculator), _damageLibrary(damageLibrary),
|
||||
_experienceLibrary(experienceLibrary), _scriptResolver(scriptResolver), _miscLibrary(miscLibrary) {
|
||||
AssertNotNull(_staticLib);
|
||||
AssertNotNull(_statCalculator);
|
||||
AssertNotNull(_damageLibrary);
|
||||
AssertNotNull(_experienceLibrary);
|
||||
AssertNotNull(_scriptResolver);
|
||||
AssertNotNull(_miscLibrary);
|
||||
EnsureNotNull(_staticLib);
|
||||
EnsureNotNull(_statCalculator);
|
||||
EnsureNotNull(_damageLibrary);
|
||||
EnsureNotNull(_experienceLibrary);
|
||||
EnsureNotNull(_scriptResolver);
|
||||
EnsureNotNull(_miscLibrary);
|
||||
}
|
||||
|
||||
const std::unique_ptr<const CreatureLib::Library::LibrarySettings>& BattleLibrary::GetSettings() const noexcept {
|
||||
|
|
|
@ -23,14 +23,14 @@ Battling::BattleStatCalculator::CalculateBoostedStats(Battling::Creature* creatu
|
|||
}
|
||||
|
||||
uint32_t CalculateHealthStat(Battling::Creature* creature) {
|
||||
AssertNotNull(creature)
|
||||
EnsureNotNull(creature)
|
||||
auto level = creature->GetLevel();
|
||||
float a = (creature->GetBaseStat(Library::Statistic::Health)) * 2.0 * level;
|
||||
return static_cast<uint32_t>(floor(a / 100.0) + level + 10);
|
||||
}
|
||||
|
||||
uint32_t CalculateOtherStat(Battling::Creature* creature, Library::Statistic stat) {
|
||||
AssertNotNull(creature)
|
||||
EnsureNotNull(creature)
|
||||
auto level = creature->GetLevel();
|
||||
float a = (creature->GetBaseStat(stat)) * 2.0 * level;
|
||||
return static_cast<uint32_t>(floor(a / 100.0) + 5);
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
using namespace CreatureLib::Battling;
|
||||
uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||
const ExecutingAttack::HitData& hitData) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
EnsureNotNull(attack)
|
||||
EnsureNotNull(target)
|
||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
|
||||
auto bp = hitData.GetBasePower();
|
||||
auto statMod = GetStatModifier(attack, target, hitIndex, hitData);
|
||||
|
@ -18,8 +18,8 @@ uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uin
|
|||
|
||||
uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||
[[maybe_unused]] const ExecutingAttack::HitData& hitData) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
EnsureNotNull(attack)
|
||||
EnsureNotNull(target)
|
||||
auto bp = attack->GetAttack()->GetAttack()->GetBasePower();
|
||||
HOOK(OverrideBasePower, attack, attack, target, hitIndex, &bp);
|
||||
return bp;
|
||||
|
@ -27,10 +27,10 @@ uint8_t DamageLibrary::GetBasePower(ExecutingAttack* attack, Creature* target, u
|
|||
|
||||
float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||
const ExecutingAttack::HitData& hitData) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
EnsureNotNull(attack)
|
||||
EnsureNotNull(target)
|
||||
auto user = attack->GetUser().GetRaw();
|
||||
AssertNotNull(user)
|
||||
EnsureNotNull(user)
|
||||
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
||||
Library::Statistic offensiveStat;
|
||||
Library::Statistic defensiveStat;
|
||||
|
@ -66,8 +66,8 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
|||
|
||||
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex,
|
||||
const ExecutingAttack::HitData& hitData) const {
|
||||
AssertNotNull(attack)
|
||||
AssertNotNull(target)
|
||||
EnsureNotNull(attack)
|
||||
EnsureNotNull(target)
|
||||
float mod = 1;
|
||||
mod *= hitData.GetEffectiveness();
|
||||
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
||||
|
|
|
@ -5,8 +5,6 @@ void CreatureLib::Battling::ExperienceLibrary::HandleExperienceGain(
|
|||
CreatureLib::Battling::Creature* faintedMon,
|
||||
const std::unordered_set<ArbUt::BorrowedPtr<Creature>>& opponents) const {
|
||||
for (auto opponent : opponents) {
|
||||
if (opponent == nullptr)
|
||||
continue;
|
||||
if (opponent->IsFainted())
|
||||
continue;
|
||||
if (!opponent->AllowedExperienceGain())
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
bool CreatureLib::Battling::MiscLibrary::IsCritical([[maybe_unused]] CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target,
|
||||
[[maybe_unused]] uint8_t hit) const {
|
||||
AssertNotNull(target)
|
||||
Assert(target->GetBattle().HasValue())
|
||||
EnsureNotNull(target)
|
||||
Ensure(target->GetBattle().HasValue())
|
||||
auto rand = target->GetBattle().GetValue()->GetRandom();
|
||||
return rand->Get(10) <= 0;
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ static CreatureLib::Battling::LearnedAttack* GetReplacementAttack() {
|
|||
bool CreatureLib::Battling::MiscLibrary::CanFlee([[maybe_unused]] FleeTurnChoice* switchChoice) const { return true; }
|
||||
CreatureLib::Battling::BaseTurnChoice*
|
||||
CreatureLib::Battling::MiscLibrary::ReplacementAttack(Creature* user, [[maybe_unused]] CreatureIndex target) const {
|
||||
AssertNotNull(user)
|
||||
Assert(user->GetBattleSide().HasValue())
|
||||
EnsureNotNull(user)
|
||||
Ensure(user->GetBattleSide().HasValue())
|
||||
auto sideTarget = 0;
|
||||
if (user->GetBattleSide().GetValue()->GetSideIndex() == 0)
|
||||
sideTarget = 1;
|
||||
|
|
|
@ -9,7 +9,6 @@ using namespace CreatureLib::Battling;
|
|||
const ArbUt::BorrowedPtr<const BattleLibrary>& Battle::GetLibrary() const noexcept { return _library; }
|
||||
|
||||
bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
||||
AssertNotNull(choice)
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack) {
|
||||
// HOOK: change number of uses needed.
|
||||
return choice.ForceAs<AttackTurnChoice>()->GetAttack()->GetRemainingUses() >= 1;
|
||||
|
@ -18,10 +17,10 @@ bool Battle::CanUse(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice) {
|
|||
}
|
||||
|
||||
bool Battle::TrySetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
EnsureNotNull(choice)
|
||||
if (!CanUse(choice))
|
||||
return false;
|
||||
Assert(choice->GetUser()->GetBattleSide().HasValue())
|
||||
Ensure(choice->GetUser()->GetBattleSide().HasValue())
|
||||
choice->GetUser()->GetBattleSide().GetValue()->SetChoice(choice);
|
||||
CheckChoicesSetAndRun();
|
||||
return true;
|
||||
|
@ -51,7 +50,7 @@ void Battle::CheckChoicesSetAndRun() {
|
|||
try {
|
||||
for (auto side : _sides) {
|
||||
for (auto choice : side->GetChoices()) {
|
||||
AssertNotNull(choice)
|
||||
EnsureNotNull(choice)
|
||||
if (choice->GetKind() == TurnChoiceKind::Attack) {
|
||||
auto attack = std::static_pointer_cast<AttackTurnChoice>(choice);
|
||||
uint8_t uses = 1;
|
||||
|
@ -99,7 +98,6 @@ ArbUt::BorrowedPtr<ChoiceQueue> Battle::GetCurrentTurnQueue() const noexcept { r
|
|||
BattleRandom* Battle::GetRandom() noexcept { return &_random; }
|
||||
|
||||
bool Battle::CreatureInField(ArbUt::BorrowedPtr<Creature> creature) const {
|
||||
AssertNotNull(creature)
|
||||
return std::any_of(_sides.begin(), _sides.end(), [creature](auto c) { return c->CreatureOnSide(creature); });
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace CreatureLib::Battling {
|
|||
.count())
|
||||
: _library(library), _parties(parties.GetStdList()), _canFlee(canFlee), _numberOfSides(numberOfSides),
|
||||
_creaturesPerSide(creaturesPerSide), _sides(numberOfSides), _random(randomSeed) {
|
||||
AssertAllNotNull(parties);
|
||||
EnsureAllNotNull(parties);
|
||||
|
||||
for (size_t i = 0; i < numberOfSides; i++) {
|
||||
_sides.Append(new BattleSide(i, this, creaturesPerSide));
|
||||
|
|
|
@ -11,9 +11,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
public:
|
||||
BattleParty(CreatureParty* party, const ArbUt::List<CreatureIndex>& responsibleIndices)
|
||||
: _party(party), _responsibleIndices(responsibleIndices) {
|
||||
AssertNotNull(_party)
|
||||
}
|
||||
: _party(party), _responsibleIndices(responsibleIndices) {}
|
||||
|
||||
inline const ArbUt::BorrowedPtr<CreatureParty>& GetParty() const { return _party; }
|
||||
inline const ArbUt::List<CreatureIndex>& GetResponsibleIndices() const { return _responsibleIndices; }
|
||||
|
|
|
@ -7,7 +7,6 @@ using namespace CreatureLib::Battling;
|
|||
bool BattleSide::AllChoicesSet() const noexcept { return _choicesSet == _creaturesPerSide; }
|
||||
|
||||
bool BattleSide::AllPossibleSlotsFilled() const {
|
||||
AssertNotNull(_battle)
|
||||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto c = _creatures[i];
|
||||
|
@ -30,7 +29,7 @@ void BattleSide::ResetChoices() noexcept {
|
|||
}
|
||||
|
||||
void BattleSide::SetChoice(BaseTurnChoice* choice) {
|
||||
AssertNotNull(choice)
|
||||
EnsureNotNull(choice)
|
||||
try {
|
||||
for (size_t i = 0; i < _creatures.Count(); i++) {
|
||||
auto& c = _creatures[i];
|
||||
|
@ -60,9 +59,6 @@ void BattleSide::SetCreature(ArbUt::OptionalBorrowedPtr<Creature> creature, uint
|
|||
}
|
||||
creature.GetValue()->SetBattleData(_battle, this);
|
||||
creature.GetValue()->SetOnBattleField(true);
|
||||
if (_battle == nullptr) {
|
||||
return;
|
||||
}
|
||||
for (auto* side : _battle->GetSides()) {
|
||||
if (side == this) {
|
||||
continue;
|
||||
|
@ -91,6 +87,5 @@ size_t BattleSide::ScriptCount() const { return _battle->ScriptCount() + 1; }
|
|||
|
||||
uint8_t BattleSide::GetRandomCreatureIndex() {
|
||||
// TODO: Consider adding parameter to only get index for available creatures.
|
||||
AssertNotNull(_battle)
|
||||
return _battle->GetRandom()->Get(_creaturesPerSide);
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ namespace CreatureLib::Battling {
|
|||
|
||||
void Creature::ChangeSpecies(const ArbUt::BorrowedPtr<const Library::CreatureSpecies>& species,
|
||||
const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant) {
|
||||
AssertNotNull(species);
|
||||
AssertNotNull(variant);
|
||||
_species = species;
|
||||
|
||||
// If the creature is genderless, but it's new species is not, we want to set its gender
|
||||
|
@ -51,7 +49,6 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
|
||||
void Creature::ChangeVariant(const ArbUt::BorrowedPtr<const Library::SpeciesVariant>& variant) {
|
||||
AssertNotNull(variant)
|
||||
_variant = variant;
|
||||
|
||||
// Set the types to the new variant.
|
||||
|
@ -145,8 +142,8 @@ namespace CreatureLib::Battling {
|
|||
bool Creature::IsFainted() const noexcept { return this->_currentHealth == 0; }
|
||||
|
||||
void Creature::OnFaint() {
|
||||
AssertNotNull(_battle)
|
||||
AssertNotNull(_side)
|
||||
EnsureNotNull(_battle)
|
||||
EnsureNotNull(_side)
|
||||
// HOOK: On Faint
|
||||
if (_battle.HasValue()) {
|
||||
_battle.GetValue()->TriggerEventListener<FaintEvent>(this);
|
||||
|
|
|
@ -43,8 +43,6 @@ namespace CreatureLib::Battling {
|
|||
const std::unique_ptr<Script>& script)
|
||||
: _numberHits(numberHits), _hits(std::make_unique<HitData[]>(targets.Count() * numberHits)), _user(user),
|
||||
_attack(attack), _targets(targets) {
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
// Take ownership of the script of the attack choice, and give attack choice our initial nullptr.
|
||||
_script.swap(const_cast<std::unique_ptr<Script>&>(script));
|
||||
}
|
||||
|
|
|
@ -4,13 +4,11 @@ CreatureLib::Battling::LearnedAttack::LearnedAttack(
|
|||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, uint8_t maxUses,
|
||||
AttackLearnMethod learnMethod)
|
||||
: _attack(attack), _maxUses(maxUses), _remainingUses(maxUses), _learnMethod(learnMethod) {
|
||||
AssertNotNull(_attack)
|
||||
}
|
||||
|
||||
CreatureLib::Battling::LearnedAttack::LearnedAttack(
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>& attack, AttackLearnMethod learnMethod)
|
||||
: _attack(attack), _maxUses(attack->GetBaseUsages()), _remainingUses(_maxUses), _learnMethod(learnMethod) {
|
||||
AssertNotNull(_attack)
|
||||
}
|
||||
|
||||
const ArbUt::BorrowedPtr<const CreatureLib::Library::AttackData>&
|
||||
|
|
|
@ -48,10 +48,8 @@ namespace CreatureLib::Battling {
|
|||
std::optional<ArbUt::BorrowedPtr<Script>> GetNextNotNull() {
|
||||
while (HasNext()) {
|
||||
auto s = GetNext();
|
||||
if (s != nullptr) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
auto aggregator = source->GetScriptIterator(); \
|
||||
while (aggregator.HasNext()) { \
|
||||
auto next = aggregator.GetNext(); \
|
||||
if (next == nullptr) \
|
||||
continue; \
|
||||
try { \
|
||||
next->hookName(__VA_ARGS__); \
|
||||
} catch (const std::exception& e) { \
|
||||
|
|
|
@ -19,8 +19,6 @@ namespace CreatureLib::Battling {
|
|||
if (_attackScript != nullptr)
|
||||
return;
|
||||
auto user = GetUser();
|
||||
if (user == nullptr)
|
||||
return;
|
||||
auto battle = user->GetBattle();
|
||||
if (battle.HasValue()) {
|
||||
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
||||
|
@ -38,20 +36,13 @@ namespace CreatureLib::Battling {
|
|||
public:
|
||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target)
|
||||
: BaseTurnChoice(user), _attack(attack), _target(target) {
|
||||
#ifndef TESTS_BUILD
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
#endif
|
||||
EnsureNotNull(user)
|
||||
ResolveScript();
|
||||
_priority = _attack->GetAttack()->GetPriority();
|
||||
}
|
||||
AttackTurnChoice(Creature* user, const ArbUt::BorrowedPtr<LearnedAttack>& attack, const CreatureIndex& target,
|
||||
Script* script)
|
||||
: BaseTurnChoice(user), _attack(attack), _target(target), _attackScript(script) {
|
||||
#ifndef TESTS_BUILD
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(attack)
|
||||
#endif
|
||||
_priority = _attack->GetAttack()->GetPriority();
|
||||
}
|
||||
|
||||
|
@ -68,19 +59,14 @@ namespace CreatureLib::Battling {
|
|||
|
||||
const std::unique_ptr<Script>& GetAttackScript() const noexcept { return _attackScript; }
|
||||
size_t ScriptCount() const override {
|
||||
if (_user == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
return 1 + GetUser()->ScriptCount();
|
||||
}
|
||||
|
||||
protected:
|
||||
void GetActiveScripts(ArbUt::List<ScriptWrapper>& scripts) override {
|
||||
scripts.Append(ScriptWrapper::FromScript(&_attackScript));
|
||||
if (_user != nullptr) {
|
||||
GetUser()->GetActiveScripts(scripts);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@ namespace CreatureLib::Library {
|
|||
virtual ~BaseLibrary() noexcept { _values.Clear(); }
|
||||
|
||||
inline virtual void Insert(const ArbUt::StringView& key, const T* value) {
|
||||
AssertNotNull(value)
|
||||
EnsureNotNull(value)
|
||||
_values.GetStdMap().insert({key.GetHash(), std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(key);
|
||||
}
|
||||
inline virtual void Insert(uint32_t hashedKey, const T* value) {
|
||||
AssertNotNull(value)
|
||||
EnsureNotNull(value)
|
||||
_values.GetStdMap().insert({hashedKey, std::unique_ptr<const T>(value)});
|
||||
_listValues.Append(hashedKey);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ struct CreatureSpecies::impl {
|
|||
const ArbUt::StringView _growthRate;
|
||||
uint8_t _captureRate;
|
||||
|
||||
ArbUt::Dictionary<uint32_t, std::unique_ptr<const SpeciesVariant>> _variantsLookup;
|
||||
ArbUt::Dictionary<uint32_t, ArbUt::UniquePtr<const SpeciesVariant>> _variantsLookup;
|
||||
ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>> _variantsList;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
|
@ -17,7 +17,7 @@ struct CreatureSpecies::impl {
|
|||
const ArbUt::StringView& growthRate, uint8_t captureRate, std::unordered_set<uint32_t> flags)
|
||||
: _name(name), _id(id), _genderRate(genderRatio), _growthRate(growthRate), _captureRate(captureRate),
|
||||
_variantsLookup(1), _variantsList(1), _flags(std::move(flags)) {
|
||||
AssertNotNull(defaultVariant)
|
||||
EnsureNotNull(defaultVariant)
|
||||
SetVariant("default"_cnc, defaultVariant);
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,13 @@ struct CreatureSpecies::impl {
|
|||
auto find = _variantsLookup.GetStdMap().find(hash);
|
||||
if (find == _variantsLookup.end())
|
||||
return {};
|
||||
return std::get<1>(*find);
|
||||
return std::get<1>(*find).GetRaw();
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(const ArbUt::BasicStringView& key) const {
|
||||
return _variantsLookup.Get(key);
|
||||
return _variantsLookup.Get(key).GetRaw();
|
||||
}
|
||||
[[nodiscard]] inline ArbUt::BorrowedPtr<const SpeciesVariant> GetVariant(uint32_t key) const {
|
||||
return _variantsLookup.Get(key);
|
||||
return _variantsLookup.Get(key).GetRaw();
|
||||
}
|
||||
[[nodiscard]] Gender GetRandomGender(ArbUt::Random& rand) const noexcept {
|
||||
if (this->_genderRate == -1) {
|
||||
|
@ -60,10 +60,9 @@ struct CreatureSpecies::impl {
|
|||
[[nodiscard]] inline const ArbUt::StringView& GetName() const noexcept { return _name; }
|
||||
|
||||
void SetVariant(const ArbUt::StringView& name, const SpeciesVariant* variant) {
|
||||
Assert(!name.IsEmpty())
|
||||
AssertNotNull(variant)
|
||||
Ensure(!name.IsEmpty())
|
||||
_variantsList.CreateBack(variant);
|
||||
_variantsLookup.GetStdMap().insert({name, std::unique_ptr<const SpeciesVariant>(variant)});
|
||||
_variantsLookup.GetStdMap().emplace(name, variant);
|
||||
}
|
||||
|
||||
inline const ArbUt::List<ArbUt::BorrowedPtr<const SpeciesVariant>>& GetVariantsIterator() const {
|
||||
|
|
|
@ -7,10 +7,10 @@ CreatureLib::Library::DataLibrary::DataLibrary(LibrarySettings* settings, Creatu
|
|||
TypeLibrary* typeLibrary)
|
||||
: _settings(settings), _species(species), _attacks(attacks), _items(items), _growthRates(growthRates),
|
||||
_typeLibrary(typeLibrary) {
|
||||
AssertNotNull(_settings)
|
||||
AssertNotNull(_species)
|
||||
AssertNotNull(_attacks)
|
||||
AssertNotNull(_items)
|
||||
AssertNotNull(_growthRates)
|
||||
AssertNotNull(_typeLibrary)
|
||||
EnsureNotNull(_settings)
|
||||
EnsureNotNull(_species)
|
||||
EnsureNotNull(_attacks)
|
||||
EnsureNotNull(_items)
|
||||
EnsureNotNull(_growthRates)
|
||||
EnsureNotNull(_typeLibrary)
|
||||
}
|
|
@ -11,8 +11,8 @@ namespace CreatureLib::Library {
|
|||
public:
|
||||
inline ExternGrowthRate(level_int_t (*calcLevel)(uint32_t), uint32_t (*calcExperience)(level_int_t level))
|
||||
: _calcLevel(calcLevel), _calcExperience(calcExperience) {
|
||||
AssertNotNull(calcLevel)
|
||||
AssertNotNull(calcExperience)
|
||||
EnsureNotNull(calcLevel)
|
||||
EnsureNotNull(calcExperience)
|
||||
}
|
||||
|
||||
level_int_t CalculateLevel(uint32_t experience) const override { return _calcLevel(experience); }
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include <vector>
|
||||
|
||||
// Arbutils
|
||||
#include <Arbutils/Assert.hpp>
|
||||
#include <Arbutils/Collections/Dictionary.hpp>
|
||||
#include <Arbutils/Collections/List.hpp>
|
||||
#include <Arbutils/Ensure.hpp>
|
||||
#include <Arbutils/Enum.hpp>
|
||||
#include <Arbutils/Exception.hpp>
|
||||
#include <Arbutils/Memory/Memory.hpp>
|
||||
|
|
|
@ -49,8 +49,7 @@ TEST_CASE("Script source with script ptr being set.") {
|
|||
auto source = ScriptSourceWithScriptPtr();
|
||||
source.ScriptPtr = std::make_unique<TestScript>("foobar");
|
||||
auto scripts = source.GetScriptIterator();
|
||||
auto first = scripts.GetNext();
|
||||
CHECK(first != nullptr);
|
||||
[[maybe_unused]] auto first = scripts.GetNext();
|
||||
}
|
||||
|
||||
TEST_CASE("Script source with script ptr being set after first iteration.") {
|
||||
|
@ -59,8 +58,7 @@ TEST_CASE("Script source with script ptr being set after first iteration.") {
|
|||
REQUIRE_FALSE(scripts.HasNext());
|
||||
source.ScriptPtr = std::make_unique<TestScript>("foobar");
|
||||
scripts = source.GetScriptIterator();
|
||||
auto first = scripts.GetNext();
|
||||
CHECK(first != nullptr);
|
||||
[[maybe_unused]] auto first = scripts.GetNext();
|
||||
}
|
||||
|
||||
TEST_CASE("Script source with empty script set.") {
|
||||
|
|
Loading…
Reference in New Issue