Allowing the AI to produce a unit, only faith purchase for humans

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
As the title says - if I want to make a unit buildable by the AI, but only purchasable for faith by human players, how do I do it in Lua? Events like PlayerCanTrain or CityCanTrain don't seem to offer any way to distinguish between producing the unit and purchasing it for faith.
 
Two very similar units, one only the AI players can train and one only the human player can faith purchase

If you want/need the two units to be identical, detect the training (via the new city event) of the AI only one and switch it with the faith purchase one
 
@Craig_Sutter: I don't get what you mean, can you explain it further?

@whoward69: Using two units is a somewhat complicated solution, currently I'm thinking about a modification to the interface file(s), so these units don't appear on the production selection list. But I'm not sure if there is only one way to set production in a city, or there are multiple ways that use different "screens", so I would need to modify them all.
 
Assuming you can discount EUI, or any other mod that changes the UI, all human city production occurs via the ProductionPopup.lua/xml UI context pair.

Certainly if you can mod that (and I'd forgotten this was a TC related question) it would be a darn sight easier than two units!

In ProductionPopup.lua, look for the UpdateWindow function. A long way into that (it's around line 394 in my file - but I tend to edit them, so it may be higher or lower in yours) is the main unit loop

Code:
 	for unit in GameInfo.Units() do
 		local unitID = unit.ID;
 		if g_IsProductionMode then
 			-- test w/ visible (ie COULD train if ... )
			if city:CanTrain( unitID, 0, 1 ) [B][COLOR="Red"]and IsNotFaithPurchaseOnly(unitID)[/COLOR][/B] then
				local isDisabled = false;

you'll need to write the IsNotFaithPurchaseOnly() function dependant on what you only want purchased with faith

W
 
Thanks, that's what I'm doing right now, I found this place in the file myself and it's easy to change indeed - if I had this idea earlier, I wouldn't start this thread :) I added a column to the Units table in the database that controls which units shouldn't be human buildable, so my code checks for this column instead of using a function.

I don't think my mod is EUI-compatible, as I already changed a lot of interface files. But at a later stage of development (after the first release) I'm going to implement some nice features from EUI and other UI mods.
 
Top Bottom