First foray into python (please help!)

moopoo

King
Joined
Jan 5, 2008
Messages
729
Location
Adelaide, Australia
I'm attempting a (hopefully) small modcomp and am looking for advice/a couple of suggestion :)

I'm looking to script in python the idea of a port: Workers can build a port on any coastal square (as in, the land square next to the water) that isn't in a city radius. Cities that are surrounded by land can then build boats, which would appear at a port. possibly at a cost increase dependant on the distance from the port.

does anyone have any suggestions as to how to go about this? Advice i am especially looking for is which functions, in the API or otherwise (just incase there's something else), would be most useful. Please keep in mind that while I have read and attempted several python tutorial's and have a basic understanding, this is my first attempt at programming/scripting (i'm so new to this i don't know which word applies here :lol: ), and i'm new to all of this.
 
Moderator Action: Thread moved to SDK/python area. You should receive excellent service here.
 
You can make the port act like a city to allow ships there. Unless you have a problem with the other things it'll do then, like give the resource if any. I don't know if you can limit it to outside city borders in just XML, if you can't there's canBuild in CvGameUtils.py to make it so.

There's a canTrain function in CvGameUtils.py. If you return true the city in question should be able to build ships even if it's not costal. CyPlayer has a function called getImprovementCount to see if the player has any ports, but you'll problably want your own check aswell to make sure it's on the same area. Would be weird to build a ship and have it appear on another continent ;)

In CvEventManager there's onUnitBuilt which is called when a unit is finished. Here you can move the unit to the appropriate place (which you'll have to find first).
 
At the Risk of sounding really dumb, could someone please run through this with me, or direct me to a post? How do I implement code that i've written?
This is the impression i have thus far gotten:
1. Write the code and save it to an appropriate temporary location
2. Create a mod folder, Assets, Python
3. This is where i'm stuck
Do I copy and paste the code into a file like CvEventManager, or CvGameUtils? or do i stick an "import blah" at the top, and move my python file? or something completely different?
Any help would be Hot, as the great Jar Jar would say
 
1. Create a mod folder, assets, python.
2. Copy the python files you want there.
3. Change the copied files to what you want.

You can change the files while playing the game (windowed mode recommended). Once you save them the game will reload them.
 
WOW! Didn't know that. I figured I'd save my file in there (e.g Ports.py) and stick an 'import Ports' into the top of CvEventManager. Cool, thanks
 
You can do that too if you want to.
 
Back
Top Bottom