📄 referee.cc
字号:
M_timer--; if( M_timer == 0 ) awardDropBall( M_stadium.ball->pos ); }}voidFreeKickRef::playModeChange( PlayMode pm ){ if( pm != PM_PlayOn ) M_kick_taken = false; if( goalKick( pm ) ) { M_timer = ServerParam::instance().drop_time; if( !goalKick( M_stadium.mode ) ) M_goal_kick_count = 0; else M_goal_kick_count++; } else M_goal_kick_count = 0; if( freeKick( pm ) ) M_timer = ServerParam::instance().drop_time; if( indirectFreeKick( pm ) ) { M_stadium.m_indirect = true; if( pm == PM_IndFreeKick_Right ) m_indirect_side = RIGHT; else if( pm == PM_IndFreeKick_Left ) m_indirect_side = LEFT; else m_indirect_side = NEUTRAL; } else if( pm != PM_PlayOn && pm != PM_Drop_Ball ) { M_stadium.m_indirect = false; m_indirect_side = NEUTRAL; } if( !freeKick( pm ) && !goalKick( pm ) ) M_timer = -1;}boolFreeKickRef::goalKick( PlayMode pm ){ return ( pm == PM_GoalKick_Right || pm == PM_GoalKick_Left );}boolFreeKickRef::freeKick( PlayMode pm ){ switch( pm ) { case PM_KickOff_Right: case PM_KickIn_Right: case PM_FreeKick_Right: case PM_CornerKick_Right: case PM_IndFreeKick_Right: case PM_KickOff_Left: case PM_KickIn_Left: case PM_FreeKick_Left: case PM_CornerKick_Left: case PM_IndFreeKick_Left: return true; default: return false; }}boolFreeKickRef::indirectFreeKick( PlayMode pm ){ switch( pm ) { case PM_IndFreeKick_Right: case PM_IndFreeKick_Left: return true; default: return false; }}boolFreeKickRef::ballStopped(){ return M_stadium.ball->vel.r() < ServerParam::instance().stoppedBallVel(); }boolFreeKickRef::ballInPenaltyArea(){ PVector ball_pos = M_stadium.ball->pos; return ( fabs( ball_pos.x ) > ( PITCH_LENGTH * 0.5 - PENALTY_AREA_LENGTH + ServerParam::instance().bsize ) && fabs( ball_pos.x ) < PITCH_LENGTH * 0.5 + ServerParam::instance().bsize && fabs( ball_pos.y ) < PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize );}boolFreeKickRef::tooManyGoalKicks(){ return M_goal_kick_count >= ServerParam::instance().maxGoalKicks(); }//**********// TouchRef//**********voidTouchRef::analyse(){ if( M_stadium.penaltyShootOut( ) ) return ; if( !M_stadium.check_goal() && M_stadium.mode != PM_AfterGoal_Left && M_stadium.mode != PM_AfterGoal_Right && M_stadium.mode != PM_TimeOver ) { if( fabs( M_stadium.ball->pos.x ) > PITCH_LENGTH * 0.5 + ServerParam::instance().bsize ) { // check for goal kick or corner kick Side side = NEUTRAL; if( M_last != NULL ) side = M_last->team->side; if( M_stadium.ball->pos.x > PITCH_LENGTH * 0.5 + ServerParam::instance().bsize ) { if( side == RIGHT ) awardCornerKick( LEFT, M_stadium.ball->pos ); else if ( M_stadium.M_caught_ball == NULL ) awardGoalKick( RIGHT, M_stadium.ball->pos ); else // the ball is caught and the goalie must have // moved to a position beyond the opponents goal // line. Let the catch ref clean up the mess return; } else if( M_stadium.ball->pos.x < PITCH_LENGTH * 0.5 - ServerParam::instance().bsize ) { if( side == LEFT ) awardCornerKick( RIGHT, M_stadium.ball->pos ); else if ( M_stadium.M_caught_ball == NULL ) awardGoalKick( LEFT, M_stadium.ball->pos ); else // the ball is caught and the goalie must have // moved to a position beyond the opponents goal // line. Let the catch ref clean up the mess return; } } else if( fabs( M_stadium.ball->pos.y ) > PITCH_WIDTH * 0.5 + ServerParam::instance().bsize ) { // check for kick in. Side side = NEUTRAL; if( M_last != NULL ) side = M_last->team->side; if( side == NEUTRAL ) { // somethings gone wrong but give a drop ball awardDropBall( M_stadium.ball->pos ); } else { awardKickIn( -side, M_stadium.ball->pos ); } } }}voidTouchRef::kickTaken( Player& kicker ){ M_last = &kicker;}voidTouchRef::ballTouched( Player& kicker ){ M_last = &kicker;}voidTouchRef::playModeChange( PlayMode pm ){ if( pm != PM_PlayOn ) M_last = NULL;}//************// KeepawayRef//************voidKeepawayRef::analyse(){ if( ServerParam::instance().kaway ) { if ( M_stadium.mode == PM_PlayOn ) { if( !ballInKeepawayArea() ) { logEpisode( "o" ); M_stadium.say( trainingMsg ); resetField(); } else if( M_take_time >= TURNOVER_TIME ) { logEpisode( "t" ); M_stadium.say( trainingMsg ); resetField(); } else { bool keeperPoss = false; for( int i = 0; i < MAX_PLAYER * 2; i++ ) { PVector ppos = M_stadium.player[i]->pos; if( M_stadium.player[i]->alive != DISABLE && ppos.distance( M_stadium.ball->pos ) < ServerParam::instance().kmargin + ServerParam::instance().psize + ServerParam::instance().bsize ) { if( M_stadium.player[i]->team->side == LEFT ) { keeperPoss = true; } else if( M_stadium.player[i]->team->side == RIGHT ) { keeperPoss = false; M_take_time++; break; } } } if( keeperPoss ) M_take_time = 0; } } else if ( ServerParam::instance().kawayStart() >= 0 ) { if ( difftime( time( NULL ), M_start_time ) > ServerParam::instance().kawayStart() ) M_stadium.change_play_mode( PM_PlayOn ); } }}voidKeepawayRef::kickTaken( Player& ){}voidKeepawayRef::ballTouched( Player& ){}voidKeepawayRef::playModeChange( PlayMode pm ){ if( ServerParam::instance().kaway ) { if( pm == PM_PlayOn && M_episode == 0 ) { M_episode = 1; for( int i = 0; i < MAX_PLAYER * 2; i++ ) { if( M_stadium.player[i]->alive != DISABLE ) { if( M_stadium.player[i]->team->side == LEFT ) M_keepers++; else if( M_stadium.player[i]->team->side == RIGHT ) M_takers++; } } logHeader(); resetField(); } }}boolKeepawayRef::ballInKeepawayArea(){ PVector ball_pos = M_stadium.ball->pos; return ( fabs( ball_pos.x ) < ServerParam::instance().ka_length * 0.5 && fabs( ball_pos.y ) < ServerParam::instance().ka_width * 0.5 );}voidKeepawayRef::logHeader(){ if ( M_stadium.kaway_log.is_open() ) { M_stadium.kaway_log << "# Keepers: " << M_keepers << endl << "# Takers: " << M_takers << endl << "# Region: " << ServerParam::instance().ka_length << " x " << ServerParam::instance().ka_width << endl; M_stadium.kaway_log << "#\n"; M_stadium.kaway_log << "# Description of Fields:\n" << "# 1) Episode number\n" << "# 2) Start time in simulator steps (100ms)\n" << "# 3) End time in simulator steps (100ms)\n" << "# 4) Duration in simulator steps (100ms)\n" << "# 5) (o)ut of bounds / (t)aken away\n"; M_stadium.kaway_log << "#\n"; }}voidKeepawayRef::logEpisode( const char *endCond ){ if ( M_stadium.kaway_log.is_open() ) { M_stadium.kaway_log << M_episode++ << "\t" << M_time << "\t" << M_stadium.time << "\t" << M_stadium.time - M_time << "\t" << endCond << endl; } M_time = M_stadium.time;}voidKeepawayRef::resetField(){ int keeper_pos = irand( M_keepers ); for( int i = 0; i < MAX_PLAYER * 2; i++ ) { if( M_stadium.player[i]->alive != DISABLE ) { double x, y; if( M_stadium.player[i]->team->side == LEFT ) { switch( keeper_pos ) { case 0: x = -ServerParam::instance().ka_length * 0.5 + drand( 0, 3 ); y = -ServerParam::instance().ka_width * 0.5 + drand( 0, 3 ); break; case 1: x = ServerParam::instance().ka_length * 0.5 - drand( 0, 3 ); y = -ServerParam::instance().ka_width * 0.5 + drand( 0, 3 ); break; case 2: x = ServerParam::instance().ka_length * 0.5 - drand( 0, 3 ); y = ServerParam::instance().ka_width * 0.5 - drand( 0, 3 ); break; default: x = drand( -1, 1 ); y = drand( -1, 1 ); break; } M_stadium.player[i]->place( PVector( x, y ) ); keeper_pos = ( keeper_pos + 1 ) % M_keepers;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -