• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Changing ownership of city

myristate

Chieftain
Joined
Dec 18, 2011
Messages
5
Would it be possible to change the ownership of a city through the live tuner tool. By default it does not appear you can do it. Is it even possible to create a panel/control that could do that? If anyone has an idea of how it could be done i would be most appreciative to know how :)

Moderator Action: Moved to the main forum.
Because the tutorials subforum is only for tutorials, not for questions ;).
 
There's no button for this in the tuner, but you can do it by hand by giving a Lua command while the tuner is in InGame mode. Specifically, you'd use the Player:AcquireCity function, although the arguments are a bit of a pain since it wants the pCity structure instead of the city's ID number.
 
Thanks for finding the time to reply. Apologies for i guess noobish questions.

I looked Player:AcquireCity up and am i correct in saying it has three arguments.

pCity
bConquest
bTrade

If so what do the arguments mean and how do you pass them
 
What it means is that you'd need a routine like this:
Code:
function ChangeCityOwner(oldOwner, cityID, newOwner)
  local pPlayer = Players[newOwner];
  local pCity = Players[oldOwner]:GetCityByID(cityID);
  pPlayer:AcquireCity(pCity, true, false);
end

where the "true" and "false" are the two booleans. Then, you call this from within whatever routine you've set up.

The booleans are bConquest (the second argument) is a true/false depending on whether the city was gained through conquest, and bTrade (the third argument) is another true/false depending on whether the city changed hands because of a trade deal, such as a peace treaty. The game needs those two flags to know whether it needs to put the city into resistance, whether its population should get reduced, and so on. So depending on exactly how you want the city to be treated, set those flags to either true or false as necessary.

Now, what I have up there could be boiled down to a single Lua command, like
Code:
Players[newOwner]:AcquireCity(Players[oldOwner]:GetCityByID(cityID), true, false);
and passed directly to FireTuner as a executable command. Of course, you'll need the three ID numbers first.
 
So i finished off making the city changer for Live tuner. I dont know if its of any value to anyone. However i will share what i did. I would also appreciate any feedback especially from people more knowledgeable in it. Because I am aware that even though code can work it does not always mean it is good code and that it could cause bad things to happen. Anyway let me know i am still learning this stuff

look.png


Thats how it looks on the Live Tuner, You simply select the city you wish to acquire in the window on the left and then in the list on the right select what civilization you want it to belong too. Then select the appropriate button at the bottom

Code for the Edit Box is as follows:

Populate List
Code:
function()
	local listItems = {};
	local i = 0;
	local z = 1;
	for i = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
		
             local pPlayer = Players[i];
             if pPlayer:IsEverAlive()  then
				
	          local strPlayer = pPlayer:GetCivilizationShortDescription();				
	          local strrPlayer = pPlayer:GetID();
		  local str = strrPlayer .. ";" .. strPlayer;			

                  listItems[z] = str;
	          z = z + 1;			

	      end
	end

  return listItems;
end

On Selection
Code:
function(selection)
	local selectionParts = {};
	-- No split available?
	local str1 = string.match(selection, "%d+");

	g_TunerSelectedCityPlayerNewID = tonumber(str1);

end

Code For "Acquire City Via Trade" Button At Bottom
Code:
	local pCity = nil;
	local pPlayer = Players[g_TunerSelectedCityPlayerID];
	

 if pPlayer ~= nil then
		pCity = pPlayer:GetCityByID(g_TunerSelectedCityID);
	end		
	

if pCity == nil then
		pCity = UI:GetHeadSelectedCity();
end


if pCity ~= nil then


Players[g_TunerSelectedCityPlayerNewID]:AcquireCity(Players[g_TunerSelectedCityPlayerID]:GetCityByID(g_TunerSelectedCityID), false, true);
end
 
Seriously? I'd just delete and re-create the city thank you very much.
 
Hate to bring up an old thread, but I'm trying to transfer ownership of some cities from one city state civilization to another...

Below is my attempt at code... but it is not working. Am I missing something simple or misapplying the AcquireCity function?

As per usual, I state the disclaimer that I am not proficient at lua. I have done many searches of scenarios and on-line, but I cannot seem to find a simplified version of the function in use. RED WWII uses it, but it is wrapped around with so many functions that I have difficulty pulling out the useful (to me) bits. My coding is not so elegant.

Spoiler :

Code:
function ChangetoFrankOwner()
	if Game.GetGameTurn() == 2 then

	local newOwner
	local pFranks
	local oldOwner
	local pSyagrius
	local pCity

		-- Set up Franks (newOwner)

		for newOwner=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 
		local pFranks = Players[newOwner];

   			if (GameInfo.MinorCivilizations.MINOR_CIV_FRANKS == pFranks:GetMinorCivType()) then
			
			-- Set up Syagrius (oldOwner)

				for oldOwner=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do
				local pSyagrius = Players[oldOwner];
					if (GameInfo.MinorCivilizations.MINOR_CIV_SYAGRIUS == pSyagrius:GetMinorCivType()) then
					
						if pSyagrius:IsAlive() then 
			
			-- Enumerate cities

							for cityIndex = 0, pSyagrius:GetNumCities() - 1, 1 do
    						local pCity = pSyagrius:GetCityByID(cityIndex)

				-- City exists?
    							if pCity ~= nil then 

				-- Give City to Franks
								pFranks:AcquireCity(pCity, false, true)
												
    							end
							end
						end
					end
				end
			end
		end
	end
end

Events.ActivePlayerTurnEnd.Add(ChangetoFrankOwner)


Thank-you for any pointers.
 
Here it is:

Code:
function ChangetoFrankOwner()
	if Game.GetGameTurn() == 0 then
		
	local Franks
	local Syagrius
	local pCity

for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do  

local pFranks = Players[iPlayer]

	if (GameInfo.MinorCivilizations.MINOR_CIV_FRANKS.ID == pFranks:GetMinorCivType()) then
	
	Franks = pFranks
	print(Franks:GetName())
	end	
end


for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pSyagrius = Players[iPlayer]

	if (GameInfo.MinorCivilizations.MINOR_CIV_SYAGRIUS.ID == pSyagrius:GetMinorCivType()) then
	
	Syagrius = pSyagrius	
	print(Syagrius:GetName())

	end
end

 if (Syagrius:IsAlive()) then

	for cityIndex = 0, Syagrius:GetNumCities() - 1, 1 do
    			local pCity = Syagrius:GetCityByID(cityIndex)
				print(pCity:GetName())
				-- City exists and has the proper name?
    			if pCity ~= nil then
				Franks:AcquireCity(pCity, true, false)

end
end
end

	
	end
end

Events.ActivePlayerTurnEnd.Add(ChangetoFrankOwner)
 
Back
Top Bottom