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


#include "JetLi.h" 
#include "../Common/Common.h" 
#include "../TOOLS/BallTricks.h" 
#include "../TOOLS/BasicTricks.h" 
#include "../TOOLS/HeadTricks.h" 
#include "../TOOLS/ComplexTricks.h" 
#include "../TOOLS/MovementTricks.h" 
#include "../TOOLS/PenaltyTricks.h" 
 
// 2003 penalty player. This dude lost the 2003 semi-final :) 
JetLi::JetLi() { 
  configuration_.ParseFile("/ms/open-r/mw/data/jetli.cfg"); 
 
  debugOutput = configuration_.GetAsBool("JetLi_DebugOutput"); 
 
  homeX[0] = configuration_.GetAsInt("JetLi_HomeX"); 
  homeY[0] = configuration_.GetAsInt("JetLi_HomeY"); 
  homeRadius = configuration_.GetAsInt("JetLi_HomeRadius"); 
  homeErrorDistance = configuration_.GetAsInt("JetLi_HomeErrorDistance"); 
 
  currentTrick = new BasicTricks::NullBody(); 
  headTrick = new BasicTricks::NullHead(); 
  inPlaying = false; 
  currentHomeIndex = 0; 
   
  homeX[0] = 0; 
  homeY[0] = -55; 
  homeX[1] = 0; 
  homeY[1] = 55; 
  homeRadius = 20; 
 
} 
 
JetLi::~JetLi() { 
  delete currentTrick; 
  delete headTrick; 
} 
 
void JetLi::NewReadyModel() { 
  if (inPlaying) { 
    delete headTrick; 
    headTrick = new HeadTricks::HeadPan(85,-85,3,50);   // MQ 19/6 .. changed from (70,-70,0,12) 
    headTrick->Start(); 
    delete currentTrick; 
    currentTrick = new BasicTricks::NullBody(); 
    currentTrick->Start(); 
  } 
 
  int hC=headTrick->Continue(); 
//char* hMsg = headTrick->GetErrorMsg(hC); 
  if (!currentTrick->IsUsingHead() && (hC < 1)) { 
    headTrick = new HeadTricks::HeadPan(85,-85,3,50);   // MQ 19/6 .. changed from (70,-70,0,12) 
    headTrick->Start(); 
  }/* else if (vo_ball_ != NULL && strcmp(headTrick->GetName(),"HeadPan")==0) { 
    delete headTrick; 
    headTrick = new HeadTricks::FollowBallWithHeadSticky(3); 
    headTrick->Start(); 
  }*/ 
 
  inPlaying = false; 
} 
 
void JetLi::NewPlayingModel() { 
  if (!inPlaying) { 
    delete headTrick; 
    headTrick = new BasicTricks::NullHead(); 
    headTrick->Start(); 
 
    delete currentTrick; 
    currentTrick = new BasicTricks::NullBody(); 
    currentTrick->Start(); 
  } 
  inPlaying=true; 
 
 
 
 
 
 
 
 
  int hC = headTrick->Continue(); 
  if (hC < 1) { 
    delete headTrick; 
    headTrick = new BasicTricks::NullHead(); 
    headTrick->Start(); 
  } 
 
  int cC = currentTrick->Continue(); 
  //executing normally. we may wish to interrupt. 
  if (cC >= 1) { 
    if (strcmp(currentTrick->GetName(),"MoveToPoint")==0) { 
      // we can see the ball !! 
      if (vo_ball_ != NULL) { 
        if (debugOutput) 
          cout << "JetLi: Aborting MoveToPoint and going after ball !" << endl << flush; 
        currentTrick->Abort();   
        delete currentTrick; 
        currentTrick = new PenaltyTricks::ChaseWithKick(); 
        currentTrick->Start(); 
 
        headTrick->Abort(); 
        delete headTrick; 
        headTrick = new BasicTricks::NullHead(); 
        headTrick->Start(); 
      } else if ( (pow(wo_self_->x_ - homeX[currentHomeIndex], 2)+pow(wo_self_->y_ - homeY[currentHomeIndex], 2)) < homeRadius*homeRadius) { 
        currentTrick->Abort(); 
        delete currentTrick; 
        currentTrick = new MovementTricks::SearchForBall(360.0); 
//        currentTrick = new MovementTricks::SearchForBallChallenge(360.0,40); 
        currentTrick->Start(); 
 
        headTrick->Abort(); 
        delete headTrick; 
        headTrick = new BasicTricks::NullHead(); 
        headTrick->Start(); 
      } 
    } 
  } else if (cC < 1) { 
    if (IsBallVisible()) { 
      if (debugOutput) 
        cout << "JetLi: Ball visible, previous trick has ended. Chasing." << endl << flush; 
      delete currentTrick; 
      currentTrick = new PenaltyTricks::ChaseWithKick(); 
      currentTrick->Start(); 
 
      headTrick->Abort(); 
      delete headTrick; 
      headTrick = new BasicTricks::NullHead(); 
      headTrick->Start(); 
    } else { 
      // if we're just out of a trick, and we did NOT just search, and the ball is not visible .. spin around ! 
      if ((strcmp(currentTrick->GetName(), "SearchForBall")!=0) && (IsBallVisible() == false)) { 
        if (debugOutput) 
          cout << "JetLi: Searching for ball." << endl << flush; 
        delete currentTrick; 
        currentTrick = new MovementTricks::SearchForBall(360.0); 
        //currentTrick = new MovementTricks::SearchForBallChallenge(360.0,40); 
        currentTrick->Start(); 
 
        delete headTrick; 
        headTrick = new BasicTricks::NullHead(); 
        headTrick->Start(); 
      } else if ((pow(wo_self_->x_ - homeX[currentHomeIndex], 2)+pow(wo_self_->y_ - homeY[currentHomeIndex], 2)) < homeRadius*homeRadius) { 
        currentHomeIndex++;         
        if (currentHomeIndex > 1) currentHomeIndex=0; 
        delete currentTrick; 
 
        if (currentHomeIndex == 0) { 
          currentTrick = new MovementTricks::MoveToPoint(homeX[currentHomeIndex],homeY[currentHomeIndex],0.0,MovementTricks::MoveToPoint::MTP_DYNAMIC_FACE_BALL); 
        } else { 
          currentTrick = new MovementTricks::MoveToPoint(homeX[currentHomeIndex],homeY[currentHomeIndex],0.0,MovementTricks::MoveToPoint::MTP_DYNAMIC); 
        } 
        currentTrick->Start(); 
        delete headTrick; 
        headTrick = new HeadTricks::HeadPanForBall(); 
        headTrick->Start(); 
 
      } else { 
        // if we've just searched and didn't find the ball, let's go home ! 
        delete currentTrick; 
 
        if (currentHomeIndex == 0) { 
          currentTrick = new MovementTricks::MoveToPoint(homeX[currentHomeIndex],homeY[currentHomeIndex],0.0,MovementTricks::MoveToPoint::MTP_DYNAMIC_FACE_BALL); 
        } else { 
          currentTrick = new MovementTricks::MoveToPoint(homeX[currentHomeIndex],homeY[currentHomeIndex],0.0,MovementTricks::MoveToPoint::MTP_DYNAMIC);        } 
        currentTrick->Start(); 
        delete headTrick; 
        headTrick = new HeadTricks::HeadPanForBall(); 
        headTrick->Start(); 
      }  
    } 
  } 
} 
 
 
bool JetLi::IsBallVisible() { 
  return (vo_ball_ != NULL); 
}