Bazaar developer reference

CvPlot::setRouteType(RouteTypes)

Defined in
CvPlot.cpp, line 7187
Class
CvPlot
Hook name
CivHooks::CvPlot_setRouteType
Lua events
GameEvents.TileRouteChanged

Hooks

static bool BeforeCvPlot_setRouteType(CvPlot* self, RouteTypes eNewValue);static void AfterCvPlot_setRouteType(CvPlot* self, RouteTypes eNewValue);static void ReplaceCvPlot_setRouteType(void (*original)(CvPlot*, RouteTypes), CvPlot* self, RouteTypes eNewValue);CivRegisterBefore<CivHooks::CvPlot_setRouteType>(host, &BeforeCvPlot_setRouteType);CivRegisterAfter<CivHooks::CvPlot_setRouteType>(host, &AfterCvPlot_setRouteType);CivRegisterReplace<CivHooks::CvPlot_setRouteType>(host, &ReplaceCvPlot_setRouteType);

Code

7187void CvPlot::setRouteType(RouteTypes eNewValue)7188{7189	bool bOldRoute;7190	RouteTypes eOldRoute = getRouteType();7191	int iI;71927193#if defined(MOD_BUGFIX_PLOT_VALIDATION)7194	if (eNewValue < NO_ROUTE) return;7195	if (eNewValue > NO_ROUTE && GC.getRouteInfo(eNewValue) == NULL) return;7196#endif71977198	if(eOldRoute != eNewValue || (eOldRoute == eNewValue && IsRoutePillaged()))7199	{7200		bOldRoute = isRoute(); // XXX is this right???72017202		// Remove old effects7203		if(eOldRoute != NO_ROUTE && !isCity())7204		{7205			// Owned by someone7206			if(isOwned())7207			{7208				CvRouteInfo& oldRouteInfo = *GC.getRouteInfo(eOldRoute);7209				CvPlayer& owningPlayer = GET_PLAYER(getOwner());72107211				// Maintenance change!7212				if(MustPayMaintenanceHere(getOwner()))7213				{7214					GET_PLAYER(getOwner()).GetTreasury()->ChangeBaseImprovementGoldMaintenance(-GC.getRouteInfo(getRouteType())->GetGoldMaintenance());7215				}72167217				// Update the amount of a Resource used up by a Route which was previously here7218				int iNumResourceInfos = GC.getNumResourceInfos();7219				for(int iResourceLoop = 0; iResourceLoop < iNumResourceInfos; iResourceLoop++)7220				{7221					int iRequiredResources = oldRouteInfo.getResourceQuantityRequirement(iResourceLoop);7222					if(iRequiredResources > 0)7223					{7224						owningPlayer.changeNumResourceUsed((ResourceTypes) iResourceLoop, -iRequiredResources);7225					}7226				}7227			}72287229			// Someone built a route here in an unowned plot, remove the effects of it (since we're changing it to something else)7230			if(GetPlayerResponsibleForRoute() != NO_PLAYER)7231			{7232				// Maintenance change!7233				if(MustPayMaintenanceHere(GetPlayerResponsibleForRoute()))7234				{7235					CvRouteInfo* pkRouteInfo = GC.getRouteInfo(getRouteType());7236					if(pkRouteInfo)7237					{7238						GET_PLAYER(GetPlayerResponsibleForRoute()).GetTreasury()->ChangeBaseImprovementGoldMaintenance(-pkRouteInfo->GetGoldMaintenance());7239					}7240				}72417242				SetPlayerResponsibleForRoute(NO_PLAYER);7243			}7244		}72457246		// Route switch here!7247		m_eRouteType = eNewValue;72487249		// Apply new effects7250		if(isOwned() && eNewValue != NO_ROUTE && !isCity())7251		{7252			CvRouteInfo* newRouteInfo = GC.getRouteInfo(eNewValue);7253			if(newRouteInfo)7254			{7255				CvPlayer& owningPlayer = GET_PLAYER(getOwner());72567257				// Maintenance7258				if(MustPayMaintenanceHere(getOwner()))7259				{7260					GET_PLAYER(getOwner()).GetTreasury()->ChangeBaseImprovementGoldMaintenance(newRouteInfo->GetGoldMaintenance());7261				}72627263				// Update the amount of a Resource used up by this Route7264				int iNumResourceInfos = GC.getNumResourceInfos();7265				for(int iResourceLoop = 0; iResourceLoop < iNumResourceInfos; iResourceLoop++)7266				{7267					int iRequiredResources = newRouteInfo->getResourceQuantityRequirement(iResourceLoop);7268					if(iRequiredResources > 0)7269					{7270						owningPlayer.changeNumResourceUsed((ResourceTypes) iResourceLoop, iRequiredResources);7271					}7272				}7273			}7274		}72757276		// make sure this plot is not disabled7277#if defined(MOD_EVENTS_TILE_IMPROVEMENTS)7278		SetRoutePillaged(false, false);7279#else7280		SetRoutePillaged(false);7281#endif72827283		for(iI = 0; iI < MAX_TEAMS; ++iI)7284		{7285			if(GET_TEAM((TeamTypes)iI).isAlive())7286			{7287				if(isVisible((TeamTypes)iI))7288				{7289					setRevealedRouteType((TeamTypes)iI, getRouteType());7290				}7291			}7292		}72937294		updateYield();72957296#if defined(MOD_EVENTS_TILE_IMPROVEMENTS)7297		if (MOD_EVENTS_TILE_IMPROVEMENTS) {7298			GAMEEVENTINVOKE_HOOK(GAMEEVENT_TileRouteChanged, getX(), getY(), getOwner(), eOldRoute, eNewValue, IsRoutePillaged());7299		}7300#endif7301	}7302}

Calls

Called by