[Gcblue-commits] gcb_wx/src/scriptinterface tcPlatformInterface.cpp,1.43,1.44 tcPlatformInterfaceExt
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-05-05 02:15:34
|
Update of /cvsroot/gcblue/gcb_wx/src/scriptinterface In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv777/src/scriptinterface Modified Files: tcPlatformInterface.cpp tcPlatformInterfaceExtensionB.cpp tcScenarioInterface.cpp tcSimPythonInterface.cpp Log Message: Index: tcPlatformInterfaceExtensionB.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcPlatformInterfaceExtensionB.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** tcPlatformInterfaceExtensionB.cpp 29 Apr 2005 18:52:54 -0000 1.23 --- tcPlatformInterfaceExtensionB.cpp 5 May 2005 02:14:53 -0000 1.24 *************** *** 146,149 **** --- 146,150 ---- .def("IsAvailable", &tcPlatformInterface::IsAvailable) .def("IsMultiplayerActive", &tcPlatformInterface::IsMultiplayerActive) + .def("ReleaseControl", &tcPlatformInterface::ReleaseControl) .def("TakeControl", &tcPlatformInterface::TakeControl) Index: tcSimPythonInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcSimPythonInterface.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** tcSimPythonInterface.cpp 29 Apr 2005 18:52:54 -0000 1.29 --- tcSimPythonInterface.cpp 5 May 2005 02:14:53 -0000 1.30 *************** *** 41,44 **** --- 41,46 ---- #include "ai/ScriptedTask.h" #include "ai/ScriptedTaskInterface.h" + #include "common/tcStream.h" + #include "common/tcObjStream.h" #ifdef _DEBUG *************** *** 120,124 **** * Begin a submenu in current menu */ ! void tcMenuInterface::BeginSubMenu(void) { if (mpMenu == NULL) {return;} mpMenu->BeginSubMenu(); --- 122,126 ---- * Begin a submenu in current menu */ ! void tcMenuInterface::BeginSubMenu() { if (mpMenu == NULL) {return;} mpMenu->BeginSubMenu(); *************** *** 128,132 **** * Clear menu */ ! void tcMenuInterface::Clear(void) { if (mpMenu == NULL) {return;} mpMenu->Clear(); --- 130,134 ---- * Clear menu */ ! void tcMenuInterface::Clear() { if (mpMenu == NULL) {return;} mpMenu->Clear(); *************** *** 136,140 **** * End submenu in current menu */ ! void tcMenuInterface::EndSubMenu(void) { if (mpMenu == NULL) {return;} mpMenu->EndSubMenu(); --- 138,142 ---- * End submenu in current menu */ ! void tcMenuInterface::EndSubMenu() { if (mpMenu == NULL) {return;} mpMenu->EndSubMenu(); *************** *** 155,158 **** --- 157,267 ---- } + + + /** + * Loads state from command stream + * MetaString of stream must be set to player name for control validation + */ + tcCommandStream& tcSimPythonInterface::operator<<(tcCommandStream& stream) + { + wxASSERT(!mpSimState->IsMultiplayerClient()); + + const std::string& playerName = stream.GetMetaString(); + + unsigned char nCommands; + stream >> nCommands; + + for (unsigned char n=0; n<nCommands; n++) + { + unsigned char nId; + stream >> nId; + + std::vector<long> idList; + for (unsigned char n=0; n<nId; n++) + { + long id; + stream >> id; + idList.push_back(id); + } + + std::string command; + stream >> command; + + if (command.size() < 128) + { + bool playerHasControl = true; + for (unsigned int n=0; (n<idList.size()) && playerHasControl; n++) + { + tcGameObject* obj = mpSimState->GetObject(idList[n]); + playerHasControl = obj->IsControlledBy(playerName); + } + if (playerHasControl) + { + #ifdef _DEBUG + long id0 = (idList.size() > 0) ? idList[0] : -1; + fprintf(stdout, "Script cmd (%d/%d): %s\n", id0, idList.size(), command.c_str()); + #endif + ProcessCallbackString(command, idList); + } + else + { + fprintf(stderr, "Script command issued for obj that player does not control, " + "player: %s\n", playerName.c_str()); + } + } + else + { + fprintf(stderr, "Overlength command string received from client\n"); + wxASSERT(false); + } + } + + return stream; + } + + + /** + * Saves state to command stream + */ + tcCommandStream& tcSimPythonInterface::operator>>(tcCommandStream& stream) + { + wxASSERT(mpSimState->IsMultiplayerClient()); + + wxASSERT(clientCommands.size() < 16); + + unsigned char nCommands = clientCommands.size(); + stream << nCommands; + + for (unsigned char n=0; n<nCommands; n++) + { + ClientCommand& cmd = clientCommands[n]; + + wxASSERT(cmd.idList.size() < 256); + unsigned char nId = cmd.idList.size(); + stream << nId; + + for (unsigned char n=0; n<nId; n++) + { + long id = cmd.idList[n]; + stream << id; + } + + stream << cmd.commandText; + } + + return stream; + } + + void tcSimPythonInterface::ClearNewCommand() + { + clientCommands.clear(); + } + + bool tcSimPythonInterface::HasNewCommand() const + { + return (clientCommands.size() > 0); + } + + // write apObj void tcSimPythonInterface::SetUnitInfo(tcPlatformObject *apObj) { *************** *** 521,529 **** if (param == -1) ! sprintf(zBuff,"Menu.%s(%s,%.3f)\n",command.c_str(),zObject,afData); else ! sprintf(zBuff,"Menu.%s(%s,%.3f,%d)\n",command.c_str(),zObject,afData,param); ! CallPython(zBuff,"Exception occured in ProcessCallback\n"); PopMode(); --- 630,649 ---- if (param == -1) ! sprintf(zBuff, "Menu.%s(%s,%.3f)\n",command.c_str(),zObject,afData); else ! sprintf(zBuff, "Menu.%s(%s,%.3f,%d)\n",command.c_str(),zObject,afData,param); ! if (!mpSimState->IsMultiplayerClient()) ! { ! CallPython(zBuff, "Exception occured in ProcessCallback\n"); ! } ! else ! { ! ClientCommand cmd; ! cmd.idList = id; ! cmd.commandText = std::string(zBuff); ! ! clientCommands.push_back(cmd); ! } PopMode(); *************** *** 555,559 **** command.c_str(),zObject,afData1,afData2,param); } ! CallPython(zBuff,"Exception occured in ProcessCallback\n"); PopMode(); --- 675,695 ---- command.c_str(),zObject,afData1,afData2,param); } ! ! ! ! if (!mpSimState->IsMultiplayerClient()) ! { ! CallPython(zBuff, "Exception occured in ProcessCallback\n"); ! } ! else ! { ! ClientCommand cmd; ! cmd.idList = id; ! unsigned nId = id.size(); ! ! cmd.commandText = std::string(zBuff); ! ! clientCommands.push_back(cmd); ! } PopMode(); *************** *** 584,588 **** sprintf(zBuff,"Menu.%s(%s,%d,%d)\n",command.c_str(),zObject,anData,param); ! CallPython(zBuff,"Exception occured in ProcessCallback\n"); PopMode(); --- 720,767 ---- sprintf(zBuff,"Menu.%s(%s,%d,%d)\n",command.c_str(),zObject,anData,param); ! ! if (!mpSimState->IsMultiplayerClient()) ! { ! CallPython(zBuff, "Exception occured in ProcessCallback\n"); ! } ! else ! { ! ClientCommand cmd; ! cmd.idList = id; ! cmd.commandText = std::string(zBuff); ! ! clientCommands.push_back(cmd); ! } ! ! PopMode(); ! } ! ! /** ! * Version with string that includes exact call syntax ! */ ! void tcSimPythonInterface::ProcessCallbackString(const std::string& command, const std::vector<long>& id) ! { ! PushMode(); ! SetMenuGroup(id); ! ! if (mpHookedObj == NULL) ! { ! PopMode(); ! return; ! } ! ! ! if (!mpSimState->IsMultiplayerClient()) ! { ! CallPython(command.c_str(), "Exception occured in ProcessCallbackString\n"); ! } ! else ! { ! ClientCommand cmd; ! cmd.idList = id; ! cmd.commandText = command; ! ! clientCommands.push_back(cmd); ! } PopMode(); *************** *** 603,608 **** if (!mpSimState->mpUserInfo->IsOwnAlliance(mpHookedObj->GetAlliance())) return; ! sprintf(zBuff,"Menu.ProcessHotKey(HookedUnitInfo,'%c')\n",key); ! CallPython(zBuff,"Exception occured in ProcessHotKey\n"); } --- 782,790 ---- if (!mpSimState->mpUserInfo->IsOwnAlliance(mpHookedObj->GetAlliance())) return; ! sprintf(zBuff, "Menu.ProcessHotKey(HookedUnitInfo,'%c')\n", key); ! ! ! CallPython(zBuff, "Exception occured in ProcessHotKey\n"); ! } Index: tcScenarioInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcScenarioInterface.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** tcScenarioInterface.cpp 29 Apr 2005 18:52:54 -0000 1.24 --- tcScenarioInterface.cpp 5 May 2005 02:14:53 -0000 1.25 *************** *** 107,112 **** tcMapOverlay* tcScenarioInterface::overlay = 0; tcSimState* tcScenarioInterface::simState = 0; ! // Interface class management functions void tcScenarioInterface::AddGoalClasses(boost::python::dict *dictionary) --- 107,120 ---- tcMapOverlay* tcScenarioInterface::overlay = 0; tcSimState* tcScenarioInterface::simState = 0; + + // non-python methods + + tcGameObject* tcScenarioInterface::GetLastObjectAdded() const + { + return lastObjectAdded; + } ! ! // Interface class management methods void tcScenarioInterface::AddGoalClasses(boost::python::dict *dictionary) *************** *** 194,197 **** --- 202,207 ---- bool tcScenarioInterface::AddUnitToAlliance(tcScenarioUnit unit, int alliance) { + lastObjectAdded = 0; + if (!unit.Validate()) return false; *************** *** 205,209 **** fprintf(stderr, errorMessage.c_str()); ! wxMessageBox(errorMessage.c_str(), "Error", wxICON_ERROR); return false; } --- 215,223 ---- fprintf(stderr, errorMessage.c_str()); ! // don't popup errors if sim is running ! if (simState->GetTime() == 0) ! { ! wxMessageBox(errorMessage.c_str(), "Error", wxICON_ERROR); ! } return false; } *************** *** 229,232 **** --- 243,249 ---- gameObj->mfStatusTime = 0; // for lack of a better time gameObj->mzUnit = unit.unitName.c_str(); + + float terrainHeight = mapData->GetTerrainHeight(unit.lon, unit.lat, 0); + // class-specific initialization if (tcPlatformObject *platObj = dynamic_cast<tcPlatformObject*>(gameObj)) *************** *** 254,257 **** --- 271,279 ---- if (tcAirObject *airObj = dynamic_cast<tcAirObject*>(gameObj)) { + if (airObj->mcKin.mfAlt_m < terrainHeight + 10.0f) + { + airObj->mcKin.mfAlt_m = terrainHeight + 10.0f; + } + airObj->SetAltitude(airObj->mcKin.mfAlt_m); } *************** *** 274,277 **** --- 296,302 ---- simState->AddPlatform(gameObj); + + lastObjectAdded = gameObj; + return true; } Index: tcPlatformInterface.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/scriptinterface/tcPlatformInterface.cpp,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** tcPlatformInterface.cpp 29 Apr 2005 18:52:54 -0000 1.43 --- tcPlatformInterface.cpp 5 May 2005 02:14:53 -0000 1.44 *************** *** 503,507 **** } ! const tcLauncher* const pLauncher = mpPlatformObj->mcLauncherState.GetLauncher(anLauncher); wxASSERT(pLauncher); --- 503,507 ---- } ! tcLauncher* pLauncher = mpPlatformObj->mcLauncherState.GetLauncher(anLauncher); wxASSERT(pLauncher); *************** *** 742,745 **** --- 742,747 ---- void tcPlatformInterface::AddTask(const std::string& taskName, double priority) { + if (mpPlatformObj->IsClientMode()) return; + ai::Brain* brain = mpPlatformObj->GetBrain(); wxASSERT(brain); *************** *** 750,753 **** --- 752,757 ---- void tcPlatformInterface::AddNavWaypoint(float afLon_rad, float afLat_rad) { + if (mpPlatformObj->IsClientMode()) return; + ai::Brain* brain = mpPlatformObj->GetBrain(); wxASSERT(brain); *************** *** 769,772 **** --- 773,778 ---- void tcPlatformInterface::ClearTasks() { + if (mpPlatformObj->IsClientMode()) return; + ai::Brain* brain = mpPlatformObj->GetBrain(); wxASSERT(brain); *************** *** 777,780 **** --- 783,788 ---- void tcPlatformInterface::DeleteTask(const std::string& taskName) { + if (mpPlatformObj->IsClientMode()) return; + ai::Brain* brain = mpPlatformObj->GetBrain(); wxASSERT(brain); *************** *** 818,822 **** // sensor map commands ! tcTrackIterator tcPlatformInterface::GetFirstTrack(void) { tcTrackIterator t; --- 826,830 ---- // sensor map commands ! tcTrackIterator tcPlatformInterface::GetFirstTrack() { tcTrackIterator t; *************** *** 833,837 **** } ! int tcPlatformInterface::GetTrackCount(void) { if (mpSensorMap == NULL) {return 0;} --- 841,845 ---- } ! int tcPlatformInterface::GetTrackCount() { if (mpSensorMap == NULL) {return 0;} *************** *** 1085,1088 **** --- 1093,1106 ---- } + void tcPlatformInterface::ReleaseControl() + { + using network::tcMultiplayerInterface; + if (mpPlatformObj->IsControlled()) + { + tcMultiplayerInterface::Get()->SendControlRelease(mpPlatformObj->mnID); + } + } + + void tcPlatformInterface::TakeControl() { |