OrionVeteran
Deity
I have an Ice Breaker unit that can move on impassable terrain and remove ice. I want to move the Ice Breaker to a plot with ice (as opposed to snow, which is a land plot). I have a function that does a search for nearby plots within a specified range.
I want to move the Ice Breaker unit to an ice plot, but the code fails to progress past the red line (near the end of the code), which is crucial to the success of this function.
Please note that my test game has a qualified plot just 3 plots away from an Ice Breaker unit. How can I fix this?
Spoiler :
Code:
def doIceBreakerPlacement(pUnit):
# Orion's Icebreaker Mod
# 1. Moves Icebreaker to unowned plots, within range of 10 plots.
# 2. If it finds ice next to land, it moves the Icebreaker to that plot.
iOwner = pUnit.getOwner()
FoundTargetIcePlot = False
pUnitPlot = CyMap().plot(pUnit.getX(), pUnit.getY())
iPlotOwner = pUnitPlot.getOwner()
iBreakIce = gc.getInfoTypeForString("BUILD_BREAK_ICE")
iFeatureIce = gc.getInfoTypeForString("FEATURE_ICE")
if pUnitPlot.isCity():
# Kick the naval unit out of the city
StandardFunctions.kickNavalUnitOutOfCity(pUnit)
if not pUnitPlot.isCity():
# water plot must be owned by player or by nobody
if iPlotOwner == iOwner or iPlotOwner == -1:
# Make sure the water plot is next to land
if pUnitPlot.isAdjacentToLand():
# plot must have ice
if pUnitPlot.getFeatureType() == gc.getInfoTypeForString("FEATURE_ICE"): #CyInterface().addImmediateMessage("A", "")
# Break the Ice
pUnit.getGroup().pushMission(MissionTypes.MISSION_BUILD, iBreakIce, -1, 0, True, False, MissionAITypes.NO_MISSIONAI, pUnitPlot, pUnit)
# No Ice on plot
else:
# Find plot to move Ice Breaker
for iPlotLoop in range(CyMap().numPlots()):
pLoopPlot = CyMap().plotByIndex(iPlotLoop)
# find shortest path between the source plot and the destination plot.
# ******* Ice Breaker must be on a water plot for the calculatePathDistance command to work
iPlotDistance = CyMap().calculatePathDistance(pUnitPlot, pLoopPlot)
if iPlotDistance in range(1, 10):
# Find a water plot
if pLoopPlot.isWater():
ipLoopPlotOwner = pLoopPlot.getOwner()
# water plot must be owned by player or by nobody
if ipLoopPlotOwner == iOwner or ipLoopPlotOwner == -1:
CyInterface().addImmediateMessage("A", "")
# Make sure the water plot is next to land
if pLoopPlot.isAdjacentToLand():
# plot must have ice
CyInterface().addImmediateMessage("B", "")
[COLOR="Red"][B]if pLoopPlot.getFeatureType() == gc.getInfoTypeForString("FEATURE_ICE"):[/B][/COLOR] #if pLoopPlot.getFeatureType() == iFeatureIce:
CyInterface().addImmediateMessage("C", "")
FoundTargetIcePlot = True
TargetIcePlot = pLoopPlot
break
if FoundTargetIcePlot:
CyInterface().addImmediateMessage("D", "")
pUnit.getGroup().pushMission(MissionTypes.MISSION_MOVE_TO, TargetIcePlot.getX(), TargetIcePlot.getY(), 0, False, True, MissionAITypes.NO_MISSIONAI, pUnitPlot, pUnit)
CyMap().resetPathDistance()
I want to move the Ice Breaker unit to an ice plot, but the code fails to progress past the red line (near the end of the code), which is crucial to the success of this function.
