[Gcblue-commits] gcb_wx/src/ai Brain.cpp, 1.12, 1.13 Nav.cpp, 1.7, 1.8 ScriptedTask.cpp, 1.3, 1.4 S
Status: Alpha
Brought to you by:
ddcforge
From: Dewitt C. <ddc...@us...> - 2006-08-27 21:28:58
|
Update of /cvsroot/gcblue/gcb_wx/src/ai In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv21970/src/ai Modified Files: Brain.cpp Nav.cpp ScriptedTask.cpp SelfPreservation.cpp Task.cpp Log Message: Added attributes (hidden and permanent) to AI tasks so that automation tasks can be hidden and not distract player Index: ScriptedTask.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/ScriptedTask.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ScriptedTask.cpp 23 Mar 2006 01:11:01 -0000 1.3 --- ScriptedTask.cpp 27 Aug 2006 21:28:54 -0000 1.4 *************** *** 112,117 **** ScriptedTask::ScriptedTask(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, const std::string& scriptName) ! : Task(platform_, bb, id_, priority_, scriptName) { --- 112,117 ---- ScriptedTask::ScriptedTask(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, int attributes_, const std::string& scriptName) ! : Task(platform_, bb, id_, priority_, attributes_, scriptName) { Index: Task.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/Task.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Task.cpp 23 Mar 2006 01:11:01 -0000 1.5 --- Task.cpp 27 Aug 2006 21:28:54 -0000 1.6 *************** *** 51,54 **** --- 51,59 ---- } + int Task::GetAttributes() const + { + return attributes; + } + tcPlatformInterface Task::GetPlatformInterface() { *************** *** 61,64 **** --- 66,79 ---- } + bool Task::IsHidden() const + { + return (attributes & HIDDEN) != 0; + } + + bool Task::IsPermanent() const + { + return (attributes & PERMANENT) != 0; + } + bool Task::IsReadyForUpdate(double t) const { *************** *** 67,70 **** --- 82,90 ---- + void Task::SetAttributes(int attributes_) + { + attributes = attributes_; + } + void Task::SetUpdateInterval(float interval) *************** *** 78,85 **** Task::Task(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, const std::string& taskName_) : BlackboardInterface(bb, id_, priority_), platform(platform_), taskName(taskName_), lastUpdateTime(0), updateInterval(4.0f) --- 98,106 ---- Task::Task(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, int attributes_, const std::string& taskName_) : BlackboardInterface(bb, id_, priority_), platform(platform_), taskName(taskName_), + attributes(attributes_), lastUpdateTime(0), updateInterval(4.0f) Index: Brain.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/Brain.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Brain.cpp 23 Mar 2006 01:11:01 -0000 1.12 --- Brain.cpp 27 Aug 2006 21:28:54 -0000 1.13 *************** *** 77,81 **** stream >> priority; ! AddTask(taskName, (double)priority); } --- 77,84 ---- stream >> priority; ! int attributes; ! stream >> attributes; ! ! AddTask(taskName, (double)priority, attributes); } *************** *** 111,114 **** --- 114,120 ---- float priority = (float)task->GetPriority(); stream << priority; + + int attributes = task->GetAttributes(); + stream << attributes; } *************** *** 224,227 **** --- 230,235 ---- /** + * Assumed that this is used for display purposes so hidden tasks are NOT + * returned in this list. * @return list of task names */ *************** *** 234,238 **** for (;iter != done; ++iter) { ! taskList.push_back(iter->first); } --- 242,249 ---- for (;iter != done; ++iter) { ! if (!iter->second->IsHidden()) ! { ! taskList.push_back(iter->first); ! } } *************** *** 257,269 **** } ! void Brain::AddTask(const std::string& taskName, double priority_) { ! // if task already exists, update priority std::map<std::string, Task*>::iterator tm_iter = taskMap.find(taskName); if (tm_iter != taskMap.end()) { tm_iter->second->SetPriority(priority_); fprintf(stderr, "Warning - Brain::AddTask - task already exists, " ! "updating priority (%s)\n", priority_); return; } --- 268,281 ---- } ! void Brain::AddTask(const std::string& taskName, double priority_, int attributes_) { ! // if task already exists, update priority and attributes std::map<std::string, Task*>::iterator tm_iter = taskMap.find(taskName); if (tm_iter != taskMap.end()) { tm_iter->second->SetPriority(priority_); + tm_iter->second->SetAttributes(attributes_); fprintf(stderr, "Warning - Brain::AddTask - task already exists, " ! "updating priority and attributes (%s)\n", taskName.c_str()); return; } *************** *** 276,280 **** { taskMap[taskName] = new ScriptedTask(platform, &board, ! nextId++, priority_, taskName); } else --- 288,292 ---- { taskMap[taskName] = new ScriptedTask(platform, &board, ! nextId++, priority_, attributes_, taskName); } else *************** *** 289,293 **** case NAV_TASK: taskMap[taskName] = new Nav(platform, &board, ! nextId++, priority_, taskName); break; default: --- 301,305 ---- case NAV_TASK: taskMap[taskName] = new Nav(platform, &board, ! nextId++, priority_, attributes_, taskName); break; default: *************** *** 310,318 **** if (taskMap.size() > 0) hasNewCommand = true; std::map<std::string, Task*>::iterator iter = taskMap.begin(); ! while (iter != taskMap.end()) { ! delete iter->second; ! taskMap.erase(iter++); } } --- 322,337 ---- if (taskMap.size() > 0) hasNewCommand = true; + // additional test to avoid infinite loop due to permanent task + size_t nTasks = taskMap.size(); + size_t nChecked = 0; + std::map<std::string, Task*>::iterator iter = taskMap.begin(); ! while ((iter != taskMap.end()) && (nChecked++ < nTasks)) { ! if (!iter->second->IsPermanent()) ! { ! delete iter->second; ! taskMap.erase(iter++); ! } } } *************** *** 349,352 **** --- 368,376 ---- if (iter != taskMap.end()) { + if (iter->second->IsPermanent()) + { + return; // ignore request + } + // remove all blackboard entries from the author being erased board.EraseAllFromAuthor(iter->second->GetAuthor()); Index: SelfPreservation.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/SelfPreservation.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SelfPreservation.cpp 23 Mar 2006 01:11:01 -0000 1.3 --- SelfPreservation.cpp 27 Aug 2006 21:28:54 -0000 1.4 *************** *** 86,91 **** SelfPreservation::SelfPreservation(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, const std::string& taskName_) ! : Task(platform_, bb, id_, priority_, taskName_) { wxASSERT(platform); --- 86,91 ---- SelfPreservation::SelfPreservation(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, int attributes_, const std::string& taskName_) ! : Task(platform_, bb, id_, priority_, attributes_, taskName_) { wxASSERT(platform); Index: Nav.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/ai/Nav.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Nav.cpp 23 Mar 2006 01:11:01 -0000 1.7 --- Nav.cpp 27 Aug 2006 21:28:54 -0000 1.8 *************** *** 202,207 **** Nav::Nav(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, const std::string& taskName_) ! : Task(platform_, bb, id_, priority_, taskName_), currentWaypoint(0), loop(false) --- 202,207 ---- Nav::Nav(tcPlatformObject* platform_, Blackboard* bb, ! long id_, double priority_, int attributes_, const std::string& taskName_) ! : Task(platform_, bb, id_, priority_, attributes_, taskName_), currentWaypoint(0), loop(false) |