Thalassicus
Bytes and Nibblers
How can we check if a resource is near a city?
-- Nearby Resources
local pCapital = pPlayer:GetCapitalCity();
if (pCapital ~= nil) then
local strResourceText = "";
local iNumResourcesFound = 0;
local thisX = pCapital:GetX();
local thisY = pCapital:GetY();
local iRange = 5;
local iCloseRange = 2;
for iDX = -iRange, iRange, 1 do
for iDY = -iRange, iRange, 1 do
local pTargetPlot = Map.GetPlotXY(thisX, thisY, iDX, iDY);
if pTargetPlot ~= nil then
local iOwner = pTargetPlot:GetOwner();
if (iOwner == iPlayer or iOwner == -1) then
local plotX = pTargetPlot:GetX();
local plotY = pTargetPlot:GetY();
local plotDistance = Map.PlotDistance(thisX, thisY, plotX, plotY);
if (plotDistance <= iRange and (plotDistance <= iCloseRange or iOwner == iPlayer)) then
local iResourceType = pTargetPlot:GetResourceType(Game.GetActiveTeam());
if (iResourceType ~= -1) then
if (Game.GetResourceUsageType(iResourceType) ~= ResourceUsageTypes.RESOURCEUSAGE_BONUS) then
-- Add spacing if we already have found an entry
if (iNumResourcesFound > 0) then
strResourceText = strResourceText .. ", ";
end
local pResource = GameInfo.Resources[iResourceType];
strResourceText = strResourceText .. pResource.IconString .. " [COLOR_POSITIVE_TEXT]" .. Locale.ConvertTextKey(pResource.Description) .. " (" .. pTargetPlot:GetNumResource() .. ") [ENDCOLOR]";
iNumResourcesFound = iNumResourcesFound + 1;
end
end
end
end
end
end
end
Controls.ResourcesInfo:SetText(strResourceText);
Controls.ResourcesLabel:SetHide(false);
Controls.ResourcesInfo:SetHide(false);
local strResourceTextTT = Locale.ConvertTextKey("TXT_KEY_CITY_STATE_RESOURCES_TT");
Controls.ResourcesInfo:SetToolTipString(strResourceTextTT);
Controls.ResourcesLabel:SetToolTipString(strResourceTextTT);
else
Controls.ResourcesLabel:SetHide(true);
Controls.ResourcesInfo:SetHide(true);
end
I'm not sure if this is determined by the plot ID, city ID, order cities were founded, XY coordinates, etc.
I don't see IsHasResourceLocal in the game's Lua files or the API, what are its parameters?
I'm also fairly sure that multiple cities can use the feature/resource for the purposes of building circus or observatory (for example), provided they are within workable range (ie. near), or "next to" depending on the buildings requirements.