Linking rituals to improvements/unit training?

LightofAbraxas

Chieftain
Joined
Sep 9, 2011
Messages
30
I'm trying to do a couple of things in Python, I want to require a certain ritual to be completed before:

1) The training of extra Priests of Winter becomes possible.

2) Priests can build Ice Nodes on raw mana. I've gotten all of the unit and improvement xml taken care of for this one already.

But, I can't seem to find any examples of a unit or improvement order being enabled by a project in either the xml or python code. Nearest I'm able to figure, it could be done by creating a hidden tech that's awarded by the ritual, but that just doesn't seem very elegant.

Does anyone have any experience with trying to do something like this? Thanks in advance!
 
No love for the Illians out there I guess? I don't know about coding, but doesn't the Draw allow the Ascension ritual? That should at least get you an example for allowing unit builds.
 
Ah, yeah, I looked at that. The Ascension seems to create Auric directly, rather than allow you to build him in one of your cities.

I did manage to find code that allows for the building of Ice nodes after ritual completion (Advanced Ice Nodes modcomp on this subforum), but I'm still looking around for the code that would enable the building of a unit.

Anyway, thanks!
 
Before I added the White Hand religion, Priests worked the way you suggest in my modmod.

I don't remember exactly what versions worked that way and I don't feel like turning on my external hard drive to search by backups of all the old versions, but it is easy enough to reproduce.

Just add this under def cannotTrain(self,argsList): in CvGameUtils.py:
Code:
		if eUnit == gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'):
			if gc.getGame().getProjectCreatedCount(gc.getInfoTypeForString('PROJECT_THE_WHITE_HAND')) < 1:
				return True

You could limit the construction of Ice nodes by adding this to def canBuild(self,argsList): in the same file.
Code:
		if iBuild == gc.getInfoTypeForString('BUILD_MANA_ICE'):
			if gc.getGame().getProjectCreatedCount(gc.getInfoTypeForString('PROJECT_THE_WHITE_HAND')) < 1:
				return 0

Of course, you would have to add the Build order for the improvement in CIV4BuildInfos.xml, and give both it and a positive <iWorkRate>and to the appropriate units.

Note that the comment at the bottom of def canBuild(self,argsList):
# Returning -1 means ignore; 0 means Build cannot be performed; 1 or greater means it can

It is possible for this python callback to allow the construction of improvements where it would normally be impossible. In the most recent version of my modmod, I use it to allow those running the Arete civic to build Mines and Quarries on Peaks, where otherwise no improvement can ever be built.

The thought just came to mind that you could use this to allow Priests of Winter to build Ice Nodes on top of any mana resource, without needing to have a mage with Metamagic II to revert it to Raw Mana first, even on mana resources in rival territory.

(The code does not actually allow any way to check which unit is trying to build the improvement, which is rather annoying as it prevents me from using the code in some of the ways I'd really like. It does however allow you to find the coordinates of the tile which player is trying to build there. From the coordinates you can find the plot, the owner of the plot, and the resources/features/bonuses/units on the plot. You can easily allow something to be built on by a specific civilization. You can make multiple build types for the same improvement if you want to give them to different units types and give those units different limitations on where they can build the improvement.)
 
Oh, hey, thanks again for your help!

I actually have been thinking of severely restricting the Illians' access to mana, possibly limiting them to one sphere of each type. My only concern is that if node conversion is done strictly through the PoW/HPow units, does custom python code need to be written so that the AI will do this specific type of terraforming?

I mean, I saw that Tholal has added some code to help the AI with adept-class units in one of the files, and I didn't know if that was necessary to port to disciple-class units or if it just helped the AI decide roles for their mages.

Anyway, thanks again, I really appreciate it.
 
My only concern is that if node conversion is done strictly through the PoW/HPow units, does custom python code need to be written so that the AI will do this specific type of terraforming?

Currently, the only way to get an AI unit to build mana nodes is to assign them as UNITAI_MANA_UPGRADE (you can see this being done in onUnitBuilt in python)

I hope to one day make this more versatile, but that's a difficult project. If you do assign the above AI, they should be able to successfully find mana nodes and build on them without any help. Give it a try and let me know what happens.
 
Ok, I'll give that a try and let you know.

Would putting that AI under the UnitAIs tag in the UnitInfos file be adequate? Or would it be better to assign it directly, either under the defaultAI or through python when they're created?

Thanks!
 
Thanks. Rather than set the PoWs' default AI to MANA_UPGRADE (since I have no idea what they'd be doing if there weren't any free nodes), I left it at HERO and adapted the following from your mod:

Code:
			numIceTerraformer=0
			if unit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'):
				neededIceTerraformer = 1
				if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
					neededIceTerraformer = neededIceTerraformer + (pPlayer.getNumCities() / 5)
				for pUnit in player.getUnitList():
					if pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER'):
						if pUnit.getUnitAIType() == gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'):
							numIceTerraformer = numIceTerraformer+1
				if numIceTerraformer < neededIceTerraformer:
					unit.setUnitAIType(gc.getInfoTypeForString('UNITAI_MANA_UPGRADE'))

I'm going to try to figure out how to only have the code run once The Deepening is completed (since they can't be built until then) and run a test game. I'll let you know how it goes.
 
Back
Top Bottom