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

📄 monitor.cc

📁 在LINUX下运行的仿真机器人服务器源代码
💻 CC
字号:
// -*-c++-*-/***************************************************************************                                 monitor.cc    A class providing the communication interface for remote monitors that    connect to the server                             -------------------    begin                : 27-DEC-2001    copyright            : (C) 2001 by The RoboCup Soccer Server                            Maintainance 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.                                                        * *                                                                         * ***************************************************************************/#include "monitor.h"#include "field.h"Monitor::Monitor ( Stadium* stadium_p, const double& version )    : M_stadium_p ( stadium_p ),      M_version ( version ){}Monitor::~Monitor (){}bool Monitor::parseCommand ( const char *message ){  int n;    if (!strcmp(message,"(dispbye)"))	  {      disable();      return true;    }  else if (!strcmp(message,"(dispstart)"))     {      // kick off message      _Start(*M_stadium_p) ;    }  else if (!strncmp(message,"(dispplayer", 11))     {      // a player is given new position by the monitor      int side, unum ;      int x, y, a;      double real_x, real_y, angle;      n = sscanf(message,"(dispplayer %d %d %d %d %d)", &side, &unum, &x, &y, &a) ;      if (n == 5) {        real_x= x / SHOWINFO_SCALE;        real_y= y / SHOWINFO_SCALE;        angle= Deg2Rad(a);         Player* p = (side == LEFT ? M_stadium_p->team_l : M_stadium_p->team_r)->player[unum-1];        p->pos = PVector(real_x, real_y);        p->vel = 0;        p->angle= angle;        //check_collision(p);        M_stadium_p->collisions ();      }    }  else if (!strncmp(message,"(dispdiscard", 12))     {      // a player is discarded by the monitor      int side, unum ;      n = sscanf(message,"(dispdiscard %d %d)", &side, &unum) ;      if (n == 2)        M_stadium_p->discard_player(side, unum) ;    }  else if (!strncmp(message, "(compression", 12))     {      int level ;      if ((n = sscanf(message,"(compression %d)", &level)) < 1)        {           send("(error illegal_command_form)") ;          return false;        }#ifdef HAVE_LIBZ      if ( level > 9 )        {           send("(error illegal_command_form)") ;          return false;        }#ifdef HAVE_SSTREAM      std::ostringstream reply;      reply << "(ok compression " << level << ")";      send ( reply.str().c_str() );#else      std::ostrstream reply;      reply << "(ok compression " << level << ")" << std::ends;      send ( reply.str() );      reply.freeze( false );#endif      setCompressionLevel ( level );                    #else      send ( "(warning compression_unsupported)" );#endif    }   else     {      // foul or drop_ball      int x, y, side ;      double real_x, real_y ;      n = sscanf(message,"(dispfoul %d %d %d)", &x, &y, &side) ;            if (n == 3) {        real_x = x / SHOWINFO_SCALE ;        real_y = y / SHOWINFO_SCALE ;        if ( side == NEUTRAL )          M_stadium_p->referee_drop_ball(real_x, real_y, side) ;        else          M_stadium_p->referee_get_foul(real_x, real_y, side) ;      }      else        // no message sent by a soccermonitor        return false;    }  return true;}

⌨️ 快捷键说明

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