playerparam.cpp

来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 414 行 · 第 1/2 页

CPP
414
字号
/* -*- Mode: C++ -*- *//* *Copyright: Copyright (C) 1996-2000 Electrotechnical Laboratory. Itsuki Noda, Yasuo Kuniyoshi and Hitoshi Matsubara. Copyright (C) 2000, 2001 RoboCup Soccer Server Maintainance Group. Patrick Riley, Tom Howard, Daniel Polani, Itsuki Noda, Mikhail Prokopenko, Jan Wendler This file is a part of SoccerServer. This code is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *EndCopyright: */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "playerparam.h"#include <rcssbase/conf/parser.hpp>#include <rcssbase/conf/builder.hpp>#include <boost/filesystem/path.hpp>#include <string>#include <iostream>#include <cerrno>#include <cassert>#ifdef HAVE_SYS_PARAM_H#include <sys/param.h> /* needed for htonl, htons, ... */#endif#ifdef HAVE_WINSOCK2_H#include <Winsock2.h> /* needed for htonl, htons, ... */#endif#ifdef HAVE_NETINET_IN_H#include <netinet/in.h>#endifinlineInt32roundint( const double & value ){    return static_cast< Int32 >( value + 0.5 );}#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) || defined (__CYGWIN__)#  ifndef WIN32#    define WIN32#  endif#endif#ifdef WIN32const std::string PlayerParam::CONF_DIR = "~\\.rcssserver\\";const std::string PlayerParam::PLAYER_CONF = "player.conf";const std::string PlayerParam::OLD_PLAYER_CONF = "~\\.rcssserver-player.conf";#elseconst std::string PlayerParam::CONF_DIR = "~/.rcssserver/";const std::string PlayerParam::PLAYER_CONF = "player.conf";const std::string PlayerParam::OLD_PLAYER_CONF = "~/.rcssserver-player.conf";#endifconst int PlayerParam::DEFAULT_PLAYER_TYPES = 18; // [12.0.0] 7 -> 18const int PlayerParam::DEFAULT_SUBS_MAX = 3;const int PlayerParam::DEFAULT_PT_MAX = 1; // [12.0.0] 3 -> 1const double PlayerParam::DEFAULT_PLAYER_SPEED_MAX_DELTA_MIN = 0.0;const double PlayerParam::DEFAULT_PLAYER_SPEED_MAX_DELTA_MAX = 0.0;const double PlayerParam::DEFAULT_STAMINA_INC_MAX_DELTA_FACTOR = 0.0;// [13.0.0] -0.05 -> -0.1// [12.0.0]  0.0  -> -0.05const double PlayerParam::DEFAULT_PLAYER_DECAY_DELTA_MIN = -0.1;// [12.0.0] 0.2 -> 0.1const double PlayerParam::DEFAULT_PLAYER_DECAY_DELTA_MAX = 0.1;const double PlayerParam::DEFAULT_INERTIA_MOMENT_DELTA_FACTOR = 25.0;const double PlayerParam::DEFAULT_DASH_POWER_RATE_DELTA_MIN = 0.0;const double PlayerParam::DEFAULT_DASH_POWER_RATE_DELTA_MAX = 0.0;const double PlayerParam::DEFAULT_PLAYER_SIZE_DELTA_FACTOR = -100.0;const double PlayerParam::DEFAULT_KICKABLE_MARGIN_DELTA_MIN = -0.1; // [12.0.0] 0.0 -> -0.1const double PlayerParam::DEFAULT_KICKABLE_MARGIN_DELTA_MAX = 0.1; // [12.0.0] 0.2 -> 0.1const double PlayerParam::DEFAULT_KICK_RAND_DELTA_FACTOR = 1.0; // [12.0.0] 0.5 -> 1.0const double PlayerParam::DEFAULT_EXTRA_STAMINA_DELTA_MIN = 0.0;// [13.0.0] 100.0 -> 50.0const double PlayerParam::DEFAULT_EXTRA_STAMINA_DELTA_MAX = 50.0;// [13.0.0] -0.002 -> -0.004const double PlayerParam::DEFAULT_EFFORT_MAX_DELTA_FACTOR = -0.004;// [13.0.0] -0.002 -> -0.004const double PlayerParam::DEFAULT_EFFORT_MIN_DELTA_FACTOR = -0.004;const int    PlayerParam::DEFAULT_RANDOM_SEED = -1; //negative means generate a new seed// [13.0.0] -0.0005 -> -0.0012// [12.0.0]  0      -> -0.0005const double PlayerParam::DEFAULT_NEW_DASH_POWER_RATE_DELTA_MIN = -0.0012;// [13.0.0] 0.0015 -> 0.0008// [12.0.0] 0.002  -> 0.0015const double PlayerParam::DEFAULT_NEW_DASH_POWER_RATE_DELTA_MAX = 0.0008;// [12.0.0] -10000.0 -> -6000.0const double PlayerParam::DEFAULT_NEW_STAMINA_INC_MAX_DELTA_FACTOR = -6000.0;PlayerParam &PlayerParam::instance( rcss::conf::Builder * parent ){    static bool parent_set = false;    if ( parent != NULL || parent_set )    {        static PlayerParam rval( parent );        parent_set = true;        return rval;    }    // hack to allow link testing to call instance without crashing    // do not used the return value in these situations    PlayerParam * rval = NULL;    return *rval;}PlayerParam &PlayerParam::instance(){    return PlayerParam::instance( NULL );}boolPlayerParam::init( rcss::conf::Builder * parent ){    assert( parent );    instance( parent );    if ( ! instance().m_builder->parser() )    {        std::cerr << __FILE__ << ": " << __LINE__                  << ": internal error: player param could not find configuration parser\n";        std::cerr << "Please submit a full bug report to sserver-bugs@lists.sf.net\n";        return false;    }    std::string conf_dir = PlayerParam::CONF_DIR;    const char * env_conf_dir = std::getenv( "RCSS_CONF_DIR" );    if ( env_conf_dir )    {        conf_dir = env_conf_dir;    }    //boost::filesystem::path conf_path( tildeExpand( PlayerParam::PLAYER_CONF ),    boost::filesystem::path conf_path( tildeExpand( conf_dir ),                                       boost::filesystem::portable_posix_name );    conf_path /= PlayerParam::PLAYER_CONF;    instance().convertOldConf( conf_path.string() );    if ( ! instance().m_builder->parser()->parseCreateConf( conf_path, "player" ) )    {        std::cerr << "could not parse configuration file '"                  << conf_path.string()                  << "'\n";        return false;    }    if ( instance().m_builder->version() != instance().m_builder->parsedVersion() )    {        std::cerr << "Version mismatched in the configuration file. "                  << "Need to regenerate '" << tildeExpand( PlayerParam::PLAYER_CONF ) << "'"                  << " or set '" << instance().m_builder->version() << "' to the 'version' option."                  << std::endl;//         std::cerr << "registered version = ["//                   << instance().m_builder->version() << "]\n"//                   << "parsed version = ["//                   << instance().m_builder->parsedVersion() << "]\n"//                   << std::flush;        return false;    }    return true;}voidPlayerParam::convertOldConf( const std::string & new_conf ){#ifndef WIN32    if ( std::system( ( "ls " + tildeExpand( PlayerParam::OLD_PLAYER_CONF ) + " > /dev/null 2>&1" ).c_str() ) == 0

⌨️ 快捷键说明

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