From: <geo...@us...> - 2007-05-26 02:25:29
|
Revision: 2059 http://svn.sourceforge.net/freeorion/revision/?rev=2059&view=rev Author: geoffthemedio Date: 2007-05-25 19:25:31 -0700 (Fri, 25 May 2007) Log Message: ----------- -Tweaked AIInterface to take std::strings insntead of const char* for LogOutput. -Made PythonAI send player 0 a CHAT_MSG every turn -Made MapWnd clear its chat history after ending a game Modified Paths: -------------- trunk/FreeOrion/AI/AIInterface.cpp trunk/FreeOrion/AI/AIInterface.h trunk/FreeOrion/AI/FreeOrionAI.py trunk/FreeOrion/AI/PythonAI.cpp trunk/FreeOrion/UI/MapWnd.cpp Modified: trunk/FreeOrion/AI/AIInterface.cpp =================================================================== --- trunk/FreeOrion/AI/AIInterface.cpp 2007-05-25 18:19:06 UTC (rev 2058) +++ trunk/FreeOrion/AI/AIInterface.cpp 2007-05-26 02:25:31 UTC (rev 2059) @@ -229,7 +229,7 @@ void LoadState() {} - void LogOutput(char const* log_text) + void LogOutput(const std::string& log_text) { Logger().debugStream() << "AI Log : " << log_text; } Modified: trunk/FreeOrion/AI/AIInterface.h =================================================================== --- trunk/FreeOrion/AI/AIInterface.h 2007-05-25 18:19:06 UTC (rev 2058) +++ trunk/FreeOrion/AI/AIInterface.h 2007-05-26 02:25:31 UTC (rev 2059) @@ -62,7 +62,7 @@ //@} /** Misc */ //@{ - void LogOutput(char const* log_text); ///< output text to logfile + void LogOutput(const std::string& log_text); ///< output text to logfile //@} }; Modified: trunk/FreeOrion/AI/FreeOrionAI.py =================================================================== --- trunk/FreeOrion/AI/FreeOrionAI.py 2007-05-25 18:19:06 UTC (rev 2058) +++ trunk/FreeOrion/AI/FreeOrionAI.py 2007-05-26 02:25:31 UTC (rev 2059) @@ -5,4 +5,5 @@ def GenerateOrders(): foaiint.DoneTurn() + foaiint.SendChatMessage(0, "Sending chat message from within Python!") foaiint.LogOutput("Generated Orders") \ No newline at end of file Modified: trunk/FreeOrion/AI/PythonAI.cpp =================================================================== --- trunk/FreeOrion/AI/PythonAI.cpp 2007-05-25 18:19:06 UTC (rev 2058) +++ trunk/FreeOrion/AI/PythonAI.cpp 2007-05-26 02:25:31 UTC (rev 2059) @@ -13,20 +13,24 @@ boost::python::def("DoneTurn", AIInterface::DoneTurn); + boost::python::def("SendChatMessage", AIInterface::SendPlayerChatMessage); + boost::python::def("LogOutput", AIInterface::LogOutput); } /////////////////////// // PythonAI // /////////////////////// -using boost::python::borrowed; - PythonAI::PythonAI() { + using boost::python::borrowed; + Py_Initialize(); // initializes Python interpreter, allowing Python functions to be called from C++ initfoaiint(); // allows the "foaiint" C++ module to be imported within Python code + + // get access to Python main namespace, which is needed to call other functions below try { main_module = PyOBJECT((PyHANDLE(borrowed(PyImport_AddModule("__main__"))))); dict = PyOBJECT(main_module.attr("__dict__")); @@ -37,6 +41,7 @@ PyHANDLE handle; + // import Python built-in sys module, giving access to sys.path below try { handle = PyHANDLE(PyRun_String("import sys", Py_file_input, dict.ptr(), dict.ptr())); } catch (PyERROR err) { @@ -44,7 +49,7 @@ return; } - + // tell Python the path in which to locate AI script file std::string AI_DIR("C:\\FreeOrion\\AI"); std::string python_path_command = "sys.path.append('" + AI_DIR + "')"; try { @@ -54,15 +59,15 @@ return; } - + // load Python script of AI functions try { handle = PyHANDLE(PyRun_String("import FreeOrionAI", Py_file_input, dict.ptr(), dict.ptr())); } catch (PyERROR err) { - Logger().errorStream() << "error importing blah"; + Logger().errorStream() << "error importing FreeOrionAI.py into Python"; return; } - + // initialize AI within Python try { handle = PyHANDLE(PyRun_String("FreeOrionAI.InitFreeOrionAI()", Py_file_input, dict.ptr(), dict.ptr())); } catch(PyERROR err) { Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2007-05-25 18:19:06 UTC (rev 2058) +++ trunk/FreeOrion/UI/MapWnd.cpp 2007-05-26 02:25:31 UTC (rev 2059) @@ -1486,6 +1486,7 @@ Cleanup(); m_side_panel->MoveTo(GG::Pt(GG::GUI::GetGUI()->AppWidth() - SIDE_PANEL_WIDTH, m_toolbar->LowerRight().y)); m_chat_display->MoveTo(GG::Pt(LAYOUT_MARGIN, m_turn_update->LowerRight().y + LAYOUT_MARGIN)); + m_chat_display->Clear(); m_chat_edit->MoveTo(GG::Pt(LAYOUT_MARGIN, GG::GUI::GetGUI()->AppHeight() - CHAT_EDIT_HEIGHT - LAYOUT_MARGIN)); m_sitrep_panel->MoveTo(GG::Pt((GG::GUI::GetGUI()->AppWidth() - SITREP_PANEL_WIDTH) / 2, (GG::GUI::GetGUI()->AppHeight() - SITREP_PANEL_HEIGHT) / 2)); m_sitrep_panel->Resize(GG::Pt(SITREP_PANEL_WIDTH, SITREP_PANEL_HEIGHT)); |