referee.cpp

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

CPP
2,262 行
字号
         && pm != PM_AfterGoal_Left         && pm != PM_OffSide_Right         && pm != PM_OffSide_Left         && pm != PM_Back_Pass_Right         && pm != PM_Back_Pass_Left         && pm != PM_Free_Kick_Fault_Right         && pm != PM_Free_Kick_Fault_Left         && pm != PM_CatchFault_Right         && pm != PM_CatchFault_Left )    {        if ( M_stadium.ball().vel().x != 0.0             || M_stadium.ball().vel().y != 0.0 )        {            M_stadium.change_play_mode( PM_PlayOn );        }    }    M_stadium.placePlayersInField();    if ( pm != PM_PlayOn         && pm != PM_TimeOver         && pm != PM_GoalKick_Left         && pm != PM_GoalKick_Right )    {        clearPlayersFromBall( (Side)(-M_stadium.kickOffSide() ) );    }    if ( freeKick( pm ) )    {        if ( M_timer > -1 )        {            M_timer--;        }        if ( M_timer == 0 )        {            awardDropBall( M_stadium.ball().pos() );        }    }}voidFreeKickRef::playModeChange( PlayMode pm ){    if ( pm != PM_PlayOn )    {        M_kick_taken = false;    }    if ( pm == PM_KickOff_Left         || pm == PM_KickIn_Left         || pm == PM_FreeKick_Left         || pm == PM_IndFreeKick_Left         || pm == PM_CornerKick_Left         || pm == PM_GoalKick_Left )    {        clearPlayersFromBall( RIGHT );    }    else if ( pm == PM_KickOff_Right              || pm == PM_KickIn_Right              || pm == PM_FreeKick_Right              || pm == PM_IndFreeKick_Right              || pm == PM_CornerKick_Right              || pm == PM_GoalKick_Right )    {        clearPlayersFromBall( LEFT );    }    else if ( pm == PM_Drop_Ball )    {        clearPlayersFromBall( NEUTRAL );    }    if ( goalKick( pm ) )    {        M_timer = ServerParam::instance().dropTime();        if ( ! goalKick( M_stadium.playmode() ) )        {            M_goal_kick_count = 0;        }        else        {            M_goal_kick_count++;        }    }    else    {        M_goal_kick_count = 0;    }    if ( freeKick( pm ) )    {        M_timer = ServerParam::instance().dropTime();    }    if ( ! freeKick( pm ) && ! goalKick( pm ) )    {        M_timer = -1;    }    if ( pm == PM_Free_Kick_Fault_Left         || pm == PM_Free_Kick_Fault_Right )    {        M_stadium.clearBallCatcher();        M_after_free_kick_fault_time = 0;    }}voidFreeKickRef::callFreeKickFault( Side side, PVector pos ){    pos = truncateToPitch( pos );    pos = moveOutOfPenalty( side, pos );    M_stadium.clearBallCatcher();    if ( side == LEFT )    {        M_stadium.placeBall( PM_Free_Kick_Fault_Left, RIGHT, pos );    }    else if ( side == RIGHT )    {        M_stadium.placeBall( PM_Free_Kick_Fault_Right, LEFT, pos );    }    M_after_free_kick_fault_time = 0;}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::ballStopped(){    return M_stadium.ball().vel().r() < ServerParam::instance().stoppedBallVel();}boolFreeKickRef::tooManyGoalKicks(){    return M_goal_kick_count >= ServerParam::instance().maxGoalKicks();}voidFreeKickRef::placePlayersForGoalkick(){    static const RArea p_l( PVector( - ServerParam::PITCH_LENGTH/2                                     + ServerParam::PENALTY_AREA_LENGTH/2.0,                                     0.0 ),                            PVector( ServerParam::PENALTY_AREA_LENGTH,                                     ServerParam::PENALTY_AREA_WIDTH ) );    static const RArea p_r( PVector( + ServerParam::PITCH_LENGTH/2                                     - ServerParam::PENALTY_AREA_LENGTH/2.0,                                     0.0 ),                            PVector( ServerParam::PENALTY_AREA_LENGTH,                                     ServerParam::PENALTY_AREA_WIDTH ) );    const RArea * p_area;    int oppside;    if ( M_stadium.playmode() == PM_GoalKick_Left )    {        oppside = RIGHT;        p_area = &p_l;    }    else    {        oppside = LEFT;        p_area = &p_r;    }    const Stadium::PlayerCont::iterator end = M_stadium.players().end();    for ( Stadium::PlayerCont::iterator p = M_stadium.players().begin();          p != end;          ++p )    {        if ( (*p)->state() == DISABLE ) continue;        if ( (*p)->side() == oppside )        {            const double size = (*p)->size();            RArea expand_area( p_area->left - size,                               p_area->right + size,                               p_area->top - size,                               p_area->bottom + size );            if ( expand_area.inArea( (*p)->pos() ) )            {                PVector new_pos = expand_area.nearestEdge( (*p)->pos() );                if ( new_pos.x * oppside >= ServerParam::PITCH_LENGTH/2 )                {                    new_pos.x                        = ( ServerParam::PITCH_LENGTH/2                            - ServerParam::PENALTY_AREA_LENGTH                            - size )                        * oppside;                }                (*p)->moveTo( new_pos );            }        }    }}//**********// TouchRef//**********const int TouchRef::AFTER_GOAL_WAIT = 50;voidTouchRef::analyse(){    analyseImpl();    M_prev_ball_pos = M_stadium.ball().pos();}voidTouchRef::analyseImpl(){    if ( isPenaltyShootOut( M_stadium.playmode() ) )    {        return;    }    if ( M_stadium.playmode() == PM_AfterGoal_Left )    {        if ( ++M_after_goal_time > AFTER_GOAL_WAIT )        {            M_stadium.placeBall( PM_KickOff_Right, RIGHT, PVector(0.0,0.0) );            placePlayersInTheirField();        }        return;    }    if ( M_stadium.playmode() == PM_AfterGoal_Right )    {        if ( ++M_after_goal_time > AFTER_GOAL_WAIT )        {            M_stadium.placeBall( PM_KickOff_Left, LEFT, PVector(0.0,0.0) );            placePlayersInTheirField();        }        return;    }    if ( checkGoal() )    {        return;    }    if ( M_stadium.playmode() != PM_AfterGoal_Left         && M_stadium.playmode() != PM_AfterGoal_Right         && M_stadium.playmode() != PM_TimeOver )    {        if ( std::fabs( M_stadium.ball().pos().x )             > ServerParam::PITCH_LENGTH * 0.5             + ServerParam::instance().ballSize() )        {            // check for goal kick or corner kick            Side side = NEUTRAL;            if ( M_last_touched != NULL )            {                side = M_last_touched->side();            }            if ( M_stadium.ball().pos().x                 > ServerParam::PITCH_LENGTH * 0.5                 + ServerParam::instance().ballSize() )            {                if ( side == RIGHT )                {                    awardCornerKick( LEFT, M_stadium.ball().pos() );                }                else if ( M_stadium.ballCatcher() == 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                      < ServerParam::PITCH_LENGTH * 0.5                      - ServerParam::instance().ballSize() )            {                if ( side == LEFT )                {                    awardCornerKick( RIGHT, M_stadium.ball().pos() );                }                else if ( M_stadium.ballCatcher() == 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 ( std::fabs( M_stadium.ball().pos().y )                  > ServerParam::PITCH_WIDTH * 0.5                  + ServerParam::instance().ballSize() )        {            // check for kick in.            Side side = NEUTRAL;            if ( M_last_touched != NULL )            {                side = M_last_touched->side();            }            if ( side == NEUTRAL )            {                // somethings gone wrong but give a drop ball                awardDropBall( M_stadium.ball().pos() );            }            else            {                awardKickIn( (Side)( -side ), M_stadium.ball().pos() );            }        }    }}voidTouchRef::kickTaken( const Player & kicker ){    if ( M_stadium.playmode() == PM_PlayOn         && M_last_indirect_kicker         && M_last_indirect_kicker != &kicker )    {        M_last_indirect_kicker = NULL;        M_indirect_mode = false;    }    if ( M_indirect_mode )    {        M_last_indirect_kicker = &kicker;    }    M_last_touched = &kicker;}voidTouchRef::ballTouched( const Player & kicker ){    if ( M_stadium.playmode() == PM_PlayOn         && M_last_indirect_kicker         && M_last_indirect_kicker != &kicker )    {        M_last_indirect_kicker = NULL;        M_indirect_mode = false;    }    if ( M_indirect_mode )    {        M_last_indirect_kicker = &kicker;    }    M_last_touched = &kicker;}voidTouchRef::playModeChange( PlayMode pm ){    if ( pm != PM_PlayOn )    {        M_last_touched = NULL;    }    if ( indirectFreeKick( pm ) )    {        M_last_indirect_kicker = NULL;        M_indirect_mode = true;    }    else if ( pm != PM_PlayOn && pm != PM_Drop_Ball )    {        M_last_indirect_kicker = NULL;        M_indirect_mode = false;    }}boolTouchRef::checkGoal(){    if ( M_stadium.playmode() == PM_AfterGoal_Left         || M_stadium.playmode() == PM_AfterGoal_Right         || M_stadium.playmode() == PM_TimeOver )    {        return false;    }    if ( M_indirect_mode )    {        return false;    }    // FIFA rules:  Ball has to be completely outside of the pitch to be considered out    //    static RArea pt( PVector(0.0,0.0),    //                       PVector( ServerParam::PITCH_LENGTH    //                                + ServerParam::instance().ballSize() * 2,    //                                ServerParam::PITCH_WIDTH    //                                + ServerParam::instance().ballSize() * 2 ) );    if ( std::fabs( M_stadium.ball().pos().x )         <= ServerParam::PITCH_LENGTH * 0.5 + ServerParam::instance().ballSize() )    {        return false;    }    if ( ( ! M_stadium.ballCatcher()           || M_stadium.ballCatcher()->side() == LEFT )

⌨️ 快捷键说明

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