Python Questions

MaxAstro

Spiral Knight
Joined
Dec 18, 2007
Messages
645
How would one make a Python check for a spell such that the spell can only be cast if the caster has at least 1 move point left? Also, how would you make casting a spell cost the unit a move point?

Secondly, how do you change a unit's religion through Python? Specifically, I want a spell that converts every unit of a given unitclass in the same tile as the caster to a given religion. What would be the best way to do this?
 
This should work:
Code:
def reqSpell(caster):	
	if caster.movesLeft() < 1:
		return False
	return true

def spell(caster):
	caster.setMoves(caster.getMoves()-1)

Unfortunately I don't think that there is currently a way to change religion in python, so you would probably have to make SDK changes (which is beyond my current skill level). You can detect a units religion in python.

Edit: I just checked the SDK, and even though I don't think that void CvUnit::setReligion(int iReligion) is actually used, it is defined.

The spell would work like this:
Code:
def reqEvangelize(caster):
	pPlot = caster.plot()
	iReligion= caster.getReligion()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getTeam() != caster.getTeam() and pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_RECON')):
			if pUnit.getReligion() == iReligion:
				return true
	return false
	
	
def spellEvangelize(caster):
	pPlot = caster.plot()
	iReligion= caster.getReligion()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getTeam() != caster.getTeam() and pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_RECON')):
			pUnit.setReligion(iReligion)
 
Awesome! That is ~exactly~ what I am looking for. One thing, though. Shouldn't "if pUnit.getReligion() == iReligion:" in the req function be an "if not" statement, since you want to check that the unit type ~isn't~ that religion?

...Also, how did you guess that I wanted to target recon units? :p I suppose you guessed that I am creating a spell that converts units to the Council of Esus religion?
 
Well, yeah, but only if you want the spell to work only under reasonable conditions. :p

The way I wrote it you could cast the spell if the first unit (which might very well be the caster himself) has the caster's religion.


Just a lucky guess I guess. I slightly suspected that it might be CoE, I wasn't not sure why a the spell would be limited to any unitcombat, but I figured for CoE it might make sense. At first I wrote disciple, but most of those would already have a religion, and it would be weird to change the religion of a priest. I wonder, could that allow you to keep high priest when you convert, if the unit converts first?


I actually think I may add a spell like this for the Luonnotar in my modmod, but it would remove the religions from nearby units (I already gave them a replacement for the Inquisition spell that ignores state religion, so they can remove even state religions from rival cities). I may also bring back the Evangelist promotion and make it randomly have a chance of converting nearby units to its religion using the pyPerTurn tag, which works just like a spell but autocasts every turn.
 
Yep, I am adding Esus priests in my personal mod. Well, sort of. They don't work at all like normal priests, and the only divine magic they have is Shadow 2 (Word of Esus, converts Recon units in the tile to CoE) and, when you upgrade them, Shadow 3 (Enveloping Darkness, grants HN to all units in the tile). Both spells will require gold to cast.

The main point of these "priests" is to allow gaining CoE without having to found it to not be such an incredible bother. The low level priest unit, the Council Advocate, can spread CoE (like a disciple), without requiring you to worship CoE, and if it gains enough XP it can upgrade into the higher level priest, the Scion of Esus (Only for Esus worshippers).

However, the Council Advocate can't be trained like a normal unit. Instead, it can be hired at the CoE holy city, by any unit not at war with the holy city's owner. This leaves the founder in relative control of the religion (and gives them free access to Esus priests), while allowing anyone else who can successfully locate and make a pilgramige to the Esus holy city to aquire the religion without having to wait for natural spread/the will of the founder.
 
Yep, I am adding Esus priests in my personal mod. Well, sort of. They don't work at all like normal priests, and the only divine magic they have is Shadow 2 (Word of Esus, converts Recon units in the tile to CoE) and, when you upgrade them, Shadow 3 (Enveloping Darkness, grants HN to all units in the tile). Both spells will require gold to cast.

The main point of these "priests" is to allow gaining CoE without having to found it to not be such an incredible bother. The low level priest unit, the Council Advocate, can spread CoE (like a disciple), without requiring you to worship CoE, and if it gains enough XP it can upgrade into the higher level priest, the Scion of Esus (Only for Esus worshippers).

However, the Council Advocate can't be trained like a normal unit. Instead, it can be hired at the CoE holy city, by any unit not at war with the holy city's owner. This leaves the founder in relative control of the religion (and gives them free access to Esus priests), while allowing anyone else who can successfully locate and make a pilgramige to the Esus holy city to aquire the religion without having to wait for natural spread/the will of the founder.

That actually sounds like a very neat Modcomp :) Any chance we could persuade you to release it once finished rather than leaving it purely a personal mod?
 
I'll probably release several of the parts of my personal mod as minimods; specifically the Esus priests and what I've done with Giant Spiders, as well as possibly my city defense changes and the new civ I am working on.

But I don't want to start releasing things until a) I get more of it finished, and b) I finish updating everything for patch k, now that I know that k will be the last .30 patch.
 
Top Bottom