1 /* $Id: Training.cpp,v 1.11 2003/07/16 15:55:24 nan Exp $ */
2 
3 // Copyright (C) 2000, 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 "Training.h"
21 #include "TrainingView.h"
22 #include "BaseView.h"
23 #include "Player.h"
24 #include "Ball.h"
25 #include "Event.h"
26 
27 extern Ball theBall;
28 extern long mode;
29 
Training()30 Training::Training() {
31   m_View = NULL;
32   m_trainingCount = 0;
33   m_trainingMax = 0;
34 }
35 
~Training()36 Training::~Training() {
37   if ( m_View ){
38     BaseView::TheView()->RemoveView( m_View );
39     delete m_View;
40   }
41 }
42 
43 bool
Init()44 Training::Init() {
45   m_View = (TrainingView *)View::CreateView( VIEW_TRAINING );
46 
47   m_View->Init( this );
48 
49   BaseView::TheView()->AddView( m_View );
50 
51   return true;
52 }
53 
54 void
Create(long player,long com)55 Training::Create( long player, long com ) {
56   Control::ClearControl();
57 
58   m_theControl = new Training();
59   m_theControl->Init();
60 
61   m_thePlayer = Player::Create( player, 1, 2 );
62   m_comPlayer = Player::Create( com, -1, 3 );
63 
64   m_thePlayer->Init();
65   m_comPlayer->Init();
66 
67   // Move it to view?
68   SDL_ShowCursor(0);
69   SDL_WM_GrabInput( SDL_GRAB_ON );
70 }
71 
72 bool
Move(SDL_keysym * KeyHistory,long * MouseXHistory,long * MouseYHistory,unsigned long * MouseBHistory,int Histptr)73 Training::Move( SDL_keysym *KeyHistory, long *MouseXHistory,
74 		long *MouseYHistory, unsigned long *MouseBHistory,
75 		int Histptr ) {
76   bool reDraw = false;
77   long ballStatus = theBall.GetStatus();
78 
79   if ( KeyHistory[Histptr].unicode == 'Q' ) {
80     mode = MODE_TITLE;
81     return true;
82   }
83 
84   theBall.Move();
85   reDraw |= m_thePlayer->Move( KeyHistory, MouseXHistory,
86 			     MouseYHistory, MouseBHistory, Histptr );
87   reDraw |= m_comPlayer->Move( NULL, NULL, NULL, NULL, 0 );
88 
89   if ( ballStatus != theBall.GetStatus() ) {
90     if ( theBall.GetStatus() == 8 ) {
91       if ( m_trainingCount > m_trainingMax )
92 	m_trainingMax = m_trainingCount;
93       m_trainingCount = 0;
94     }
95   }
96 
97   return reDraw;
98 }
99 
100 bool
LookAt(double & srcX,double & srcY,double & srcZ,double & destX,double & destY,double & destZ)101 Training::LookAt( double &srcX, double &srcY, double &srcZ,
102 		  double &destX, double &destY, double &destZ ) {
103   if (m_thePlayer) {
104     srcX = m_thePlayer->GetX() + m_thePlayer->GetEyeX();
105     srcY = m_thePlayer->GetY() + m_thePlayer->GetEyeY();
106     srcZ = m_thePlayer->GetZ() + m_thePlayer->GetEyeZ();
107     destX = m_thePlayer->GetLookAtX();
108     destY = m_thePlayer->GetLookAtY();
109     destZ = m_thePlayer->GetLookAtZ();
110   }
111 
112   return true;
113 }
114 
115 void
AddTrainingCount()116 Training::AddTrainingCount() {
117   m_trainingCount++;
118 }
119