From 3e8e61b1ceea4ece8b78cbc8f6ab694cc500d0f2 Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sat, 23 Feb 2013 09:51:36 -0800 Subject: [PATCH 1/7] Don't crash if religions tie on multiple criteria. --- Source/EU3World/EU3Province.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/EU3World/EU3Province.cpp b/Source/EU3World/EU3Province.cpp index 4fb87bd32..426ea81bd 100644 --- a/Source/EU3World/EU3Province.cpp +++ b/Source/EU3World/EU3Province.cpp @@ -664,7 +664,6 @@ void EU3Province::determineReligion(const religionMapping& religionMap, const ve vector tiedReligions2; if (tie == true) { - topReligion = NULL; topCount = 0; for (map::iterator countsItr = religionCounts2.begin(); countsItr != religionCounts2.end(); countsItr++) { @@ -693,7 +692,6 @@ void EU3Province::determineReligion(const religionMapping& religionMap, const ve if (tie == true) { - topReligion = NULL; topCount = 0; for (map::iterator countsItr = religionCounts3.begin(); countsItr != religionCounts3.end(); countsItr++) { From 66172eee5e1e9eb034ccc3a2b6890a6e9ec2215a Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sat, 23 Feb 2013 09:52:47 -0800 Subject: [PATCH 2/7] Read titular settlements and allow them to be a character's primary holding. --- Source/CK2World/CK2Barony.cpp | 4 ++-- Source/CK2World/CK2Barony.h | 2 +- Source/CK2World/CK2Building.cpp | 10 +++++++--- Source/CK2World/CK2Building.h | 9 +++++---- Source/CK2World/CK2Character.cpp | 10 +++++++--- Source/CK2World/CK2Province.cpp | 4 ++-- Source/CK2World/CK2Province.h | 2 +- Source/CK2World/CK2Title.cpp | 25 ++++++++++++++++++++++++- Source/CK2World/CK2Title.h | 8 +++++++- Source/CK2World/CK2World.cpp | 10 ++++++---- 10 files changed, 62 insertions(+), 22 deletions(-) diff --git a/Source/CK2World/CK2Barony.cpp b/Source/CK2World/CK2Barony.cpp index 57d028701..0a93e3437 100644 --- a/Source/CK2World/CK2Barony.cpp +++ b/Source/CK2World/CK2Barony.cpp @@ -8,7 +8,7 @@ -CK2Barony::CK2Barony(Object* obj, CK2Title* newTitle, CK2Province* newProvince, const CK2BuildingFactory* buildingFactory, const cultureGroupMapping& cultureGroupMap) +CK2Barony::CK2Barony(Object* obj, CK2Title* newTitle, CK2Province* newProvince, const CK2BuildingFactory* buildingFactory) { title = newTitle; province = newProvince; @@ -22,7 +22,7 @@ CK2Barony::CK2Barony(Object* obj, CK2Title* newTitle, CK2Province* newProvince, string key = (*i)->getKey(); if ( (key.substr(0, 3) == "ca_") || (key.substr(0, 3) == "ct_") || (key.substr(0, 3) == "tp_") ) { - const CK2Building* newBuilding = buildingFactory->getBuilding(key, title->getHolder(), cultureGroupMap); + const CK2Building* newBuilding = buildingFactory->getBuilding(key, title->getHolder()); if (newBuilding != NULL) { buildings.push_back(newBuilding); diff --git a/Source/CK2World/CK2Barony.h b/Source/CK2World/CK2Barony.h index 4c141bee6..b97f6be78 100644 --- a/Source/CK2World/CK2Barony.h +++ b/Source/CK2World/CK2Barony.h @@ -17,7 +17,7 @@ class CK2Province; class CK2Barony { public: - CK2Barony(Object*, CK2Title*, CK2Province*, const CK2BuildingFactory*, const cultureGroupMapping& cultureGroupMap); + CK2Barony(Object*, CK2Title*, CK2Province*, const CK2BuildingFactory*); CK2Title* getTitle() const { return title; }; CK2Province* getProvince() const { return province; }; diff --git a/Source/CK2World/CK2Building.cpp b/Source/CK2World/CK2Building.cpp index 368036d9e..d52758176 100644 --- a/Source/CK2World/CK2Building.cpp +++ b/Source/CK2World/CK2Building.cpp @@ -152,8 +152,12 @@ CK2Building::CK2Building(Object* obj) } -CK2BuildingFactory::CK2BuildingFactory() +map CK2BuildingFactory::buildings; + + +CK2BuildingFactory::CK2BuildingFactory(const cultureGroupMapping* _cultureGroupMap) { + cultureGroupMap = _cultureGroupMap; buildings.clear(); } @@ -174,7 +178,7 @@ void CK2BuildingFactory::addBuildingTypes(Object* obj) } -const CK2Building* CK2BuildingFactory::getBuilding(string type, const CK2Character* baronyHolder, const cultureGroupMapping& cultureGroupMap) const +const CK2Building* CK2BuildingFactory::getBuilding(string type, const CK2Character* baronyHolder) const { const CK2Building* returnMe = NULL; @@ -197,7 +201,7 @@ const CK2Building* CK2BuildingFactory::getBuilding(string type, const CK2Charact vector acceptableCultureGroups = itr->second->getAcceptableCultureGroups(); for (vector::iterator cultureGroupsItr = acceptableCultureGroups.begin(); cultureGroupsItr < acceptableCultureGroups.end(); cultureGroupsItr++) { - if ( *cultureGroupsItr == cultureGroupMap.find(baronyHolder->getCulture())->second ) + if ( *cultureGroupsItr == cultureGroupMap->find(baronyHolder->getCulture())->second ) { returnMe = itr->second; break; diff --git a/Source/CK2World/CK2Building.h b/Source/CK2World/CK2Building.h index f9d12ee08..9b2a0f030 100644 --- a/Source/CK2World/CK2Building.h +++ b/Source/CK2World/CK2Building.h @@ -45,13 +45,14 @@ class CK2Building class CK2BuildingFactory { public: - CK2BuildingFactory(); + CK2BuildingFactory(const cultureGroupMapping* _cultureGroupMap); - void addBuildingTypes(Object* obj); - const CK2Building* getBuilding(string type, const CK2Character* baronyHolder, const cultureGroupMapping& cultureGroupMap) const; + static void addBuildingTypes(Object* obj); + const CK2Building* getBuilding(string type, const CK2Character* baronyHolder) const; private: - map buildings; + const cultureGroupMapping* cultureGroupMap; + static map buildings; }; diff --git a/Source/CK2World/CK2Character.cpp b/Source/CK2World/CK2Character.cpp index 2f6c3f344..a7ce665cb 100644 --- a/Source/CK2World/CK2Character.cpp +++ b/Source/CK2World/CK2Character.cpp @@ -419,10 +419,14 @@ void CK2Character::setEmployer(map& characters, mapgetCapitalString(); - CK2Barony* homeBarony = baronies[hostCapitalString]; - if (homeBarony != NULL) + map::iterator itr = baronies.find(hostCapitalString); + if (itr != baronies.end()) { - locationNum = homeBarony->getProvince()->getNumber(); + CK2Barony* homeBarony = itr->second; + if (homeBarony != NULL) + { + locationNum = homeBarony->getProvince()->getNumber(); + } } } } diff --git a/Source/CK2World/CK2Province.cpp b/Source/CK2World/CK2Province.cpp index 9dac736d3..49811b78b 100644 --- a/Source/CK2World/CK2Province.cpp +++ b/Source/CK2World/CK2Province.cpp @@ -9,7 +9,7 @@ -CK2Province::CK2Province(Object* obj, map titles, const CK2BuildingFactory* buildingFactory, const cultureGroupMapping& cultureGroupMap) +CK2Province::CK2Province(Object* obj, map titles, const CK2BuildingFactory* buildingFactory) { number = atoi( obj->getKey().c_str() ); @@ -25,7 +25,7 @@ CK2Province::CK2Province(Object* obj, map titles, const CK2Bu log("Error: baron-level title %s is used in your save, but does not exist in your CK2 install.\n", key.c_str()); continue; } - CK2Barony* newBarony = new CK2Barony( leaves[i], title->second, this, buildingFactory, cultureGroupMap); + CK2Barony* newBarony = new CK2Barony( leaves[i], title->second, this, buildingFactory); if (newBarony->getTitle()->getHolder()->getCapitalString() == newBarony->getTitle()->getTitleString()) { newBarony->getTitle()->getHolder()->setCapital(this); diff --git a/Source/CK2World/CK2Province.h b/Source/CK2World/CK2Province.h index cb098d8ab..aabae30d4 100644 --- a/Source/CK2World/CK2Province.h +++ b/Source/CK2World/CK2Province.h @@ -18,7 +18,7 @@ class CK2Religion; class CK2Province { public: - CK2Province(Object*, map, const CK2BuildingFactory* buildingFactory, const cultureGroupMapping& cultureGroupMap); + CK2Province(Object*, map, const CK2BuildingFactory* buildingFactory); int getNumber() const { return number; }; vector getBaronies() const { return baronies; }; diff --git a/Source/CK2World/CK2Title.cpp b/Source/CK2World/CK2Title.cpp index e802397a2..04245f11a 100644 --- a/Source/CK2World/CK2Title.cpp +++ b/Source/CK2World/CK2Title.cpp @@ -5,6 +5,7 @@ #include "CK2Title.h" #include "CK2Dynasty.h" #include "CK2History.h" +#include "CK2Barony.h" #include "..\Log.h" #include #include "..\Configuration.h" @@ -28,11 +29,13 @@ CK2Title::CK2Title(string _titleString) deJureLiege = NULL; independent = true; inHRE = false; + active = false; dstCountry = NULL; + settlement = NULL; } -void CK2Title::init(Object* obj, map& characters) +void CK2Title::init(Object* obj, map& characters, const CK2BuildingFactory* buildingFactory) { titleString = obj->getKey(); holder = NULL; @@ -117,6 +120,26 @@ void CK2Title::init(Object* obj, map& characters) deJureLiegeString = deJureLiegeString.substr(1, deJureLiegeString.size() - 2); } + active = true; + vector activeObjs = obj->getValue("active"); + if (activeObjs.size() > 0) + { + if (activeObjs[0]->getLeaf() == "no") + active = false; + } + + vector settlementObjs = obj->getValue("settlement"); + if (settlementObjs.size() > 0) + { + settlement = new CK2Barony(settlementObjs[0], this, NULL, buildingFactory); + if (holder != NULL) + { + holder->addHolding(settlement); + if (holder->getPrimaryHolding() == NULL) // if no other capital, a title holding will work + holder->setPrimaryHolding(settlement); + } + } + independent = true; inHRE = false; } diff --git a/Source/CK2World/CK2Title.h b/Source/CK2World/CK2Title.h index cf653c647..8c5ced6de 100644 --- a/Source/CK2World/CK2Title.h +++ b/Source/CK2World/CK2Title.h @@ -12,13 +12,15 @@ class Object; class CK2World; class CK2Character; class CK2History; +class CK2Barony; +class CK2BuildingFactory; class EU3Country; class CK2Title { public: CK2Title(string _titleString); - void init(Object*, map&); + void init(Object*, map&, const CK2BuildingFactory* buildingFactory); void setLiege(CK2Title*); void addToHRE(); @@ -47,6 +49,7 @@ class CK2Title CK2Title* getDeJureLiege() const { return deJureLiege; }; bool isIndependent() const { return independent; }; bool isInHRE() const { return inHRE; }; + bool isActive() const { return active; }; EU3Country* getDstCountry() const { return dstCountry; }; bool eatTitle(CK2Title* target, bool checkInheritance); @@ -77,9 +80,12 @@ class CK2Title vector deJureVassals; string deJureLiegeString; CK2Title* deJureLiege; + + CK2Barony* settlement; bool independent; bool inHRE; + bool active; EU3Country* dstCountry; }; diff --git a/Source/CK2World/CK2World.cpp b/Source/CK2World/CK2World.cpp index 0c19f80f3..50b3341f1 100644 --- a/Source/CK2World/CK2World.cpp +++ b/Source/CK2World/CK2World.cpp @@ -17,7 +17,7 @@ CK2World::CK2World() { - buildingFactory = new CK2BuildingFactory; + buildingFactory = NULL; version = NULL; endDate = date(); @@ -37,6 +37,8 @@ CK2World::CK2World() void CK2World::init(Object* obj, const cultureGroupMapping& cultureGroupMap) { + buildingFactory = new CK2BuildingFactory(&cultureGroupMap); + // get version vector versionObj = obj->getValue("version"); if (versionObj.size() > 0) @@ -147,7 +149,7 @@ void CK2World::init(Object* obj, const cultureGroupMapping& cultureGroupMap) log("\t\tWarning: tried to create title %s, but it is not a potential title.\n", key.c_str()); continue; } - titleItr->second->init(leaves[i], characters); + titleItr->second->init(leaves[i], characters, buildingFactory); titles.insert( make_pair(titleItr->second->getTitleString(), titleItr->second) ); } } @@ -166,7 +168,7 @@ void CK2World::init(Object* obj, const cultureGroupMapping& cultureGroupMap) string key = leaves[i]->getKey(); if (atoi(key.c_str()) > 0) { - CK2Province* newProvince = new CK2Province(leaves[i], titles, buildingFactory, cultureGroupMap); + CK2Province* newProvince = new CK2Province(leaves[i], titles, buildingFactory); provinces.insert( make_pair(atoi(key.c_str()), newProvince) ); vector newBaronies = newProvince->getBaronies(); @@ -270,7 +272,7 @@ void CK2World::init(Object* obj, const cultureGroupMapping& cultureGroupMap) void CK2World::addBuildingTypes(Object* obj) { - buildingFactory->addBuildingTypes(obj); + CK2BuildingFactory::addBuildingTypes(obj); } From 89eb548ec919be32b6a482462218af6bc198395d Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sat, 23 Feb 2013 10:17:21 -0800 Subject: [PATCH 3/7] Read dynamic titles and their settlements. --- Source/CK2World/CK2Title.cpp | 8 ++++++++ Source/CK2World/CK2Title.h | 2 ++ Source/CK2World/CK2World.cpp | 17 +++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/CK2World/CK2Title.cpp b/Source/CK2World/CK2Title.cpp index 04245f11a..10e6b07f2 100644 --- a/Source/CK2World/CK2Title.cpp +++ b/Source/CK2World/CK2Title.cpp @@ -32,6 +32,7 @@ CK2Title::CK2Title(string _titleString) active = false; dstCountry = NULL; settlement = NULL; + dynamic = false; } @@ -128,6 +129,13 @@ void CK2Title::init(Object* obj, map& characters, const CK2 active = false; } + vector dynObjs = obj->getValue("dynamic"); + if (dynObjs.size() > 0) + { + if (dynObjs[0]->getLeaf() == "yes") + dynamic = true; + } + vector settlementObjs = obj->getValue("settlement"); if (settlementObjs.size() > 0) { diff --git a/Source/CK2World/CK2Title.h b/Source/CK2World/CK2Title.h index 8c5ced6de..e0102555a 100644 --- a/Source/CK2World/CK2Title.h +++ b/Source/CK2World/CK2Title.h @@ -50,6 +50,7 @@ class CK2Title bool isIndependent() const { return independent; }; bool isInHRE() const { return inHRE; }; bool isActive() const { return active; }; + bool isDynamic() const { return dynamic; }; EU3Country* getDstCountry() const { return dstCountry; }; bool eatTitle(CK2Title* target, bool checkInheritance); @@ -86,6 +87,7 @@ class CK2Title bool independent; bool inHRE; bool active; + bool dynamic; EU3Country* dstCountry; }; diff --git a/Source/CK2World/CK2World.cpp b/Source/CK2World/CK2World.cpp index 50b3341f1..ebde12c89 100644 --- a/Source/CK2World/CK2World.cpp +++ b/Source/CK2World/CK2World.cpp @@ -146,11 +146,20 @@ void CK2World::init(Object* obj, const cultureGroupMapping& cultureGroupMap) map::iterator titleItr = potentialTitles.find(key); if (titleItr == potentialTitles.end()) { - log("\t\tWarning: tried to create title %s, but it is not a potential title.\n", key.c_str()); - continue; + CK2Title* dynTitle = new CK2Title(key); + dynTitle->init(leaves[i], characters, buildingFactory); + if (!dynTitle->isDynamic()) + { + log("\t\tWarning: tried to create title %s, but it is neither a potential title nor a dynamic title.\n", key.c_str()); + continue; + } + titles.insert( make_pair(dynTitle->getTitleString(), dynTitle) ); + } + else + { + titleItr->second->init(leaves[i], characters, buildingFactory); + titles.insert( make_pair(titleItr->second->getTitleString(), titleItr->second) ); } - titleItr->second->init(leaves[i], characters, buildingFactory); - titles.insert( make_pair(titleItr->second->getTitleString(), titleItr->second) ); } } From f32934cb3d3dbffce42b4d113af9cb825422bc40 Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sat, 23 Feb 2013 10:33:44 -0800 Subject: [PATCH 4/7] Don't erase the buildings from the building map after adding them. --- Source/CK2World/CK2Building.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/CK2World/CK2Building.cpp b/Source/CK2World/CK2Building.cpp index d52758176..8f484f6d0 100644 --- a/Source/CK2World/CK2Building.cpp +++ b/Source/CK2World/CK2Building.cpp @@ -158,7 +158,6 @@ map CK2BuildingFactory::buildings; CK2BuildingFactory::CK2BuildingFactory(const cultureGroupMapping* _cultureGroupMap) { cultureGroupMap = _cultureGroupMap; - buildings.clear(); } From 5b7006d4ef9209df3008b7fe029e9b6fc6077720 Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sun, 3 Mar 2013 08:55:05 -0800 Subject: [PATCH 5/7] If the title specified for HRETitle doesn't exist, don't try to set up the HRE mechanics. --- Source/EU3World/EU3World.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/EU3World/EU3World.cpp b/Source/EU3World/EU3World.cpp index c2200e269..73bb976bb 100644 --- a/Source/EU3World/EU3World.cpp +++ b/Source/EU3World/EU3World.cpp @@ -1332,6 +1332,9 @@ void EU3World::determineMapSpread() void EU3World::convertHRE() { + if (srcWorld->getHRETitle() == NULL) + return; + hreEmperor = srcWorld->getHRETitle()->getHolder()->getPrimaryTitle()->getDstCountry(); map hreMembers = srcWorld->getHREMembers(); vector potentialElectors; From fc24dea2c76b848cd50c9c54014ffcf5d3e7b520 Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sun, 3 Mar 2013 09:06:44 -0800 Subject: [PATCH 6/7] Add tax/pop/manpower proxies for family palaces (unused, but silences an error). Correct manpower proxy for temples. --- Source/CK2World/CK2Barony.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/CK2World/CK2Barony.cpp b/Source/CK2World/CK2Barony.cpp index 0a93e3437..161f6e8e2 100644 --- a/Source/CK2World/CK2Barony.cpp +++ b/Source/CK2World/CK2Barony.cpp @@ -106,6 +106,10 @@ void CK2Barony::determineBaseTaxProxy() { baseTaxProxy += 8.0f; } + else if (type == "family_palace") + { + baseTaxProxy += 10.0f; + } else { log("Note! Unhandled barony type %s\n", type.c_str()); @@ -139,6 +143,10 @@ void CK2Barony::determinePopProxy() { popProxy += 8.0f; } + else if (type == "family_palace") + { + popProxy += 10.0f; + } else { log("Note! Unhandled barony type %s\n", type.c_str()); @@ -166,7 +174,11 @@ void CK2Barony::determineManpowerProxy() } else if (type == "temple") { - manpowerProxy += 125; + manpowerProxy += 130; + } + else if (type == "family_palace") + { + manpowerProxy += 50; } else { From 33bd3f9b2d4d1835be55fca4a07dc860028fe5a4 Mon Sep 17 00:00:00 2001 From: Daniel Remenak Date: Sun, 3 Mar 2013 09:14:20 -0800 Subject: [PATCH 7/7] Don't generate EU3 supply for the null tradegood. --- Source/EU3World/EU3Province.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/EU3World/EU3Province.cpp b/Source/EU3World/EU3Province.cpp index 426ea81bd..e4773a41a 100644 --- a/Source/EU3World/EU3Province.cpp +++ b/Source/EU3World/EU3Province.cpp @@ -1163,7 +1163,8 @@ void EU3Province::determineGoodsDemand(const tradeGoodMapping& tradeGoodMap, con void EU3Province::addSupplyContribution(map& goodsSupply) { - goodsSupply[tradeGood] += supply / 100; + if (!tradeGood.empty()) + goodsSupply[tradeGood] += supply / 100; }