def doPlaceDeepOcean():
	iNumMapPlots = gc.getMap().numPlots()
	#iDirectionTypes = DirectionTypes.NUM_DIRECTION_TYPES
	iCoast = gc.getInfoTypeForString("TERRAIN_COAST")
	iOcean = gc.getInfoTypeForString("TERRAIN_OCEAN")
	iDeepOcean = gc.getInfoTypeForString("TERRAIN_DEEP_OCEAN")
	iRange = 2

	for i in xrange(iNumMapPlots):
		pPlot = gc.getMap().plotByIndex(i)
		if pPlot and not pPlot.isNone() and pPlot.getTerrainType() == iOcean:
			iX = pPlot.getX()
			iY = pPlot.getY()
			bSet = True
			for x in xrange(-iRange, iRange+1):
				for y in xrange(-iRange, iRange+1):
					pLoopPlot = plotXY(iX, iY, x, y)
					if not pLoopPlot or pLoopPlot.isNone():
						continue
					if pLoopPlot.getTerrainType() == iCoast:
						bSet = False
						break
				if not bSet:
					break

			if bSet:
				# VOID setTerrainType (TerrainType eNewValue, BOOL bRecalculate, BOOL bRebuildGraphics)

				bRebuildGraphics = (iX == 3 or iX % 6 == 0) and (iY == 3 or iY % 6 == 0)

				pPlot.setTerrainType(iDeepOcean, False, bRebuildGraphics)
def doMoveGrasshoppers(pPlot):

	# Am Plot bleiben 2:3
	if CvUtil.myRandom(3, "doMoveGrasshoppers") != 0:
		return

	iFeatGrasshopper = gc.getInfoTypeForString("FEATURE_GRASSHOPPER")
	lPlots = []
	# Umkreis checken
	iRange = 1
	for x in xrange(-iRange, iRange+1):
		for y in xrange(-iRange, iRange+1):
			loopPlot = plotXY(pPlot.getX(), pPlot.getY(), x, y)
			if loopPlot and not loopPlot.isNone():
				if loopPlot.getFeatureType() == -1:
					if not loopPlot.isWater() and not loopPlot.isPeak():
						lPlots.append(loopPlot)

	if lPlots:
		iRand = CvUtil.myRandom(len(lPlots), "doMoveGrasshoppers")
		# Heuschrecken vom alten Plot entfernen
		pPlot.setFeatureType(-1, 0)
		# Heuschrecken auf dem neuen Plot erzeugen
		lPlots[iRand].setFeatureType(iFeatGrasshopper, 0)
		# Farmen auf dem neuen Plot vernichten (ausgenommen Weiden)
		if lPlots[iRand].getImprovementType() != gc.getInfoTypeForString("IMPROVEMENT_PASTURE") \
		   and lPlots[iRand].getImprovementType() in L.LFarms:
			lPlots[iRand].setImprovementType(-1)
Example #3
0
def checkNearbyUnits(pPlot, iRange):
    iX = pPlot.getX()
    iY = pPlot.getY()
    for x in xrange(-iRange, iRange + 1):
        for y in xrange(-iRange, iRange + 1):
            loopPlot = plotXY(iX, iY, x, y)
            if loopPlot.getNumUnits() > 0:
                return True
    return False
Example #4
0
def countNearbyUnits(pPlot, iRange, iPlayer):
    iAnz = 0
    iX = pPlot.getX()
    iY = pPlot.getY()
    for x in xrange(-iRange, iRange + 1):
        for y in xrange(-iRange, iRange + 1):
            loopPlot = plotXY(iX, iY, x, y)
            if loopPlot.getNumUnits() > 0 and loopPlot.getUnit(
                    0).getOwner() == iPlayer:
                iAnz += loopPlot.getNumUnits()
    return iAnz
def doMoveDesertStorm(lDesertStorm):
	iFeatDesertstorm = gc.getInfoTypeForString("FEATURE_FALLOUT")
	iTerrainDesert = gc.getInfoTypeForString("TERRAIN_DESERT")
	#iDarkIce = gc.getInfoTypeForString("FEATURE_DARK_ICE")

	lImprovements = [
		gc.getInfoTypeForString("IMPROVEMENT_FORT"),
		gc.getInfoTypeForString("IMPROVEMENT_FORT2"),
		gc.getInfoTypeForString("IMPROVEMENT_TURM2"),
		gc.getInfoTypeForString("IMPROVEMENT_MINE")
	]

	# Wegen Wind von West nach Ost, die Reihenfolge der Plot-Liste umkehren
	lDesertStorm.reverse()

	for p in lDesertStorm:
		loopPlot = plotXY(p.getX(), p.getY(), 2, 0) # 2-Plot-Schritte nach Osten
		if loopPlot and not loopPlot.isNone():
			if loopPlot.getTerrainType() == iTerrainDesert:
				if loopPlot.getFeatureType() == -1:
					if not loopPlot.isPeak():
						bMeldung = False
						# Entferne Modernisierung 1:3
						if loopPlot.getImprovementType() not in lImprovements:
							if CvUtil.myRandom(3, "doDestroyImprovementDueToDesertStorm") == 1:
								loopPlot.setImprovementType(-1)
								bMeldung = True
						# Entferne Strasse 1:3
						if loopPlot.getRouteType() == 0 and not loopPlot.isCity():
							if CvUtil.myRandom(3, "doDestroyRouteDueToDesertStorm") == 1:
								loopPlot.setRouteType(-1)
								bMeldung = True
						# Sandsturm setzen
						loopPlot.setFeatureType(iFeatDesertstorm, 0)
						# Meldung an den Spieler
						if bMeldung and loopPlot.getOwner() != -1:
							if gc.getPlayer(loopPlot.getOwner()).isHuman():
								CyInterface().addMessage(gc.getPlayer(loopPlot.getOwner()).getID(), True, 12, CyTranslator().getText("TXT_KEY_DISASTER_DESERTSTORM", ("", )), None, 2, gc.getFeatureInfo(iFeatDesertstorm).getButton(), ColorTypes(7), loopPlot.getX(), loopPlot.getY(), True, True)
		# Sandsturm entfernen (vorheriger Plot)
		p.setFeatureType(-1, 0)
def doSeewind():
	terr_ocean = gc.getInfoTypeForString("TERRAIN_OCEAN")
	terr_ocean2 = gc.getInfoTypeForString("TERRAIN_DEEP_OCEAN")
	feat_ice = gc.getInfoTypeForString("FEATURE_ICE")

	iNumDirection = min(DirectionTypes.NUM_DIRECTION_TYPES, len(L.LSeewind)) # should both be 8
	iWindplots = 6 # amount of wind arrows (plots) per wind
	iDarkIce = gc.getInfoTypeForString("FEATURE_DARK_ICE")

	iMapW = gc.getMap().getGridWidth()
	iMapH = gc.getMap().getGridHeight()
	# get all ocean plots
	OceanPlots = []
	for i in xrange(iMapW):
		for j in xrange(iMapH):
			loopPlot = gc.getMap().plot(i, j)
			if loopPlot and not loopPlot.isNone():
				if loopPlot.getTerrainType() == terr_ocean or loopPlot.getTerrainType() == terr_ocean2:
					if loopPlot.getFeatureType() != feat_ice and loopPlot.getFeatureType() != iDarkIce:
						OceanPlots.append(loopPlot)

	if not OceanPlots:
		return
	#  0 = WORLDSIZE_DUEL
	#  1 = WORLDSIZE_TINY
	#  2 = WORLDSIZE_SMALL
	#  3 = WORLDSIZE_STANDARD
	#  4 = WORLDSIZE_LARGE
	#  5 = WORLDSIZE_HUGE
	iMaxEffects = (gc.getMap().getWorldSize() + 1) * 2
	for i in xrange(iMaxEffects):
		# get first ocean plot
		iRand = CvUtil.myRandom(len(OceanPlots), "doSeewind1")
		loopPlot = OceanPlots[iRand]
		# First direction
		iDirection = CvUtil.myRandom(iNumDirection, "doSeewind2")

		# Start Windplots
		for j in xrange(iWindplots):
			if loopPlot and not loopPlot.isNone():
				if loopPlot.getFeatureType() == iDarkIce:
					continue
				# Flunky: disabled, because already checked
				# if loopPlot.getFeatureType() != feat_ice and (loopPlot.getTerrainType() == terr_ocean or loopPlot.getTerrainType() == terr_ocean2):
					# Im Umkreis von 5 soll kein weiteres Windfeature sein
				bSet = True
				iRange = 2
				for x in xrange(-iRange, iRange+1):
					for y in xrange(-iRange, iRange+1):
						pPlot2 = plotXY(loopPlot.getX(), loopPlot.getY(), x, y)
						if pPlot2.getFeatureType() in L.LSeewind:
							bSet = False
							break
					if not bSet:
						break

				if bSet:
					CvUtil.pyPrint(u'Seewind %d was selected of %d possibilities' %(iDirection, len(L.LSeewind)))
					loopPlot.setFeatureType(L.LSeewind[iDirection], 0)
					iDirection = (iDirection + CvUtil.myRandom(3, "doSeewind3") - 1) % iNumDirection
					loopPlot = plotDirection(loopPlot.getX(), loopPlot.getY(), DirectionTypes(iDirection))
				else:
					break
def setGoodies(eImprovement,eNum, plots):
	impBarbFort = gc.getInfoTypeForString("IMPROVEMENT_BARBARENFORT")
	impCave = gc.getInfoTypeForString("IMPROVEMENT_CAVE")
	impGoody = gc.getInfoTypeForString("IMPROVEMENT_GOODY_HUT")

	lGoodies = [impBarbFort,impCave,impGoody]

	#  0 = WORLDSIZE_DUEL
	#  1 = WORLDSIZE_TINY
	#  2 = WORLDSIZE_SMALL
	#  3 = WORLDSIZE_STANDARD
	#  4 = WORLDSIZE_LARGE
	#  5 = WORLDSIZE_HUGE
	iMapSize = gc.getMap().getWorldSize() * 3
	iAnz = iMapSize + 1 - eNum
	if iAnz <= 0:
		return

	i = 0
	while i < iAnz:
		bIgnore = False

		if not plots:
			return

		iRand = CvUtil.myRandom(len(plots), "setBarbFortsOrCavesOrGoodyHuts")
		plot = plots[iRand]

		#CyInterface().addMessage(gc.getGame().getActivePlayer(), True, 15, CyTranslator().getText("TXT_KEY_MESSAGE_TEST", ("setGoodies",len(plots))), None, 2, None, ColorTypes(11), 0, 0, False, False)

		# Umkreis checken
		iRange = 3
		for x in xrange(-iRange, iRange+1):
			for y in xrange(-iRange, iRange+1):
				loopPlot = plotXY(plot.getX(), plot.getY(), x, y)
				if loopPlot and not loopPlot.isNone():
					if loopPlot.getImprovementType() in lGoodies or loopPlot.getOwner() != -1:
						bIgnore = True
						# Umkreis des gefundenen Plots aus der Plotliste entfernen
						for x2 in xrange(-iRange, iRange+1):
							for y2 in xrange(-iRange, iRange+1):
								loopPlot = plotXY(plot.getX(), plot.getY(), x2, y2)
								if loopPlot and not loopPlot.isNone():
									if loopPlot in plots:
										plots.remove(loopPlot)
						break
			if bIgnore:
				break

		i += 1

		if bIgnore:
			continue

		# Improvement setzen
		plot.setImprovementType(eImprovement)

		# Einheit in die Festung setzen
		if eImprovement == impBarbFort:
			PAE_Barbaren.setFortDefence(plot)
		# Einheit in die Cave setzen
		elif eImprovement == impCave:
			setUnitIntoCave(plot)

		# Alle Plots im Umkreis von 4 Feldern aus der Liste entfernen
		iRange = 4
		for x in xrange(-iRange, iRange+1):
			for y in xrange(-iRange, iRange+1):
				loopPlot = plotXY(plot.getX(), plot.getY(), x, y)
				if loopPlot and not loopPlot.isNone():
					if loopPlot in plots:
						plots.remove(loopPlot)
	return