1 /* $Id: NetPenDrive.cpp,v 1.3 2003/07/16 16:03:38 nan Exp $ */
2 
3 // Copyright (C) 2001, 2002  $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 "NetPenDrive.h"
21 #include "Ball.h"
22 #include "Event.h"
23 
24 extern Ball   theBall;
25 
NetPenDrive()26 NetPenDrive::NetPenDrive() : PenDrive() {
27 }
28 
NetPenDrive(long side)29 NetPenDrive::NetPenDrive(long side) : PenDrive(side) {
30 }
31 
NetPenDrive(long playerType,long side,double x,double y,double z,double vx,double vy,double vz,long status,long swing,long swingType,bool swingSide,long afterSwing,long swingError,double targetX,double targetY,double eyeX,double eyeY,double eyeZ,long pow,double spin,double stamina,long statusMax)32 NetPenDrive::NetPenDrive( long playerType, long side,
33 			  double x, double y, double z,
34 			  double vx, double vy, double vz,
35 			  long status, long swing, long swingType,
36 			  bool swingSide, long afterSwing,
37 			  long swingError,
38 			  double targetX, double targetY,
39 			  double eyeX, double eyeY, double eyeZ,
40 			  long pow, double spin, double stamina,
41 			  long statusMax ) :
42   PenDrive( playerType, side, x, y, z, vx, vy, vz, status, swing, swingType,
43 	    swingSide, afterSwing, swingError, targetX, targetY,
44 	    eyeX, eyeY, eyeZ, pow, spin, stamina, statusMax ) {
45 }
46 
~NetPenDrive()47 NetPenDrive::~NetPenDrive() {
48 }
49 
50 bool
Move(SDL_keysym * KeyHistory,long * MouseXHistory,long * MouseYHistory,unsigned long * MouseBHistory,int Histptr)51 NetPenDrive::Move( SDL_keysym *KeyHistory, long *MouseXHistory,
52 		   long *MouseYHistory, unsigned long *MouseBHistory,
53 		   int Histptr ) {
54   PenDrive::Move( KeyHistory, MouseXHistory, MouseYHistory,MouseBHistory,
55 		  Histptr );
56 
57   // Calc the ball location of 0.1 second later.
58   // This part seems to be the same as Swing(). Consider again.
59   Ball *tmpBall;
60   double tmpBallX, tmpBallY, tmpBallZ;
61   double tmpX, tmpY;
62 
63   tmpBall = new Ball( theBall.GetX(), theBall.GetY(), theBall.GetZ(),
64 		      theBall.GetVX(), theBall.GetVY(), theBall.GetVZ(),
65 		      theBall.GetSpin(), theBall.GetStatus() );
66 
67   for ( int i = 0 ; i < 9 ; i++ )
68     tmpBall->Move();
69   tmpX = m_x+m_vx*0.08;
70   tmpY = m_y+m_vy*0.08;
71 
72   if ( ((tmpBall->GetStatus() == 3 && m_side == 1) ||
73 	(tmpBall->GetStatus() == 1 && m_side == -1)) &&
74        (tmpY-tmpBall->GetY())*m_side < 0.3 &&
75        (tmpY-tmpBall->GetY())*m_side > -0.6 &&
76        m_swing <= 10 ) {
77 
78     tmpBallX = tmpBall->GetX();
79     tmpBallY = tmpBall->GetY();
80     tmpBallZ = tmpBall->GetZ();
81 
82     // If the ball location becomes better at 1/100 second later, wait.
83     tmpBall->Move();
84     if ( fabs(tmpY+m_vy*0.01-tmpBall->GetY()) > fabs(tmpY-tmpBallY) ) {
85       if ( (m_x-tmpBallX)*m_side < 0 )
86 	Swing(3);
87       else
88 	Swing(1);
89     }
90   }
91   delete tmpBall;
92 
93   return true;
94 }
95