Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pythonai.cpp
Go to the documentation of this file.
1 #include <Python.h>
2 #include <compile.h>
3 #include <eval.h>
4 #include <stdio.h>
5 #include <boost/version.hpp>
6 #if BOOST_VERSION != 102800
7 #include <boost/python/class.hpp>
8 #else
9 #include <boost/python/class_builder.hpp>
10 #include <boost/python/detail/extension_class.hpp>
11 #endif
12 #include "python/python_class.h"
13 #include "python/python_compile.h"
14 #include "config_xml.h"
15 #include "vs_globals.h"
16 #include "vsfilesystem.h"
17 #include "pythonai.h"
18 using namespace Orders;
19 PythonAI*PythonAI::last_ai = NULL;
20 PythonAI::PythonAI( PyObject *self_, float reaction_time, float aggressivity ) : FireAt( reaction_time, aggressivity )
21 {
22  self = self_;
23  //boost::python:
24  Py_XINCREF( self ); //by passing this to whoami, we are counting on them to Destruct us
25  last_ai = this;
26 }
28 {
29  Py_XDECREF( self ); //this should destroy SELF
30 }
32 {
33  (self_).FireAt::Execute();
34 }
36 {
37  PythonAI *myai = last_ai;
38  last_ai = NULL;
39  return myai;
40 }
41 PythonAI* PythonAI::Factory( const std::string &filename )
42 {
43  CompileRunPython( filename );
44  return LastAI();
45 }
47 {
48  boost::python::callback< void >::call_method( self, "Execute" );
49 }
51 {
52  boost::python::module_builder ai_builder( "AI" );
53  boost::python::class_builder< FireAt, PythonAI >BaseClass( ai_builder, "FireAt" );
54 
55  BaseClass.def( boost::python::constructor< float, float > () );
56  BaseClass.def( &FireAt::Execute, "PythonAI", PythonAI::default_Execute );
57 }
59 {
60  VSFileSystem::vs_fprintf( stderr, "Destruct called. If called from C++ this is death %ld (%lx)", (unsigned long) this,
61  (unsigned long) this );
62 }
63