<PythonCanDo> for specific city name

wotan321

Emperor
Joined
Oct 25, 2001
Messages
1,228
Location
NC, USA
I know this must have been answered before in this thread, but I cannot find it.

I want to see if the human player owns a certain city by name or plot coordinates, all this is the <PythonCanDo> call.

Any help is greatly appreciated.
 
The python interface to EventTriggeredData has the following:
PHP:
    python::class_<EventTriggeredData>("EventTriggeredData")
       .def_readwrite("iId", &EventTriggeredData::m_iId)
       .def_readwrite("eTrigger", &EventTriggeredData::m_eTrigger)
       .def_readwrite("iTurn", &EventTriggeredData::m_iTurn)
       .def_readwrite("ePlayer", &EventTriggeredData::m_ePlayer)
       .def_readwrite("iCityId", &EventTriggeredData::m_iCityId)
       .def_readwrite("iPlotX", &EventTriggeredData::m_iPlotX)
       .def_readwrite("iPlotY", &EventTriggeredData::m_iPlotY)
       .def_readwrite("iUnitId", &EventTriggeredData::m_iUnitId)
       .def_readwrite("eOtherPlayer", &EventTriggeredData::m_eOtherPlayer)
       .def_readwrite("iOtherPlayerCityId", &EventTriggeredData::m_iOtherPlayerCityId)
       .def_readwrite("eReligion", &EventTriggeredData::m_eReligion)
       .def_readwrite("eCorporation", &EventTriggeredData::m_eCorporation)
       .def_readwrite("eBuilding", &EventTriggeredData::m_eBuilding)

Clearly you need ePlayer, iCityId, iPlotX and/or iPlotY. It seems simple enough, assuming all of them are always set correctly.

Looking at vanilla PythonCanDo calls, we get
PHP:
player = gc.getPlayer(kTriggeredData.ePlayer)
plot = gc.getMap().plot(kTriggeredData.iPlotX, kTriggeredData.iPlotY)
city = player.getCity(kTriggeredData.iCityId)
if (plot.getOwner() != kTriggeredData.ePlayer and plot.getOwner() != -1):
if city == None or city.getOwner() != kTriggeredData.ePlayer:
That should be enough to see how you get the data you need from EventTriggeredData.
 
Thank-you for your reply. I apologize for not stating my question more clearly.

I have a historical scenario in which I want an event to fire (Civ4EventTriggerInfos.xml) when a particular civ controls a specific city. I want that if-then statement in the CvRandomEventInterface.py file.

I know how to specify the civ, if they are alive, if they are the human player, but I do not know how to specify the city.

Thanks.
 
PHP:
iPlotX = 1
iPlotY = 1
plot = gc.getMap().plot(iPlotX, iPlotY)
if plot.getOwner() == whatever:
Do this and set X,Y to the coordinates of the city. This should work because you always play on the same map (I assume) and it completely avoids the issue of comparing city names. Say if the target city is Rome, I can just rename my city in China to Rome and trigger the event if it only compared names.
 
Yes, that works. Thanks so much, you really were a great help.

PHP:
def canTriggerGetCart(argsList):
    kTriggeredData = argsList[0]
    player = gc.getPlayer(kTriggeredData.ePlayer)
    iGameTurn = gc.getGame().getGameTurn()
    iPlotX = 61
    iPlotY = 44
    plot = gc.getMap().plot(iPlotX, iPlotY)

    if iGameTurn >= 26 and (gc.getPlayer(plot.getOwner()).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ROME')) and (player.isAlive() and player.isHuman()):
        return true
    return false
 
Back
Top Bottom