📄 referee.cc
字号:
// -*-c++-*-/*************************************************************************** referee.h Refereeing module ------------------- begin : 16-May-2002 copyright : (C) 2001 by The RoboCup Soccer Server Maintenance Group. email : sserver-admin@lists.sourceforge.net ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * * * ***************************************************************************/#include "referee.h"#include "field.h"char* KeepawayRef::trainingMsg = "training Keepaway 1";const int KeepawayRef::TURNOVER_TIME = 4;PVectorReferee::truncateToPitch( PVector pos ){ if( pos.y > PITCH_WIDTH * 0.5 + ServerParam::instance().bsize ) pos.y = PITCH_WIDTH * 0.5 + ServerParam::instance().bsize; else if( pos.y < -PITCH_WIDTH * 0.5 - ServerParam::instance().bsize ) pos.y = -PITCH_WIDTH * 0.5 - ServerParam::instance().bsize; if( pos.x > PITCH_LENGTH * 0.5 + ServerParam::instance().bsize ) pos.x = PITCH_LENGTH * 0.5 + ServerParam::instance().bsize; else if( pos.x < -PITCH_LENGTH * 0.5 - ServerParam::instance().bsize) pos.x = -PITCH_LENGTH * 0.5 - ServerParam::instance().bsize; return pos;}PVectorReferee::moveOutOfPenalty( Side side, PVector pos ){ if( side != RIGHT ) { if( pos.x < -PITCH_LENGTH * 0.5 + PENALTY_AREA_LENGTH + ServerParam::instance().bsize && fabs( pos.y ) < PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize ) { pos.x = -PITCH_LENGTH * 0.5 + PENALTY_AREA_LENGTH + ServerParam::instance().bsize; if( pos.y > 0 ) pos.y = PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize; else pos.y = -PENALTY_AREA_WIDTH * 0.5 - ServerParam::instance().bsize; } } if( side != LEFT ) { if( pos.x > PITCH_LENGTH * 0.5 - PENALTY_AREA_LENGTH - ServerParam::instance().bsize && fabs( pos.y ) < PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize ) { pos.x = PITCH_LENGTH * 0.5 - PENALTY_AREA_LENGTH - ServerParam::instance().bsize; if( pos.y > 0 ) pos.y = PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize; else pos.y = -PENALTY_AREA_WIDTH * 0.5 - ServerParam::instance().bsize; } } return pos;}PVectorReferee::moveIntoPenalty( Side side, PVector pos ){ if( side != RIGHT ) { if( pos.x > -PITCH_LENGTH * 0.5 + PENALTY_AREA_LENGTH + ServerParam::instance().bsize ) pos.x = -PITCH_LENGTH * 0.5 + PENALTY_AREA_LENGTH + ServerParam::instance().bsize; if( fabs( pos.y ) > PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize ) { if( pos.y > 0 ) pos.y = PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize; else pos.y = -PENALTY_AREA_WIDTH * 0.5 - ServerParam::instance().bsize; } } if( side != LEFT ) { if( pos.x < PITCH_LENGTH * 0.5 - PENALTY_AREA_LENGTH - ServerParam::instance().bsize ) pos.x = PITCH_LENGTH * 0.5 - PENALTY_AREA_LENGTH - ServerParam::instance().bsize; if( fabs( pos.y ) > PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize ) { if( pos.y > 0 ) pos.y = PENALTY_AREA_WIDTH * 0.5 + ServerParam::instance().bsize; else pos.y = -PENALTY_AREA_WIDTH * 0.5 - ServerParam::instance().bsize; } } return pos;}voidReferee::awardFreeKick( Side side, PVector pos ){ pos = truncateToPitch( pos ); pos = moveOutOfPenalty( -side, pos ); if( side == LEFT ) M_stadium.placeBall( PM_FreeKick_Left, LEFT, pos ); else if( side == RIGHT ) M_stadium.placeBall( PM_FreeKick_Right, RIGHT, pos );}voidReferee::callCatchFault( Side side, PVector pos ){ pos = truncateToPitch( pos ); pos = moveIntoPenalty( -side, pos ); M_stadium.M_caught_ball = NULL; if( side == LEFT ) M_stadium.placeBall( PM_CatchFault_Right, LEFT, pos ); else if( side == RIGHT ) M_stadium.placeBall( PM_CatchFault_Left, RIGHT, pos );}voidReferee::callFreeKickFault( Side side, PVector pos ){ pos = truncateToPitch( pos ); pos = moveOutOfPenalty( side, pos ); M_stadium.M_caught_ball = NULL; if( side == LEFT ) M_stadium.placeBall( PM_Free_Kick_Fault_Left, RIGHT, M_stadium.ball->pos ); else if( side == RIGHT ) M_stadium.placeBall( PM_Free_Kick_Fault_Right, LEFT, M_stadium.ball->pos );}voidReferee::awardGoalKick( Side side, PVector pos ){ if( pos.y > 0 ) pos.y = GOAL_AREA_WIDTH * 0.5; else pos.y = -GOAL_AREA_WIDTH * 0.5; M_stadium.M_caught_ball = NULL; if( side == LEFT ) { pos.x = -PITCH_LENGTH * 0.5 + GOAL_AREA_LENGTH; M_stadium.placeBall( PM_GoalKick_Left, LEFT, pos ); } else { pos.x = PITCH_LENGTH * 0.5 - GOAL_AREA_LENGTH; M_stadium.placeBall( PM_GoalKick_Right, RIGHT, pos ); }}voidReferee::awardDropBall( PVector pos ){ M_stadium.M_caught_ball = NULL; pos = truncateToPitch( pos ); pos = moveOutOfPenalty( NEUTRAL, pos ); M_stadium.placeBall( PM_Drop_Ball, NEUTRAL, pos ); M_stadium.check_player_in_field() ; if( ! M_stadium.penaltyShootOut( ) ) M_stadium.change_play_mode(PM_PlayOn) ;}voidReferee::awardKickIn( Side side, PVector pos ){ M_stadium.M_caught_ball = NULL; pos = truncateToPitch( pos ); if( side == LEFT ) M_stadium.placeBall( PM_KickIn_Left, LEFT, pos ); else M_stadium.placeBall( PM_KickIn_Right, RIGHT, pos );}voidReferee::awardCornerKick( Side side, PVector pos ){ M_stadium.M_caught_ball = NULL; if( pos.y > 0 ) pos.y = PITCH_WIDTH * 0.5 - ServerParam::instance().ckmargin; else pos.y = -PITCH_WIDTH * 0.5 + ServerParam::instance().ckmargin; if( side == LEFT ) { pos.x = PITCH_LENGTH * 0.5 - ServerParam::instance().ckmargin; M_stadium.placeBall( PM_CornerKick_Left, LEFT, pos ); } else { pos.x = -PITCH_LENGTH * 0.5 + ServerParam::instance().ckmargin; M_stadium.placeBall( PM_CornerKick_Right, RIGHT, pos ); }}boolReferee::inPenaltyArea( Side side, PVector pos ){ if( side != RIGHT ) { // according to FIFA the ball is catchable if it is at // least partly within the penalty area, thus we add ball size static RArea pen_area( PVector( -PITCH_LENGTH/2+PENALTY_AREA_LENGTH/2.0, 0.0 ), PVector( PENALTY_AREA_LENGTH + ServerParam::instance().bsize * 2, PENALTY_AREA_WIDTH + ServerParam::instance().bsize * 2 ) ) ; if( !pen_area.inArea( pos ) ) { return false; } } if( side != LEFT ) { // according to FIFA the ball is catchable if it is at // least partly within the penalty area, thus we add ball size static RArea pen_area( PVector( +PITCH_LENGTH/2-PENALTY_AREA_LENGTH/2.0, 0.0 ), PVector( PENALTY_AREA_LENGTH + ServerParam::instance().bsize * 2, PENALTY_AREA_WIDTH + ServerParam::instance().bsize * 2 ) ) ; if( !pen_area.inArea( M_stadium.ball->pos ) ) { return false; } } return true;}//**********// FreeKickRef//**********voidFreeKickRef::kickTaken( Player& kicker ){ if( M_stadium.penaltyShootOut( ) ) return; if( goalKick( M_stadium.mode ) ) { if( M_kick_taken ) { // ball was not kicked directly into play (i.e. out of penalty area // without touching another player if( &kicker != M_kick_taker ) { if( ServerParam::instance().properGoalKicks() ) awardGoalKick( M_kick_taker->team->side, M_stadium.ball->pos ); } else if( M_kick_taker_dashes != M_kick_taker->count_dash ) { if( ServerParam::instance().freeKickFaults() ) callFreeKickFault( kicker.team->side, M_stadium.ball->pos ); else if( ServerParam::instance().properGoalKicks() ) awardGoalKick( M_kick_taker->team->side, M_stadium.ball->pos ); } // else it's part of a compound kick } else { M_kick_taken = true; M_kick_taker = &kicker; M_kick_taker_dashes = M_kick_taker->count_dash; } } else if( M_stadium.mode != PM_PlayOn ) { M_kick_taken = true; M_kick_taker = &kicker; M_kick_taker_dashes = M_kick_taker->count_dash; M_stadium.change_play_mode( PM_PlayOn ); } else // PM_PlayOn { if( m_indirect_side != kicker.team->side ) { M_stadium.m_indirect = false; m_indirect_side = NEUTRAL; } if( M_kick_taken ) { if( M_kick_taker != &kicker ) { M_kick_taken = false; M_stadium.m_indirect = false; m_indirect_side = NEUTRAL; } else if( M_kick_taker->count_dash > M_kick_taker_dashes && ServerParam::instance().freeKickFaults() ) callFreeKickFault( M_kick_taker->team->side, M_stadium.ball->pos ); } }}voidFreeKickRef::ballTouched( Player& player ){ if( M_kick_taken ) { if( M_kick_taker == &player && ServerParam::instance().freeKickFaults() ) { if( M_kick_taker->count_dash > M_kick_taker_dashes ) { callFreeKickFault( M_kick_taker->team->side, M_stadium.ball->pos ); } /// else do nothing yet as the player just colided with the ball instead of dashing into it } else { M_kick_taken = false; M_stadium.m_indirect = false; m_indirect_side = NEUTRAL; } }}voidFreeKickRef::analyse(){ if( M_stadium.penaltyShootOut( ) ) return; if( goalKick( M_stadium.mode ) ) { if( !ballInPenaltyArea() ) M_stadium.change_play_mode( PM_PlayOn ); else { if( M_kick_taken && ServerParam::instance().properGoalKicks() ) { if( ballStopped() ) { if( tooManyGoalKicks() ) awardFreeKick( -M_kick_taker->team->side, M_stadium.ball->pos ); else awardGoalKick( M_kick_taker->team->side, M_stadium.ball->pos ); } } else { if( M_timer > -1 ) M_timer--; if( M_timer == 0 ) awardDropBall( M_stadium.ball->pos ); } } } else if( freeKick( M_stadium.mode ) ) { if( M_timer > -1 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -