Code: Select all
Index: SConscript
===================================================================
--- SConscript (revision 2073)
+++ SConscript (working copy)
@@ -71,7 +71,8 @@
'universe/Universe.cpp',
'util/AppInterface.cpp',
'AI/AIInterface.cpp',
- 'AI/ReferenceAI.cpp'
+ 'AI/ReferenceAI.cpp',
+ 'AI/PythonAI.cpp'
]
target = 'ai'
Index: AI/PythonAI.h
===================================================================
--- AI/PythonAI.h (revision 2073)
+++ AI/PythonAI.h (working copy)
@@ -1,9 +1,9 @@
-#include "AIInterface.h"
-
#include <boost/python.hpp>
#include <string>
+#include "AIInterface.h"
+
class PythonAI : public AIBase
{
public:
Index: SConstruct
===================================================================
--- SConstruct (revision 2073)
+++ SConstruct (working copy)
@@ -62,6 +62,9 @@
options.Add('with_gg', 'Root directory of GG installation')
options.Add('with_gg_include', 'Specify exact include dir for GG headers')
options.Add('with_gg_libdir', 'Specify exact library dir for GG library')
+options.Add('with_python_include', 'Specify exact include dir for Python headers')
+options.Add('with_python_libdir', 'Specify exact library dir for Python library')
+options.Add('python_version', 'Version of python to link against. For example python_version=2.4 will link against libpython2.4.so or python2.4.dll')
if str(Platform()) == 'win32':
options.Add('with_zlib', 'Root directory of zlib installation')
options.Add('with_zlib_include', 'Specify exact include dir for zlib headers')
@@ -180,6 +183,42 @@
else:
print 'Configuring unknown system (assuming the system is POSIX-like) ...'
+ # Python
+ if str(Platform()) == 'posix':
+ python_include = ''
+ python_version = ''
+ python_libdir = ''
+ if env.has_key('with_python_include') and env['with_python_include'] != '':
+ python_include = env['with_python_include']
+ else:
+ for version in ['2.4', '2.5']:
+ include_path_guess = '/usr/include/python' + version
+ if os.access(include_path_guess, os.R_OK):
+ python_include = include_path_guess
+ python_version = version
+ if python_include == '':
+ print 'Failed to guess location of python headers.'
+ print 'Use with_python_include, with_python_libdir and python_version command line options.'
+ Exit(1)
+ if env.has_key('with_python_libdir') and env['with_python_libdir'] != '':
+ python_libdir = env['with_python_libdir']
+ else:
+ python_libdir = '/usr/lib'
+ if env.has_key('python_version') and env['python_version'] != '': python_version = env['python_version']
+ else:
+ if not (env.has_key('with_python_include') and env.has_key('with_python_libdir') and env.has_key('python_version')):
+ print 'Use with_python_include, with_python_libdir and python_version command line options.'
+ Exit(1)
+ else:
+ python_include = env['with_python_include']
+ python_libdir = env['with_python_libdir']
+ python_version = env['python_version']
+
+ env.AppendUnique(CPPPATH=[python_include])
+ env.AppendUnique(LIBPATH=[python_libdir])
+ if not conf.CheckLibWithHeader('python' + python_version, 'Python.h', 'C', 'Py_Initialize();'):
+ Exit(1)
+
####################################################################
# Configure GG requirements; use GG pkg-config first, if available #
####################################################################
@@ -194,7 +233,8 @@
freeorion_boost_libs = [
('boost_serialization', 'boost/archive/binary_iarchive.hpp', 'boost::archive::binary_iarchive::is_saving();'),
- ('boost_iostreams', 'boost/iostreams/filtering_stream.hpp', '')
+ ('boost_iostreams', 'boost/iostreams/filtering_stream.hpp', ''),
+ ('boost_python', 'boost/python.hpp', 'boost::python::throw_error_already_set();')
]
if found_gg_pkg_config:
Index: client/AI/AIClientApp.cpp
===================================================================
--- client/AI/AIClientApp.cpp (revision 2073)
+++ client/AI/AIClientApp.cpp (working copy)
@@ -1,3 +1,6 @@
+#include "../../AI/PythonAI.h"
+#include "../../AI/ReferenceAI.h"
+
#include "AIClientApp.h"
#include "../../util/MultiplayerCommon.h"
@@ -26,9 +29,6 @@
#include <boost/filesystem/fstream.hpp>
-#include "../../AI/ReferenceAI.h"
-//#include "../../AI/PythonAI.h"
-
// static member(s)
AIClientApp* AIClientApp::s_app = 0;
@@ -137,8 +137,8 @@
void AIClientApp::Initialize()
{
- m_AI = new ReferenceAI();
- //m_AI = new PythonAI();
+ //m_AI = new ReferenceAI();
+ m_AI = new PythonAI();
// join game at server
const int MAX_TRIES = 5;
int tries = 0;
boost/python.hpp #includes Python.h so it must be #included before standard headers and headers that may #include standard headers.Warning: Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included.