Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
Now pulls original pop info from V2 install. Used for uncontrolled pr…
Browse files Browse the repository at this point in the history
…ovinces & pre-conversion population counts.
  • Loading branch information
Idhrendur committed May 2, 2011
1 parent d3c075a commit 48da078
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cpp_version/EU3toV2Converter/EU3toV2Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ int main(int argc, char * argv[]) //changed from TCHAR, no use when everything e


// Parse V2 input file
log("Parsing Vicky2 input save.\n");
printf("Parsing Vicky2 input save.\n");
log("Parsing Vicky2 data.\n");
printf("Parsing Vicky2 data.\n");

initParser();
obj = Parser::topLevel;
Expand All @@ -82,7 +82,7 @@ int main(int argc, char * argv[]) //changed from TCHAR, no use when everything e
readFile(read);
read.close();
V2World destWorld;
destWorld.init(obj);
destWorld.init(obj, V2Loc);


// Parse province mappings
Expand Down
6 changes: 6 additions & 0 deletions cpp_version/EU3toV2Converter/V2Pop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void V2Pop::setReligion(string newReligion)
}


int V2Pop::getSize()
{
return size;
}


void V2Pop::output(FILE* output)
{
fprintf(output, " %s=\n", type.c_str());
Expand Down
1 change: 1 addition & 0 deletions cpp_version/EU3toV2Converter/V2Pop.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class V2Pop
void setSize(int);
void setCulture(string);
void setReligion(string);
int getSize();
void output(FILE*);
private:

Expand Down
29 changes: 18 additions & 11 deletions cpp_version/EU3toV2Converter/V2Province.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ void V2Province::init(Object* obj) {
}

oldPopulation = 0;
vector<Object*> leaves = obj->getLeaves();
for (unsigned int i = 0; i < leaves.size(); i++)
{
string key = leaves[i]->getKey();
if ( ( key == "aristocrats") || ( key == "artisans") || ( key == "bureaucrats") || ( key == "") || ( key == "clergymen") || ( key == "clerks") || ( key == "craftsmen") || ( key == "farmers") || ( key == "labourers") || ( key == "officers") || ( key == "slaves") || ( key == "soldiers") )
{
oldPopulation += atoi( (leaves[i]->getValue("size"))[0]->getLeaf().c_str() );
}
}
}


Expand Down Expand Up @@ -83,6 +74,12 @@ bool V2Province::isColonial()
return colonial;
}

void V2Province::addOldPop(V2Pop oldPop)
{
oldPops.push_back(oldPop);
oldPopulation += oldPop.getSize();
}


string V2Province::getOwner()
{
Expand Down Expand Up @@ -267,9 +264,19 @@ void V2Province::output(FILE* output)
fprintf(output, " garrison=100.000\n");
if (land)
{
for (unsigned int i = 0; i < pops.size(); i++)
if (owner == "")
{
for (unsigned int i = 0; i < pops.size(); i++)
{
oldPops[i].output(output);
}
}
else
{
pops[i].output(output);
for (unsigned int i = 0; i < pops.size(); i++)
{
pops[i].output(output);
}
}
fprintf(output, " rgo=\n");
fprintf(output, " {\n");
Expand Down
2 changes: 2 additions & 0 deletions cpp_version/EU3toV2Converter/V2Province.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class V2Province {
void setCulture(string);
void setReligion(string);
bool isColonial();
void addOldPop(V2Pop);
void createPops(EU3Province* oldProvince, EU3Country* oldCountry);
void output(FILE*);
private:
Expand All @@ -32,6 +33,7 @@ class V2Province {
//cores
bool colonial;
int oldPopulation;
vector<V2Pop> oldPops;
vector<V2Pop> pops;
string culture;
string religion;
Expand Down
61 changes: 60 additions & 1 deletion cpp_version/EU3toV2Converter/V2World.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "V2World.h"

void V2World::init(Object* obj)
void V2World::init(Object* obj, string V2Loc)
{
std::string key;
std::vector<Object*> leaves = obj->getLeaves();
Expand All @@ -18,6 +18,65 @@ void V2World::init(Object* obj)
}
}

struct _finddata_t popsFileData;
intptr_t fileListing;
if ( (fileListing = _findfirst( (V2Loc + "\\history\\pops\\1836.1.1\\*").c_str(), &popsFileData)) == -1L)
{
log("Could not open pops files.\n");
return;
}
do
{
if (popsFileData.name == "." || popsFileData.name == "..")
{
continue;
}

Object* obj2; // generic object
ifstream read; // ifstream for reading files
initParser();
obj2 = Parser::topLevel;
read.open( (V2Loc + "\\history\\pops\\1836.1.1\\" + popsFileData.name).c_str() );
if (!read.is_open())
{
log("Error: Could not open %s\n", popsFileData.name);
printf("Error: Could not open %s\n", popsFileData.name);
read.close();
continue;
}
readFile(read);
read.close();

leaves = obj2->getLeaves();
for (unsigned int j = 0; j < leaves.size(); j++)
{
int provNum = atoi(leaves[j]->getKey().c_str());
unsigned int k = 0;
while (k < provinces.size() && provNum != provinces[k].getNum())
{
k++;
}
if (k == provinces.size())
{
log("Could not find province %d for original pops.\n", provNum);
continue;
}
else
{
vector<Object*> pops = leaves[j]->getLeaves();
for(unsigned int l = 0; l < pops.size(); l++)
{
V2Pop newPop;
newPop.setType(pops[l]->getKey());
newPop.setCulture(pops[l]->getLeaf("culture"));
newPop.setReligion(pops[l]->getLeaf("religion"));
newPop.setSize(atoi(pops[l]->getLeaf("size").c_str()));
provinces[k].addOldPop(newPop);
}
}
}
} while(_findnext(fileListing, &popsFileData) == 0);
_findclose(fileListing);
}


Expand Down
4 changes: 3 additions & 1 deletion cpp_version/EU3toV2Converter/V2World.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#include <stdio.h>
#include <vector>
#include <io.h>
#include "V2Province.h"
#include "V2Country.h"
#include "V2State.h"
#include "EU3World.h"
#include "Parsers/Object.h"
#include "Parsers/Parser.h"
#include "Mapper.h"
#include "Log.h"
#include "tempFuncs.h"
Expand All @@ -16,7 +18,7 @@ using namespace std;

class V2World {
public:
void init(Object* obj);
void init(Object* obj, string V2Loc);
void addPotentialCountries(ifstream &countriesMapping, string V2Loc);
vector<string> getPotentialTags();
void convertCountries(EU3World sourceWorld, countryMapping countryMap, cultureMapping cultureMap, religionMapping religionMap);
Expand Down

0 comments on commit 48da078

Please sign in to comment.