00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00055 #include <iostream>
00056 #include <stdio.h>
00057 #ifdef Solaris
00058 #include <strings.h>
00059 #else
00060 #include <string.h>
00061 #endif
00062
00063 #include "SoccerTypes.h"
00064 #include "Parse.h"
00065
00066
00067
00068
00069
00070
00075 Time::Time( int iTime, int iStopped )
00076 {
00077 m_iTime = iTime;
00078 m_iStopped = iStopped;
00079 }
00080
00087 bool Time::updateTime( int iTime )
00088 {
00089 if( m_iTime == iTime )
00090 m_iStopped++;
00091 else
00092 {
00093 m_iTime = iTime;
00094 m_iStopped = 0;
00095 }
00096 return true;
00097 }
00098
00103 bool Time::setTimeStopped( int iTime )
00104 {
00105 m_iStopped = iTime;
00106 return true;
00107 }
00108
00112 int Time::getTime( )
00113 {
00114 return m_iTime;
00115 }
00116
00120 int Time::getTimeStopped( )
00121 {
00122 return m_iStopped;
00123 }
00124
00128 int Time::getTimeDifference( Time t )
00129 {
00130 if( getTime() < t.getTime() )
00131 return getTime() - t.getTime() - t.getTimeStopped();
00132 else if( getTime() == t.getTime() )
00133 return getTimeStopped() - t.getTimeStopped();
00134 else
00135 return getTime() - t.getTime();
00136 }
00137
00142 bool Time::isStopped( )
00143 {
00144 return m_iStopped != 0;
00145 }
00146
00161 Time Time::getTimeAddedWith( int iCycles )
00162 {
00163 int iTime = getTime();
00164 int iStopped = getTimeStopped();
00165
00166 if( iCycles > 0 )
00167 {
00168 if( iStopped > 0 )
00169 iStopped += iCycles;
00170 else
00171 iTime += iCycles;
00172 }
00173 else
00174 {
00175 if( iStopped > 0 && iStopped >= iCycles)
00176 iStopped += iCycles;
00177 else if( iStopped > 0 )
00178 {
00179 iStopped = 0;
00180 iCycles += iStopped;
00181 iTime += iCycles;
00182 }
00183 else
00184 iTime += iCycles;
00185 if( iTime < 0 )
00186 iTime = 0;
00187 }
00188 return Time( iTime, iStopped );
00189 }
00190
00195 bool Time::addToTime( int iCycles )
00196 {
00197 *this = getTimeAddedWith( iCycles );
00198 return true;
00199 }
00200
00205 void Time::show( ostream &os )
00206 {
00207 os << "(" << getTime() << "," << getTimeStopped() << ")";
00208 }
00209
00215 Time Time::operator + ( const int &i )
00216 {
00217 return getTimeAddedWith( i );
00218 }
00219
00226 Time Time::operator + ( Time t )
00227 {
00228 return Time( getTime() + t.getTime(), t.getTimeStopped() );
00229 }
00230
00236 Time Time::operator - ( const int &i )
00237 {
00238 return getTimeAddedWith( -i );
00239 }
00240
00245 int Time::operator - ( Time t )
00246 {
00247 return getTimeDifference( t );
00248 }
00249
00254 void Time::operator = ( const int &i )
00255 {
00256 updateTime( i );
00257 setTimeStopped( 0 );
00258 }
00259
00263 void Time::operator += ( const int &i )
00264 {
00265 addToTime( i );
00266 }
00267
00273 void Time::operator += ( Time t )
00274 {
00275 updateTime ( getTime() + t.getTime() );
00276 setTimeStopped( t.getTimeStopped() );
00277 }
00278
00283 void Time::operator -= ( const int &i )
00284 {
00285 addToTime( -i );
00286 }
00287
00292 void Time::operator -= ( Time t )
00293 {
00294 updateTime ( getTime() - t.getTime() );
00295 setTimeStopped( 0 );
00296 }
00297
00298
00307 bool Time::operator != ( const int &i )
00308 {
00309 return getTimeDifference( Time(i, 0) ) != 0;
00310 }
00311
00319 bool Time::operator != ( Time t )
00320 {
00321 return getTimeDifference( t ) != 0;
00322 }
00323
00332 bool Time::operator == ( const int &i )
00333 {
00334 return !( *this != i );
00335 }
00336
00342 bool Time::operator == ( Time t )
00343 {
00344 return !( *this != t );
00345 }
00346
00354 bool Time::operator < ( Time t )
00355 {
00356 return getTimeDifference( t ) < 0;
00357 }
00358
00365 bool Time::operator < ( const int &i )
00366 {
00367 return Time( i, 0 ) >= *this ;
00368 }
00369
00376 bool Time::operator <= ( Time t )
00377 {
00378 return ( *this < t ) || (*this == t );
00379 }
00380
00388 bool Time::operator <= ( const int &i )
00389 {
00390 return ( *this < i ) || (*this == i );
00391 }
00392
00397 bool Time::operator > ( Time t )
00398 {
00399 return !( *this <= t );
00400 }
00401
00410 bool Time::operator > ( const int &i )
00411 {
00412 return !( *this <= i );
00413 }
00414
00419 bool Time::operator >= ( Time t )
00420 {
00421 return !( *this < t );
00422
00423 }
00424
00431 bool Time::operator >= ( const int &i )
00432 {
00433 return !( *this < i );
00434 }
00435
00443 ostream& operator <<( ostream &os, Time t )
00444 {
00445 return os << "(" << t.getTime() << "," << t.getTimeStopped() << ")";
00446 }
00447
00448
00449
00450
00451
00452
00462 SoccerCommand::SoccerCommand( CommandT com, double d1, double d2, double d3 )
00463 {
00464
00465 commandType = com;
00466 dPower = UnknownDoubleValue;
00467 dAngle = UnknownDoubleValue;
00468 va = VA_ILLEGAL;
00469 vq = VQ_ILLEGAL;
00470 iTimes = 1;
00471 strcpy( str, "\0" );
00472 if( com == CMD_CHANGEVIEW )
00473 makeCommand( commandType, (ViewAngleT)d1, (ViewQualityT)d2 );
00474 else if( com != CMD_SAY )
00475 makeCommand( commandType, d1, d2, d3 );
00476 }
00477
00482 SoccerCommand::SoccerCommand( CommandT com, char *msg )
00483 {
00484 makeCommand( com, msg ) ;
00485 }
00486
00505 void SoccerCommand::makeCommand( CommandT com, double d1,
00506 double d2, double d3 )
00507 {
00508
00509 commandType = com;
00510 switch ( com )
00511 {
00512 case CMD_TURN:
00513 case CMD_TURNNECK:
00514 case CMD_CATCH:
00515 dAngle = d1;
00516 break;
00517 case CMD_DASH:
00518 case CMD_TACKLE:
00519 dPower = d1;
00520 break;
00521 case CMD_KICK:
00522 dPower = d1;
00523 dAngle = d2;
00524 break;
00525 case CMD_MOVE:
00526 dX = d1;
00527 dY = d2;
00528 if( d3 != UnknownDoubleValue )
00529 dAngle = d3;
00530 else
00531 dAngle = 0;
00532 break;
00533 case CMD_CHANGEPLAYER:
00534 case CMD_ATTENTIONTO:
00535 case CMD_POINTTO:
00536 dX = d1;
00537 dY = d2;
00538 break;
00539 default:
00540 break;
00541 }
00542 }
00543
00548 void SoccerCommand::makeCommand( CommandT com, ViewAngleT v, ViewQualityT q )
00549 {
00550 commandType = com;
00551 if( com == CMD_CHANGEVIEW )
00552 {
00553 va = (ViewAngleT) v;
00554 vq = (ViewQualityT)q;
00555 }
00556 }
00557
00562 void SoccerCommand::makeCommand( CommandT com, char* msg )
00563 {
00564 commandType = com;
00565 if( com == CMD_SAY )
00566 strcpy( str, msg );
00567 }
00568
00571 void SoccerCommand::show( ostream& os )
00572 {
00573
00574
00575 switch( commandType )
00576 {
00577 case CMD_ILLEGAL:
00578 os << "illegal\n" ;
00579 break;
00580 case CMD_DASH:
00581 os << commandType << " " << dPower << "\n";
00582 break;
00583 case CMD_TURN:
00584 case CMD_TURNNECK:
00585 os << commandType << " " << dAngle << "\n";
00586 break;
00587 case CMD_CATCH:
00588 os << "catch " << dAngle << "\n";
00589 break;
00590 case CMD_KICK:
00591 os << commandType << " " << dPower << " " << dAngle << "\n";
00592 break;
00593 case CMD_MOVE:
00594 os << commandType << " " << dX << " " << dY << " " << dAngle << "\n";
00595 break;
00596 case CMD_SENSEBODY:
00597 os << "sense_body" << "\n";
00598 break;
00599 case CMD_SAY:
00600 os << "say " << str << "\n";
00601 break;
00602 case CMD_CHANGEPLAYER:
00603 os << "change_player " << (int)dX << " " << (int)dY << "\n";
00604 break;
00605 case CMD_ATTENTIONTO:
00606 os << "attentionto " << (int)dX << " " << (int)dY << "\n";
00607 break;
00608 case CMD_TACKLE:
00609 os << "tackle " << (int)dPower << "\n";
00610 break;
00611 case CMD_POINTTO:
00612 os << "pointto " << dX << " " << dY << "\n";
00613 break;
00614 default:
00615 os << "unknown" << "\n";
00616 break;
00617 }
00618 return;
00619
00620 }
00621
00626 bool SoccerCommand::isIllegal( )
00627 {
00628 return commandType == CMD_ILLEGAL;
00629 }
00630
00640 bool SoccerCommand::getCommandString( char *str, ServerSettings *ss )
00641 {
00642 SS = ss;
00643 bool b = true;
00644 switch( commandType )
00645 {
00646 case CMD_DASH: b = makeDashCommand( str ); break;
00647 case CMD_TURN: b = makeTurnCommand( str ); break;
00648 case CMD_TURNNECK: b = makeTurnNeckCommand( str ); break;
00649 case CMD_CHANGEVIEW: b = makeChangeViewCommand( str ); break;
00650 case CMD_CATCH: b = makeCatchCommand( str ); break;
00651 case CMD_KICK: b = makeKickCommand( str ); break;
00652 case CMD_MOVE: b = makeMoveCommand( str ); break;
00653 case CMD_SENSEBODY: b = makeSenseBodyCommand( str ); break;
00654 case CMD_SAY: b = makeSayCommand( str ); break;
00655 case CMD_CHANGEPLAYER:b = makeChangePlayerCommand( str ); break;
00656 case CMD_ATTENTIONTO: b = makeAttentionToCommand( str ); break;
00657 case CMD_TACKLE: b = makeTackleCommand( str ); break;
00658 case CMD_POINTTO: b = makePointToCommand( str ); break;
00659 case CMD_ILLEGAL: b = true; str[0] = '\0'; break;
00660 default:
00661 b = false;
00662 cerr << "(ActHandler::makeCommandString) Unkown command!"<<"\n";
00663 }
00664 if( b == false )
00665 str[0] = '\0';
00666
00667 return b;
00668 }
00669
00676 bool SoccerCommand::makeCatchCommand( char *str )
00677 {
00678 if( SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )
00679 sprintf( str, "(catch %d)", (int)dAngle );
00680 else
00681 {
00682 fprintf(stderr,
00683 "(SoccerCommand::makeCatchCommand) angle %f out of bounds\n",dAngle);
00684 return false;
00685 }
00686 return true;
00687 }
00688
00695 bool SoccerCommand::makeChangeViewCommand( char *str )
00696 {
00697 if( va != VA_ILLEGAL && vq != VQ_ILLEGAL )
00698 sprintf( str,"(change_view %s %s)", SoccerTypes::getViewAngleStr ( va ),
00699 SoccerTypes::getViewQualityStr( vq ) );
00700 else
00701 {
00702 fprintf( stderr,
00703 "(SoccerCommand::makeChangeViewCommand) wrong arguments %s %s\n",
00704 SoccerTypes::getViewAngleStr ( va ),
00705 SoccerTypes::getViewQualityStr( vq ) );
00706 return false;
00707 }
00708 return true;
00709 }
00710
00717 bool SoccerCommand::makeDashCommand( char *str )
00718 {
00719 if( SS->getMinPower() <= dPower && dPower <= SS->getMaxPower() )
00720 sprintf( str,"(dash %d)", (int)dPower );
00721 else
00722 {
00723 fprintf( stderr,
00724 "(SoccerCommand::makeDashCommand) power %d out of bounds (%d,%d)\n",
00725 (int)dPower, SS->getMinPower(), SS->getMaxPower() );
00726 dPower = 0.0;
00727 sprintf( str, "(dash 0)" );
00728 return false;
00729 }
00730 return true;
00731 }
00732
00739 bool SoccerCommand::makeKickCommand( char *str )
00740 {
00741 if( SS->getMinPower( ) <= dPower && dPower <= SS->getMaxPower( ) &&
00742 SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )
00743 sprintf( str,"(kick %d %d)", (int)dPower, (int)dAngle );
00744 else
00745 {
00746 fprintf(stderr,
00747 "(SoccerCommand::makeKickCommand) one argument %d or %d is wrong\n",
00748 (int)dPower, (int)dAngle );
00749 return false;
00750 }
00751 return true;
00752 }
00753
00760 bool SoccerCommand::makeMoveCommand( char *str )
00761 {
00762 if( -PITCH_LENGTH/2 - PITCH_MARGIN <= dX &&
00763 PITCH_LENGTH/2 + PITCH_MARGIN >= dX &&
00764 -PITCH_WIDTH/2 - PITCH_MARGIN <= dY &&
00765 PITCH_WIDTH/2 + PITCH_MARGIN >= dY )
00766 sprintf( str,"(move %d %d)", (int)dX, (int)dY);
00767 else
00768 {
00769 fprintf( stderr,
00770 "(SoccerCommand::makeMoveCommand) one argument %d or %d is wrong\n",
00771 (int)dX, (int)dY) ;
00772 return false;
00773 }
00774 return true;
00775 }
00776
00783 bool SoccerCommand::makeSayCommand( char *str_com )
00784 {
00785 if( str != NULL && str[0] != '\0' )
00786 sprintf( str_com, "(say \"%s\")", str );
00787 else
00788 {
00789 fprintf( stderr, "(SoccerCommand::makeSayCommand) no string filled in\n" );
00790 return false;
00791 }
00792 return true;
00793 }
00794
00800 bool SoccerCommand::makeSenseBodyCommand( char *str )
00801 {
00802 sprintf( str,"(sense_body)" );
00803 return true;
00804 }
00805
00812 bool SoccerCommand::makeTurnCommand( char *str )
00813 {
00814 if( SS->getMinMoment( ) <= dAngle && dAngle <= SS->getMaxMoment( ) )
00815 sprintf( str,"(turn %d)", (int)dAngle );
00816 else
00817 {
00818 fprintf( stderr,
00819 "(SoccerCommand::makeTurnCommand) argument %d incorrect (%d, %d)\n",
00820 (int)dAngle, SS->getMinMoment( ), SS->getMaxMoment( ) );
00821 dAngle = 0.0;
00822 sprintf( str, "(turn 0)" );
00823 return false;
00824 }
00825 return true;
00826 }
00827
00834 bool SoccerCommand::makeTurnNeckCommand( char *str )
00835 {
00836 if( SS->getMinNeckMoment( ) <= (int)dAngle &&
00837 (int)dAngle <= SS->getMaxNeckMoment( ) )
00838 sprintf( str,"(turn_neck %d)", (int)dAngle );
00839 else
00840 {
00841 fprintf( stderr,
00842 "(SoccerCommand::makeTurnNeckCommand) argument %d is wrong\n",
00843 (int)dAngle );
00844 dAngle = 0.0;
00845 sprintf( str, "(turn_neck 0)" );
00846 return false;
00847 }
00848 return true;
00849 }
00850
00860 bool SoccerCommand::makeChangePlayerCommand( char *str )
00861 {
00862 if( (int)dX > 0 && (int)dX <= MAX_TEAMMATES &&
00863 (int)dY >= 0 && (int)dY < MAX_HETERO_PLAYERS )
00864 sprintf( str,"(change_player_type %d %d)", (int)dX, (int)dY );
00865 else
00866 {
00867 fprintf( stderr,
00868 "(SoccerCommand::makeChangePlayerCommand) argument %d or %d is wrong\n",
00869 (int)dX, (int)dY );
00870 return false;
00871 }
00872 return true;
00873 }
00874
00885 bool SoccerCommand::makeAttentionToCommand( char *str )
00886 {
00887 char strTeam[10];
00888 if( dY < 0 )
00889 {
00890 sprintf( str, "(attentionto off)" );
00891 return true;
00892 }
00893
00894 if( dX < 0 )
00895 strcpy( strTeam, "opp" );
00896 else
00897 strcpy( strTeam, "our" );
00898
00899 if( (int)dY > 0 && (int)dY <= MAX_TEAMMATES )
00900 sprintf( str,"(attentionto %s %d)", strTeam, (int)dY );
00901 else
00902 {
00903 fprintf( stderr,
00904 "(SoccerCommand::makeAttentionToCommand) argument %s or %d is wrong\n",
00905 strTeam, (int)dY );
00906 return false;
00907 }
00908 return true;
00909 }
00910
00917 bool SoccerCommand::makeTackleCommand( char *str )
00918 {
00919 if( SS->getMinPower() <= dPower && dPower <= SS->getMaxPower() )
00920 sprintf( str,"(tackle %d)", (int)dPower );
00921 else
00922 {
00923 fprintf( stderr,
00924 "(SoccerCommand::makeTackleCommand) power %d out of bounds (%d,%d)\n",
00925 (int)dPower, SS->getMinPower(), SS->getMaxPower() );
00926 return false;
00927 }
00928 return true;
00929 }
00930
00939 bool SoccerCommand::makePointToCommand( char *str )
00940 {
00941 if( dX < 0 )
00942 {
00943 sprintf( str, "(pointto off)" );
00944 return true;
00945 }
00946
00947 if( dY >= SS->getMinMoment() && dY <= SS->getMaxMoment() )
00948 sprintf( str,"(pointto %1.2f %1.2f)", dX, dY );
00949 else
00950 {
00951 fprintf( stderr,
00952 "(SoccerCommand::makePointToCommand) arg %f or %f is wrong\n", dX, dY );
00953 return false;
00954 }
00955 return true;
00956 }
00957
00958
00959
00960
00961
00964 Feature::Feature( )
00965 {
00966 setFeature( Time(UnknownTime, 0), Time(UnknownTime, 0),Time(UnknownTime, 0),
00967 OBJECT_ILLEGAL, UnknownDoubleValue );
00968 }
00969
00981 Feature::Feature( Time timeSee, Time timeSense, Time timeHear, ObjectT object,
00982 double dInfo, SoccerCommand soc, VecPosition pos )
00983 {
00984 setFeature( timeSee, timeSense, timeHear, object, dInfo, soc, pos );
00985 }
00986
01000 bool Feature::setFeature( Time timeSee, Time timeSense, Time timeHear,
01001 ObjectT object, double dInfo, SoccerCommand soc,
01002 VecPosition pos )
01003 {
01004 bool b;
01005 b = setTimeSee( timeSee );
01006 b &= setTimeSense( timeSense );
01007 b &= setTimeHear( timeHear );
01008 b &= setObject( object );
01009 b &= setInfo( dInfo );
01010 b &= setCommand( soc );
01011 b &= setVec( pos );
01012 return b;
01013 }
01014
01017 bool Feature::setTimeSee( Time time )
01018 {
01019 m_timeSee = time;
01020 return true;
01021 }
01022
01025 Time Feature::getTimeSee( )
01026 {
01027 return m_timeSee;
01028 }
01029
01032 bool Feature::setTimeSense( Time time )
01033 {
01034 m_timeSense = time;
01035 return true;
01036 }
01037
01040 Time Feature::getTimeSense( )
01041 {
01042 return m_timeSense;
01043 }
01044
01047 bool Feature::setTimeHear( Time time )
01048 {
01049 m_timeHear = time;
01050 return true;
01051 }
01052
01055 Time Feature::getTimeHear( )
01056 {
01057 return m_timeHear;
01058 }
01059
01062 bool Feature::setObject ( ObjectT object )
01063 {
01064 m_object = object;
01065 return true;
01066 }
01067
01070 ObjectT Feature::getObject( )
01071 {
01072 return m_object;
01073 }
01074
01077 bool Feature::setInfo( double d )
01078 {
01079 m_dInfo = d;
01080 return true;
01081 }
01082
01085 double Feature::getInfo( )
01086 {
01087 return m_dInfo;
01088 }
01089
01092 bool Feature::setVec( VecPosition pos )
01093 {
01094 m_vec = pos;
01095 return true;
01096 }
01097
01100 VecPosition Feature::getVec( )
01101 {
01102 return m_vec;
01103 }
01104
01107 bool Feature::setCommand( SoccerCommand soc )
01108 {
01109 m_soc = soc;
01110 return true;
01111 }
01112
01115 SoccerCommand Feature::getCommand( )
01116 {
01117 return m_soc;
01118 }
01119
01120
01121
01122
01123
01129 const char * ObjectNames[] =
01130 {
01131 "(b)", "(g l)", "(g r)", "(g ?)", "(l l)", "(l r)", "(l b)", "(l t)",
01132 "(f l t)","(f t l 50)", "(f t l 40)", "(f t l 30)", "(f t l 20)",
01133 "(f t l 10)", "(f t 0)","(f c t)","(f t r 10)", "(f t r 20)", "(f t r 30)",
01134 "(f t r 40)","(f t r 50)", "(f r t)", "(f r t 30)", "(f r t 20)","(f r t 10)",
01135 "(f g r t)" , "(f r 0)", "(f g r b)" , "(f r b 10)", "(f r b 20)",
01136 "(f r b 30)", "(f r b)" , "(f b r 50)", "(f b r 40)", "(f b r 30)",
01137 "(f b r 20)", "(f b r 10)", "(f c b)" , "(f b 0)" , "(f b l 10)",
01138 "(f b l 20)", "(f b l 30)", "(f b l 40)", "(f b l 50)", "(f l b)",
01139 "(f l b 30)", "(f l b 20)", "(f l b 10)", "(f g l b)" , "(f l 0)",
01140 "(f g l t)" , "(f l t 10)", "(f l t 20)", "(f l t 30)", "(f p l t)",
01141 "(f p l c)", "(f p l b)", "(f p r t)", "(f p r c)", "(f p r b)", "(f c)" };
01142
01150 char* SoccerTypes::getObjectStr( char* strBuf, ObjectT o,
01151 const char *strTeamName )
01152 {
01153 if( o >= OBJECT_BALL && o <= OBJECT_FLAG_C )
01154 sprintf( strBuf, ObjectNames[(int)o] );
01155 else if( isKnownPlayer( o ) && strTeamName != NULL )
01156 sprintf( strBuf, "(p %s %d)", strTeamName, getIndex( o ) + 1);
01157 else if( isKnownPlayer( o ) && isTeammate( o ) )
01158 sprintf( strBuf, "(p l %d)", getIndex( o ) + 1);
01159 else if( isKnownPlayer( o ) && isOpponent( o ) )
01160 sprintf( strBuf, "(p r %d)", getIndex( o ) + 1);
01161 else if( o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_TEAMMATE_UNKNOWN )
01162 sprintf( strBuf, "(p %s)", strTeamName );
01163 else if( o == OBJECT_PLAYER_UNKNOWN )
01164 sprintf( strBuf, "(p)" );
01165 else if( o == OBJECT_UNKNOWN )
01166 sprintf( strBuf, "(unknown)" );
01167 else
01168 sprintf( strBuf, "illegal: %d", (int)o );
01169 return strBuf;
01170 }
01171
01185 ObjectT SoccerTypes::getObjectFromStr( char** str, bool *isGoalie,
01186 const char* strMyTeamName )
01187 {
01188 ObjectT o = OBJECT_ILLEGAL;
01189 char* ptrStr = *str;
01190 *isGoalie = false;
01191
01192 switch( ptrStr[1] )
01193 {
01194 case 'b':
01195 case 'B':
01196 o = OBJECT_BALL; break;
01197 case 'G':
01198 o = OBJECT_GOAL_UNKNOWN;
01199 break;
01200 case 'g': o = (ptrStr[3] == 'l') ? OBJECT_GOAL_L : OBJECT_GOAL_R; break;
01201 case 'l':
01202 switch( ptrStr[3] )
01203 {
01204 case 'l': o = OBJECT_LINE_L; break;
01205 case 'r': o = OBJECT_LINE_R; break;
01206 case 'b': o = OBJECT_LINE_B; break;
01207 case 't': o = OBJECT_LINE_T; break;
01208 default: o = OBJECT_ILLEGAL; break;
01209 }
01210 break;
01211 case 'F':
01212 o = OBJECT_UNKNOWN; break;
01213 case 'f':
01214 switch( ptrStr[3] )
01215 {
01216 case 'l':
01217 if( ptrStr[6] == ')' )
01218 {
01219 switch( ptrStr[5] )
01220 {
01221 case '0': o = OBJECT_FLAG_L_0; break;
01222 case 't': o = OBJECT_FLAG_L_T; break;
01223 case 'b': o = OBJECT_FLAG_L_B; break;
01224 default: o = OBJECT_ILLEGAL; break;
01225 }
01226 }
01227 else
01228 {
01229 switch( ptrStr[7] )
01230 {
01231 case '1':
01232 o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_10 :OBJECT_FLAG_L_B_10;
01233 break;
01234 case '2':
01235 o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_20 :OBJECT_FLAG_L_B_20;
01236 break;
01237 case '3':
01238 o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_30 :OBJECT_FLAG_L_B_30;
01239 break;
01240 default:
01241 o = OBJECT_ILLEGAL;
01242 break;
01243 }
01244 }
01245 break;
01246 case 'r':
01247 if( ptrStr[6] == ')' )
01248 {
01249 switch( ptrStr[5] )
01250 {
01251 case '0': o = OBJECT_FLAG_R_0; break;
01252 case 't': o = OBJECT_FLAG_R_T; break;
01253 case 'b': o = OBJECT_FLAG_R_B; break;
01254 }
01255 }
01256 else
01257 {
01258 switch( ptrStr[7] )
01259 {
01260 case '1':
01261 o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_10 :OBJECT_FLAG_R_B_10;
01262 break;
01263 case '2':
01264 o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_20 :OBJECT_FLAG_R_B_20;
01265 break;
01266 case '3':
01267 o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_30 :OBJECT_FLAG_R_B_30;
01268 break;
01269 default:
01270 o = OBJECT_ILLEGAL;
01271 break;
01272 }
01273 }
01274 break;
01275 case 't':
01276 if( ptrStr[5] == '0' )
01277 o = OBJECT_FLAG_T_0;
01278 else
01279 {
01280 switch( ptrStr[7] )
01281 {
01282 case '1':
01283 o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_10 : OBJECT_FLAG_T_R_10;
01284 break;
01285 case '2':
01286 o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_20 : OBJECT_FLAG_T_R_20;
01287 break;
01288 case '3':
01289 o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_30 : OBJECT_FLAG_T_R_30;
01290 break;
01291 case '4':
01292 o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_40 : OBJECT_FLAG_T_R_40;
01293 break;
01294 case '5':
01295 o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_50 : OBJECT_FLAG_T_R_50;
01296 break;
01297 }
01298 }
01299 break;
01300 case 'b':
01301 if( ptrStr[5] == '0')
01302 o = OBJECT_FLAG_B_0;
01303 else
01304 {
01305 switch( ptrStr[7] )
01306 {
01307 case '1':
01308 o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_10 : OBJECT_FLAG_B_R_10;
01309 break;
01310 case '2':
01311 o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_20 : OBJECT_FLAG_B_R_20;
01312 break;
01313 case '3':
01314 o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_30 : OBJECT_FLAG_B_R_30;
01315 break;
01316 case '4':
01317 o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_40 : OBJECT_FLAG_B_R_40;
01318 break;
01319 case '5':
01320 o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_50 : OBJECT_FLAG_B_R_50;
01321 break;
01322 }
01323 }
01324 break;
01325 case 'c':
01326 if( ptrStr[4] == ')' )
01327 o = OBJECT_FLAG_C;
01328 else
01329 o = (ptrStr[5] == 't') ? OBJECT_FLAG_C_T : OBJECT_FLAG_C_B;
01330 break;
01331 case 'g':
01332 if( ptrStr[5] == 'l' )
01333 o = (ptrStr[7] == 't') ? OBJECT_FLAG_G_L_T : OBJECT_FLAG_G_L_B;
01334 else
01335 o = (ptrStr[7] == 't') ? OBJECT_FLAG_G_R_T : OBJECT_FLAG_G_R_B;
01336 break;
01337 case 'p':
01338 switch( ptrStr[7] )
01339 {
01340 case 't':
01341 o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_T : OBJECT_FLAG_P_R_T;
01342 break;
01343 case 'c':
01344 o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_C : OBJECT_FLAG_P_R_C;
01345 break;
01346 case 'b':
01347 o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_B : OBJECT_FLAG_P_R_B;
01348 break;
01349 default:
01350 o = OBJECT_ILLEGAL;
01351 break;
01352 }
01353 break;
01354 default:
01355 o = OBJECT_ILLEGAL;
01356 }
01357 break;
01358 case 'p':
01359 case 'P':
01360 ptrStr += 2;
01361
01362 if( Parse::gotoFirstSpaceOrClosingBracket(&ptrStr) == ')' )
01363 o = OBJECT_PLAYER_UNKNOWN;
01364
01365 else if( strncmp( ptrStr+1, strMyTeamName, strlen( strMyTeamName )) == 0 ||
01366 strncmp( ptrStr+2, strMyTeamName, strlen( strMyTeamName )) == 0 )
01367 {
01368 ptrStr++;
01369 if( Parse::gotoFirstSpaceOrClosingBracket(&ptrStr) == ' ' )
01370 {
01371 switch( Parse::parseFirstInt( &ptrStr ) )
01372 {
01373 case 1: o = OBJECT_TEAMMATE_1; break;
01374 case 2: o = OBJECT_TEAMMATE_2; break;
01375 case 3: o = OBJECT_TEAMMATE_3; break;
01376 case 4: o = OBJECT_TEAMMATE_4; break;
01377 case 5: o = OBJECT_TEAMMATE_5; break;
01378 case 6: o = OBJECT_TEAMMATE_6; break;
01379 case 7: o = OBJECT_TEAMMATE_7; break;
01380 case 8: o = OBJECT_TEAMMATE_8; break;
01381 case 9: o = OBJECT_TEAMMATE_9; break;
01382 case 10: o = OBJECT_TEAMMATE_10; break;
01383 case 11: o = OBJECT_TEAMMATE_11; break;
01384 default: o = OBJECT_ILLEGAL;
01385 }
01386 if( ptrStr[0] != ')' && ptrStr[1] == 'g' )
01387 *isGoalie = true;
01388 }
01389 else
01390 o = OBJECT_TEAMMATE_UNKNOWN;
01391 }
01392 else
01393 {
01394 ptrStr++;
01395 if( Parse::gotoFirstSpaceOrClosingBracket( &ptrStr ) == ' ' )
01396 {
01397 switch( Parse::parseFirstInt( &ptrStr ) )
01398 {
01399 case 1: o = OBJECT_OPPONENT_1; break;
01400 case 2: o = OBJECT_OPPONENT_2; break;
01401 case 3: o = OBJECT_OPPONENT_3; break;
01402 case 4: o = OBJECT_OPPONENT_4; break;
01403 case 5: o = OBJECT_OPPONENT_5; break;
01404 case 6: o = OBJECT_OPPONENT_6; break;
01405 case 7: o = OBJECT_OPPONENT_7; break;
01406 case 8: o = OBJECT_OPPONENT_8; break;
01407 case 9: o = OBJECT_OPPONENT_9; break;
01408 case 10: o = OBJECT_OPPONENT_10; break;
01409 case 11: o = OBJECT_OPPONENT_11; break;
01410 default: o = OBJECT_ILLEGAL;
01411 }
01412 if( ptrStr[0] != ')' && ptrStr[1] == 'g' )
01413 *isGoalie = true;
01414 }
01415 else
01416 o = OBJECT_OPPONENT_UNKNOWN;
01417
01418 }
01419 break;
01420 default:
01421 cerr << "(SoccerTypes::getObjectFromStr) Unknown msg: " << ptrStr << "\n";
01422 o = OBJECT_ILLEGAL;
01423 break;
01424 }
01425
01426 Parse::gotoFirstOccurenceOf( ')', &ptrStr );
01427 *str=ptrStr;
01428 return o;
01429 }
01430
01437 int SoccerTypes::getIndex( ObjectT o )
01438 {
01439 if( o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_11 )
01440 return o - OBJECT_OPPONENT_1;
01441 else if( o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_11 )
01442 return o - OBJECT_TEAMMATE_1;
01443 else if( o >= OBJECT_GOAL_L && o <= OBJECT_GOAL_R )
01444 return o - OBJECT_GOAL_L;
01445 else if( o >= OBJECT_FLAG_L_T && o <= OBJECT_FLAG_C )
01446 return o - OBJECT_FLAG_L_T + 2;
01447 else if( o >= OBJECT_LINE_L && o <= OBJECT_LINE_T )
01448 return o - OBJECT_LINE_L;
01449 else
01450 return -1;
01451 }
01452
01457 ObjectT SoccerTypes::getTeammateObjectFromIndex( int iIndex )
01458 {
01459 return (ObjectT) ( OBJECT_TEAMMATE_1 + iIndex );
01460 }
01461
01466 ObjectT SoccerTypes::getOpponentObjectFromIndex( int iIndex )
01467 {
01468 return (ObjectT) ( OBJECT_OPPONENT_1 + iIndex );
01469 }
01470
01478 bool SoccerTypes::isInSet( ObjectT o, ObjectSetT o_g, ObjectT objGoalie )
01479 {
01480 switch( o_g )
01481 {
01482 case OBJECT_SET_TEAMMATES: return isTeammate( o ) && isKnownPlayer( o );
01483 case OBJECT_SET_OPPONENTS: return isOpponent( o ) && isKnownPlayer( o );
01484 case OBJECT_SET_PLAYERS: return isPlayer ( o ) && isKnownPlayer( o );
01485 case OBJECT_SET_FLAGS: return isFlag ( o );
01486 case OBJECT_SET_LINES: return isLine ( o );
01487 case OBJECT_SET_TEAMMATES_NO_GOALIE:
01488 return isTeammate( o ) && isKnownPlayer( o ) &&
01489 o != objGoalie;
01490 case OBJECT_SET_ILLEGAL:
01491 default: break;
01492 }
01493 return false;
01494 }
01495
01496
01500 bool SoccerTypes::isPlayerTypeInSet( PlayerT p, PlayerSetT p_s )
01501 {
01502 switch( p_s )
01503 {
01504 case PS_DEFENDERS:
01505 return p == PT_DEFENDER_CENTRAL || p == PT_DEFENDER_WING;
01506 case PS_MIDFIELDERS:
01507 return p == PT_MIDFIELDER_CENTER || p == PT_MIDFIELDER_WING;
01508 case PS_ATTACKERS:
01509 return p == PT_ATTACKER_WING || p == PT_ATTACKER;
01510 case PS_ALL:
01511 return true;
01512 default:
01513 break;
01514 }
01515 return false;
01516
01517 }
01518
01519
01523 bool SoccerTypes::isFlag( ObjectT o )
01524 {
01525 return ( o >= OBJECT_FLAG_L_T && o <= OBJECT_FLAG_C ) ||
01526 ( o >= OBJECT_GOAL_L && o <= OBJECT_GOAL_R );
01527 }
01528
01532 bool SoccerTypes::isLine( ObjectT o )
01533 {
01534 return o >= OBJECT_LINE_L && o <= OBJECT_LINE_T;
01535 }
01536
01540 bool SoccerTypes::isGoal( ObjectT o )
01541 {
01542 return o == OBJECT_GOAL_L || o == OBJECT_GOAL_R;
01543 }
01544
01548 bool SoccerTypes::isTeammate( ObjectT o )
01549 {
01550 return o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_UNKNOWN;
01551 }
01552
01556 bool SoccerTypes::isOpponent( ObjectT o )
01557 {
01558 return o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_UNKNOWN;
01559 }
01560
01567 bool SoccerTypes::isPlayer( ObjectT o )
01568 {
01569 return isKnownPlayer( o ) || o == OBJECT_TEAMMATE_UNKNOWN ||
01570 o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_PLAYER_UNKNOWN;
01571 }
01572
01579 bool SoccerTypes::isKnownPlayer( ObjectT o )
01580 {
01581 return (o >= OBJECT_OPPONENT_1 && o <= OBJECT_OPPONENT_11) ||
01582 (o >= OBJECT_TEAMMATE_1 && o <= OBJECT_TEAMMATE_11);
01583 }
01584
01589 bool SoccerTypes::isGoalie( ObjectT o )
01590 {
01591 return o == OBJECT_TEAMMATE_1 || o == OBJECT_OPPONENT_1;
01592 }
01593
01597 bool SoccerTypes::isBall( ObjectT o )
01598 {
01599 return o == OBJECT_BALL;
01600 }
01601
01605 ObjectT SoccerTypes::getOwnGoal( SideT s )
01606 {
01607 if( SIDE_LEFT == s )
01608 return OBJECT_GOAL_L;
01609 else if( SIDE_RIGHT == s )
01610 return OBJECT_GOAL_R;
01611
01612 cerr << "(SoccerTypes::isOwnGoal) Wrong side argument" << "\n";
01613 return OBJECT_ILLEGAL;
01614 }
01615
01621 ObjectT SoccerTypes::getGoalOpponent( SideT s )
01622 {
01623 if( SIDE_LEFT == s )
01624 return OBJECT_GOAL_R;
01625 else if( SIDE_RIGHT == s )
01626 return OBJECT_GOAL_L;
01627
01628 cerr << "(SoccerTypes::isGoalOpponent) Wrong side argument" << "\n";
01629 return OBJECT_ILLEGAL;
01630 }
01631
01641 VecPosition SoccerTypes::getGlobalPositionFlag( ObjectT o, SideT s,
01642 double dGoalWidth )
01643 {
01644 VecPosition pos;
01645 if( !(isFlag(o) || isGoal(o)) )
01646 return VecPosition(UnknownDoubleValue, UnknownDoubleValue);
01647 switch( o )
01648 {
01649 case OBJECT_GOAL_L:
01650 pos.setVecPosition( -PITCH_LENGTH/2.0, 0.0 ); break;
01651 case OBJECT_GOAL_R:
01652 pos.setVecPosition( PITCH_LENGTH/2.0, 0.0 ); break;
01653 case OBJECT_FLAG_L_T:
01654 pos.setVecPosition( -PITCH_LENGTH/2.0, -PITCH_WIDTH/2.0 ); break;
01655 case OBJECT_FLAG_T_L_50:
01656 pos.setVecPosition( -50.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01657 case OBJECT_FLAG_T_L_40:
01658 pos.setVecPosition( -40.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01659 case OBJECT_FLAG_T_L_30:
01660 pos.setVecPosition( -30.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01661 case OBJECT_FLAG_T_L_20:
01662 pos.setVecPosition( -20.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01663 case OBJECT_FLAG_T_L_10:
01664 pos.setVecPosition( -10.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01665 case OBJECT_FLAG_T_0:
01666 pos.setVecPosition( 0.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN ); break;
01667 case OBJECT_FLAG_C_T:
01668 pos.setVecPosition( 0.0, -PITCH_WIDTH/2.0); break;
01669 case OBJECT_FLAG_T_R_10:
01670 pos.setVecPosition( 10.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break;
01671 case OBJECT_FLAG_T_R_20:
01672 pos.setVecPosition( 20.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break;
01673 case OBJECT_FLAG_T_R_30:
01674 pos.setVecPosition( 30.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break;
01675 case OBJECT_FLAG_T_R_40:
01676 pos.setVecPosition( 40.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break;
01677 case OBJECT_FLAG_T_R_50:
01678 pos.setVecPosition( 50.0, -PITCH_WIDTH/2.0 - PITCH_MARGIN); break;
01679 case OBJECT_FLAG_R_T:
01680 pos.setVecPosition( PITCH_LENGTH/2.0, -PITCH_WIDTH/2.0 ); break;
01681 case OBJECT_FLAG_R_T_30:
01682 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -30.0 ); break;
01683 case OBJECT_FLAG_R_T_20:
01684 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -20.0 ); break;
01685 case OBJECT_FLAG_R_T_10:
01686 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, -10.0 ); break;
01687 case OBJECT_FLAG_G_R_T:
01688 pos.setVecPosition( PITCH_LENGTH/2.0, -dGoalWidth/2.0 ); break;
01689 case OBJECT_FLAG_R_0:
01690 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 0.0 ); break;
01691 case OBJECT_FLAG_G_R_B:
01692 pos.setVecPosition( PITCH_LENGTH/2.0, dGoalWidth/2.0 ); break;
01693 case OBJECT_FLAG_R_B_10:
01694 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 10.0 ); break;
01695 case OBJECT_FLAG_R_B_20:
01696 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 20.0 ); break;
01697 case OBJECT_FLAG_R_B_30:
01698 pos.setVecPosition( PITCH_LENGTH/2.0 + PITCH_MARGIN, 30.0 ); break;
01699 case OBJECT_FLAG_R_B:
01700 pos.setVecPosition( PITCH_LENGTH/2.0, PITCH_WIDTH/2.0 ); break;
01701 case OBJECT_FLAG_B_R_50:
01702 pos.setVecPosition( 50.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01703 case OBJECT_FLAG_B_R_40:
01704 pos.setVecPosition( 40.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01705 case OBJECT_FLAG_B_R_30:
01706 pos.setVecPosition( 30.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01707 case OBJECT_FLAG_B_R_20:
01708 pos.setVecPosition( 20.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01709 case OBJECT_FLAG_B_R_10:
01710 pos.setVecPosition( 10.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01711 case OBJECT_FLAG_C_B:
01712 pos.setVecPosition( 0.0, PITCH_WIDTH/2.0 ); break;
01713 case OBJECT_FLAG_B_0:
01714 pos.setVecPosition( 0.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01715 case OBJECT_FLAG_B_L_10:
01716 pos.setVecPosition( -10.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01717 case OBJECT_FLAG_B_L_20:
01718 pos.setVecPosition( -20.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01719 case OBJECT_FLAG_B_L_30:
01720 pos.setVecPosition( -30.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01721 case OBJECT_FLAG_B_L_40:
01722 pos.setVecPosition( -40.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01723 case OBJECT_FLAG_B_L_50:
01724 pos.setVecPosition( -50.0, PITCH_WIDTH/2.0 + PITCH_MARGIN ); break;
01725 case OBJECT_FLAG_L_B:
01726 pos.setVecPosition( -PITCH_LENGTH/2.0, PITCH_WIDTH/2.0 ); break;
01727 case OBJECT_FLAG_L_B_30:
01728 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 30.0 ); break;
01729 case OBJECT_FLAG_L_B_20:
01730 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 20.0 ); break;
01731 case OBJECT_FLAG_L_B_10:
01732 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 10.0 ); break;
01733 case OBJECT_FLAG_G_L_B:
01734 pos.setVecPosition( -PITCH_LENGTH/2.0, dGoalWidth/2.0 ); break;
01735 case OBJECT_FLAG_L_0:
01736 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, 0.0 ); break;
01737 case OBJECT_FLAG_G_L_T:
01738 pos.setVecPosition( -PITCH_LENGTH/2.0, -dGoalWidth/2.0 ); break;
01739 case OBJECT_FLAG_L_T_10:
01740 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -10.0 ); break;
01741 case OBJECT_FLAG_L_T_20:
01742 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -20.0 ); break;
01743 case OBJECT_FLAG_L_T_30:
01744 pos.setVecPosition( -PITCH_LENGTH/2.0 - PITCH_MARGIN, -30.0 ); break;
01745 case OBJECT_FLAG_P_L_T:
01746 pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH,
01747 - PENALTY_AREA_WIDTH/2.0 ); break;
01748 case OBJECT_FLAG_P_L_C:
01749 pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH, 0.0 );break;
01750 case OBJECT_FLAG_P_L_B:
01751 pos.setVecPosition( -PITCH_LENGTH/2.0 + PENALTY_AREA_LENGTH,
01752 PENALTY_AREA_WIDTH/2.0 ); break;
01753 case OBJECT_FLAG_P_R_T:
01754 pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH,
01755 -PENALTY_AREA_WIDTH/2.0 ); break;
01756 case OBJECT_FLAG_P_R_C:
01757 pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH, 0.0 );break;
01758 case OBJECT_FLAG_P_R_B:
01759 pos.setVecPosition( PITCH_LENGTH/2.0 - PENALTY_AREA_LENGTH,
01760 PENALTY_AREA_WIDTH/2.0 ); break;
01761 case OBJECT_FLAG_C:
01762 pos.setVecPosition( 0.0 , 0.0 ); break;
01763 default:
01764 cerr << "(SoccerTypes::getGlobalPositionObject) wrong objecttype! " <<
01765 (int)o << "\n" ;
01766 }
01767
01768 if( s == SIDE_RIGHT )
01769 pos.setVecPosition( -pos.getX(), -pos.getY() );
01770 return pos;
01771 }
01772
01782 AngDeg SoccerTypes::getGlobalAngleLine( ObjectT o , SideT s )
01783 {
01784 AngDeg angle;
01785 switch( o )
01786 {
01787 case OBJECT_LINE_L: angle = 180.0; break;
01788 case OBJECT_LINE_R: angle = 0.0; break;
01789 case OBJECT_LINE_T: angle = -90.0; break;
01790 case OBJECT_LINE_B: angle = 90.0; break;
01791 default:
01792 cerr << "(SoccerTypes::getGlobalAngleLine) wrong objecttype! " <<
01793 (int)o << "\n";
01794 return UnknownAngleValue;
01795 }
01796
01797 if( s == SIDE_RIGHT )
01798 angle += 180;
01799
01800 return VecPosition::normalizeAngle( angle );
01801 }
01802
01807 char* SoccerTypes::getPlayModeStr( PlayModeT pm )
01808 {
01809 switch( pm )
01810 {
01811 case PM_BEFORE_KICK_OFF: return "before_kick_off";
01812 case PM_KICK_OFF_LEFT: return "kick_off_l";
01813 case PM_KICK_OFF_RIGHT: return "kick_off_r";
01814 case PM_KICK_IN_LEFT: return "kick_in_l";
01815 case PM_KICK_IN_RIGHT: return "kick_in_r";
01816 case PM_CORNER_KICK_LEFT: return "corner_kick_l";
01817 case PM_CORNER_KICK_RIGHT: return "corner_kick_r";
01818 case PM_GOAL_KICK_LEFT: return "goal_kick_l";
01819 case PM_GOAL_KICK_RIGHT: return "goal_kick_r";
01820 case PM_GOAL_LEFT: return "goal_r";
01821 case PM_GOAL_RIGHT: return "goal_l";
01822 case PM_FREE_KICK_FAULT_LEFT: return "free_kick_fault_l";
01823 case PM_FREE_KICK_FAULT_RIGHT: return "free_kick_fault_r";
01824 case PM_FREE_KICK_LEFT: return "free_kick_l";
01825 case PM_FREE_KICK_RIGHT: return "free_kick_r";
01826 case PM_INDIRECT_FREE_KICK_RIGHT: return "indirect_free_kick_r";
01827 case PM_INDIRECT_FREE_KICK_LEFT: return "indirect_free_kick_l";
01828 case PM_BACK_PASS_LEFT: return "back_pass_l";
01829 case PM_BACK_PASS_RIGHT: return "back_pass_r";
01830 case PM_OFFSIDE_LEFT: return "offside_l";
01831 case PM_OFFSIDE_RIGHT: return "offside_l";
01832 case PM_PENALTY_SETUP_LEFT: return "penalty_setup_left";
01833 case PM_PENALTY_SETUP_RIGHT: return "penalty_setup_right";
01834 case PM_PENALTY_READY_LEFT: return "penalty_ready_left";
01835 case PM_PENALTY_READY_RIGHT: return "penalty_ready_right";
01836 case PM_PENALTY_TAKEN_LEFT: return "penalty_taken_left";
01837 case PM_PENALTY_TAKEN_RIGHT: return "penalty_taken_right";
01838 case PM_PLAY_ON: return "play_on";
01839 case PM_FROZEN: return "play_off";
01840 case PM_QUIT: return "quit";
01841 case PM_ILLEGAL:
01842 default: return NULL;
01843 }
01844 }
01845
01849 PlayModeT SoccerTypes::getPlayModeFromStr( char* str )
01850 {
01851
01852
01853 return getPlayModeFromRefereeMessage( getRefereeMessageFromStr( str ) );
01854 }
01855
01859 PlayModeT SoccerTypes::getPlayModeFromRefereeMessage( RefereeMessageT rm )
01860 {
01861 switch( rm )
01862 {
01863 case REFC_BEFORE_KICK_OFF: return PM_BEFORE_KICK_OFF;
01864 case REFC_KICK_OFF_LEFT: return PM_KICK_OFF_LEFT;
01865 case REFC_KICK_OFF_RIGHT: return PM_KICK_OFF_RIGHT;
01866 case REFC_KICK_IN_LEFT: return PM_KICK_IN_LEFT;
01867 case REFC_KICK_IN_RIGHT: return PM_KICK_IN_RIGHT;
01868 case REFC_CORNER_KICK_LEFT: return PM_CORNER_KICK_LEFT;
01869 case REFC_CORNER_KICK_RIGHT: return PM_CORNER_KICK_RIGHT;
01870 case REFC_GOAL_KICK_LEFT: return PM_GOAL_KICK_LEFT;
01871 case REFC_GOAL_KICK_RIGHT: return PM_GOAL_KICK_RIGHT;
01872 case REFC_FREE_KICK_LEFT: return PM_FREE_KICK_LEFT;
01873 case REFC_FREE_KICK_RIGHT: return PM_FREE_KICK_RIGHT;
01874 case REFC_INDIRECT_FREE_KICK_LEFT: return PM_INDIRECT_FREE_KICK_LEFT;
01875 case REFC_INDIRECT_FREE_KICK_RIGHT: return PM_INDIRECT_FREE_KICK_RIGHT;
01876 case REFC_FREE_KICK_FAULT_LEFT: return PM_FREE_KICK_FAULT_LEFT;
01877 case REFC_FREE_KICK_FAULT_RIGHT: return PM_FREE_KICK_FAULT_RIGHT;
01878 case REFC_BACK_PASS_LEFT: return PM_BACK_PASS_LEFT;
01879 case REFC_BACK_PASS_RIGHT: return PM_BACK_PASS_RIGHT;
01880 case REFC_FOUL_LEFT: return PM_FREE_KICK_RIGHT;
01881 case REFC_FOUL_RIGHT: return PM_FREE_KICK_LEFT;
01882 case REFC_OFFSIDE_LEFT: return PM_OFFSIDE_LEFT;
01883 case REFC_OFFSIDE_RIGHT: return PM_OFFSIDE_RIGHT;
01884 case REFC_GOAL_LEFT: return PM_GOAL_LEFT;
01885 case REFC_GOAL_RIGHT: return PM_GOAL_RIGHT;
01886 case REFC_PENALTY_SETUP_LEFT: return PM_PENALTY_SETUP_LEFT;
01887 case REFC_PENALTY_SETUP_RIGHT: return PM_PENALTY_SETUP_RIGHT;
01888 case REFC_PENALTY_READY_LEFT: return PM_PENALTY_READY_LEFT;
01889 case REFC_PENALTY_READY_RIGHT: return PM_PENALTY_READY_RIGHT;
01890 case REFC_PENALTY_TAKEN_LEFT: return PM_PENALTY_TAKEN_LEFT;
01891 case REFC_PENALTY_TAKEN_RIGHT: return PM_PENALTY_TAKEN_RIGHT;
01892 case REFC_PLAY_ON: return PM_PLAY_ON;
01893 case REFC_FROZEN: return PM_FROZEN;
01894 case REFC_TIME_OVER: return PM_TIME_OVER;
01895 case REFC_QUIT: return PM_QUIT;
01896 default: return PM_ILLEGAL;
01897 }
01898 }
01899
01904 char* SoccerTypes::getRefereeMessageStr( RefereeMessageT rm )
01905 {
01906 switch( rm )
01907 {
01908 case REFC_BEFORE_KICK_OFF: return "before_kick_off";
01909 case REFC_KICK_OFF_LEFT: return "kick_off_l";
01910 case REFC_KICK_OFF_RIGHT: return "kick_off_r";
01911 case REFC_KICK_IN_LEFT: return "kick_in_l";
01912 case REFC_KICK_IN_RIGHT: return "kick_in_r";
01913 case REFC_CORNER_KICK_LEFT: return "corner_kick_l";
01914 case REFC_CORNER_KICK_RIGHT: return "corner_kick_r";
01915 case REFC_GOAL_KICK_LEFT: return "goal_kick_l";
01916 case REFC_GOAL_KICK_RIGHT: return "goal_kick_r";
01917 case REFC_FREE_KICK_LEFT: return "free_kick_l";
01918 case REFC_FREE_KICK_RIGHT: return "free_kick_r";
01919 case REFC_INDIRECT_FREE_KICK_LEFT: return "indirect_free_kick_l";
01920 case REFC_INDIRECT_FREE_KICK_RIGHT: return "indirect_free_kick_r";
01921 case REFC_FREE_KICK_FAULT_LEFT: return "free_kick_fault_l";
01922 case REFC_FREE_KICK_FAULT_RIGHT: return "free_kick_fault_r";
01923 case REFC_BACK_PASS_LEFT: return "back_pass_l";
01924 case REFC_BACK_PASS_RIGHT: return "back_pass_r";
01925 case REFC_PLAY_ON: return "play_on";
01926 case REFC_FROZEN: return "play_off";
01927 case REFC_QUIT: return "quit";
01928 case REFC_OFFSIDE_LEFT: return "offside_l";
01929 case REFC_OFFSIDE_RIGHT: return "offside_r";
01930 case REFC_HALF_TIME: return "half_time";
01931 case REFC_TIME_UP: return "time_up";
01932 case REFC_TIME_OVER: return "time_over";
01933 case REFC_TIME_UP_WITHOUT_A_TEAM: return "time_up_without_a_team";
01934 case REFC_TIME_EXTENDED: return "time_extended";
01935 case REFC_FOUL_LEFT: return "foul_l";
01936 case REFC_FOUL_RIGHT: return "foul_r";
01937 case REFC_GOAL_LEFT: return "goal_l";
01938 case REFC_GOAL_RIGHT: return "goal_r";
01939 case REFC_DROP_BALL: return "drop_ball";
01940 case REFC_GOALIE_CATCH_BALL_LEFT: return "goalie_catch_ball_l";
01941 case REFC_GOALIE_CATCH_BALL_RIGHT: return "goalie_catch_ball_r";
01942 case REFC_PENALTY_SETUP_LEFT: return "penalty_setup_left";
01943 case REFC_PENALTY_SETUP_RIGHT: return "penalty_setup_right";
01944 case REFC_PENALTY_READY_LEFT: return "penalty_ready_left";
01945 case REFC_PENALTY_READY_RIGHT: return "penalty_ready_right";
01946 case REFC_PENALTY_TAKEN_LEFT: return "penalty_taken_left";
01947 case REFC_PENALTY_TAKEN_RIGHT: return "penalty_taken_right";
01948 case REFC_PENALTY_MISS_LEFT: return "penalty_miss_left";
01949 case REFC_PENALTY_MISS_RIGHT: return "penalty_miss_right";
01950 case REFC_PENALTY_SCORE_LEFT: return "penalty_score_left";
01951 case REFC_PENALTY_SCORE_RIGHT: return "penalty_score_right";
01952 case REFC_PENALTY_FOUL_LEFT: return "penalty_foul_left";
01953 case REFC_PENALTY_FOUL_RIGHT: return "penalty_foul_right";
01954 case REFC_PENALTY_ONFIELD_LEFT: return "penalty_onfield_left";
01955 case REFC_PENALTY_ONFIELD_RIGHT: return "penalty_onfield_right";
01956 case REFC_PENALTY_WINNER_LEFT: return "penalty_winner_l";
01957 case REFC_PENALTY_WINNER_RIGHT: return "penalty_winner_r";
01958 case REFC_PENALTY_DRAW: return "penalty_draw";
01959 case REFC_ILLEGAL:
01960 default: return NULL;
01961 }
01962 }
01963
01964
01970 RefereeMessageT SoccerTypes::getRefereeMessageFromStr( char* str )
01971 {
01972 switch( str[0] )
01973 {
01974 case 'b':
01975 if( str[1] == 'e' )
01976 return REFC_BEFORE_KICK_OFF;
01977 else
01978 return (str[10] == 'l') ? REFC_BACK_PASS_LEFT : REFC_BACK_PASS_RIGHT;
01979 case 'c':
01980 return (str[12] == 'l') ? REFC_CORNER_KICK_LEFT : REFC_CORNER_KICK_RIGHT;
01981 case 'd':
01982 return REFC_DROP_BALL;
01983 case 'g':
01984 switch( str[5] )
01985 {
01986 case 'k':
01987 return (str[10] == 'l') ? REFC_GOAL_KICK_LEFT : REFC_GOAL_KICK_RIGHT;
01988 case 'e':
01989 return (str[18] == 'l') ? REFC_GOALIE_CATCH_BALL_LEFT
01990 : REFC_GOALIE_CATCH_BALL_RIGHT;
01991 case 'l':
01992 return REFC_GOAL_LEFT;
01993 case 'r':
01994 return REFC_GOAL_RIGHT;
01995 }
01996 case 'h':
01997 return REFC_HALF_TIME;
01998 case 'i':
01999 if( strlen( str ) > 19 )
02000 return ( str[19] == 'l' )
02001 ? REFC_INDIRECT_FREE_KICK_LEFT
02002 : REFC_INDIRECT_FREE_KICK_RIGHT;
02003 break;
02004 case 'f':
02005 if( str[5] == 'k' )
02006 {
02007 if( str[10] == 'f' )
02008 return ( str[16] == 'l' )
02009 ? REFC_FREE_KICK_FAULT_LEFT
02010 : REFC_FREE_KICK_FAULT_RIGHT;
02011 else
02012 return (str[10] == 'l') ? REFC_FREE_KICK_LEFT : REFC_FREE_KICK_RIGHT;
02013 }
02014 else if( str[5] == 'l' )
02015 return REFC_FOUL_LEFT;
02016 else if( str[5] == 'r' )
02017 return REFC_FOUL_RIGHT;
02018 case 'k':
02019 if( str[5] == 'i' )
02020 return (str[8] == 'l' ) ? REFC_KICK_IN_LEFT : REFC_KICK_IN_RIGHT;
02021 else if( str[5] == 'o' )
02022 return (str[9] == 'l' ) ? REFC_KICK_OFF_LEFT : REFC_KICK_OFF_RIGHT;
02023 case 'o':
02024 return ( str[8] == 'l' ) ? REFC_OFFSIDE_LEFT : REFC_OFFSIDE_RIGHT;
02025 case 'p':
02026 if( str[1] == 'l' )
02027 return REFC_PLAY_ON;
02028 else if( str[8] == 's' && str[9] == 'e' )
02029
02030 return ( str[14] == 'l' ) ? REFC_PENALTY_SETUP_LEFT
02031 : REFC_PENALTY_SETUP_RIGHT;
02032 else if( str[8] == 's' && str[9] == 'c' )
02033 return ( str[14] == 'l' ) ? REFC_PENALTY_SCORE_LEFT
02034 : REFC_PENALTY_SCORE_RIGHT;
02035 else if( str[8] == 'r' )
02036 return ( str[14] == 'l' ) ? REFC_PENALTY_READY_LEFT
02037 : REFC_PENALTY_READY_RIGHT;
02038 else if( str[8] == 't' )
02039 return ( str[14] == 'l' ) ? REFC_PENALTY_TAKEN_LEFT
02040 : REFC_PENALTY_TAKEN_RIGHT;
02041 else if( str[8] == 'm' )
02042 return ( str[13] == 'l' ) ? REFC_PENALTY_MISS_LEFT
02043 : REFC_PENALTY_MISS_RIGHT;
02044 else if( str[8] == 'o' )
02045 return ( str[16] == 'l' ) ? REFC_PENALTY_ONFIELD_LEFT
02046 : REFC_PENALTY_ONFIELD_RIGHT;
02047 else if( str[8] == 'f' )
02048 return ( str[13] == 'l' ) ? REFC_PENALTY_FOUL_LEFT
02049 : REFC_PENALTY_FOUL_RIGHT;
02050 else if( str[8] == 'f' )
02051 return ( str[15] == 'l' ) ? REFC_PENALTY_WINNER_LEFT
02052 : REFC_PENALTY_WINNER_RIGHT;
02053 else if( str[8] == 'd' )
02054 return REFC_PENALTY_DRAW;
02055 case 't':
02056 if( str[5] == 'o' )
02057 return REFC_TIME_OVER;
02058 else if( str[5] == 'e' )
02059 return REFC_TIME_EXTENDED;
02060 else if( str[5] == 'u' )
02061 return REFC_TIME_UP;
02062 else if( str[8] == 'w' )
02063 return REFC_TIME_UP_WITHOUT_A_TEAM;
02064 default:
02065 printf("(SoccerTypes::getRefereeMessageFromStr) ?? ref msg %s\n",str);
02066 return REFC_ILLEGAL;
02067 }
02068 printf("(SoccerTypes::getRefereeMessageFromStr) ?? ref msg %s\n",str);
02069 return REFC_ILLEGAL;
02070 }
02071
02072
02077 char* SoccerTypes::getViewAngleStr( ViewAngleT va )
02078 {
02079 switch( va )
02080 {
02081 case VA_NARROW: return "narrow";
02082 case VA_NORMAL: return "normal";
02083 case VA_WIDE: return "wide";
02084 case VA_ILLEGAL:
02085 default: return NULL;
02086 }
02087 }
02088
02092 ViewAngleT SoccerTypes::getViewAngleFromStr( char* str )
02093 {
02094 switch( str[1] )
02095 {
02096 case 'a': return VA_NARROW;
02097 case 'o': return VA_NORMAL;
02098 case 'i': return VA_WIDE;
02099 default: return VA_ILLEGAL;
02100 }
02101 }
02102
02112 AngDeg SoccerTypes::getHalfViewAngleValue( ViewAngleT va )
02113 {
02114 switch( va )
02115 {
02116 case VA_NARROW: return 22.5;
02117 case VA_NORMAL: return 45.0;
02118 case VA_WIDE: return 90.0;
02119 case VA_ILLEGAL:
02120 default: return 0.0;
02121 }
02122
02123 }
02124
02129 char* SoccerTypes::getViewQualityStr( ViewQualityT vq )
02130 {
02131 switch( vq )
02132 {
02133 case VQ_HIGH: return "high";
02134 case VQ_LOW: return "low";
02135 case VQ_ILLEGAL:
02136 default: return NULL;
02137 }
02138 }
02139
02144 ViewQualityT SoccerTypes::getViewQualityFromStr( char* str )
02145 {
02146 if( str[0] == 'h' ) return VQ_HIGH;
02147 else if( str[0] == 'l' ) return VQ_LOW;
02148 else return VQ_ILLEGAL;
02149 }
02150
02155 char* SoccerTypes::getCommandStr( CommandT com )
02156 {
02157 switch( com )
02158 {
02159 case CMD_DASH: return "dash";
02160 case CMD_TURN: return "turn";
02161 case CMD_TURNNECK: return "turn_neck";
02162 case CMD_CHANGEVIEW: return "change_view";
02163 case CMD_CATCH: return "catch";
02164 case CMD_KICK: return "kick";
02165 case CMD_MOVE: return "move";
02166 case CMD_SENSEBODY: return "sense_body";
02167 case CMD_SAY: return "neck";
02168 case CMD_ATTENTIONTO: return "attentionto";
02169 case CMD_TACKLE: return "tackle";
02170 case CMD_POINTTO: return "pointto";
02171 case CMD_ILLEGAL:
02172 default: return NULL;
02173
02174 }
02175 }
02176
02182 bool SoccerTypes::isPrimaryCommand( CommandT com )
02183 {
02184 return com == CMD_KICK || com == CMD_DASH || com == CMD_MOVE ||
02185 com == CMD_TURN || com == CMD_CATCH || com == CMD_TACKLE ;
02186 }
02187
02188
02193 char* SoccerTypes::getSideStr( SideT s )
02194 {
02195 switch( s )
02196 {
02197 case SIDE_LEFT: return "l";
02198 case SIDE_RIGHT: return "r";
02199 case SIDE_ILLEGAL:
02200 default: return NULL;
02201 }
02202 }
02203
02208 SideT SoccerTypes::getSideFromStr( char* str )
02209 {
02210 if( str[0] == 'l' ) return SIDE_LEFT;
02211 else if( str[0] == 'r' ) return SIDE_RIGHT;
02212 else return SIDE_ILLEGAL;
02213
02214 }
02215
02221 char* SoccerTypes::getBallStatusStr( BallStatusT bs )
02222 {
02223 switch( bs )
02224 {
02225 case BS_IN_FIELD: return "in_field";
02226 case BS_GOAL_LEFT: return "goal_left";
02227 case BS_GOAL_RIGHT: return "goal_right";
02228 case BS_OUT_OF_FIELD: return "out_of_field";
02229 default: return NULL;
02230 }
02231 }
02232
02239 BallStatusT SoccerTypes::getBallStatusFromStr( char* str )
02240 {
02241 switch( str[0] )
02242 {
02243 case 'i': return BS_IN_FIELD;
02244 case 'o': return BS_OUT_OF_FIELD;
02245 case 'g': return (str[5]=='l') ? BS_GOAL_LEFT : BS_GOAL_RIGHT;
02246 default:
02247 cout << "(SoccerTypes::getBallStatusFromStr) illegal status " <<
02248 str << "\n";
02249 return BS_ILLEGAL;
02250 }
02251 }
02252
02255 AngDeg SoccerTypes::getAngleFromDirection( DirectionT dir )
02256 {
02257 switch( dir )
02258 {
02259 case DIR_NORTH: return 0.0;
02260 case DIR_NORTHWEST: return -45.0;
02261 case DIR_WEST: return -90.0;
02262 case DIR_SOUTHWEST: return -135.0;
02263 case DIR_SOUTH: return 180.0;
02264 case DIR_SOUTHEAST: return 135.0;
02265 case DIR_EAST: return 90.0;
02266 case DIR_NORTHEAST: return 45.0;
02267 case DIR_ILLEGAL:
02268 default:
02269 break;
02270
02271 }
02272 cerr << "(SoccerTypes::getAngleFromDirection) illegal dir " << dir << endl;
02273 return 0.0;
02274 }
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324