[Python] Spawn barbarian naval units

jkp1187

Unindicted Co-Conspirator
Joined
Aug 29, 2004
Messages
2,496
Location
Pittsburgh, Pennsylvania
Hello, me again. This time I'm trying to get Barbarian naval units to spawn as part of a random event. I basically want the event to be similar to the existing barbarian events, except that they spawn as privateers.

I wrote what I thought would be the correct code to do this, but nothing happens every time I try to trigger the event. I am not getting any XML errors, nor do I have any python errors in the log....the event just isn't firing. This is the code I have....

Code:
def canTriggerBlackbeard(argsList):

    kTriggeredData = argsList[0]
    pPlayer = gc.getPlayer(kTriggeredData.ePlayer)
    
#   If Barbarians are disabled in this game, this event will not occur.
    if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_BARBARIANS):
        return false
            
#   At least one civ on the board must know Chemistry.
    bFoundValid = false
    iTech = CvUtil.findInfoTypeNum(gc.getTechInfo, gc.getNumTechInfos(), 'TECH_CHEMISTRY')
    for iPlayer in range(gc.getMAX_CIV_PLAYERS()):            
        loopPlayer = gc.getPlayer(iPlayer)
        if loopPlayer.isAlive():
            if gc.getTeam(loopPlayer.getTeam()).isHasTech(iTech):
                bFoundValid = true
                break
                
    if not bFoundValid:
        return false
                    
#   At least one civ on the board must know Astronomy.
    bFoundValid = false
    iTech = CvUtil.findInfoTypeNum(gc.getTechInfo, gc.getNumTechInfos(), 'TECH_ASTRONOMY')
    for iPlayer in range(gc.getMAX_CIV_PLAYERS()):            
        loopPlayer = gc.getPlayer(iPlayer)
        if loopPlayer.isAlive():
            if gc.getTeam(loopPlayer.getTeam()).isHasTech(iTech):
                bFoundValid = true
                break
                
    if not bFoundValid:
        return false

#    Find an eligible plot
    map = gc.getMap()    
    for i in range(map.numPlots()):
        plot = map.plotByIndex(i)
        if (plot.getOwner() == -1 and plot.isWater() and not plot.isImpassable() and plot.area().getCitiesPerPlayer(kTriggeredData.ePlayer) > 0):
            return true

    return false
 
I would be very interested in the solution to this problem. Earlier I tried to do something very similar: when I tested an event in-game, nothing happened, not even any errors. When I tried to run a stock BtS event that used Python (I think it was the Champion event), nothing happened then, either!
 
LoOl you want a tile of water with a number of cities positive on the water area :

Code:
    for i in range(map.numPlots()):
        plot = map.plotByIndex(i)
        if plot.getOwner() != -1 : continue
        if not plot.isWater() : continue
        if plot.isImpassable() : continue
        if plot.getNumUnits() > 0 : continue
        return True
    return False

An example to use the serial of test on an easy way to change .

Tcho !
 
[SMACKS FOREHEAD]

Ohhhh! I thought that line was just testing to see if the triggered civ had more than one city, but I see now why it wouldn't.

I can easily figure things out once you explain them to me in language that a four-year-old could understand. :D

I am so smrt!
 
Back
Top Bottom