[SDK] Trade routes factor building created resources.

mjjepper

Chieftain
Joined
Jan 16, 2012
Messages
29
For the mod I am making I require gold from trade routes to increase as new luxuries and resources are generated by buildings (much like recycling centers give aluminium, yet the aluminum originally didn't factor into trade route calculations). Replacing the following function with this bit-O-code should do the trick.

Code:
/// Does this City have eResource nearby?
bool CvCity::IsHasResourceLocal(ResourceTypes eResource, bool bTestVisible) const
{
	VALIDATE_OBJECT
	CvAssertMsg(eResource > -1 && eResource < GC.getNumResourceInfos(), "Invalid resource index.");
	// See if we have the resource linked to this city, but not connected yet
	bool bFoundResourceLinked = false;

	//MJJEPPER MOD. Check if a building is producing that resource.
	for(int iBuildingLoop = 0; iBuildingLoop < GC.getNumBuildingInfos(); iBuildingLoop++)
	{
		const BuildingTypes eBuilding = static_cast<BuildingTypes>(iBuildingLoop);
		CvBuildingEntry* pkBuildingInfo = GC.getBuildingInfo(eBuilding);
		if(pkBuildingInfo)
		{
			// Do we have this building?
			if(GetCityBuildings()->GetNumBuilding(eBuilding) > 0)
			{
				int iNumResource = pkBuildingInfo->GetResourceQuantity(eResource);
				if(iNumResource != 0)
				{
					bFoundResourceLinked = true;
					return bFoundResourceLinked;
				}
			}
		}
	}
	// Actually check to see if we have this Resource to use right now
	if(!bTestVisible)
	{
		return m_paiNumResourcesLocal[eResource] > 0;
	}
	




	// Loop through all plots near this City to see if we can find eResource - tests are ordered to optimize performance
	CvPlot* pLoopPlot;
	for(int iCityPlotLoop = 0; iCityPlotLoop < NUM_CITY_PLOTS; iCityPlotLoop++)
	{
		pLoopPlot = plotCity(getX(), getY(), iCityPlotLoop);

		// Invalid plot
		if(pLoopPlot == NULL)
			continue;

		// Doesn't have the resource (ignore team first to save time)
		if(pLoopPlot->getResourceType() != eResource)
			continue;

		// Not owned by this player
		if(pLoopPlot->getOwner() != getOwner())
			continue;

		// Team can't see the resource here
		if(pLoopPlot->getResourceType(getTeam()) != eResource)
			continue;

		// Resource not linked to this city
		if(pLoopPlot->GetResourceLinkedCity() != this)
			continue;

		bFoundResourceLinked = true;
		break;
	}

	return bFoundResourceLinked;
}

//	--------------------------------------------------------------------------------
 
Top Bottom