[Gcblue-commits] gcb_wx/src/sim Game.cpp,1.92,1.93 tcGoal.cpp,1.4,1.5 tcGoalTracker.cpp,1.4,1.5 tcSi
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2004-09-05 02:38:55
|
Update of /cvsroot/gcblue/gcb_wx/src/sim In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11670/src/sim Modified Files: Game.cpp tcGoal.cpp tcGoalTracker.cpp tcSimState.cpp Log Message: Index: tcSimState.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcSimState.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** tcSimState.cpp 9 Aug 2004 02:35:16 -0000 1.51 --- tcSimState.cpp 5 Sep 2004 02:38:45 -0000 1.52 *************** *** 1486,1490 **** catch (...) { ! throw std::string("exception in GenerateRandomGoals"); } --- 1486,1498 ---- catch (...) { ! fprintf(stderr, "First exception in GenerateRandomGoals, trying again\n"); ! try ! { ! GenerateRandomGoals(); ! } ! catch (...) ! { ! throw std::string("exception in GenerateRandomGoals"); ! } } *************** *** 1842,1845 **** --- 1850,1854 ---- GetAlliancePlatforms(&key,1,1); obj = GetObject(key); + wxASSERT(obj); goalTracker->SetAllianceGoal(2, new tcDestroyGoal(obj->mzUnit.mz)); fprintf(stdout,"Added destroy goal for alliance %d: %s\n",2,obj->mzUnit.mz); *************** *** 1847,1850 **** --- 1856,1860 ---- GetAlliancePlatforms(&key,1,2); obj = GetObject(key); + wxASSERT(obj); goalTracker->SetAllianceGoal(1, new tcDestroyGoal(obj->mzUnit.mz)); fprintf(stdout,"Added destroy goal for alliance %d: %s\n",1,obj->mzUnit.mz); Index: tcGoal.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcGoal.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcGoal.cpp 8 Aug 2004 00:31:35 -0000 1.4 --- tcGoal.cpp 5 Sep 2004 02:38:45 -0000 1.5 *************** *** 81,84 **** --- 81,104 ---- /*** tcGoal ***/ + /** + * @return goalState as a string + */ + std::string tcGoal::GoalStateToString(int goalState) + { + if (goalState == UNRESOLVED) + { + return std::string("UNRESOLVED"); + } + else if (goalState == FAILED) + { + return std::string("FAILED"); + } + else + { + return std::string("PASSED"); + } + + } + tcGoal* tcGoal::Clone() { *************** *** 95,98 **** --- 115,126 ---- } + /** + * Writes status summary of goal condition to file + */ + void tcGoal::WriteStatus(std::stringstream& stream) + { + stream << "* Generic goal" << GoalStateToString(goalState) << "\n"; + } + tcGoal::tcGoal() { *************** *** 159,162 **** --- 187,229 ---- } } + void tcCompoundGoal::WriteStatus(std::stringstream& stream) + { + std::string typeString; + + if (logicType == AND) + { + typeString = "ALL"; + } + else + { + typeString = "ANY"; + } + + stream << "* Compound Goal -- " + "Mission to achieve " << typeString << " of these subgoals "; + + if (goalState == PASSED) + { + stream << "ACCOMPLISHED:\n"; + } + else if (goalState == FAILED) + { + stream << "FAILED:\n"; + } + else + { + stream << "NOT ACCOMPLISHED:\n"; + } + + + size_t nChildren = children.size(); + + for (size_t n=0; n<nChildren; n++) + { + stream << " "; + tcGoal* childGoal = children.at(n); + childGoal->WriteStatus(stream); + } + } tcCompoundGoal::tcCompoundGoal(int type) *************** *** 212,215 **** --- 279,306 ---- } + void tcTimeGoal::WriteStatus(std::stringstream& stream) + { + if (simState->GetTime() >= passTimeout) + { + stream << "* Time Goal -- " + "Orders were satisfied for specified time, goal SUCCESS\n"; + } + else if (simState->GetTime() >= failTimeout) + { + stream << "* Time Goal -- " + "The mission time limit was exceeded, goal FAILED\n"; + } + else if (failTimeout < passTimeout) + { + stream << "* Time Goal -- " + "Time limit not exceeded, goal UNRESOLVED\n"; + } + else + { + stream << "* Time Goal -- " + "Time goal not satisfied, goal NOT ACHIEVED\n"; + } + } + tcTimeGoal::tcTimeGoal() { *************** *** 248,251 **** --- 339,344 ---- tnPoolIndex key; bool unitFound = false; + + // inefficient linear search for now for(unsigned i=0;(i<nSize)&&(!unitFound);i++) { *************** *** 261,264 **** --- 354,372 ---- } + void tcDestroyGoal::WriteStatus(std::stringstream& stream) + { + stream << "* Destroy Goal -- Platform " << targetString; + + if (goalState == PASSED) + { + stream << " was DESTROYED.\n"; + } + else + { + stream << " NOT DESTROYED.\n"; + } + } + + tcDestroyGoal::tcDestroyGoal(const tcDestroyGoal& goal) : tcGoal(goal) Index: tcGoalTracker.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/tcGoalTracker.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** tcGoalTracker.cpp 8 Aug 2004 00:31:35 -0000 1.4 --- tcGoalTracker.cpp 5 Sep 2004 02:38:45 -0000 1.5 *************** *** 29,32 **** --- 29,34 ---- #include "tcGoalTracker.h" #include "tcGoal.h" + #include <sstream> + #include <fstream> #ifdef _DEBUG *************** *** 93,96 **** --- 95,118 ---- } + /** + * Writes goal status out to file <fileName>. This should + * be called at least once at the end of the game. + */ + void tcGoalTracker::LogAllianceGoalStatus(std::string fileName, int alliance) + { + std::stringstream statusStream; + + WriteStatus(statusStream, alliance); + + + std::ofstream logFile; + + logFile.open(fileName.c_str()); + + logFile << statusStream.str(); + + logFile.close(); + } + void tcGoalTracker::SetAllianceGoal(int alliance, tcGoal* goal) { *************** *** 115,118 **** --- 137,152 ---- } + void tcGoalTracker::WriteStatus(std::stringstream& stream, int alliance) + { + if (tcGoal* allianceGoal = allianceGoals[alliance]) + { + allianceGoal->WriteStatus(stream); + } + else + { + fprintf(stderr, "tcGoalTracker::WriteStatus - null alliance goal\n"); + } + } + tcGoalTracker::tcGoalTracker() : updateInterval(9.01) Index: Game.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/sim/Game.cpp,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** Game.cpp 5 Sep 2004 01:02:03 -0000 1.92 --- Game.cpp 5 Sep 2004 02:38:45 -0000 1.93 *************** *** 230,233 **** --- 230,236 ---- void tcGame::EndGame() { + goalTracker->LogAllianceGoalStatus("log\\goal_results.txt", + mcUserInfo.GetOwnAlliance()); + // hide all game windows briefingConsoleLeft->SetActive(false); *************** *** 1762,1765 **** --- 1765,1770 ---- } + + /** * Update member objects with new hook ID. |