Problem getting the ID of a city

ArbogLi

Chieftain
Joined
Apr 25, 2010
Messages
64
Hi everybody, I have a little problem and I need help to solve it because I really tryed but I missed.

I'm working on my random events mod and looking for bugs I found one: when a city expand the territory getting a free tile this is assigned to the player, nor to the city, and it doesn't change when the city is conquered.

The code is the next:

Code:
function addPlot(pCurrentPlayer)
	--player should be alive and own cities
	if (pCurrentPlayer ~= nil and pCurrentPlayer:IsAlive() and pCurrentPlayer:GetNumCities() > 0) then
		local CityNum = Map.Rand(pCurrentPlayer:GetNumCities(), "Random city - Lua");
		local City = GetCityByNum(pCurrentPlayer, CityNum);
		local plot = City:GetNextBuyablePlot();
		
		plot:SetOwner(City:GetOwner());

		if (pCurrentPlayer:IsHuman() == true) then
			LuaEvents.CustomNotification(City:GetX(), City:GetY(), "Citizens from " .. City:GetName() .. " have been wonking a tile near to their city and they claimed it for their empire", "Expansion");
		end
	end
end -- addPlot


function GetCityByNum(player, N)
	local n = 0;
	for city in player:Cities() do
		if (n == N) then
			return city;
		end
		n = n + 1;
	end
end

This is the original code, but looking for the bug I found what I said: plot:SetOwner(City:GetOwner()); The I tried to fix it giving the plot ownership to the city instead of the player and it works, replacing this line by:

Code:
plot:SetOwner(City:GetID());

The problem is that the ID is always the same (in this case the human player first city's ID), but it should be the ID of the other player cities. It tryed to find if the choosen city was wrong but asking for the name instead of the ID it is ok, gives me the correct city name but the ID don't change.

Any ideas? I don't know what the hell I must do to change the ID (and belive me, I tryed :( )
 
you should double check that you are passing the correct player to the getcity function

plot:SetOwner() has a different way also on how to use it

about for the ids being the same, i've seen that too. first one 8192 (same id as the unitid of the settler) then the second always seems to be 16385 (same id as your first warrior).. think the 3rd is the same too never looked into it that far though. must be some pattern to it i suppose.
 
I would assume that the IDs are memory offsets within the individual Player's data structures which is why plot:SetOwner() has parameters for both the Player id and the city id.
 
you cannot just set the owner in the method "plot:SetOwner"
you should refer to a PlayerType, not the playerID, you must specify iAcquiringCityID and two booleans too

usage is :
void plot:setOwner(PlayerTypes eNewValue, int iAcquiringCityID, boolean bCheckUnits = true, boolean bUpdateResources = true);

source


it should be:
plot:SetOwner(pCurrentPlayer, CityNum, true, true);
or
plot:SetOwner(pCurrentPlayer, CityNum);

i cannot verify my code now, good luck
 
plot:SetOwner(City:GetID());
is wrong,
it should be
plot:SetOwner(City:GetOwner(), City:GetID());
 
Top Bottom