Ejemplo n.º 1
0
void CvMapGenerator::addFeatures()
{
	PROFILE_FUNC();

	CvPlot* pPlot;
	int iI, iJ;

	if (gDLL->getPythonIFace()->pythonAddFeatures() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl())
	{
		return; // Python override
	}

	for (iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
	{
		pPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
		FAssert(pPlot != NULL);

		for (iJ = 0; iJ < GC.getNumFeatureInfos(); iJ++)
		{
			if (pPlot->canHaveFeature((FeatureTypes)iJ))
			{
				if (GC.getGameINLINE().getMapRandNum(10000, "addFeaturesAtPlot") < GC.getFeatureInfo((FeatureTypes)iJ).getAppearanceProbability())
				{
					pPlot->setFeatureType((FeatureTypes)iJ);
				}
			}
		}
	}
}
void CvMapGenerator::addFeatures()
{
	PROFILE("CvMapGenerator::addFeatures");

	if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "addFeatures", NULL))
	{
		if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl())
		{
			return;
		}
	}

	for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
	{
		CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
		FAssert(pPlot != NULL);

		for (int iJ = 0; iJ < GC.getNumFeatureInfos(); iJ++)
		{
			if (pPlot->canHaveFeature((FeatureTypes)iJ))
			{
				if (GC.getGameINLINE().getMapRandNum(10000, "addFeaturesAtPlot") < GC.getFeatureInfo((FeatureTypes)iJ).getAppearanceProbability())
				{
					pPlot->setFeatureType((FeatureTypes)iJ);
				}
			}
		}
	}
}
Ejemplo n.º 3
0
void CvMapGenerator::eraseFeatures()
{
	for (int i = 0; i < GC.getMapINLINE().numPlotsINLINE(); i++)
	{
		CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(i);
		pPlot->setFeatureType(NO_FEATURE);
	}
}
Ejemplo n.º 4
0
///TKs Med TradeScreens
void CvMapGenerator::addEurope()
{
	PROFILE_FUNC();
	gDLL->NiTextOut("Adding Europe...");

	for (int iEurope = 0; iEurope < GC.getNumEuropeInfos(); ++iEurope)
	{
		EuropeTypes eEurope = (EuropeTypes) iEurope;
		CvEuropeInfo& kEurope = GC.getEuropeInfo(eEurope);
		int iWidthPercent = kEurope.getWidthPercent();
		gDLL->getPythonIFace()->pythonGetEuropeWidthPercent(eEurope, &iWidthPercent);
		int iMinLandDistance = kEurope.getMinLandDistance();
		gDLL->getPythonIFace()->pythonGetEuropeMinLandDistance(eEurope, &iMinLandDistance);

		//try several times until at least one start europe is found
		//bool bWaterRoute = (kEurope.getDomainsValid(DOMAIN_SEA));
		bool bAnyEuropeFound = false;
		bool bCheckDirection = true;
		//int iDomainCount = 0;
		int iGridWidth = GC.getMapINLINE().getGridWidthINLINE();
		int iGridHeight = GC.getMapINLINE().getGridHeightINLINE();
		for ( ; iMinLandDistance >= 0 && !bAnyEuropeFound; iMinLandDistance--)
		{
			for (int i = 0; i < GC.getMapINLINE().numPlotsINLINE(); ++i)
			{
				CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(i);
				bCheckDirection = true;
				if (!kEurope.getDomainsValid(DOMAIN_SEA) && pPlot->isWater())
				{
                    bCheckDirection = false;
				}
				//else if (kEurope.getDomainsValid(DOMAIN_SEA))
				//{
					//iDomainCount++;
				//}

				if (!kEurope.getDomainsValid(DOMAIN_LAND) && !pPlot->isWater())
				{
				    bCheckDirection = false;
				}
				//else if (kEurope.getDomainsValid(DOMAIN_LAND))
				//{
					//iDomainCount++;
				//}

				if (bCheckDirection && !pPlot->isTradeScreenAccessPlot(eEurope))
				{
					for (int iDir = 0; iDir < NUM_DIRECTION_TYPES; ++iDir)
					{
						/*DIRECTION_NORTH,
						DIRECTION_NORTHEAST,
						DIRECTION_EAST,
						DIRECTION_SOUTHEAST,
						DIRECTION_SOUTH,
						DIRECTION_SOUTHWEST,
						DIRECTION_WEST,
						DIRECTION_NORTHWEST,*/
						bool bEurope = false;
						
						if (kEurope.getDirectionValid(iDir))
						{
							switch ((DirectionTypes)iDir)
							{
							case DIRECTION_EAST:
								bEurope = (pPlot->getX_INLINE() > (100 - iWidthPercent) * iGridWidth / 100 && pPlot->getY_INLINE() <= (100 - iWidthPercent) * iGridHeight / 100 && pPlot->getY_INLINE() >= iWidthPercent * iGridHeight / 100);
								break;
							case DIRECTION_NORTHEAST:
								bEurope = (pPlot->getX_INLINE() > (100 - iWidthPercent) * iGridWidth / 100 && pPlot->getY_INLINE() > (100 - iWidthPercent) * iGridHeight / 100);
								break;
							case DIRECTION_SOUTHEAST:
								bEurope = (pPlot->getX_INLINE() > (100 - iWidthPercent) * iGridWidth / 100 && pPlot->getY_INLINE() < iWidthPercent * iGridHeight / 100);
								break;
							case DIRECTION_WEST:
								bEurope = (pPlot->getX_INLINE() < iWidthPercent * iGridWidth / 100 && pPlot->getY_INLINE() <= (100 - iWidthPercent) * iGridHeight / 100 && pPlot->getY_INLINE() >= iWidthPercent * iGridHeight / 100);
								break;
							case DIRECTION_NORTHWEST:
								bEurope = (pPlot->getX_INLINE() < (100 - iWidthPercent) * iGridWidth / 100 && pPlot->getY_INLINE() > (100 - iWidthPercent) * iGridHeight / 100);
								break;
							case DIRECTION_SOUTHWEST:
								bEurope = (pPlot->getX_INLINE() < (100 - iWidthPercent) * iGridWidth / 100 && pPlot->getY_INLINE() < iWidthPercent * iGridHeight / 100);
								break;
							case DIRECTION_NORTH:
								bEurope = (pPlot->getY_INLINE() > (100 - iWidthPercent) * iGridHeight / 100 && pPlot->getX_INLINE() > iWidthPercent * iGridWidth / 100 && pPlot->getX_INLINE() < (100 - iWidthPercent) * iGridWidth / 100);
								break;
							case DIRECTION_SOUTH:
								bEurope = (pPlot->getY_INLINE() < iWidthPercent * iGridHeight / 100 && pPlot->getX_INLINE() > iWidthPercent * iGridWidth / 100 && pPlot->getX_INLINE() < (100 - iWidthPercent) * iGridWidth / 100);
								break;
							default:
								FAssertMsg(false, "Invalid direction");
								break;
							}
						}

						if (bEurope)
						{
							
								if (kEurope.getDomainsValid(DOMAIN_SEA))
								{
									for (int i = -iMinLandDistance; i <= iMinLandDistance && bEurope; i++)
									{
										for (int j = -iMinLandDistance; j <= iMinLandDistance && bEurope; j++)
										{
											CvPlot* pLoopPlot = ::plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), i, j);
											if (pLoopPlot != NULL)
											{
												if (!pLoopPlot->isWater())
												{
													bEurope = false;
												}
											}
										}
									}

									if (bEurope)
									{
										if (pPlot->getFeatureType() != NO_FEATURE && GC.getFeatureInfo(pPlot->getFeatureType()).isImpassable())
										{
											pPlot->setFeatureType(NO_FEATURE);
										}

										if (pPlot->isImpassable())
										{
											bEurope = false;
										}
									}

									if (bEurope)
									{
										if (!pPlot->isEurope())
										{
											pPlot->setEurope(eEurope);
										}
										pPlot->setTradeScreenAccess(eEurope);
										bAnyEuropeFound = true;
									}

									bEurope = true;
								}
								
								if (kEurope.getDomainsValid(DOMAIN_LAND))
								{
								
									switch ((DirectionTypes)iDir)
									{
									case DIRECTION_EAST:
										if (pPlot->getX_INLINE() < (iGridWidth - kEurope.getMaxLandCoverage()))
										{
											bEurope = false;
										}
										break;
									case DIRECTION_NORTHEAST:
										if (pPlot->getX_INLINE() < (iGridWidth - kEurope.getMaxLandCoverage()) && pPlot->getY_INLINE() < (iGridHeight - kEurope.getMaxLandCoverage()))
										{
											bEurope = false;
										}
										break;
									case DIRECTION_SOUTHEAST:
										if (pPlot->getY_INLINE() > kEurope.getMaxLandCoverage() && pPlot->getX_INLINE() < (iGridWidth - kEurope.getMaxLandCoverage()))
										{
											bEurope = false;
										}
										break;
									case DIRECTION_WEST:
										if (pPlot->getX_INLINE() > kEurope.getMaxLandCoverage())
										{
											bEurope = false;
										}
										break;
									case DIRECTION_NORTHWEST:
										if (pPlot->getX_INLINE() > kEurope.getMaxLandCoverage() && pPlot->getY_INLINE() < (iGridHeight - kEurope.getMaxLandCoverage()))
										{
											bEurope = false;
										}
										break;
									case DIRECTION_SOUTHWEST:
										if (pPlot->getY_INLINE() > kEurope.getMaxLandCoverage() && pPlot->getX_INLINE() > kEurope.getMaxLandCoverage())
										{
											bEurope = false;
										}
										break;
									case DIRECTION_NORTH:
										if (pPlot->getY_INLINE() < (iGridHeight - kEurope.getMaxLandCoverage()))
										{
											bEurope = false;
										}
										break;
									case DIRECTION_SOUTH:
										if (pPlot->getY_INLINE() > kEurope.getMaxLandCoverage())
										{
											bEurope = false;
										}
										break;
									default:
										FAssertMsg(false, "Invalid direction");
										break;
									}

									if (bEurope)
									{
										if (pPlot->getFeatureType() != NO_FEATURE && GC.getFeatureInfo(pPlot->getFeatureType()).isImpassable())
										{
											pPlot->setFeatureType(NO_FEATURE);
										}

										if (pPlot->isImpassable())
										{
											bEurope = false;
										}
									}

									if (bEurope)
									{
										if (!pPlot->isEurope())
										{
											pPlot->setEurope(eEurope);
										}
										pPlot->setTradeScreenAccess(eEurope);
										bAnyEuropeFound = true;
									}
								}
							
						}

						/*if (bEurope)
						{
							if (pPlot->getFeatureType() != NO_FEATURE && GC.getFeatureInfo(pPlot->getFeatureType()).isImpassable())
							{
								pPlot->setFeatureType(NO_FEATURE);
							}

							if (pPlot->isImpassable())
							{
								bEurope = false;
							}
						}

						if (bEurope)
						{
							if (!pPlot->isEurope())
							{
								pPlot->setEurope(eEurope);
							}
							pPlot->setTradeScreenAccess(eEurope);
							bAnyEuropeFound = true;
						}*/
					}
				}
			}
		}
	}
}