How do I determine plot location?

Evalis

Prince
Joined
Mar 2, 2009
Messages
505
So lets say I want to obtain the plot value for a city. What would the command be to obtain this information. Secondly, at what locations are the plots surrounding that city? In civ 4 it would be -1,-1 -1,0 and so on. But with hexes.. I'm a bit lost on how that would work.

Anyone have the answer?
 
One way do to this is:
Code:
local _Result = {}
local _Player = Players[Game.GetActivePlayer()]
for _City in _Player:Cities() do
	local _cityId = _City:GetID()
	_Result[_cityId] = {}
	for i = 0, _City:GetNumCityPlots() - 1, 1 do
		local _Plot = _City:GetCityIndexPlot( i );
		table.insert(_Result[_cityId], _Plot)
	end
end
Then you can get all plot information through that _Result table.

You can find more example code about this from the original CityView.lua. Specifically from the UpdateWorkingHexes() function.
..\Sid Meier's Civilization V\assets\UI\InGame\CityView\CityView.lua
 
I guess what he wants is to rank possible locations for cities, so the city does not exist yet.

"Value", of course, must be defined. You can either devise your own definition and algorithm, or look at the map generation helpers scripts in Assets/Gameplay/Lua since they probably contain something like that.

Now, to work with hexes, you need to use Map.plotDirection(x, y, DirectionTypes.DIRECTION_NORTHEAST). You can also directly use Map.GetPlot(x, y), here are how the "X" are laid out:
Code:
0 1 2 3 4 5     (even y)
 0 1 2 3 4 5    (odd y)
0 1 2 3 4 5     (even y)
 0 1 2 3 4 5    (odd y)

However be careful if you prefer Map.PlotXYWithRangeCheck(x, y, dx, dy, range), because this function rely on GetPlotXY(x, y, dx, dy) and this one does something strange (if you use dx = 0 and dy = 2, from plot (5, 5), it will return (6, 7): every two rows it goes one tile left or right, depending on whether dy is positive or negative). Now you may probably use it if you are careful (for a range of 3 you probably need dx going from -5 to +5, dy from -3 to +3).
 
Onni has the right of it. I want the city location after it has been built, and then I want to check around that city within 2 hexes. The program that whoward suggested seems like it can do that, but it's difficult to grasp what is happening in that module (I will ask my relevant question there though)

However, and I may be wrong on this, because I have pretty much no clue what I'm doing, but the code that Onni wrote seems to be checking every single tile within the city radius. Meaning it would only gather tiles that have actually been claimed as well as tiles that extend beyond a specific radius (2 in this case). Do I have that right?

On that note, How do you get the game to return the specific plot the city is on. Is it with :GetCityPlot ?
 
Indeed, the solution suggested by Whoward does exactly what you need. And you're right about the one from Onni: it would only enumerate the tiles claimed by the city.

The solution from Whoward uses the functions I described earlier. It may be hard to understand because, as he wrote "enumerators are easy to use but hard to write". I suggest you try to understand how pairs and ipairs work first:
Code:
function pairs(enumeratedTable)
   return next, enumeratedTable, nil
end
Where "next" is a builtin LUA function with the next(t, key) signature. It takes a table and a key and returns the next key and value in that table. So when you write a "for + pairs" loop, it calls "pairs" once. This one returns a function (the iterator), the table, and the first key (nil). Then the iterator is successively called. Here are the performed invocations:
Code:
pairs(t) => next, t, nil
next(t, nil) => key1, value1
next(t, key1) => key2, value2
next(t, key2) => key3, value3

Finally, yes, GetCityPlot is what you think it is
 
Thanks! I didn't understand any of that, but thanks ^^;

For future readers, the GetCityPlot function no longer appears to work. :Plot is the method of determining the x y value. Also resources can be placed with:

:SetResourceType("ID of Resource in xml", "Number of resources assigned to plot")
An example of placing aluminum with 3 units would be:

pPlot:SetResourceType(5,3)

If someone could update the wiki that would be fantastic. Sadly I do not have access =/
 
Back
Top Bottom