Skip to content

Commit

Permalink
Fix for unlinked family members crashing conversion (#264) #patch
Browse files Browse the repository at this point in the history
* fix for unlinked family members crashing conversion

* Update Family.cpp
  • Loading branch information
IhateTrains authored Aug 13, 2021
1 parent 7be3078 commit e952763
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ImperatorToCK3/Source/CK3/Dynasties/Dynasty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ CK3::Dynasty::Dynasty(const Imperator::Family& impFamily, const mappers::Localiz

const auto& impMembers = impFamily.getMembers();
if (!impMembers.empty()) {
culture = impMembers[0].second->getCK3Character()->culture; // make head's culture the dynasty culture
auto firstMember = impMembers[0];
culture = firstMember.second->getCK3Character()->culture; // make head's culture the dynasty culture
}
else {
Log(LogLevel::Warning) << "Couldn't determine culture for dynasty " << ID << ", needs manual setting!";
Expand Down
7 changes: 7 additions & 0 deletions ImperatorToCK3/Source/Imperator/Families/Families.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ void Imperator::Families::loadFamilies(std::istream& theStream) {
}


void Imperator::Families::removeUnlinkedMembers() {
for (const auto& family : families) {
family.second->removeUnlinkedMembers();
}
}


void Imperator::Families::registerKeys() {
registerRegex(commonItems::integerRegex, [this](const std::string& theFamilyID, std::istream& theStream) {
const auto familyStr = commonItems::stringOfItem(theStream).getString();
Expand Down
1 change: 1 addition & 0 deletions ImperatorToCK3/Source/Imperator/Families/Families.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Families : commonItems::parser {
public:
void loadFamilies(const std::string& thePath);
void loadFamilies(std::istream& theStream);
void removeUnlinkedMembers();

auto& operator= (const Families& obj) { this->families = obj.families; return *this; }

Expand Down
5 changes: 5 additions & 0 deletions ImperatorToCK3/Source/Imperator/Families/Family.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ void Imperator::Family::linkMember(const std::shared_ptr<Character>& newMemberPt
// matching ID was not found
Log(LogLevel::Warning) << "Family " << ID << ": cannot link " << newMemberPtr->getID() << ": not found in members!";
}


void Imperator::Family::removeUnlinkedMembers() {
std::erase_if(members, [](auto member) { return member.second == nullptr; });
}
1 change: 1 addition & 0 deletions ImperatorToCK3/Source/Imperator/Families/Family.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Family {
Family() = default;

void linkMember(const std::shared_ptr<Character>& newMemberPtr);
void removeUnlinkedMembers();

[[nodiscard]] auto getID() const { return ID; }
[[nodiscard]] const auto& getKey() const { return key; }
Expand Down
1 change: 1 addition & 0 deletions ImperatorToCK3/Source/Imperator/ImperatorWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Imperator::World::World(const Configuration& theConfiguration, const commonItems
// Link all the intertwining pointers
Log(LogLevel::Info) << "-- Linking Characters with Families";
characters.linkFamilies(families);
families.removeUnlinkedMembers();
Log(LogLevel::Info) << "-- Linking Characters with Spouses";
characters.linkSpouses();
Log(LogLevel::Info) << "-- Linking Characters with Mothers and Fathers";
Expand Down

0 comments on commit e952763

Please sign in to comment.