Page 3 of 4 FirstFirst 1 2 3 4 LastLast
Results 61 to 90 of 111

Thread: Initial Python reference

  1. #61
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    IT WORKS!!!!!!!!!!!!!!!!!!
    wow, I L O V E YOU Bhruic
    THX a lot

  2. #62
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    my ?last? question in this thread...

    what is wrong with the last line of this code (unit don't spawn)?

    PHP Code:
    def onBuildingBuilt(selfargsList):
            
    'Building Completed'
            
    pCityiBuildingType argsList
            game 
    CyGame()


            if 
    iBuildingType == gc.getInfoTypeForString'BUILDING_xyz' ):
                
    pPlayer gc.getPlayer(pCity.plot().getOwner())
                
    gc.getTeam(pPlayer.getTeam()).setHasTech(gc.getInfoTypeForString'TECH_zyz' ), truepPlayer.getID(), falsefalse)
                
    #gc.getPlayer(pCity.plot().getOwner()).initUnit( 17, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI )
                
    pPlayer.initUnit17pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI )
    ... 
    Last edited by GIR; December 6, 2005 at 21:29.

  3. #63
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    14:23
    Try:
    PHP Code:
    pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARRIOR'), pCity.getX(), pCity.getY(), gc.getInfoTypeForString('NO_UNITAI')) 
    Bh

  4. #64
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    thx for your help!
    it was my fault that the last line in the code didnt worke because i created a backup folder in the python folder instead of renaming it (...mod...\assets\Python\backup\cveventmanager.py) and cIV used that backupfile (dont know why - maybe im just too stupid).
    now it works and im happy

  5. #65
    Impaler[WrG]
    King Impaler[WrG]'s Avatar
    Join Date
    06 May 2002
    Location
    Civ4 Colonization UI Programmer
    Posts
    2,473
    Country
    This is Impaler[WrG]'s Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    12:23
    I'm wondering is it possible to add new elements to the various XML files AND get python to read this data? Would this require the SDK to write new API functions for extraction the data?

    The specific goal I have is to convert Civics for the C4:AC mod
    I would create a new Civic for each level of the social effect meters SMAC uses for example "<"POLICE_PLUS_TWO">" would handle the effects of a +2 police rating and be under a "<"POLICE">" CivicType. The effect could be anything that a normal Civic can do.

    All of these new Civics would be hidden from direct usage by the player and they would instead select from a subset of the Civics which are defined with a boolean to be the "real" Civic options like FreeMarket and Cybornetic. They would be featureless like Barbarism and Paganism but need to have modifiers like "<"Police_Meter">"-1"<"/Police_Meter">" that will be totaled up by Python to get to net meter values and set the meters in the backgroud.

    I cant realy see any other way to create SMAC style Social Enginering in Civ4. Is it possible to do such a thing (oh and by the way I know I will need to alter the Schem'a but that not a problem, its the Python calls I need to be able to perform).
    Companions the creator seeks, not corpses, not herds and believers. Fellow creators, the creator seeks - those who write new values on new tablets. Companions the creator seeks, and fellow harvesters; for everything about him is ripe for the harvest. - Thus spoke Zarathustra, Fredrick Nietzsche

  6. #66
    PJayTycy
    King
    Join Date
    23 Apr 2005
    Posts
    1,709
    Country
    This is PJayTycy's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    20:23

    Re: Initial Python reference

    Changes in patch 1.09 (from the file CvEventManager.py) :
    Red is old version, black is new version.

    onCombatCalc => onCombatLogCalc
    onCombatHit => onCombatLogHit



    actually, I'm not sure if it's a change since 1.09 or if it's been like that all the time.
    no sig

  7. #67
    Ganraeln
    Settler
    Join Date
    03 Mar 2003
    Posts
    11
    Country
    This is Ganraeln's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23

    Modding worker automation

    What I really want to mod for Civ4 is the worker behavior. I have been combing the python reference, but can't seem to find anything related to the worker automation.

    Is this behavior moddable? If so, where do I need to look?

  8. #68
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Hi Locutus. I am a total newb when it comes to Python, but I was wondering if you could give me a few pointers? There are a few things I am trying to achieve, and I was wondering how I might go about it.

    (a) I want the computer to check-each turn-for civics settings and if CivicSetting=Slavery, then [plus two slaves].

    (b) I want the computer to check each city-every turn-for specialists and, if SpecialistSetting=Soldier, then reduce unit build time by 10% and/or then add +2XP.

    (c) As with (a), I want the computer to check each turn for civics settings and, if CivicSetting=X then add Building Y to the build queue.

    (d) I want to do a python script which might allow a specialist or building, if present, to strip away the number of Unhappiness points a city has.

    (e) Lastly I want to write a script which looks at Health-Unhealth and, if >0, then +5% city growth per turn or, if <0, then -5% city growth per turn. I would like to do the same thing with happiness, but with it being applied to production and commerce.

    Anyway, sorry to be such a pain, but any pointers you can give-such as what part of the code I should tackle-would be VERY much appreciated.

    Yours,
    Aussie_Lurker.

  9. #69
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    hi @ all
    new problem... (getBonusType)
    what is wrong with the last three lines? (CvEventManager.py file)
    example:

    PHP Code:
        def onImprovementBuilt(selfargsList):
            
    'Improvement Built'
            
    iImprovementiXiY argsList

            pPlot 
    CyMap().plot(iX,iY)
            if(
    iImprovement==gc.getInfoTypeForString('IMPROVEMENT_MINE')):
                if(
    pPlot.getTerrainType()==gc.getInfoTypeForString'TERRAIN_GRASS' )):
                    
    pPlot.setImprovementType(-1)
            if(
    iImprovement==gc.getInfoTypeForString('IMPROVEMENT_LUMBERMILL')):
                if(
    pPlot.getFeatureType()==gc.getInfoTypeForString'FEATURE_FOREST' )):
                    
    pPlot.setImprovementType(-1)
            if(
    iImprovement==gc.getInfoTypeForString('IMPROVEMENT_FARM')):
                if(
    pPlot.getBonusType()==gc.getInfoTypeForString'BONUS_HORSE' )):
                    
    pPlot.setImprovementType(-1)
    .
    .

    the code works with the mine and the lumbermill improvement, but not with the farm improvement, because the if(pPlot.getBonusType()==gc.getInfoTypeForString( 'BONUS_HORSE' )): string dont work. it has the same syntax than the strings above but what the hack...

  10. #70
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Apologies for sounding like a complete moron, GIR, but what exactly does this script do? Then I might be able to look at it with 'fresh eyes' as it were.

    Also, there is something else that I want to write a script for. Have the computer look for a strategic resource a civ has access to and if resource X=yes, then Technology Y=beakers/2

    So, for example, if Resource (Iron)=yes, then Iron Working=Beakers (X/2).
    Hope that makes sense.

    Yours,
    Aussie_Lurker.

  11. #71
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    14:23
    Originally posted by GIR
    the code works with the mine and the lumbermill improvement, but not with the farm improvement, because the if(pPlot.getBonusType()==gc.getInfoTypeForString( 'BONUS_HORSE' )): string dont work. it has the same syntax than the strings above but what the hack...
    It does have the same syntax, but it shouldn't.

    BonusType getBonusType(TeamType eTeam)

    That's the function - you'll note that it takes a variable, the eTeam. You can't use it with (), because that's not how it works.

    Bh

  12. #72
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    @The_Aussie_Lurker:

    the code is only a stupid example (dont makes any sense). if you build a farm and this farm is on a horse bonus title, the farm should be deleted (pPlot.setImprovementType(-1 )). i was of the opinion that the getBonusType command work like the getFeatureType and the getTerrainType command, but it's different (but the setBonusType command work, how strange!!).

    @Bhruic:

    thx!
    where is the source of all your knowledge - is there some kind of guid anywhere? i used the PyHelpers.py file but it doesnt help much especially for the getBonusType command.
    and now im totally lost (eTeam ). how should the string looks like?
    Last edited by GIR; December 7, 2005 at 09:18.

  13. #73
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    14:23
    You'll want to check out http://civilization4.net/files/modding/PythonAPI/

    It lists the various classes and functions that you can use. The reason that Bonus type is tied to teams is because the whole team will get to use that bonus, if they are connected to it. Ie, if a city is connect via roads to a Horses bonus, then the city gets to use it. Improvements don't work like that, so there's no need to check.

    Bh

  14. #74
    GIR
    Settler
    Join Date
    25 Nov 2005
    Posts
    28
    Country
    This is GIR's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    wow! thx
    thats a great guid!
    now it works!

  15. #75
    Ganraeln
    Settler
    Join Date
    03 Mar 2003
    Posts
    11
    Country
    This is Ganraeln's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23

    worker automation take 2

    Ok guys, obviously my last post was too vague.

    I am a software engineer by trade, so I'm no idiot. What I'm looking for, and have been unable to find, is enough information in the python reference to determine how to automate a worker. I'm guessing there just isn't enough exposed in the python interface to do it, or there isn't enough documented to figure it out. Am I wrong?

    What I do see, that gives me some sort of hope, is definitions for AUTOMATE types. I'd think that perhaps checking the unit type, along with whether the unit is set to AUTOMATE_BUILD, is a starting point.

    Where I'm falling down is determining what type of enhancement the worker intends to put on a given plot, and how many turns into the enhancement the worker is. The intent would be to change the enhancement type if the worker is on the first turn of work.

    Another problem is that I've noticed that the automated workers ignore mining hills entirely, so I'm not sure if the above approach covers all bases. I would prefer to add to the list of viable worker automation terrain types, and dictate what enhancements will be built.

    Or am I clutching at straws here? Any thoughts? Bueller?

  16. #76
    PJayTycy
    King
    Join Date
    23 Apr 2005
    Posts
    1,709
    Country
    This is PJayTycy's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    20:23
    Ganraeln : I think your question is too complex to be answered in this topped thread where all subjects flow through each other. You might get better results with a new thread with the only focus on your problem.
    no sig

  17. #77
    Ganraeln
    Settler
    Join Date
    03 Mar 2003
    Posts
    11
    Country
    This is Ganraeln's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    PJay,

    Thanks for the response. After posting the first time, and seeing a bunch of posts responding to something else entirely, I was probably coming off a bit snippish. That, I'm sure, will get me nowhere, especially since we should all be grateful for any information given out by these fine folks.

    I'll just wait for the SDK, I think. I'm hoping the documentation is much better then. Otherwise, it's looking very much like hunt and peck - something I've never found very much fun.

  18. #78
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Hi guys,

    Just let me quickly explain what I am trying to attempt.

    I have created a specialist-Slave-which is only ever going to appear under the Slavery Civic, because I think the Slavery Civic is currently a little lacklustre.

    Anyway, After modding the SpecialistInfo.xml file, I did a VERY simple python script, called CvCivics.py, to access this specialist under the Slavery Civic. Problem is, it is NOT currently working. Here it is:

    def onBeginPlayerTurn(self, argsList):
    'Civic Chosen'

    iGameTurn, iPlayer, iCity = argsList

    if iCivic==gc.getInfoTypeForString('CIVIC_SLAVERY')):
    pSpecialist.gc.getFreeSpecialist(7)-int(2)

    print("You have enslaved the local natives")

    Can anyone help me with some advice as to what I need to add? Thanks in advance.

    Yours,
    Aussie_Lurker.
    Last edited by The_Aussie_Lurker; December 10, 2005 at 05:36.

  19. #79
    PJayTycy
    King
    Join Date
    23 Apr 2005
    Posts
    1,709
    Country
    This is PJayTycy's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    20:23
    This part looks very wrong:

    pSpecialist.gc.getFreeSpecialist(7)-int(2)


    if you defined gc like everybody does, it can't be used with anything in front of it. I don't quite get what you want this line to do exactly.
    What do you think pSpecialist is (it's not defined in your code here)?
    Why the - int(2) ?


    Anyway, the freespecialist functions you find in the API are for things like mercantilism giving 1 free specialist, and can be set in XML without python. Perhaps you'll have to give the specialists' bonusses directly to the cities instead of giving them indirectly through a specialist.
    no sig

  20. #80
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Hi there. Thanks for the advice regarding specialists. Actually, things have evolved quite a bit since that post, and I feel quite positive that I have got the right code now. I will post the results of my efforts within the next 7 days.

    Yours,
    Aussie_Lurker.

  21. #81
    platypotamus
    Chieftain
    Join Date
    18 Nov 2005
    Posts
    48
    Country
    This is platypotamus's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    11:23
    Is there anyway to define new "types"?

    Specifically, I'd like to add a couple of new CivilopediaPageTypes, but I can't find a place to do this.

  22. #82
    The_Aussie_Lurker
    King
    Join Date
    06 May 2001
    Location
    Adelaide, South Australia, Australia
    Posts
    1,457
    Country
    This is The_Aussie_Lurker's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Does anyone know if it is possible to link tech rates to in-game factors via python? For instance I would like to do something like this:

    essentially if player has resource=copper, then tech rate for bronze working is 0.75 of normal.

    Anyone able to help me with this?

    Yours,
    Aussie_Lurker.

  23. #83
    LDiCesare
    Emperor
    Join Date
    03 Jan 2001
    Location
    Ashes
    Posts
    3,215
    Country
    This is LDiCesare's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    21:23
    Anyone knows how rivers are generated in map scripts? I can see land/peak/hills/water on one side, ice/tundra/grass/plains/desert on another, and resources and forest/jungle in the third part, but can't find rivers.
    Clash of Civilization team member
    (a civ-like game whose goal is low micromanagement and good AI)
    web site http://clash.apolyton.net/frame/index.shtml and forum here on apolyton)

  24. #84
    LDiCesare
    Emperor
    Join Date
    03 Jan 2001
    Location
    Ashes
    Posts
    3,215
    Country
    This is LDiCesare's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    21:23
    On river generation in map scripts: It is done by a set of global functions, mainly, if I'm not mistaken, getRiverAltitude, which seems to provide the altitude of a plot in order to compute where the river should flow.
    The problem is the rivers are computed to flow from a source to the sea rather than the opposite. This means the rivers will sometimes cross mountain ranges because they seem unable to decide to go sideways when they meet a mountain, and even that wouldn't ensure they will someday meet the sea. If anyone knows how to replace the whole river system generation, I'd like to hear from them.
    Clash of Civilization team member
    (a civ-like game whose goal is low micromanagement and good AI)
    web site http://clash.apolyton.net/frame/index.shtml and forum here on apolyton)

  25. #85
    Yosh
    Chieftain Yosh's Avatar
    Join Date
    04 Nov 2005
    Location
    Chicago, Illinois
    Posts
    70
    Country
    This is Yosh's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    13:23
    Hi I've got a question for someone:

    I want to extract the combat log; I've found the relevant functions that write to the combat log, but since CyInterface().addCombatMessage is not in the SDK, I can't think of a way to get these logs extracted to a text file!

    Any help on this would be appreciated -- I'm probably looking in the wrong places since I went to the Python first (I'm a programmer) :P

  26. #86
    Zuul
    Chieftain
    Join Date
    11 Nov 2005
    Posts
    69
    Country
    This is Zuul's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    20:23
    If you have a unit and move it, how to know on what tile it was on? So you can change things on a tile when a unit moves away from it.

  27. #87
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    14:23
    There's no way to do that. If you read earlier in the thread, you'll note I asked already, and was told I'd have to wait for the SDK - so I guess you will too.

    Bh

  28. #88
    Zuul
    Chieftain
    Join Date
    11 Nov 2005
    Posts
    69
    Country
    This is Zuul's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    20:23
    Okey :-). Well my solution was to check every tile around the unit that moved. One could also check the direction and reverse it to get the old tile but I didn't want to do that.



    Originally posted by Bhruic
    Another question - it's possible to add new Promotion types, yes? I haven't been able to successfully do so at this point, just want to make sure I'm not banging my head against the wall pointlessly.

    edit: nm, got it working. Apparently if you add a new promotion type and try and load an old savegame, it'll die, but if you start a new one, it works fine.

    Bh
    How do you add it?



    Originally posted by Locutus
    General
    onUnitCreated
    'Unit Completed'
    arguments: unit

    onUnitLost
    'Unit Lost'
    arguments: unit
    Can't get those to work. When are they called? When I tried to check unit x y it gave me an error.


    Also is there any onImprovementRemoved or something?
    Last edited by Zuul; January 20, 2006 at 07:26.

  29. #89
    siroxo
    Settler
    Join Date
    21 Nov 2005
    Posts
    8
    Country
    This is siroxo's Country Flag
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    19:23
    Is there an ETA on documentation for the Map generation scripts? If not, has someone figured out the name for floodplains terrain features in the FeatureGenerator class? I haven't found it in any of the map scripts.

  30. #90
    Bhruic
    Prince
    Join Date
    26 Jun 2004
    Posts
    410
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Local Date
    November 27, 2014
    Local Time
    14:23
    Originally posted by Zuul

    How do you add it?
    Just edit the xml file.

    Can't get those to work. When are they called? When I tried to check unit x y it gave me an error.

    Also is there any onImprovementRemoved or something?
    They both work fine for me. What exactly are you trying to do with them?

    As for removing Improvements, no, no function exists for that (that I'm aware of).

    Bh

Page 3 of 4 FirstFirst 1 2 3 4 LastLast

Similar Threads

  1. python import of external python question
    By DougM in forum Civilization IV Creation
    Replies: 0
    Last Post: February 8, 2006, 16:34
  2. Python reference question
    By vovan in forum Civilization IV Creation
    Replies: 4
    Last Post: November 1, 2005, 12:02
  3. CIV 4 - Initial Python Reference y una Utilidad
    By OBV in forum Civilization en Español
    Replies: 3
    Last Post: October 26, 2005, 20:34
  4. Replies: 14
    Last Post: March 23, 2003, 13:11
  5. mod cross-reference
    By seawolfe in forum CtP2-Creation/AI/Mods/Scenarios-Archive
    Replies: 4
    Last Post: February 15, 2002, 14:37

Bookmarks

Posting Permissions