Continued refactor work.
[tagua.git] / src / variants / chess.cpp
blob52379f3fd5abd3cb41fdeead7f25de8a5bb296d2
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 #include <QPainter>
12 #include <boost/shared_ptr.hpp>
13 #include "variants/chess.h"
14 #include "common.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;
31 //BEGIN Dream code
33 typedef UnwrappedGraphicalAPI<ChessVariant> ChessGraphicalAPI;
35 class ChessAnimator {
36 ChessGraphicalAPI* m_cinterface;
37 public:
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);
50 if( !c && f ) {
51 //current->set(i, f);
52 SpritePtr sprite = m_cinterface->setSprite(i, *f, false, false);
53 res->addPreAnimation( shared_ptr<DropAnimation>(new DropAnimation(sprite)) );
55 else if (c && !f) {
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) ) {
61 //current->set(i, 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
70 return res;
75 //END Dream code
78 void ChessVariant::forallPieces(PieceFunction& f) {
79 f(WHITE, KING);
80 f(WHITE, QUEEN);
81 f(WHITE, ROOK);
82 f(WHITE, BISHOP);
83 f(WHITE, KNIGHT);
84 f(WHITE, PAWN);
85 f(BLACK, KING);
86 f(BLACK, QUEEN);
87 f(BLACK, ROOK);
88 f(BLACK, BISHOP);
89 f(BLACK, KNIGHT);
90 f(BLACK, PAWN);
93 VariantInfo* ChessVariant::info() {
94 if (!static_chess_variant)
95 static_chess_variant = new WrappedVariantInfo<ChessVariant>;
96 return static_chess_variant;