00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2004 RoboCup Soccer Server 3D Maintenance Group 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; version 2 of the License. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 #include "hearperceptor.h" 00022 #include <soccer/agentstate/agentstate.h> 00023 #include <soccer/soccerbase/soccerbase.h> 00024 #include <soccer/gamestateaspect/gamestateaspect.h> 00025 //#include <soccer/soccertypes.h> 00026 00027 using namespace oxygen; 00028 using namespace zeitgeist; 00029 using namespace std; 00030 00031 HearPerceptor::HearPerceptor() : oxygen::Perceptor() 00032 { 00033 } 00034 00035 HearPerceptor::~HearPerceptor() 00036 { 00037 } 00038 00039 bool 00040 HearPerceptor::Percept(boost::shared_ptr<PredicateList> predList) 00041 { 00042 if ( 00043 (mAgentState.get() == 0) || 00044 (mGameState.get() == 0) 00045 ) 00046 { 00047 return false; 00048 } 00049 00050 bool result = false; 00051 00052 string message; 00053 float direction; 00054 00055 if (mAgentState->GetSelfMessage(message)) 00056 { 00057 string self = "self"; 00058 Predicate& predicate = predList->AddPredicate(); 00059 predicate.name = "hear"; 00060 predicate.parameter.Clear(); 00061 predicate.parameter.AddValue(mGameState->GetTime()); 00062 predicate.parameter.AddValue(self); 00063 predicate.parameter.AddValue(message); 00064 result = true; 00065 } 00066 00067 if (mAgentState->GetMessage(message, direction, true)) 00068 { 00069 Predicate& predicate = predList->AddPredicate(); 00070 predicate.name = "hear"; 00071 predicate.parameter.Clear(); 00072 predicate.parameter.AddValue(mGameState->GetTime()); 00073 predicate.parameter.AddValue(direction); 00074 predicate.parameter.AddValue(message); 00075 result = true; 00076 } 00077 00078 if (mAgentState->GetMessage(message, direction, false)) 00079 { 00080 Predicate& predicate = predList->AddPredicate(); 00081 predicate.name = "hear"; 00082 predicate.parameter.Clear(); 00083 predicate.parameter.AddValue(mGameState->GetTime()); 00084 predicate.parameter.AddValue(direction); 00085 predicate.parameter.AddValue(message); 00086 result = true; 00087 } 00088 00089 return result; 00090 } 00091 00092 void 00093 HearPerceptor::OnLink() 00094 { 00095 SoccerBase::GetAgentState(*this, mAgentState); 00096 SoccerBase::GetGameState(*this, mGameState); 00097 } 00098 00099 void 00100 HearPerceptor::OnUnlink() 00101 { 00102 mAgentState.reset(); 00103 mGameState.reset(); 00104 }