reward_V2.c

snippets · 28.3 KB · 2010-03-30

reward.c v2.1 (March 19, 2008) by Sandi Fallon: a reward system.

Download   « Back to the snippets list

/****
Title:		reward.c
Version:	2.1
Date:		March 19, 2008
Author: 	Sandi Fallon
Email:		sandif@townsip.com
License:	Diku/Merc/ROM

                    This snippet is dedicated to Gothar
I learned so much from his snippets, I hope others can learn from this one.

History:	The first 'autoquest' code I ever saw was Ryan Addams'. I was a
little newbie at the time, so I really can't speak to issue of how original
his idea was. While this is obviously a variation on his idea, my code is
not derived from his; in fact, it is a deliberate attempt to be different.
Naturally, we independently used the same solutions to certain problems and
some tricks, such as adding IMM_SUMMON to exclude mobs, I copied from him.
This code was written in response to demands from my players - they wanted
autoquests, and they wanted certain problems fixed, so Ryan gets both the
credit and the blame for my inspiration!  :)  On a personal note, I would
like to thank him for the 100's of hours of enjoyment I had as a player
using his autoquest code.

			In particular, Addams' code does not choose a random mob, but
rather walks the char_list from the beginning each time, then checks the
criteria, then flips a coin. With a 15% chance of success, the players tend
to get the same mobs again and again as they'll probably (64%) get a hit in
the first five mobs. The other major annoyance is his code uses pulse_area
for timing, but expresses everything in RL minutes. The timing of ROM's
pulses varies from server to server, so the time reported to the player
is seldom right.


Features:	Only one command, no arguments, help is optional as the command
			tells you what to do next.

			Players are sent to retrieve an object from a mob, then are sent
			to another mob to exchange it for a reward.

			The search routine picks a random room rather than mob, then checks
			all mobs in room for an appropriate object. ACT_AGGRESSIVE and
			alignment as well as the level of mob are checked.

			Time is tracked by current_time(), not ticks.

			There is no quest_update. The code is entirely event-driven.
			(this might also be considered a flaw or at least an inconvenience,
			but it certainly is more efficient.)

Missing:	There is no quest_update. No more nagging about "You're almost out
			of time!". The downside is, when a player returns too late she just
			gets a new quest. Everything has been reset, so there's no way to
			say, "Sorry...".

			The Captain doesn't sell quest items. You'll have to make another
			mob into a special shopkeeper. On my mud, reward points earn IMM
			favors like restrings, corpse recoveries and spell-ups. I put too
			much work into balancing the areas to allow radical EQ.

Other:		The time allotted for the quests is constant, as the amount of the
			reward is adjusted by the time remaining upon completion.

			Credits: If you like, you may include my name in the "help <your
			game name>" file and leave my header as-is in reward.c. It's also
			customary to email people when you use a posted snippet. I leave
			it all up to you, and while a note saying "I love your code!" would
			be gratifying, I'm more concerned with knowing if you have any
			problems.

****/


/* Make a file called reward.c and copy the following code (the part between
 * the SNIP HERE lines) into it.  Copy each of the remaining sections into
 * your source files as directed below.  Add reward.o to the list in your
 * Makefile.
 *
 * In your src/ type:
 *   rm -rf *.o
 *   make
 *
 * Now copy the rom* file to your area directory. Pray. Reboot.
 */


/******* SNIP HERE ********  Beginning of reward.c  ******* SNIP HERE *******/

/* * * * * * * * * * * * * *    reward.c    * * * * * * * * * * * * * * *
*                                                                       *
*    Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,    *
*   Michael Seifert, Hans-Henrik Stæfeldt, Tom Madsen and Katja Nyboe   *
*                                                                       *
*         Merc Diku Mud improvements copyright (C) 1992, 1993 by        *
*            Michael Chastain, Michael Quan, and Mitchell Tse           *
*                                                                       *
*         ROM 2.4 is copyright 1993-1998 Russ Taylor                    *
*         ROM has been brought to you by the ROM consortium:            *
*               Russ Taylor (rtaylor@hypercube.org)                     *
*               Gabrielle Taylor (gtaylor@hypercube.org)                *
*               Brian Moore (zump@rom.org)                              *
*                                                                       *
*    reward.c and associated patches copyright 2008 by Sandi Fallon     *
*                                                                       *
*  By using code from this ROM Merc Diku MUD, you agree to comply with  *
*  the original Diku license in 'license.doc' as well the Merc license  *
*  in 'license.txt' and also the ROM license in 'rom.license', each to  *
*  be found in doc/. Using the reward.c code without conforming to the  *
*  requirements of each of these documents is violation of any and all  *
*  applicable copyright laws. In particular, you may not remove any of  *
*  these copyright notices or claim other's work as your own.           *
*                                                                       *
*    Much time and thought has gone into this software you are using.   *
*            We hope that you share your improvements, too.             *
*                   "What goes around, comes around."                   *
*                                                                       *
* * tabs = 4 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"

/* imported stuff */
DECLARE_DO_FUN( do_say );
DECLARE_DO_FUN( do_emote );


/* adapted from healer.c */
CHAR_DATA *find_captain( CHAR_DATA *ch )
{
	CHAR_DATA *captain;


	if( ch->position <= POS_SLEEPING )
	{
		return NULL;
	}

	for( captain = ch->in_room->people; captain; captain = captain->next_in_room )
	{
		if( IS_NPC(captain) && IS_SET(captain->act, ACT_REWARD) )
		break;
	}
	if( captain == NULL )
	{
		return NULL;
	}
	if( !can_see( captain, ch ) )
	{
		do_say( captain, "Huh? I hear something, but see no one!" );
		return NULL;
	}
	if( IS_NPC(ch) )
	{
	  	act( "$n waves $s hand at $N.", captain, NULL, ch, TO_ROOM );
		do_say( captain, "I don't have time for animals!" );
		return NULL;
	}
	return captain;
}

/* adapted from healer.c */
CHAR_DATA *find_rewarder( CHAR_DATA *ch )
{
	CHAR_DATA *rewarder;


	if( ch->position <= POS_SLEEPING )
	{
		return NULL;
	}

	for( rewarder = ch->in_room->people; rewarder; rewarder = rewarder->next_in_room )
	{
		if( IS_NPC(rewarder) && rewarder->pIndexData->vnum == ch->pcdata->rewarder )
		break;
	}
	if( rewarder == NULL )
	{
		return NULL;
	}
	if( !can_see( rewarder, ch ) )
	{
		do_say( rewarder, "Huh? I hear something, but see no one!" );
		return NULL;
	}
	if( IS_NPC(ch) )
	{
	  	act( "$n waves $s hand at $N.", rewarder, NULL, ch, TO_ROOM );
		do_say( rewarder, "I don't have time for animals!" );
		return NULL;
	}
	return rewarder;
}

/* this is where we pretend to decrement a counter - Fallon */
/* the magic number 720 is the number of seconds in 12 minutes */
void reset_hunt( CHAR_DATA *ch )
{
	int diff = 0;

	if( (diff = (current_time - ch->pcdata->hunt_time)) < 720 )
	{
		if( diff < 0 )
		{
			ch->pcdata->recovery = current_time + 720;
		}
		else
		{
			ch->pcdata->recovery = current_time + 720 - diff;
		}
	}

	else
	{
		ch->pcdata->recovery  = 0;
	}

	ch->pcdata->hunt_time  = 0;
	ch->pcdata->rewarder   = 0;
	ch->pcdata->reward_mob = 0;
	ch->pcdata->reward_obj = 0;
}

/* adapted from Furey's mfind() code */
void reward( CHAR_DATA *ch, CHAR_DATA *captain )
{
	char 			buf[MAX_STRING_LENGTH];
	char 			first[MAX_INPUT_LENGTH];
	char const 		*prep;
	char			*where;
	ROOM_INDEX_DATA *room;
	CHAR_DATA 		*victim = NULL;
	CHAR_DATA		*guard;
	OBJ_DATA 		*obj = NULL;
	OBJ_DATA 		*obj_next;
	int vnum 		= 0;
	bool obj_found	= 0;
	bool aggie_found;


	/* start with a random number */
	/* note that the condition in the for() will never be met, so be careful
	 * about changing things here or you'll have an infinite loop.
	 */
	for ( vnum = 1202; vnum < 30001; vnum = number_range(100, 30000) )
	{
		/* make it a random room */
		if ( ( room = get_room_index( vnum ) ) != NULL )
		{
			/* go through the mobs in the room and check for aggies */
			aggie_found = FALSE;
			for ( victim = room->people; victim != NULL; victim = victim->next_in_room )
			{
				if ( IS_NPC(victim) && IS_SET(victim->act, ACT_AGGRESSIVE) && victim->level > ch->level )
				{
					aggie_found = TRUE;
					break;
				}
			}

			if ( !aggie_found )
			{
				/* go through the mobs in the room and check their level and flags */
				for ( victim = room->people; victim != NULL; victim = victim->next_in_room )
				{
					if ( IS_NPC(victim)
					&&   ( IS_NEUTRAL(victim)  ||  (ch->alignment > 0 ? IS_EVIL(victim) : IS_GOOD(victim)) )
					&&   ch->level + (ch->level / 4) >= victim->level
					&&   ch->level - (ch->level / 3) <= victim->level
					/* &&   !IS_SET(victim->act, ACT_TRAIN)
					&&   !IS_SET(victim->act, ACT_PRACTICE)
					&&   !IS_SET(victim->act, ACT_IS_HEALER)
					&&   !IS_SET(victim->act, ACT_IS_CHANGER)
					&&	 !IS_SET(victim->act, ACT_BANKER) you might not have ACT_BANKER */

					/*   this idea is from Addams: add IMM_SUMMON to all the healers, shopkeeps,
					 *   trainers, school mobs, etc. that you don't want to be hunted.
					 *   they really should be, anyway. Otherwise, uncomment the code above. */
					&&   !IS_SET(victim->imm_flags, IMM_SUMMON)
					&&   !IS_SET(victim->affected_by, AFF_CHARM) )
					{
						/* see if the mob has an object */
						/* you might want to add a check for wear_loc - the following
						*  includes inventory but without 'peek' they can only see what
						*  the mob is wearing. This does, however, give peek more value.
						*/
						obj_found = FALSE;
						for (obj = victim->carrying; obj != NULL; obj= obj_next)
						{
							obj_next = obj->next_content;

							if ( !IS_SET(obj->extra_flags, ITEM_INVENTORY)
							&&   !IS_SET(obj->extra_flags, ITEM_ROT_DEATH)
							&&    IS_SET(obj->wear_flags,  ITEM_TAKE) )
							{
								obj_found = TRUE;
								break;
							}
						}
					}
					if ( obj_found )
					break;
				}
			}
		}
		if ( obj_found )
		break;
	}

	if ( !obj_found )
	{
		sprintf( buf, "Right now, %s, there are no rewards worthy of your talents.", ch->name );
		do_say( captain, buf );
		return;
	}

	/* make sure we didn't screw up - if any of these are missing, we go boom */
	if ( ( room = get_room_index( vnum ) ) == NULL || obj == NULL || victim == NULL )
	{
		bug( "Reward: found NULL in reward.", 0 );
		return;
	}

	/* you need to either commit to fixing capitalised articles on mob->short in
	 * all the areas, or make it LOWER(victim->short_descr) in the 4th argument */
	switch ( obj->item_type )
	{
		case ITEM_WEAPON :
		sprintf( buf, "%s, everyone knows %s stole %s. Find the thief and get %s, bring it to me, and I will see you are handsomely rewarded!",
			ch->name, victim->short_descr, obj->short_descr, obj->short_descr );
			break;
		case ITEM_ARMOR :
		sprintf( buf, "%s has been reported lost, %s, but we know who took it. Find %s and get %s, bring it to me, and I will tell you who will pay a generous reward for its return.",
			capitalize(obj->short_descr), ch->name, victim->short_descr, obj->short_descr );
			break;
		case ITEM_CONTAINER :
		sprintf( buf, "%s is gone! %s, rumor among the %s is that %s filched it. Slay %s and get %s, bring it to me, and I'll see to it you are rewarded!",
			capitalize(obj->short_descr), ch->name, race_table[victim->race].name, victim->short_descr, victim->short_descr, obj->short_descr );
			break;
		default :
		sprintf( buf, "%s is gone! %s, just before %s died, our %s informant said %s filched it. Slay %s and get %s, bring it to me, and I'll see to it you are rewarded!",
			capitalize(obj->short_descr), ch->name, victim->sex == 1 ? "he" : "she", race_table[victim->race].name, victim->short_descr, victim->short_descr, obj->short_descr );
			break;
	}
	do_say( captain, buf );

	/* again, you'll probably need to edit a few areas - the Sewers has room names ending in periods */
	for( guard = ch->in_room->people; guard; guard = guard->next_in_room )
	{
		if( IS_NPC(guard) && !IS_AFFECTED(guard, AFF_CHARM)
		&&  !IS_SET(guard->act, ACT_REWARD) )
		break;
	}
	/* this is in case all the guards wander off while the door is open.
	 * you might want to set one guard 'sentinel', so he stays put. */
	if( guard == NULL )
	{
		guard = captain;
	}

	do_emote( guard, "points to a map." );

	one_argument( room->name, first );
	if( is_exact_name(first, "the a an") )
	{
		prep = "at ";
		where = decap(victim->in_room->name);
	}

	else if( is_exact_name(first, "on in at by near inside under within approaching standing climbing swimming sailing walking sliding floating close lost along going over near very atop beneath before below between" ) )
	{
		prep = "";
		where = decap(victim->in_room->name);
	}

	else
	{
		prep = "at ";
		where = victim->in_room->name;
	}

	sprintf( buf,  "I hear that %s was recently seen %s%s in %s.",
		 victim->short_descr, prep, where, room->area->name );
	do_say( guard, buf );

	ch->pcdata->rewarder   = 0;
	ch->pcdata->reward_mob = victim->pIndexData->vnum;
	ch->pcdata->reward_obj = obj->pIndexData->vnum;
	ch->pcdata->hunt_time  = (current_time + 1200);
	return;
}


/* the reward command structure eliminates the need for arguments
 * but do_command needs them */
void do_reward( CHAR_DATA *ch, char *argument )
{
	char 				buf[MAX_STRING_LENGTH];
	char 				arg[MAX_STRING_LENGTH];
	char const 			*art;
	CHAR_DATA 			*captain;
	CHAR_DATA 			*rewarder = NULL;
	OBJ_DATA			*obj = NULL;
	OBJ_DATA			*obj_next;
	ROOM_INDEX_DATA 	*room;
	int					reward = 0;
	int 				vnum = 0;
	bool obj_found		= FALSE;
	bool rewarder_found	= FALSE;

	/* Newbie's can't hunt for rewards. */
	if (ch->level < 3 )
	{
		sprintf( buf, "Sorry, you must be level 3 to hunt for a reward.\n\r" );
		send_to_char( buf, ch );
		return;
	}

	/* Imms can't get rewards, either. */
	else if (ch->level > 51)
	{
		sprintf( buf, "Sorry, you're too old to hunt for a reward.\n\r" );
		send_to_char( buf, ch );
		return;
	}

	/* reset them if they've run out of time */
	if ( ch->pcdata->hunt_time < current_time )
	{
		reset_hunt(ch);
	}

	/* see if they're available for work */
	if ( ch->pcdata->recovery > current_time )
	{
		sprintf( buf, "You have %ld minute%s left to recover from the last hunt.\n\r",
		((ch->pcdata->recovery - current_time) / 60) + 1,
		((ch->pcdata->recovery - current_time) / 60) + 1 == 1 ? "" : "s" );
		send_to_char( buf, ch );
		return;
	}

	/* if they have been assigned a hunt, look for the object in
	 * the char's inventory */
	if ( ch->pcdata->reward_obj > 0 )
	{
		obj_found = FALSE;
		for (obj = ch->carrying; obj != NULL; obj= obj_next)
		{
			obj_next = obj->next_content;

			if ( obj->pIndexData->vnum  ==  ch->pcdata->reward_obj )
			{
				obj_found = TRUE;
				break;
			}
		}
	}

	/* if they have the object, check for the rewarder in the room */
	if ( obj_found  &&  (rewarder = find_rewarder(ch)) != NULL )
	{
   		reward = ( (ch->level + 50) / 3 ) + ( (ch->pcdata->hunt_time - current_time) / 20 ) +
				 ( UMAX((get_mob_index(ch->pcdata->reward_mob)->level - ch->level), 0) * 10 );

		switch( number_range(1, 3) )
		{
			case 1:
			sprintf( buf, "Wonderful, %s! You have found %s that was stolen from me by %s! In appreciation, I grant you a reward of %d.",
				ch->name, obj->pIndexData->short_descr,
				get_mob_index(ch->pcdata->reward_mob)->short_descr, reward );
				break;
			case 2:
			sprintf( buf, "%s, you have found %s! This is marvelous! Here, I'll give you %d for a reward.",
				ch->name, obj->pIndexData->short_descr, reward );
				break;
			case 3:
			sprintf( buf, "%s! %s, you have %s! To show my gratitude, you shall have a reward of %d.",
				capitalize(obj->pIndexData->short_descr), ch->name, obj->pIndexData->short_descr, reward );
				break;
		}
		do_say( rewarder, buf );

		act( "$c takes $p from $N and pays $M a reward.", rewarder, obj, ch, TO_NOTVICT );
		act( "$c takes $p from you and pays you a reward.", rewarder, obj, ch, TO_VICT );

		extract_obj(obj);
		reset_hunt(ch);
		ch->pcdata->rewards  += reward;
		return;
	}

	/* see if the character is in the room with the ACT_REWARD mob */
	if ( ( captain = find_captain(ch) ) != NULL )
	{
		/* if the char has no REWARD_obj set, give her one */
		if ( ch->pcdata->REWARD_obj < 1 )
		{
			/* reward() will almost always find a mob, so if you want a chance of
			 * failure, THIS is the place to put it - before we load the CPU. */
			reward( ch, captain );
			return;
		}

		/* they have found the object, so we find someone to send them to */
		if ( obj_found )
		{
			/* first make sure it's their first time asking */
			if ( ch->pcdata->rewarder > 0 )
			{
				sprintf( buf, "%s, you have %s that belongs to %s. Now, get going! You have %ld minute%s left.",
					ch->name,
					get_obj_index(ch->pcdata->reward_obj)->short_descr,
					get_mob_index(ch->pcdata->rewarder)->short_descr,
					((ch->pcdata->hunt_time - current_time) / 60) + 1,
					((ch->pcdata->hunt_time - current_time) / 60) + 1 == 1 ? "" : "s" );
				do_say( captain, buf );
				return;
			}

			else
			{
				rewarder_found	= FALSE;
				/* start with a random number */
				for ( vnum = 1202; vnum < 30001; vnum = number_range(100, 30000) )
				{
					/*make it a random room */
					if ( ( room = get_room_index(vnum) ) != NULL )
					{
						for ( rewarder = room->people; rewarder != NULL; rewarder = rewarder->next_in_room )
						{
							if ( IS_NPC(rewarder)
							&&   ch->level + (ch->level / 3) + 3 >= rewarder->level
							&&   rewarder->race != race_lookup("school monster") /* this takes care of school */
							&&   !IS_SET(rewarder->act, ACT_AGGRESSIVE)          /* by popular demand! */
							&&   !IS_SET(rewarder->act, ACT_PRACTICE)
							&&   !IS_SET(rewarder->act, ACT_TRAIN)
							&&   !IS_SET(rewarder->act, ACT_GAIN)                /* watch out for mobs in clan halls */
							&&   !IS_SET(rewarder->affected_by, AFF_CHARM) )     /* No children, no pets allowed */
							{
								ch->pcdata->rewarder = rewarder->pIndexData->vnum;
								ch->pcdata->hunt_time = (current_time + 1200);
								rewarder_found = TRUE;
								break;
							}
						}
					}
					if ( rewarder_found )
					break;
				}
			}

			if ( ( room = get_room_index(vnum) ) == NULL || rewarder == NULL )
			{
				bug( "Reward: found NULL in reward.", 0 );
				return;
			}

			one_argument( room->name, arg );
			if( is_exact_name(arg, "on in at by near inside under within approaching standing climbing flying sailing swimming falling close shipwrecked along going over near very beneath before way" ) )
			art = "";
			else art = "at ";

			sprintf( buf, "Well done, %s, you have found %s! Now, take it to %s %s%s in %s and ask for a fat reward.",
				ch->name,
				get_obj_index(ch->pcdata->reward_obj)->short_descr,
				get_mob_index(ch->pcdata->rewarder)->short_descr,
				art,
				lowercase(room->name), room->area->name );
			do_say( captain, buf );

			return;
		}

		/* OK, no obj, let's give them a progress report */
		else
		{
			sprintf( buf, "%s, you are hunting for %s that was stolen by %s. You have %ld minute%s left.",
				ch->name,
				get_obj_index(ch->pcdata->reward_obj)->short_descr,
				get_mob_index(ch->pcdata->reward_mob)->short_descr,
				((ch->pcdata->hunt_time - current_time) / 60) + 1,
				((ch->pcdata->hunt_time - current_time) / 60) + 1 == 1 ? "" : "s");
			do_say( captain, buf );
			return;
		}
	}

	/* not with the ACT_REWARD or REWARDER mob, so...  */

	if ( ch->pcdata->reward_obj < 1 )
	{
		sprintf( buf, "You are not bounty hunting at the moment.\n\rSee the Cityguard Captain for a chance at a reward.\n\r" );
		send_to_char( buf, ch );
		return;
	}

	if ( obj_found )
	{
		/* if they have a rewarder, send a reminder */
		if ( ch->pcdata->rewarder != 0 )
		{
			sprintf( buf, "You have %ld minute%s left to return %s to %s!\n\r",
				((ch->pcdata->hunt_time - current_time) / 60) + 1,
				((ch->pcdata->hunt_time - current_time) / 60) + 1 == 1 ? "" : "s",
				get_obj_index(ch->pcdata->reward_obj)->short_descr,
				get_mob_index(ch->pcdata->rewarder)->short_descr );
			send_to_char( buf, ch );
			return;
		}

		/* if they've just found the object, send them back to the captain */
		else
		{
			sprintf( buf, "You have found %s with %ld minute%s left to go!\n\rReturn to the Captain for further intructions.\n\r",
				get_obj_index(ch->pcdata->reward_obj)->short_descr,
				((ch->pcdata->hunt_time - current_time) / 60) + 1,
				((ch->pcdata->hunt_time - current_time) / 60) + 1 == 1 ? "" : "s");
			send_to_char( buf, ch );
			return;
		}
	}

	/* if they're still hunting, give them a progress report */
	if ( ch->pcdata->reward_obj > 0 )
	{
		sprintf( buf, "You are hunting for %s that was stolen by %s.\n\rYou have %ld minute%s left.\n\r",
			get_obj_index(ch->pcdata->reward_obj)->short_descr,
			get_mob_index(ch->pcdata->reward_mob)->short_descr,
			((ch->pcdata->hunt_time - current_time) / 60) + 1,
			((ch->pcdata->hunt_time - current_time) / 60) + 1 == 1 ? "" : "s");
		send_to_char( buf, ch );
		return;
	}

	/* since we've tested all the possibilities, you should never see this message */
	else
	{
		bug( "Reward: A player passed ALL the tests. Error!", 0 );
		return;
	}

}


/********** SNIP HERE ********  End of reward.c  ******* SNIP HERE **********/


/*##########################################################################*/

/*  Add the following lines to your source code. */


/*==== in act_comm.c in: do_say and do_emote ====*/

    act( "$c says '$T'", ch, NULL, argument, TO_ROOM );
    act( "You say '$T'", ch, NULL, argument, TO_CHAR );

    act( "$c $T", ch, NULL, argument, TO_ROOM );
    act( "$c $T", ch, NULL, argument, TO_CHAR );

/* replace the $n with $c */

/*==== end insert act_comm.c ====*/


/*++++ insert in act_info.c in: format_obj_to_char ++++*/

	if ( obj->pIndexData->vnum  ==  ch->pcdata->reward_obj )
	{
		if( ch->pcdata->hunt_time < current_time )	reset_hunt(ch);
		else	strcat( buf, "(Stolen Aura) " );
	}

/*++++ end insert act_info.c ++++*/



/*==== insert in comm.c in void act_new after: case 'N' ====*/

		case 'c': i = capitalize(PERS( ch, to  ));              break;

/*==== add this to act.txt ====*/

    $c
        Result is the capitalized name of 'ch'.  If 'ch' is not visible to the
        target character, result is the string 'Someone'.

/*==== end insert comm.c ====*/



/*++++  insert these in db.c under capitalize() ++++*/

/* Returns a string all lowercase - Fallon*/
char *lowercase( const char *str )
{
	static char strlow[MAX_STRING_LENGTH];
	int i;

	if(!str) return NULL;

	for ( i = 0; str[i] != '\0'; i++ )
	strlow[i] = LOWER(str[i]);
	strlow[i] = '\0';
	return strlow;
}

/* Returns a string with the first letter lowercased - Fallon */
char *decap( const char *str )
{
	static char firstlow[MAX_STRING_LENGTH];
	int i;

	for ( i = 0; str[i] != '\0'; i++ )
	firstlow[i] = str[i];
	firstlow[i] = '\0';
	firstlow[0] = LOWER(firstlow[0]);
	return firstlow;
}

/*++++ end insert db.c ++++*/



/*==== insert in merc.h in: ACT bits for mobs. ====*/

#define ACT_REWARD				(N)		/* Can assign find_missing targets */

/* If you don't want to use a bit, see Addams' quest-2.03.zip for
 * instructions on how to use spec_lookup() instead of IS_SET() */

/*==== insert in merc.h at the end of: struct	pc_data ====*/

	int			 		rewards;
	int					recovery;
	int					hunt_time;
	sh_int				reward_obj;
	sh_int				reward_mob;
	sh_int				rewarder;

/*==== insert in merc.h after: char *	capitalize ====*/

char *	lowercase			args( ( const char *str ) );
char *	decap				args( ( const char *str ) );

/*==== insert in merc.h after: void	obj_cast_spell ====*/

/* reward.c */
void	reset_hunt		args( ( CHAR_DATA *ch ) );
CD *	find_rewarder	args( ( CHAR_DATA *ch ) );
CD *	find_captain	args( ( CHAR_DATA *ch ) );
void	find_missing	args( ( CHAR_DATA *ch, CHAR_DATA *captain ) );

/*==== end insert merc.h ====*/



/*++++ insert in fight.c in is_safe after: if( IS_SET(victim->act,ACT_TRAIN) ++++*/

		||  IS_SET(victim->act,ACT_REWARD)

/*++++ end insert fight.c ++++*/



/*==== insert in interp.c in: miscellaneous commands ====*/

	{ "reward",			do_reward,		POS_SLEEPING,	 0,  LOG_NORMAL, 1 },

/*==== end insert interp.c ====*/



/*++++ insert in interp.h after: DECLARE_DO_FUN( do_return		); ++++*/

DECLARE_DO_FUN(	do_reward		);

/*++++ end insert interp.h ++++*/



/*==== insert in save.c under: fprintf( fp, "Wimp ====*/

	if (ch->pcdata->hunt_time != 0)
		fprintf( fp, "HuntTime %d\n",  ch->pcdata->hunt_time );
	if (ch->pcdata->rewards != 0)
		fprintf( fp, "Rewards %d\n",  ch->pcdata->rewards );
	if (ch->pcdata->recovery != 0)
		fprintf( fp, "Recovery %d\n",  ch->pcdata->recovery );
	if (ch->pcdata->reward_obj != 0)
		fprintf( fp, "RewardObj %d\n",  ch->pcdata->reward_obj );
	if (ch->pcdata->reward_mob != 0)
		fprintf( fp, "RewardMob %d\n",  ch->pcdata->reward_mob );
	if (ch->pcdata->rewarder != 0)
		fprintf( fp, "Rewarder %d\n",  ch->pcdata->rewarder );

/*==== insert in save.c under: if ( !str_cmp( word, "HMVperm" ) ====*/

		KEY( "HuntTime",	ch->pcdata->hunt_time,		fread_number( fp ) );

/*==== insert in save.c under: if ( !str_cmp( word, "Race" ) ====*/

		KEY( "Recovery",	ch->pcdata->recovery,	fread_number( fp ) );
		KEY( "Rewarder",	ch->pcdata->rewarder,	fread_number( fp ) );
		KEY( "Rewards",		ch->pcdata->rewards,	fread_number( fp ) );
		KEY( "RewardMob",	ch->pcdata->reward_mob,	fread_number( fp ) );
		KEY( "RewardObj",	ch->pcdata->reward_obj,	fread_number( fp ) );

/*
 * If you've been using Addam's quest code, there will be two places
 * (read and save) that mention "quest_curr". Leave these lines in place,
 * but change "quest_curr" to "rewards". This will convert the points
 * the players have already accumulated (no attempt has been made to
 * make "rewards" equivalent to "quest_curr". "quest_curr" should probably
 * be devalued, or the amount of the rewards increased, since you have
 * to find two mobs instead of one). Or, just copy the way "quest_curr"
 * is saved to the pfile and read back to the mud, then change the copy
 * to say "rewards". There's no reason you couldn't run both quest systems
 * at the same time.
 */

/*==== end insert save.c ====*/


/*##########################################################################*/


/* Area Editing:
 * Set the Captain of the Guard in Midgaard (or any other mob with appropriate
 * changes to the text) ACT_REWARD. Remove the aggy flag from him and the 4
 * guards with him, and change their descrs. Remove the lock on the door in
 * and out.
 *
 * In midgaard.are Mobiles section find:  #3140 the Captain
 * The line below human~ starts with the flag array:  ABCFT
 * Change this to:  ABCNT
 * In the next mob down, #3141 the Cityguard, change it to:  ACT
 * (the F is Aggy, the N is Reward, the B is Sentinel)
 * Change the Captain's  CDEHKLU 0 C 0  to  CDEHKLU A C 0
 * (this makes him IMM_SUMMON)
 *
 * In the room #3110 Cityguard Head Quarters you see:
 * door~
 * 1 3120 3142
 * make it:  1 -1 3142
 * (that takes the lock and key away)
 * Be sure to do the same in the Captain's Office.
 */

/* Help File:

-1 REWARD~
Syntax:	reward

We have automated quests that use the REWARD command.  Just type REWARD
and follow the directions.  You will be sent to retrieve an object from a
mob and return it to another mob for a reward.  The object you're looking
for will be flagged (Stolen Aura).  The find_mob code is pretty smart. You
should never be sent to find a thief in a room with aggie mobs, but the
rewarder might have nasty friends.  Be careful! Unfortunately, there's no
way to know what path you'll take and ensure you'll survive the journey.
Many quests will be easy, but some will be impossible.  Over time, it
should balance out.

If you have played Addams' QuestMaster code, you'll notice two major
differences:

* REWARD takes no arguments. (i.e., REWARD LIST does not work.)

* There's no update timer to nag you. You'll have to keep track
  of the time yourself.

Reward was written by Sandi Fallon for the Blades of Destiny.
~

*/


/* Extra Credit:
 * You probably should modify the score command to display the rewards
 * accumulated, or you could add a separate command, make it part of
 * "worth", whatever....
 *
 * Color to taste.
 *
 * I'm going to make a copy of most of this, change the message strings,
 * and have a separate mob to assign "assassinations" to evil players.
 * More in character, you know. :)
 */



Site Stats

Snippets: 1791
Codebases: 571