[Gcblue-commits] gcb_wx/src/scriptinterface tcScenarioInterface.cpp,1.17,1.18 tcSimPythonInterface.c
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-02-16 23:13:57
|
Update of /cvsroot/gcblue/gcb_wx/src/scriptinterface In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15507/src/scriptinterface Modified Files: tcScenarioInterface.cpp tcSimPythonInterface.cpp Log Message: Parallel ai update Index: tcSimPythonInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcSimPythonInterface.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** tcSimPythonInterface.cpp 4 Feb 2005 18:50:35 -0000 1.26 --- tcSimPythonInterface.cpp 16 Feb 2005 23:13:49 -0000 1.27 *************** *** 2,6 **** ** @file tcSimPythonInterface.cpp */ ! /* Copyright (C) 2003-2004 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 2,6 ---- ** @file tcSimPythonInterface.cpp */ ! /* Copyright (C) 2003-2005 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 38,41 **** --- 38,43 ---- #include "tcSoundConsole.h" #include "tcDirector.h" + #include "ai/ScriptedTask.h" + #include "ai/ScriptedTaskInterface.h" #ifdef _DEBUG *************** *** 142,147 **** ! // write apObj --- 144,156 ---- + /** + * Singleton accessor + */ + tcSimPythonInterface* tcSimPythonInterface::Get() + { + static tcSimPythonInterface instance; ! return &instance; ! } // write apObj *************** *** 151,167 **** ! void tcSimPythonInterface::CallPlatformScript(tcPlatformObject *apObj, char *azCommand) { - /* - SetUnitInfo(apObj); - PlatformInterface.attr("GetLocalObj")(); - */ platformInterface->SetPlatform(apObj); ! try { handle<>( PyRun_String(azCommand , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); } ! catch(error_already_set) { // handle the exception in some way fprintf(stderr,"Exception occured\n"); --- 160,174 ---- ! void tcSimPythonInterface::CallPlatformScript(tcPlatformObject *apObj, const char* azCommand) { platformInterface->SetPlatform(apObj); ! try ! { handle<>( PyRun_String(azCommand , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); } ! catch(error_already_set) ! { // handle the exception in some way fprintf(stderr,"Exception occured\n"); *************** *** 170,173 **** --- 177,203 ---- } + + /** + * Task script for ai + */ + void tcSimPythonInterface::CallTaskScript(ScriptedTask* task, const char* azCommand) + { + wxASSERT(taskInterface); + + taskInterface->SetTask(task); + + try + { + handle<>( PyRun_String(azCommand + , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); + } + catch (error_already_set) + { + // handle the exception in some way + fprintf(stderr,"Exception occured in CallTaskScript\n"); + PyErr_Print(); + } + } + tcFlightPort* tcSimPythonInterface::GetHookedObjFlightPort() { *************** *** 754,757 **** --- 784,791 ---- ScenarioInterface = scenarioInterfaceType(); + ScriptedTaskInterface tempInterface; + TaskInterfaceObject = object(tempInterface); + taskInterface = extract<ScriptedTaskInterface*>(TaskInterfaceObject); + // add PlatformInterface to python environment as global var // called "UnitInfo" *************** *** 764,767 **** --- 798,802 ---- PyDict_SetItemString(mpDictionary->ptr(), "ScenarioManager", ScenarioInterface.ptr()); PyDict_SetItemString(mpDictionary->ptr(), "GroupInfo", GroupInterface.ptr()); + PyDict_SetItemString(mpDictionary->ptr(), "TaskInterface", TaskInterfaceObject.ptr()); PyDict_SetItemString(mpDictionary->ptr(), "Y", PyInt_FromLong(2)); /* dict['Y']=2 */ Index: tcScenarioInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcScenarioInterface.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** tcScenarioInterface.cpp 31 Jan 2005 01:33:08 -0000 1.17 --- tcScenarioInterface.cpp 16 Feb 2005 23:13:49 -0000 1.18 *************** *** 46,49 **** --- 46,50 ---- #include "tcStores.h" #include "tcSubObject.h" + #include "ai/Brain.h" #include "wxcommands.h" *************** *** 51,54 **** --- 52,56 ---- using namespace std; using namespace boost::python; + using ai::Brain; #ifdef _DEBUG *************** *** 137,140 **** --- 139,143 ---- .def("AddUnitToAlliance",&tcScenarioInterface::AddUnitToAlliance) .def("AddUnitToFlightDeck",&tcScenarioInterface::AddUnitToFlightDeck) + .def("AddUnitTask", &tcScenarioInterface::AddUnitTask) .def("AddToUnitMagazine",&tcScenarioInterface::AddToUnitMagazine) .def("SetUnitLauncherItem",&tcScenarioInterface::SetUnitLauncherItem) *************** *** 322,325 **** --- 325,352 ---- } } + + /** + * Adds task to unit (newer AI system with parallel tasks) + * Logs error if unit is not eligible + */ + void tcScenarioInterface::AddUnitTask(const std::string& unitName, const std::string& taskName, + double priority) + { + wxASSERT(simState); + tcGameObject* parentObj = simState->GetObjectByName(unitName); + if (tcPlatformObject* platform = dynamic_cast<tcPlatformObject*>(parentObj)) + { + ai::Brain* brain = platform->GetBrain(); + wxASSERT(brain); + brain->AddTask(taskName, priority); + } + else + { + fprintf(stderr, "tcScenarioInterface::AddUnitTask - " + "Unit not found: %s\n", unitName.c_str()); + } + + } + /** |