Verb.cc
musicmud-2.1.6/src/Verb.cc · 2.0 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD Daemon, version 1.0
* Copyright (C) 1998-2003 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 <string.h>
#include <stdio.h>
#include "musicmud.h"
#include "pflags.h"
#include "util.h"
#include "verbs.h"
Verb::Verb(const char *id, int minlen, int privneeded, PFlag pflag, VFlag vflags)
: Object(id), minlen(minlen), privneeded(privneeded), pflag(pflag==-1?PFL_NONE:pflag), disabled(0),
vflags(vflags) {
}
bool Verb::matches(const char *what) const {
if (strlen(what) < minlen)
return false;
return strcasestr(id, what)==id;
}
bool Verb::has_privs(MudObject *who) const {
if (disabled)
return 0;
int pl = privs_of(who, -1);
if (pl==-1) return true;
bool has_needed_level = pl >= (int)privneeded;
bool has_needed_pflag = true;
if (pflag == PFL_NONE) {
/* yes */
} else if (pflag == PFL_AWAKE) {
// has_needed_pflag == !who->get_flag(FL_SLEEPING);
if (who->get_flag(FL_SLEEPING))
has_needed_pflag = 0;
} else {
has_needed_pflag = who->get_priv(pflag);
}
return has_needed_pflag && has_needed_level;
}
Verb *get_verb(const char *verbname) {
int i;
if (Verb *v = verbs->get(verbname))
return v->drill();
for (i=0;i<verbs->getsize();i++) {
Verb *v = verbs->get(i);
if (v->matches(verbname)) {
return v->drill();
}
}
return NULL;
}