def handleInput(self, inputClass): screen = CyGInterfaceScreen("WBPlotScreen", CvScreenEnums.WB_PLOT) global bAdd global bSensibility global iEditType global iChange global iCulturePlayer global iSelectedClass if inputClass.getFunctionName() == "ChangeBy": iChange = screen.getPullDownData("ChangeBy", screen.getSelectedPullDownID("ChangeBy")) elif inputClass.getFunctionName() == "CurrentPlayer": iIndex = screen.getPullDownData("CurrentPlayer", screen.getSelectedPullDownID("CurrentPlayer")) pPlot.setOwner(iIndex) elif inputClass.getFunctionName() == "ChangeType": bAdd = screen.getPullDownData("ChangeType", screen.getSelectedPullDownID("ChangeType")) elif inputClass.getFunctionName() == "EditType": iEditType = screen.getPullDownData("EditType", screen.getSelectedPullDownID("EditType")) elif inputClass.getFunctionName() == "CurrentPage": iIndex = screen.getPullDownData("CurrentPage", screen.getSelectedPullDownID("CurrentPage")) if iIndex == 1: WBEventScreen.WBEventScreen().interfaceScreen(pPlot) elif iIndex == 2: if pPlot.getOwner() != -1: WBPlayerScreen.WBPlayerScreen().interfaceScreen(pPlot.getOwner()) elif iIndex == 3: WBTeamScreen.WBTeamScreen().interfaceScreen(pPlot.getTeam()) elif iIndex == 4: if pPlot.isCity(): WBCityEditScreen.WBCityEditScreen().interfaceScreen(pPlot.getPlotCity()) elif iIndex == 5: pUnit = pPlot.getUnit(0) if pUnit: WBUnitScreen.WBUnitScreen(CvPlatyBuilderScreen.CvWorldBuilderScreen()).interfaceScreen(pUnit) elif iIndex == 11: iPlayer = pPlot.getOwner() if iPlayer == -1: iPlayer = CyGame().getActivePlayer() WBInfoScreen.WBInfoScreen().interfaceScreen(iPlayer) if iIndex == 12: WBRiverScreen.WBRiverScreen().interfaceScreen(pPlot) elif inputClass.getFunctionName() == "NextPlotUpButton": pNewPlot = CyMap().plot(pPlot.getX(), pPlot.getY() + 1) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotDownButton": pNewPlot = CyMap().plot(pPlot.getX(), pPlot.getY() - 1) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotLeftButton": pNewPlot = CyMap().plot(pPlot.getX() - 1, pPlot.getY()) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotRightButton": pNewPlot = CyMap().plot(pPlot.getX() + 1, pPlot.getY()) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName().find("BaseYield") > -1: i = YieldTypes(inputClass.getData2()) if inputClass.getData1() == 1030: CyGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), i, iChange) elif inputClass.getData1() == 1031: iYield = pPlot.getYield(i) iImprovement = pPlot.getImprovementType() if iImprovement > -1: iYield -= pPlot.calculateImprovementYieldChange(iImprovement, i, pPlot.getOwner(), False) CyGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), i, - min(iChange, iYield)) self.placeStats() elif inputClass.getFunctionName() == "RiverWestAButton": pWestPlot = CyMap().plot(pPlot.getX() - 1, pPlot.getY()) pWestPlot.setWOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_NORTH) self.placeStats() elif inputClass.getFunctionName() == "RiverWestBButton": pWestPlot = CyMap().plot(pPlot.getX() - 1, pPlot.getY()) pWestPlot.setWOfRiver(False, CardinalDirectionTypes.NO_CARDINALDIRECTION) self.placeStats() elif inputClass.getFunctionName() == "RiverWestCButton": pWestPlot = CyMap().plot(pPlot.getX() - 1, pPlot.getY()) pWestPlot.setWOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_SOUTH) self.placeStats() elif inputClass.getFunctionName() == "RiverEastAButton": pPlot.setWOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_NORTH) self.placeStats() elif inputClass.getFunctionName() == "RiverEastBButton": pPlot.setWOfRiver(False, CardinalDirectionTypes.NO_CARDINALDIRECTION) self.placeStats() elif inputClass.getFunctionName() == "RiverEastCButton": pPlot.setWOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_SOUTH) self.placeStats() elif inputClass.getFunctionName() == "RiverNorthAButton": pNorthPlot = CyMap().plot(pPlot.getX(), pPlot.getY() + 1) pNorthPlot.setNOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_WEST) self.placeStats() elif inputClass.getFunctionName() == "RiverNorthBButton": pNorthPlot = CyMap().plot(pPlot.getX(), pPlot.getY() + 1) pNorthPlot.setNOfRiver(False, CardinalDirectionTypes.NO_CARDINALDIRECTION) self.placeStats() elif inputClass.getFunctionName() == "RiverNorthCButton": pNorthPlot = CyMap().plot(pPlot.getX(), pPlot.getY() + 1) pNorthPlot.setNOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_EAST) self.placeStats() elif inputClass.getFunctionName() == "RiverSouthAButton": pPlot.setNOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_WEST) self.placeStats() elif inputClass.getFunctionName() == "RiverSouthBButton": pPlot.setNOfRiver(False, CardinalDirectionTypes.NO_CARDINALDIRECTION) self.placeStats() elif inputClass.getFunctionName() == "RiverSouthCButton": pPlot.setNOfRiver(True, CardinalDirectionTypes.CARDINALDIRECTION_EAST) self.placeStats() elif inputClass.getFunctionName() == "WBSigns": if inputClass.getData1() == 7876 or inputClass.getData1() == 7872: iCulturePlayer = inputClass.getData2() /10000 self.placeSigns() elif inputClass.getFunctionName().find("EditCulture") > -1: if inputClass.getData1() == 1030: pPlot.changeCulture(iCulturePlayer, iChange, True) elif inputClass.getData1() == 1031: pPlot.changeCulture(iCulturePlayer, -min(iChange, pPlot.getCulture(iCulturePlayer)), True) self.interfaceScreen(pPlot) elif inputClass.getFunctionName() == "WBPlotType": if iEditType == 0: pPlot.setPlotType(PlotTypes(inputClass.getData()), True, True) elif iEditType == 1: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if pLoopPlot.getArea() == pPlot.getArea(): pLoopPlot.setPlotType(PlotTypes(inputClass.getData()), True, True) else: CyMap().setAllPlotTypes(PlotTypes(inputClass.getData())) self.interfaceScreen(pPlot) elif inputClass.getFunctionName() == "WBPlotTerrain": iTerrain = inputClass.getData2() if iEditType == 0: pPlot.setTerrainType(iTerrain, True, True) else: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if iEditType == 1: if pLoopPlot.getArea() == pPlot.getArea(): pLoopPlot.setTerrainType(iTerrain, True, True) elif iEditType == 2: if bSensibility and pLoopPlot.isWater() != pPlot.isWater(): continue pLoopPlot.setTerrainType(iTerrain, True, True) self.interfaceScreen(pPlot) elif inputClass.getFunctionName() == "BonusClass": iSelectedClass = screen.getPullDownData("BonusClass", screen.getSelectedPullDownID("BonusClass")) self.createBonusList() elif inputClass.getFunctionName() == "WBPlotBonus": iBonus = inputClass.getData2() if iEditType == 0: if bAdd: pPlot.setBonusType(iBonus) else: pPlot.setBonusType(-1) else: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if iEditType == 1 and pLoopPlot.getArea() != pPlot.getArea(): continue iOld = pLoopPlot.getBonusType(-1) if bAdd: pLoopPlot.setBonusType(-1) if iBonus > -1 and bSensibility and not pLoopPlot.canHaveBonus(iBonus, False): pLoopPlot.setBonusType(iOld) continue pLoopPlot.setBonusType(iBonus) else: pLoopPlot.setBonusType(-1) self.placeBonus() elif inputClass.getFunctionName() == "WBPlotImprovement": iImprovement = inputClass.getData2() if iEditType == 0: if bAdd: pPlot.setImprovementType(iImprovement) else: pPlot.setImprovementType(-1) else: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if iEditType == 1 and pLoopPlot.getArea() != pPlot.getArea(): continue if bAdd: if iImprovement > -1 and bSensibility and not pLoopPlot.canHaveImprovement(iImprovement, -1, True): continue pLoopPlot.setImprovementType(iImprovement) else: pLoopPlot.setImprovementType(-1) self.placeImprovements() elif inputClass.getFunctionName().find("UpgradeTime") > -1: if inputClass.getData1() == 1030: pPlot.changeUpgradeProgress(- iChange) elif inputClass.getData1() == 1031: pPlot.changeUpgradeProgress(min(iChange, pPlot.getUpgradeTimeLeft(pPlot.getImprovementType(), pPlot.getOwner()) - 1)) self.placeImprovements() elif inputClass.getFunctionName() == "WBPlotFeature": iFeature = inputClass.getData2() % 10000 iVariety = inputClass.getData2() / 10000 if iVariety < 0 or iFeature < 0: iFeature = -1 iVariety = 0 if iEditType == 0: if bAdd: pPlot.setFeatureType(-1, 0) if CvRiverUtil.isRiverFeature(iFeature): CvRiverUtil.addRiverFeatureSimple(pPlot, iFeature, iVariety) else: pPlot.setFeatureType(iFeature, iVariety) CvUtil.removeScriptData(pPlot, "r") else: pPlot.setFeatureType(-1, 0) CvUtil.removeScriptData(pPlot, "r") else: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if iEditType == 1 and pLoopPlot.getArea() != pPlot.getArea(): continue iOldFeature = pLoopPlot.getFeatureType() iOldVariety = pLoopPlot.getFeatureVariety() if bAdd: pLoopPlot.setFeatureType(-1, 0) if iFeature > -1 and bSensibility and not pLoopPlot.canHaveFeature(iFeature): pLoopPlot.setFeatureType(iOldFeature, iOldVariety) continue if CvRiverUtil.isRiverFeature(iFeature): CvRiverUtil.addRiverFeatureSimple(pLoopPlot, iFeature, iVariety) else: pLoopPlot.setFeatureType(iFeature, iVariety) if CvRiverUtil.isRiverFeature(iOldFeature): CvUtil.removeScriptData(pLoopPlot, "r") else: pLoopPlot.setFeatureType(-1, 0) CvUtil.removeScriptData(pLoopPlot, "r") self.placeFeature() self.placeScript() elif inputClass.getFunctionName() == "WBPlotRoutes": iRoute = inputClass.getData2() if iEditType == 0: if bAdd: pPlot.setRouteType(iRoute) else: pPlot.setRouteType(-1) else: for i in xrange(CyMap().numPlots()): pLoopPlot = CyMap().plotByIndex(i) if pLoopPlot.isNone(): continue if bSensibility: if pLoopPlot.isImpassable(): continue if pLoopPlot.isWater(): continue if iEditType == 1 and pLoopPlot.getArea() != pPlot.getArea(): continue if bAdd: pLoopPlot.setRouteType(iRoute) else: if pLoopPlot.getRouteType() == iRoute: pLoopPlot.setRouteType(-1) self.placeRoutes() elif inputClass.getFunctionName() == "PlotEditScriptData": popup = Popup.PyPopup(5555, EventContextTypes.EVENTCONTEXT_ALL) popup.setHeaderString(CyTranslator().getText("TXT_KEY_WB_SCRIPT", ())) popup.setUserData((pPlot.getX(), pPlot.getY())) popup.createEditBox(pPlot.getScriptData()) popup.launch() elif inputClass.getFunctionName() == "EditLandMark": iIndex = -1 sText = "" for i in xrange(CyEngine().getNumSigns()): pSign = CyEngine().getSignByIndex(i) if pSign.getPlot().getX() != pPlot.getX(): continue if pSign.getPlot().getY() != pPlot.getY(): continue if pSign.getPlayerType() == iCulturePlayer: iIndex = i sText = pSign.getCaption() break popup = Popup.PyPopup(CvUtil.EventWBLandmarkPopup, EventContextTypes.EVENTCONTEXT_ALL) popup.setHeaderString(CyTranslator().getText("TXT_KEY_WB_LANDMARKS", ())) popup.setUserData((pPlot.getX(), pPlot.getY(), iCulturePlayer, iIndex)) popup.createEditBox(sText) popup.launch() elif inputClass.getFunctionName() == "SensibilityCheck": bSensibility = not bSensibility screen.setState("SensibilityCheck", bSensibility) return 1
def handleInput(self, inputClass): screen = CyGInterfaceScreen("WBRiverScreen", CvScreenEnums.WB_PLOT_RIVER) global bAdd global bSensibility global bFord global iSelectedSide global iEditType global bRiverAutomatic global bRiverBranch global bRiverComplete if False: pass elif inputClass.getFunctionName() == "CurrentPage": iIndex = screen.getPullDownData( "CurrentPage", screen.getSelectedPullDownID("CurrentPage")) if iIndex == 1: WBEventScreen.WBEventScreen().interfaceScreen(pPlot) elif iIndex == 2: if pPlot.getOwner() != -1: WBPlayerScreen.WBPlayerScreen().interfaceScreen( pPlot.getOwner()) elif iIndex == 3: WBTeamScreen.WBTeamScreen().interfaceScreen(pPlot.getTeam()) elif iIndex == 4: if pPlot.isCity(): WBCityEditScreen.WBCityEditScreen().interfaceScreen( pPlot.getPlotCity()) elif iIndex == 5: pUnit = pPlot.getUnit(0) if pUnit: WBUnitScreen.WBUnitScreen( CvPlatyBuilderScreen.CvWorldBuilderScreen( )).interfaceScreen(pUnit) elif iIndex == 11: iPlayer = pPlot.getOwner() if iPlayer == -1: iPlayer = CyGame().getActivePlayer() WBInfoScreen.WBInfoScreen().interfaceScreen(iPlayer) elif iIndex == 12: WBPlotScreen.WBPlotScreen().interfaceScreen(pPlot) elif inputClass.getFunctionName() == "NextPlotUpButton": pNewPlot = CyMap().plot(pPlot.getX(), pPlot.getY() + 1) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotDownButton": pNewPlot = CyMap().plot(pPlot.getX(), pPlot.getY() - 1) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotLeftButton": pNewPlot = CyMap().plot(pPlot.getX() - 1, pPlot.getY()) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "NextPlotRightButton": pNewPlot = CyMap().plot(pPlot.getX() + 1, pPlot.getY()) if not pNewPlot.isNone(): self.interfaceScreen(pNewPlot) elif inputClass.getFunctionName() == "WBRiverFeature": iFeature = pPlot.getFeatureType() iVariety = pPlot.getFeatureVariety() bSkip = False if inputClass.getData2() < 0 or not bAdd: pPlot.setFeatureType(-1, 0) CvUtil.removeScriptData(pPlot, "r") bSkip = True if bSensibility and pPlot.getPlotType( ) is not PlotTypes.PLOT_OCEAN: bSkip = True if not bSkip: if inputClass.getData2() >= 1000: if iFeature in riverIds["features"]: CvUtil.removeScriptData(pPlot, "r") pPlot.setTerrainType( riverIds["terrains"][inputClass.getData2() - 1000], True, True) pPlot.setFeatureType(-1, 0) pPlot.setFeatureType( riverIds["features"][inputClass.getData2() - 1000], 0) else: ra = self.lRiveralign[inputClass.getData2()] riverDesc = CvRiverUtil.getRiverScriptData(pPlot) riverDesc.rtype = ra[0] riverDesc.align = ra[1] if riverDesc.variant not in CvRiverUtil.RiverTypes[ riverDesc.rtype][riverDesc.align]: riverDesc.variant = 1 if not len(riverDesc.getVariantSides()) > iSelectedSide: iSelectedSide = 0 if iFeature not in riverIds["features"] or iVariety == 0: CvRiverUtil.addRiverFeature(pPlot) CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) self.placeScript() self.placeRiverFeature() elif inputClass.getFunctionName() == "WBRiverVariant": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) iOld = riverDesc.variant iNew = inputClass.getData2() if iNew is not iOld: riverDesc.variant = iNew if iSelectedSide >= len(riverDesc.getVariantSides()): iSelectedSide = 0 CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) self.placeRiverFeature(0) elif inputClass.getFunctionName() == "WBRiverSubtile": iNew = inputClass.getData2() if iNew is not iSelectedSide: iSelectedSide = iNew self.placeRiverFeature(1) elif inputClass.getFunctionName() == "WBRiverTexture": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) iOld = riverDesc.textures[iSelectedSide] iNew = inputClass.getData2() if iNew is not iOld: riverDesc.textures[iSelectedSide] = iNew CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) self.placeRiverFeature(2) if bRiverComplete or bRiverBranch: nearbyPlots = CvRiverUtil.getAdjacentTiles( pPlot, not bRiverComplete) # Remove this plot (=first entry) nearbyPlots.pop(0) CvRiverUtil.setTexture(nearbyPlots, iSelectedSide, iNew) elif inputClass.getFunctionName() == "WBRiverDecoration": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) bActive = not (inputClass.getData2() in riverDesc.decorations) if bActive: riverDesc.decorations.append(inputClass.getData2()) else: riverDesc.decorations.remove(inputClass.getData2()) CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) self.placeRiverDecoration() elif inputClass.getFunctionName() == "WBRiverRapids": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) riverDesc.rapids = inputClass.getData2() CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) if bRiverComplete or bRiverBranch: nearbyPlots = CvRiverUtil.getAdjacentTiles( pPlot, not bRiverComplete) """ dmsg = "" for n in nearbyPlots: dmsg += "(%i,%i)\n" % (n[0].getX(), n[0].getY()) CyInterface().addMessage(gc.getGame().getActivePlayer(), True, 5, dmsg, None, 2, None, ColorTypes(14), 0, 0, False, False) """ CvRiverUtil.setRapidDirection(nearbyPlots) self.placeRiverFeature(4) self.placeScript() elif inputClass.getFunctionName() == "WBRiverWaterColors": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) # order is [ full texture color 1, halve texture color 1, ... ] riverDesc.waterColor = max(0, inputClass.getData2() - 2) # Use halve texture if rotation is set CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) if bRiverComplete or bRiverBranch: nearbyPlots = CvRiverUtil.getAdjacentTiles( pPlot, not bRiverComplete) CvRiverUtil.setWaterColor(nearbyPlots) self.placeRiverFeature(5) self.placeScript() elif inputClass.getFunctionName() == "WBRiverWaterRotations": riverDesc = CvRiverUtil.getRiverScriptData(pPlot) riverDesc.waterRotation = inputClass.getData2() if riverDesc.waterColor > 0: iPlus = 0 if riverDesc.waterRotation > 0: iPlus = 1 riverDesc.waterColor = 2 * \ ((riverDesc.waterColor+1)/2) - 1 + iPlus CvRiverUtil.updateRiverFeature(pPlot, riverDesc, True) self.placeRiverFeature(5) self.placeScript() elif inputClass.getFunctionName() == "PlotEditScriptData": popup = Popup.PyPopup(5555, EventContextTypes.EVENTCONTEXT_ALL) popup.setHeaderString(CyTranslator().getText( "TXT_KEY_WB_SCRIPT", ())) popup.setUserData((pPlot.getX(), pPlot.getY())) popup.createEditBox(pPlot.getScriptData()) popup.launch() elif inputClass.getFunctionName() == "SensibilityCheck": bSensibility = not bSensibility screen.setState("SensibilityCheck", bSensibility) elif inputClass.getFunctionName() == "FordCheck": bFord = not bFord iTerrain = pPlot.getTerrainType() iFeature = pPlot.getFeatureType() iVariety = pPlot.getFeatureVariety() if (iTerrain in riverIds["terrains"] and iTerrain is not riverIds["terrains"][int(bFord)]): pPlot.setTerrainType(riverIds["terrains"][int(bFord)], True, True) if (iFeature in riverIds["features"] and iVariety in riverIds["varieties"] and iFeature is not riverIds["features"][int(bFord)]): pPlot.setFeatureType(-1, 0) pPlot.setFeatureType(riverIds["features"][int(bFord)], iVariety) riverDesc = CvRiverUtil.getRiverScriptData(pPlot) if not iVariety == 0: CvRiverUtil.updateRiverFeature(pPlot, riverDesc, False) screen.setState("FordCheck", bFord) self.placeRiverFeature() elif inputClass.getFunctionName() == "RiverAutomaticCheck": bRiverAutomatic = not bRiverAutomatic screen.setState("RiverAutomaticCheck", bRiverAutomatic) elif inputClass.getFunctionName() == "RiverBranchCheck": bRiverBranch = not bRiverBranch screen.setState("RiverBranchCheck", bRiverBranch) elif inputClass.getFunctionName() == "RiverCompleteCheck": bRiverComplete = not bRiverComplete screen.setState("RiverCompleteCheck", bRiverComplete) return 1