Difference between revisions of "Development:Python:AI Scripts"
(added categories) |
|||
Line 8: | Line 8: | ||
Let me talk about AI scripts briefly. | Let me talk about AI scripts briefly. | ||
− | You'll notice a nice AI script named printhello.py | + | You'll notice a nice AI script named '''[http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/vegastrike/data/printhello.py?rev=HEAD&content-type=text/vnd.viewcvs-markup printhello.py]'''. It is very similar to a mission with a few notable differences. {{fixme}} ''This is a reference to the old pre 4.0 data'' |
* First of all the AI class you make must inherit from the class '''VS.PythonAI'''. | * First of all the AI class you make must inherit from the class '''VS.PythonAI'''. | ||
− | * Secondly instead of having an '''__init__ ''' function it must have an '''init()''' function. The reasons for this have something to do with how inheritance works from C++, but this init function takes in self of course and the unit to which thie AI script belongs. '''__init__''' may start off some AI scripts from the get go, or you may wait until you execute each frame. in this case printhello loads the XML script '''++turntowards.xml''' (which is the hard coded C++ equivalent to '''ai/scripts/turntowards.xml'''). After loading that AI script it replaces its parents order with the last AI script, in this case the XML script. In the Execute function this AI script calls Execute on the higher level (which takes care of responding to communications) and then prints h to the console for no apparent reason. | + | * Secondly instead of having an '''__init__ ''' function it must have an '''init()''' function. The reasons for this have something to do with how inheritance works from C++, but this init function takes in self of course and the unit to which thie AI script belongs. '''__init__''' may start off some AI scripts from the get go, or you may wait until you execute each frame. in this case printhello loads the XML script '''++turntowards.xml''' (which is the hard coded C++ equivalent to '''[http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/vegastrike/data4.x/ai/scripts/turntowards.xml?rev=HEAD&content-type=text/vnd.viewcvs-markup ai/scripts/turntowards.xml]'''). After loading that AI script it replaces its parents order with the last AI script, in this case the XML script. In the Execute function this AI script calls Execute on the higher level (which takes care of responding to communications) and then prints h to the console for no apparent reason. |
* Lastly and most importantly, the AI script makes a new class for itself. So when the C++ code executes '''printhello.py''' it will call the C++ constructor which will take care of binding it. So when you make a new unit like so: | * Lastly and most importantly, the AI script makes a new class for itself. So when the C++ code executes '''printhello.py''' it will call the C++ constructor which will take care of binding it. So when you make a new unit like so: | ||
<pre> | <pre> |
Revision as of 06:34, 23 March 2005
Missions | Edit Missions | Python Bindings |
Let me talk about AI scripts briefly.
You'll notice a nice AI script named printhello.py. It is very similar to a mission with a few notable differences. FIXME This is a reference to the old pre 4.0 data
- First of all the AI class you make must inherit from the class VS.PythonAI.
- Secondly instead of having an __init__ function it must have an init() function. The reasons for this have something to do with how inheritance works from C++, but this init function takes in self of course and the unit to which thie AI script belongs. __init__ may start off some AI scripts from the get go, or you may wait until you execute each frame. in this case printhello loads the XML script ++turntowards.xml (which is the hard coded C++ equivalent to ai/scripts/turntowards.xml). After loading that AI script it replaces its parents order with the last AI script, in this case the XML script. In the Execute function this AI script calls Execute on the higher level (which takes care of responding to communications) and then prints h to the console for no apparent reason.
- Lastly and most importantly, the AI script makes a new class for itself. So when the C++ code executes printhello.py it will call the C++ constructor which will take care of binding it. So when you make a new unit like so:
VS.launch (fgname,type,faction,"unit","printhello.py",nr_ships,nr_waves,vec,logo)
it will have this python AI attached to it. However if you are too lazy to write AI's you can use the most excellent default AI
VS.launch (fgname,type,faction,"unit","default",nr_ships,nr_waves,vec,logo)
Missions | Edit Missions | Python Bindings |