need python help, please

hrochland

Prince
Joined
Apr 9, 2006
Messages
2,414
Location
Czech Kingdom
Hi all
please, friend wrote this code for me for place monster on map (event)
problem is that monster is in first turn placed but in second turn is away
can someone check this code where is error, please?

Code:
######## SEATURTLE ###########

def canTriggerSeaTurtle(argsList):

	kTriggeredData = argsList[0]
	player = gc.getPlayer(kTriggeredData.ePlayer)

#   If Barbarians are disabled in this game, this event will not occur.
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_BARBARIANS):
		return false

#   At least one civ on the board must know Sailing.
	bFoundValid = false
	iTech = CvUtil.findInfoTypeNum(gc.getTechInfo, gc.getNumTechInfos(), 'TECH_SAILING')
	for iPlayer in range(gc.getMAX_CIV_PLAYERS()):			
		loopPlayer = gc.getPlayer(iPlayer)
		if loopPlayer.isAlive():
			if gc.getTeam(loopPlayer.getTeam()).isHasTech(iTech):
				bFoundValid = true
				break

	if not bFoundValid:
		return false

	# Can we build the counter unit?		
	iCounterUnitClass = CvUtil.findInfoTypeNum(gc.getUnitClassInfo, gc.getNumUnitClassInfos(), 'UNITCLASS_GALLEY')
	iCounterUnit = gc.getCivilizationInfo(player.getCivilizationType()).getCivilizationUnits(iCounterUnitClass)
	if iCounterUnit == -1:
		return false

	(loopCity, iter) = player.firstCity(false)
	bFound = false
	while(loopCity):
		if (loopCity.canTrain(iCounterUnit, false, false)):
			bFound = true
			break
				
		(loopCity, iter) = player.nextCity(iter, false)
		
	if not bFound:
		return false

#	Find an eligible plot
	map = gc.getMap()
	for i in range(map.numPlots()):
		plot = map.plotByIndex(i)
		if (plot.getOwner() == -1 and plot.isWater() and not plot.isImpassable() and not plot.getNumUnits() > 0 and not plot.isLake() and plot.isAdjacentPlayer(kTriggeredData.ePlayer, true)):
			return true

	return false


def getHelpSeaTurtle1(argsList):
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	
	szHelp = localText.getText("TXT_KEY_EVENT_SEATURTLE_HELP_1", ())	

	return szHelp


def applySeaTurtle1(argsList):
	iEvent = argsList[0]
	kTriggeredData = argsList[1]

	listPlots = []
	map = gc.getMap()
	for i in range(map.numPlots()):
		plot = map.plotByIndex(i)
		if (plot.getOwner() == -1 and plot.isWater() and not plot.isImpassable() and not plot.getNumUnits() > 0 and not plot.isLake() and plot.isAdjacentPlayer(kTriggeredData.ePlayer, true)):
			listPlots.append(i)

	if 0 == len(listPlots):
		return

	plot = map.plotByIndex(listPlots[gc.getGame().getSorenRandNum(len(listPlots), "SeaTurtle event location")])

	iUnitSeaTurtle = CvUtil.findInfoTypeNum(gc.getUnitInfo, gc.getNumUnitInfos(), 'UNIT_SEATURTLE')

	barbPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
	barbPlayer.initUnit(iUnitSeaTurtle, plot.getX(), plot.getY(), UnitAITypes.UNITAI_ATTACK_SEA, DirectionTypes.NO_DIRECTION)

many thanks for help
HROCHland
 
You said that the monster actually appears, so most of the code should be right: the choice of the location, the unit type, the likelihood of the event, they all work fine.
Maybe there's an issue with the 'initUnit' call (something like, the unit is created, but some odd flag makes it disappear the next turn).
The only thing that differs from how I usually use the 'initUnit' is the DIRECTION parameter. I usually set a default direction, I don't know what can happen if you set NoDirection. Try using something like DirectionTypes.DIRECTION_SOUTH.
 
Unfortunately, I´m not programer. I can´t edit code. :(

I can somebody find error, write me, please
thanks
Hrochland
 
Umm, if the seaturtle is not allowed to move into ocean squares, and it spawns on an ocean sqaure, it will die at the end of the turn. Could that be it?
 
I think if the turtle in the CIV4UnitInfos.xml has this:

<TerrainImpassables>
------><TerrainImpassable>
------------><TerrainType>TERRAIN_OCEAN</TerrainType>
------------><bTerrainImpassable>1</bTerrainImpassable>
------></TerrainImpassable>
</TerrainImpassables>

Then I think it will disappear at the end of the turn. If you want it to just stay at the coast, then you should set it to spawn only on coastal tiles, and not ocean ones. I don't know, however, if Python supports something like isCoastal...?
 
Top Bottom