Fixed sprite creation.
[tagua/yd.git] / src / entities / userentity.h
blob40e96ae62c4d671ecee3a1d169823accce66c65c
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
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 */
11 #ifndef USERENTITY_H
12 #define USERENTITY_H
14 #ifndef GAMEBASEDRULES_H
15 #define GAMEBASEDRULES_H
17 #include "entity.h"
18 #include "fwd.h"
19 #include "kboard.h"
20 #include "usermove.h"
21 #include "agent.h"
23 class PGN;
25 class TurnTest {
26 public:
27 virtual ~TurnTest() { }
28 virtual bool operator()(int turn) const = 0;
31 class FreeTurnTest : public TurnTest {
32 public:
33 virtual bool operator()(int) const { return true; }
36 class NoTurnTest : public TurnTest {
37 public:
38 virtual bool operator()(int) const { return false; }
41 class OneTurnTest : public TurnTest {
42 int m_turn;
43 public:
44 OneTurnTest(int turn)
45 : m_turn(turn) { }
46 virtual bool operator()(int turn) const {
47 return turn == m_turn;
51 class UserEntity : public Entity
52 , public Agent {
53 protected:
54 boost::shared_ptr<TurnTest> m_turn_test;
55 bool m_editing_tools;
56 int m_promotion;
57 public:
58 UserEntity(const GamePtr& game, int);
59 virtual void setTurnTest(const boost::shared_ptr<TurnTest>& test) { m_turn_test = test; }
60 virtual void enableEditingTools(bool value);
62 // promotion
63 void changePromotionType(int type) { m_promotion = type; }
64 void setPromotion(NormalUserMove& move) { move.promotionType = m_promotion; }
65 int promotionType() const { return m_promotion; }
67 /**
68 * Return a PGN for the game.
70 virtual QString save() const = 0;
72 /**
73 * Load the content of a PGN inside the game.
75 virtual void loadPGN(const PGN& pgn) = 0;
77 virtual AbstractMove::Ptr testMove(const NormalUserMove& m) const = 0;
78 virtual AbstractMove::Ptr testMove(const DropUserMove& m) const = 0;
79 virtual bool testPremove(const NormalUserMove& m) const = 0;
80 virtual bool testPremove(const DropUserMove&) const = 0;
81 virtual void executeMove(AbstractMove::Ptr move) = 0;
82 virtual void addPremove(const NormalUserMove& m) = 0;
83 virtual void addPremove(const DropUserMove& m) = 0;
84 virtual void cancelPremove() = 0;
85 virtual void handleRightClick(const Point&) const;
87 virtual InteractionType validTurn(const Point&) const = 0;
88 virtual InteractionType validTurn(int) const = 0;
89 virtual bool movable(const Point&) const = 0;
90 virtual bool oneClickMoves() const { return false; }
92 /**
93 * Jump to the end of the game.
95 virtual bool gotoFirst() = 0;
97 /**
98 * Jump to the beginning of the game.
100 virtual bool gotoLast() = 0;
103 * Jump to an arbitrary index.
105 virtual bool goTo(const Index& index) = 0;
108 * Go forward one move in the game.
110 virtual bool forward() = 0;
113 * Go back one move in the game.
115 virtual bool back() = 0;
118 * Undo the last editing action.
120 virtual bool undo() = 0;
123 * Redo the last editing action.
125 virtual bool redo() = 0;
128 * Remove the current position.
130 virtual bool truncate() = 0;
133 * Promote the current variation to mainline.
135 virtual bool promoteVariation() = 0;
138 * Move hint.
139 * @sa AbstractPosition::moveHint
141 virtual AbstractPiece::Ptr moveHint(AbstractMove::Ptr) const { return AbstractPiece::Ptr(); }
143 virtual bool canDetach() const;
147 #endif // GAMEBASEDRULES_H
150 #endif // USERENTITY_H