From c484c376c39d85d6c0e9ddb9d65d67b08b6a9872 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 13 Aug 2020 12:23:49 +0200 Subject: [PATCH] When changing species, account for gender changes. Signed-off-by: Deukhoofd --- src/Battling/Models/Creature.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index f582d5b..b404020 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -37,6 +37,22 @@ namespace CreatureLib::Battling { AssertNotNull(variant); _species = species; ChangeVariant(variant); + + // If the creature is genderless, but it's new species is not, we want to set its gender + if (_gender != CreatureLib::Library::Gender::Genderless && _species->GetGenderRate() != -1) { + // If we are currently in battle, use the battle random so we can get predictable events. + if (!_battle.IsNull()) { + _gender = _species->GetRandomGender(_battle->GetRandom()->GetRNG()); + } + // Else create a new random. + else { + ArbUt::Random rand; + _gender = _species->GetRandomGender(rand); + } + } // Else if the new species is genderless, but the creature has a gender, make the creature genderless. + else if (_species->GetGenderRate() == -1 && _gender != CreatureLib::Library::Gender::Genderless) { + _gender = CreatureLib::Library::Gender::Genderless; + } } void Creature::ChangeVariant(const ArbUt::BorrowedPtr& variant) {