Mini Dev Journal:
In my opinion, you can't really appreciate the advantages of something like Boost.Python until you've done it the long way first. On top of that, when we first started Elemental, we wanted to see what our possibilities were as far as scripting went.
So we started looking into Python. I was assigned to get it in the game and doing something... anything. So I started with a script called Music.py. It was called once per turn. The script would get the turn number from the game, and would tell the sound system to play a different track depending on the turn number (for turns 1, 5, and 10 if I remember correctly). Again, this was just a test bed, and sort of a proof-of-concept. So we used the Python/C API, because that's what the python docs show you how to do.
During this time, I also created a more complicated test script called Missions.py that would create mission objects on the map, and when the player collided with them, it would call the script again to see what to do. Still, this was just a test to see how things worked.
Fast forward a bunch of time, and we're back to working on Elemental full steam and we realize that the python stuff hasn't been touched since way back when we did these test scripts. But, as we work on AI (a very iterative process), we find that if we could just get it to work via python then we could iterate much faster with our AI behavior changes without having to close the game, change the c++ code and then compile and run the game again.
So again, I use the python/c API to expose parts of our c++ AI functionality to a script. One reason for this is because I already know how it works (because of having done it for test scripts already). Another reason is that it needed to be done soon. The third reason is to see how much code it actually takes to expose this stuff using python/c API.
In the script, which is called once per turn per AI player, it would just test to see if it could build a city, and then do it if so (this functionality is exposed from the game). Clearly this isn't smart AI, they don't even move around, they just plop down one city and camp there. But, it was a quick and dirty way to see how much python/c API wrapper code was necessary to even expose this little amount of functionality.
Now that we had experienced the pain of doing it the "hard" way, it was time to look to the "supposedly easier" way. Enter Boost.Python. Boost is a collection of all sorts of useful and common functionality that isn't already built into the standard c++ language. Some things that were part of Boost in the past have now become part of the standard c++ language. We use various parts of Boost throughout our games, even in GalCiv2. Anyway, Boost.Python is a section of Boost that deals with working with Python.
That's kind of where we're at right now. Learning how Boost.Python works so we can use it and see the savings in wrapper code, so that we can quickly expose parts of our game to python so that the AI can be quickly iterated on using python scripts that can be changed while the game is running.
~C
ps. To answer some replies above:
Q: Don't you know about Boost.Python
A: Yes. And I'm neck deep in the docs but thanks for the link anyway.
Q: I can't believe you're using IDLE. ...IDLE is way too clunky ...who the hell would use IDLE anymore??
A: It came with the Python install. We haven't written much Python code yet, in fact the test scripts were written in notepad if I remember correctly. The AI one is where I used IDLE, because the python docs mention it and it was already on my PC from when I installed Python. We do appreciate the other IDE suggestions, so thanks!
Q: have you tried looking at SWIG yet?
A: There was an article about SWIG in Game Developer magazine this month. It discussed using SWIG with Lua and C# though, but did mention that it could be used with Python and C++. In the end I think we'll likely stick with Boost.Python.