Announcement

Collapse
No announcement yet.

Initial Python reference

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

  • #16
    Scenario making can be done on different levels, from very simple to very complex. Look at the Earth 1000 AD scenario for a very simple but still fun and replayable scenario: it's entirely made with the World Builder, no XML or Python changes there. Anyone who knows how to use a mouse and keyboard and is a little bit creative could design something like that, no real technical skills are required. The Greek World scenario involves some a fair amount of XML modding but very little Python, the scenario would be entirely playable and enjoyable if you deleted the Python folder. Anyone could still design something like that but you have to dive into some XML files to accomplish it, which may require some getting used to, but it's not hard to do at all. The Revolutionary War scenario contains more complex Python code, although as far as Python goes, it's still fairly straight-forward and easy to adjust for your own purposes. The Desert War scenario is another step up in complexity and it requires some skill and experience to create something similar. But I'm in the process of writing a detailed Python guide that should make Python modding a lot easier for everyone from novices to expert programmers.
    Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

    Comment


    • #17
      Thanks Locutus

      I speak from experience, you are a very helpful individual

      I have called on you for many years in CTP and have had untold hours of fun modding

      Looking forward after Amazon gets done abusing my Presell edition of CIV IV to doing some modding

      Thanks a lot

      Gramps
      Hi, I'm RAH and I'm a Benaholic.-rah

      Comment


      • #18
        Thanks to everyone for your comments and encouragement. I'll be reading Dale's manual while I wait on Amazon.

        Comment


        • #19
          Originally posted by Peter Triggs
          I don't remember a lot of the Civ2 scenarios I used to play as having a lot of scripting. But this was in the last millenium and I'm sure that the ones that have come out more recently are way more sophisticated.
          There were a few extremely sophisticated Civ2 scenarios released at one point - these used multiple event files etc. For example, Red Front is a classic example. It is still my all-time favourite Civ game. Hopefully with the new tools in Civ4 this can be surpassed!

          Comment


          • #20
            Originally posted by sgrig
            There were a few extremely sophisticated Civ2 scenarios released at one point - these used multiple event files etc. For example, Red Front is a classic example. It is still my all-time favourite Civ game. Hopefully with the new tools in Civ4 this can be surpassed!
            It most certainly can be. If it will be, is up to the fans
            Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

            Comment


            • #21
              Originally posted by Locutus
              The Revolutionary War scenario contains more complex Python code, although as far as Python goes, it's still fairly straight-forward and easy to adjust for your own purposes. The Desert War scenario is another step up in complexity and it requires some skill and experience to create something similar.
              Hey now... the functions I wrote to spawn rebel barbarian units randomly within a certain radius of any plot while also moving enemy units currently on that plot aside to a random plot in a list of the closest friendly ones is just as complicated as anything in DesertWar.

              Comment


              • #22
                Originally posted by sgrig
                There were a few extremely sophisticated Civ2 scenarios released at one point - these used multiple event files etc. For example, Red Front is a classic example. It is still my all-time favourite Civ game. Hopefully with the new tools in Civ4 this can be surpassed!
                As Locutus, I certainly expect Civ 4 to pass Civ 2. The Civ community is much larger and more experienced now and more is possible - mix the two together you and you can come up with some amazing stuff.

                Comment


                • #23
                  Originally posted by Trip

                  Hey now... the functions I wrote to spawn rebel barbarian units randomly within a certain radius of any plot while also moving enemy units currently on that plot aside to a random plot in a list of the closest friendly ones is just as complicated as anything in DesertWar.
                  My version's more robust though

                  Either way, both our scenarios are just the tip of the iceberg in terms of what can be done with Python, it'll be very exciting to see what the community will do in the coming years with the tools they've been given. If previous moddable games such as Civ2 and the CtP series are any indication, the only thing we know for sure that it'll surpass all our expectations
                  Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                  Comment


                  • #24
                    Any idea how to attach a vertical scrollbar to an existing panel?

                    I printed some stuff on a panel which goes beyond it's clip boundary, so I need to somehow put a scrollbar on that panel...

                    Comment


                    • #25
                      Re: Initial Python reference

                      Originally posted by Locutus
                      Example
                      Finally, I'll give one simple example of how to use all this code in practice. For more examples, see the Python code in the Mods folder, the various scenarios come with a lot of interesting code.

                      Code:
                      def onGameStart(self, argsList):
                      	'Create a popup message at the start of the game'
                      	popup = PyPopup.PyPopup()
                      	popup.setBodyString( 'Hello World' )
                      	popup.launch()
                      
                      def onCityBuilt(self, argsList):
                      	'For player 1, create a Warrior (index 17) in every city that is built'
                      	city = argsList[0]
                      	if city.getOwner() == 1:
                      		city.getOwner().initUnit(17, city.getX(), city.getY(), UnitAITypes.NO_UNITAI)
                      I'm a bit confused... in which file i have to add those lines (for example)? "CvEventManager.py"?

                      Comment


                      • #26
                        How do I edit properties of the cities? I want to add bonuses to the cities based on resources, health, ect, but I'm not sure what event to use to keep them up to date, plus to make sure it processes for every city.

                        I'm thinking I can add something like this, but it has to be called for each city every turn, just to make sure it's up to date, so I'm not sure where to add it (or if I'm calling/editing the write variables).
                        Code:
                        if (Pycity.getFoodRate() * (getGoodHealth() -  getBadHealth()) * 0.05 > 0):
                        	YieldTypes.YIELD_FOOD = Pycity.getFoodRate() * (getGoodHealth() -  getBadHealth()) * 0.05:
                        Would I put this in onEndTurn? And how would I make sure it processes for every city?
                        Mylon Mod - Adressing game pace and making big cities bigger.
                        Inquisition Mod - Exterminating heretic religions since 1200 AD

                        Comment


                        • #27
                          Re: Initial Python reference

                          Originally posted by Locutus
                          4) Overrides - some game functions can be overwritten, for example what can be built in what cities, what civics/techs/religions/etc are available to who
                          Anyone have any suggestion on how I can forbid certain civs from getting certain religions? For example, if I wanted to put both Christianity and Islam under Monothesim and have the French, English, and Germans only able to found Christianity when getting the tech and the Persians, Arabs, and Egypt only able to found Islam?

                          I'm a super newbie at python/xml but I've been spending a fair amount of time poking around the files trying to get a sense of how to set something like this up. Any ideas would be greatly appreciated.

                          Comment


                          • #28
                            map scripts with static terrain

                            I want to create a map script that recreates the same map every time, but randomizes resource placement. Can I simply input coordinates for each terrain type in the relevant portion of the script(cutting and pasting from the BMP-WBS converter values), or is it more complex than that? Can I preplace cities, units, and generate tech levels in the map script, as well?

                            Why I ask, is I want to create a scenario, but want certain factors randomized, but keep the same map. In civ III, I'd simply randomize the resource placement in the editor... but not having the game yet, I'm uncertain is the worldbuilder allows me to do this.

                            Comment


                            • #29
                              Re: Initial Python reference

                              Originally posted by Locutus

                              A note of caution: please do NOT, I repeat, do NOT mess with the Python files in the default Assets folder, this will cause all kinds of problems with future patching, MP play, tournaments, etc. Please use the mod setup that's also used for the in-game scenarios, see the Mods folder. Here you only need to keep the things you add/change, files that remain unchanged you can leave out, the game will just take the version from the default Assets folder for any file it's missing (similar to CtP modding, for those familiar with it -- only this time it actually works). More detailed info will follow but I think most people will be able to figure this out soon enough, it's pretty simple.
                              So, if I want to modify a certain PY file, I should copy it to the MODS folder, edit that copy in the mods folder, and leave it there, while keeping the original PY file in its original directory? This sounds like the system first grabs PY's in the Mods folder and then collects from the original folders any PYs that are not found in the Mods, right?

                              This is my first time modding Civ, so if my question sits better in another thread, please direct me to it... IF there is a Newbie's guide to Modding Civ, I'd love to read it. Thanks.
                              XP SP2; 1280MB w/3200MB virtual memory
                              AMD Athlon 1700+; 500W power, 2HD's
                              Radeon 9600pro 256MB (Dec 2005 Catalyst)
                              SoundBlaster X-Fi (8.8.05 driver)

                              Comment


                              • #30
                                Originally posted by TheDarkside
                                Any idea how to attach a vertical scrollbar to an existing panel?

                                I printed some stuff on a panel which goes beyond it's clip boundary, so I need to somehow put a scrollbar on that panel...
                                You have to use attachMultilineText instead of setText or whatever is currently used. The civilopedia file (CvPedia*) have a number of examples of this.

                                Originally posted by Nevs23
                                I'm a bit confused... in which file i have to add those lines (for example)? "CvEventManager.py"?
                                Yes.

                                Originally posted by Mylon
                                Would I put this in onEndTurn? And how would I make sure it processes for every city?
                                onCityDoTurn would seem like the best event for this, it gets called for every city at the start of every turn, when production, food, etc get updated for the new turn.

                                You can't just change the value of YieldTypes.YIELD_FOOD though, that's just the index of the food value, not the actual food value. You can't manipulate in-game variables such as food, hitpoints, etc directly, you have to do so through functions. The onCityDoTurn event gives you a city argument, so the second line in your example would have to be something like:

                                Code:
                                pCity.changeFood(Pycity.getFoodRate() * (getGoodHealth() -  getBadHealth()) * 0.05)
                                Originally posted by Fintilgin
                                Anyone have any suggestion on how I can forbid certain civs from getting certain religions?
                                You're not far off by quoting the overrides bit. You can actually sort of see an example of this in the Greek World scenario, where the founding of Christianity is forbidden until ~1 AD. By default the override functions in CvGameUtils.py return false, if you make them return True (under certain circumstances), an event is stopped. With doHolyCityTech you can allow and disallow cities from founding religions, but I don't think it's really designed to deal with several religions being founded with the same tech. You may have to wait for the SDK to be released to modify the source code so that you can actually run this override once per religion rather than once per tech. When I have time I'll play around with this myself and if it works as I think it does, I can fix this myself and request Firaxis to add my fix to the next patch. But I'm not sure when I'll get around to it, might be a while.

                                Originally posted by craig_sutter
                                I want to create a map script that recreates the same map every time, but randomizes resource placement. Can I simply input coordinates for each terrain type in the relevant portion of the script(cutting and pasting from the BMP-WBS converter values), or is it more complex than that? Can I preplace cities, units, and generate tech levels in the map script, as well?
                                I'm by no means an expert when it comes to map scripts, that's Sirian's terrain. You might want to start a seperate thread, that might draw his attention.

                                That said, I think this was actually discussed by some of the testers and it was concluded that it would require some serious changes to the current setup. It would probably be best to just create a pre-set WBS map without resources and write a seperate Python routine (that could probably be very similar to the ones used in the map scripts) to place resources at the start of the game. Doing it the other way around of having a map script and just removing all the randomness in it would likely be much harder, but as said, I'm not the guy to ask.

                                Originally posted by Spocko
                                So, if I want to modify a certain PY file, I should copy it to the MODS folder, edit that copy in the mods folder, and leave it there, while keeping the original PY file in its original directory? This sounds like the system first grabs PY's in the Mods folder and then collects from the original folders any PYs that are not found in the Mods, right?
                                Yes, exactly. I should add though that I've recently learned that you can also place your changed files in the CustomAssets folder if you want them to apply to all games, not just to one mod (but still without affecting patches, MP, etc). But the idea remains the same: the system first gets the file from the mod folder, then (I think) from CustomAssets, then from Assets. The CustomAssets thing was added (or at least functional) very late so I have no experience with it yet.
                                Administrator of WePlayCiv -- Civ5 Info Centre | Forum | Gallery

                                Comment

                                Working...
                                X