Founding a Religion with Multiplayer

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
One of my best mods (the Limited Religions Component) still has a problem, under the "Choose Religions" option, I would like to solve. The problem only happens in multiplayer games. For some crazy reason, the popup to select the religion comes up on the wrong player's turn to select a religion. The correct civ still gets the religion, but doesn't get to pick the religion. :crazyeye: Again, this happens only in multiplayer. Single player works perfectly. The founding of a religion is controlled by the function onTechAcquired in the LimitedReligionsEvents.py file. I want to make sure the popup waits to appear at the beginning of the correct civs turn.

Example: You have 2 human players. Player A and B. Player A receives a popup to select a religion, even though Player A has not completed a tech. The popup comes up because player B has completed research for a religious tech, but Player B never gets the popup to select the religion. Player B still gets a religion, but the religion he gets had to be selected by Player A before Player B's turn actually started.

I want to have the popup, to select the religion for Player B, to wait until Player B's turn starts, not before. Any suggestions, on how this multiplayer python annoyance can be fixed, would be greatly appreciated.

You can get the very small mod comp here: http://forums.civfanatics.com/downloads.php?do=file&id=14831
 
Without looking at your actual code, you could try firing the popup on the beginPlayerTurn event. What you need to do is store a value somewhere so that it is carried over from onTechAcquired() to onBeginPlayerTurn(). The CvEventManager class/class instance is a good place to store values:
Spoiler :
@onTechAcquired()
Code:
self.religionFounder = iPlayer
Then check and reset the values:
Spoiler :
@onBeginPlayerTurn()
Code:
if self.religionFounder == iPlayer:
    LimitedReligionsEvents.lauchPopup()
    self.religionFounder = -1
A global variable would also work. The values should probably however be stored as scriptData as not to break the mod comp if onPreSave() method is executed in between onTechAcquired() and onBeginPlayerTurn().
 
Without looking at your actual code, you could try firing the popup on the beginPlayerTurn event. What you need to do is store a value somewhere so that it is carried over from onTechAcquired() to onBeginPlayerTurn(). The CvEventManager class/class instance is a good place to store values:
Spoiler :
@onTechAcquired()
Code:
self.religionFounder = iPlayer
Then check and reset the values:
Spoiler :
@onBeginPlayerTurn()
Code:
if self.religionFounder == iPlayer:
    LimitedReligionsEvents.lauchPopup()
    self.religionFounder = -1
A global variable would also work. The values should probably however be stored as scriptData as not to break the mod comp if onPreSave() method is executed in between onTechAcquired() and onBeginPlayerTurn().


It appears that onBeginPlayerTurn is called before onTechAcquired and a global variable does not seem to work. This is the line of code that I want to prevent running until the begining of that player's turn:

LimitedReligions.doPickReligionPopup(iPlayer, iSlot)

You see, the game wants to announce that a religion is founded in a distant land by another player (in this case a Human player), but the religion must be picked. So the popup comes up with the line above to allow the religion to be selected before the announcement. Again, it doesn't wait for the next player's turn start to pick the religion.
 
I wonder what doReligion() and doReviveActivePlayer() in CvGameUtils does? I'm thinking that you could change the return value of either to True and see what it does...
 
I wonder what doReligion() and doReviveActivePlayer() in CvGameUtils does? I'm thinking that you could change the return value of either to True and see what it does...

I think doReligion is somehow involved with the spread of a religion and doReviveActivePlayer allows you to perform an action after an AIAutoPlay.

DoReligion is not going to work because we are trying to delay the selection of a religion, which happens before it is established.
 
How are you making the popup? Because there is a CyPopupInfo.addPopup() method that take a PlayerTypes value as a parameter.

And you're testing this in hotseat, right? Because then it would only make sense that the popup fires on the "wrong" turn. It may not even be possible to "delay" an event like that. Hotseat is probably a special case as far as multiplayer is concerned.
 
How are you making the popup? Because there is a CyPopupInfo.addPopup() method that take a PlayerTypes value as a parameter.

With two functions:
Spoiler :

Code:
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(0)
		
def addPopup(szTitle, szText):
	# Don't display popups for autoplay games
	if (gc.getPlayer(CyGame().getActivePlayer()).isAlive()):
			
		popup = PyPopup.PyPopup(-1)
		popup.setHeaderString(szTitle)
		popup.setBodyString(szText)		
		popup.launch(true, PopupStates.POPUPSTATE_QUEUED)


And you're testing this in hotseat, right? Because then it would only make sense that the popup fires on the "wrong" turn. It may not even be possible to "delay" an event like that. Hotseat is probably a special case as far as multiplayer is concerned.


Yes. The problem only occurs when I play a multiplayer game from hotseat. There has got to be a way to put up a message at the begining of a selected hot seat player. If not, I will have to keep this as a known issue with multiplayer. :(

Edit: I solved it!!!!!! I got rid of the second function in favor of a change to the last line of the first function.

Code:
popupInfo.addPopup(iPlayer)

Thank you for helping me isolate the problem. :goodjob::banana::bounce:

:thanx:
 
Well, you're very welcome. I relied on tried-and-tested dumb luck. :lol:
 
Top Bottom