follow.cc
musicmud-2.1.6/src/extras/follow.cc · 5.2 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD - Grouping module
* 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 <stdio.h>
#include "musicmud.h"
#include "misc.h"
#include "pflags.h"
#include "verbs.h"
#include "util.h"
#include "events.h"
#include "trap.h"
#define MODULE "follow"
static bool verb_party(MudObject *who, int, const char **) {
int i;
bool a = false;
MudObject *p;
foreach(planet, p, i) if (!p->nuke_me && p->followers.getsize()) {
bool b = false;
MudObject *o2;
int i2;
if (!is_player(p)) {
int hnm = 0;
foreach((&p->followers), o2, i2) {
if (is_player(o2)) {
hnm = 1;
break;
}
}
if (!hnm)
continue;
}
if (!a) {
who->printf("%s\n", title_for("Groups", who).c_str());
}
a = true;
who->printf("\nLed by %M.\n",
p);
who->printf(" ");
foreach((&p->followers), o2, i2) {
if (o2) {
who->printf("%s%M", b ? ", " : "", o2);
b = true;
}
}
who->printf("\n");
}
if (!a) {
who->printf("No parties formed.\n");
} else {
who->printf("\n");
who->printf("%s\n", footer_for(who).c_str());
}
return true;
}
static bool verb_charm(MudObject *who, int argc, const char **argv) {
if (argc < 2) {
who->printf("Charm who?\n");
return true;
}
MudObject *target = get_player(who, argv[1]);
if (!target) {
who->printf("Charm who?\n");
return true;
}
if (target == who) {
who->printf("You admire yourself.\n");
return true;
}
who->printf("You wave a ^opendulum^n in front of %M's eyes.\n", target);
who->oprintf(cansee && avoid(target), "%#M waves a ^opendulum^n in front of %M's eyes.\n", who, target);
target->printf("%#M waves a ^opendulum^n in front of your eyes.\n", who, target);
if (privs_of(target) < privs_of(who)) {
target->interpretf("follow %s", who->id);
}
return true;
}
static bool verb_follow(MudObject *who, int argc, const char **argv) {
if (argc < 2) {
who->printf("Follow who?\n");
return true;
}
if (!is_mobile(who) && !is_player(who)) {
log(PFL_SEEINFO, 0, "bug", "%s tried to follow %s", who->id, argv[1]);
who->printf("You aren't a person.\n");
return true;
}
MudObject *target = get_player(who, argv[1]);
if (!target && streq(argv[1], "$1")) {
target = who->get_object("!$1");
}
if (!target) {
who->printf("Follow who?\n");
return true;
}
if (target == who) {
who->printf("You run around in circles.\n");
return true;
}
if (target->owner != who->owner) {
who->printf("You can only follow people in the same place as you.\n");
return true;
}
if (who->follows == target) {
who->printf("You are already following %M.\n", target);
return true;
}
if (target->get_flag(FL_MOBILE) && !target->get_flag(FL_CANLEADER)) {
who->printf("You can't follow %M.\n", target);
return true;
}
if (who->follows) {
who->follows->printf("%#M stops following you.\n", who);
}
who->follow(target);
who->printf("You follow %M.\n", target);
target->printf("%#M starts following you.\n", who);
dotrap(E_AFTERFOLLOWED, who, target, 0, 0);
/* ::: after_followed o1==leader; after everything, including CanLeader or player check */
return true;
}
static bool verb_leave(MudObject *who, int, const char **) {
MudObject *p = who->follows;
if (!p) {
who->printf("You aren't following anyone.\n");
return true;
}
who->follow(0);
who->printf("You stop following %M.\n", p);
if (!who->nuke_me)
p->printf("%#M stops following you.\n", who);
return true;
}
static bool verb_lose(MudObject *who, int argc, const char **argv) {
if (argc < 2) {
who->printf("Lose who?\n");
return true;
}
if (streq(argv[1], "all")) {
NewWorld lost;
MudObject *o;
int i;
foreach(&(who->followers), o, i) {
lost.add(*o);
o->follow(0);
i--;
o->printf("%#M loses you.\n", who);
}
if (lost.getsize()) {
who->printf("You lose %s.\n", magiclist(lost).c_str());
return true;
}
}
MudObject *target = get_player(who, argv[1]);
if (!target) {
who->printf("Lose who?\n");
return true;
}
if (target->follows != who) {
who->printf("%#M isn't following you.\n", target);
return true;
}
target->follow(0);
target->printf("%#M loses you.\n", who);
who->printf("You lose %M.\n", target);
return true;
}
#include "verbmodule.h"
void startup() {
AUTO_VERB(party, 3, 0, PFL_NONE);
AUTO_VERB(leave, 4, 0, PFL_AWAKE);
AUTO_VERB(follow, 3, 0, PFL_AWAKE);
AUTO_VERB(lose, 4, 0, PFL_AWAKE);
AUTO_VERB(charm, 5, 0, PFL_FORCE);
}