⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agentstate.cpp

📁 robocup rcssserver 运行防真机器人足球比赛所用的服务器端
💻 CPP
字号:
/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-   this file is part of rcssserver3D   Fri May 9 2003   Copyright (C) 2002,2003 Koblenz University   Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group   $Id: agentstate.cpp,v 1.6 2008/03/10 23:57:07 sgvandijk Exp $   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; version 2 of the License.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "agentstate.h"#include <soccer/soccertypes.h>#include <soccer/soccerbase/soccerbase.h>#include <soccer/gamestateaspect/gamestateaspect.h>#include <sstream>using namespace oxygen;using namespace std;AgentState::AgentState() : ObjectState(), mTeamIndex(TI_NONE),                           mTemperature(20.0), mBattery(100.0),                           mHearMax(2), mHearInc(1),                           mHearDecay(2), mHearMateCap(2),                           mHearOppCap(2), mIfSelfMsg(false),                           mIfMateMsg(false), mIfOppMsg(false){    // set mID and mUniformNumber into a joint state    SetUniformNumber(0);}AgentState::~AgentState(){}voidAgentState::SetTeamIndex(TTeamIndex idx){    mTeamIndex = idx;}TTeamIndexAgentState::GetTeamIndex() const{    return mTeamIndex;}voidAgentState::SetUniformNumber(int number){    mUniformNumber = number;    std::ostringstream ss;    ss << number;    ObjectState::SetID(ss.str());}intAgentState::GetUniformNumber() const{    return mUniformNumber;}voidAgentState::SetID(const std::string& id, TPerceptType pt){    std::istringstream iss(id);    iss >> mUniformNumber;    if (!iss)    {        // conversion failed. mUniformNumber is not changed.        return;    }    ObjectState::SetID(id,pt);}floatAgentState::GetBattery() const{    return mBattery;}voidAgentState::SetBattery(float battery){    mBattery = battery;}floatAgentState::GetTemperature() const{    return 23.0;}voidAgentState::SetTemperature(float temperature){    mTemperature = temperature;}boolAgentState::ReduceBattery(float consumption){    if (mBattery - consumption >= 0.0)    {        mBattery -= consumption;        return true;    }    return false;}voidAgentState::AddMessage(const string& msg, float direction, bool teamMate){    if (teamMate)    {        if (mHearMateCap < mHearDecay)        {            return;        }        mHearMateCap -= mHearDecay;        mMateMsg = msg;        mMateMsgDir = direction;        mIfMateMsg = true;    }    else    {        if (mHearOppCap < mHearDecay)        {            return;        }        mHearOppCap -= mHearDecay;        mOppMsg = msg;        mOppMsgDir = direction;        mIfOppMsg = true;    }}voidAgentState::AddSelfMessage(const string& msg){    mSelfMsg = msg;    mIfSelfMsg = true;}boolAgentState::GetMessage(string& msg, float& direction, bool teamMate){    if (teamMate)    {        if (mHearMateCap < mHearMax)        {            mHearMateCap += mHearInc;        }        if (! mIfMateMsg)        {            return false;        }        msg = mMateMsg;        direction = mMateMsgDir;        mIfMateMsg = false;        return true;    }    else    {        if (mHearOppCap < mHearMax)        {            mHearOppCap += mHearInc;        }        if (! mIfOppMsg)        {            return false;        }        msg = mOppMsg;        direction = mOppMsgDir;        mIfOppMsg = false;        return true;    }}boolAgentState::GetSelfMessage(string& msg){    if (! mIfSelfMsg)    {        return false;    }    msg = mSelfMsg;    mIfSelfMsg = false;    return true;}voidAgentState::OnUnlink(){    ObjectState::OnUnlink();    boost::shared_ptr<GameStateAspect> game_state;    if (!SoccerBase::GetGameState(*this,                 game_state))    {      GetLog()->Error() << "ERROR: (AgentState::OnUnlink) could not get game state\n";      return;    }        game_state->ReturnUniform(GetTeamIndex(), GetUniformNumber());}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -