Wintermod coding help

kevinman4404

Lightning Warrior
Joined
Mar 31, 2007
Messages
837
Location
Ontario
This is for my mod component which emulates monthly snow cover. There is one map of values (like the ones from AIWars and CityNames from RFC), which has a value depending on the type of terrain its on and what month it gets covered in snow. For example month 1, the first month after July (August), when snow starts to advance, 10(tundra), 20(thinsoil) and 30(grasslands) are all changed to snow. These terrains are all labeled with different numbers so I can convert them back to their original terrain in the spring. Then month 2 (September) 40, 50 and 60 are covered with snow. Etc.

Here's some code

Code:
		if iGameTurn == 2:
			if (iTerrain != iCoast and iTerrain != iCoastFrozen):
				snowCover = tCityMap[67-pPlot.getY()][pPlot.getX()]
                        if (snowCover != "10"):
                                pPlot.setTerrainType(iSnow,True,True)
		                if iFeature == iForest:
			              pPlot.setFeatureType(iForest,2)
                        elif (snowCover != "20"):
                                pPlot.setTerrainType(iSnow,True,True)
		                if iFeature == iForest:
			              pPlot.setFeatureType(iForest,2)
                        elif (snowCover != "30"):
                                pPlot.setTerrainType(iSnow,True,True)
		                if iFeature == iForest:
		                      pPlot.setFeatureType(iForest,2)


What I really need is to know how to say:

"If game turn = X or ever X turns after"
ie
"If game turn = X or every 48 turns (one year for this mod's purposes) after, change all the terrains to what they should be at this time"

This is because I don't want it to do it just on that one turn, I want it to change the terrains every year (48 turns)

If I can get that written I should easily have a working mod component.

Also let me know if you see any glaring errors so far.

Thank you
Kevin
 
What you want is the "mod" operator which returns the remainder after integer division. Python uses % for this operator.

10 % 3 = 1
15 % 4 = 3

I recommend creating some helper functions like these:

Code:
TURNS_PER_MONTH = 4
FIRST_YEAR = 1912

def getYear(iGameTurn):
    """Returns the calendar year from the 0-based game turn."""
    return iGameTurn / (12 * TURNS_PER_MONTH) + FIRST_YEAR

def getMonth(iGameTurn):
    """Returns the 1-based month # from the 0-based game turn."""
    return iGameTurn / TURNS_PER_MONTH + 1

def getWeek(iGameTurn):
    """Returns the 1-based week # from the 0-based game turn."""
    return iGameTurn % TURNS_PER_MONTH + 1

Then you can use it to track when the month changes and make your terrain changes at that time.
 
Alright, thank you for the help

Would this work?

Code:
TURNS_PER_MONTH = 4
FIRST_YEAR = 1912

def getYear(iGameTurn):
    """Returns the calendar year from the 0-based game turn."""
    return iGameTurn / (12 * TURNS_PER_MONTH) + FIRST_YEAR

def getMonth(iGameTurn):
    """Returns the 1-based month # from the 0-based game turn."""
    return iGameTurn / TURNS_PER_MONTH + 1

def getWeek(iGameTurn):
    """Returns the 1-based week # from the 0-based game turn."""
    return iGameTurn % TURNS_PER_MONTH + 1
class CvModEvents(CvEventManager.CvEventManager):

tCityMap = (
)

class CityNameManager:

        def assignName(self, city):
                """Names a city depending on its plot"""
                if (iOwner < iNumMajorPlayers):
                        snowCover = tCityMap[67-city.getY()][city.getX()]

		if getWeek == 1
			if getMonth == 1:
			            snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
                                    if (snowCover != "10"):
                                              pPlot.setTerrainType(iSnow,True,True)
	                                      if iFeature == iForest:
					 	       pPlot.setFeatureType(iForest,2)
                                    elif (snowCover != "20"):
                                              pPlot.setTerrainType(iSnow,True,True)
	                                      if iFeature == iForest:
				                       pPlot.setFeatureType(iForest,2)
                                    elif (snowCover != "30"):
                                              pPlot.setTerrainType(iSnow,True,True)
			                      if iFeature == iForest:
						       pPlot.setFeatureType(iForest,2)								
		            elif getMonth == 2:
			            snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
                                    if (snowCover != "40"):
                                              pPlot.setTerrainType(iSnow,True,True)
			                      if iFeature == iForest:
						       pPlot.setFeatureType(iForest,2)
                                    elif (snowCover != "50"):
                                              pPlot.setTerrainType(iSnow,True,True)
				              if iFeature == iForest:
						       pPlot.setFeatureType(iForest,2)
                                    elif (snowCover != "60"):
                                              pPlot.setTerrainType(iSnow,True,True)
				              if iFeature == iForest:
						       pPlot.setFeatureType(iForest,2)

Also, I'm not very good with format, or any of this really... what do I need to do for the Class, and is the order of the stuff so far OK?

Thanks again
Kevin
 
Alright, I fixed this:

def assignName(self, city):
"""Names a city depending on its plot"""
if (iOwner < iNumMajorPlayers):
snowCover = tCityMap[67-city.getY()][city.getX()]

to what it should be which is: def snowCover(self, pplot) i think
then i took out the iOwner line, and in the next line replaced city with pPlot.

I also made sure to import my terrain constants (which I've already added) from a different python file. i took out the classes, i don't think they are needed

Is there anything I'm forgetting to import for changing the terrain of plots?
I stuck in a temporary map which should give Nova Scotia snow for most of the year, and it has no effect.

Kevin
 
Right, you need to call this function from somewhere. Also, whenever calling getMonth(), getYear(), etc you must pass in the game turn # inside parentheses. Parens () is what tell Python to treat the thing before them as a function to call.

Code:
iTurn = gc.getGame().getGameTurn()
iMonth = getMonth(iTurn)
iWeek = getWeek(iTurn)
if iWeek == 0:
    # first week of any month
    if iMonth = 8:
        # August
        ...

When you say you aren't good at formatting, do you mean when posting on the forums or when writing code for the game? If the latter, you need to practice this as Python uses indentation to determine what to do when. Whitespace is syntax in Python. if you're talking about the forum, just make sure to use
Code:
 tags around your code (use the # icon above the edit area).
 
Updated code:

Code:
from CvPythonExtensions import *
import sys
import Popup as PyPopup
from PyHelpers import PyPlayer
import pickle
import CvEventManager
from CvScreenEnums import *
from PyHelpers import *
import CvUtil
import CvTopCivs
import CvAdvisorUtils
import PyHelpers
import Consts as con

# globals
gc = CyGlobalContext()
localText = CyTranslator()

DefaultUnitAI = UnitAITypes.NO_UNITAI

iTundra = con.iTundra
iThinsoil = con.iThinsoil
iGrass = con.iGrass
iPlains = con.iPlains
iSnow = con.iSnow    
     
TURNS_PER_MONTH = 4
FIRST_YEAR = -4000

def getYear(iGameTurn):
    """Returns the calendar year from the 0-based game turn."""
    return iGameTurn / (12 * TURNS_PER_MONTH) + FIRST_YEAR

def getMonth(iGameTurn):
    """Returns the 1-based month # from the 0-based game turn."""
    return iGameTurn / TURNS_PER_MONTH + 1

def getWeek(iGameTurn):
    """Returns the 1-based week # from the 0-based game turn."""
    return iGameTurn % TURNS_PER_MONTH + 1

iTurn = gc.getGame().getGameTurn()
iMonth = getMonth(iTurn)
iWeek = getWeek(iTurn)

tSnowMap = (
*MAP HERE
)

def snowCover(self, pPlot):
		snowCover = tSnowMap[67-city.getY()][city.getX()]
		if (snowCover != "0"):
				pPlot.setTerrainType(snowCover, False)

				if iWeek == 1
						if iMonth == 1:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "10"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "20"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "30"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)								
						elif iMonth == 2:
								if (snowCover != "40"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "50"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
								elif (snowCover != "60"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
						elif iMonth == 3:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "70"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "80"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "90"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "100"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)	
						elif iMonth == 4:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "110"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "120"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "130"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "140"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)	
						elif iMonth == 6:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "110"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
								elif (snowCover != "120"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "130"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)		
								elif (snowCover != "140"):
										pPlot.setTerrainType(iPlains,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)											
						elif iMonth == 7:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "70"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "80"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "90"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)	
								elif (snowCover != "100"):
										pPlot.setTerrainType(iPlains,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)										
						elif iMonth == 8:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "40"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "50"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "60"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
						elif iMonth == 9:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "10"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "20"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "30"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)

I meant python formatting, as you saw I used the code feature in previous posts, however there was some spacing issues (in some cases i used spaces instead of tabs, and it took like half an hour per post to fix)

Also, there are now going to be a peak snow month and a least snow month, with 8 months in between, for a total of 10. But I doubt it matters caz I havent had to use the year helper.

Again it is not working, and I'm not sure if I should be using "pPlot"

Kevin
 
Assuming this is a single Python module (.py file), it doesn't really do anything.

First, you call getMonth() and getWeek() at the module level, and this code is called only once the first time the module is loaded. You need to put that code inside a function and then call that function from somewhere else (see below).

Second, you shouldn't define a variable (snowCover) inside a function of the same name. It will work, but it will be confusing. Also, since the function isn't defined inside a class, it should not have the "self" first parameter; just remove it.

You probably want to have this code run once each game turn. A good time to do this is from the BeginGameTurn event. You can modify CvEventManager's onBeginGameTurn() function and have it call your code's snowCover() function.

In the future, it will help to be more clear about how something isn't working. I assume nothing different happens; is this correct?
 
You're correct, there is no change.

Didn't understand what to do for the SnowCover part, so I left that unfixed for now, as you said it won't affect it

I know it's not right yet; I didn't know where to put the stuff you said was incorrectly placed in the module (getmonth, getweek). Is where I placed it inside the function/where it's supposed to go?

Anyways, here is the updated code:

Code:
from CvPythonExtensions import *
import sys
import Popup as PyPopup
from PyHelpers import PyPlayer
import pickle
import CvEventManager
from CvScreenEnums import *
from PyHelpers import *
import CvUtil
import CvTopCivs
import CvAdvisorUtils
import PyHelpers
import Consts as con

# globals
gc = CyGlobalContext()
localText = CyTranslator()

DefaultUnitAI = UnitAITypes.NO_UNITAI

iTundra = con.iTundra
iThinsoil = con.iThinsoil
iGrass = con.iGrass
iPlains = con.iPlains
iSnow = con.iSnow    
     
TURNS_PER_MONTH = 4
FIRST_YEAR = -4000

def getYear(iGameTurn):
    """Returns the calendar year from the 0-based game turn."""
    return iGameTurn / (12 * TURNS_PER_MONTH) + FIRST_YEAR

def getMonth(iGameTurn):
    """Returns the 1-based month # from the 0-based game turn."""
    return iGameTurn / TURNS_PER_MONTH + 1

def getWeek(iGameTurn):
    """Returns the 1-based week # from the 0-based game turn."""
    return iGameTurn % TURNS_PER_MONTH + 1

tSnowMap = (
*map inserted here*
)


def snowCover(pPlot):
		iTurn = gc.getGame().getGameTurn()
		iMonth = getMonth(iTurn)
		iWeek = getWeek(iTurn)
		snowCover = tSnowMap[67-city.getY()][city.getX()]
		if (snowCover != "0"):
				pPlot.setTerrainType(snowCover, False)

				if iWeek == 1
						if iMonth == 1:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "10"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "20"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "30"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)								
						elif iMonth == 2:
								if (snowCover != "40"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "50"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
								elif (snowCover != "60"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
						elif iMonth == 3:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "70"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "80"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "90"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "100"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)	
						elif iMonth == 4:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "110"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "120"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "130"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "140"):
										pPlot.setTerrainType(iSnow,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)	
						elif iMonth == 6:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "110"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
											pPlot.setFeatureType(iForest,2)
								elif (snowCover != "120"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "130"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)		
								elif (snowCover != "140"):
										pPlot.setTerrainType(iPlains,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)											
						elif iMonth == 7:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "70"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "80"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "90"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)	
								elif (snowCover != "100"):
										pPlot.setTerrainType(iPlains,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)										
						elif iMonth == 8:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "40"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "50"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "60"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
						elif iMonth == 9:
								snowCover = tCityMap[159-pPlot.getY()][pPlot.getX()]
								if (snowCover != "10"):
										pPlot.setTerrainType(iTundra,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,2)
								elif (snowCover != "20"):
										pPlot.setTerrainType(iThinsoil,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
								elif (snowCover != "30"):
										pPlot.setTerrainType(iGrass,True,True)
										if iFeature == iForest:
												pPlot.setFeatureType(iForest,1)
Code:
	def onBeginGameTurn(self, argsList):
		'Called at the beginning of the end of each turn'
		iGameTurn = argsList[0]
		CvTopCivs.CvTopCivs().turnChecker(iGameTurn)
		Wintermod2.snowCover(pPlot)

I am also not sure if I called the function properly in the EventManager.

However, I have already learned quite a bit just getting this far. Thanks for the help so far

Kevin
 
Hm...I haven't done a lot of stuff yet and very little of it in python, since I am much better with C++, but I suspect that you need to call this snowCover function which you wrote for each plot on the map; I don't think it is being used correctly in the EventManager. I am not sure on the exact syntax you need, but you can access the map through the global context variable; something like gc.getCyMap().plot(x, y) to get the plot at coordinates x, y. Call the snowCover function on each plot in the map using a nested loop of some sort.

~7thGate
 
Thanks 7thGate, I really appreciate the help.

The strange bit is, I don't call the function (snowcover) for every plot.

Let's say the map I want to play on is 4x4 tiles. The aim of the python file I made is to do something like this:

tSnowMap = (
(( "10", "0", "0", "0", ),
( "0", "20", "0", "0", ),
( "0", "0", "20", "0", ),
( "0", "0", "0", "0", )),
)

Every Game Turn, if it is time for a change (something like every four turns) then if month = 1 change all "10" tiles to snow. If month = 2 change all "20" tiles to snow. Of course, it is a lot more complicated than this, as it has to remember what the original tile was so it can change it back later, same with the trees, which become snow-covered during this simulated winter.

I think pPlot, which I used in the main code, does what your suggestion does, but I am not entirely sure.

Actually, I'd have to say I'm totally lost. All I know is what you are suggesting doesn't match the way I wrote the code. My function takes care of all plots, I presume/hope. I have a feeling that, other than mistakes in my maid code, the problem is that I did not call Snowcover properly in the events file.

Here is some fixed (I noticed quite a few mistakes) and simplified code.

Code:
from CvPythonExtensions import *
import sys
import Popup as PyPopup
from PyHelpers import PyPlayer
import pickle
import CvEventManager
from CvScreenEnums import *
from PyHelpers import *
import CvUtil
import CvTopCivs
import CvAdvisorUtils
import PyHelpers
import Consts as con

# globals
gc = CyGlobalContext()
localText = CyTranslator()

DefaultUnitAI = UnitAITypes.NO_UNITAI

iTundra = con.iTundra
iThinsoil = con.iThinsoil
iGrass = con.iGrass
iPlains = con.iPlains
iSnow = con.iSnow    
     
TURNS_PER_MONTH = 4
FIRST_YEAR = -4000

def getYear(iGameTurn):
    """Returns the calendar year from the 0-based game turn."""
    return iGameTurn / (12 * TURNS_PER_MONTH) + FIRST_YEAR

def getMonth(iGameTurn):
    """Returns the 1-based month # from the 0-based game turn."""
    return iGameTurn / TURNS_PER_MONTH + 1

def getWeek(iGameTurn):
    """Returns the 1-based week # from the 0-based game turn."""
    return iGameTurn % TURNS_PER_MONTH + 1

tSnowMap = (
*INSERT MAP HERE*
)

def snowCover(pPlot):
		iTurn = gc.getGame().getGameTurn()
		iMonth = getMonth(iTurn)
		iWeek = getWeek(iTurn)
		snowCover = tSnowMap[159-pPlot.getY()][pPlot.getX()]
		if iWeek == 1
				if iMonth == 1:
						if (snowCover != "10"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "20"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "30"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)								
				elif iMonth == 2:
						if (snowCover != "40"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "50"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "60"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
				elif iMonth == 3:
						if (snowCover != "70"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "80"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "90"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "100"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)	
				elif iMonth == 4:
						if (snowCover != "110"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "120"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "130"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "140"):
								pPlot.setTerrainType(iSnow,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)	
				elif iMonth == 6:
						if (snowCover != "110"):
								pPlot.setTerrainType(iTundra,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "120"):
								pPlot.setTerrainType(iThinsoil,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)
						elif (snowCover != "130"):
								pPlot.setTerrainType(iGrass,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)		
						elif (snowCover != "140"):
								pPlot.setTerrainType(iPlains,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)											
				elif iMonth == 7:
						if (snowCover != "70"):
								pPlot.setTerrainType(iTundra,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "80"):
								pPlot.setTerrainType(iThinsoil,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)
						elif (snowCover != "90"):
								pPlot.setTerrainType(iGrass,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)	
						elif (snowCover != "100"):
								pPlot.setTerrainType(iPlains,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)										
				elif iMonth == 8:
						if (snowCover != "40"):
								pPlot.setTerrainType(iTundra,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "50"):
								pPlot.setTerrainType(iThinsoil,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)
						elif (snowCover != "60"):
								pPlot.setTerrainType(iGrass,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)
				elif iMonth == 9:
						if (snowCover != "10"):
								pPlot.setTerrainType(iTundra,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,2)
						elif (snowCover != "20"):
								pPlot.setTerrainType(iThinsoil,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)
						elif (snowCover != "30"):
								pPlot.setTerrainType(iGrass,True,True)
								if iFeature == iForest:
										pPlot.setFeatureType(iForest,1)

The events part of the code is still the same, until I hear back from you/anyone on the topic.

Let me know, you/anyone, if you have any advice

Kevin
 
The snowCover function you wrote expects a single CyPlot object to be passed in to it. However, in the onBeginGameTurn() event handler, you don't provide a CyPlot to the function. Here is where you will need to loop over all plots in the map or all values in your tSnowMap data structure.

Your code needs to also inspect the CyPlot to determine the feature it has. Instead, you're just using iFeature like it has that value, but it doesn't. Search this forum for a thread I wrote about a year ago. I wrote code to do nearly exactly what you're trying to do. It will show you how to get the information you need.
 
I found and looked at your code, admittedly I'm very confused by it, because i know nothing about python.

I think at some point I am going to switch to the customeventmanager. Your code will probably be more useful to me (given my terrible understanding of python) once I switch to customeventmanager, where I can use your example more closely.

The feature problem should be easy to fix; I'm going to see if I can get everything else working before I get to that.

So, to loop it in the eventmanager, I say...
For each plot in all x
For each plot in all of y
WinterMod2.Snowcover (pPlot)

? (in simplified language)
Do i need anything else for that? Is that little part somewhat right?

Also, is it a problem that Snowcover doesn't return anything (I think)?

Kevin
 
Essentially that is correct. Use a CyMap()

Code:
map = CyMap()

to loop over all plots, calling snowCover() for each

Code:
for x in range(map.getWidth()):
    for y in range(map.getHeight()):
        plot = map.plot(x, y)
        WinterMod2.Snowcover(plot)

It is fine for a function not to return a value. In Python, that means the function actually returns the special value None which you can safely ignore.
 
I did the change you told me to do, as well as took out the "change forest" part, and tested it. I also tested your code, with and without the BUG mod. Neither of them had any effect (though I must say the BUG mod is quite nice :))

I am running the latest version of BTS.

Do you have any ideas of where to go from here? I think this could be very useful and adaptable (certainly I could make an excel file that would create the maps, adjustable for different map sizes)

Kevin
 
Post the errors you get when testing. They are found in the file Logs/PythonErr.log. Someone might be able to help you then.
 
I found a syntax error on the following:

for x in range(map.getWidth()):

I also get about a million errors saying it can't find the module CvEventInterface. I will try modifying and using the one from your code.

Also, although your mod displays fine because you have all the files, whenever I play BTS there is NO interface, NO popups, and not much i can do. Consequently, I do not get python popups, and I don't even know if the game itself is working properly or how to fix this. Some files must have disappeared. Once I've cleaned up my computer I'll probably reinstall, though on my computer this may be a lengthy process.

Anyways please let me know what went wrong with the syntax, and we'll see how it goes.

EDIT: your code produces no error, but appears to have no effect
 
Ah, it's getGridWidth() and getGridHeight(). You can look up other functions in the Civ4 Python API. The errors regarding CvEventInterface generally happen once an error happens and Civ4 gets in a borked state. Look for the first stack trace and fix that problem, then retest to find the next problem.

Regarding BUG, are you saying that it doesn't work at all now? How did you install it (EXE or ZIP)? Did you use Standard or Mod install? What version? You can post a question in the BUG forum to keep from hijacking your own thread. ;)
 
SPOILER]
map = CyMap()
for x in range(map.getGridWidth()):
for y in range(map.getGridHeight()):
plot = map.plot(x, y)
WinterMod2.Snowcover(plot)
[/SPOILER]

Syntax error on the same line still.

Also, i downloaded the API; it should really help me figure future coding out, and I kind of get how the functions work.

What I meant by the really buggy interface was it happens whenever I'm NOT using BUG. So that's definitely a good thing; I must be missing files and probably have to reinstall civ at some point. But the code you posted in the other thread, though displaying no errors, appears to have no effect.

And I must say BAT is pretty nice :goodjob:
 
What's the error you get now? It should be in Logs/PythonErr.log.

When posting code, use the CODE tags (not SPOILER) with the # button. This will maintain the indentation and other formatting.
 
Top Bottom