Hiding Previously Explored Terrain

Lplate

Esus (Allegedly)
Joined
Feb 8, 2011
Messages
578
Location
Ireland
Hi,

I'd suggested in http://forums.civfanatics.com/showpost.php?p=11785491&postcount=269, that it might make exploration more interesting if some explored tiles became obscured.
If you don't know how to make maps, you can't accurately record the information about the land you've previously explored.

I wasn't aware of this being done previously so I thought I'd try to do a quick python mod to see if a concept along these lines adds any enjoyment to the game. Unfortunately, my initial coding isn't working. It looks fine on the first turn :) but crashes on the second:cry:.

Code:
cf = CustomFunctions.CustomFunctions()
gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo
getInfoType = gc.getInfoTypeForString
getPlot	= CyMap().plot

getPlayer = gc.getPlayer

iCart = gc.getInfoTypeForString('TECH_CARTOGRAPHY')

iElohim = gc.getInfoTypeForString('CIVILIZATION_ELOHIM')

def onBeginPlayerTurn(self, argsList):
	'Called at the beginning of the end of each turn'
	iGameTurn, iPlayer = argsList
	pPlayer = gc.getPlayer(iPlayer)
	py = PyPlayer(iPlayer)
	ePlayer = getPlayer(iPlayer)
	
	iTeam = pPlayer.getTeam()

	if pPlayer.getCivilizationType() == iElohim:
		iUniqueRem = 0
	else:
		iUniqueRem = 10

###
# Can they map where they have been?
	if not pPlayer.isHasTech(iCart):

		for iPlotIndex in range(CyMap().numPlots()):
			pLoopPlot = CyMap().plotByIndex(iPlotIndex)

			if pLoopPlot.isRevealed(iTeam, True):
				if not pLoopPlot.isVisible(iTeam, True):
					iRemember = 90
					if pLoopPlot.getImprovementType() != -1 and (gc.getImprovementInfo(pLoopPlot.getImprovementType()).isUnique() == True) :
						
						iRemember = iUniqueRem
							
					iLostKnowledge = CyGame().getSorenRandNum(100, "Lost")
					if iLostKnowledge < iRemember:

						pLoopPlot.setRevealed(iTeam, False, False, iTeam)

						pLoopPlot.updateVisibility()

Does anyone have any ideas as to what is causing the crash or how I can fix it?
I'm doing the mod as a python module for RifE.
 
1) Reduntant definitions of variables. pPlayer and ePlayer refer to same thing.
2) isHasTech is a function of CyTeam not CyPlayer
3) if pLoopPlot.getImprovementType() != -1 and (gc.getImprovementInfo(pLoopPlot.getImprovementType()).isUnique() == True) :
Since you are using "and" to test both conditions together, if there is no improvement, the second condition will give an error since it is a None type.
4) As The_J mentioned, this is awful performance.
Every single turn, you are looping through every single plot to do something.
If there are 20 players in the game, you are looping through the whole map 20 times each time you press end turn.

If you really insist on having this function, define it under BeginGameTurn and use team check rather than player check.
Thus if there are 5 teams of 4 players each, at least you are looping through the map 5 times rather than 20 times.
Still bad for performance, but much better than what you are doing right now.
 
3) if pLoopPlot.getImprovementType() != -1 and (gc.getImprovementInfo(pLoopPlot.getImprovementType()).isUnique() == True) :
Since you are using "and" to test both conditions together, if there is no improvement, the second condition will give an error since it is a None type.

This particular point is probably not correct. Python uses shortcut type evaluation for expressions. With an "and" if the first of the two parts is false then the entire expression is false so it never even attempts to run the code after the "and". At least, that is what it is supposed to be doing (or not doing, in this case).
 
Hi,

Thanks for the suggestions:goodjob:. I got it working:). The code is below.
I moved it to onBeginGameTurn as suggested and tried to use a tuple to prevent unnecessary cycling through all of the plots.
I couldn't get isHasTech to work for the team but this is working in the code using the pPlayer.
If there's any further suggestions on how to make it more efficient, they'd be welcome.

Spoiler :
Code:
def onBeginGameTurn(self, argsList):
	'Called at the beginning of the end of each turn'
	iGameTurn = argsList[0]

# Identify players who have not learned Cartography
	BlindPlayers = []
	for iPlayer in range(gc.getMAX_PLAYERS()):
		
		pPlayer = gc.getPlayer(iPlayer)
		iTeam = pPlayer.getTeam()
		if (pPlayer.isAlive() and not pPlayer == gc.getPlayer(gc.getORC_PLAYER()) and not pPlayer == gc.getPlayer(gc.getANIMAL_PLAYER()) and not pPlayer == gc.getPlayer(gc.getDEMON_PLAYER())):
		
			if not pPlayer.isHasTech(iCart):
				BlindPlayers.append(pPlayer)

# Only check plots if someone hasn't Cartography
	if len(BlindPlayers) > 0:
		for iPlotIndex in range(CyMap().numPlots()):
			pLoopPlot = CyMap().plotByIndex(iPlotIndex)
			for pBlindPlayer in BlindPlayers:
		
				iTeam = pBlindPlayer.getTeam()
				if pBlindPlayer.getCivilizationType() == iElohim:
					iUniqueRem = 0
				else:
					iUniqueRem = 10

				if pLoopPlot.isRevealed(iTeam, True):
					if not pLoopPlot.isVisible(iTeam, True):
						iRemember = 90
						if pLoopPlot.getImprovementType() != -1 and (gc.getImprovementInfo(pLoopPlot.getImprovementType()).isUnique() == True) :
							iRemember = iUniqueRem
							
						iLostKnowledge = CyGame().getSorenRandNum(100, "Lost")
						if iLostKnowledge < iRemember:
							pLoopPlot.setRevealed(iTeam, False, False, iTeam)
				pLoopPlot.updateVisibility()
 
Code:
pTeam = gc.getTeam(iTeam)
if not pTeam.isHasTech(XXX):

Great improvement, but what I will do is append the team and not the player.
As mentioned, for games with 2 teams and 10 players each, looping with players will result in looping through the whole map 10 times more unnecessarily, since vision is shared by the whole team.
 
Back
Top Bottom