State.h

musicmud-2.1.6/include/State.h · 985 B

From the archive musicmud2.1.6.tar.gz

Download the archive   « Back to the archive contents

#ifndef STATE_H
#define STATE_H

#include "Player.h"

typedef void (*state_t)(Player *, const char *);

extern MudObject *qui;

//! A state that a player can be in
class State : public Object {
  const char *prompt;
  state_t fn;
  bool need_lf;
 public:
  State(const char *id, const char *prompt, state_t fn, bool needcr=false) 
    : Object(id), prompt(prompt), fn(fn), need_lf(needcr) {
  }
  void invoke(Player *who, const char *what) const {
    MudObject *wh = qui;
    qui = who;
    if (need_lf) 
      who->printf("\n");
    fn(who, what);
    qui = wh;
  }
  const char *get_prompt() const {
    return prompt;
  }
  bool needs_noecho() const {
    return need_lf;
  }
};

// #define ADD_STATE(a, b, c) states->add(*(new State(a, b, c)))

extern World<State> *states;

//! an item on the stack of states for each player
class PersonState : public base {
 public:
	PersonState *previous;
	PersonState(const char *state) {
		previous = 0;
		set("state", state);
	}
};

#endif

Site Stats

Snippets: 1791
Codebases: 571