1 #ifndef _global_h
2 #	include "global.h"
3 #endif
4 
5 #ifndef _pool_h
6 #	include "pool.h"
7 #endif
8 #ifndef _pcon_h
9 #	include "pcon.h"
10 #endif
11 #ifndef _pocket_h
12 #	include "pocket.h"
13 #endif
14 #ifndef _wall_h
15 #	include "wall.h"
16 #endif
17 #ifndef _graph_h
18 #	include "graph.h"
19 #endif
20 #ifndef _mover_h
21 #	include "mover.h"
22 #endif
23 #ifndef _keeper_h
24 #	include "keeper.h"
25 #endif
26 
27 
28 //
29 // Voreinstellungen
30 //
31 
32 
33 const int  Pool::nPockets		= 6;
34 
35 
GetNormalBallSize()36 const Real & Pool::GetNormalBallSize() const {
37 	return BallRadius;
38 }
39 
InitArea(double wx,double wy)40 void Pool::InitArea( double wx, double wy ) {
41 	area_width  = wx;
42 	area_height = wy;
43 	if (area_width/2.>area_height)   area_height = area_width/2.;
44 	else                             area_width  = area_height*2.;
45 	area_off_x = (MaxX()-area_width)/2.;
46 	area_off_y = (MaxY()-PocketHeight-area_height)/2.;
47 }
48 
SelectTable(int col)49 int Pool::SelectTable( int col ) {
50 	col = Billard::SelectTable(col);
51 	pocket_col  = CreateColorMix( 0, table_line_col );
52 	return col;
53 }
54 
Pool(double wx,double wy)55 Pool::Pool(double wx, double wy) :
56 Billard(wx,wy+PocketHeight)
57 {
58 	InitArea(wx,wy);
59 	pcon = 0;
60 	for (int i=0;i<nPockets;i++) 		p[i] = 0;
61 
62 // SetMainBgColor( "SeaGreen" );		// GlobalBackground
63 	cue_col		= AddBallColor( "ivory" );
64 	pocket_col  = CreateColorMix( 0, table_line_col );
65 
66 	keeper = new LineKeeper(PocketHeight,PocketFrame,inner_cushion_col,table_col);
67 
68 	cue_in_pocket = 0;
69 }
70 
~Pool()71 Pool::~Pool() {
72 	if (pcon)		delete [] pcon;
73 	for (int i=0;i<6;i++)		if (p[i])	delete p[i];
74 }
75 
76 
InitTable(double rad)77 void Pool::InitTable( double rad ) {
78 	po = PocketRadius/sqrt(2);
79 //	po=0;
80 
81 	p[0] = new Pocket( PAreaOffX()+po,					 PAreaOffY()+po, PocketRadius );
82 	p[1] = new Pocket( PAreaOffX()+PAreaWidth()/2.,  PAreaOffY()+po, PocketRadius );
83 	p[2] = new Pocket( PAreaOffX()+PAreaWidth()-po, PAreaOffY()+po, PocketRadius );
84 	p[3] = new Pocket( PAreaOffX()+PAreaWidth()-po, PAreaOffY()+PAreaHeight()-po,
85 																				PocketRadius );
86 	p[4] = new Pocket( PAreaOffX()+PAreaWidth()/2.,	PAreaOffY()+PAreaHeight()-po,
87 																				PocketRadius );
88 	p[5] = new Pocket( PAreaOffX()+po,					PAreaOffY()+PAreaHeight()-po,
89 																				PocketRadius );
90 
91 	pcon = new PocketConnector[nPockets];
92 	pcon[0].Init( *p[0], EdgeAngle, *p[1],  MidAngle, InnerCushion-po, rad );
93 	pcon[1].Init( *p[1],  MidAngle, *p[2], EdgeAngle, InnerCushion-po, rad );
94 	pcon[2].Init( *p[2], EdgeAngle, *p[3], EdgeAngle, InnerCushion-po, rad );
95 	pcon[3].Init( *p[3], EdgeAngle, *p[4],  MidAngle, InnerCushion-po, rad );
96 	pcon[4].Init( *p[4],  MidAngle, *p[5], EdgeAngle, InnerCushion-po, rad );
97 	pcon[5].Init( *p[5], EdgeAngle, *p[0], EdgeAngle, InnerCushion-po, rad );
98 }
99 
100 
InitPlayground()101 void Pool::InitPlayground() {
102 	Billard::InitPlayground();
103 	BallRadius = m->GetActRadius();
104 
105 	InitTable();
106 }
107 
DrawBackground()108 void Pool::DrawBackground() const {
109 	Billard::DrawBackground();
110 
111 // Undraw middle marker
112 	SetBgColor( outer_cushion_col );
113 	double	outer = PAreaOffY()-TAreaOffY();
114 	int		i=4;
115 	DrawMarker( AreaOffX()+AreaWidth()*Real(i)/8., TAreaOffY()+outer/2.,
116 																		outer/8., outer/4. );
117 	DrawMarker( AreaOffX()+AreaWidth()*Real(i)/8., TAreaOffY()+TAreaHeight()-outer/2.,
118 																		outer/8., outer/4. );
119 
120 // Draw Pockets
121 	for (i=0;i<nPockets;i++) {
122 		SetBgColor( table_col );
123 		FillPoly(4, &pcon[i].w1->p1, &pcon[i].w2->p1,
124 						&pcon[(i+nPockets-1)%nPockets].w2->p2,
125 						&pcon[(i+nPockets-1)%nPockets].w3->p2 );
126 		SetBgColor(pocket_col);
127 		FillCircle( p[i]->P(), p[i]->R() );
128 	}
129 	for (i=0;i<nPockets;i++) {
130 		SetBgColor(inner_cushion_col);
131 		FillArc( pcon[i].b1->p, pcon[i].b1->r, pcon[i].b1->start, pcon[i].b1->angle );
132 		FillArc( pcon[i].b2->p, pcon[i].b2->r, pcon[i].b2->start, pcon[i].b2->angle );
133 		FillPoly(6,	&pcon[i].w1->p1, &pcon[i].w1->p2,
134 						&pcon[i].w2->p1, &pcon[i].w2->p2,
135 						&pcon[i].w3->p1, &pcon[i].w3->p2	);
136 	}
137 }
138 
139 
140 //////////////////////////////////////////////////////////////////////////////
141 
ResetGame()142 void Pool::ResetGame() {
143 	cueball->SetPV( cuedef );
144 	cue_in_pocket = 0;
145 	Billard::ResetGame();
146 }
147 
InPocket(Ball * b)148 void Pool::InPocket( Ball *b ) {
149 	Billard::InPocket(b);
150 	if (b==cueball)	cue_in_pocket = 1;
151 }
152 
AllBallsStopped()153 void Pool::AllBallsStopped() {
154 	Billard::AllBallsStopped();
155 	(void)IsSelectable(cueball);		// back on the table
156 }
157 
IsSelectable(Ball * b)158 int Pool::IsSelectable(Ball *b) {
159 	if (b==cueball) {
160 		if (cue_in_pocket) {
161 			Vec2	newpos;
162 
163 			b->FitsNextTo(cuedef,Vec2(-1.0,RealZero),&newpos);
164 			cue_in_pocket = 0;
165 			b->SetP(newpos);
166 			b->ChgV(Vec2Zero);
167 
168 			return 0;
169 		}
170 		else {
171 			return 1;
172 		}
173 	}
174 
175 	return Billard::IsSelectable(b);
176 }
177