• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

SDK Questions

j_mie6

Deity
Joined
Dec 20, 2009
Messages
2,963
Location
Bristol (uni)/Swindon (home)
Hi!

Just had a couple of thoughts:

1) how do I define functions that can be exposed to python without the need of a class?

2) Python as the events manager. What does C++ do to use and manage it's methods?

3) how do I create and expose a new event (like onRebellionTriggered or something) into the python EventManager?

I had a little look around for 3 and I couldn't find anything for it...
 
Hi!

Just had a couple of thoughts:

1) how do I define functions that can be exposed to python without the need of a class?
Civ4 uses Boost Python, documentation here (the simple case is in the Quick Start section):
http://www.boost.org/doc/libs/1_32_0/libs/python/doc/tutorial/doc/html/index.html#python.quickstart

2) Python as the events manager. What does C++ do to use and manage it's methods?
In the end that are simple Python function calls from C++. See CvDllPythonEvents.cpp.

3) how do I create and expose a new event (like onRebellionTriggered or something) into the python EventManager?

I had a little look around for 3 and I couldn't find anything for it...
Check CvDllPythonEvents, follow the references and copy the pattern.
 
I don't quite understand how the python events call backs link to the ones in pythonEvents or how to mkae a new one, but the boost python seems pretty easy :p
 
I don't quite understand how the python events call backs link to the ones in pythonEvents or how to mkae a new one

In CvEventInterface.py you have the function onEvent Which is called from the C++ code (CvDllPythonEvents:: postEvent) with all the relevant event parameters, including the name (as the first argument).

onEvent calls handleEvent which is a method of the CvEventManager class which is defined in CvEventManager.py.
In this file you have EventHandlerMap which is a map of all the event names (listed in __init__, which is the class constructor).
Each event name is mapped there to an appropriate function, e.g. unitMove is mapped to self.onUnitMove (also a method of CvEventManager).
Note that the function name doesn't have to match the event name. It's just convenient.

You can add your own event names and functions to this list, and then use CvDllPythonEvents:: postEvent from C++ to post it.
See any of the CvDllPythonEvents::report* methods in CvDllPythonEvents.cpp as examples.
 
but how do the events work?

I can see how C++ gets it's hands on them (and therefore code put in the post methods presumably runs C++ code on the python event) but how are the conditions made the for python event itself. How does python know that the turn is beginning or a unit is moving. In short, when defining a new event like onRebellion() how do you make the conditions for it?
 
As I said, search in the DLL code for all the places where postEvent is called.
You will need to add a function there (as well as in Python) for your new event, and add C++ code to call it where ever you need.
 
I still don't really understand... can you post an example of a function that is triggered when for example... the UN makes a resolution...

Also, how does C++ actually manage stuff ingame, like how are apostolic resolutions triggered and stuff?
 
Back
Top Bottom