Advertisement
Civilization Fanatics' Center  

Welcome to Civilization Fanatics' Center.

You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support.

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python

Notices

Reply
 
Thread Tools
Old Aug 12, 2010, 08:29 PM   #1
Jarlaxe Baenre
Secular Humanist
 
Jarlaxe Baenre's Avatar
 
Join Date: Feb 2010
Location: Alberta, Canada
Posts: 1,675
Civ4 BTS Units built on national wonder completion

How would you, for example, get all cities within (59, 48) and (66, 54) to receive 3 units (Musketman, Rifleman, Infantry, Marine, whichever is the most modern the civ can build) upon completion of a specific building? (Let's say "BUILDING_WALKÜRE" or whatever it would be called in python)
If I can't remove the German UP, I'll improve it
Jarlaxe Baenre is offline   Reply With Quote
Old Aug 12, 2010, 09:50 PM   #2
Baldyr
"Hit It"
 
Baldyr's Avatar
 
Join Date: Dec 2009
Location: Sweden
Posts: 5,530
First of all, you launch your code with the onBuildingBuilt callup in CvEventManager. The second argsList value is the building type, so the conditional statement would read:
Code:
if argsList[1] == buildingTypes.BUILDING_WALKÜRE:
You loop the coordinates with:
Code:
for iX in range(59, 66+1):
    for iY in range(48, 54+1):
You check every tile for a city with:
Code:
pPlot = gc.getMap().plot(iX, iY)
if pPlot.isCity():
Then you get the current unit type for each city with:
Code:
pCity = pPlot.getPlotCity()
eUnitType = pCity.getConscriptionUnit()
And finally you spawn the unit with:
Code:
player = PyHelpers.PyPlayer(ePlayer)
player.initUnit(eUnitType, iX, iY, 3)
The marked line requires two things: Firstly you need to know which player ID gets the spawned units, and secondly you need to import the PyHelpers module - if it isn't imported already in the module your working with.

To get the player ID you can use the line:
Code:
ePlayer = argsList[0].getOwner()
Some practical help with this can be found in my Python tutorial.
__________________
How to Make a Python Mod - Python modding tutorial
CivIV Python Class Reference - modding Python API
How to Think Like a Computer Scientist - online Python textbook
CivPlayer - Python scripting tool
Spoiler:
Q: Who is the woman in the avatar image?
A: Miss Li.
Q: Why does she have a brass-eye?
A: It's a conceptual thing. More of the same on the profile page.

Q: What does you title mean?
A: That is the title of Miss Li's latest single.
Baldyr is offline   Reply With Quote
Old Aug 13, 2010, 04:37 PM   #3
Jarlaxe Baenre
Secular Humanist
 
Jarlaxe Baenre's Avatar
 
Join Date: Feb 2010
Location: Alberta, Canada
Posts: 1,675
Where would I type all that? Can it just be anywhere? (But in order, of course)
Jarlaxe Baenre is offline   Reply With Quote
Old Aug 13, 2010, 04:47 PM   #4
The_J
Say No 2 Net Validations

 
The_J's Avatar
 
Join Date: Oct 2008
Location: Germany / Netherlands
Posts: 24,867
Images: 51
In Assets\Python\CvEventManager.py, one example:
PHP Code:
    def onBuildingBuilt(selfargsList):
                print 
'onBuildingBuilt'
        'Building Completed'
        
pCityiBuildingType argsList
        game 
gc.getGame()
    
###new code
        
if iBuildingType == gc.getInfoTypeForString'BUILDING_MT_RUSHMORE' ):
                        
iX ppCity.getX()
                        
iY ppCity.getY()
                        
pPlayer gc.getPlayer(pCity.getOwner())
                        
iUnit gc.getInfoTypeForString'UNIT_MACEMAN' )
                        
pNewUnit pPlayer.initUnitiUnitiXiYUnitAITypes.UNITAI_CITY_DEFENSEDirectionTypes.NO_DIRECTION 
__________________
Civ4-BtS-Mod "Mars, Now!"


Steam eats the souls of little gamers!!!
The_J is offline   Reply With Quote
Old Aug 14, 2010, 01:20 AM   #5
Baldyr
"Hit It"
 
Baldyr's Avatar
 
Join Date: Dec 2009
Location: Sweden
Posts: 5,530
Quote:
Originally Posted by Jarlaxe Baenre View Post
Where would I type all that? Can it just be anywhere? (But in order, of course)
Note that you also have to consider things like indentation. I you're gonna start programming, you really should learn some of the basics first. Just a suggestion.

So I intentionally didn't do your mod for you, as then you wouldn't have to learn anything. Just tell me if you're not interested and I can do the whole thing to your specifications. Then you wouldn't have to bother with it.

And most of these things are explained in the tutorial.
__________________
How to Make a Python Mod - Python modding tutorial
CivIV Python Class Reference - modding Python API
How to Think Like a Computer Scientist - online Python textbook
CivPlayer - Python scripting tool
Spoiler:
Q: Who is the woman in the avatar image?
A: Miss Li.
Q: Why does she have a brass-eye?
A: It's a conceptual thing. More of the same on the profile page.

Q: What does you title mean?
A: That is the title of Miss Li's latest single.

Last edited by Baldyr; Aug 15, 2010 at 05:04 AM.
Baldyr is offline   Reply With Quote
Old Aug 14, 2010, 03:21 PM   #6
Baldyr
"Hit It"
 
Baldyr's Avatar
 
Join Date: Dec 2009
Location: Sweden
Posts: 5,530
Also, I now realize you're mod-modding RFC, right?

Then you would add the code in the UniquePowers module with its own function definition:
Code:
        def germanUP(self, argsList):
Note that the indentation for all code must match. RFC modules mostly use 8 blank spaces for each indentation level. And the indentation levels goes up whenever the previous line ends with a colon, like the definition line above.

This function (really a method of the UniquePowers class, don't ask) would then be called from the onBuildingBuilt callup in CvRFCEventHandler module, like:
Code:
                self.up.germanUP(argsList)
This is basically it, but there are a good number of places you could mess this one up.
__________________
How to Make a Python Mod - Python modding tutorial
CivIV Python Class Reference - modding Python API
How to Think Like a Computer Scientist - online Python textbook
CivPlayer - Python scripting tool
Spoiler:
Q: Who is the woman in the avatar image?
A: Miss Li.
Q: Why does she have a brass-eye?
A: It's a conceptual thing. More of the same on the profile page.

Q: What does you title mean?
A: That is the title of Miss Li's latest single.
Baldyr is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python > [PYTHON] Units built on national wonder completion

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
out dated units cant be built?? Vietcong Civ4 - General Discussions 11 Jul 26, 2006 01:36 PM
Units I never built kokomo Civ4 - General Discussions 63 May 30, 2006 02:17 AM
Any units you've never built? madmaven Civ4 - General Discussions 58 Dec 14, 2005 12:27 PM
Units that can't be Built, but CAN be Upgraded to Mr. Do Civ3 - Creation & Customization 29 Jul 19, 2004 06:47 AM


Advertisement

All times are GMT -6. The time now is 07:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR