Limiting no. of Missionary units not possible?

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,753
Location
Calgary, Canada
Unless I am doing something wrong, it appears that neither this XML:

Code:
<UnitClasses>
		
	<Replace>
			<Type>UNITCLASS_MISSIONARY</Type>
			<Description>TXT_KEY_UNIT_MISSIONARY</Description>
			<DefaultUnit>UNIT_MISSIONARY</DefaultUnit>
			<MaxPlayerInstances>2</MaxPlayerInstances>
	</Replace>		
		
</UnitClasses>

nor this LUA:

Code:
--allows building of Missionary Class units up to two units

local iMissionaryID = GameInfo.Units.UNIT_MISSIONARY.ID
local iIrishMissionaryID = GameInfo.Units.UNIT_IRISH_MISSIONARY.ID
local iMissionaryClassID = GameInfo.UnitClasses.UNITCLASS_MISSIONARY.ID

function MissionaryUnit (iPlayer, iUnit)

	--differentiate Missionary Class units
	if iUnit == iMissionaryID or iUnit == iIrishMissionaryID then

		local pPlayer = Players[iPlayer]
		local iMissionaryClassID = GameInfo.UnitClasses.UNITCLASS_MISSIONARY.ID
		local iValue = pPlayer:GetUnitClassCount(iMissionaryClassID)
		if iValue <= 2 then	
		print(iValue, "is <= 2 missionaries so can build")			
			return true
			
		else
		print(iValue, "is not <= 2 missionaries so cannot build")
			return false
			
		end
	else	
		return true	--default needed for other units
	end
end

GameEvents.PlayerCanTrain.Add (MissionaryUnit)

... can be used to limit the number of Missionary units produced.

For your information or correction as the case may be...
 
It's come up before on these forums, but religious units are only limited by available faith, and not other factors (max units, gameevents, etc)
 
It's come up before on these forums, but religious units are only limited by available faith, and not other factors (max units, gameevents, etc)

Is this rule the same for faith-purchased only buildings as well?
 
If not, one could have such buildings spawn missionaries and make missionaries unpurchaseable... it would be a faux purchase of tge missionaries via a faith purchased building. The building would be removed via lua. Building construction, hopefully, can be limited as one wishes via player or city can construct functions.

A UI wizard may even be able to make it seem as though a unit is being purchased directly while this is all happening under the hood, so to speak.
 
If not, one could have such buildings spawn missionaries and make missionaries unpurchaseable ...
Which will kill the AI - it's logic says "I want to buy a missionary with faith" not "what can I buy with faith, just buy something/anything"
 
But the AI will never buy the building that will spawn the missionary.
 
I was being facetious.

But why wouldn't they? They buy cathedrals/mosques and monasteries. You could add whatever flavours and yields or attributes you wish to entice the purchase (the building will removed upon construction in any case) and create a belief that would be associated with every religion by lua. It would be built... the problem might be it would be too popular, but presumably (and this is the question) the construction could be limited by lua. For example, construction of the missionary spawning building could be restricted by the number of missionaries the player has.

If I granted the ability to spawn missionaries to cathedrals, mosques and monasteries, are you saying the AI would then not build them? You could attach a different spawning building to each pantheon belief to ensure all religions would spawn missionaries, make the missionary -1 faith. And limit it by lua in any number of ways (only founders may build/limited by numbers of the unit class etc. Don't even need to limit it to missionaries... any unit could be essentially a faith purchased unit if handled this way).

The essential question revolves upon whether lua restrictions work on faith based buildings... if they do not, the question is moot.
 
The AI does not use flavours or yields or attributes to decide what to buy with faith. It has a hard-coded precedence list (which another post of mine on these forums outlines)

The AI logic is

if I_Want_to_Buy_A_Missionary() then
Buy_A_Missionary()
end

If you alter the Buy_A_Missionary() bit (by removing the ability to buy missionaries) without altering the corresponding I_Want_to_Buy_A_Missionary() bit (which you can't without a DLL mod), the AI will get stuck in a "I want to buy a missionary, try to buy a missionary, I can't" loop turn after turn after turn. It is a common misconception (mainly with religion, but also some other aspects of the game) that if a mod stops the AI doing X then it will do Y instead - the DLL is (generally) not coded like that. It assumes that if the AI wants to do X then it can do X. A mod that removes the ability to do X will not (generally) cause the AI to do Y instead - the AI will loop every turn, stuck at "I want to do X".

The AI's priority for buying religious buildings differentiates between those from its chosen beliefs and those it can buy from other beliefs - the latter are considerably lower than the former, and the former only kick-in after the AI has all the prophets and missionaries it believes it wants. You stop it buying missionaries, you'll effectively stop it buying everything else (except prophets) with faith. And, IIRC, the AI never buys combat units with faith, as that option has been omitted from the hard-coded precedence list.

So, if you want to achieve these effects, you will have to completely take over the decision making (via Lua) of what to buy with faith for the AI
 
You can't make Buildings purchaseable via faith with a Pantheon Belief. The game ignores Pantheon Beliefs that are listed in the Belief_BuildingClassFaithPurchase table.

You can make Buildings purchasable via Faith with Founder, Follower, Reformation, and Enhancer Beliefs.

You should as a general rule tend to make buildings that are purchasable with Faith in addition to the normal acquisition methods only use Follower and Reformation Beliefs for this 'purchasing' -- ie, when making an additional type of Building work the same way as Universities, etc., work for Jesuit Education. Every time I've tried to make, for example, Temples become purchasable with Faith in addition to the usual methods of getting a Temple, the game tends to start doing random CTD when a religion with such a Belief is spread to a new city if the Belief allowing the purchase of the 'normal' building is not either a Follower or a Reformation Belief. This occurs both for the human player and during the AI turns, and seems to occur both for Missionary spreads and 'natural' religion spreading to a new city.

I don't remember seeing this CTD with new types of Buildings that are set only to be acquired via purchase with Faith, ie, like as if I added a new 'mini-Cathedral' and made a new belief for it to be purchasable (or otherwise acquirable) only if you select this new Founder or Enhancer belief, for example. But to be honest it has been long enough since I experimented with this method of adding a Faith-Buyable building that my memory may be in error and you may run into the same rando CTD issues if the new building is not linked to a Follower or Reformation belief.
 
Thank-you for the explanation of AI priorities whoward.

And thank-you for your explanation about how beliefs and faith based building purchases are related, LeeS.

I am still curious as to whether lua PlayerCanConstruct would work with faith-based religious buildings. If, for example, I did wish to devolve AI decision-making to LUA.
 
Faith purchase of buildings calls both PlayerCanConstruct and CityCanConstruct
 
Top Bottom