1 /* $Id: PlayerSelect.cpp,v 1.23 2003/07/19 14:25:44 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 "PlayerSelect.h"
21 #include "BaseView.h"
22 #include "Player.h"
23 #include "Sound.h"
24 #include "PlayerSelectView.h"
25 #include "PlayerSelectView2D.h"
26 #include "Event.h"
27 #include "RCFile.h"
28 
29 extern RCFile *theRC;
30 
31 extern long mode;
32 
33 extern bool isComm;
34 
35 extern long wins;
36 
PlayerSelect()37 PlayerSelect::PlayerSelect() {
38   m_rotate = 0;
39   m_View = NULL;
40   m_selected = 0;
41 }
42 
~PlayerSelect()43 PlayerSelect::~PlayerSelect() {
44   if ( m_View ){
45     BaseView::TheView()->RemoveView( m_View );
46     delete m_View;
47   }
48 }
49 
50 bool
Init()51 PlayerSelect::Init() {
52   m_View = (PlayerSelectView *)View::CreateView( VIEW_PLAYERSELECT );
53 
54   m_View->Init( this );
55 
56   BaseView::TheView()->AddView( m_View );
57 
58   return true;
59 }
60 
61 void
Create()62 PlayerSelect::Create() {
63   Control::ClearControl();
64 
65   m_theControl = new PlayerSelect();
66   m_theControl->Init();
67 
68   SDL_ShowCursor(SDL_DISABLE);
69 }
70 
71 bool
Move(SDL_keysym * KeyHistory,long * MouseXHistory,long * MouseYHistory,unsigned long * MouseBHistory,int Histptr)72 PlayerSelect::Move( SDL_keysym *KeyHistory, long *MouseXHistory,
73 		    long *MouseYHistory, unsigned long *MouseBHistory,
74 		    int Histptr ) {
75   static long lastRotate = 0;
76   static long nothing = 0;
77 
78   // Next opponent
79   if ( wins > 0 && m_selected == 0 ) {
80     m_selected = 1;
81     m_rotate = (m_thePlayer->GetPlayerType()-1)*(360/PLAYERS);
82     return true;
83   }
84 
85   if ( (KeyHistory[Histptr].unicode == SDLK_ESCAPE ||
86 	KeyHistory[Histptr].unicode == 'Q') && !isComm ) {
87     mode = MODE_TITLE;
88     wins = 0;
89     return true;
90   }
91 
92   if ( m_selected > 500 ) {
93     if (isComm)
94       mode = MODE_MULTIPLAY;
95     else
96       mode = MODE_SOLOPLAY;
97     return true;
98   }
99 
100   if ( MouseBHistory[Histptr]&BUTTON_LEFT &&
101        ( (Histptr > 0 && !(MouseBHistory[Histptr-1]&BUTTON_LEFT)) ||
102 	 (Histptr == 0 && !(MouseBHistory[MAX_HISTORY]&BUTTON_LEFT)) ) ){
103     nothing = 0;
104     if ( m_selected == 0 ) {
105       m_selected = 1;
106       Sound::TheSound()->Play( SOUND_CLICK, 0, 0 );
107     } else if ( m_selected > 100 ) {
108       if (isComm)
109 	mode = MODE_MULTIPLAY;
110       else
111 	mode = MODE_SOLOPLAY;
112       return true;
113     }
114   }
115 
116   if ( m_selected > 0 ) {
117     m_selected++;
118     return true;
119   }
120 
121   if ( lastRotate == 0 ) {
122     if ( MouseXHistory[Histptr] - BaseView::GetWinWidth()/2 > 10 ) {
123       nothing = 0;
124       lastRotate = 2;
125     } else if ( MouseXHistory[Histptr] - BaseView::GetWinWidth()/2 < -10 ) {
126       nothing = 0;
127       lastRotate = -2;
128     } else
129       nothing++;
130 
131     if ( lastRotate != 0 ) {
132       m_rotate += lastRotate;
133       if ( m_rotate < 0 )
134 	m_rotate += 360;
135       else
136 	m_rotate %= 360;
137     }
138   } else {
139     long nextRotate = m_rotate + lastRotate;
140 
141     if ( nextRotate < 0 )
142       nextRotate += 360;
143     else
144       nextRotate %= 360;
145 
146     if ( m_rotate/(360/PLAYERS) != nextRotate/(360/PLAYERS) ) {
147       m_rotate = (nextRotate+360/PLAYERS/2)/(360/PLAYERS)*(360/PLAYERS);
148       lastRotate = 0;
149       Sound::TheSound()->Play( SOUND_CLICK, 0, 0 );
150     } else
151       m_rotate = nextRotate;
152   }
153 
154   if ( nothing > 1000 && !isComm ) {
155     nothing = 0;
156     //mode = MODE_DEMO;
157     mode = MODE_TITLE;
158   }
159 
160   if ( nothing != 0 )
161     return false;
162   else
163     return true;
164 }
165 
166 long
GetPlayerNum()167 PlayerSelect::GetPlayerNum() {
168   if ( GetRotate() < 0 )
169     return (360+(GetRotate()%360))/(360/PLAYERS);
170   else
171     return (GetRotate()%360)/(360/PLAYERS);
172 }
173 
174 long
GetOpponentNum()175 PlayerSelect::GetOpponentNum() {
176   return (GetPlayerNum()+wins+1)%PLAYERS;
177 }
178 
179 bool
LookAt(double & srcX,double & srcY,double & srcZ,double & destX,double & destY,double & destZ)180 PlayerSelect::LookAt( double &srcX, double &srcY, double &srcZ,
181 		      double &destX, double &destY, double &destZ ) {
182   srcX = 0.0;
183   srcY = -TABLELENGTH-1.2;
184   srcZ = 1.4;
185 
186   return true;
187 }
188