Bazaar developer reference

CvPlot::setPlotType(PlotTypes, bool, bool, bool)

Defined in
CvPlot.cpp, line 5950
Class
CvPlot
Hook name
CivHooks::CvPlot_setPlotType
Lua events
GameEvents.TerraformingPlot

Hooks

static bool BeforeCvPlot_setPlotType(CvPlot* self, PlotTypes eNewValue, bool bRecalculate, bool bRebuildGraphics, bool bEraseUnitsIfWater);static void AfterCvPlot_setPlotType(CvPlot* self, PlotTypes eNewValue, bool bRecalculate, bool bRebuildGraphics, bool bEraseUnitsIfWater);static void ReplaceCvPlot_setPlotType(void (*original)(CvPlot*, PlotTypes, bool, bool, bool), CvPlot* self, PlotTypes eNewValue, bool bRecalculate, bool bRebuildGraphics, bool bEraseUnitsIfWater);CivRegisterBefore<CivHooks::CvPlot_setPlotType>(host, &BeforeCvPlot_setPlotType);CivRegisterAfter<CivHooks::CvPlot_setPlotType>(host, &AfterCvPlot_setPlotType);CivRegisterReplace<CivHooks::CvPlot_setPlotType>(host, &ReplaceCvPlot_setPlotType);

Code

5950void CvPlot::setPlotType(PlotTypes eNewValue, bool bRecalculate, bool bRebuildGraphics, bool bEraseUnitsIfWater)5951{5952	CvArea* pNewArea;5953	CvArea* pCurrArea;5954	CvArea* pLastArea;5955	CvPlot* pLoopPlot;5956	bool bWasWater;5957	bool bRecalculateAreas;5958	int iAreaCount;5959	int iI;5960	5961#if defined(MOD_BUGFIX_PLOT_VALIDATION)5962	if (eNewValue <= NO_PLOT || eNewValue >= NUM_PLOT_TYPES) return;5963#endif59645965	if(getPlotType() != eNewValue)5966	{5967		if((getPlotType() == PLOT_OCEAN) || (eNewValue == PLOT_OCEAN))5968		{5969			erase(bEraseUnitsIfWater);5970		}59715972		bWasWater = isWater();59735974		updateSeeFromSight(false);59755976#if defined(MOD_EVENTS_TERRAFORMING)5977		if (MOD_EVENTS_TERRAFORMING) {5978			GAMEEVENTINVOKE_HOOK(GAMEEVENT_TerraformingPlot, TERRAFORMINGEVENT_PLOT, m_iX, m_iY, 0, eNewValue, m_ePlotType, -1, -1);5979		}5980#endif59815982		m_ePlotType = eNewValue;59835984		updateYield();59855986		updateSeeFromSight(true);59875988		if((getTerrainType() == NO_TERRAIN) || (GC.getTerrainInfo(getTerrainType())->isWater() != isWater()))5989		{5990			if(isWater())5991			{5992				if(isAdjacentToLand())5993				{5994					setTerrainType(((TerrainTypes)(GC.getSHALLOW_WATER_TERRAIN())), bRecalculate, bRebuildGraphics);5995					m_bIsAdjacentToLand = true;5996				}5997				else5998				{5999					setTerrainType(((TerrainTypes)(GC.getDEEP_WATER_TERRAIN())), bRecalculate, bRebuildGraphics);6000					m_bIsAdjacentToLand = false;6001				}6002			}6003			else6004			{6005				setTerrainType(((TerrainTypes)(GC.getLAND_TERRAIN())), bRecalculate, bRebuildGraphics);6006			}6007		}60086009		GC.getStepFinder().ForceReset();60106011		if(bWasWater != isWater())6012		{6013			if(bRecalculate)6014			{6015				for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6016				{6017					pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));60186019					if(pLoopPlot != NULL)6020					{6021						if(pLoopPlot->isWater())6022						{6023							if(pLoopPlot->isAdjacentToLand())6024							{6025								pLoopPlot->setTerrainType(((TerrainTypes)(GC.getSHALLOW_WATER_TERRAIN())), bRecalculate, bRebuildGraphics);6026								m_bIsAdjacentToLand = true;6027							}6028							else6029							{6030								pLoopPlot->setTerrainType(((TerrainTypes)(GC.getDEEP_WATER_TERRAIN())), bRecalculate, bRebuildGraphics);6031								m_bIsAdjacentToLand = false;6032							}6033						}6034					}6035				}6036			}60376038			for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6039			{6040				pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));60416042				if(pLoopPlot != NULL)6043				{6044					pLoopPlot->updateYield();6045				}6046			}60476048#if defined(MOD_GLOBAL_CITY_WORKING)6049			for(iI = 0; iI < MAX_CITY_PLOTS; ++iI)6050#else6051			for(iI = 0; iI < NUM_CITY_PLOTS; ++iI)6052#endif6053			{6054				pLoopPlot = plotCity(getX(), getY(), iI);60556056				if(pLoopPlot != NULL)6057				{6058					pLoopPlot->updatePotentialCityWork();6059				}6060			}60616062			GC.getMap().changeLandPlots((isWater()) ? -1 : 1);60636064			if(getResourceType() != NO_RESOURCE)6065			{6066				GC.getMap().changeNumResourcesOnLand(getResourceType(), ((isWater()) ? -1 : 1));6067			}60686069			if(isOwned())6070			{6071				GET_PLAYER(getOwner()).changeTotalLand((isWater()) ? -1 : 1);6072				GET_TEAM(getTeam()).changeTotalLand((isWater()) ? -1 : 1);6073			}60746075			if(bRecalculate)6076			{6077				pNewArea = NULL;6078				bRecalculateAreas = false;60796080				if(isWater())6081				{6082					for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6083					{6084						pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));60856086						if(pLoopPlot != NULL)6087						{6088							if(pLoopPlot->area()->isWater())6089							{6090								if(pNewArea == NULL)6091								{6092									pNewArea = pLoopPlot->area();6093								}6094								else if(pNewArea != pLoopPlot->area())6095								{6096									bRecalculateAreas = true;6097									break;6098								}6099							}6100						}6101					}6102				}6103				else6104				{6105					for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6106					{6107						pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));61086109						if(pLoopPlot != NULL)6110						{6111							if(!(pLoopPlot->area()->isWater()))6112							{6113								if(pNewArea == NULL)6114								{6115									pNewArea = pLoopPlot->area();6116								}6117								else if(pNewArea != pLoopPlot->area())6118								{6119									bRecalculateAreas = true;6120									break;6121								}6122							}6123						}6124					}6125				}61266127				if(!bRecalculateAreas)6128				{6129					pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)(NUM_DIRECTION_TYPES - 1)));61306131					if(pLoopPlot != NULL)6132					{6133						pLastArea = pLoopPlot->area();6134					}6135					else6136					{6137						pLastArea = NULL;6138					}61396140					iAreaCount = 0;61416142					for(iI = 0; iI < NUM_DIRECTION_TYPES; ++iI)6143					{6144						pLoopPlot = plotDirection(getX(), getY(), ((DirectionTypes)iI));61456146						if(pLoopPlot != NULL)6147						{6148							pCurrArea = pLoopPlot->area();6149						}6150						else6151						{6152							pCurrArea = NULL;6153						}61546155						if(pCurrArea != pLastArea)6156						{6157							iAreaCount++;6158						}61596160						pLastArea = pCurrArea;6161					}61626163					if(iAreaCount > 2)6164					{6165						bRecalculateAreas = true;6166					}6167				}61686169				if(bRecalculateAreas)6170				{6171					GC.getMap().recalculateAreas();6172				}6173				else6174				{6175					setArea(FFreeList::INVALID_INDEX);61766177					if((area() != NULL) && (area()->getNumTiles() == 1))6178					{6179						GC.getMap().deleteArea(getArea());6180					}61816182					if(pNewArea == NULL)6183					{6184						pNewArea = GC.getMap().addArea();6185						pNewArea->init(pNewArea->GetID(), isWater());6186					}61876188					setArea(pNewArea->GetID());6189				}6190			}6191		}61926193		if(bRebuildGraphics && GC.IsGraphicsInitialized())6194		{6195			//Update terrain graphical6196			setLayoutDirty(true);6197		}6198	}6199}

Calls

Called by