Is it possible to forbid units to found city?

Prairial

Chieftain
Joined
May 2, 2014
Messages
25
Location
China
I want to make players can found city only after they reach certain technologies or unlock certain policies, so forbidding the settlers to found city is necessity. But it seems there is no suitable funcion in GameEvents. Can anyone help me? Thanks.
 
I suppose it would be theoretically possible to create a unit that has all the attributes of the Settler except for the ability to found cities, then use lua to detect when a settler is built, at which point the real settler is secretly switched out for your non-settling settler.

Then a separate code could detect when a specific policy is unlocked (GameEvents.PlayerAdoptPolicy) or a specific tech is researched (GameEvents.TeamTechResearched), at which point all the non-settling settlers are switched out for real settlers.

I'm not sure if there's an easier way other than directly editing the coding for the settler's Found City mission, and I don't what file that's in. :/
 
I suppose it would be theoretically possible to create a unit that has all the attributes of the Settler except for the ability to found cities, then use lua to detect when a settler is built, at which point the real settler is secretly switched out for your non-settling settler.

Then a separate code could detect when a specific policy is unlocked (GameEvents.PlayerAdoptPolicy) or a specific tech is researched (GameEvents.TeamTechResearched), at which point all the non-settling settlers are switched out for real settlers.

I'm not sure if there's an easier way other than directly editing the coding for the settler's Found City mission, and I don't what file that's in. :/

Thank you, it is feasible to switch all settlers to non-settling settlers when the player cannot found city.

To forbid human player to found city is quite easy(just hide the "found city" button in UnitPanel.lua) but I haven't find any method to control AI's behavior.
 
I want to make players can found city only after they reach certain technologies or unlock certain policies, so forbidding the settlers to found city is necessity. But it seems there is no suitable funcion in GameEvents. Can anyone help me? Thanks.
Do you mean after they found the capital they cannot found more cities until they have researched Tech_X or have selected Policy_X ?

If so you should be able to do a PlayerCanTrain event to stop the player (human and AI) from building Settlers until they acquire a tech, for example (note that I have not tested this but I think it ought to work). You would need to change TECH_X to the valid XML name of the Tech you want to allow the player to make new cities:
Code:
local iSettler = GameInfoTypes.UNIT_SETTLER
local iTechNeededToSettle = GameInfoTypes.TECH_X
GameEvents.PlayerCanTrain.Add(function(iPlayer, iUnit) 
  if (iUnit == iSettler) then
	local pPlayer = Players[iPlayer]
	if not Teams[pPlayer:GetTeam()]:IsHasTech(iTechNeededToSettle) then
		return false;
	end
  end

  return true
end)
 
Do you mean after they found the capital they cannot found more cities until they have researched Tech_X or have selected Policy_X ?

If so you should be able to do a PlayerCanTrain event to stop the player (human and AI) from building Settlers until they acquire a tech, for example (note that I have not tested this but I think it ought to work). You would need to change TECH_X to the valid XML name of the Tech you want to allow the player to make new cities:
Code:
local iSettler = GameInfoTypes.UNIT_SETTLER
local iTechNeededToSettle = GameInfoTypes.TECH_X
GameEvents.PlayerCanTrain.Add(function(iPlayer, iUnit) 
  if (iUnit == iSettler) then
	local pPlayer = Players[iPlayer]
	if not Teams[pPlayer:GetTeam()]:IsHasTech(iTechNeededToSettle) then
		return false;
	end
  end

  return true
end)

Well, for example, players can found 1 city after TECH_I, found 2 cities after TECH_II, and so on.
 
Right, so just make the training of settlers be shorthand for this; i.e., they can train 1 settler after TECH_I, etc. Or, better yet, just make settlers untrainable but give the player free settlers for researching the techs in question.
 
Back
Top Bottom