/*

 BabbleMud - A MUD server

 Author:  Nick Gammon 
          http://www.gammon.com.au/ 

(C) Copyright Nick Gammon 2004. Permission to copy, use, modify, sell and
distribute this software is granted provided this copyright notice appears
in all copies. This software is provided "as is" without express or implied
warranty, and with no claim as to its suitability for any purpose.
 
*/

#include "commands.h"

// basic commands 

//~ attributes used:


//~ PLAYER (number):
  
const string ROOM = "room";     // current room

// quit

void DoQuit (CommandInfo & info)
  {
  info.player ().ClosePlayer ();
  } // end of DoQuit

// save player file

void DoSave  (CommandInfo & info)
{
 info.player ().Save (); 
}

void PlayerToRoom (Character & p,     // which player
                   const int & vnum,  // which room
                   CommandInfo & info)  // for messages
{

  World & target = FindRoom (vnum);    // check room exists

  p.send (p.prefix () + "depart_self", info.command_.get_sdata (), info.sub_); // tell us we did it

  //~ p << FixMessage (info.command_.gets ("depart_self"), info); // departure message
 
  // message to everyone else in the current room TODO fix this
  SendToAll ("depart_room", info.command_.get_sdata (), info.sub_, &p, NULL, p.geti (ROOM));
  
  p.seti (ROOM, vnum);  // move to new room
  
  // do a "look" *after* seeing any arrival messages
  info.command_.setb ("do_look", true);

} // end of PlayerToRoom

// go somewhere (take an exit)

void DoDirection (CommandInfo & info)
  {
  PlayerToRoom (info.player (), info.command_.geti ("target"), info);
  } // end of DoDirection
 

static int LoadCommandsMap ()
  {
static CommandHandlerMap & commandmap = getCommandHandlerMap ();

  cout << "Loading command handlers in " __FILE__ << endl;
    
  COMMAND (DoQuit);      // bye bye
  COMMAND (DoSave);      // save a player
  COMMAND (DoDirection); // take an exit

  return 0;
  } // end of LoadCommands

static int loadThemUp = LoadCommandsMap ();

