Announcement

Collapse
No announcement yet.

Initial Python reference

Collapse
This is a sticky topic.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #61
    IT WORKS!!!!!!!!!!!!!!!!!!
    wow, I L O V E YOU Bhruic
    THX a lot

    Comment


    • #62
      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, 21:29.

      Comment


      • #63
        Try:
        PHP Code:
        pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARRIOR'), pCity.getX(), pCity.getY(), gc.getInfoTypeForString('NO_UNITAI')) 
        Bh

        Comment


        • #64
          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

          Comment


          • #65
            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

            Comment


            • #66
              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

              Comment


              • #67
                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?

                Comment


                • #68
                  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.

                  Comment


                  • #69
                    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...

                    Comment


                    • #70
                      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.

                      Comment


                      • #71
                        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

                        Comment


                        • #72
                          @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, 09:18.

                          Comment


                          • #73
                            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

                            Comment


                            • #74
                              wow! thx
                              thats a great guid!
                              now it works!

                              Comment


                              • #75
                                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?

                                Comment

                                Working...
                                X