Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

agentstate.cpp

Go to the documentation of this file.
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) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: agentstate.cpp,v 1.4 2005/12/13 20:50:13 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "agentstate.h"
00023 #include <soccer/soccerbase/soccerbase.h>
00024 #include <oxygen/physicsserver/body.h>
00025 #include <sstream>
00026 
00027 using namespace oxygen;
00028 using namespace std;
00029 
00030 AgentState::AgentState() : ObjectState(), mTeamIndex(TI_NONE),
00031                            mTemperature(20.0), mBattery(100.0),
00032                            mHearMax(2), mHearInc(1),
00033                            mHearDecay(2), mHearMateCap(2),
00034                            mHearOppCap(2), mIfSelfMsg(false),
00035                            mIfMateMsg(false), mIfOppMsg(false)
00036 {
00037     // set mID and mUniformNumber into a joint state
00038     SetUniformNumber(0);
00039 }
00040 
00041 AgentState::~AgentState()
00042 {
00043 }
00044 
00045 void
00046 AgentState::SetTeamIndex(TTeamIndex idx)
00047 {
00048     mTeamIndex = idx;
00049 }
00050 
00051 TTeamIndex
00052 AgentState::GetTeamIndex() const
00053 {
00054     return mTeamIndex;
00055 }
00056 
00057 
00058 void
00059 AgentState::SetUniformNumber(int number)
00060 {
00061     mUniformNumber = number;
00062     std::ostringstream ss;
00063     ss << number;
00064     ObjectState::SetID(ss.str());
00065 }
00066 
00067 int
00068 AgentState::GetUniformNumber() const
00069 {
00070     return mUniformNumber;
00071 }
00072 
00073 void
00074 AgentState::SetID(const std::string& id, TPerceptType pt)
00075 {
00076     std::istringstream iss(id);
00077     iss >> mUniformNumber;
00078     if (!iss)
00079     {
00080         // conversion failed. mUniformNumber is not changed.
00081         return;
00082     }
00083     ObjectState::SetID(id,pt);
00084 }
00085 
00086 float
00087 AgentState::GetBattery() const
00088 {
00089     return mBattery;
00090 }
00091 
00092 void
00093 AgentState::SetBattery(float battery)
00094 {
00095     mBattery = battery;
00096 }
00097 
00098 float
00099 AgentState::GetTemperature() const
00100 {
00101     return 23.0;
00102 }
00103 
00104 void
00105 AgentState::SetTemperature(float temperature)
00106 {
00107     mTemperature = temperature;
00108 }
00109 
00110 bool
00111 AgentState::ReduceBattery(double consumption)
00112 {
00113     if (mBattery - consumption >= 0.0)
00114     {
00115         mBattery -= consumption;
00116         return true;
00117     }
00118     return false;
00119 }
00120 
00121 void
00122 AgentState::AddMessage(const string& msg, float direction, bool teamMate)
00123 {
00124     if (teamMate)
00125     {
00126         if (mHearMateCap < mHearDecay)
00127         {
00128             return;
00129         }
00130 
00131         mHearMateCap -= mHearDecay;
00132 
00133         mMateMsg = msg;
00134         mMateMsgDir = direction;
00135         mIfMateMsg = true;
00136     } 
00137     else
00138     {
00139         if (mHearOppCap < mHearDecay)
00140         {
00141             return;
00142         }
00143 
00144         mHearOppCap -= mHearDecay;
00145 
00146         mOppMsg = msg;
00147         mOppMsgDir = direction;
00148         mIfOppMsg = true;
00149     }
00150 }
00151 
00152 void
00153 AgentState::AddSelfMessage(const string& msg)
00154 {
00155     mSelfMsg = msg;
00156     mIfSelfMsg = true;
00157 }
00158 
00159 bool
00160 AgentState::GetMessage(string& msg, float& direction, bool teamMate)
00161 {
00162     if (teamMate)
00163     {
00164         if (mHearMateCap < mHearMax)
00165         {
00166             mHearMateCap += mHearInc;
00167         }
00168 
00169         if (! mIfMateMsg)
00170         {
00171             return false;
00172         }
00173 
00174         msg = mMateMsg;
00175         direction = mMateMsgDir;
00176         mIfMateMsg = false;
00177         return true;
00178     } 
00179     else
00180     {
00181         if (mHearOppCap < mHearMax)
00182         {
00183             mHearOppCap += mHearInc;
00184         }
00185 
00186         if (! mIfOppMsg)
00187         {
00188             return false;
00189         }
00190 
00191         msg = mOppMsg;
00192         direction = mOppMsgDir;
00193         mIfOppMsg = false;
00194         return true;
00195     }
00196 }
00197 
00198 bool
00199 AgentState::GetSelfMessage(string& msg)
00200 {
00201     if (! mIfSelfMsg)
00202     {
00203         return false;
00204     }
00205 
00206     msg = mSelfMsg;
00207     mIfSelfMsg = false;
00208 
00209     return true;
00210 }

Generated on Thu Apr 6 15:25:37 2006 for rcssserver3d by  doxygen 1.4.4