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"
19 #include "unwrapped_graphicalapi.h"
20 #include "animation.h"
22 using namespace boost
;
23 typedef boost::shared_ptr
<class Animation
> AnimationPtr
;
25 const char *ChessVariant::m_name
= "Chess";
26 const char *ChessVariant::m_theme_proxy
= "Chess";
27 VariantInfo
* ChessVariant::static_chess_variant
= 0;
33 typedef UnwrappedGraphicalAPI
<ChessVariant
> ChessGraphicalAPI
;
36 ChessGraphicalAPI
* m_cinterface
;
38 ChessAnimator(ChessGraphicalAPI
* cinterface
)
39 : m_cinterface(cinterface
) {
42 AnimationPtr
warp(const ChessPosition
* final
) {
43 const ChessPosition
* current
= m_cinterface
->position();
44 boost::shared_ptr
<AnimationGroup
> res(new AnimationGroup
);
46 for (Point i
= current
->first(); i
<= current
->last(); i
= current
->next(i
)) {
47 const ChessPiece
* c
= current
->get(i
);
48 const ChessPiece
* f
= final
->get(i
);
52 SpritePtr sprite
= m_cinterface
->setSprite(i
, *f
, false, false);
53 res
->addPreAnimation( shared_ptr
<DropAnimation
>(new DropAnimation(sprite
)) );
56 //current->set(i, NULL);
57 SpritePtr old_sprite
= m_cinterface
->getSprite(i
);
58 res
->addPreAnimation( shared_ptr
<CaptureAnimation
>(new CaptureAnimation(old_sprite
)) );
60 else if(c
&& !c
->equals(f
) ) {
62 SpritePtr old_sprite
= m_cinterface
->takeSprite(i
);
63 SpritePtr sprite
= m_cinterface
->setSprite(i
, *f
, false, false);
64 res
->addPreAnimation( shared_ptr
<PromotionAnimation
>(new PromotionAnimation(old_sprite
, sprite
)) );
68 //TODO: implement pool update
78 void ChessVariant::forallPieces(PieceFunction
& f
) {
93 VariantInfo
* ChessVariant::info() {
94 if (!static_chess_variant
)
95 static_chess_variant
= new WrappedVariantInfo
<ChessVariant
>;
96 return static_chess_variant
;