www.pudn.com > Product_Submit2004.rar > BallPredict.cc, change:2004-10-12,size:2321b


#include "BallPredict.h" 
#include "../Common/Common.h" 
 
// tests ball prediction. badly :) 
BallPredict::BallPredict() { 
  currentTrick = new BasicTricks::NullBody(); 
  headTrick = new BasicTricks::NullHead(); 
  isFollowingBall = false; 
} 
 
void BallPredict::NewReadyModel() { 
  int hC=headTrick->Continue(); 
  char* hMsg = headTrick->GetErrorMsg(hC); 
  if (!currentTrick->IsUsingHead() && (hC < 1)) { 
    delete headTrick; 
    if (strcmp(hMsg,"SEE_BALL") == 0) { 
      headTrick = new HeadTricks::FollowBallWithHeadSticky(20); 
      isFollowingBall=true; 
    } else { 
      headTrick = new HeadTricks::HeadPanForBall(); 
      isFollowingBall=false; 
    } 
    headTrick->Start(); 
  } 
 
} 
 
void BallPredict::NewPlayingModel() { 
  static int blockingCount = 0; 
 
  int cC = currentTrick->Continue(); 
  if (cC < 1  && strcmp(currentTrick->GetName(), "Kick") == 0) { 
    delete currentTrick; 
    currentTrick = new BasicTricks::NullBody(); 
    currentTrick->Start(); 
  } 
 
  if (blockingCount == 0) { 
    if (ballPrediction_.ShouldIDive()) { 
      cout << "Kick Dammit, KICK!" << endl; 
//      int direction = ballPrediction_.DiveDirection(); 
      delete currentTrick; 
      //if (direction == BallPrediction::BP_LEFT) currentTrick = new BasicTricks::Kick(LocomotionCommand::TP_GOALIE_LEFT); 
      //else if (direction == BallPrediction::BP_RIGHT) currentTrick = new BasicTricks::Kick(LocomotionCommand::TP_GOALIE_RIGHT); 
      //else  
      currentTrick = new BasicTricks::Kick(LocomotionCommand::TP_GOALIE_BLOCK); 
      currentTrick->Start(); 
      blockingCount ++; 
      return; 
    } 
 
    int hC=headTrick->Continue(); 
    char* hMsg = headTrick->GetErrorMsg(hC); 
    if (!currentTrick->IsUsingHead() && (hC < 1)) { 
      delete headTrick; 
      if (strcmp(hMsg,"SEE_BALL") == 0) { 
        headTrick = new HeadTricks::FollowBallWithHeadSticky(20); 
        isFollowingBall=true; 
      } else { 
        headTrick = new HeadTricks::HeadPanForBall(); 
        isFollowingBall=false; 
      } 
      headTrick->Start(); 
    } 
  } else { 
    blockingCount++; 
    if (blockingCount > 19 /*ballPrediction_.diveTime*/) { 
      delete currentTrick; 
      currentTrick = new BasicTricks::Kick(99); 
      currentTrick->Start(); 
      blockingCount = 0; 
    } 
  } 
}