summaryrefslogtreecommitdiffstats
path: root/kue/localplayer.cpp
blob: 51b157b3ffe9f2c80abda064972eb61663ee992b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <tdeapplication.h>
#include <kdebug.h>
#include <tqtimer.h>

#include "localplayer.h"
#include "global.h"
#include "interface.h"
#include "physics.h"


KueLocalPlayer::KueLocalPlayer(TQString n, TQColor color) : KuePlayer(n), _dest(0)
{
	_color = color;
}

// Rules' functions
void KueLocalPlayer::placeBilliard(int index, const KueBilliard &b, double line, TQObject *dest, const char *dest_slot)
{
	_dest = dest;
	_dest_slot = dest_slot;

	connect(KueGlobal::glWidget(), TQ_SIGNAL(billiardPlaced(point &)), this, TQ_SLOT(billiardPlaced(point &)));
	connect(KueGlobal::glWidget(), TQ_SIGNAL(previewBilliardPlace(point &)), this, TQ_SLOT(previewBilliardPlace(point &)));

	_index = index;
	// We use the passed billiard as a template, and just move it around
	KueGlobal::physics()->insertBilliard(index, b);

	KueGlobal::glWidget()->placeBilliard(line);
}

void KueLocalPlayer::takeShot(int index, bool forward_only, TQObject *dest, const char *dest_slot)
{
	_dest = dest;
	_dest_slot = dest_slot;

	connect(KueGlobal::glWidget(), TQ_SIGNAL(shotTaken(vector &)), this, TQ_SLOT(shotTaken(vector &)));

	_index = index;
	KueGlobal::glWidget()->startShot(*KueGlobal::physics()->billiards()[index], _color, forward_only);
}

// Called by the interface when the user has decided on a cue location
void KueLocalPlayer::billiardPlaced(point &location)
{
	KueGlobal::physics()->billiards()[_index]->setPosition(location);
	KueGlobal::physics()->run(0);

	disconnect();
	callBack();
}

// Called by the interface when the user is deciding on a cue location
void KueLocalPlayer::previewBilliardPlace(point &location)
{
	 // Inform the physics engine
	KueGlobal::physics()->billiards()[_index]->setPosition(location);

	// Redraw
	KueGlobal::glWidget()->updateGL();
}

void KueLocalPlayer::shotTaken(vector &velocity)
{
	KueGlobal::physics()->billiards()[_index]->setVelocity(velocity);

	disconnect();
	callBack();
}

void KueLocalPlayer::callBack()
{
	// Call the completion callback
	if (_dest)
	{
		TQTimer::singleShot(0, _dest, _dest_slot);
		_dest = 0;
	}
}


#include "localplayer.moc"