1 /* $Id: comPlayer.cpp,v 1.5 2001/12/05 15:39:25 nan Exp $ */
2 
3 // Copyright (C) 2000  $B?@Fn(B $B5H9((B(Kanna Yoshihiro)
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19 #include "ttinc.h"
20 #include "Player.h"
21 #include "comPlayer.h"
22 #include "Ball.h"
23 
24 extern Ball   theBall;
25 
ComPlayer()26 ComPlayer::ComPlayer() {
27   _prevBallstatus = 0;
28   _hitX = 0;
29   _hitY = -TABLELENGTH/3;
30 }
31 
~ComPlayer()32 ComPlayer::~ComPlayer() {
33 }
34 
35 // Calculate top of the ball
36 double
GetBallTop(double & maxX,double & maxY,Player * p)37 ComPlayer::GetBallTop( double &maxX, double &maxY, Player *p ) {
38   Ball *tmpBall;
39   double max = -1.0;             /* highest point of the ball */
40 
41   tmpBall = new Ball( theBall.GetX(), theBall.GetY(), theBall.GetZ(),
42 		      theBall.GetVX(), theBall.GetVY(), theBall.GetVZ(),
43 		      theBall.GetSpin(), theBall.GetStatus() );
44 
45   while ( tmpBall->GetStatus() != -1 ) {
46     if ( (tmpBall->GetStatus() == 3 && p->GetSide() == 1) ||
47 	 (tmpBall->GetStatus() == 1 && p->GetSide() == -1) ) {
48       if ( tmpBall->GetZ() > max &&
49 	   fabs(tmpBall->GetY()) < TABLELENGTH/2+1.0 &&
50 	   fabs(tmpBall->GetY()) > TABLELENGTH/2-0.5 ) {
51 	max = tmpBall->GetZ();
52 	maxX = tmpBall->GetX();
53 	maxY = tmpBall->GetY();
54       }
55     }
56     tmpBall->Move();
57   }
58 
59   delete tmpBall;
60   return max;
61 }
62