verbmodule.h
musicmud-2.1.6/src/extras/verbmodule.h · 3.7 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD Daemon, version 0.5.9
* Copyright (C) 1998 Abigail Brady
*
* 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 should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdio.h>
#ifndef MODULE
#error "You must define MODULE before including verbmodule.h"
#endif
#ifdef VERBS_H
World<Verb> *native_verbs;
#endif
#ifdef STATE_H
World<State> *native_states;
#endif
#ifdef VERB_H
Verb *get_verb(const char *);
#endif
#ifdef VERBS_H
void verb_add(const char *id, int minlen, int minlev, verbhandler_t fn, PFlag pflag, VFlag vflags=VFL_NONE) {
if (Verb *o = verbs->get(id)) {
log(PFL_SEEINFO, 0, "verbs", "verb conflict : %s.%s with %s.%s",
MODULE, id, o->get("module"), o->id);
return;
}
string name(id, minlen);
if (Verb *v=get_verb(name.c_str())) {
log(PFL_SEEINFO, 0, "verbs", "verb conflict : [%s.%s] [%s.%s]",
MODULE, id, v->get("module"), v->id);
}
Verb *me = new NativeVerb(id, minlen, minlev, fn, pflag, vflags);
verbs->add (me);
native_verbs->add (me);
me->set("module", MODULE);
}
void verb_add(const char *id, int minlen, int minlev, playerverb_t fn, PFlag pflag, VFlag vflags=VFL_NONE) {
if (Verb *o = verbs->get(id)) {
log(PFL_SEEINFO, 0, "verbs", "verb conflict : %s.%s with %s.%s",
MODULE, id, o->get("module"), o->id);
return;
}
string name(id, minlen);
if (Verb *v=get_verb(name.c_str())) {
log(PFL_SEEINFO, 0, "verbs", "verb conflict : [%s.%s] [%s.%s]",
MODULE, id, v->get("module"), v->id);
}
Verb *me = new PlayerVerb(id, minlen, minlev, fn, pflag, vflags);
verbs->add (me);
native_verbs->add (me);
me->set("module", MODULE);
}
void alias_add(const char *verbname, int minlen, const char *toname)
{
Verb *to=verbs->get(toname);
if (!to) {
log(PFL_SEEINFO, 0, "verbs", "alias for %s points to non-existant %s",
verbname, toname);
return;
}
AliasVerb *a = new AliasVerb(verbname, to);
verbs -> add (*a);
native_verbs->add (*a);
a->minlen = minlen;
a->set("module", MODULE);
}
#endif
#ifdef STATE_H
void state_add(const char *name, const char *prompt, state_t d, bool what) {
State *me = new State(name, prompt, d, what);
states -> add( *me );
native_states -> add ( *me );
}
#endif
extern "C" void remove_verbs() {
#ifdef CLEANUP
CLEANUP
#endif
#ifdef VERBS_H
for (int l=0;l<native_verbs->getsize();l++) {
Verb *o = native_verbs->get(l);
verbs-> remove( *o );
delete o;
}
#endif
#ifdef STATE_H
for (int l=0;l<native_states->getsize();l++) {
State *o = native_states->get(l);
states-> remove( *o );
delete o;
}
#endif
}
#define ADD_VERB(str, minlen, func, minlev, args...) verb_add(str, minlen, minlev, func, ## args);
#define AUTO_VERB(str, minlen, minlev, args...) verb_add(#str, minlen, minlev, verb##_##str, ## args)
#define ADD_STATE(id, prompt, fn, echo) state_add(id, prompt, fn, echo)
#define ADD_ALIAS(alias, len, real) alias_add(#alias, len, #real)
void startup();
extern "C" void register_verbs() {
#ifdef VERBS_H
native_verbs = new World<Verb>();
#endif
#ifdef STATE_H
native_states = new World<State>();
#endif
startup();
}