Ejemplo n.º 1
0
def isWHEOOH(playerOrID, askingPlayerOrID):
    """
    Returns True if askingPlayerOrID can see that playerOrID is WHEOOH.

    In game terms, this is the case if the player gives the TOO_MANY_WARS denial type
    for a request to go to war against a rival.
    """
    askedPlayer, askedTeam = getPlayerAndTeam(playerOrID)
    askingPlayer, askingTeam = getPlayerAndTeam(askingPlayerOrID)
    if not TradeUtil.canTrade(askingPlayer, askedPlayer):
        return False
    tradeData = TradeData()
    tradeData.ItemType = TradeableItems.TRADE_WAR
    for player in players(alive=True, barbarian=False, minor=False):
        eTeam = player.getTeam()
        if eTeam == askingPlayer.getTeam() or eTeam == askedPlayer.getTeam(
        ) or askedTeam.isAtWar(eTeam):
            # won't DoW your team, their team, or a team they are fighting
            continue
        if not ((askingTeam.isHasMet(eTeam) and askedTeam.isHasMet(eTeam))
                or gc.getGame().isDebugMode()):
            # won't DoW someone you or they haven't met
            continue
        tradeData.iData = eTeam
        if askedPlayer.canTradeItem(askingPlayer.getID(), tradeData, False):
            denial = askedPlayer.getTradeDenial(askingPlayer.getID(),
                                                tradeData)
            if denial == DenialTypes.DENIAL_TOO_MANY_WARS:
                return True
    return False
Ejemplo n.º 2
0
def getPossibleWars(playerOrID, askingPlayerOrID):
    """
    Returns a tuple containing the WHEOOH status of the given player and
    a list of all CyPlayers on which playerOrID will declare war in a trade.

    The askingPlayerOrID is used to limit the list to players they have met.
    """
    askedPlayer, askedTeam = getPlayerAndTeam(playerOrID)
    askingPlayer, askingTeam = getPlayerAndTeam(askingPlayerOrID)
    if not TradeUtil.canTrade(askingPlayer, askedPlayer):
        return (False, ())
    wheooh = False
    wars = []
    tradeData = TradeData()
    tradeData.ItemType = TradeableItems.TRADE_WAR
    for player in players(alive=True, barbarian=False, minor=False):
        eTeam = player.getTeam()
        if eTeam == askingPlayer.getTeam() or eTeam == askedPlayer.getTeam(
        ) or askedTeam.isAtWar(eTeam):
            # won't DoW your team, their team, or a team they are fighting
            continue
        if not ((askingTeam.isHasMet(eTeam) and askedTeam.isHasMet(eTeam))
                or gc.getGame().isDebugMode()):
            # won't DoW someone you or they haven't met
            continue
        tradeData.iData = eTeam
        if askedPlayer.canTradeItem(askingPlayer.getID(), tradeData, False):
            denial = askedPlayer.getTradeDenial(askingPlayer.getID(),
                                                tradeData)
            if denial == DenialTypes.NO_DENIAL:
                wars.append(player)
            elif denial == DenialTypes.DENIAL_TOO_MANY_WARS:
                wheooh = True
    return (wheooh, wars)
Ejemplo n.º 3
0
def getPossibleEmbargos(playerOrID, askingPlayerOrID):
    """
    Returns a list of all CyPlayers with which playerOrID will stop trading.

    The askingPlayerOrID is used to limit the list to players they have met.
    """
    askedPlayer, askedTeam = getPlayerAndTeam(playerOrID)
    askingPlayer, askingTeam = getPlayerAndTeam(askingPlayerOrID)
    if not TradeUtil.canTrade(askingPlayer, askedPlayer):
        return ()
    embargos = []
    tradeData = TradeData()
    tradeData.ItemType = TradeableItems.TRADE_EMBARGO
    for player in players(alive=True, barbarian=False, minor=False):
        eTeam = player.getTeam()
        if eTeam == askingPlayer.getTeam() or eTeam == askedPlayer.getTeam(
        ) or askedTeam.isAtWar(eTeam):
            # won't embargo your team, their team, or a team they are fighting
            continue
        if not ((askingTeam.isHasMet(eTeam) and askedTeam.isHasMet(eTeam))
                or gc.getGame().isDebugMode()):
            # won't embargo someone you or they haven't met
            continue
        tradeData.iData = eTeam
        if askedPlayer.canTradeItem(askingPlayer.getID(), tradeData, True):
            embargos.append(player)
    return embargos
Ejemplo n.º 4
0
def printStatus(ePlayer, eAskingPlayer=None):
    player = PlayerUtil.getPlayer(ePlayer)
    if eAskingPlayer is None:
        eAskingPlayer = PlayerUtil.getActivePlayerID()
    CvUtil.pyPrint("Trade Status -- %s" % player.getName())
    for eItem, name in STATUS_TRADE_ITEMS:
        tradeData = TradeData()
        tradeData.ItemType = eItem
        can = player.canTradeItem(eAskingPlayer, tradeData, False)
        denial = player.getTradeDenial(eAskingPlayer, tradeData)
        will = denial == DenialTypes.NO_DENIAL
        if denial in DENIALS:
            denial = DENIALS[denial]
        else:
            denial = str(denial)
        if not can:
            if will:
                CvUtil.pyPrint("%s: can't but will" % (name))
            else:
                CvUtil.pyPrint("%s: can't and won't because %s" %
                               (name, denial))
        else:
            if will:
                CvUtil.pyPrint("%s: will" % (name))
            else:
                CvUtil.pyPrint("%s: won't because %s" % (name, denial))
Ejemplo n.º 5
0
def getTradeableBonuses(fromPlayerOrID, toPlayerOrID):
    """
    Returns two sets of bonus IDs that <fromPlayer> will and won't trade to <toPlayer>.

    Assumes that the two players can trade bonuses.
    """
    fromPlayer = PlayerUtil.getPlayer(fromPlayerOrID)
    eToPlayer = PlayerUtil.getPlayerID(toPlayerOrID)
    fromPlayerIsHuman = fromPlayer.isHuman()
    will = set()
    wont = set()
    tradeData = TradeData()
    tradeData.ItemType = TradeableItems.TRADE_RESOURCES
    for eBonus in xrange(gc.getNumBonusInfos()):
        tradeData.iData = eBonus
        if fromPlayer.canTradeItem(eToPlayer, tradeData, False):
            if fromPlayerIsHuman or fromPlayer.canTradeItem(
                    eToPlayer, tradeData, True):
                will.add(eBonus)
            else:
                wont.add(eBonus)
    return will, wont
Ejemplo n.º 6
0
def isGivingFavoriteCivicDenial(playerOrID, askingPlayerOrID):
    """
    Returns True if askingPlayerOrID can see that playerOrID is refusing Civic changes
    because of the "that would go against everything we stand for" FAVORITE_CIVIC denial.

    In the unmodified game, this denial type will show for every available civic choice
    so long as they are running their favorite civic; so we can't tell which civic is the
    favorite, but we do know that one of their current civics is the favorite one.
    """
    tradeData = TradeData()
    tradeData.ItemType = TradeableItems.TRADE_CIVIC
    askedPlayer, askedTeam = getPlayerAndTeam(playerOrID)
    askingPlayer, askingTeam = getPlayerAndTeam(askingPlayerOrID)
    if askingTeam.isHasMet(askedTeam.getID()):
        for iCategory in xrange(gc.getNumCivicOptionInfos()):
            iCivic = askingPlayer.getCivics(iCategory)
            tradeData.iData = iCivic
            if askedPlayer.canTradeItem(askingPlayer.getID(), tradeData,
                                        False):
                denial = askedPlayer.getTradeDenial(askingPlayer.getID(),
                                                    tradeData)
                if denial == DenialTypes.DENIAL_FAVORITE_CIVIC:
                    return True
    return False
Ejemplo n.º 7
0
def makeTrade(type, value=-1):
    trade = TradeData()
    trade.ItemType = TradeableItems(type)
    if value != -1:
        trade.iData = value
    return trade