def fnCheckLandBridge(self, pPlot, x, y): pTestPlot = CyMap().plot(pPlot.getX()+x, pPlot.getY()+y) if not (pPlot.isCity() or pTestPlot.isCity()): pTestPlot = CyMap().plot(pPlot.getX()+x, pPlot.getY()) if (pTestPlot.isCoastalLand()): pTestPlot = CyMap().plot(pPlot.getX(), pPlot.getY()+y) if (pTestPlot.isCoastalLand()): return True return False
def doFogOfWar(iPlayer,iGameTurn): pPlayer = gc.getPlayer(iPlayer) iTeam = pPlayer.getTeam() pTeam = gc.getTeam(iTeam) # Human oder KI alle x Runden, aber unterschiedliche Civs pro Runde fuer optimale Rundenzeiten if pPlayer.isHuman() or (iGameTurn % 20 == iPlayer % 20 and pTeam.isMapTrading()): bDontGoBlackAnymore = False bShowCoasts = False bShowPeaksAndRivers = False if pTeam.isHasTech(gc.getInfoTypeForString("TECH_KARTOGRAPHIE2")): # Strassenkarten bDontGoBlackAnymore = True elif pTeam.isHasTech(gc.getInfoTypeForString("TECH_KARTEN")): # Karte zeichnen bShowCoasts = True bShowPeaksAndRivers = True elif pTeam.isHasTech(gc.getInfoTypeForString("TECH_KARTOGRAPHIE")): # Kartographie: Erste Karten bShowCoasts = True if bDontGoBlackAnymore: return iRange = CyMap().numPlots() for iI in xrange(iRange): pPlot = CyMap().plotByIndex(iI) if not pPlot.isVisible(iTeam, 0): bGoBlack = True # fully black or standard fog of war if pPlot.isCity(): pCity = pPlot.getPlotCity() if pCity.isCapital(): bGoBlack = False elif pCity.getNumWorldWonders() > 0: bGoBlack = False # Holy Mountain Quest if bGoBlack: if CvUtil.getScriptData(pPlot, ["H", "t"]) == "X": bGoBlack = False # Improvements (to normal fog of war) # if bGoBlack: # if pPlot.getImprovementType() == improv1 or pPlot.getImprovementType() == improv2: bGoBlack = False # 50% Chance Verdunkelung if bGoBlack and CvUtil.myRandom(2, "bGoBlack") == 0: bGoBlack = False # Black fog if bGoBlack and pPlot.isRevealed(iTeam, 0): # River and coast (land only) #if pPlot.isRevealed (iTeam, 0) and not (pPlot.isRiverSide() or pPlot.isCoastalLand()): pPlot.setRevealed (iTeam,0,0,-1) # River and coast (land and water) #if pPlot.isRevealed (iTeam, 0) and not (pPlot.isRiverSide() or pPlot.isCoastalLand() or (pPlot.isAdjacentToLand() and pPlot.isWater())): pPlot.setRevealed (iTeam,0,0,-1) if bShowCoasts and (pPlot.isCoastalLand() or pPlot.isAdjacentToLand() and pPlot.isWater()): continue if bShowPeaksAndRivers and (pPlot.isRiverSide() or pPlot.isPeak()): continue pPlot.setRevealed(iTeam, 0, 0, -1)
def drawContents(self): screen = self.getScreen() self.deleteAllWidgets() BUTTON_SIZE = 48 # +++ 1 +++ Units with trade routes lTradeUnitsLand = [ gc.getInfoTypeForString("UNIT_TRADE_MERCHANT"), gc.getInfoTypeForString("UNIT_CARAVAN") ] lTradeUnitsSea = [ gc.getInfoTypeForString("UNIT_TRADE_MERCHANTMAN"), gc.getInfoTypeForString("UNIT_GAULOS"), gc.getInfoTypeForString("UNIT_CARVEL_TRADE") ] list1 = [] list2 = [] pPlayer = gc.getPlayer(CyGame().getActivePlayer()) (unit, pIter) = pPlayer.firstUnit(False) while unit: if unit.getUnitType() in lTradeUnitsLand: if int(CvUtil.getScriptData(unit, ["autA"], 0)): list1.append(unit) elif unit.getUnitType() in lTradeUnitsSea: if int(CvUtil.getScriptData(unit, ["autA"], 0)): list2.append(unit) (unit, pIter) = pPlayer.nextUnit(pIter, False) # Zeige zuerst Landeinheiten, danach Schiffe lHandelseinheiten = list1 + list2 iY = 80 i = 0 iRange = len(lHandelseinheiten) if iRange == 0: szText = localText.getText("TXT_KEY_TRADE_ADVISOR_INFO2", ()) screen.setLabel("Label1_"+str(i), "Background", u"<font=3>" + szText + u"</font>", CvUtil.FONT_LEFT_JUSTIFY, 100, iY+20, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 ) else: for j in xrange(iRange): pUnit = lHandelseinheiten[j] screen.addPanel( "PanelBG_"+str(i), u"", u"", True, False, 40, iY, 935, 51, PanelStyles.PANEL_STYLE_MAIN_BLACK25 ) iY += 4 # Button unit screen.setImageButton("L1_"+str(i), pUnit.getButton(), 50, iY, BUTTON_SIZE, BUTTON_SIZE, WidgetTypes.WIDGET_GENERAL, 1, pUnit.getID()) # Unit name szText = pUnit.getName() screen.setLabel("L2_"+str(i), "Background", u"<font=3>" + szText + u"</font>", CvUtil.FONT_LEFT_JUSTIFY, 100, iY+5, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 ) # Unit load szText = localText.getText("TXT_UNIT_INFO_BAR_5", ()) + u" " iValue1 = CvUtil.getScriptData(pUnit, ["b"], -1) if iValue1 != -1: sBonusDesc = gc.getBonusInfo(iValue1).getDescription() iBonusChar = gc.getBonusInfo(iValue1).getChar() szText += localText.getText("TXT_UNIT_INFO_BAR_4", (iBonusChar,sBonusDesc)) else: szText += localText.getText("TXT_KEY_NO_BONUS_STORED", ()) screen.setLabel("L3_"+str(i), "Background", u"<font=3>" + szText + u"</font>", CvUtil.FONT_LEFT_JUSTIFY, 100, iY+24, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 ) # City 1 iCityX = int(CvUtil.getScriptData(pUnit, ["autX1"], -1)) iCityY = int(CvUtil.getScriptData(pUnit, ["autY1"], -1)) tmpPlot = CyMap().plot(iCityX, iCityY) if tmpPlot and not tmpPlot.isNone() and tmpPlot.isCity(): szText = tmpPlot.getPlotCity().getName() if tmpPlot.getOwner() == CyGame().getActivePlayer(): iTmpX = 470 else: iTmpX = 500 screen.setLabel("L4_"+str(i), "Background", u"<font=3>" + szText + u"</font>", CvUtil.FONT_RIGHT_JUSTIFY, iTmpX, iY+5, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 ) if tmpPlot.getOwner() != -1: iCiv = gc.getPlayer(tmpPlot.getOwner()).getCivilizationType() # Flagge if tmpPlot.getOwner() == CyGame().getActivePlayer(): screen.addFlagWidgetGFC("L5_"+str(i), 480, iY, 24, 54, tmpPlot.getOwner(), WidgetTypes.WIDGET_FLAG, tmpPlot.getOwner(), -1) # Civ-Button else: screen.setImageButton("L5_"+str(i), gc.getCivilizationInfo(iCiv).getButton(), 476, iY+24, 24, 24, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIV, iCiv, -1) szText = gc.getPlayer(tmpPlot.getOwner()).getCivilizationDescription(0) screen.setLabel("L6_"+str(i), "Background", u"<font=2>" + szText + u"</font>", CvUtil.FONT_RIGHT_JUSTIFY, 470, iY+28, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIV, iCiv, -1 ) # Button Bonus 1 iBonus = CvUtil.getScriptData(pUnit, ["autB1"], -1) if iBonus != -1: screen.setImageButton("L7_"+str(i), gc.getBonusInfo(iBonus).getButton(), 510, iY, BUTTON_SIZE, BUTTON_SIZE, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BONUS, iBonus, -1) # Buttons Arrow to left screen.setImageButton("L8_"+str(i), "Art/Interface/Buttons/arrow_left.tga", 580, iY+9, 32, 32, WidgetTypes.WIDGET_GENERAL, -1, -1) # Promotion Escort / Begleitschutz iPromo = gc.getInfoTypeForString("PROMOTION_SCHUTZ") if pUnit.isHasPromotion(iPromo): screen.setImageButton("L14_"+str(i), gc.getPromotionInfo(iPromo).getButton(), 615, iY+9, 32, 32, WidgetTypes.WIDGET_PEDIA_JUMP_TO_PROMOTION, iPromo, -1) # Button Arrow to right screen.setImageButton("L9_"+str(i), "Art/Interface/Buttons/arrow_right.tga", 650, iY+9, 32, 32, WidgetTypes.WIDGET_GENERAL, -1, -1) # Button Bonus 2 iBonus = CvUtil.getScriptData(pUnit, ["autB2"], -1) if iBonus != -1: screen.setImageButton("L10_"+str(i), gc.getBonusInfo(iBonus).getButton(), 700, iY, BUTTON_SIZE, BUTTON_SIZE, WidgetTypes.WIDGET_PEDIA_JUMP_TO_BONUS, iBonus, -1) # City 2 iCityX = int(CvUtil.getScriptData(pUnit, ["autX2"], -1)) iCityY = int(CvUtil.getScriptData(pUnit, ["autY2"], -1)) tmpPlot = CyMap().plot(iCityX,iCityY) if tmpPlot and not tmpPlot.isNone() and tmpPlot.isCity(): szText = tmpPlot.getPlotCity().getName() if tmpPlot.getOwner() == CyGame().getActivePlayer(): iTmpX = 790 else: iTmpX = 760 screen.setLabel("L11_"+str(i), "Background", u"<font=3>" + szText + u"</font>", CvUtil.FONT_LEFT_JUSTIFY, iTmpX, iY+5, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_GENERAL, -1, -1 ) if tmpPlot.getOwner() != -1: iCiv = gc.getPlayer(tmpPlot.getOwner()).getCivilizationType() # Flagge if tmpPlot.getOwner() == CyGame().getActivePlayer(): screen.addFlagWidgetGFC("L12_"+str(i), 756, iY, 24, 54, tmpPlot.getOwner(), WidgetTypes.WIDGET_FLAG, tmpPlot.getOwner(), -1) # Civ-Button else: screen.setImageButton("L12_"+str(i), gc.getCivilizationInfo(iCiv).getButton(), 760, iY+24, 24, 24, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIV, iCiv, -1) szText = gc.getPlayer(tmpPlot.getOwner()).getCivilizationDescription(0) screen.setLabel("L13_"+str(i), "Background", u"<font=2>" + szText + u"</font>", CvUtil.FONT_LEFT_JUSTIFY, 790, iY+28, 0.0, FontTypes.GAME_FONT, WidgetTypes.WIDGET_PEDIA_JUMP_TO_CIV, iCiv, -1 ) # Cancel Button screen.setImageButton("L15_"+str(i), ArtFileMgr.getInterfaceArtInfo("INTERFACE_TRADE_AUTO_STOP").getPath(), 900, iY, BUTTON_SIZE, BUTTON_SIZE, WidgetTypes.WIDGET_GENERAL, 748, pUnit.getID()) # ---- i += 1 iY += 60
def getPlotHealFactor(pUnit): # heal rates for certain areas. They are usually stored in the GlobalDefines.XML but can't be read out with a standard API function. # So I placed them here as constants. ENEMY_HEAL_RATE = 5 NEUTRAL_HEAL_RATE = 10 FRIENDLY_HEAL_RATE = 15 CITY_HEAL_RATE = 20 # set/reset some variables pPlot = pUnit.plot() iSameTileHealFactor = 0 iAdjacentTileHealFactor = 0 iBuildingHealFactor = 0 iSelfHealFactor = 0 iPromotionHealFactor = 0 iTileHealFactor = 0 iActivePlayer = CyGame().getActivePlayer() pActivePlayer = gc.getPlayer(iActivePlayer) iActivePlayerTeam = pActivePlayer.getTeam() eDomain = gc.getUnitInfo(pUnit.getUnitType()).getDomainType() # a sea or air unit in a city, behaves like a land unit if pPlot.isCity(): eDomain = DomainTypes.DOMAIN_LAND # calculate the adjacent-tile heal-factor caused by other units (only the unit with the highest factor counts) for dx in xrange(-1, 2): for dy in xrange(-1, 2): # ignore same tile. Adjacent-tile healing does not work on the same tile. if not (dx == 0 and dy == 0): pLoopPlot = CyMap().plot(pPlot.getX() + dx, pPlot.getY() + dy) # loop through all units on the plot for i in xrange(pLoopPlot.getNumUnits()): pLoopUnit = pLoopPlot.getUnit(i) eLoopUnitDomain = gc.getUnitInfo( pLoopUnit.getUnitType()).getDomainType() # a sea or air unit in a city, behaves like a land unit if pLoopPlot.isCity(): eLoopUnitDomain = DomainTypes.DOMAIN_LAND # adjacent-tile heal does only work if the units have the same domain type if (eDomain == eLoopUnitDomain): if (pLoopUnit.getTeam() == iActivePlayerTeam): if (pLoopUnit.getAdjacentTileHeal() > iAdjacentTileHealFactor): iAdjacentTileHealFactor = pLoopUnit.getAdjacentTileHeal( ) # calculate the same-tile heal-factor caused by other or same unit (only the unit with the highest factor counts) # the same-tile healing is also a kind of self-healing. Means : the promotion Medic I has also effect on the owner unit for i in xrange(pPlot.getNumUnits()): pLoopUnit = pPlot.getUnit(i) eLoopUnitDomain = gc.getUnitInfo( pLoopUnit.getUnitType()).getDomainType() # a sea or air unit in a city, behaves like a land unit if pLoopPlot.isCity(): eLoopUnitDomain = DomainTypes.DOMAIN_LAND # same tile heal does only work if the units are of the same domain type if (eDomain == eLoopUnitDomain): if (pLoopUnit.getTeam() == iActivePlayerTeam): if (pLoopUnit.getSameTileHeal() > iSameTileHealFactor): iSameTileHealFactor = pLoopUnit.getSameTileHeal() # only the highest value counts iTileHealFactor = max(iAdjacentTileHealFactor, iSameTileHealFactor) # calculate the self heal factor by the location and promotion iTeam = pPlot.getTeam() pTeam = gc.getTeam(iTeam) iSelfHealFactor = NEUTRAL_HEAL_RATE iPromotionHealFactor = pUnit.getExtraNeutralHeal() if pPlot.isCity(): iSelfHealFactor = CITY_HEAL_RATE iPromotionHealFactor = pUnit.getExtraFriendlyHeal() elif (iTeam == iActivePlayerTeam): iSelfHealFactor = FRIENDLY_HEAL_RATE iPromotionHealFactor = pUnit.getExtraFriendlyHeal() elif (iTeam != TeamTypes.NO_TEAM): if (pTeam.isAtWar(iActivePlayerTeam)): iSelfHealFactor = ENEMY_HEAL_RATE iPromotionHealFactor = pUnit.getExtraEnemyHeal() # calculate the heal factor by city buildings if pPlot.isCity(): if (pPlot.getTeam() == iActivePlayerTeam): # EF: should probably allow friendly healing too, but this doesn't pCity = pPlot.getPlotCity() # loop for all buldings for iBuilding in xrange(gc.getNumBuildingInfos()): # check if city has that building if pCity.getNumActiveBuilding(iBuilding) > 0: # sum up all heal rates iBuildingHealFactor += gc.getBuildingInfo(iBuilding).getHealRateChange() * \ pCity.getNumActiveBuilding(iBuilding) # return the sum of all heal factors return iTileHealFactor + iBuildingHealFactor + iSelfHealFactor + iPromotionHealFactor