00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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 }