adapt a script

CIAO. poi ecco la schermata con la promozione, nel gioco.

potrebbe dipendere dal fatto che la promozione è modulare? o nel caso in cui esista già una funzione phyton su quella chiamata?
questa funzione è in cveventmanager:
def onCombatResult(self, argsList):
"Risultato del combattimento"
pWinner,pLoser = argsList
giocatoreX = PyPlayer(pWinner.getOwner())
unitX = PyInfo.UnitInfo(pWinner.getUnitType())
giocatoreY = PyPlayer(pLoser.getOwner())
unitàY = PyInfo.UnitInfo(pLoser.getUnitType())

## Inizio del raid ##

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

se pWinner.isHasPromotion(gc.getInfoTypeForString('PROMOTION_RAIDER')):

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

iGold = giocatoreY.getGold( )
messaggio = 0

iOro rubato = ( iOro//25 )

se giocatoreY.getGold( ) >= 500:
giocatoreY.changeOro( -20 )
elif giocatoreY.getGold( ) >= 25:
playerY.changeGold( -iGoldStolen )
elif (playerY.getGold( ) >= 1) e (playerY.getGold( ) < 25):
giocatoreY.changeOro( -1 )

iGold2 = giocatoreX.getGold( )
se giocatoreY.getGold( ) >= 500:
playerX.changeGold( +20 )
messaggio = 1
elif giocatoreY.getGold( ) >= 25:
playerX.changeGold( +iGoldRubato )
messaggio = 2
altro:
playerX.changeGold( +1 )
messaggio = 3

pPID = pPlayer.getID()
iX = pWinner.getX()
iY = pWinner.getY()
szNome = pPlayer.getNome()

## Questo controlla solo il testo, tutti gli importi effettivi in oro vengono indicati sopra:
iGoldStolenMax = ( 500//25 )
iGoldStolenMin = ( 25//25 )

se ( messaggio == 1 ):
CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_RAIDER_GOLD1",(szName,iGoldStolenMax)),'',0,',Art/Interface/Buttons/TechTree/Banking.dds,Art/ Interfaccia/Pulsanti/TechTree_Atlas.dds,8,1',ColorTypes(44), iX, iY, True,True)
### messaggio: %s1 ha saccheggiato %d2 [ICON_GOLD]!###
se ( messaggio == 2 ):
CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_RAIDER_GOLD2",(szName,iGoldStolen)),'',0,',Art/Interface/Buttons/TechTree/Banking.dds,Art/ Interfaccia/Pulsanti/TechTree_Atlas.dds,8,1',ColorTypes(44), iX, iY, True,True)
### messaggio: %s1 ha saccheggiato %d2 [ICON_GOLD]!###
se ( messaggio == 3 ):
CyInterface().addMessage(pPID,false,15,CyTranslator().getText("TXT_KEY_RAIDER_GOLD3",(szName,iGoldStolenMin)),'',0,',Art/Interface/Buttons/TechTree/Banking.dds,Art/ Interfaccia/Pulsanti/TechTree_Atlas.dds,8,1',ColorTypes(44), iX, iY, True,True)
### messaggio: %s1 ha saccheggiato %d2 [ICON_GOLD]!###

## Fine del predatore ##

if (non self.__LOG_COMBAT):
ritorno
se giocatoreX e giocatoreX e unitàX e giocatoreY:
CvUtil.pyPrint('Il giocatore %d Civilization %s Unit %s ha sconfitto il giocatore %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))
..
 

Attachments

  • Screenshot 2024-06-02 111546.png
    Screenshot 2024-06-02 111546.png
    2 MB · Views: 1,905
  • debug.txt
    debug.txt
    2.4 MB · Views: 12
  • Screenshot 2024-06-02 114029.png
    Screenshot 2024-06-02 114029.png
    68.5 KB · Views: 14
  • Screenshot 2024-06-02 142128.png
    Screenshot 2024-06-02 142128.png
    393.8 KB · Views: 11
Last edited:
OK, I've tried it; indeed doesn't work. This comment in BugEventManager helped me:
BugEventManager.py said:
Note that the naming conventions for the event type strings vary from event
to event. Some use initial capitalization, some do not; some eliminate the
"on..." prefix used in the event handler function name, some do not. Look
at the unmodified CvEventManager.py source code to determine the correct
name for a particular event.
I did look up the combat result event handler and, sure enough, it does not use a capital "C": 'combatResult' : self.onCombatResult,
So em.addEventHandler('combatResult', onCombatResult) should fix it. I don't think the Raider code in CvEventManager should be a problem. Since Realism Invictus has already copied CvEventManager.py and added code to it, you could also just place your code there. Though I think it's cleaner to keep your additions in your own module(s) when possible.

(Your post seems to have flipped to Italian when you edited it. But I did see the translated version too.)
 
OK, I've tried it; indeed doesn't work. This comment in BugEventManager helped me:I did look up the combat result event handler and, sure enough, it does not use a capital "C": 'combatResult' : self.onCombatResult,
So em.addEventHandler('combatResult', onCombatResult) should fix it. I don't think the Raider code in CvEventManager should be a problem. Since Realism Invictus has already copied CvEventManager.py and added code to it, you could also just place your code there. Though I think it's cleaner to keep your additions in your own module(s) when possible.

(Your post seems to have flipped to Italian when you edited it. But I did see the translated version too.)
Thanks now, I'll try right away.
N.b. Unfortunately when I edit, if I'm not careful the text translates. :)
 
HI. Sorry if I bother you with my requests for help.
I wanted to try to adapt the limited religion component mod for bug , but I don't think I could do it on my own. So this is the text I prepared, I hope it goes well. also attach the original mod. I have already prepared the init and the mod file in the config folder.

## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Implementaion of miscellaneous game functions

from CvPythonExtensions import *
import CvEventInterface
import CvGameUtils
import Popup as PyPopup
import PyHelpers
import LimitedReligions

# for C++ compatibility
false=False
true=True

# globals
gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo
PyCity = PyHelpers.PyCity
PyGame = PyHelpers.PyGame
import BugEventManager
import BugPath


class CvGameUtils:
"Miscellaneous game functions"
def __init__(self):
pass
def init():
em = BugEventManager.g_eventManager
em.addEventHandler('BeginGameTurn', onBeginGameTurn)
em.addEventHandler('TechAcquired', onTechAcquired)

def onBeginPlayerTurn(argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList

# Limited Religions
if LimitedReligions.NonStateHolyCityReligionSpreadCheck(iPlayer):
LimitedReligions.doNonStateHolyCityReligionSpread(iPlayer)
# Limited Religions

def onTechAcquired(argsList):
'Tech Acquired'
iTechType, iTeam, iPlayer, bAnnounce = argsList
# Note that iPlayer may be NULL (-1) and not a refer to a player object
# Limited Religions
game = CyGame()
pPlayer = gc.getPlayer(iPlayer)
FoundRel = False

if iPlayer > -1:
# Is this a religious Tech?
if LimitedReligions.isReligiousTech(iTechType):
# Is the game option selected for Limited Religions?
if LimitedReligions.isOC_LIMITED_RELIGIONS():
# Skip dead players and Barbarions
if pPlayer.isAlive() and not pPlayer.isBarbarian():
# Must not already have a Holy City
if not LimitedReligions.OwnsHolyCity(iPlayer):
# Loop through all religions
for iSlot in range(gc.getNumReligionInfos()):
# Does the player have the prerequisite tech for this religion slot?
if gc.getTeam(pPlayer.getTeam()).isHasTech(gc.getReligionInfo(iSlot).getTechPrereq()):
# Must be at least one religion slot available
if not game.isReligionSlotTaken(iSlot):
# The number of religious techs discovered must be greater than total religions founded.
if LimitedReligions.RelTechsGreaterThanReligions:
# PreConditions are met to found a religion.
# If the active player is Human
if iPlayer == gc.getGame().getActivePlayer() and pPlayer.isHuman:
# Choose religions option on?
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
# If Autoplay is running, Let the game pick the religion.
if( game.getAIAutoPlay() > 0 ):
FoundRel = True
break

else:
#Display the popup to pick a religion
#CyInterface().addImmediateMessage("Pick Religion", "")
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_FOUND_RELIGION)
popupInfo.setData1(iSlot)
popupInfo.addPopup(iPlayer)
break

else:
# Not Playing Choose Religions, So let the game pick the religion.
#CyInterface().addImmediateMessage("C", "")
FoundRel = True
break

else:
# Not Human, So let the game pick the religion.
#CyInterface().addImmediateMessage("Found a Religion", "")
FoundRel = True
break

if FoundRel:
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
# Get Civ's Favorite religion or random pick if favorite religion is not available.
iNewReligion = LimitedReligions.AI_chooseReligion(iPlayer)
if iNewReligion != -1:
# Found the religion.
#CyInterface().addImmediateMessage("Found Favorite Religion", "")
pPlayer.foundReligion(iNewReligion, iSlot, True)

else:
for i in range(gc.getNumReligionInfos()):
if gc.getReligionInfo(i).getTechPrereq() == iTechType:
if not gc.getGame().isReligionFounded(i):
# Found the religion.
#CyInterface().addImmediateMessage("Found Prerequisit Religion", "")
pPlayer.foundReligion(i,i,True)
# End Limited Religions Mod

def cannotTrain(argsList):
# Limited Religions
# Restricts the Missionary production to only state religion missionaries.
# Requires the Cannot Train call back to be enabled in the PythonCallbackDefines.xml file
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
bIgnoreUpgrades = argsList[5]
iOwner = pCity.getOwner()
pPlayer = gc.getPlayer(iOwner)
iStateReligion = pPlayer.getStateReligion()

# If the Player has a state religion
if iStateReligion != -1:
# If option is selected for restricting missionary production
if LimitedReligions.isOC_TRAIN_ONLY_STATE_RELIGION_MISSIONARY:
# Does the Player have a non-State Religion
for iReligionLoop in range(gc.getNumReligionInfos()):
# Make sure only non-state religions are selected
if iReligionLoop != iStateReligion:
# Get the Missionary for the non State Religion
MyNonStateRelMissionary = str(LimitedReligions.getReligionMissionary(iOwner, iReligionLoop))
# If this is a non state religion Missionary
if eUnit == gc.getInfoTypeForString(MyNonStateRelMissionary):
# Deny the ability to train the non state religion Missionary
return True
break

return False
# End Limited Religions

def doHolyCity(self):
# Limited Religions
# Purpose: Determine if Religion should be allowed to be founded
# Returns True if religion should not be founded
# Returns False if religion should be founded (Default)
if LimitedReligions.isOC_LIMITED_RELIGIONS():
#CyInterface().addImmediateMessage("doHolyCity", "")
# religion should not be founded
return True

# religion should be founded
return False

def doHolyCityTech(argsList):
eTeam = argsList[0]
ePlayer = argsList[1]
eTech = argsList[2]
bFirst = argsList[3]
# Limited Religions
# Purpose: Determine if Religion Popup should be dispalyed
# Returns True if Religion Popup should not be dispalyed
# Returning False if Religion Popup should be dispalyed (Default)

if LimitedReligions.isOC_LIMITED_RELIGIONS():
# Stop Religion Popup from being dispalyed
#CyInterface().addImmediateMessage("doHolyCityTech", "")
return True

# Allow the Religion popup to be displayed
return False
def isOC_LIMITED_RELIGIONS():
# Limited Religions
return gc.getDefineINT("OC_LIMITED_RELIGIONS") != 0

def isOC_TRAIN_ONLY_STATE_RELIGION_MISSIONARY():
# Limited Religions
return gc.getDefineINT("OC_TRAIN_ONLY_STATE_RELIGION_MISSIONARY") != 0

def OwnsHolyCity(iPlayer):
# Limited Religions
#Checks to see if player has a Holy City (Any Holy City)
#Returns True if player has a Holy City
#Returns False if player does not have a Holy City
#pPlayer = gc.getPlayer(iPlayer)
iRefCityList = PyPlayer(iPlayer).getCityList()
pHolyCity = False

for pyCity in iRefCityList:
pCity = pyCity.GetCy()
#iCity = pCity.getID()

for iRel in range(gc.getNumReligionInfos()):
if pCity.isHasReligion(iRel):
if pCity.isHolyCityByType(iRel):
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Holy City Found!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
pHolyCity = True
break

return pHolyCity

def OwnsStateRelHolyCity(iPlayer):
# Limited Religions
#Checks to see if player has the Holy City for the State Religion
#Returns True if player has the State Religion Holy City
#Returns False if player does not have the State Religion Holy City
iRefCityList = PyPlayer(iPlayer).getCityList()
pPlayer = gc.getPlayer(iPlayer)
iStateReligion = pPlayer.getStateReligion()
pHolyCity = False

if iStateReligion != -1:
for pyCity in iRefCityList:
pCity = pyCity.GetCy()
#iCity = pCity.getID()

for iRel in range(gc.getNumReligionInfos()):
if pCity.isHasReligion(iRel):
if iRel == iStateReligion:
if pCity.isHolyCityByType(iRel):
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Holy City Found!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
pHolyCity = True
break

return pHolyCity

def OwnsNonStateRelHolyCity(iPlayer):
# Limited Religions
#Checks to see if player has a Non-State Religion Holy City
#Returns True if player has a Non-State Religion Holy City
#Returns False if player does not have a Non-State Religion Holy City
iRefCityList = PyPlayer(iPlayer).getCityList()
pPlayer = gc.getPlayer(iPlayer)
iStateReligion = pPlayer.getStateReligion()
pHolyCity = False

if iStateReligion != -1:
for pyCity in iRefCityList:
pCity = pyCity.GetCy()
#iCity = pCity.getID()

for iRel in range(gc.getNumReligionInfos()):
if pCity.isHasReligion(iRel):
if iRel != iStateReligion:
if pCity.isHolyCityByType(iRel):
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Holy City Found!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
pHolyCity = True
break

return pHolyCity


def onTechPreviouslyFounded(MyiTechType):
# Limited Religions
# Purpose: Check to see if tech has been previously discovered
# Returns True if tech has been previously discovered
# Returns False if tech has not been previously discovered
pdTech = False

for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
PzPlayer = gc.getPlayer(ePlayer)
if PzPlayer.isAlive():
#if ePlayer != gc.getPlayer(CyGame().getActivePlayer()).getID():
if gc.getTeam(PzPlayer.getTeam()).isHasTech(MyiTechType):
# Tech has been previously discovered
pdTech = True
break

if not pdTech:
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Tech was not previously discovered!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
return False
else:
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Tech was previously discovered!','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
return True

def isReligiousTech(iTechType):
# Limited Religions
# Returns True if the Tech is a Religious Tech
# Returns False if the Tech is not a Religious Tech
ReligiousTech = False

for iREL in range(gc.getNumReligionInfos()):
if gc.getReligionInfo(iREL).getTechPrereq() == iTechType:
ReligiousTech = True
break

return ReligiousTech

def RelTechsGreaterThanReligions():
# Limited Religions
TCount = False

if getTotalReligiousTechsFounded > getTotalReligionsFounded:
TCount = True

return TCount

def getTotalReligionsFounded():
# Limited Religions
# Returns the total number of Religions founded.
iReligionCount = 0

for ixReligion in range(gc.getNumReligionInfos()):
#If the religion has not been founded
if gc.getGame().isReligionFounded(ixReligion):
iReligionCount = iReligionCount + 1

#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Total Religious founded' [iReligionCount],'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
return iReligionCount

def getTotalReligiousTechsFounded():
# Limited Religions
# Returns the total number of Religious Techs founded.
iRelTechCount = 0

for iTech in range(gc.getNumTechInfos()):
if isReligiousTech(iTech):
if onTechPreviouslyFounded(iTech):
iRelTechCount = iRelTechCount + 1

#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Total Religious Techs founded' [iRelTechCount],'AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
return iRelTechCount

def ReligionDiscoveryConditions(iPlayer):
# Limited Religions
# Returns True if Civ can found a religion.
# Returns false if Civ can't found a religion.
Condition = False
pPlayer = gc.getPlayer(iPlayer)
iTotalTechs = getTotalReligiousTechsFounded()
iTotalReligions = getTotalReligionsFounded()

if not OwnsHolyCity(iPlayer):
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Message A','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)
if iTotalTechs > iTotalReligions:
Condition = True
#CyInterface().addMessage(CyGame().getActivePlayer(),True,25,'Message A','AS2D_DISCOVERBONUS',1,'Art/Interface/Buttons/TerrainFeatures/Forest.dds',ColorTypes(8),0,0,False,False)

return Condition

def AI_chooseReligion(iPlayer):
# Limited Religions
# Purpose:
# 1. Finds the AI's favorite religion and if available, selects it.
# 2. If favorite religion is not available, the AI makes a randum pick.
pPlayer = gc.getPlayer(iPlayer)
eFavorite = gc.getLeaderHeadInfo(pPlayer.getLeaderType()).getFavoriteReligion()

if eFavorite > -1 and not CyGame().isReligionFounded(eFavorite):
return eFavorite

aeReligions = list()
for i in range(gc.getNumReligionInfos()):
if not CyGame().isReligionFounded(i):
aeReligions.append(i)

if len(aeReligions) > 0:
return aeReligions[CyGame().getSorenRandNum(len(aeReligions), "AI pick religion")]
return -1

def getNonStateHolyCityReligion(iPlayer):
# Limited Religions
# Looks to see if the AI has a non-State Holy City Religion
iRefCityList = PyPlayer(iPlayer).getCityList()
pPlayer = gc.getPlayer(iPlayer)
iStateReligion = pPlayer.getStateReligion()

for pyCity in iRefCityList:
pCity = pyCity.GetCy()
#iCity = pCity.getID()

for iReligion in range( gc.getNumReligionInfos()):
if iReligion != iStateReligion:
if pCity.isHolyCityByType(iReligion):
NSHCReligion = iReligion
break

return NSHCReligion


def isMaxedOut(zReligion, zPlayer):
# Limited Religions
# 1. Returns True if every city has the official state religion
# 1. Returns False if at least one city does not have the official state religion

iPlayer = zPlayer.getID()
iRefCityList = PyPlayer(iPlayer).getCityList()
MaxedOut = True

for pyCity in iRefCityList:
zCity = pyCity.GetCy()

for iRel in range(gc.getNumReligionInfos()):
if iRel == zReligion:
if not zCity.isHasReligion(iRel):
MaxedOut = False

return MaxedOut


def NonStateHolyCityReligionSpreadCheck(iPlayer):
# Limited Religions
# Returns True if the conditions below are met for AI players:
# 1. AI Player does not own the state religion Holy City
# 2. AI Player has a non-state HolyCity
# 3. The non-State religion should be spread or...
# 4. The state religion should be converted to the non-state Holy City religion.
# Returns False if the conditions above are not met.
AIpPlayer = gc.getPlayer(iPlayer)
iStateReligion = AIpPlayer.getStateReligion()

# Make sure the AI player has a state religion
if iStateReligion != -1:
# If Limited Religions
if isOC_LIMITED_RELIGIONS():
# If this is an AI player
if not AIpPlayer.isNone() and not AIpPlayer.isBarbarian() and not AIpPlayer.isHuman() and AIpPlayer.isAlive():
# Make sure the AI player does not own the state religion Holy City.
if not OwnsStateRelHolyCity(iPlayer):
# Does the Player have a non-state Holy City?
if OwnsNonStateRelHolyCity(iPlayer):
return True

return False


def doNonStateHolyCityReligionSpread(iPlayer):
# Limited Religions
# Applies to AI Players Only
# Purpose: Spreads a non-State religion or converts state religion to the non-state Holy City religion.
AIpPlayer = gc.getPlayer(iPlayer)

# Is the game option selected for Limited Religions?
if isOC_LIMITED_RELIGIONS():
# If this is an AI player
if not AIpPlayer.isNone() and not AIpPlayer.isBarbarian() and not AIpPlayer.isHuman() and AIpPlayer.isAlive():
# If the AI Player meets the conditions to spread a non-state religion
if NonStateHolyCityReligionSpreadCheck(iPlayer):
# Find the Religion matching non-State Holy City Religion
NonStateHolyCityReligion = getNonStateHolyCityReligion(iPlayer)

if not isMaxedOut(NonStateHolyCityReligion, AIpPlayer):
# Spread the non-state Religion to a city
SpreadHolyCityReligion(iPlayer, NonStateHolyCityReligion)

# If every city has the non-state religion, then force the AI player to covert.
elif isMaxedOut(NonStateHolyCityReligion, AIpPlayer):
# Force Civ to covert the state Religion to the non-stae Holy City religion
AIpPlayer.convert(NonStateHolyCityReligion)


#def doPickReligionPopup(iPlayer, religionSlot):
# # Limited Religions
# pPlayer = gc.getPlayer(iPlayer)
# popupInfo = CyPopupInfo()
# popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
# popupInfo.setData1(iPlayer)
# popupInfo.setData2(religionSlot)
# popupInfo.setOnClickedPythonCallback("foundReligionCallback")
# popupInfo.setText(CyTranslator().getText(("TXT_KEY_FOUNDED_RELIGION"),()))
#
# for i in range(gc.getNumReligionInfos()):
# if not CyGame().isReligionFounded(i):
# popupInfo.addPythonButton(gc.getReligionInfo(i).getDescription(), gc.getReligionInfo(i).getButton())
#
# popupInfo.addPopup(iPlayer)


def ReligiousTechCheck(iPlayer, iTechType):
# Limited Religions
# Returns True if the player has the specified Religious Tech
# Returns False if the player doesn't have the specified Religious Tech
pPlayer = gc.getPlayer(iPlayer)
TechCheck = False

for iTech in range(gc.getNumTechInfos()):
# Is this a religious Tech?
if isReligiousTech(iTech):
# Does the player have this tech?
if gc.getTeam(pPlayer.getTeam()).isHasTech(iTech):
if iTech == iTechType:
TechCheck = True
break

return TechCheck


def getReligionMissionary(iPlayer, iReligion):
# Limited Religions
# Returns the Missionary Name for the specified Religion
pPlayer = gc.getPlayer(iPlayer)
pCivilization = gc.getCivilizationInfo(pPlayer.getCivilizationType())

for iUnitClass in range(gc.getNumUnitClassInfos()):
if gc.getUnitClassInfo(iUnitClass).getMaxPlayerInstances() > 0:
#if gc.getBuildingClassInfo(iUnitClass).getMaxPlayerInstances() > 0:
kUnit = gc.getUnitInfo(pCivilization.getCivilizationUnits(iUnitClass))
if kUnit.getPrereqReligion() == iReligion:
if kUnit.getReligionSpreads(iReligion):
iUnit = pCivilization.getCivilizationUnits(iUnitClass)
MyMissionaryName = gc.getUnitInfo(iUnit).getType()
#CyInterface().addImmediateMessage(str(MyMissionaryName), "")
return MyMissionaryName
break


def SpreadHolyCityReligion(iPlayer, HolyCityiReligion):
# Limited Religions
# Purpose: 1. To increase the influence a non-state Holy City until Civ converts to the religion.
# 2. Spreads Religion one City per turn
# Scope: 1. Called when a Civ does not own the Holy City for their state religion
# 2. Will not run if Civ owns the Holy City for their state religion
#iPlayer = pPlayer.getID()
iRefCityList = PyPlayer(iPlayer).getCityList()

for pyCity in iRefCityList:
pCity = pyCity.GetCy()
#iCity = pCity.getID()

for iRel in range(gc.getNumReligionInfos()):
if not pCity.isHasReligion(iRel):
if iRel == HolyCityiReligion:
# Spread Holy City Religion to the City
pCity.setHasReligion(iRel, True, 0, 0)
break
# End Limited Religions Functions
 

Attachments

As far as I can tell, the GameOptionsStatus part is optional. I don't think the Limited Religions functionality depends on it. Looks like it only shows a popup at game start that tells the player whether OC_LIMITED_RELIGIONS and OC_TRAIN_ONLY_STATE_RELIGION_MISSIONARY are enabled in GlobalDefines.xml. Perhaps you could try getting it to work without that popup at first. I've written the text below mostly based on just your first post (hadn't seen the second one yet).

I have already prepared the init and the mod file in the config folder.
So this won't go into the module you've used for your earlier additions? I.e. LimitedReligions.py is going to be a separate module, initialized from init.xml, I assume. Or, rather, MyfileCvGameUtils.py, and you intend to copy the contents of LimitedReligions.py there. That might not be ideal because it'll mean that all the references to the LimitedReligions module will have to be deleted, e.g. isReligiousTech(iTechType) instead of LimitedReligions.isReligiousTech(iTechType). You could do that quickly through automated search-and-replace, but maybe it's cleaner to just keep LimitedReligions.py intact and to put only the stuff from CvEventManager.py, CvGameUtils.py into MyfileCvGameUtils.py. (Or maybe name that thing LimitedReligionsHandlers.py?)

For PyHelpers, the mod's changes aren't highlighted. I've looked at a diff (modified file vs. the BtS version) in WinMerge. The only consequential changes are these additions to the PyPlayer class:
Spoiler :
Code:
	def AI_changeAttitude(self, iPlayer, amount):
		#return self.player.AI_changeAttitudeExtra(iPlayer, amount)
		self.player.AI_changeAttitudeExtra(iPlayer, amount)

	def getStateReligion(self):
		return self.player.getStateReligion()
The first one I've corrected; AI_changeAttitudeExtra doesn't return a value. BUG does not have its own copy of PyHelpers, so you could just copy the whole file from the LR mod. That being said, I only see the mod call getStateReligion directly on CyPlayer, never on PyPlayer. (PyPlayer is a wrapper class based on CyPlayer.) And the mod doesn't seem to change any diplo attitude values (which explains why the excess return statement isn't causing problems). In other words, I think the mod's PyHelpers.py can simply be omitted. Maybe worth a try; shouldn't hurt to include it either.

On the XML side, we've got some game text, two GlobalDefines and the enabled USE_CANNOT_TRAIN_CALLBACK. I'm assuming that you've got this covered. I've ignored the WOC folder; let's hope the standard version does just the same thing.

In LimitedReligions.py, the global stuff can probably be reduced to this:
Code:
from CvPythonExtensions import *
import PyHelpers

gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer
Or it could just be kept as it is.

That leaves just the BUG integration of events and overrides: doNonStateHolyCityReligionSpread and ...Check are supposed to be called from onBeginPlayerTurn. A bunch of stuff is supposed to happen in onTechAcquired. Both of these will require a new handler function. Then we've got additional checks for cannotTrain; those also need a new function. And isOC_LIMITED_RELIGIONS and isOC_LIMITED_RELIGIONS are supposed to override doHolyCity and doHolyCityTech.

If you keep LimitedReligions.py as its own module, you'll only need to import that one at the top (plus the usual):
Code:
from CvPythonExtensions import *
import BugEventManager
import BugGameUtils
import LimitedReligions

gc = CyGlobalContext()
Code:
def init():
	em = BugEventManager.g_eventManager
    em.addEventHandler('BeginPlayerTurn', onBeginPlayerTurn)
    em.addEventHandler('techAcquired', onTechAcquired)
I've copied that from you and replaced "GameTurn" with "PlayerTurn" and changed 'techAcquired' to a lower-case 't'. I've double checked the handler names in the EventHandlerMap in CvEventManager.py, and a lower-case 't' is used there. A game turn consists of each player taking their turn, the start of a game turn and the start of each player turn are separate events. I trust you're making sure that the indentation (spaces/ tabs) is consistent within each module.

Will also need to add the BugGameUtils handlers in init:
Code:
	BugGameUtils.addHandler(cannotTrain)
	BugGameUtils.addHandler(doHolyCity)
	BugGameUtils.addHandler(doHolyCityTech)
Then, your handlers - onBeginPlayerTurn, onTechAcquired, cannotTrain, doHolyCity and doHolyCityTech - look good as they are. Looks like you've kept all the correct indentation, and you didn't copy the tech splash stuff; great.

And all the functions below, copied from LimitedReligions.py, I would delete.

I'll be suprised if everything works correctly just like this, but it looks a reasonable first attempt.
 
I'm wondering if the discussion on page 2 of the Limited Religions thread is even still relevant to the current version. I see no CvScreenInterface.py in the current download.
 
thank you very much for your availability.here is the first edited part

## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Implementaion of miscellaneous game functions

from CvPythonExtensions import *
import BugGameUtils
import LimitedReligions

gc = CyGlobalContext()

import BugEventManager

def init():
em = BugEventManager.g_eventManager
em.addEventHandler('BeginPlayerTurn', onBeginPlayerTurn)
em.addEventHandler('techAcquired', onTechAcquired)
BugGameUtils.addHandler(cannotTrain)
BugGameUtils.addHandler(doHolyCity)
BugGameUtils.addHandler(doHolyCityTech)

def onBeginPlayerTurn(argsList):
..........then continue as above
 
There is an excess tab at that line. And, if you want to keep everything in one module, then the import LimitedReligions needs to be removed (the module can't and shouldn't import itself), this stuff ...
Code:
import PyHelpers
PyPlayer = PyHelpers.PyPlayer
... will be needed instead, and you'll probably need to delete all occurrences of LimitedReligions.
e.g. isReligiousTech(iTechType) instead of LimitedReligions.isReligiousTech(iTechType). You could do that quickly through automated search-and-replace, [...]
Or perhaps Python tolerates those redundant references to the current module, not sure. On the plus side, the code will become more readable without all that clutter. Alternatively, you could keep the original LimitedReligions.py, name your own module something else and place there only the code up to the line that currently produces the indentation error.
 
ok I left limitedreligion.py identical and merged as in the figure, with a single LimitedReligionsHandlers.py file

## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Implementaion of miscellaneous game functions

from CvPythonExtensions import *
import BugGameUtils
import LimitedReligions

gc = CyGlobalContext()

import BugEventManager

def init():
em = BugEventManager.g_eventManager
em.addEventHandler('BeginPlayerTurn', onBeginPlayerTurn)
em.addEventHandler('techAcquired', onTechAcquired)
BugGameUtils.addHandler(cannotTrain)
BugGameUtils.addHandler(doHolyCity)
BugGameUtils.addHandler(doHolyCityTech)

def onBeginPlayerTurn(argsList):
'Called at the beginning of a players turn'
iGameTurn, iPlayer = argsList

# Limited Religions
if LimitedReligions.NonStateHolyCityReligionSpreadCheck(iPlayer):
LimitedReligions.doNonStateHolyCityReligionSpread(iPlayer)
# Limited Religions

def onTechAcquired(argsList):
'Tech Acquired'
iTechType, iTeam, iPlayer, bAnnounce = argsList
# Note that iPlayer may be NULL (-1) and not a refer to a player object
# Limited Religions
game = CyGame()
pPlayer = gc.getPlayer(iPlayer)
FoundRel = False

if iPlayer > -1:
# Is this a religious Tech?
if LimitedReligions.isReligiousTech(iTechType):
# Is the game option selected for Limited Religions?
if LimitedReligions.isOC_LIMITED_RELIGIONS():
# Skip dead players and Barbarions
if pPlayer.isAlive() and not pPlayer.isBarbarian():
# Must not already have a Holy City
if not LimitedReligions.OwnsHolyCity(iPlayer):
# Loop through all religions
for iSlot in range(gc.getNumReligionInfos()):
# Does the player have the prerequisite tech for this religion slot?
if gc.getTeam(pPlayer.getTeam()).isHasTech(gc.getReligionInfo(iSlot).getTechPrereq()):
# Must be at least one religion slot available
if not game.isReligionSlotTaken(iSlot):
# The number of religious techs discovered must be greater than total religions founded.
if LimitedReligions.RelTechsGreaterThanReligions:
# PreConditions are met to found a religion.
# If the active player is Human
if iPlayer == gc.getGame().getActivePlayer() and pPlayer.isHuman:
# Choose religions option on?
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
# If Autoplay is running, Let the game pick the religion.
if( game.getAIAutoPlay() > 0 ):
FoundRel = True
break

else:
#Display the popup to pick a religion
#CyInterface().addImmediateMessage("Pick Religion", "")
popupInfo = CyPopupInfo()
popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_FOUND_RELIGION)
popupInfo.setData1(iSlot)
popupInfo.addPopup(iPlayer)
break

else:
# Not Playing Choose Religions, So let the game pick the religion.
#CyInterface().addImmediateMessage("C", "")
FoundRel = True
break

else:
# Not Human, So let the game pick the religion.
#CyInterface().addImmediateMessage("Found a Religion", "")
FoundRel = True
break

if FoundRel:
if game.isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
# Get Civ's Favorite religion or random pick if favorite religion is not available.
iNewReligion = LimitedReligions.AI_chooseReligion(iPlayer)
if iNewReligion != -1:
# Found the religion.
#CyInterface().addImmediateMessage("Found Favorite Religion", "")
pPlayer.foundReligion(iNewReligion, iSlot, True)

else:
for i in range(gc.getNumReligionInfos()):
if gc.getReligionInfo(i).getTechPrereq() == iTechType:
if not gc.getGame().isReligionFounded(i):
# Found the religion.
#CyInterface().addImmediateMessage("Found Prerequisit Religion", "")
pPlayer.foundReligion(i,i,True)
# End Limited Religions Mod

def cannotTrain(argsList):
# Limited Religions
# Restricts the Missionary production to only state religion missionaries.
# Requires the Cannot Train call back to be enabled in the PythonCallbackDefines.xml file
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
bIgnoreCost = argsList[4]
bIgnoreUpgrades = argsList[5]
iOwner = pCity.getOwner()
pPlayer = gc.getPlayer(iOwner)
iStateReligion = pPlayer.getStateReligion()

# If the Player has a state religion
if iStateReligion != -1:
# If option is selected for restricting missionary production
if LimitedReligions.isOC_TRAIN_ONLY_STATE_RELIGION_MISSIONARY:
# Does the Player have a non-State Religion
for iReligionLoop in range(gc.getNumReligionInfos()):
# Make sure only non-state religions are selected
if iReligionLoop != iStateReligion:
# Get the Missionary for the non State Religion
MyNonStateRelMissionary = str(LimitedReligions.getReligionMissionary(iOwner, iReligionLoop))
# If this is a non state religion Missionary
if eUnit == gc.getInfoTypeForString(MyNonStateRelMissionary):
# Deny the ability to train the non state religion Missionary
return True
break

return False
# End Limited Religions

def doHolyCity(self):
# Limited Religions
# Purpose: Determine if Religion should be allowed to be founded
# Returns True if religion should not be founded
# Returns False if religion should be founded (Default)
if LimitedReligions.isOC_LIMITED_RELIGIONS():
#CyInterface().addImmediateMessage("doHolyCity", "")
# religion should not be founded
return True

# religion should be founded
return False

def doHolyCityTech(argsList):
eTeam = argsList[0]
ePlayer = argsList[1]
eTech = argsList[2]
bFirst = argsList[3]
# Limited Religions
# Purpose: Determine if Religion Popup should be dispalyed
# Returns True if Religion Popup should not be dispalyed
# Returning False if Religion Popup should be dispalyed (Default)

if LimitedReligions.isOC_LIMITED_RELIGIONS():
# Stop Religion Popup from being dispalyed
#CyInterface().addImmediateMessage("doHolyCityTech", "")
return True

# Allow the Religion popup to be displayed
return False
 

Attachments

You'll still need the LimitedReligions.xml from your previous upload, just with everything named LimitedReligionsHandlers. And, as before, invoked from init.xml. As it is, I expect that the mod would have no effect. And LimitedReligionsHandlers.py seems to have a duplicate file ending (.py.py).
 
then I don't need the orionmod folder? do I put both LimitedReligion.py and limitedreligionhandler.py files in the contrib folder? the xml is ok?
 

Attachments

  • 1.png
    1.png
    17.2 KB · Views: 10
Yes, I hope it's enough to have LimitedReligionsHandlers under "module" so that the mod ID can still be just LimitedReligions. (Come to think of it, LimitedReligionsInit might be a more self-explanatory name than ...Handlers. But, whatever.) I don't think you need an OrionMod folder. For the options popup, I'd try adopting this handler ...
Spoiler :
Code:
	def onGameStart(self, argsList):
		'Called at the start of the game'
		if (gc.getGame().getGameTurnYear() == gc.getDefineINT("START_YEAR") and not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ADVANCED_START)):
			# ###############################################
			#            Orion's Game Options Status
			# ###############################################
			GameOptionsStatus.getGameOptionsStatus()
			# End Orion's Game Options Status
... and GameOptionsStatus.py (then also to be imported in your LimitedReligionsHandlers.py). I.e. just the stuff from the current version of the LimitedReligions mod. So far, I don't see why it should be more complicated than that. But let's perhaps get it to work without the popup first.
 
Before trying, I wanted to know if I put the files in the right folders
 

Attachments

  • Screenshot 2024-06-26 171945 copy.jpg
    Screenshot 2024-06-26 171945 copy.jpg
    156.2 KB · Views: 8
As far as I know, the Python system will look everywhere in the Assets\Python folder, so you can use whichever folder structure you like. Only files that replace files of the original game need to have the same relative path as in the original game. I guess I'd put all my new modules into a single new folder directly under Assets\Python. Well, that's what I did in my own BUG-based mod (screenshot attached).
 

Attachments

  • taurus-py-modules.jpg
    taurus-py-modules.jpg
    38 KB · Views: 9
I did the test and loaded everything fine, but when I do shift 2 it crashes.
LimitedrReligions.py is the original without modifications
 

Attachments

Back
Top Bottom