Converter Series: Converting Titles

After the last set of updates, there is a forest of CK2Titles, mapping their relationships. And there’s a vector containing all the independent ones. Time to map them to EU3 tags (tags being a three letter abbreviation identifying a country).

In mapper.h/cpp, I create a typedef for the mapping:
typedef map< string, string > countryMapping; // < sourceTitle, destCountry>
Also a function that will create a mapping given all necessary information:
int initCountryMap(countryMapping& mapping, vector CK2Titles, vector EU3Tags, vector blockedNations, Object* rulesObj);

Note that the converter needs a list of EU3 tags to do the mapping: this allows it to be adaptable to the EU3 install, which may be modded to have more tags. So in EU3World, I add the functions addPotentialCountries(ifstream&, string); and getPotentialTags();; and the member vector potentialCountries;. The first function uses the EU3 data file countries.txt to determine which countries can exist in the game. This data file also mentions which data files correspond to those countries. Both the country tag and the filename are extracted, then a new EU3Country created and saved to the potentialCountries vector. The second function returns a list of tags of those potential nations.

Oh, EU3Country? It’s brand new. All it does at this point is keep track of its tag and its country file. It’ll do much much more down the road, though.

The converter is almost ready to map titles to nations. It just needs one more thing: rules! The mapping rules are placed in county_mappings.txt in the following form:
link = { CK2 = k_england EU3 = ENG } # England => England
This says to map the title k_england to the tag ENG. Straightforward as can be.

That initCountryMap() keeps a pool of available EU3 tags and CK2 titles. At first these pools correspond to all possible tags and all independent titles, respectively. The function goes through the rules in order, and sees if both the title and the tag are in the appropriate pools. If so, it creates a mapping between those two and removes them from their pools.

Eventually, there will be multiple set of rules. So you would have direct mappings, like the one above, then regional mappings, say
link = { CK2 = d_lancaster EU3 = ENG }
That way, if England wasn’t independent in CK2, but the duchy of Lancaster was, Lancaster might be able to use the EU3 tag, helping keep tags in the right region.

After going through all the rules, the function maps any remaining items left in the titles pool to any remaining items in the tags pool, in a completely arbitrary order. However, this is not always desirable, because some tags should only ever be given to appropriately equivalent CK2 nations (Germany and Scandinavia come to mind). So first, it uses a list of ‘blocked’ nations to trim the EU3 tags pool a little.

This list of blocked nations is specified in blocked_nations.txt, which initially consists of the following:
eu3 = REB eu3 = PIR eur = NAT eu3 = GER
In what, again, is a straightforward format. This entry blocks REB (rebels), PIR (pirates), NAT (natives), and GER (Germany).

With these changes, the converter has a mapping between titles and tags. Next up: doing something with that mapping!

 

Relevant Repository Links:
Country Mappings

Converter Series: Reading in Titles

To convert the ownership of European territories is a little tricky. Before it can be done, the converter has to have a list of the relevant nations. Those more-or-less map to titles in CK2. So the first step is to import titles.

What’s also important about titles is the relationship among them. In CK2, characters will often be vassals of other characters. In the save file, this is represented as titles potentially having a liege. This is true even in the cases where both the vassal and the liege title are held by the same character. In effect, there’s a nice tree structure relating titles (actually, it’s a collection of trees, which is called a forest).

To create a representation of these relationships, each title will need the following data: its name, its liege (if any), and its vassals (if any). So I create a class (CK2Title) that has all those. The liege is a bit tricky, because the save file only has the name of the liege title, but we want to have access to the liege CK2Title. And until all titles are imported, we can’t be assured we can look up the CK2Title from the name. So the class stores both the liege name and a pointer to the liege CK2Title. With all the functions I can guess are relevant, the class ends up declared as

class CK2Title
{
   public:
      void     init(Object*);
      void     addLiege(CK2Title*);
      void     addVassal(CK2Title*);
      string   getTitleString();
      string   getLiegeString();
   private:
      string            titleString;
      string            liegeString;
      CK2Title*         liege;
      vector<CK2Title>  vassals;
};

CK2World is updated to identify all the titles in the save, (they all start with “e_”, “k_”, “d_”, “c_”, or “b_”, which makes this easy), create a new CK2Title for each, and save all of these titles (in a vector).

Once all the titles have been read in, relating them is easy. Just loop through all of them and get the liege name. If there isn’t one, the title is independent and thus should be related to an EU3 country. If there is one, loop through the titles until you find the one with the same name, then add it as a liege (the CK2Title adding a liege then tells the liege CK2Title “add me as a vassal).

Yes, there’s a major flaw with that process. Points to you if you can figure it out (it’s more obvious when you run the code). It’ll be addressed in a a post or two.

Next up, doing something useful with all of those titles.

 

Relevant Repository Links:
Read in titles
Create tree of vassal/liege relationships