Mod-Modders Guide to Fall Further

Sorry to bring this up again, but I only stopped because I felt like I was wasting your time, and a little hopeless.

Since I had no idea in which file and where to put it, I tried entering Tarquelne's code right after Tsentom1's code in CvEventManager. Not only didn't it work, it also made me incapable of entering landmarks.

Any idea what I have to do in order to make a promotion that makes a unit survive losing combat while staying in the same spot?
 
Thanks for the reply! Although unfortunately, there's still nothing happening when I actually do a game as the Bannor-- turns pass with OO in my city and I get neither the Heresy building or the NotHeresy building. So I've got doTurnBannor defined in CustomFunctions, and the command to doTurnBannor in the CvEventManager.... is there anything else I should need to get this to work?

you can use
CyInterface().addImmediateMessage('Hello', "AS2D_NEW_ERA") to check if your code is used at all.
 
Since I had no idea in which file and where to put it, I tried entering Tarquelne's code right after Tsentom1's code in CvEventManager. Not only didn't it work, it also made me incapable of entering landmarks.

My code would need to go in CvSpellInterface.py. And to use it you'd need the promotion have the tag "PythonPostostCombatLost". It'd be

Code:
<PythonPostCombatLost>onCombatLostSurvival(pCaster)</PythonPostCombatLost>

And remember I couldn't quite get my code to work quite right either. It'd need further fiddling.

If you use my code don't use Tsentom1's, and visa versa. His runs a check after every combat, mine - using a new feature of FF/FfH2 - would run only when a unit with the promotion lost a combat. Theoretically the new way is better. OTOH, the way that actually works is best...

If you use Tsentom1's code put it before the LOG_COMBAT line in CvEventManager's OnCombatResult section, and turn to "1" USE_COMBAT_RESULT_CALLBACK in "PythonCallbackDefines.xml" - the file is in the XML directory.
 
I have 4 promotions tied together. Basically, they "grow" in this order: NoFood -> Food1 -> Food2 -> Food3. They are gained on combat victory (in Orbis, the PythonPostCombatWon tag isn't available so I had to use onCombatResult), replacing the previous level. I would like them to have a chance to wear off each turn and then degrade to the previous level. I know how to do that and I did it. However, when a level replace the previous through combat (say, a unit with Food1 gains Food2), the degrade is triggered, resulting in a case where the unit has both Food1 and Food2 or similar. I would like to keep the degrading thing but I would like it not to be triggered when I replace one promotion with another... Here is the actual python:
Code:
# ngomele start
		pPlayer = gc.getPlayer(pWinner.getOwner())
		pNoFood = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_EMPTY')
		p1Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_1')
		p2Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_2')
		p3Food = gc.getInfoTypeForString('PROMOTION_FOOD_CARRY_3')
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_NGOMELE'):
			if pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GNOLL')):
				iChance = CyGame().getSorenRandNum(100, "Hunting")
				if pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GREAT_HUNTER')):
					iChance += 30
				if pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HUNTING_TOOLS')):
					iChance += 30
				CvUtil.pyPrint('Chance is %d'
					%(iChance))
				if iChance > 90:
					if pWinner.isHasPromotion(p2Food):
						pWinner.setHasPromotion(p2Food, false)
						pWinner.setHasPromotion(p3Food, true)
					if pWinner.isHasPromotion(p1Food):
						pWinner.setHasPromotion(p1Food, false)
						pWinner.setHasPromotion(p2Food, true)
					if pWinner.isHasPromotion(pNoFood):
						pWinner.setHasPromotion(pNoFood, false)
						pWinner.setHasPromotion(p1Food, true)
## ngomele end
 
(You're using the "PromotionDegradesTo" tag in promotioninfos?)

Have you tried having the python clear off the degraded-to promotion?

Spoiler :

Code:
    if pWinner.isHasPromotion(p2Food):
        pWinner.setHasPromotion(p2Food, false)
        pWinner.setHasPromotion(p3Food, true)
        pWinner.setHasPromotion(p1Food, false)

If not many units are going to be using the promotions you might try using pyperturn rather than "degrades".
That way there'd be no automatic creation of the lower promotion when a higher one is gained in combat.
 
Since you are using python, you can use the new tag I created for exactly this purpose.

pWinner.safeRemovePromotion(p2Food)
pWinner.setHasPromotion(p3Food, true)


safeRemove disables degrade and any other "Automatically done on removal" actions.
 
My code would need to go in CvSpellInterface.py. And to use it you'd need the promotion have the tag "PythonPostostCombatLost". It'd be

Code:
<PythonPostCombatLost>onCombatLostSurvival(pCaster)</PythonPostCombatLost>

And remember I couldn't quite get my code to work quite right either. It'd need further fiddling.

If you use my code don't use Tsentom1's, and visa versa. His runs a check after every combat, mine - using a new feature of FF/FfH2 - would run only when a unit with the promotion lost a combat. Theoretically the new way is better. OTOH, the way that actually works is best...

If you use Tsentom1's code put it before the LOG_COMBAT line in CvEventManager's OnCombatResult section, and turn to "1" USE_COMBAT_RESULT_CALLBACK in "PythonCallbackDefines.xml" - the file is in the XML directory.
Thanks to both you and Xienwolf for helping me. I'm going to slam my head into the wall for the mistake I made: I copied
Spoiler :
Code:
## Survival Start ##

		pPlayer = gc.getPlayer(pLoser.getOwner())

		if pLoser.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SURVIVAL')):

			self.iResistance = self.getRandomNumber( 9 )

			if self.iResistance == 0:

				iUnit = pLoser.getUnitType()
				pClearPlot = self.findClearPlot(pLoser)
				pPlot = pLoser.plot()

				newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
				pLoser.setDamage(90, False)
				newUnit.convert(pLoser)
				pLoser.setDamage(100, False)
				newUnit.finishMoves()

## Survival End ##
from his modcomp, and thinking that was all I didn't copy:
Spoiler :
Code:
### Survival Start ###

	def getRandomNumber(self, int):
		return CyGame().getSorenRandNum(int, "Gods")

	def findClearPlot(self, pUnit):
		BestPlot = -1
		iBestPlot = 0
		pOldPlot = pUnit.plot()
		iX = pOldPlot.getX()
		iY = pOldPlot.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				iCurrentPlot = 0
				pPlot = CyMap().plot(iiX,iiY)
				if pPlot.getNumUnits() == 0:
					iCurrentPlot = iCurrentPlot + 5
				if iCurrentPlot >= 1:
					iCurrentPlot = iCurrentPlot + CyGame().getSorenRandNum(5, "findClearPlot")
					if iCurrentPlot >= iBestPlot:
						BestPlot = pPlot
						iBestPlot = iCurrentPlot
		return BestPlot

### Survival End ###

So it works now, though I would like some advice regarding what I have to change in order to make the promotion copy the existing unit instead of making a new one (I was testing with adventurers so there was a new popup and the unit got a new name each time it died).
 
Thanks to both of you, I'll try that. I don't if your new function is in Orbis, xienwolf. It would be nice :)
 
Thanks to both you and Xienwolf for helping me. I'm going to slam my head into the wall for the mistake I made: I copied


So it works now, though I would like some advice regarding what I have to change in order to make the promotion copy the existing unit instead of making a new one (I was testing with adventurers so there was a new popup and the unit got a new name each time it died).

Don't know that it's possible to manipulate units like that without making a new one... I'd look at how the immortality code is handled, but I'm pretty sure that newunit.convert(pCaster) is about the only way to do that.
 
You have to create a new unit and copy the existing one in order to change a unit to something else unfortunately. Mildly odd with Great People since from python you can't block the generation of the GPPopup, but otherwise works just as well
 
Seems like you're heading in that scary place after all, Valkrionn :p
 
Aye, just make sure that the order you list the gameoption in XML matches the order in CvEnums.h (the CyEnumsInterface order doesn't actually matter, but it is nice to keep that matching as well).


Also, special to Fall Further: Make absolutely certain that you list your option BEFORE Civ Select. I have it set up so that nothing listed after that option is ever allowed to be active so we can avoid the annoying "Oops, I ran another mod and now invisible options are active in Fall Further!" bugs.
 
Back
Top Bottom