mount.cc
musicmud-2.1.6/src/extras/mount.cc · 4.8 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD - mount code
* Copyright (C) 2001-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 "musicmud.h"
#include "verbs.h"
#include "misc.h"
#include "util.h"
#include "events.h"
#include "trap.h"
#include "pflags.h"
#include "match.h"
#define MODULE "mount"
NewWorld riders(MudObject *m)
{
NewWorld w;
if (mount(m->owner)==m)
w.add(m->owner);
MudObject *o;
int i;
foreach(m->owner->children, o, i)
if (mount(o)==m)
w.add(o);
return w;
}
static int riders_max(MudObject *what)
{
if (what->get_flag(FL_ONEPERSON))
return 1;
if (what->get_flag(FL_TWOPERSON))
return 2;
return what->get_int("mounters.max", 1);
}
static bool verb_mount(MudObject *who, int argc, const char **argv) {
MudObject *what = 0;
NewWorld whatg = match(who, argc-1, argv+1, NULL, LOOK_INV|LOOK_ROOM|IGNORE_EXITS);
if (whatg.getsize()>1) {
who->printf("You can only mount one thing at a time.\n");
return true;
}
if (whatg.getsize()) {
what = whatg.get_nth(0);
}
if (!what) {
who->printf("Mount what?\n");
return true;
}
if (!what->get_flag(FL_MOUNT)) {
who->printf("You can't mount %s.\n", is_mobile(what)?him_or_her(what):"that");
return true;
}
if (who->get_object(KEY_WIELD)==what) {
who->printf("You cannot mount something you are wielding.\n");
return true;
}
if (dotrap(E_BEFOREMOUNT, who, what))
/* ::: before_mount o1==potential mount; return 1 to abort */
return true;
NewWorld riders(riders(what));
if (riders.getsize()>riders_max(what)) {
const char *rv = what->get("riding_verb");
if (!rv) rv = "riding";
if (riders.getsize()>1)
who->printf("%#W are already %s %s.\n", riders, rv, him_or_her(what));
else
who->printf("%#Y %[is/are] already %s %s.\n", riders.get(0), rv, him_or_her(what));
return true;
}
const char *steponp = what->get("stepon_p");
const char *stepons = what->get("stepon_s");
if (what->get_flag(FL_MOBILE)) {
if (!steponp) steponp = "jump up onto the back of";
if (!stepons) stepons = "jumps up onto the back of";
} else {
if (!what->get_flag(FL_FIXED))
set_owner(what, who);
else
set_owner(what, who->owner);
if (!steponp) steponp = what->get_flag(FL_NOSADDLE)?"step on":"jump into the saddle of";
if (!stepons) stepons = what->get_flag(FL_NOSADDLE)?"steps on":"jumps into the saddle of";
}
who->printf("You %s %Y.\n", steponp, what);
who->oprintf(cansee && avoid(what), "%#M %s %P.\n", who, stepons, what);
what->printf("%#M %s you.\n", who, stepons);
who->set_flag(FL_SITTING, 0);
who->set_flag(FL_SLEEPING, 0);
who->set("$mount", what->id);
if (dotrap(E_AFTERMOUNT, who, what))
/* ::: after_mount o1==the mount */
return true;
return true;
}
static bool verb_dismount(MudObject *who, int argc, const char **argv) {
MudObject *what = mount(who);
if (!what) {
who->printf("You aren't riding anything.\n");
return true;
}
if (dotrap(E_BEFOREDISMOUNT, who, what))
/* ::: before_dismount o1==the mount; return 1 to abort */
return true;
const char *steponp = what->get("stepoff_p");
const char *stepons = what->get("stepoff_s");
if (what->get_flag(FL_MOBILE)) {
if (!steponp) steponp = "jump off the back of";
if (!stepons) stepons = "jumps off the back of";
} else {
if (!steponp) steponp = what->get_flag(FL_NOSADDLE)?"step off":"jump off the saddle of";
if (!stepons) stepons = what->get_flag(FL_NOSADDLE)?"steps off":"jumps off the saddle of";
}
who->printf("You %s %Y.\n", steponp, what);
who->oprintf(cansee && avoid(what), "%#M %s %P.\n", who, stepons, what);
what->printf("%#M %s you.\n", who, stepons);
who->unset("$mount");
if (what->owner == who) {
set_owner(what, who->owner);
}
if (dotrap(E_AFTERDISMOUNT, who, what))
/* ::: after_dismount o1==the former mount */
return true;
return true;
}
#include "verbmodule.h"
void startup() {
AUTO_VERB(mount, 3, 0, PFL_NONE);
ADD_ALIAS(ride, 3, mount);
AUTO_VERB(dismount, 4, 0, PFL_NONE);
ADD_ALIAS(unmount, 3, dismount);
}