Пример #1
0
int CountryRegion::CreateData(vector<BufferData> &regData) {
	vector<BufferData>::iterator iter = regData.begin();
    while (iter != regData.end()) {
		if ( 2 == (*iter).id.length() ) {
			addProvince((*iter).name, (*iter).id);
		}
		if ( 4 == (*iter).id.length() ) {
			addCity((*iter).name, (*iter).id, (*iter).upId);
		}
		if ( 4 < (*iter).id.length() ) {
			addCounty((*iter).name, (*iter).id, (*iter).upId);
		}
        ++iter;
    }

/*
	// 增加省
	vector<BufferData>::iterator iter = regData.data.begin();
    while (iter != regData.data.end()) {
		if ( 2 == (*iter).id.length() ) {
			addProvince((*iter).name, (*iter).id);
		}
        ++iter;
    }

	// 增加市
	iter = regData.data.begin();
    while (iter != regData.data.end()) {
		if ( 4 == (*iter).id.length() ) {
			addCity((*iter).name, (*iter).id, (*iter).upId);
		}
        ++iter;
    }

	// 增加县
	iter = regData.data.begin();
    while (iter != regData.data.end()) {
		if ( 4 < (*iter).id.length() ) {
			addCounty((*iter).name, (*iter).id, (*iter).upId);
		}
        ++iter;
    }
	//*/

	return 0;
}
void EU3Country::eatCountry(EU3Country* target)
{
	// autocannibalism is forbidden
	if (target->getTag() == tag)
		return;

	// for calculation of weighted averages
	int totalProvinces = target->provinces.size() + provinces.size();
	if (totalProvinces == 0)
		totalProvinces = 1;
	double myWeight = (double)provinces.size() / (double)totalProvinces;
	double targetWeight = (double)target->provinces.size() / (double)totalProvinces;

	// acquire target's cores (always)
	for (unsigned int j = 0; j < target->cores.size(); j++)
	{
		addCore(target->cores[j]);
		target->cores[j]->addCore(tag);
		target->cores[j]->removeCore(target->tag);
	}

	// everything else, do only if this country actually currently exists
	if (target->provinces.size() > 0)
	{
		// acquire target's provinces
		for (unsigned int j = 0; j < target->provinces.size(); j++)
		{
			addProvince(target->provinces[j]);
			target->provinces[j]->setOwner(this);
		}

		// acquire target's armies, navies, admirals, and generals
		armies.insert(armies.end(), target->armies.begin(), target->armies.end());
		leaders.insert(leaders.end(), target->leaders.begin(), target->leaders.end());

		// acquire the target's treasury and income, as well as their liabilities
		treasury += target->treasury;
		estMonthlyIncome += target->estMonthlyIncome;
		loans.insert(loans.end(), target->loans.begin(), target->loans.end());

		// rebalance prestige, badboy, inflation and techs from weighted average
		prestige					= myWeight * prestige					+ targetWeight * target->prestige;
		badboy					= myWeight * badboy						+ targetWeight * target->badboy * (getBadboyLimit() / target->getBadboyLimit());
		inflation				= myWeight * inflation					+ targetWeight * target->inflation;
		landTech					= myWeight * landTech					+ targetWeight * target->landTech;
		navalTech				= myWeight * navalTech					+ targetWeight * target->navalTech;
		tradeTech				= myWeight * tradeTech					+ targetWeight * target->tradeTech;
		productionTech			= myWeight * productionTech			+ targetWeight * target->productionTech;
		governmentTech			= myWeight * governmentTech			+ targetWeight * target->governmentTech;
		armyInvestment			= myWeight * armyInvestment			+ targetWeight * target->armyInvestment;
		navyInvestment			= myWeight * navyInvestment			+ targetWeight * target->navyInvestment;
		commerceInvestment	= myWeight * commerceInvestment		+ targetWeight * target->commerceInvestment;
		industryInvestment	= myWeight * industryInvestment		+ targetWeight * target->industryInvestment;
		cultureInvestment		= myWeight * cultureInvestment		+ targetWeight * target->cultureInvestment;
		estMonthlyIncome		= myWeight * estMonthlyIncome			+ targetWeight * target->estMonthlyIncome;
	}

	// coreless, landless countries will be cleaned up automatically
	target->clearProvinces();
	target->clearCores();

	LOG(LogLevel::Debug) << "Merged " << target->tag << " into " << tag;
}
Пример #3
0
void V2Country::eatCountry(V2Country* target)
{
	// autocannibalism is forbidden
	if (target->getTag() == tag)
		return;

	// for calculation of weighted averages
	int totalProvinces = target->provinces.size() + provinces.size();
	if (totalProvinces == 0)
		totalProvinces = 1;
	double myWeight = (double)provinces.size() / (double)totalProvinces;
	double targetWeight = (double)target->provinces.size() / (double)totalProvinces;

	// acquire target's cores (always)
	for (unsigned int j = 0; j < target->cores.size(); j++)
	{
		addCore(target->cores[j]);
		target->cores[j]->addCore(tag);
		target->cores[j]->removeCore(target->tag);
	}

	// everything else, do only if this country actually currently exists
	if (target->provinces.size() > 0)
	{
		// acquire target's provinces
		for (unsigned int j = 0; j < target->provinces.size(); j++)
		{
			addProvince(target->provinces[j]);
			target->provinces[j]->setOwner(tag);
		}

		// acquire target's armies, navies, admirals, and generals
		armies.insert(armies.end(), target->armies.begin(), target->armies.end());
		//XXX: leaders.insert(leaders.end(), target->leaders.begin(), target->leaders.end());

		// acquire the target's treasury and reserves, as well as their liabilities
		money += target->money;
		bankReserves += target->bankReserves;
		//XXX: loans.insert(loans.end(), target->loans.begin(), target->loans.end());

		// rebalance prestige, badboy from weighted average
		prestige		= myWeight * prestige		+ targetWeight * target->prestige;
		badboy			= myWeight * badboy			+ targetWeight * target->badboy;

		// give merged nation any techs owned by either nation
		vector<string> ttechs = target->getTechs();
		for (vector<string>::iterator tech = ttechs.begin(); tech != ttechs.end(); ++tech)
		{
			vector<string>::iterator stech = std::find(techs.begin(), techs.end(), *tech);
			if (stech == techs.end())
				techs.push_back(*tech);
		}

		// and do the same with inventions
		inventionStatus* tinvs = target->getInventionStatusArray();
		for (int i = 0; i < naval_exercises; ++i)
		{
			inventions[i] = std::max(inventions[i], tinvs[i]);
		}
	}

	// coreless, landless countries will be cleaned up automatically
	target->clearProvinces();
	target->clearCores();

	log("Merged %s into %s\n", target->tag.c_str(), tag.c_str());
}