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.
12 #include <boost/shared_ptr.hpp>
13 #include "variants/chess.h"
15 #include "highlevel.h"
16 #include "moveserializer.impl.h"
17 #include "xchess/animator.impl.h"
18 #include "piecefunction.h"
20 using namespace boost
;
22 const char *ChessVariant::m_name
= "Chess";
23 const char *ChessVariant::m_theme_proxy
= "Chess";
24 VariantInfo
* ChessVariant::static_chess_variant
= 0;
26 class ChessAnimator
: public SimpleAnimator
<ChessVariant
> {
28 ChessAnimator(PointConverter
* converter
,
29 const shared_ptr
<GPosition
>& position
)
30 : SimpleAnimator
<ChessVariant
>(converter
, position
) { }
32 shared_ptr
<MovementAnimation
>
33 createMovementAnimation(const GElement
& element
, const QPoint
& destination
) {
34 if (element
.piece().type() == KNIGHT
) {
35 return shared_ptr
<MovementAnimation
>(
36 new KnightMovementAnimation(element
.sprite(),
37 destination
, m_anim_rotate
));
40 return shared_ptr
<MovementAnimation
>(
41 new MovementAnimation(element
.sprite(),
51 typedef UnwrappedGraphicalAPI
<ChessVariant
> ChessGraphicalAPI
;
54 ChessGraphicalAPI
* m_cinterface
;
56 ChessAnimator(ChessGraphicalAPI
* cinterface
)
57 : m_cinterface(cinterface
) {
60 AnimationPtr
warp(const ChessPosition
* final
) {
61 const ChessPosition
* current
= m_cinterface
->position();
62 AnimationPtr
res(new AnimationGroup
);
64 for (Point i
= m_current
->first(); i
<= m_position
->last(); i
= m_position
->next(i
)) {
65 ChessPiece
* c
= current
->get(i
);
66 ChessPiece
* f
= final
->get(i
);
70 PieceSpritePtr sprite
= m_cinterface
->setSprite(i
, *f
, false, false);
71 res
->addPreAnimation( shared_ptr
<DropAnimation
>(new DropAnimation(sprite
)) );
74 //current->set(i, shared_ptr<ChessPiece>());
75 PieceSpritePtr old_sprite
= m_cinterface
->getSprite(i
);
76 res
->addPreAnimation( shared_ptr
<CaptureAnimation
>(new CaptureAnimation(sprite
)) );
78 else if(!c
.equals(f
) ) {
80 PieceSpritePtr old_sprite
= m_cinterface
->takeSprite(i
);
81 res
->addPreAnimation( shared_ptr
<PromotionProAnimation
>(new PromotionAnimation(sprite
)) );
86 //TODO: implement pool update
93 typedef UnwrappedGraphicalAPI
<ChessVariant
> ChessGraphicalAPI
;
96 ChessGraphicalAPI
* m_cinterface
;
98 ChessAnimator(ChessGraphicalAPI
* cinterface
)
99 : m_cinterface(cinterface
) {
102 AnimationPtr
warp(ChessPosition
* final
) {
103 ChessPosition
* current
= m_cinterface
->position();
104 AnimationPtr
res(new AnimationGroup
);
106 for (Point i
= m_current
->first(); i
<= m_position
->last(); i
= m_position
->next(i
)) {
107 ChessPiece
* c
= current
->get(i
);
108 ChessPiece
* f
= final
->get(i
);
112 PieceSpritePtr sprite
= m_cinterface
->setSprite(i
, *f
, false, false);
113 res
->addPreAnimation( shared_ptr
<DropAnimation
>(new DropAnimation(sprite
)) );
116 current
->set(i
, shared_ptr
<ChessPiece
>());
117 PieceSpritePtr old_sprite
= m_cinterface
->getSprite(i
);
118 res
->addPreAnimation( shared_ptr
<CaptureAnimation
>(new CaptureAnimation(sprite
)) );
120 else if(!c
.equals(f
) ) {
122 PieceSpritePtr old_sprite
= m_cinterface
->takeSprite(i
);
123 res
->addPreAnimation( shared_ptr
<PromotionProAnimation
>(new PromotionAnimation(sprite
)) );
135 void ChessVariant::forallPieces(PieceFunction
& f
) {
150 VariantInfo
* ChessVariant::info() {
151 if (!static_chess_variant
)
152 static_chess_variant
= new WrappedVariantInfo
<ChessVariant
>;
153 return static_chess_variant
;