Пример #1
0
def getTrainableUnits(playerOrID,
                      knowableUnits,
                      checkCities=True,
                      military=None):
    """
    Returns the set of all units the player can train, including obsolete ones.
    """
    game = CyGame()
    player, team = PlayerUtil.getPlayerAndTeam(playerOrID)
    civInfo = gc.getCivilizationInfo(player.getCivilizationType())
    if checkCities:
        cities = PlayerUtil.getPlayerCities(player)
    else:
        cities = None
    units = set()
    BugUtil.debug("%s =========", player.getName())
    for eClass in xrange(NUM_CLASSES):
        eUnit = civInfo.getCivilizationUnits(eClass)
        if eUnit == -1 or eUnit not in knowableUnits:
            #BugUtil.debug("  %s -> unknowable", gc.getUnitClassInfo(eClass).getDescription())
            continue
        unitInfo = gc.getUnitInfo(eUnit)
        # military
        if military is not None:
            combat = (unitInfo.getUnitCombatType() > 0
                      or unitInfo.getNukeRange() != -1
                      or unitInfo.getAirCombat() > 0)
            if military != combat:
                #BugUtil.debug("  %s -> combat is %s", unitInfo.getDescription(), combat)
                continue
        # OCC and Settlers
        if game.isOption(GameOptionTypes.GAMEOPTION_ONE_CITY_CHALLENGE
                         ) and unitInfo.isFound():
            BugUtil.debug("  %s -> no founding units in OCC",
                          unitInfo.getDescription())
            continue
        # techs
        for eTech in unitTechs[eUnit]:
            if not team.isHasTech(eTech):
                BugUtil.debug("  %s -> doesn't know %s",
                              unitInfo.getDescription(),
                              gc.getTechInfo(eTech).getDescription())
                missing = True
                break
        else:
            missing = False
        if missing:
            continue
        # state religion
        eReligion = unitInfo.getStateReligion()
        if eReligion != -1 and player.getStateReligion() != eReligion:
            BugUtil.debug("  %s -> wrong state religion",
                          unitInfo.getDescription())
            continue
        # nukes
        if (game.isNoNukes()
                or not game.isNukesValid()) and unitInfo.getNukeRange() != -1:
            BugUtil.debug("  %s -> no nukes", unitInfo.getDescription())
            continue
        # getSpecialUnitType, game.isSpecialUnitValid
        eSpecialType = unitInfo.getSpecialUnitType()
        if eSpecialType != -1 and not game.isSpecialUnitValid(eSpecialType):
            BugUtil.debug("  %s -> special unit type %s invalid",
                          unitInfo.getDescription(),
                          gc.getSpecialUnitInfo(eSpecialType).getDescription())
            continue
        # cities
        if cities and not canAnyCityBuildUnit(eUnit, cities, -1, True):
            BugUtil.debug("  %s -> no city can train unit",
                          unitInfo.getDescription())
            continue
        BugUtil.debug("  %s", unitInfo.getDescription())
        units.add(eUnit)
    return units