Bazaar developer reference

CvMap::DefaultContinentStamper()

Defined in
CvMap.cpp, line 1962
Class
CvMap
Hook name
CivHooks::CvMap_DefaultContinentStamper

Hooks

static bool BeforeCvMap_DefaultContinentStamper(CvMap* self);static void AfterCvMap_DefaultContinentStamper(CvMap* self);static void ReplaceCvMap_DefaultContinentStamper(void (*original)(CvMap*), CvMap* self);CivRegisterBefore<CivHooks::CvMap_DefaultContinentStamper>(host, &BeforeCvMap_DefaultContinentStamper);CivRegisterAfter<CivHooks::CvMap_DefaultContinentStamper>(host, &AfterCvMap_DefaultContinentStamper);CivRegisterReplace<CivHooks::CvMap_DefaultContinentStamper>(host, &ReplaceCvMap_DefaultContinentStamper);

Code

1962void CvMap::DefaultContinentStamper()1963{1964	const int iNumContinentTypes = 4;1965	const int iMinimumThresholdToBeAContinentIMHO = 10;19661967	int iNumLargeContinents = 0;1968	int iLargeContinentsID[iNumContinentTypes] = {-1,-1,-1,-1};1969	int iLargeContinentsSize[iNumContinentTypes] = {0,0,0,0};1970	int iLargeContinentsArtStyle[iNumContinentTypes] = {0,0,0,0};1971	int iLargeContinentsX[iNumContinentTypes] = {0,0,0,0};1972	int iLargeContinentsY[iNumContinentTypes] = {0,0,0,0};19731974	recalculateLandmasses();19751976	CvLandmass* pLoopMass;1977	int iLoop;19781979	// find the 4 (because that is how many art styles we have) biggest continents - if there aren't 4, oh well1980	for(pLoopMass = firstLandmass(&iLoop); pLoopMass != NULL; pLoopMass = nextLandmass(&iLoop))1981	{1982		if(!pLoopMass->isWater())1983		{1984			int iBestContinent;1985			int iNumTiles = pLoopMass->getNumTiles();1986			for(iBestContinent=0; iBestContinent<iNumContinentTypes; iBestContinent++)1987			{1988				if(iNumTiles >= iMinimumThresholdToBeAContinentIMHO && iNumTiles > iLargeContinentsSize[iBestContinent])1989				{1990					// push the rest of the tiles down one and store this1991					for(int iloop=iNumContinentTypes-1; iloop>iBestContinent; iloop--)1992					{1993						iLargeContinentsID[iloop] = iLargeContinentsID[iloop-1];1994						iLargeContinentsSize[iloop] = iLargeContinentsSize[iloop-1];1995					}1996					iLargeContinentsID[iBestContinent] = pLoopMass->GetID();1997					iLargeContinentsSize[iBestContinent] = iNumTiles;1998					break;1999				}2000			}2001		}2002	}20032004	// for each of these large continents give them unique art style (randomly)2005	shuffleArray(iLargeContinentsArtStyle, 4, GC.getGame().getMapRand());2006	for(int i=0; i < iNumContinentTypes; i++)2007	{2008		iLargeContinentsArtStyle[i]++;2009	}20102011	for(int i=0; i < iNumContinentTypes; i++)2012	{2013		if(iLargeContinentsID[i] != -1)2014			iNumLargeContinents++;2015	}20162017	for(int i=0; i < iNumLargeContinents; i++)2018	{2019		CvLandmass* pLandmass = getLandmass(iLargeContinentsID[i]);2020		iLargeContinentsX[i] = pLandmass->GetCentroidX();2021		iLargeContinentsY[i] = pLandmass->GetCentroidY();2022	}20232024	// for all landmasses in the game2025	for(pLoopMass = firstLandmass(&iLoop); pLoopMass != NULL; pLoopMass = nextLandmass(&iLoop))2026	{2027		int iX = pLoopMass->GetCentroidX();2028		int iY = pLoopMass->GetCentroidY();2029		// if water continent type = 02030		if(pLoopMass->isWater())2031		{2032			pLoopMass->SetContinentType(0);2033		}2034		else // if land2035		{2036			// continent type = continent type of the closest of the "big four"2037			int iBestPlotDistance = 999999;2038			for(int i=0; i < iNumLargeContinents; i++)2039			{2040				int iPlotDistance = plotDistance(iX, iY, iLargeContinentsX[i], iLargeContinentsY[i]);2041				if(iPlotDistance < iBestPlotDistance)2042				{2043					iBestPlotDistance = iPlotDistance;2044					pLoopMass->SetContinentType(iLargeContinentsArtStyle[i]);2045				}2046			}2047		}2048	}20492050	// now stamp all plots with the relevant data2051	for(int iI = 0; iI < numPlots(); iI++)2052	{2053		CvPlot* pLoopPlot = plotByIndexUnchecked(iI);2054		CvLandmass* pLandmass = getLandmass(pLoopPlot->getLandmass());2055		if(pLandmass != NULL)2056		{2057			pLoopPlot->SetContinentType(pLandmass->GetContinentType());2058		}2059	}2060}

Calls

Called by