musicmud-2.1.6/data/
musicmud-2.1.6/data/help/
musicmud-2.1.6/data/policy/
musicmud-2.1.6/data/wild/
musicmud-2.1.6/data/world/
musicmud-2.1.6/doc/
musicmud-2.1.6/src/ident/
musicmud-2.1.6/src/lua/
musicmud-2.1.6/src/lua/include/
musicmud-2.1.6/src/lua/src/lib/
musicmud-2.1.6/src/lua/src/lua/
musicmud-2.1.6/src/lua/src/luac/
#ifndef PLAYER_H
#define PLAYER_H

#include <list>

#include "commandhandler.h"

namespace msi {
  class player;
};

class State;
class PersonState;

//! the physical manifestation of a player
class Player : public MudObject, commandhandler {

  //! the output buffer. (after colourisation, wordwrap, etc)
  string buffer;

  //! the stack of states
  PersonState *state;

  //! last time this player did anything
  time_t idle_since;
  
  //! the speculative buffer
  string spec_buffer;

  string get_prompt2() const;
  string get_prompt3() const;
  
 public:

  //! linkdead buffer
  string seenbuffer;
  
  //! the last command entered by this player
  string previous;

  //! list of commands that have been delayed and need executing.
  list<string> todo;

  //! how long the player has been on?
  time_t on_since;

  //! time since last save
  time_t time_since;
  
  //! whether the player needs a prompt sending to them
  int need_prompt, had_prompt;

  //! the telnet stack associated with this player
  msi::player *p;

  //! the current column of the remote terminal.
  int curcol;
 public:
  //! create a new player
  Player(const char *id, msi::player *p);

  //! push state
  void push_state(PersonState *);
  //! create and push state
  void push_state(const char *);

  //! change the state on the top to this one
  void set_state(PersonState *);
  //! change the state on the top to this one
  void set_state(const char *);

  //! remove the state from the top of the stack
  void pop_state();

  //! obtain the state pointed to by the stack
  State *get_state() const;

  //! obtain the personstate at the top of the stack
  PersonState *get_person_state() { return state; }

  //! output stuff
  virtual void real_printf(const char *what, const PARMS &p, MudObject *b=0, int snoop=0);

  //! flush cache to the telnet stack
  virtual void send_data() {
    send_data(0, -1);
  }
  //! flush cache to the telnet stack, but with some extra stuff
  virtual void send_data(const char *prompt, int);
  
  virtual void push_data();

  //! page file
  virtual bool spewfile(const char *,const char *,bool=true, const char* ="");

  //! speculatively print. This will be confirmed the next time anything gets really printed to the player. Until then it can be cancelled
  virtual void real_spec_printf(const char *fmt, const PARMS &p);

  //! cancel speculative print
  virtual bool cancel_printf();

  //! poll for events
  virtual void execute();
  
  //! poll for io
  void tryio(bool);
  
  virtual void set(const char*, const char *);
  virtual void set(const char*a , int b) { MudObject::set(a, b); }
  virtual void set(const char*a , string b) { set(a, b.c_str()); }
  
  /* accessor */
  string get_prompt() const;

  time_t &get_idle() {
    return idle_since;
  }
 
  time_t get_idle() const {
    return idle_since;
  }
  
  void handle_input(const char *str);
  
  void input(const char *str);
  void size_changed();
  void username(const char *str);

  /* destruction */
  virtual ~Player();
};

void state_init();

#define is_player(who) (dynamic_cast<const Player *>(who)!=0)

static inline bool linkdead(const MudObject *who) {
  if (const Player *p=((dynamic_cast<const Player*>(who)))) {
    return p->p==0;
  }
  return false;
}

extern World<Player> *players;

#endif