def startPlague(self, iPlagueCounter):
     iWorstCiv = -1
     iWorstHealth = 200
     for iPlayer in range(iNumMajorPlayers):
         pPlayer = gc.getPlayer(iPlayer)
         if pPlayer.isAlive():
             if self.isVulnerable(iPlayer):
                 iHealth = self.calculateHealth(iPlayer) / 2
                 if pPlayer.calculateTotalCityHealthiness() > 0:
                     iHealth += gc.getGame().getSorenRandNum(
                         40, 'random modifier')
                     #print ("starting plague", "civ:", iPlayer, "iHealth:", iHealth)
                     if iPlagueCounter == 2:  #medieval black death
                         if iPlayer in lCivGroups[0]:
                             iHealth -= 5
                 if iHealth < iWorstHealth:
                     iWorstHealth = iHealth
                     iWorstCiv = iPlayer
     if iWorstCiv != -1:
         print("worstCiv", iWorstCiv)
         if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
             utils.logwithid(
                 iWorstCiv,
                 'starting plague with iWorstHealth: ' + str(iWorstHealth))
         pWorstCiv = gc.getPlayer(iWorstCiv)
         city = utils.getRandomCity(iWorstCiv)
         if city:
             self.spreadPlague(iWorstCiv)
             self.infectCity(city)
             self.announceForeignPlagueSpread(city)
 def infectCitiesNear(self, iPlayer, startingX, startingY):
     for city in utils.getCityList(iPlayer):
         if utils.calculateDistance(city.getX(), city.getY(), startingX,
                                    startingY) <= 3:
             self.infectCity(city)
             if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                 utils.logwithid(iPlayer, ' is infecting near city')
             self.announceForeignPlagueSpread(city)
 def spreadPlague(self, iPlayer):
     pPlayer = gc.getPlayer(iPlayer)
     iHealth = self.calculateHealth(
         iPlayer) / 7  #duration range will be -4 to +4 for 30 to 90
     data.players[iPlayer].iPlagueCountdown = min(9, iDuration - iHealth)
     print("spreading plague to", iPlayer)
     if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
         utils.logwithid(iPlayer, ' is spreading plague')
    def spreadBetweenCities(self, iPlayer, lSourceCities, lTargetCities):
        if data.players[iPlayer].iPlagueCountdown <= 2: return

        random.shuffle(lTargetCities)
        for targetCity in lTargetCities:
            if [
                    city for city in lSourceCities
                    if targetCity.isConnectedTo(city)
                    and utils.calculateDistance(targetCity.getX(
                    ), targetCity.getY(), city.getX(), city.getY()) <= 6
            ]:
                self.infectCity(targetCity)
                if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                    utils.logwithid(iPlayer,
                                    ' plague is spreading between city')
                return
    def spreadToVassals(self, iPlayer):
        if data.players[iPlayer].bFirstContactPlague: return

        for iLoopPlayer in range(iNumMajorPlayers):
            if gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isVassal(
                    iLoopPlayer) or gc.getTeam(
                        gc.getPlayer(iLoopPlayer).getTeam()).isVassal(iPlayer):
                if self.isVulnerable(iLoopPlayer) and data.players[
                        iLoopPlayer].iPlagueCountdown > 2:
                    if gc.getPlayer(iLoopPlayer).getNumCities() > 0:
                        capital = gc.getPlayer(iLoopPlayer).getCapitalCity()
                        self.spreadPlague(iLoopPlayer)
                        self.infectCity(capital)
                    if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                        utils.logwithid(iPlayer,
                                        ' plague is spreading to vassals')
    def spreadAlongTradeRoutes(self, city):
        iPlayer = city.getOwner()

        if data.players[iPlayer].bFirstContactPlague: return
        if data.players[iPlayer].iPlagueCountdown <= 2: return

        for iTradeRoute in range(city.getTradeRoutes()):
            tradeCity = city.getTradeCity(iTradeRoute)
            if not tradeCity.isNone():
                iOwner = tradeCity.getOwner()
                if not tradeCity.isHasRealBuilding(iPlague):
                    if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                        utils.logwithid(
                            iPlayer,
                            ' plague is spreading through trade route')
                    if iPlayer == iOwner:
                        self.infectCity(tradeCity)
                    elif self.isVulnerable(iOwner):
                        self.spreadPlague(iOwner)
                        self.infectCity(tradeCity)
                        self.announceForeignPlagueSpread(city)
    def onFirstContact(self, iTeamX, iHasMetTeamY):
        if data.bNoPlagues:
            return

        if gc.getGame().getGameTurn() > getTurnForYear(
                tBirth[iAztecs]) + 2 and gc.getGame().getGameTurn(
                ) < getTurnForYear(1800):
            iOldWorldCiv = -1
            iNewWorldCiv = -1
            if iTeamX in lCivBioNewWorld and iHasMetTeamY in lCivBioOldWorld:
                iNewWorldCiv = iTeamX
                iOldWorldCiv = iHasMetTeamY
            if iOldWorldCiv != -1 and iNewWorldCiv != -1:
                pNewWorldCiv = gc.getPlayer(iNewWorldCiv)
                if data.players[
                        iNewWorldCiv].iPlagueCountdown == 0:  #vulnerable
                    #print ("vulnerable", iNewWorldCiv)
                    if not gc.getTeam(
                            pNewWorldCiv.getTeam()).isHasTech(iBiology):
                        city = utils.getRandomCity(iNewWorldCiv)
                        if city:
                            iHealth = self.calculateHealth(iNewWorldCiv)
                            if iHealth < 10:  #no spread for iHealth >= 70 years
                                iHealth /= 10
                                if gc.getGame().getSorenRandNum(
                                        100, 'roll') > 30 + 5 * iHealth:
                                    data.players[
                                        iNewWorldCiv].iPlagueCountdown = iDuration - iHealth
                                    data.players[
                                        iNewWorldCiv].bFirstContactPlague = True
                                    #print ("spreading (through first contact) plague to", iNewWorldCiv)
                                    self.infectCity(city)
                                    if (gc.getDefineINT(
                                            "PYTHON_LOG_ON_MAIN_PLAGUE") == 1):
                                        utils.logwithid(
                                            iHasMetTeamY,
                                            ' is infecting new world civ city')
                                    self.announceForeignPlagueSpread(city)
    def checkConquest(self,
                      tConquest,
                      tPrereqConquest=(),
                      iWarPlan=WarPlanTypes.WARPLAN_TOTAL):
        iID, iPlayer, iPreferredTarget, tTL, tBR, iNumTargets, iYear, iIntervalTurns = tConquest

        iGameTurn = gc.getGame().getGameTurn()
        iStartTurn = getTurnForYear(iYear) - 5 + (data.iSeed % 5)
        if (iStartTurn - iGameTurn in range(0, 10)):  #mediv01  alert for AIWAR
            if (iID < 200):
                utils.log2(
                    "AI WAR [" + str(iID) + "] GAME TURN LEFT: " +
                    str(iStartTurn - iGameTurn), 'DoC_SmallMap_Log_AIWar')
                pass

        if iGameTurn <= getTurnForYear(tBirth[iPlayer]) + 3: return

        if not (iStartTurn <= iGameTurn <= iStartTurn + iIntervalTurns): return
        if tPrereqConquest and not self.isConquered(tPrereqConquest): return
        if (gc.getDefineINT("AIWAR_PY_CAN_USE_SUPER_AI_WAR") == 0
                and int(iID) >= 13):
            return  #参数控制
        if utils.getHumanID() == iPlayer and gc.getDefineINT(
                "AIWAR_PY_HUMAN_CAN_USE_AI_WAR") == 0:
            return  #人类可以使用AIWAR开关
        if ((not gc.getPlayer(iPlayer).isAlive()) and
                gc.getDefineINT("AIWAR_PY_DEAD_CIV_CANNOT_USE_AI_WAR") == 1):
            return  #参数控制
        #if not gc.getPlayer(iPlayer).isAlive() and iPlayer != iTurks: return  #mediv01

        if ((not gc.getPlayer(iPreferredTarget).isAlive()) and
                gc.getDefineINT("AIWAR_PY_CAN_USE_AI_WAR_TO_DEAD_CIV") == 0):
            return  #参数控制    #刷兵目标不存在,返回
        if gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isDefensivePact(
                iPreferredTarget):
            return
        if gc.getDefineINT("PYTHON_NOAIWAR_WHEN_VASSAL"):
            if (gc.getTeam(gc.getPlayer(iPreferredTarget).getTeam()).isVassal(
                    iPlayer)):
                return
            if (gc.getTeam(gc.getPlayer(iPlayer).getTeam()).isVassal(
                    iPreferredTarget)):
                return

        if gc.getDefineINT(
                "PYTHON_NOAIWAR_WHEN_VASSAL_MASTER") or gc.getDefineINT(
                    "PYTHON_NOAIWAR_WHEN_VASSAL_TO_OTHER"):
            for iLoopPlayer in range(iNumPlayers):
                #AIWAR目标附庸他人时,无法发动战争
                if gc.getTeam(gc.getPlayer(
                        iPreferredTarget).getTeam()).isVassal(iLoopPlayer):
                    if (gc.getDefineINT("PYTHON_NOAIWAR_WHEN_VASSAL_TO_OTHER")
                        ):
                        return

                #附庸其他人时,无法发动AIWAR
                if gc.getTeam(
                        gc.getPlayer(iPlayer).getTeam()).isVassal(iLoopPlayer):
                    if (iLoopPlayer is not iPlayer and gc.getDefineINT(
                            "PYTHON_NOAIWAR_WHEN_VASSAL_MASTER")):
                        return
            pass

        if (iStartTurn - iGameTurn == 2
                and gc.getDefineINT("AIWAR_PY_HUMAN_AI_WAR_ALERT") == 1
                and utils.getHumanID()
                == iPreferredTarget):  #mediv01  alert for AIWAR
            tem_text = '&#35686;&#25253;&#65306;&#25932;&#22269;&#27491;&#22312;&#25105;&#22269;&#36793;&#22659;&#38598;&#32467;&#22823;&#20891;&#65281;&#25112;&#20105;&#30340;&#38452;&#20113;&#31548;&#32617;&#22312;&#25105;&#22269;&#19978;&#31354;&#65281;'  #警报:敌国正在我国边境集结大军!战争的阴云笼罩在我国上空!
            utils.show(tem_text)
            CyInterface().addMessage(gc.getGame().getActivePlayer(), False,
                                     iDuration, tem_text, "", 0, "",
                                     ColorTypes(iWhite), -1, -1, True, True)
            pass
        if (iStartTurn - iGameTurn == 2
                and gc.getDefineINT("AIWAR_PY_HUMAN_AI_WAR_ALERT") == 1
                and utils.getHumanID() == iPlayer):  #mediv01  alert for AIWAR

            tem_text = '&#35686;&#25253;&#65306;&#25932;&#20891;&#27491;&#22312;&#36793;&#22659;&#25361;&#34885;&#25105;&#26041;&#20891;&#38431;&#65292;&#25112;&#20105;&#30340;&#38452;&#20113;&#31548;&#32617;&#22312;&#25105;&#22269;&#19978;&#31354;&#65281;&#10;'  #警报:敌军正在边境挑衅我方军队,战争的阴云笼罩在我国上空!
            utils.show(tem_text)
            CyInterface().addMessage(gc.getGame().getActivePlayer(), False,
                                     iDuration, tem_text, "", 0, "",
                                     ColorTypes(iWhite), -1, -1, True, True)
            pass

        if (iID < len(data.lConquest)):
            if data.lConquest[iID]: return
        else:
            return
        if iPreferredTarget >= 0 and gc.getPlayer(iPreferredTarget).isAlive(
        ) and gc.getTeam(iPreferredTarget).isVassal(iPlayer):
            return

        import GlobalDefineAlt
        if (iID in GlobalDefineAlt.PYTHON_NO_AIWAR_ID): return

        if (iPlayer == iEngland and iYear <= 1250) or (
                iPlayer == iHolyRome
                and iYear <= 1250) or (iPlayer == iFrance
                                       and iYear <= 1250):  #耶路撒冷在天主教文明手里,则停止刷兵

            lAreaCities = utils.getAreaCities(
                utils.getPlotList(tCrusadesTL, tCrusadesBR))
            for city in lAreaCities:
                if city.getOwner() in [
                        iByzantium, iEngland, iGermany, iFrance, iVikings,
                        iHolyRome, iPoland, iSpain
                ]:
                    return
        data.lConquest[iID] = True
        if (gc.getDefineINT("PYTHON_LOG_ON_MAIN_AIWAR") == 1):
            utils.logwithid(
                iPlayer, ' Start AI WAR with ' + str(
                    gc.getPlayer(
                        iPreferredTarget).getCivilizationShortDescription(0)))
        self.spawnConquerors(iPlayer, iPreferredTarget, tTL, tBR, iNumTargets,
                             iYear, iIntervalTurns, iWarPlan)