📄 memory.c
字号:
void Memory::UpdateActive(){/* if ( PlayMode != PLAY_ON ) */ if ( CurrentTime == 0 ) return; /* Do this in terms of distance so it works even if the players not back in position yet */ float cdist, max_cdist = GetMaxActiveDistance(); float ball_dist = GetBallDistance(); switch( GetCurrentFormationType() ){ case fRT_FORMATION: if ( GetBallGlobalY() > 5 && PlayMode == PLAY_ON){ SetMyselfInactive(); return; } break; case fLT_FORMATION: if ( GetBallGlobalY() < -5 && PlayMode == PLAY_ON){ SetMyselfInactive(); return; } break; } if ( strcmp(GetMyStatus(),RECEIVER_STAT) ){ /* Stay active if receiving */ if ( PlayMode != PLAY_ON && GetMyPositionType() != GOALTENDER ) max_cdist = 100; } if ( OnlyActiveIfClosest() ) /* not set in the previous switch function */ cdist = MIN(max_cdist,.2+ClosestTeammateToBall()); else cdist = max_cdist; cdist = MAX(GetMinInactiveDistance(), cdist);#if 0 float ball_vel_dir = GetBallVelDirection(); int ball_vel_known = ball_vel_dir != NODIR; int ball_moving_towards = ball_vel_known && fabs(ball_vel_dir) > 135; int ball_not_moving_towards = ball_vel_known && !ball_moving_towards;#else int ball_vel_known = BallTrajectoryValid() > 0 ? TRUE : FALSE; float ball_vel_dir; if ( ball_vel_known) ball_vel_dir = GetBallTrajectoryRelativeDirection(); int ball_moving_towards = ball_vel_known && fabs(ball_vel_dir) > 150; int ball_not_moving_towards = ball_vel_known && fabs(ball_vel_dir) < 120;#endif if ( !strcmp(GetMyStatus(),RECEIVER_STAT) ){ /* I'm the receiver */ if ( GetMyActiveStatus() != ACTIVE ){#if ACTIVE_DEBUG if (Mem->MyNumber == 4) printf("%d -----> ACTIVE (%d)\n", Mem->CurrentTime,Mem->MyNumber);#endif SetMyselfActive(); } if ( ball_dist < cdist || /* Active in my own right */ GetMyStamina() < 500 ) /* Or getting tired */ Mem->ClearMyStatus(); return; }/* After you were active, if the ball's still within 40 and if you don't know what direction it's going, stay at attention until you do. If you KNOW it's not coming towards you, you can go inactive, if you KNOW it is, then you go back active... Don't say going to position on transition from active to at attention. But do from at attention to inactive */ /* when inactive or at attention, check if should go active */ if ( GetMyActiveStatus() != ACTIVE && ball_dist < max_cdist ){ if ( ball_dist < cdist || ball_moving_towards ){ SAY(MY_BALL_MSG);#if ACTIVE_DEBUG if (MyNumber == 4) printf("%d -----> ACTIVE (%d)\n", Mem->CurrentTime,Mem->MyNumber); if (Mem->MyNumber == 4 && ball_moving_towards) printf(" *** %.1f *** \n",ball_vel_dir);#endif SetMyselfActive(); return; } }#if PRACTICE#else float targetX,targetY; if ( ball_vel_known && GetCollectTargetXY(&targetX,&targetY) && /* I can get there */ DistanceToPoint(targetX,targetY) < 10 && (Mem->GetMyPosition() == UNKNOWN_POSITION || TeamPositionInfo::IsWithinMyMaxRange(targetX,targetY)) ){ int closest; ClosestTeammateTo(targetX,targetY,&closest); if ( closest == MyNumber ){ /* printf("%d:%d Target (%.1f %.1f)\n",Mem->MyNumber,Mem->CurrentTime, targetX,targetY); */ SetMyselfActive(); return; } }#endif /* when active, check if should go inactive */ if ( GetMyActiveStatus() == ACTIVE && ball_dist > cdist ){ if ( !ball_vel_known ){#if ACTIVE_DEBUG if (Mem->MyNumber == 4) printf("%d AT ATTENTION <----- ACTIVE (%d)\n", Mem->CurrentTime,Mem->MyNumber);#endif SetMyselfAtAttention(); } else if ( ball_not_moving_towards ){#if ACTIVE_DEBUG if (Mem->MyNumber == 4) printf("%d INACTIVE <----- ACTIVE (%d)\n", Mem->CurrentTime,Mem->MyNumber); if (Mem->MyNumber == 4 && ball_not_moving_towards) printf(" *** %.1f *** \n",ball_vel_dir);#endif SetMyselfInactive(); /* printf("%d:%d going inactive bdist = %.1f, cdist =%.1f\n", Mem->MyNumber,Mem->CurrentTime,ball_dist,cdist);*/ if ( Mem->GetMyPosition() == UNKNOWN_POSITION ) Mem->SetMyPosition(GetNewPosition()); ANNOUNCEMYPOSITION; return; } } /* when at attention, check if should go inactive */ if ( GetMyActiveStatus() == AT_ATTENTION ){ if ( ball_dist > max_cdist || /* or ballvel !known? */ (ball_dist > cdist && ball_not_moving_towards) ){ SetMyselfInactive();#if ACTIVE_DEBUG if (Mem->MyNumber == 4) printf("%d INACTIVE <------- AT ATTENTION (%d)\n", Mem->CurrentTime,Mem->MyNumber); if (Mem->MyNumber == 4 && ball_not_moving_towards) printf(" *** %.1f *** \n",ball_vel_dir);#endif if ( Mem->GetMyPosition() == UNKNOWN_POSITION ) Mem->SetMyPosition(GetNewPosition()); ANNOUNCEMYPOSITION; return; } }}void Memory::SetStatus(char side, int num, char *status){ if ( side == MySide ){ strcpy(my_team_status[num],status); } else { /* side == TheirSide */ my_error(" Not dealing with their_team_status"); /* strcpy(their_team_status[num],status); */ }}char *Memory::GetStatus(char side, int num){ if ( side == MySide ){ return my_team_status[num]; } else { /* side == TheirSide */ my_error(" Not dealing with their_team_status (get)"); /* return their_team_status[num]; */ }}void Memory::SetData(int num, char *data){ strcpy(my_team_data[num],data);}char *Memory::GetData(int num){ return my_team_data[num];}int Memory::InPosition(){ float x = GetGlobalX(), y = GetGlobalY(); float homeX = GetCurrentHomeX(), homeY = GetCurrentHomeY(); float dist = GetDistance(&homeX,&homeY,&x,&y); if ( dist > GetMyPositionBuffer() ) return FALSE; else return TRUE;}int Memory::InKickoffPosition(){ if ( GetMyPosition() == UNKNOWN_POSITION ) return FALSE; float x = GetGlobalX(), y = GetGlobalY(); float goalX,goalY; if ( SetPlay && MyPositionInSetPlay() ) GetMySetPlayXY(&goalX,&goalY); else{ goalX = Mem->GetCurrentHomeX(); goalY = Mem->GetCurrentHomeY(); } PositionToKickoffPosition( &goalX, &goalY ); float dist = GetDistance(&goalX,&goalY,&x,&y); if ( dist > GetMyPositionBuffer() ) return FALSE; else return TRUE;}int Memory::GetPositionOfMyLocation(){ return LocationToPosition(GetGlobalX(), GetGlobalY());}int Memory::GetMyLocationsPositionType(){ return PositionType(GetPositionOfMyLocation());}int Memory::GetMyLocationsPositionSide(){ return PositionSide(GetPositionOfMyLocation());} void Memory::CheckForPlayersInMyPosition(){ for (int teammate=1; teammate<=TEAM_SIZE; teammate++){ if ( teammate != MyNumber && TeammateValid(teammate) && GetTeammateDistance(teammate) < 10 ){ int teammate_position = GetPlayerPosition(teammate); if ( 1 /* || GetActiveStatus(teammate) != ACTIVE */ ){ if ( teammate_position == UNKNOWN_POSITION ){ /*printf("%d:%d %d at unknown_position\n", Mem->MyNumber,Mem->CurrentTime,teammate);*/ SAYTO(teammate,PING_MSG); } else if ( teammate_position == GetMyPosition() ){ /*printf("%d:%d %d at my position (%d)\n", Mem->MyNumber,Mem->CurrentTime,teammate,teammate_position);*/ SAYTO(teammate, ALREADY_THERE_MSG); } } } }}int Memory::OnlyActiveIfClosest(){ int position = GetMyPosition(); if (position == UNKNOWN_POSITION) position = GetPositionOfMyLocation(); return GetCurrentFormation()->GetPosition(position)->OnlyActiveIfClosest();}float Memory::GetMaxActiveDistance(){ int position = GetMyPosition(); if (position == UNKNOWN_POSITION) position = GetPositionOfMyLocation(); return GetCurrentFormation()->GetPosition(position)->GetMaxActiveDistance();}float Memory::GetMinInactiveDistance(){ int position = GetMyPosition(); if (position == UNKNOWN_POSITION) position = GetPositionOfMyLocation(); return GetCurrentFormation()->GetPosition(position)->GetMinInactiveDistance();}int Memory::IsWithinMyHomeRange(char side, int number){ if ( !PlayerValid(side,number) ) return FALSE; float x,y; GetPlayerGlobalXY(side, number, &x, &y); return TeamPositionInfo::IsWithinMyHomeRange(x,y);}int Memory::IsWithinMyMaxRange(char side, int number){ if ( !PlayerValid(side,number) ) return FALSE; float x,y; GetPlayerGlobalXY(side, number, &x, &y); return TeamPositionInfo::IsWithinMyMaxRange(x,y);}int Memory::AmWithinMyHomeRange(){ return TeamPositionInfo::IsWithinMyHomeRange(GetGlobalX(),GetGlobalY());}int Memory::AmWithinMyMaxRange(){ return TeamPositionInfo::IsWithinMyMaxRange(GetGlobalX(),GetGlobalY());}int Memory::BallIsWithinMyHomeRange(){ float x,y; GetBallGlobalXY(&x,&y); return TeamPositionInfo::IsWithinMyHomeRange(x,y);}int Memory::BallIsWithinMyMaxRange(){ float x,y; GetBallGlobalXY(&x,&y);/* return TeamPositionInfo::IsWithinMyMaxRange(x,y);*/ int result = TeamPositionInfo::IsWithinMyMaxRange(x,y);/* if (!result){ printf("%d: Ball is outside my max range (%.1f, %.1f)\n", MyNumber,GetBallGlobalX(),GetBallGlobalY()); PositionMaxRange(Mem->GetMyPosition())->Print(); }*/ return result;}int Memory::OpponentIsWithinPlayerHomeRange(int opponent, int player){ float opponentx,opponenty; GetPlayerGlobalXY(TheirSide,opponent,&opponentx,&opponenty); return PositionHomeRange(GetPlayerPosition(player))->IsWithin(opponentx,opponenty);}int Memory::OpponentIsWithinPlayerMaxRange(int opponent, int player){ float opponentx,opponenty; GetPlayerGlobalXY(TheirSide,opponent,&opponentx,&opponenty); return PositionMaxRange(GetPlayerPosition(player))->IsWithin(opponentx,opponenty);}float Memory::PlayerDistanceToPositionHome(int player, int position){ if ( player && player != MyNumber && !TeammateValid(player) ) my_error("Don't know where the player is (PlayerDistanceToPositionHome)"); float x,y; if ( !player || player == MyNumber ){ x = GetGlobalX(); y = GetGlobalY(); } else GetTeammateGlobalXY(player,&x,&y); return DistanceToPositionHome(position,x,y);}void Memory::UpdateHome(){ /* need a HOME_GETOPEN */ switch(HomeChangeMethod){ case HOME_OBEY: /*printf("%d:%d home obey??\n",Mem->MyNumber,Mem->CurrentTime);*/ break; case HOME_MARK: /*printf("%d:%d home mark??\n",Mem->MyNumber,Mem->CurrentTime);*/ break; case HOME_MARK_ELSE_SHIFT: case HOME_SHIFT: /* Was Shade to ball side */ if ( !Mem->BallValid() ) my_error("Shouldn't be updating home if ball's not valid"); float defaultY = GetMyPositionY(); float defaultX = GetMyPositionX(); float ballX = GetBallGlobalX(); float ballY = GetBallGlobalY(); float ShadeFactor = GetMyHomeRangeHeight()/(Y0*2); /* Scale by field width */ float ShadeMag = (ballY - defaultY)*ShadeFactor; float ballDist = fabs(ballX - defaultX); ShadeMag *= MAX(0,(1 - ballDist/(X0*2))); /* Scale by ball's distance */ SetCurrentHomeY(defaultY + ShadeMag); /* drop back if the ball's on the other side of the field */ ShadeFactor = (GetMyHomeRangeWidth()/(X0*2)); /* Scale by field length */ ShadeMag = fabs((ballY - defaultY)*ShadeFactor); ShadeMag *= fabs(ballY)/Y0; /* Scale by ball's position */ if ( ballY*defaultY < 0 ) /* other side */ SetCurrentHomeX(defaultX - ShadeMag); else SetCurrentHomeX(defaultX); }}void Memory::UpdateMark(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -