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

📄 player.h

📁 在LINUX下运行的仿真机器人服务器源代码
💻 H
字号:
// -*-c++-*-/***************************************************************************                          player.h  -  A class for field players and goalies                             -------------------    begin                : 26-NOV-2001    copyright            : (C) 2001, 2002 by The RoboCup Soccer Server                            Maintenance Group.    email                : sserver-admin@lists.sourceforge.net ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU LGPL as published by the Free Software  * *   Foundation; either version 2 of the License, or (at your option) any  * *   later version.                                                        * *                                                                         * ***************************************************************************/#ifndef _PLAYER_H_#define _PLAYER_H_#include "object.h"#include "bodysensor.h"#include "serverparam.h"#include "playerparam.h"#include "hetroplayer.h"#include "visualsensor.h"#include "arm.h"#include "random.h"#include "audio.h"#include "remoteclient.h"#include "visual.h"#include "bodysender.h"#include "pcombuilder.h"#include "pcomparser.h"#include "fullstatesender.h"#include "initsender.h"#include "serializer.h"#include <string>class Team;class Player   : public MPObject,    public RemoteClient,    public BodySensor_v8,    public ServerParamSensor_v8,    public PlayerParamSensor_v8,    public PlayerTypeSensor_v8,    public VisualSensor_v8,    public rcss::Listener,    public rcss::Observer< rcss::VisualSenderPlayer >,    public rcss::BodyObserver< rcss::BodySenderPlayer >,    public rcss::FullStateObserver,    public rcss::InitObserver< rcss::InitSenderPlayer >,    public rcss::pcom::Builder{  public:    Player(Team *team, Stadium *stad, ID number);    void init( Value version, int goalie_flag );    /** This function is called in the begin of each cycle    * and in case a player sends a sense_body command. */    void sense_body();    void setPlayerType( const int& );    int getPlayerType() const;    void substitute( const int& );    void disable();    void send_visual_info();    /* contributed by Artur Merke */    void send_fullstate_information();     /** Inline-Deklarations */    inline void parseMsg( const char* msg, const size_t& len );    inline void rotate( Angle a );    inline void rotate_to( Angle a );    inline Arm& getArm();    inline const Arm& getArm() const;    inline bool getArmDir( double& arm_dir ) const;    inline unsigned int getTackleCycles() const;    inline void decrementTackleCycles();    inline bool isTackling() const;    inline unsigned int getTackleCount() const;    inline unsigned int getClangMinVer() const;    inline unsigned int getClangMaxVer() const;    inline bool isGoalie() const;    inline void setBackPasser();    inline void setFreeKickFaulter();    inline void send( const char* msg );    inline void send( const ServerParamSensor_v7::data_t& data );    inline void send( const ServerParamSensor_v8::data_t& data );    inline void send( const PlayerParamSensor_v7::data_t& data );    inline void send( const PlayerParamSensor_v8::data_t& data );    inline void send( const PlayerTypeSensor_v7::data_t& data );    inline void send( const PlayerTypeSensor_v8::data_t& data );    inline void send( const VisualSensor_v1::low_data_t& data );    inline void send( const VisualSensor_v6::low_data_t& data );    inline void send( const VisualSensor_v7::low_data_t& data );    inline void send( const VisualSensor_v1::high_data_t& data );    inline void send( const VisualSensor_v4::high_data_t& data );    inline void send( const VisualSensor_v5::high_data_t& data );    inline void send( const VisualSensor_v6::high_data_t& data );    inline void send( const VisualSensor_v7::high_data_t& data );    inline void send( const VisualSensor_v8::high_data_t& data );    inline void place( PVector location );    /** variables */    Team *team;    ID unum;  /* uniform number */    Name unumstr ;    //Client client ;    Name name_far;    Name name_toofar;    /* th 19.05.00 */    Name short_name_far;    Name short_name_toofar;    Value stamina;    Value recovery;    Value effort;    Value vis_angle;    Value defangle;    Value vis_distance;    Value inertia_moment;    Value version;#ifdef NEW_QSTEP    Value dist_qstep_player; /* each Player quantize step of distance */    Value land_qstep_player; /* each Player quantize step of distance for landmark */    Value dir_qstep_player; /* each Player quantize step of direction */#endif    Angle angle_neck;    Angle angle_neck_committed;    Angle angle_body;    // pfr 8/14/00: for RC2000 evaluation    Value kick_rand;    int vis_send;    int sendcnt;    int highquality;    int command_done;    int turn_neck_done;    int alive;    int hear_capacity_from_teammate;    int hear_capacity_from_opponent;    int goalie;    int goalie_catch_ban;    Value goalie_catch_probability;    int goalie_moves_since_catch;    int count_kick;    int count_dash;    int count_turn;    int count_catch;    int count_move;    int count_turn_neck;    int count_change_view;    int count_say;    int offside_mark;    PVector offside_pos;    PVector relative_ball_ang;    const HetroPlayer *player_type;    int player_type_id;    int done_received; //pfr:SYNCH    double distQStep() const    {#ifndef NEW_QSTEP        return ServerParam::instance().dist_qstep;#else        return dist_qstep_player;#endif    }    double landDistQStep() const    {#ifndef NEW_QSTEP        return ServerParam::instance().land_qstep;#else        return land_qstep_player;#endif    }    double dirQStep() const    {#ifndef NEW_QSTEP        return 0.1;#else        return dir_qstep_player;#endif    }    bool setSenders();  private:    /** PlayerCommands */    void dash( double power );    void turn( double moment );    void turn_neck( double moment );    void kick( double power, double dir );    void goalieCatch( double dir );    void say( std::string message );    void score();    void move( double x, double y );    void change_view( rcss::pcom::VIEW_WIDTH viewWidth, rcss::pcom::VIEW_QUALITY viewQuality );    void compression( int level );    void bye();    void done();    void pointto( bool on, double dist, double head );    void attentionto( bool on, rcss::pcom::TEAM team_side, std::string team_name, int at_unum );    void tackle( double power );    void clang( int min, int max);    void ear( bool on, rcss::pcom::TEAM team_side, std::string team_name, rcss::pcom::EAR_MODE mode );    void send( const BodySensor_v1::data_t& data );    void send( const BodySensor_v5::data_t& data );    void send( const BodySensor_v6::data_t& data );    void send( const BodySensor_v7::data_t& data );    void send( const BodySensor_v8::data_t& data );    /** variables */    Arm M_arm;    unsigned int M_tackle_cycles;    unsigned int M_tackle_count;    char M_buffer[ MaxMesg ];    unsigned int M_clang_min_ver;    unsigned int M_clang_max_ver;    // PlayerCommandParser    rcss::pcom::Parser M_parser;};/** Inline-Definitions */inline void Player::parseMsg( const char* msg, const size_t& len ){  char* command = const_cast<char*>(msg);  if( command[ len - 1 ] != 0 ) {    if( version >= 8.0 ){      send( "(warning message_not_null_terminated)" );    }    command[ len ] = 0;  }  write_log( *stadium, *this, command, RECV );  /** Call the PlayerCommandParser */  if ( M_parser.parse( command ) != 0 ){    send( "(error illegal_command_form)" );    cerr << "Error parsing >" << command << "<\n";  }}inline void Player::rotate( Angle a ){  angle_body = normalize_angle( angle + a );}inline void Player::rotate_to( Angle dir ){  angle_body = normalize_angle(dir);}inline Arm& Player::getArm(){  return M_arm;}inline const Arm& Player::getArm() const{  return M_arm;}inline bool Player::getArmDir( double& arm_dir ) const {  return M_arm.getRelDir ( rcss::geom::Vector2D ( pos.x, pos.y ),                            angle_body + angle_neck_committed,                            arm_dir );}inline unsigned int Player::getTackleCycles() const{  return M_tackle_cycles;}inline void Player::decrementTackleCycles(){  if( M_tackle_cycles > 0 )    M_tackle_cycles--;}inline bool Player::isTackling() const{  return M_tackle_cycles > 0;}inline unsigned int Player::getTackleCount() const{  return M_tackle_count;}inline unsigned int Player::getClangMinVer() const{   return M_clang_min_ver;}inline unsigned int Player::getClangMaxVer() const{  return M_clang_max_ver;}inline bool Player::isGoalie() const{  return goalie;}inline void Player::setBackPasser(){   alive |= BACK_PASS;}inline void Player::setFreeKickFaulter(){   alive |= FREE_KICK_FAULT;}inline void Player::send( const char* msg ){  if( RemoteClient::send( msg, strlen( msg ) + 1 ) != -1 ){    write_log( *stadium, *this, msg, SEND );  }}inline void Player::send( const ServerParamSensor_v7::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const ServerParamSensor_v8::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const PlayerParamSensor_v7::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const PlayerParamSensor_v8::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const PlayerTypeSensor_v7::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const PlayerTypeSensor_v8::data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v1::low_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v6::low_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v7::low_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v1::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v4::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v5::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v6::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v7::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::send( const VisualSensor_v8::high_data_t& data ){#ifdef HAVE_SSTREAM  std::ostringstream o;  toStr ( o, data );  send ( o.str().c_str() );#else  std::ostrstream o;  toStr ( o, data ) << std::ends;  send ( o.str() );  o.freeze( false );#endif}inline void Player::place( PVector location ){  acc = PVector( 0.0, 0.0 );  vel = PVector( 0.0, 0.0 );  pos = location;}#endif

⌨️ 快捷键说明

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