xienwolf
Deity
Garfield and Friends reference you mean? Didn't even know there was such a Pokemon, but I am pretty sure Garfield and Friends came first.
def unitCannotMoveInto(self,argsList):
ePlayer = argsList[0]
iUnitId = argsList[1]
iPlotX = argsList[2]
iPlotY = argsList[3]
return False
<Define>
<DefineName>USE_UNIT_CANNOT_MOVE_INTO_CALLBACK</DefineName>
<iDefineIntVal>0</iDefineIntVal>
</Define>
Though it may be better to use Kael's new tags for 0.33 to make individual Tiles become Python Active. As then you avoid doing a python check for every move of every unit.
for i in range (CyMap().numPlots()):
pPlot = CyMap().plotByIndex(i)
if pPlot.getFeatureType() == iSC1:
for i in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
if...
def getMovesLeft(pUnit):
return (pUnit.movesLeft() / gc.getMOVE_DENOMINATOR())
if pUnit.getMovesLeft() == 1:
self.addPopup(CyTranslator().getText("TXT_KEY_POPUP_MOVECHECK",()))
Okay everyone -- here is a challenge for you:
def get_connected_plots( x,y, connectivity_list=[(0,1),(0,-1),(1,0),(-1,0)] ):
open_plots = set([(x,y)])
connected_plots = []
closed_plots = set()
get_map_plot = CvPythonExtensions.CyMap().plot
iTerrain = get_map_plot( x,y ).getTerrainType()
while open_plots:
x,y = open_plots.pop()
pPlot = get_map_plot(x,y)
if not pPlot.isNone() and iTerrain == pPlot.getTerrainType():
connected_plots.append( (x,y) )
closed_plots.add( (x,y) )
for x_offset, y_offset in connectivity_list:
near_plot = (x+x_offset, y+y_offset)
if near_plot not in closed_plots:
open_plots.add( near_plot )
return connected_plots
def spellSaveMappy():
aaiStarbaseList = []
iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
iCoast = gc.getInfoTypeForString('TERRAIN_COAST')
iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
iBorder = gc.getInfoTypeForString('TERRAIN_BORDER')
for i in range (CyMap().numPlots()):
pPlot = CyMap().plotByIndex(i)
iClimate = 0
if pPlot.getTerrainType() == iCoast:
iClimate = 10
if pPlot.getTerrainType() == iGrass:
iClimate = 20
if pPlot.getTerrainType() == iPlains:
iClimate = 30
if pPlot.getTerrainType() == iDesert:
iClimate = 40
if pPlot.getTerrainType() == iTundra:
iClimate = 50
if pPlot.getTerrainType() == iSnow:
iClimate = 60
if pPlot.getTerrainType() == iBorder:
iClimate = 70
aaiStarbaseList.append([pPlot, iClimate])
# aScriptData = str(iClimate)
# pPlot.setScriptData(pickle.dumps(aScriptData))
pickle.dump(aaiStarbaseList,mapfile)
def spellLoadMappy():
caster=CyInterface().getHeadSelectedUnit()
iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
iCoast = gc.getInfoTypeForString('TERRAIN_COAST')
iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
iBorder = gc.getInfoTypeForString('TERRAIN_BORDER')
aaiStarbaseList = [pickle.load(mapfile)]
for iStarbaseLoop in range(len(aaiStarbaseList)):
pPlot = (aaiStarbaseList[iStarbaseLoop][0])
iClimate = (aaiStarbaseList[iStarbaseLoop][1])
# for i in range (CyMap().numPlots()):
# pPlot = CyMap().plotByIndex(i)
# iClimate = int[aaiStarbaseList]
if iClimate == 0:
pPlot.setTerrainType(iOcean,True,True)
if iClimate == 10:
pPlot.setTerrainType(iCoast,True,True)
if iClimate == 20:
pPlot.setTerrainType(iGrass,True,True)
if iClimate == 30:
pPlot.setTerrainType(iPlains,True,True)
if iClimate == 40:
pPlot.setTerrainType(iDesert,True,True)
if iClimate == 50:
pPlot.setTerrainType(iTundra,True,True)
if iClimate == 60:
pPlot.setTerrainType(iSnow,True,True)
if iClimate == 70:
pPlot.setTerrainType(iBorder,True,True)
3.14.4 What can be pickled and unpickled?
The following types can be pickled:
- None, True, and False
- integers, long integers, floating point numbers, complex numbers
- normal and Unicode strings
- tuples, lists, sets, and dictionaries containing only picklable objects
- functions defined at the top level of a module
- built-in functions defined at the top level of a module
- classes that are defined at the top level of a module
- instances of such classes whose __dict__ or __setstate__() is picklable
import SdToolKit
terrainMapping = {}
terrainMapping[gc.getInfoTypeForString('TERRAIN_OCEAN')] = 0
terrainMapping[gc.getInfoTypeForString('TERRAIN_COAST')] = 10
terrainMapping[gc.getInfoTypeForString('TERRAIN_GRASS')] = 20
terrainMapping[gc.getInfoTypeForString('TERRAIN_PLAINS')] = 30
terrainMapping[gc.getInfoTypeForString('TERRAIN_DESERT')] = 40
terrainMapping[gc.getInfoTypeForString('TERRAIN_TUNDRA')] = 50
terrainMapping[gc.getInfoTypeForString('TERRAIN_SNOW')] = 60
terrainMapping[gc.getInfoTypeForString('TERRAIN_BORDER')] = 70
def spellSaveMappy():
climateList = []
cyMap = CyMap()
for i in xrange( cyMap.numPlots() ):
pPlot = cyMap.plotByIndex(i)
iTerrain = pPlot.getTerrainType()
iClimate = terrainMapping[iTerrain]
climateList.append( iClimate )
SdToolKit.sdSetGlobal('DungeonAdventure', 'SavedMap', climateList )
def spellLoadMappy():
climateList = SdToolKit.sdGetGlobal('DungeonAdventure', 'SavedMap' )
if climateList is not None: # Apparently SdToolKit.sdGetGlobal returns None if it can't find the variable.
cyMap = CyMap()
reversedTerrainMapping = dict( (value, key) for key, value in terrainMapping.iteritems() )
for index, iClimate in enumerate( climateList ):
pPlot = cyMap.plotByIndex( index )
pPlot.setTerrainType(reversedTerrainMapping[iClimate],True,True)
else:
pass # Replace with whatever should be done about there being no map to load.
def spellExchangeTerrain( x, y ):
oldTerrains = []
cyMap = CyMap()
offsets = [(tx, ty) for tx in xrange(-1,2) for ty in xrange(-1,2)]
for x_offset,y_offset in offsets:
pPlot = cyMap.plot( x+x_offset, y+y_offset )
if not pPlot.isNone():
iTerrain = pPlot.getTerrainType()
oldTerrains.append( ( x_offset,y_offset, iTerrain ) )
newTerrains = SdToolKit.sdGetGlobal('DungeonAdventure', 'ExchangeTerrain' )
SdToolKit.sdSetGlobal('DungeonAdventure', 'ExchangeTerrain', oldTerrains )
if newTerrains:
for x_offset,y_offset, iTerrain in newTerrains:
pPlot = cyMap.plot( x+x_offset, y+y_offset )
pPlot.setTerrainType( iTerrain, True, True )