📄 player.cc
字号:
// << " " << team->point;// if ( team == stadium->team_l ){// if ( stadium->team_r == NULL ){// ost << " " << 0;// }// else{// ost << " " << stadium->team_r->point;// }// }// else{// if ( stadium->team_l == NULL ){// ost << " " << 0;// }// else{// ost << " " << stadium->team_l->point;// }// }// ost << ")" << std::ends;// send ( ost.str () );// ost.freeze ( false );}void Player::move( double x, double y ){ if ( command_done == FALSE ) { if ( stadium->mode == PM_BeforeKickOff || stadium->mode == PM_AfterGoal_Right ||#ifndef _FREEKICK_MOVE_ALL_ stadium->mode == PM_AfterGoal_Left) {#else stadium->mode == PM_AfterGoal_Left || stadium->mode == PM_FreeKick_Left || stadium->mode == PM_FreeKick_Right ) {#endif pos.x = x * team->side; pos.y = y * team->side; //stadium->check_collision(this); stadium->collisions(); }#ifndef _FREEKICK_MOVE_ALL_ else if ( ( stadium->mode == PM_FreeKick_Left || stadium->mode == PM_FreeKick_Right ) && stadium->M_caught_ball == this ) { if( ServerParam::instance().goalie_max_moves < 0 || goalie_moves_since_catch < ServerParam::instance().goalie_max_moves ) { pos.x = x * team->side; pos.y = y * team->side; goalie_moves_since_catch++; stadium->move_caught_ball(); // [2000.07.21:I.Noda] //stadium->check_collision(this) ; stadium->collisions(); } else{ send( "(error too_many_moves)" ); } }#endif else{ return; } command_done = TRUE ; count_move++; }}void Player::change_view( rcss::pcom::VIEW_WIDTH viewWidth, rcss::pcom::VIEW_QUALITY viewQuality ){ if ( viewWidth == rcss::pcom::NARROW ) { vis_angle = defangle / 2.0; vis_send = 2; } else if ( viewWidth == rcss::pcom::NORMAL ) { vis_angle = defangle; vis_send = 4; } else if ( viewWidth == rcss::pcom::WIDE ) { vis_angle = defangle * 2.0; vis_send = 8; } else{ return; } if ( viewQuality == rcss::pcom::HIGH ){ highquality = TRUE; } else if ( viewQuality == rcss::pcom::LOW ){ vis_send /= 2; highquality = FALSE; } else{ return; } count_change_view++;}void Player::compression( int level ){#ifdef HAVE_LIBZ if ( level > 9 ){ return; }#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}void Player::bye(){ disable(); command_done = TRUE ;}void Player::done(){ done_received = TRUE;}void Player::pointto( bool on, double dist, double head ){ if ( on == false ){ M_arm.stopPointing(); } else { M_arm.pointTo( rcss::geom::Vector2D( pos.x, pos.y ), angle + angle_neck_committed, rcss::geom::polarVector2D( dist, Deg2Rad( head ) ) ); }}void Player::attentionto( bool on, rcss::pcom::TEAM team_side, string team_name, int at_unum ){ if ( on == false ){ // turn attention to off focusOff(); } else{ Team *at_team = NULL; if ( team_side == rcss::pcom::OUR ){ at_team = team; } else if ( team_side == rcss::pcom::OPP ){ if ( team == stadium->team_l ){ at_team = stadium->team_r; } else{ at_team = stadium->team_l; } } else if ( team_side == rcss::pcom::LEFT_SIDE ){ at_team = stadium->team_l; } else if ( team_side == rcss::pcom::RIGHT_SIDE ){ at_team = stadium->team_r; } else if ( stadium->team_l->enable && team_name == stadium->team_l->name ){ at_team = stadium->team_l; } else if ( stadium->team_r->enable && team_name == stadium->team_r->name ){ at_team = stadium->team_r; } else { return; } if ( !at_team->enable ){ return; } if ( at_unum < 1 || at_unum > at_team->n ){ return; } // make sure we aren't trying to focus on ourselves. if( at_team == team && at_unum == unum ){ return; } // turn attention to on focusOn( *( at_team->player[ at_unum - 1 ] ) ); }}void Player::tackle( double power ){ if ( command_done == FALSE && isTackling() == false ) { command_done = true; M_tackle_cycles = ServerParam::instance().tackleCycles(); M_tackle_count++; PVector player_2_ball = stadium->ball->pos - pos; player_2_ball.rotate( -angle ); double tackle_dist; if ( player_2_ball.x > 0.0 ){ //cant tackle backwards. tackle_dist = ServerParam::instance().tackleDist(); } else{ tackle_dist = ServerParam::instance().tackleBackDist(); } double prob = ( pow( fabs( player_2_ball.x ) / tackle_dist, ServerParam::instance().tackleExponent() ) + pow( fabs( player_2_ball.y ) / ServerParam::instance().tackleWidth(), ServerParam::instance().tackleExponent() ) ); if ( prob < 1.0 ) { boost::bernoulli_distribution< rcss::random::DefaultRNG > rng( rcss::random::DefaultRNG::instance(), 1 - prob ); if ( rng() ) { alive |= TACKLE ; if ( stadium->mode == PM_BeforeKickOff || stadium->mode == PM_AfterGoal_Left || stadium->mode == PM_AfterGoal_Right || stadium->mode == PM_OffSide_Left || stadium->mode == PM_OffSide_Right || stadium->mode == PM_Back_Pass_Left || stadium->mode == PM_Back_Pass_Right || stadium->mode == PM_Free_Kick_Fault_Left || stadium->mode == PM_Free_Kick_Fault_Right|| stadium->mode == PM_TimeOver ) { return ; } if ( ServerParam::instance().useoffside ){ if ( stadium->mark_offside_mark( this ) ){ return; } } // Calculate the accleration that will be applied to the ball double eff_power = ( ServerParam::instance().tacklePowerRate() * NormalizeKickPower( power ) ); // Reduce the acceleration by the probability of kicking it. // For instance when the ball is on the boundry of the tackle // area, the acceleration is very low as one only barely touches // the ball. // eff_power *= 1 - prob; stadium->ball->push( Polar2PVector( eff_power, angle ) ); stadium->ball->angle = angle ; stadium->kickTaken( *this ); // pfr 8/14/00: for RC2000 evaluation // add noise to kick Value maxrnd = ( kick_rand * power * ( 1 - prob ) / ServerParam::instance().maxp ); PVector kick_noise( drand( -maxrnd, maxrnd ), drand( -maxrnd, maxrnd ) ); stadium->ball->push(kick_noise); //stadium->last_touch = this ; stadium->last_kicker = this; stadium->M_caught_ball = NULL; stadium->setPossibleBackPasser( *this ); } } else { alive |= TACKLE_FAULT; } }}void Player::clang( int min, int max){// std::ostrstream resp;// resp << "(ok clang (ver " << min << " " << max << "))" << std::ends;// send( resp.str() );// resp.freeze( false ); M_clang_min_ver = min; M_clang_max_ver = max; sendOKClang(); if( team != NULL && team->olcoach != NULL && team->olcoach->assignedp ) { team->olcoach->sendPlayerClangVer( *this ); }}void Player::ear( bool on, rcss::pcom::TEAM team_side, string team_name, rcss::pcom::EAR_MODE mode ){ Side side = NEUTRAL; if ( team_side == rcss::pcom::OUR ){ side = team->side; } else if ( team_side == rcss::pcom::OPP ){ side = -team->side; } else if ( team_side == rcss::pcom::LEFT_SIDE ){ side = LEFT; } else if ( team_side == rcss::pcom::RIGHT_SIDE ){ side = RIGHT; } else if ( team_name.length() > 0 ){ if ( stadium->team_l->enable && team_name == stadium->team_l->name ){ side = stadium->team_l->side; } else if ( stadium->team_r->enable && team_name == stadium->team_r->name ){ side = stadium->team_r->side; } else { sendErrorNoTeamName( team_name );// std::ostrstream ostr;// ostr << "(error no team with name " << team_name << ")" << std::ends;// send( ostr.str() );// ostr.freeze( false ); return; } } //std::cerr << "Ear:\n"; //std::cerr << "\tSide: " << ( side == LEFT ? "left" : "right" ) << std::endl; bool partial = true; bool complete = true; if ( mode == rcss::pcom::PARTIAL ){ complete = false; } else if ( mode == rcss::pcom::COMPLETE ) { partial = false; } //std::cerr << "\tOn: " << on << std::endl; //std::cerr << "\t\tPartial: " << partial << std::endl; //std::cerr << "\t\tComplete: " << complete << std::endl; setEar( on, side, complete, partial );}void Player::send_visual_info(void) { sendVisual(); return; sendcnt++ ; if (sendcnt >= vis_send) sendcnt = 0 ; else return ; if ( version >= 8.0 ) { if ( highquality ) { VisualSensor_v8::high_data_t data; data.set ( *stadium, *this ); send ( data ); } else { VisualSensor_v8::low_data_t data; data.set ( *stadium, *this ); send ( data ); } } else if ( version >= 7.0 ) { if ( highquality ) { VisualSensor_v7::high_data_t data; data.set ( *stadium, *this ); send ( data ); } else { VisualSensor_v7::low_data_t data; data.set ( *stadium, *this ); send ( data ); } } else if ( version >= 6.0 ) { if ( highquality ) { VisualSensor_v6::high_data_t data; data.set ( *stadium, *this ); send ( data ); } else { VisualSensor_v6::low_data_t data; data.set ( *stadium, *this ); send ( data ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -