/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   This program is free software; you can redistribute it and/or 
 *   modify it under the terms of the GNU General Public License as 
 *   published by the Free Software Foundation; either version 2 of 
 *   the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details. 
 *   You can find this license in the file 'gpl.txt'.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *   MA  02111-1307  USA
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 *********************************************************************/

#include "constants.h"

#ifdef USE_UI_GTK

#include "table.h"
#include "gtk_gui.h"

#include "../../party/party.h"
#include "../../party/rule.h"
#include "../../game/game.h"

namespace GTK_DOKO {

  /**
   *
   * constructor
   *
   * @param	table	the table this group belongs to
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBaseGroup::HTINBaseGroup(Table* table) :
    table_p(table),
  object_p()
  {
    DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_INIT,
		  "HTINBaseGroup::HTINBaseGroup()");

    this->object_p.reserve(::party.rule()(Rule::NUMBER_OF_PLAYERS));

    DEBUG_RETURNING(VOID,
		    INFO_GTK_HTIN && INFO_GTK_INIT,
		    "HTINBaseGroup::HTINBaseGroup()");
  } // HTINBaseGroup::HTINBaseGroup()

  /**
   *
   * destructor
   *
   * @param	-
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBaseGroup::~HTINBaseGroup()
  {
    DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_INIT,
		  "HTINBaseGroup::~HTINBaseGroup()");

    for (vector<HTINBase*>::iterator object = this->object_p.begin();
	 object != this->object_p.end();
	 object++)
      delete (*object);

    DEBUG_RETURNING(VOID,
		    INFO_GTK_HTIN && INFO_GTK_INIT,
		    "HTINBaseGroup::~HTINBaseGroup()");
  } // HTINBaseGroup::HTINBaseGroup()

  /**
   *
   * nothing to do
   *
   * @param	-
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  void
    HTINBaseGroup::init()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_INIT,
		    "HTINBaseGroup::init()");

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_INIT,
		      "HTINBaseGroup::init()");
    } // void HTINBaseGroup::init()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the gui
   *
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  GTK_GUI&
    HTINBaseGroup::gui()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBaseGroup::gui()");

      DEBUG_RETURNING(this->table().gui(),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBaseGroup::gui()");
    } // GTK_GUI& HTINBaseGroup::gui()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the table
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  Table&
    HTINBaseGroup::table()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBaseGroup::table()");

      DEBUG_ASSERTION((this->table_p != NULL),
		      "HTINBaseGroup::table()\n"
		      "  `table_p` == NULL");

      DEBUG_RETURNING(*(this->table_p),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBaseGroup::table()");
    } // Table& HTINBaseGroup::table()

  /**
   *
   * -> result
   *
   * @param	player	the player, whose object is returned
   *
   * @return	the object of the given player
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBase&
    HTINBaseGroup::object(Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBaseGroup::object(player)");

      DEBUG_ASSERTION((player.no() < this->object_p.size()),
		      "HTINBaseGroup::object(player):\n"
		      "  number of 'player' (" << player.no() << "too great");

      DEBUG_RETURNING(*(this->object_p[player.no()]),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBaseGroup::object(player)");
    } // HTINBase& HTINBaseGroup::object(Player const& player)

  /**
   *
   * a game is opened
   *
   * @param	game	the game
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   * @todo	use iterator
   *
   */
  void
    HTINBaseGroup::game_open(Game const& game)
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_DRAW,
		    "HTINBaseGroup::game_open()");

#ifdef POSTPHONED
      vector<Player*>::const_iterator player = ::party.game().player_begin();
      for(vector<HTINBase*>::iterator object = this->object_p.begin();
	  object != this->object_p.begin();
	  object++, player++)
	(*object)->player_p = *player;
#else
      for (unsigned p = 0; p < ::party.game().playerno(); p++)
	this->object_p[p]->player_p
	  = &(const_cast<Game const&>(::party.game()).player(p));
#endif

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_DRAW,
		      "HTINBaseGroup::game_open()");
    } // void HTINBaseGroup::game_open(Game const& game)

  /**
   *
   * a game is closed
   *
   * @param	game	the game
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  void
    HTINBaseGroup::game_close(Game const& game)
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_DRAW,
		    "HTINBaseGroup::game_close(game)");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::game_close(game)");

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_DRAW,
		      "HTINBaseGroup::game_close(game)");
    } // void HTINBaseGroup::game_close(Game const& game)

  /**
   *
   * draws the objects
   *
   * @param	update	whether the hands should be updated
   *			(default: true)
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  void
    HTINBaseGroup::draw(bool const update)
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_DRAW,
		    "HTINBaseGroup::draw(update)");

      if (::game_status & GAMESTATUS::GAME)
	for(vector<Player*>::const_iterator player = ::party.game().player_begin();
	    player != ::party.game().player_end();
	    player++)
	  this->object(**player).draw(update);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_DRAW,
		      "HTINBaseGroup::draw(update)");
    } // void HTINBaseGroup::draw(update)

  /**
   *
   * nothing to do
   *
   * @param	-
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  void
    HTINBaseGroup::language_update()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_UPDATE,
		    "HTINBaseGroup::language_update()");

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_UPDATE,
		      "HTINBaseGroup::language_update()");
    } // void HTINBaseGroup::language_update()


  /**
   *
   * constructor
   *
   * @param	group	the hands
   * @param	player	the player, this hand belongs to
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBase::HTINBase(HTINBaseGroup* group, Player const& player) :
    group_p(group),
  player_p(&player)
  {
    DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_INIT,
		  "HTINBase::HTINBase(group, player)");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_HTIN && INFO_GTK_INIT,
		    "HTINBase::HTINBase(group, player)");
  } // HTINBase::HTINBase(HTINBaseGroup* group, Player const& player)

  /**
   *
   * destructor
   *
   * @param	-
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBase::~HTINBase()
  {
    DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_INIT,
		  "HTINBase::~HTINBase()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_HTIN && INFO_GTK_INIT,
		    "HTINBase::~HTINBase()");
  } // HTINBase::~HTINBase()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the gui
   *
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  GTK_GUI&
    HTINBase::gui()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::gui()");

      DEBUG_RETURNING(this->group().gui(),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::gui()");
    } // GTK_GUI& HTINBase::gui()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the group, this object belongs to
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  HTINBaseGroup&
    HTINBase::group()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::hands()");

      DEBUG_ASSERTION((this->group_p != NULL),
		      "HTINBase::group()\n"
		      "  'group_p == NULL'");

      DEBUG_RETURNING(*(this->group_p),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::group()");
    } // HTINBaseGroup& HTINBase::group()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the player, this object belongs to
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  Player const&
    HTINBase::player() const
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::player()");

      DEBUG_RETURNING(*(this->player_p),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::player()");
    } // Player const& HTINBase::player() const

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the corresponding hand
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  Handg&
    HTINBase::hand()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::hand()");

      DEBUG_RETURNING(this->group().table().hand(this->player()),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::hand()");
    } // Handg& HTINBase::hand()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the corresponding trickpile
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  TrickPile&
    HTINBase::trickpile()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::trickpile()");

      DEBUG_RETURNING(this->group().table().trickpile(this->player()),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::trickpile()");
    } // TrickPile& HTINBase::trickpile()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the corresponding icongroup
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  IconGroup&
    HTINBase::icongroup()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::icongroup()");

      DEBUG_RETURNING(this->group().table().icongroup(this->player()),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::icongroup()");
    } // IconGroup& HTINBase::icongroup()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the corresponding name
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  Name&
    HTINBase::name()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::name()");

      DEBUG_RETURNING(this->group().table().name(this->player()),
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::name()");
    } // Name& HTINBase::name()


  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	starting-x-position
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  int
    HTINBase::start_x()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::start_x()");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::start_x()");

      DEBUG_RETURNING(0,
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::start_x()");
    } // HTINBase::start_x()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	starting y position
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  int
    HTINBase::start_y()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::start_y()");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::start_y()");

      DEBUG_RETURNING(0,
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::start_y()");
    } // HTINBase::start_y()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the width
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  unsigned
    HTINBase::width()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::width()");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::width()");

      DEBUG_RETURNING(0,
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::width()");
    } // unsigned HTINBase::width()

  /**
   *
   * -> result
   *
   * @param	-
   *
   * @return	the height
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  unsigned
    HTINBase::height()
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_VALUE,
		    "HTINBase::height()");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::height()");

      DEBUG_RETURNING(0,
		      INFO_GTK_HTIN && INFO_GTK_VALUE,
		      "HTINBase::height()");
    } // unsigned HTINBase::height()

  /**
   *
   * draws the object
   *
   * @param	update	whether the hand should be updated
   *		(default: true)
   *
   * @return	-
   * 
   * @version	0.4.4
   *
   * @author	Diether Knof
   *
   */
  void
    HTINBase::draw(bool const update)
    {
      DEBUG_CALLING(INFO_GTK_HTIN && INFO_GTK_DRAW,
		    "HTINBase::draw(update)");

      DEBUG_ASSERTION(false,
		      "call of HTINBase::draw(update)");

      DEBUG_RETURNING(VOID,
		      INFO_GTK_HTIN && INFO_GTK_DRAW,
		      "HTINBase::draw(update)");
    } // int HTINBase::draw(update)

} // namespace GTK_DOKO
#endif // #ifdef USE_UI_GTK
