📄 serverparam.c
字号:
/* -*- 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: */#include <cstring>#include <iostream>#include "serverparam.h"#include <rcssbase/conf/builder.hpp>#include <rcssbase/conf/parser.hpp>#include <string>#include "config.h"#include "playerparam.h"ServerParam::Printer::Printer( std::ostream& out, unsigned int version ) : M_out( out ), M_version( version ){} voidServerParam::Printer::operator()( const std::pair< const std::string, unsigned int > item ){ if( item.second <= M_version ) { int ivalue; if( ServerParam::instance().getInt( item.first, ivalue ) ) { M_out << "(" << item.first << " " << ivalue << ")"; return; } bool bvalue; if( ServerParam::instance().getBool( item.first, bvalue ) ) { M_out << "(" << item.first << " " << bvalue << ")"; return; } double dvalue; if( ServerParam::instance().getDoub( item.first, dvalue ) ) { M_out << "(" << item.first << " " << dvalue << ")"; return; } std::string svalue; if( ServerParam::instance().getStr( item.first, svalue ) ) { M_out << "(" << item.first << " " << svalue << ")"; return; } }}#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) || defined (__CYGWIN__)# ifndef WIN32# define WIN32# endif#endif#ifdef WIN32const char ServerParam::LANDMARK_FILE[] = "~\\.rcssserver-landmark.xml";const char ServerParam::SERVER_CONF[] = "~\\.rcssserver\\server.conf";const char ServerParam::OLD_SERVER_CONF[] = "~\\.rcssserver-server.conf";#elseconst char ServerParam::LANDMARK_FILE[] = "~/.rcssserver-landmark.xml";const char ServerParam::SERVER_CONF[] = "~/.rcssserver/server.conf";const char ServerParam::OLD_SERVER_CONF[] = "~/.rcssserver-server.conf";#endifconst int ServerParam::SEND_COMMS = false;const int ServerParam::TEXT_LOGGING = true;const int ServerParam::GAME_LOGGING = true;const int ServerParam::GAME_LOG_VERSION = 3;const char ServerParam::TEXT_LOG_DIR[] = "./";const char ServerParam::GAME_LOG_DIR[] = "./";const char ServerParam::TEXT_LOG_FIXED_NAME[] = "rcssserver";const char ServerParam::GAME_LOG_FIXED_NAME[] = "rcssserver";const int ServerParam::TEXT_LOG_FIXED = false;const int ServerParam::GAME_LOG_FIXED = false;const int ServerParam::TEXT_LOG_DATED = true;const int ServerParam::GAME_LOG_DATED = true;const char ServerParam::LOG_DATE_FORMAT[] = "%Y%m%d%H%M-";const int ServerParam::LOG_TIMES = false;const int ServerParam::RECORD_MESSAGES = false;const int ServerParam::TEXT_LOG_COMPRESSION = 0;const int ServerParam::GAME_LOG_COMPRESSION = 0;const bool ServerParam::PROFILE = false;const int ServerParam::KAWAY_LOGGING = true;const char ServerParam::KAWAY_LOG_DIR[] = "./";const char ServerParam::KAWAY_LOG_FIXED_NAME[] = "rcssserver";const int ServerParam::KAWAY_LOG_FIXED = false;const int ServerParam::KAWAY_LOG_DATED = true;const int ServerParam::KAWAY_START = -1;const int ServerParam::POINT_TO_BAN = 5;const int ServerParam::POINT_TO_DURATION= 20;const unsigned int ServerParam::SAY_MSG_SIZE = 10;const unsigned int ServerParam::HEAR_MAX = 1;const unsigned int ServerParam::HEAR_INC = 1;const unsigned int ServerParam::HEAR_DECAY = 1;const double ServerParam::TACKLE_DIST = 2.0;const double ServerParam::TACKLE_BACK_DIST = 0.5;const double ServerParam::TACKLE_WIDTH = 1.0;const double ServerParam::TACKLE_EXPONENT = 6.0;const unsigned int ServerParam::TACKLE_CYCLES = 10;const double ServerParam::TACKLE_POWER_RATE = 0.027;const int ServerParam::NR_NORMAL_HALFS = 2;const int ServerParam::NR_EXTRA_HALFS = 2;const bool ServerParam::PENALTY_SHOOT_OUTS = true;const int ServerParam::PEN_BEFORE_SETUP_WAIT = 30;const int ServerParam::PEN_SETUP_WAIT = 100;const int ServerParam::PEN_READY_WAIT = 50;const int ServerParam::PEN_TAKEN_WAIT = 200;const int ServerParam::PEN_NR_KICKS = 5;const int ServerParam::PEN_MAX_EXTRA_KICKS = 10;const double ServerParam::PEN_DIST_X = 42.5;const bool ServerParam::PEN_RANDOM_WINNER = false;const double ServerParam::PEN_MAX_GOALIE_DIST_X = 14;const bool ServerParam::PEN_ALLOW_MULT_KICKS = true;const bool ServerParam::PEN_COACH_MOVES_PLAYERS = true;const unsigned int ServerParam::FREEFORM_WAIT_PERIOD = 600;const unsigned int ServerParam::FREEFORM_SEND_PERIOD = 20;const bool ServerParam::FREE_KICK_FAULTS = true;const bool ServerParam::BACK_PASSES = true;const bool ServerParam::PROPER_GOAL_KICKS = false;const double ServerParam::STOPPED_BALL_VEL = 0.01;const int ServerParam::MAX_GOAL_KICKS = 3;const int ServerParam::CLANG_DEL_WIN = 1;const int ServerParam::CLANG_RULE_WIN = 1;const bool ServerParam::S_AUTO_MODE = false;const int ServerParam::S_KICK_OFF_WAIT = 100;const int ServerParam::S_CONNECT_WAIT = 300;const int ServerParam::S_GAME_OVER_WAIT = 100;const char ServerParam::S_TEAM_L_START[] = "";const char ServerParam::S_TEAM_R_START[] = "";#ifdef MODULEDIRconst char ServerParam::S_MODULE_DIR[] = MODULEDIR;#elseconst char ServerParam::S_MODULE_DIR[] = "/usr/local/lib/rcssserver/modules"#endifbool ServerParam::s_in_init = false;ServerParam&ServerParam::instance( const std::string& progname ){ static ServerParam rval( progname ); return rval; }ServerParam&ServerParam::instance(){ return ServerParam::instance( "" ); }boolServerParam::init( const int& argc, const char * const *argv ){ s_in_init = true; instance( argv[ 0 ] ); s_in_init = false;#ifndef WIN32 if( system( ( "ls " + tildeExpand( ServerParam::OLD_SERVER_CONF ) + " > /dev/null 2>&1" ).c_str() ) == 0 ) { if( system( ( "ls " + tildeExpand( ServerParam::SERVER_CONF ) + " > /dev/null 2>&1" ).c_str() ) != 0 ) { if( system( "which awk > /dev/null 2>&1" ) == 0 ) { std::cout << "Trying to convert old configuration file '" << ServerParam::OLD_SERVER_CONF << "'\n"; char filename[] = "/tmp/rcssserver-oldconf-XXXXXX"; int fd = mkstemp( filename ); if( fd != -1 ) { close( fd ); std::string command = "awk '/^[ \\t]*$/ {} "; command += "/^[^#]+[:]/ { gsub(/:/, \"=\" ); $1 = \"server::\" $1; } "; command += "/^[ \\t]*[^#:=]+$/ { $1 = \"server::\" $1 \" = true\"; }"; command += "{ print; }' "; command += tildeExpand( ServerParam::OLD_SERVER_CONF ); command += " > "; command += filename; if( system( command.c_str() ) == 0 ) { std::cout << "Conversion successful\n"; instance().m_conf_parser->parse( filename ); } else { std::cout << "Conversion failed\n"; } } else { std::cout << "Conversion failed\n"; } } } }#endif // not win32 if( !instance().m_conf_parser->parseCreateConf( tildeExpand( ServerParam::SERVER_CONF ) ) ) { std::cerr << "could not create or parse configuration file '" << tildeExpand( ServerParam::SERVER_CONF ) << "'\n"; instance().m_builder->displayHelp(); instance().clear(); exit( EXIT_FAILURE ); } else { if( !PlayerParam::init( ServerParam::instance().m_builder.get() ) ) { instance().m_builder->displayHelp(); instance().clear(); exit( EXIT_FAILURE ); } if( !instance().m_conf_parser->parse( argc, argv ) ) { instance().m_builder->displayHelp(); instance().clear(); exit( EXIT_FAILURE ); } if( !instance().timer_loaded ) instance().setSynchMode( false ); if( !instance().timer_loaded ) { std::cerr << "Could not load timer\n"; std::cerr << "timer library not found in '" << rcss::lib::Loader::getPath() << "'\n"; instance().clear(); exit( EXIT_FAILURE ); } if( instance().m_builder->genericHelpRequested() ) { instance().m_builder->displayHelp(); instance().clear(); exit( EXIT_SUCCESS ); } } return true;}ServerParam::ServerParam( const std::string& progname ) : m_builder( new rcss::conf::Builder( progname, "server" ) ), m_conf_parser( new rcss::conf::Parser( *m_builder ) ), m_err_handler( new rcss::conf::StreamStatusHandler() ){ m_builder->addHandler( *m_err_handler ); setDefaults(); addParams(); if( !ServerParam::s_in_init ) { std::cerr << "Warning: ServerParam is being used before it has been initialised\n"; }}ServerParam::~ServerParam(){ if( m_builder ) m_builder->removeHandler( *m_err_handler );}template< typename P >voidServerParam::addParam( const std::string& name, P& param, const std::string& desc, int version ){ m_builder->addParam( name, param, desc ); m_ver_map[ name ] = version;}template< typename S, typename G >voidServerParam::addParam( const std::string& name, const S& setter, const G& getter, const std::string& desc, int version ){ m_builder->addParam( name, setter, getter, desc ); m_ver_map[ name ] = version;}voidServerParam::addParams(){ addParam( "goal_width", gwidth, "The width of the goals", 7 ); addParam( "player_size", rcss::conf::Builder::makeSetter( this, &ServerParam::setPlayerSize ), rcss::conf::Builder::makeGetter( psize ), "The size of the default player", 7 ); addParam( "player_decay", pdecay, "Players speed decay rate", 7 ); addParam( "player_rand", prand, "Player random movement factor", 7 ); addParam( "player_weight", pweight, "The weight of the player", 7 ); addParam( "player_speed_max", pspeed_max, "The max speed of players", 7 ); // th 6.3.00 addParam( "player_accel_max", paccel_max, "The max acceleration of players", 7 ); // addParam( "stamina_max", stamina_max, "The maximum stamina of players", 7 ); addParam( "stamina_inc_max", stamina_inc, "The maximum player stamina increament", 7 ); addParam( "recover_init", recover_init, "The intial recovery value for players", 9 ); addParam( "recover_dec_thr", recover_dthr, "", 7 ); addParam( "recover_min", recover_min, "", 7 ); addParam( "recover_dec", recover_dec, "", 7 ); addParam( "effort_init", effort_init, "", 7 ); addParam( "effort_dec_thr", effort_dthr, "", 7 ); addParam( "effort_min", effort_min, "", 7 ); addParam( "effort_dec", effort_dec, "", 7 ); addParam( "effort_inc_thr", effort_ithr, "", 7 ); addParam( "effort_inc", effort_inc, "", 7 ); // pfr 8/14/00: for RC2000 evaluation addParam( "kick_rand", kick_rand, "", 7 ); addParam( "team_actuator_noise", team_actuator_noise, "", 7 ); addParam( "prand_factor_l", prand_factor_l, "", 7 ); addParam( "prand_factor_r", prand_factor_r, "", 7 ); addParam( "kick_rand_factor_l", kick_rand_factor_l, "", 7 ); addParam( "kick_rand_factor_r", kick_rand_factor_r, "", 7 ); addParam( "ball_size", rcss::conf::Builder::makeSetter( this, &ServerParam::setBallSize ), rcss::conf::Builder::makeGetter( bsize ), "", 7 ); addParam( "ball_decay", bdecay, "", 7 ); addParam( "ball_rand", brand, "", 7 ); addParam( "ball_weight", bweight, "", 7 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -