From: ajv@roi.csd.mot.com
Newsgroups: rec.games.mud.lp
Subject: A transport toy
Date: 15 Apr 92 20:23:50 GMT

We haven't seen much coding lately, so here's an item I threw together
a couple weeks ago.  It's a teleport toy which allows pretty good
player control of its function--a lot like Abc's watch, but more flexible.
I try to control game balance by (1) having limited charges on it, and
(2) by having it honor the NT attribute of rooms.  Most of our serious
quest sequences have this attribute on the rooms, so this item won't
circumvent them.

I'm also converting all the pubs, vending machines, and drink shops
to use a pub_inherit.c object.  My goal is to focus all the policy of
how much a particular kind of healing costs into a single point, and
then leave the trade-offs of healing power, drunkenness, and portability
to the individual shops/pubs/etc.  In the process, I've been amazed to
see the progressively more generous healing which various shops have
dealt out just to stay popular.  I'll post my first pass on the pub_inherit
object in a while.

For now, here's "marker.c"!

					Regards,
					Andy Valencia
					Baltor @ Squintmud
					ajv@roi.ca41.csd.mot.com

#define MAXLOC 3
#define MAXCHARGE 20

static object dests;
static int rotor, charges;

short() {
	return("A location marker tool");
}
long() {
	write(short()+".\n");
	if (disabled())
		return;
	write("It has "+charges+" charges left.\n");
	if (dests[rotor]) {
		write("Currently set to: "+dests[rotor]->short()+".\n");
	}
	write("Use 'help marker' if you need help on its use.\n");
}
id(str) {
	return ((str == "marker") || (str == "location marker") ||
		(str == "tool"));
}
get() {
	return 1;
}
reset(arg) {
	if (arg)
		return;
	dests = allocate(MAXLOC);
	charges = random(MAXCHARGE/2) + MAXCHARGE/2;
}
init() {
	add_action("mark", "mark");
	add_action("back", "back");
	add_action("jump", "jump");
	add_action("peek2", "peek");
	add_action("help", "help");
}
query_value() {
	return 100 + 100*charges;
}

/*
 * charge()
 *	Charge for use, destruct when we use all charges
 */
static
charge(amt) {
	charges -= amt;
	if (charges < 1) {
		write("The amulet disintegrates.\n");
		destruct(this_object());
	}
}

/*
 * recharge()
 *	Allow wizardry recharging
 */
recharge(amt) {
	charges += amt;
	if (charges < 0) {
		charges = 1;
	}
	if (charges > MAXCHARGE) {
		charges = MAXCHARGE;
	}
	return(charges);
}

/*
 * disabled()
 *	Tell if aren't allowed to teleport from current location
 */
static
disabled()
{
	if (environment(this_player())->realm() == "NT") {
		write("The watch appears inert.\n");
		return 1;
	}
	return 0;
}

/*
 * mark()
 *	Record current location in FIFO
 */
mark() {
	if (disabled())
		return 1;
	rotor += 1;
	if (rotor >= MAXLOC)
		rotor = 0;
	dests[rotor] = environment(this_player());
	write("Location marked.\n");
	charge(1);
	return 1;
}

/*
 * back()
 *	Move back to previous position in FIFO
 */
back() {
	int r;

	if (disabled())
		return 1;
	r = rotor;
	r -= 1;
	if (r < 0)
		r = MAXLOC-1;
	if (!dests[r]) {
		write("No further destination is remembered.\n");
		return 1;
	}
	rotor = r;
	write("Now set to: "+dests[r]->short()+"\n");
	charge(1);
	return 1;
}

/*
 * jump()
 *	Gate to position currently indicated in FIFO
 */
jump() {
	if (disabled())
		return 1;
	if (!dests[rotor]) {
		write("You have not set a location yet.\n");
		return 1;
	}
	move_object(this_player(), dests[rotor]);
	write("A cloud of golden vapor envelopes you...\n");
	peek();			/* Re-use this function to see stuff */
	charge(3);
	return 1;
}

/*
 * peek2()
 *	Front function to add the necessary verbage
 */
peek2()
{
	if (disabled())
		return 1;
	write(
	"Your stare down into the device, and a vision fills your mind...\n");
	peek();
	charge(2);
	return 1;
}

/*
 * peek()
 *	Take a peek at the given location
 */
static
peek() {
	object ob;

	ob = dests[rotor];
	if (!ob) {
		write("You have not set a location yet.\n");
		return;
	}
	ob->long();
	ob = first_inventory(ob);
	while (ob) {
		if (ob != this_player())
			write(ob->short()+".\n");
		ob = next_inventory(ob);
	}
	return;
}

/*
 * help()
 *	Give help if we match on the subject
 */
help(str)
{
	if (id(str)) {
		write(
"Use 'mark' to set the marker to the current location.\n"+
"Use 'back' to set the marker back to the previously-set location.\n"+
"Use 'jump' to transport yourself to the location set.\n"+
"Use 'peek' to sneak a peek at the current location.\n"+
"The marker remembers the last "+MAXLOC+" locations set.\n"
		);
		return 1;
	}
	return 0;
}