Vassals and Masters

mechaerik

Tuturuu!
Joined
Oct 28, 2008
Messages
7,064
Location
Los Angeles
Is there any way to identify the master (or vassal) of a civ in python? I checked the API, but I can't seem to find anything. I might be missing something though.

Another thing I would like to be able to do is to identify what type of vassal a vassal is, whether a capitulated vassal, colony, or voluntary vassal. I doubt its possible, particularly differentiating between a liberated colony or voluntary vassal, but I thought I'd try anyways.

Thanks in advance for any answers.

:)
 
I haven't tested it but CyTeam.isVassal (TeamType eIndex) should work.
 
I ended up adding these two helper functions to my own project:
PHP:
def getMaster(pTeam):
        """Returns the CyTeam instance of pTeam's master - if any.
        Otherwise returns None."""
        for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
                eTeam = gc.getPlayer(ePlayer).getTeam()
                if pTeam.isVassal(eTeam):
                        return gc.getTeam(eTeam)

def getVassals(pTeam):
        """Returns a list of TeamTypes values (Team IDs) corresponding
        to the vassals of pTeam."""
        lVassals = []
        for ePlayer in range(gc.getMAX_CIV_PLAYERS()):
                pPlayer = gc.getPlayer(ePlayer)
                eTeam = pPlayer.getTeam()
                if pPlayer.isAlive():
                        if gc.getTeam(eTeam).isVassal(pTeam.getID()):
                                lVassals.append(eTeam)
        return lVassals
(I edited the code to get rid of all the references to other helper functions used in my own code. So there might be a error or two in there.)
 
I can think of another one:
PHP:
def isVassalage(pMasterTeam, pVassalTeam):
        """Returns True if pVassal is the vassal of pMaster. Otherwise
        returns False."""
        return pVassalTeam.getID() in getVassals(pMasterTeam)
edit: Duh! This is of course equivalent of using CyTeam.isVassal() directly. :rolleyes:
 
Another thing I would like to be able to do is to identify what type of vassal a vassal is, whether a capitulated vassal, colony, or voluntary vassal. I doubt its possible, particularly differentiating between a liberated colony or voluntary vassal, but I thought I'd try anyways.
This is what I was able to dig up in the API:

There is a method called CyGame.getDeal() which takes a integer value and returns a CyDeal instance, so it would be possible to loop through all current deals with CyGame.getNumDeals():
PHP:
iDeal = 0
iNumDeals = gc.getGame().getNumDeals()
while iNumDeals:
    pDeal = gc.getGame().getDeal(iDeal)
    if not pDeal.isNone():
        iNumDeals -= 1
    iDeal += 1
Now that we have access to all CyDeal instances we can check what the players are with CyDeal.getFirstPlayer() and CyDeal.getSecondPlayer() and if one of them match the vassal we're looking for (ePlayer) we continue with getFirstDeal() and getSecondDeal() respectively and lookup at the TradeData:
PHP:
if pDeal.getFirstPlayer() == ePlayer:
    if pDeal.getFirstDeal().ItemType = TradeableItems.TRADE_SURRENDER:
        return True
elif pDeal.getSecondPlayer() == ePlayer:
    if pDeal.getSecondDeal().ItemType = TradeableItems.TRADE_SURRENDER:
        return True
So if we wrap this up in functions then:
PHP:
def isSurrender(ePlayer):
    """Returns True if ePlayer is a surrendered vassal. Otherwise returns False"""
    iDeal = 0
    iNumDeals = gc.getGame().getNumDeals()
    while iNumDeals:
        pDeal = gc.getGame().getDeal(iDeal)
        if not pDeal.isNone():
            if lookupDeal(pDeal, ePlayer):
                return True
            iNumDeals -= 1
        iDeal += 1
    return False

def lookupDeal(pDeal, ePlayer):
    if pDeal.getFirstPlayer() == ePlayer:
        if pDeal.getFirstDeal().ItemType = TradeableItems.TRADE_SURRENDER:
            return True
    elif pDeal.getSecondPlayer() == ePlayer:
        if pDeal.getSecondDeal().ItemType = TradeableItems.TRADE_SURRENDER:
            return True
Now someone would have to test this approach. :D
 
Keeping up with this we could add:
PHP:
def vassalage(ePlayer):
    """Returns two values: The CyTeam instance of the master
    if ePlayer is a vassal. And True if ePlayer is a surrendered 
    vassal. (Otherwise the second value is False.)"""
    pTeam = gc.getTeam(gc.getPlayer(ePlayer).getTeam())
    if pTeam.isAVassal():
        return getMaster(pTeam), isSurrender(ePlayer)
    return None, None
So you use it like:
PHP:
pMasterTeam, bSurrender = vassalage(ePlayer)
 
I see. I thank you all again. Ill test it tomorrow.

My plans are to allow new dynamic civ names based on a vassals master, much like RFCs naming dynamic. I would also add the masters description to a vassal, like MSTR Duchy of ShRT (ie, Celtic Duchy of Russia).
 
Top Bottom