Announcement

Collapse
No announcement yet.

Initial Python reference

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

  • #46
    I'm trying to see if I can add an option to the diplo screen, namely:
    Allow the player to offer declare war on opponent in exchange of whatever. Currently, I can declare war on Cyrus when Peter asks me to, but I can't barter and agree in exchange of this or that tech (but I can get Alex to fight Mansa Musa in exchang of Biology). This is asymetrical, the player cannot do what the ai can (and vice versa).
    So I tried to do it, but don't know where to find CyDiplomacy?
    I'll probably try to simplify the accept trade/neogtiate etc which I find really clunky to work with but for the moment I can't find where the screen class really is and that bothers me. Any ideas?
    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)

    Comment


    • #47
      Re: Initial Python reference

      Question. This here event:

      Originally posted by Locutus
      onCityAcquired
      'City Acquired'
      arguments: owner,playerType,city,bConquest,bTrade
      What are the parameters exactly? 'owner' - is that the person that lost the city or that got the city? Same for 'playerType'? And for 'city.getOwner()', has that already been set to the new owner, or is it at this point still for the original owner?

      Thanks,
      Vovan
      XBox Live: VovanSim
      xbox.com (login required)
      Halo 3 Service Record (I fail at FPS...)
      Spore page

      Comment


      • #48
        A couple of (I hope) easy questions:

        1. In the reportEvent function of CvEventManager.py there is a reference to Events.log. Where is this file? Does CvUtil.PyPrint() print to it?

        2. Can I get more detail about the arguments to CyInterface().addMessage()? The API reference is kind of vague.

        Comment


        • #49
          Thanks a lot for the class reference, Locutus. You own. I detected an error in the api if you want to fix the master:
          CvCity::getProduction() does return an int, and it is the base production of that city at that moment, not a boolean.

          I'm now trying to figure out how to change that base :]

          Comment


          • #50
            i looked through this and other threads and some things are not yet very clear to me:

            * what if i only want to overwrite parts of the things. for instance i want to add my own additional keyboard shortcuts for my notebook. eg. ALT-right moves the unit right.
            how could i make sure that that works but keeps everything else the same? is that possible?

            * is there a "safe" way to add such stuff to the normal game (not a special mod) without fiddling around with the game's own "asset" folder? please note: this should be UI only
            - Artificial Intelligence usually beats real stupidity
            - Atheism is a nonprophet organization.

            Comment


            • #51
              I'm trying to lear a thing or two here and I tried using your code.

              I replaced this lines in the CvEventManager.py file

              PHP Code:
              def onCityBuilt(selfargsList):
                    
              'City Built'
                    
              city argsList[0]
                    if (
              city.getOwner() == CyGame().getActivePlayer()):
                         
              self.__eventEditCityNameBegin(city)    
                    
              CvUtil.pyPrint('City Built Event: %s' %(city.getName()))
                    
              popup PyPopup.PyPopup()
                    
              popup.setBodyString'Hello World' )
                    
              popup.launch()
                    
              city.getOwner().initUnit(17city.getX(), city.getY(), UnitAITypes.NO_UNITAI
              The popup box shows but no unit is spwned in the city, I have tried the documentation and I can't find whats wrong here.

              I also tried your original code, no luck there either, the popup box shows but no unit is spawned. What is wrong???

              Comment


              • #52
                Hummm, ok i reply to my self here.


                I inserted this Row..
                gc.getPlayer(CyGame().getActivePlayer()).initUnit( 17,city.getX(),city.getY(),UnitAITypes.NO_UNITAI)

                Instead of this...
                city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)

                Seemed to work, now could anyone explain to me if there was something wrong with the original code or have I forgot to import a module into the CvEventManager.py file???

                I'm lost here!?!?

                Comment


                • #53
                  Enable python error messages in the civ .ini file and enable logging. They will tell you what's wrong.

                  My guess would be that either city.getOwner() doesn't exists or it returns an integer so you should wrap it with gc.getPlayer(...) like you did in the new line you used. (I couldn't find it in the python api, but maybe city here is not of the CyCity type)
                  no sig

                  Comment


                  • #54
                    the city.(getowner()) works even better than CyGame().getActivePlayer() because the latter give me a unit for all cities created the first only the owner.

                    city is a variable containing the newly created city defined in the line...

                    city = argsList[0]

                    Now i have bin able to make this work, but I can't figure out how to add promotions. I have looked around in other mods that adds them but it does not see, to work.

                    I try to add the "combat I" promotion but it will simply not be attached.

                    I added the line setHasPromotion(0,TRUE) so the last line would be then...

                    gc.getPlayer(city.(getowner()).initUnit(17,city.ge tX(),city.getY(),UnitAITypes.NO_UNITAI).setHasProm otion(0,TRUE)

                    this should add a promotion type Combat I

                    Comment


                    • #55
                      Does any one know if it's posibble to force the Technology Discovered popup dialog appear.

                      I want to use the setHasTech api call and display the popup, i have the call working but no popup appears.

                      Comment


                      • #56
                        how do I pass a null-pointer to a function ?
                        eg: for the argument "CyCity* pSkipCity = NULL" in CyMap.findCity( ... )

                        When I tried this in the in-game python console, I got errors about Null, NULL, null being unknown. Just passing a 0 got me the error "arguments "..., ..., int" don't match "..., ..., CyCity* ". Passing an empty list [] didn't work either.



                        Oh, and btw: could it be that "onUnitLost" has more arguments than only pUnit ? With this code:
                        Code:
                        	def onUnitLost(self, pUnit):
                        		if pUnit.getUnitClassType() == self.iUnitClassHarvester :
                        			self.hu.lostHarvester(pUnit)
                        I always get the error getUnitClassType() can't be executed on a tuple.
                        Last edited by PJayTycy; November 17, 2005, 21:51.
                        no sig

                        Comment


                        • #57
                          great thread!

                          one question:

                          i try to implement a wonder which provides a unit/or a certain tech (no free tech like in the xml file).
                          the 'onCityBuilt' example combined with the 'onBuildingBuilt' command is maybe a ?good idea to make this work - but i'm too stupid (learning python in a few days is a hard job) - the game don't do i want them to do.

                          can some1 help me?
                          Last edited by GIR; November 26, 2005, 08:57.

                          Comment


                          • #58
                            I don't feel like looking up the API, so double check this code before you use it!
                            During OnBuildingBuilt:

                            if iBuilding == gc.getInfoTypeForString('BUILDING_YOURWONDER')
                            (tab) iPlayer = pCity.getOwner()
                            (tab) gc.setPlayerHasTech(iPlayer, gc.getInfoTypeForString('TECH_YOURTECH').

                            And there ya go.
                            Mylon Mod - Adressing game pace and making big cities bigger.
                            Inquisition Mod - Exterminating heretic religions since 1200 AD

                            Comment


                            • #59
                              big thx Mylon for you help, the whole day i am trying to get it running!
                              this looks like a simple way but i think i make something wrong, because the game says:

                              Failed to load python module CvEventInterface.

                              her is the part i includet to the onbuildingbuilt:

                              PHP Code:

                                      
                              if iBuilding == gc.getInfoTypeForString'BUILDING_STONEHENGE' ):
                                          
                              iPlayer pCity.getOwner()
                                          
                              gc.setPlayerHasTech(iPlayergc.getInfoTypeForString'TECH_ROCKETRY' 
                              Last edited by GIR; November 26, 2005, 18:05.

                              Comment


                              • #60
                                The code you added should look like:
                                PHP Code:
                                if iBuildingType == gc.getInfoTypeForString'BUILDING_STONEHENGE' ):

                                            
                                pPlayer gc.getPlayer(pCity.plot().getOwner())

                                            
                                gc.getTeam(pPlayer.getTeam()).setHasTech(gc.getInfoTypeForString'TECH_ROCKETRY' ), truepPlayer.getID(), falsefalse
                                edit: Made slight change

                                Bh
                                Last edited by Bhruic; November 26, 2005, 15:57.

                                Comment

                                Working...
                                X