Program_Snippets-V1.3/
Program_Snippets-V1.3/Docs/
 Proceed through this file and make all the changes instructed.

  File names are enclosed in a comment box:
		/**************************************************
		 *                       file_name                           *
		 **************************************************/

  Function names are marked as follows:
		/*
		 * Function Name ************************************************************
		 */

 Instructions are marked with a preceeding //:
 		// Instruction

 Excluding the file names and function names described above, you
 should include all comments that are included here excepting those
 that begin with the double slashes (//), such as this paragraph. 




/*****************************************INSTALLATION BEGINS BELOW THIS LINE*********************************************/





/************************************************************************************************
  *                                                 act_comm.c                                                          *
  ************************************************************************************************/

/*
  * void do_say *******************************************************************************
  */

// Right after
	if ( !IS_NPC( ch ) )
	{
		CHAR_DATA *mob, *mob_next;
// Add the following line
		OBJ_DATA *obj, *obj_next;

// Right after
	    if ( IS_NPC(mob) && HAS_TRIGGER_MOB( mob, TRIG_SPEECH )
	    &&   mob->position == mob->pIndexData->default_pos )
		p_act_trigger( argument, mob, NULL, NULL, ch, NULL, NULL, TRIG_SPEECH );
// Add the following 6 lines
	    for ( obj = mob->carrying; obj; obj = obj_next )
	    {
		obj_next = obj->next_content;
		if ( HAS_TRIGGER_OBJ( obj, TRIG_SPEECH ) )
		    p_act_trigger( argument, NULL, obj, NULL, ch, NULL, NULL, TRIG_SPEECH );
	    }

// Right before the last
    }
return;
// Add the following 10 lines
	for ( obj = ch->in_room->contents; obj; obj = obj_next )
	{
	    obj_next = obj->next_content;
	    if ( HAS_TRIGGER_OBJ( obj, TRIG_SPEECH ) )
		p_act_trigger( argument, NULL, obj, NULL, ch, NULL, NULL, TRIG_SPEECH );
	}
	
	if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_SPEECH ) )
	    p_act_trigger( argument, NULL, NULL, ch->in_room, ch, NULL, NULL, TRIG_SPEECH );
 
 /*
  * End void do_say **************************************************************************
  */

/************************************************************************************************
  *                                             End act_comm.c                                                      *
  ************************************************************************************************/
  
   /************************************************************************************************
  *                                               act_enter.c                                                             *
  ************************************************************************************************/

/*
 * void do_enter ******************************************************************************
 */

// Find
        if ( !IS_NPC( ch ) )
            p_greet_trigger( ch, PRG_MPROG );
// And replace it with the following 6 lines
        if ( !IS_NPC( ch ) )
        {
            p_greet_trigger( ch, PRG_MPROG );
	    p_greet_trigger( ch, PRG_OPROG );
	    p_greet_trigger( ch, PRG_RPROG );
	}

/*
 * End void do_enter ************************************************************************
 */

/************************************************************************************************
  *                                              End act_enter.c                                                      *
  ************************************************************************************************/
  
  /************************************************************************************************
  *                                                act_move.c                                                           *
  ************************************************************************************************/

/*
 * void move_char ***************************************************************************
 */
 
 // Replace
     if ( !IS_NPC(ch) 
      && p_exit_trigger( ch, door, PRG_MPROG ) )
	return;
// With the following 5 lines
    if ( !IS_NPC(ch) 
      && (p_exit_trigger( ch, door, PRG_MPROG ) 
      ||  p_exit_trigger( ch, door, PRG_OPROG )
      ||  p_exit_trigger( ch, door, PRG_RPROG )) )
	return;

// Replace
    if ( !IS_NPC( ch ) )
    	p_greet_trigger( ch, PRG_MPROG );
// With the following 6 lines
    if ( !IS_NPC( ch ) )
    {
    	p_greet_trigger( ch, PRG_MPROG );
	p_greet_trigger( ch, PRG_OPROG );
	p_greet_trigger( ch, PRG_RPROG );
    }

/*
 * End void move_char ***********************************************************************
 */

/*
 * void do_stand ****************************************************************************
 */

// After
ch->on = obj;
// Add the following 2 lines
if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );

/*
 * End void do_stand ************************************************************************
 */

/*
 * void do_rest *****************************************************************************
 */

// After
ch->on = obj;
// Add the following 2 lines
if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );

/*
 * End void do_rest *************************************************************************
 */

/*
 * void do_sit ******************************************************************************
 */
// After
ch->on = obj;
// Add the following 2 lines
if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );

/*
 * End void do_sit **************************************************************************
 */

/*
 * void do_sleep ****************************************************************************
 */

// After
ch->on = obj;
// Add the following 2 lines
if ( HAS_TRIGGER_OBJ( obj, TRIG_SIT ) )
	p_percent_trigger( NULL, obj, NULL, ch, NULL, NULL, TRIG_SIT );

/*
 * End void do_sleep ************************************************************************
 */

/************************************************************************************************
  *                                              End act_move.c                                                     *
  ************************************************************************************************/

/************************************************************************************************
  *                                                 act_obj.c                                                              *
  ************************************************************************************************/
/*
  * void get_obj *******************************************************************************
  */
// After
    else
    {
        obj_to_char( obj, ch );
// Add the following 4 lines

	if ( HAS_TRIGGER_OBJ( obj, TRIG_GET ) )
	    p_give_trigger( NULL, obj, NULL, ch, obj, TRIG_GET );
	if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_GET ) )
	    p_give_trigger( NULL, NULL, ch->in_room, ch, obj, TRIG_GET );
 
 /*
  * End void get_obj **************************************************************************
  */
  
/*
   * void do_drop ***************************************************************************
   */
// Replace each
	if (IS_OBJ_STAT(obj,ITEM_MELT_DROP))
	{
	    act("$p dissolves into smoke.",ch,obj,NULL,TO_ROOM);
	    act("$p dissolves into smoke.",ch,obj,NULL,TO_CHAR);
	    extract_obj(obj);
	}
// With the following 11 lines
	if ( HAS_TRIGGER_OBJ( obj, TRIG_DROP ) )
	    p_give_trigger( NULL, obj, NULL, ch, obj, TRIG_DROP );
	if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_DROP ) )
	    p_give_trigger( NULL, NULL, ch->in_room, ch, obj, TRIG_DROP );
	    
	if ( obj && IS_OBJ_STAT(obj,ITEM_MELT_DROP))
	{
	    act("$p dissolves into smoke.",ch,obj,NULL,TO_ROOM);
	    act("$p dissolves into smoke.",ch,obj,NULL,TO_CHAR);
	    extract_obj(obj);
	}

/*
   * End void do_drop ***********************************************************************
   */
   
/*
  * void do_give *****************************************************************************
  */
// After
    act( "$n gives $p to $N.", ch, obj, victim, TO_NOTVICT );
    act( "$n gives you $p.",   ch, obj, victim, TO_VICT    );
    act( "You give $p to $N.", ch, obj, victim, TO_CHAR    );
    MOBtrigger = TRUE;
// Add the following 4 lines
    if ( HAS_TRIGGER_OBJ( obj, TRIG_GIVE ) )
	p_give_trigger( NULL, obj, NULL, ch, obj, TRIG_GIVE );
    if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_GIVE ) )
	p_give_trigger( NULL, NULL, ch->in_room, ch, obj, TRIG_GIVE );
/*
  * End void do_give *************************************************************************
  */
 
 /************************************************************************************************
  *                                              End act_obj.c                                                          *
  ************************************************************************************************/
  
  /************************************************************************************************
  *                                                   comm.c                                                              *
  ************************************************************************************************/

/*
  * void act_new *****************************************************************************
  */
 // After
         pbuff    = buffer;
        colourconv( pbuff, buf, to );
        write_to_buffer( to->desc, buffer, 0 );
        }
 	else
	if ( MOBtrigger )
	    p_act_trigger( buf, to, NULL, NULL, ch, NULL, NULL, TRIG_ACT );
    }

// Add the following 35 lines
    if ( type == TO_ROOM || type == TO_NOTVICT )
    {
	OBJ_DATA *obj, *obj_next;
	CHAR_DATA *tch, *tch_next;

	 point   = buf;
	 str     = format;
	 while( *str != '\0' )
	 {
	     *point++ = *str++;
	 }
	 *point   = '\0';
	 
	for( obj = ch->in_room->contents; obj; obj = obj_next )
	{
	    obj_next = obj->next_content;
	    if ( HAS_TRIGGER_OBJ( obj, TRIG_ACT ) )
		p_act_trigger( buf, NULL, obj, NULL, ch, NULL, NULL, TRIG_ACT );
	}

	for( tch = ch; tch; tch = tch_next )
	{
	    tch_next = tch->next_in_room;

	    for ( obj = tch->carrying; obj; obj = obj_next )
	    {
		obj_next = obj->next_content;
		if ( HAS_TRIGGER_OBJ( obj, TRIG_ACT ) )
		    p_act_trigger( buf, NULL, obj, NULL, ch, NULL, NULL, TRIG_ACT );
	    }
	}

	 if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_ACT ) )
	     p_act_trigger( buf, NULL, NULL, ch->in_room, ch, NULL, NULL, TRIG_ACT );
    }
  
  /************************************************************************************************
  *                                                End comm.c                                                            *
  ************************************************************************************************/
  
/************************************************************************************************
  *                                                     db.c                                                                 *
  ************************************************************************************************/

// In the globals section, find
PROG_CODE *		mprog_list;
// Add the following 2 lines after it
PROG_CODE *             oprog_list;
PROG_CODE *             rprog_list;

// In the Locals area add the following 2 lines
int                     top_oprog_index;
int                     top_rprog_index; 

// In the local booting procedures section, add the following 4 lines
void load_objprogs		args(( FILE *fp ));
void load_roomprogs	args(( FILE *fp ));
void fix_objprogs    		args( ( void ) );
void fix_roomprogs   	args( ( void ) );

/*
 * void boot_db *************************************************************
 */
//  under
else if ( !str_cmp( word, "MOBPROGS" ) ) load_mobprogs(fpArea);
// add the following 2 lines
else if ( !str_cmp( word, "OBJPROGS" ) ) load_objprogs(fpArea);
else if ( !str_cmp( word, "ROOMPROGS") ) load_roomprogs(fpArea);
		
// Find the fix up exits part and add the following 2 lines
fix_objprogs( );
fix_roomprogs( );

/*
 * End void boot_db ************************************************************
 */

/*
 * void load_rooms *************************************************************
 */

// Find the following
	    else if (letter == 'O')
	    {
		if (pRoomIndex->owner[0] != '\0')
		{
		    bug("Load_rooms: duplicate owner.",0);
		    exit(1);
		}

		pRoomIndex->owner = fread_string(fp);
	    }
// And add the following 20 lines after it
else if ( letter == 'R' )
	    {
		PROG_LIST *pRprog;
		char *word;
		int trigger = 0;

		pRprog		= alloc_perm(sizeof(*pRprog));
		word		= fread_word( fp );
		if ( !(trigger = flag_lookup( word, rprog_flags )) )
		{
		    bug( "ROOMprogs: invalid trigger.",0);
		    exit(1);
		}
		SET_BIT( pRoomIndex->rprog_flags, trigger );
		pRprog->trig_type	= trigger;
		pRprog->vnum		= fread_number( fp );
		pRprog->trig_phrase	= fread_string( fp );
		pRprog->next		= pRoomIndex->rprogs;
		pRoomIndex->rprogs	= pRprog;
	    }

/*
 * End void load_rooms **********************************************************
 */
 
/*
 * void area_update **************************************************************
 */
 
// At the top of the function, right under 
    char buf[MAX_STRING_LENGTH];
// Add the following two lines
    int hash;
    ROOM_INDEX_DATA *room;


// Right before the last return in the function, add the following 17 lines
    /*
     * ROOMprog Triggers!
     */
    for ( hash = 0; hash < MAX_KEY_HASH; hash++ )
	for ( room = room_index_hash[hash]; room; room = room->next )
	{
	    if ( room->area->empty )
	    	continue;
	    	
	    if ( HAS_TRIGGER_ROOM( room, TRIG_DELAY ) && room->rprog_delay > 0 )
	    {
		if ( --room->rprog_delay <= 0 )
		    p_percent_trigger( NULL, NULL, room, NULL, NULL, NULL, TRIG_DELAY );
	    }
	    else if ( HAS_TRIGGER_ROOM( room, TRIG_RANDOM ) )
		p_percent_trigger( NULL, NULL, room, NULL, NULL, NULL, TRIG_RANDOM );
	}

/*
 * End void area_update *************************************************************
 */

// Replace your entire PROG_CODE *get_prog_index function with the following 26 lines
PROG_CODE *get_prog_index( int vnum, int type )
{
    PROG_CODE *prg;

    switch ( type )
    {
	case PRG_MPROG:
	    prg = mprog_list;
	    break;
	case PRG_OPROG:
	    prg = oprog_list;
	    break;
	case PRG_RPROG:
	    prg = rprog_list;
	    break;
	default:
	    return NULL;
    }

    for( ; prg; prg = prg->next )
    {
	if ( prg->vnum == vnum )
            return( prg );
    }
    return NULL;
}
// Add all remaining lines in the db.c section to the end of the file
void load_objprogs( FILE *fp )
{
    PROG_CODE *pOprog;

    if ( area_last == NULL )
    {
	bug( "Load_objprogs: no #AREA seen yet.", 0 );
	exit( 1 );
    }

    for ( ; ; )
    {
	sh_int vnum;
	char letter;

	letter		  = fread_letter( fp );
	if ( letter != '#' )
	{
	    bug( "Load_objprogs: # not found.", 0 );
	    exit( 1 );
	}

	vnum		 = fread_number( fp );
	if ( vnum == 0 )
	    break;

	fBootDb = FALSE;
	if ( get_prog_index( vnum, PRG_OPROG ) != NULL )
	{
	    bug( "Load_objprogs: vnum %d duplicated.", vnum );
	    exit( 1 );
	}
	fBootDb = TRUE;

	pOprog		= alloc_perm( sizeof(*pOprog) );
	pOprog->vnum  	= vnum;
	pOprog->code  	= fread_string( fp );
	if ( oprog_list == NULL )
	    oprog_list = pOprog;
	else
	{
	    pOprog->next = oprog_list;
	    oprog_list 	= pOprog;
	}
	top_oprog_index++;
    }
    return;
}

void load_roomprogs( FILE *fp )
{
    PROG_CODE *pRprog;

    if ( area_last == NULL )
    {
	bug( "Load_roomprogs: no #AREA seen yet.", 0 );
	exit( 1 );
    }

    for ( ; ; )
    {
	sh_int vnum;
	char letter;

	letter		  = fread_letter( fp );
	if ( letter != '#' )
	{
	    bug( "Load_roomprogs: # not found.", 0 );
	    exit( 1 );
	}

	vnum		 = fread_number( fp );
	if ( vnum == 0 )
	    break;

	fBootDb = FALSE;
	if ( get_prog_index( vnum, PRG_RPROG ) != NULL )
	{
	    bug( "Load_roomprogs: vnum %d duplicated.", vnum );
	    exit( 1 );
	}
	fBootDb = TRUE;

	pRprog		= alloc_perm( sizeof(*pRprog) );
	pRprog->vnum  	= vnum;
	pRprog->code  	= fread_string( fp );
	if ( rprog_list == NULL )
	    rprog_list = pRprog;
	else
	{
	    pRprog->next = rprog_list;
	    rprog_list 	= pRprog;
	}
	top_rprog_index++;
    }
    return;
}

void fix_objprogs( void )
{
    OBJ_INDEX_DATA *pObjIndex;
    PROG_LIST        *list;
    PROG_CODE        *prog;
    int iHash;

    for ( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )
    {
	for ( pObjIndex   = obj_index_hash[iHash];
	      pObjIndex   != NULL;
	      pObjIndex   = pObjIndex->next )
	{
	    for( list = pObjIndex->oprogs; list != NULL; list = list->next )
	    {
		if ( ( prog = get_prog_index( list->vnum, PRG_OPROG ) ) != NULL )
		    list->code = prog->code;
		else
		{
		    bug( "Fix_objprogs: code vnum %d not found.", list->vnum );
		    exit( 1 );
		}
	    }
	}
    }
}

void fix_roomprogs( void )
{
    ROOM_INDEX_DATA *pRoomIndex;
    PROG_LIST        *list;
    PROG_CODE        *prog;
    int iHash;

    for ( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )
    {
	for ( pRoomIndex   = room_index_hash[iHash];
	      pRoomIndex   != NULL;
	      pRoomIndex   = pRoomIndex->next )
	{
	    for( list = pRoomIndex->rprogs; list != NULL; list = list->next )
	    {
		if ( ( prog = get_prog_index( list->vnum, PRG_RPROG ) ) != NULL )
		    list->code = prog->code;
		else
		{
		    bug( "Fix_roomprogs: code vnum %d not found.", list->vnum );
		    exit( 1 );
		}
	    }
	}
    }
}

/************************************************************************************************
  *                                               End db.c                                                                *
  ************************************************************************************************/

/************************************************************************************************
  *                                                    db2.c                                                                 *
  ************************************************************************************************/

/* 
 * void load_objects ********************************************************************
 */

// Find the following section
            else if ( letter == 'E' )
            {
                EXTRA_DESCR_DATA *ed;
 
                ed                      = alloc_perm( sizeof(*ed) );
                ed->keyword             = fread_string( fp );
                ed->description         = fread_string( fp );
                ed->next                = pObjIndex->extra_descr;
                pObjIndex->extra_descr  = ed;
                top_ed++;
            }
// And add the following 20 lines after it
	    else if ( letter == 'O' )
	    {
		PROG_LIST *pOprog;
		char *word;
		int trigger = 0;

		pOprog			= alloc_perm(sizeof(*pOprog));
		word			= fread_word( fp );
		if ( !(trigger = flag_lookup( word, oprog_flags )) )
		{
		    bug( "OBJprogs: invalid trigger.",0);
		    exit(1);
		}
		SET_BIT( pObjIndex->oprog_flags, trigger );
		pOprog->trig_type	= trigger;
		pOprog->vnum	 	= fread_number( fp );
		pOprog->trig_phrase	= fread_string( fp );
		pOprog->next		= pObjIndex->oprogs;
		pObjIndex->oprogs	= pOprog;
	    }
	    
/************************************************************************************************
  *                                              End db2.c                                                                *
  ************************************************************************************************/

/************************************************************************************************
  *                                                   fight.c                                                                 *
  ************************************************************************************************/

 /*
   * void violence_update *******************************************************************
   */
 
 // After
CHAR_DATA *victim;
 // Add the following 2 line
     OBJ_DATA *obj, *obj_next;
     bool room_trig = FALSE;
     
 // After
 check_assist(ch,victim);
 
  	if ( IS_NPC( ch ) )
	{
	    if ( HAS_TRIGGER_MOB( ch, TRIG_FIGHT ) )
		p_percent_trigger( ch, NULL, NULL, victim, NULL, NULL, TRIG_FIGHT );
	    if ( HAS_TRIGGER_MOB( ch, TRIG_HPCNT ) )
		p_hprct_trigger( ch, victim );
	}
 // Add the following 13 lines
	for ( obj = ch->carrying; obj; obj = obj_next )
	{
	    obj_next = obj->next_content;

	    if ( obj->wear_loc != WEAR_NONE && HAS_TRIGGER_OBJ( obj, TRIG_FIGHT ) )
		p_percent_trigger( NULL, obj, NULL, victim, NULL, NULL, TRIG_FIGHT );
	}

	if ( HAS_TRIGGER_ROOM( ch->in_room, TRIG_FIGHT ) && room_trig == FALSE )
	{
	    room_trig = TRUE;
	    p_percent_trigger( NULL, NULL, ch->in_room, victim, NULL, NULL, TRIG_FIGHT );
	}

/*
   * End void violence_update ***************************************************************
   */

/************************************************************************************************
  *                                                End fight.c                                                             *
  ************************************************************************************************/
  
/************************************************************************************************
  *                                                    handler.c                                                           *
  ************************************************************************************************/
  
// Replace your entire get_char_room function with this one
CHAR_DATA *get_char_room( CHAR_DATA *ch, ROOM_INDEX_DATA *room, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *rch;
    int number;
    int count;

    number = number_argument( argument, arg );
    count  = 0;
    if ( !str_cmp( arg, "self" ) )
	return ch;

    if ( ch && room )
    {
	bug( "get_char_room received multiple types (ch/room)", 0 );
	return NULL;
    }

    if ( ch )
	rch = ch->in_room->people;
    else
	rch = room->people;

    for ( ; rch != NULL; rch = rch->next_in_room )
    {
	if ( (ch && !can_see( ch, rch )) || !is_name( arg, rch->name ) )
	    continue;
	if ( ++count == number )
	    return rch;
    }

    return NULL;
}

// Replace your entire get_char_world function with this one
CHAR_DATA *get_char_world( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *wch;
    int number;
    int count;

    if ( ch && ( wch = get_char_room( ch, NULL, argument ) ) != NULL )
	return wch;

    number = number_argument( argument, arg );
    count  = 0;
    for ( wch = char_list; wch != NULL ; wch = wch->next )
    {
	if ( wch->in_room == NULL || ( ch && !can_see( ch, wch ) ) 
	||   !is_name( arg, wch->name ) )
	    continue;
	if ( ++count == number )
	    return wch;
    }

    return NULL;
}

// Replace your entire get_obj_carry function with this one
OBJ_DATA *get_obj_carry( CHAR_DATA *ch, char *argument, CHAR_DATA *viewer )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int number;
    int count;

    number = number_argument( argument, arg );
    count  = 0;
    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( obj->wear_loc == WEAR_NONE
        &&   ( viewer ? can_see_obj( viewer, obj ) : TRUE )
        &&   is_name( arg, obj->name ) )
        {
            if ( ++count == number )
                            return obj;
        }
    }

    return NULL;
}

// Replace your entire get_obj_wear function with this one
OBJ_DATA *get_obj_wear( CHAR_DATA *ch, char *argument, bool character )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int number;
    int count;

    number = number_argument( argument, arg );
    count  = 0;
    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( obj->wear_loc != WEAR_NONE
                &&  ( character ? can_see_obj( ch, obj ) : TRUE)
        &&   is_name( arg, obj->name ) )
        {
            if ( ++count == number )
                return obj;
        }
    }

    return NULL;
}

// Replace your entire get_obj_here function with this one
OBJ_DATA *get_obj_here( CHAR_DATA *ch, ROOM_INDEX_DATA *room, char *argument )
{
    OBJ_DATA *obj;
    int number, count;
    char arg[MAX_INPUT_LENGTH];

    if ( ch && room )
    {
	bug( "get_obj_here received a ch and a room",0);
	return NULL;
    }

    number = number_argument( argument, arg );
    count = 0;

    if ( ch )
    {
	obj = get_obj_list( ch, argument, ch->in_room->contents );
	if ( obj != NULL )
	    return obj;

	if ( ( obj = get_obj_carry( ch, argument, ch ) ) != NULL )
	    return obj;

	if ( ( obj = get_obj_wear( ch, argument, TRUE ) ) != NULL )
	    return obj;
    }
    else
    {
	for ( obj = room->contents; obj; obj = obj->next_content )
	{
	    if ( !is_name( arg, obj->name ) )
		continue;
	    if ( ++count == number )
		return obj;
	}
    }

    return NULL;
}

// Replace your entire get_obj_world function with this one
OBJ_DATA *get_obj_world( CHAR_DATA *ch, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int number;
    int count;

    if ( ch && ( obj = get_obj_here( ch, NULL, argument ) ) != NULL )
	return obj;

    number = number_argument( argument, arg );
    count  = 0;
    for ( obj = object_list; obj != NULL; obj = obj->next )
    {
	if ( ( ch && !can_see_obj( ch, obj ) )
	|| !is_name( arg, obj->name ) )
	    continue;
	if ( ++count == number )
	    return obj;
    }

    return NULL;
}

/************************************************************************************************
  *                                                End handler.c                                                        *
  ************************************************************************************************/

/************************************************************************************************
  *                                                  interp.c                                                                *
  ************************************************************************************************/
// add the following 7 lines in the immortal commands section
    { "opedit",         do_opedit,      POS_DEAD,   L6,  LOG_ALWAYS, 1 },
    { "rpedit",         do_rpedit,      POS_DEAD,   L6,  LOG_ALWAYS, 1 },
    { "opdump",		do_opdump,	POS_DEAD,	IM,  LOG_NEVER,  1 },
    { "opstat",		do_opstat,	POS_DEAD,	IM,  LOG_NEVER,  1 },
    { "rpdump",		do_rpdump,	POS_DEAD,	IM,  LOG_NEVER,  1 },
    { "rpstat",		do_rpstat,	POS_DEAD,	IM,  LOG_NEVER,  1 },

/************************************************************************************************
  *                                               End interp.c                                                           *
  ************************************************************************************************/

/************************************************************************************************
  *                                                  interp.h                                                                *
  ************************************************************************************************/

// add the following 6 lines in the command functions section
DECLARE_DO_FUN( do_opedit );
DECLARE_DO_FUN( do_rpedit );
DECLARE_DO_FUN( do_opdump );
DECLARE_DO_FUN( do_opstat );
DECLARE_DO_FUN( do_rpdump );
DECLARE_DO_FUN( do_rpstat );

/************************************************************************************************
  *                                              End interp.h                                                            *
  ************************************************************************************************/

/************************************************************************************************
  *                                                   mem.c                                                                *
  ************************************************************************************************/

// In the Globals section, add the following 4 lines
extern		int			top_oprog_index;
extern		int			top_rprog_index;
void    free_oprog              args ( ( PROG_LIST *op ) );
void    free_rprog              args ( ( PROG_LIST *rp ) );

/*
  *  void free_room_index ********************************************************************
  */
// After
free_string( pRoom->owner );
// Add the following line
free_rprog( pRoom->rprogs );

/*
 * End void free_room_index ********************************************************************
 */
 
/*
 * void free_obj_index  ********************************************************************
 */
// After
free_string( pObj->description );
// Add the following line
free_oprog( pObj->oprogs );

/*
 * End void free_obj_index ********************************************************************
 */
 
// After
PROG_CODE              *       mpcode_free;
// Add the following 2 lines
PROG_CODE	       *       opcode_free;
PROG_CODE	       *       rpcode_free;

// Add all remaning lines in this mem.c section to the end of the file
PROG_CODE *new_opcode(void)
{
     PROG_CODE *NewCode;

     if (!rpcode_free)
     {
         NewCode = alloc_perm(sizeof(*NewCode) );
         top_oprog_index++;
     }
     else
     {
         NewCode     = opcode_free;
         opcode_free = opcode_free->next;
     }

     NewCode->vnum    = 0;
     NewCode->code    = str_dup("");
     NewCode->next    = NULL;

     return NewCode;
}

PROG_CODE *new_rpcode(void)
{
     PROG_CODE *NewCode;

     if (!rpcode_free)
     {
         NewCode = alloc_perm(sizeof(*NewCode) );
         top_rprog_index++;
     }
     else
     {
         NewCode     = rpcode_free;
         rpcode_free = rpcode_free->next;
     }

     NewCode->vnum    = 0;
     NewCode->code    = str_dup("");
     NewCode->next    = NULL;

     return NewCode;
}

void free_opcode(PROG_CODE *pOcode)
{
    free_string(pOcode->code);
    pOcode->next = opcode_free;
    opcode_free  = pOcode;
    return;
}

void free_rpcode(PROG_CODE *pRcode)
{
    free_string(pRcode->code);
    pRcode->next = rpcode_free;
    rpcode_free  = pRcode;
    return;
}

/************************************************************************************************
  *                                                End mem.c                                                           *
  ************************************************************************************************/

/************************************************************************************************
  *                                                     merc.h                                                              *
  ************************************************************************************************/
  
// Right after
#if defined(TRADITIONAL)
// Add the following 2 lines
#define DECLARE_OBJ_FUN( fun )		void fun( )
#define DECLARE_ROOM_FUN( fun )		void fun( )
// Right after
#define args( list )			list
#define DECLARE_DO_FUN( fun )		DO_FUN    fun
#define DECLARE_SPEC_FUN( fun )		SPEC_FUN  fun
#define DECLARE_SPELL_FUN( fun )	SPELL_FUN fun
// Add the following 2 lines
#define DECLARE_OBJ_FUN( fun )		OBJ_FUN	  fun
#define DECLARE_ROOM_FUN( fun )		ROOM_FUN  fun

// Find
typedef struct  mprog_list               	MPROG_LIST;
typedef struct  mprog_code             MPROG_CODE;
// And replace with the following 2 lines
typedef struct  prog_list               	PROG_LIST;
typedef struct  prog_code               PROG_CODE;

// In the function types section, add the following 2 lines
typedef void OBJ_FUN	args( ( OBJ_DATA *obj, char *argument ) );
typedef void ROOM_FUN	args( ( ROOM_INDEX_DATA *room, char *argument ) );

// Right after
TRIG_SURR			(P)
// Add the following 9 lines
#define TRIG_GET		(Q)
#define TRIG_DROP	(R)
#define TRIG_SIT	(S)

/*
 * Prog types
 */
#define PRG_MPROG	0
#define PRG_OPROG	1
#define PRG_RPROG	2

// Find
struct mprog_list
{
    int                 trig_type;
    char *              trig_phrase;
    sh_int              vnum;
    char *              code;
    MPROG_LIST *         next;
    bool                valid;
};

struct mprog_code
{
    sh_int              vnum;
    char *              code;
    MPROG_CODE *         next;
}; 

// And replace with the following 16 lines
struct prog_list
{
    int                 trig_type;
    char *              trig_phrase;
    sh_int              vnum;
    char *              code;
    PROG_LIST *         next;
    bool                valid;
};

struct prog_code
{
    sh_int              vnum;
    char *              code;
    PROG_CODE *         next;
}; 

/*
  * struct mob_index_data ***************************************************
  */
// Find
MPROG_LIST *	mprogs;
// And replace with the following lines
PROG_LIST *		mprogs;

/*
  * End struct mob_index_data *********************************************
  */

/*
  * struct obj_index_data *****************************************************
  */
// Add the following 2 lines
PROG_LIST *		oprogs;
 long		oprog_flags;

/*
  * End struct obj_index_data ************************************************
  */

/*
  * struct obj_data **************************************************************
  */
// Add the following 2 lines
CHAR_DATA *	oprog_target;
sh_int			oprog_delay;

/*
  * End struct obj_data *********************************************************
  */

/*
  * struct room_index_data *****************************************************
  */
// Add the following 4 lines
    PROG_LIST *		rprogs;
    CHAR_DATA *		rprog_target;
    long		rprog_flags;
    sh_int		rprog_delay;

/*
  * End struct room_index_data ************************************************
  */
// After
#define HAS_TRIGGER_MOB(ch,trig) (IS_SET((ch)->pIndexData->mprog_flags,(trig)))
 // Add the following 2 lines
#define HAS_TRIGGER_OBJ(obj,trig) (IS_SET((obj)->pIndexData->oprog_flags,(trig)))
#define HAS_TRIGGER_ROOM(room,trig) (IS_SET((room)->rprog_flags,(trig)))

// In the global variables section, find
extern	   MPROG_CODE	  *	mprog_list;
// And replace with the following 3 lines
extern          PROG_CODE         *     mprog_list;
extern          PROG_CODE         *     rprog_list;
extern          PROG_CODE         *     oprog_list;

// Find
PC *    get_mprog_index args( ( int vnum ) );
// And replace it with the following line
PC *    get_prog_index args( ( int vnum, int type ) );

// Find
CD *	get_char_room		args( ( CHAR_DATA *ch, char *argument ) );
// And replace it with
CD *	get_char_room		args( ( CHAR_DATA *ch, ROOM_INDEX_DATA *room, char *argument ) );

// Find
OD *	get_obj_here	args( ( CHAR_DATA *ch, char *argument ) );
// And replace it with
OD *	get_obj_here	args( ( CHAR_DATA *ch, ROOM_INDEX_DATA *room, char *argument ) );

// Find
OD *get_obj_wear	args( ( CHAR_DATA *ch, char *argument ) );
// And replace it with
OD *get_obj_wear	args( ( CHAR_DATA *ch, char *argument, bool character ));


// Find
/* mob_prog.c */
void	program_flow	args( ( sh_int vnum, char *source, CHAR_DATA *mob, 
				CHAR_DATA *ch, const void *arg1,
				const void *arg2 ) );
void	mp_act_trigger	args( ( char *argument, CHAR_DATA *mob, 
				CHAR_DATA *ch, const void *arg1,
				const void *arg2, int type ) );
bool	mp_percent_trigger args( ( CHAR_DATA *mob,
				CHAR_DATA *ch, 
				const void *arg1, const void *arg2, int type ) );
void	mp_bribe_trigger  args( ( CHAR_DATA *mob, CHAR_DATA *ch, int amount ) );
bool	mp_exit_trigger   args( ( CHAR_DATA *ch, int dir ) );
void	mp_give_trigger   args( ( CHAR_DATA *mob,
				CHAR_DATA *ch,
				OBJ_DATA *dropped, int type ) );
void 	mp_greet_trigger  args( ( CHAR_DATA *ch ) );
void	mp_hprct_trigger  args( ( CHAR_DATA *mob, CHAR_DATA *ch ) );
// And replace it with the following 19 lines
/* mob_prog.c */
void	program_flow	args( ( sh_int vnum, char *source, CHAR_DATA *mob, 
				OBJ_DATA *obj, ROOM_INDEX_DATA *room,
				CHAR_DATA *ch, const void *arg1,
				const void *arg2 ) );
void	p_act_trigger	args( ( char *argument, CHAR_DATA *mob, 
				OBJ_DATA *obj, ROOM_INDEX_DATA *room,
				CHAR_DATA *ch, const void *arg1,
				const void *arg2, int type ) );
bool	p_percent_trigger args( ( CHAR_DATA *mob, OBJ_DATA *obj,
				ROOM_INDEX_DATA *room, CHAR_DATA *ch, 
				const void *arg1, const void *arg2, int type ) );
void	p_bribe_trigger  args( ( CHAR_DATA *mob, CHAR_DATA *ch, int amount ) );
bool	p_exit_trigger   args( ( CHAR_DATA *ch, int dir, int type ) );
void	p_give_trigger   args( ( CHAR_DATA *mob, OBJ_DATA *obj, 
				ROOM_INDEX_DATA *room, CHAR_DATA *ch,
				OBJ_DATA *dropped, int type ) );
void 	p_greet_trigger  args( ( CHAR_DATA *ch, int type ) );
void	p_hprct_trigger  args( ( CHAR_DATA *mob, CHAR_DATA *ch ) );

// Under
void mob_interpret	args( ( CHAR_DATA *ch, char *argument ) );
// Add the following 2 lines
void	obj_interpret	args( ( OBJ_DATA *obj, char *argument ) );
void room_interpret	args( ( ROOM_INDEX_DATA *room, char *argument ) );

/************************************************************************************************
  *                                                   End merc.h                                                         *
  ************************************************************************************************/
  
/************************************************************************************************
  *                                                      olc.c                                                               *
  ************************************************************************************************/

/*
  *  bool run_olc_editor **********************************************************************
  */

// Right after
    case ED_MPCODE:
    	mpedit( d->character, d->incomm );
    	break;
// Add the following 6 lines
    case ED_OPCODE:
	opedit( d->character, d->incomm );
	break;
    case ED_RPCODE:
	rpedit( d->character, d->incomm );
	break;

/*
  *  End bool run_olc_editor ******************************************************************
  */
  
/*
  *  char *olc_ed_name **********************************************************************
  */
// Right after
    case ED_MPCODE:
    	sprintf( buf, "MPEdit" );
	break;
// Add the following 6 lines
  case ED_OPCODE:
	sprintf( buf, "OPEdit" );
	break;
    case ED_RPCODE:
	sprintf( buf, "RPEdit" );
	break;

/*
  *  End char *olc_ed_name *****************************************************************
  */

/*
  *  char *olc_ed_vnum **********************************************************************
  */
// Right below
PROG_CODE *pMprog;
// Add the following 2 lines
PROG_CODE *pOprog;
PROG_CODE *pRprog;
    
// Right after
    case ED_MPCODE:
    	pMprog = (PROG_CODE *)ch->desc->pEdit;
    	sprintf( buf, "%d", pMprog ? pMprog->vnum : 0 );
	break;
// Add the following 7 lines
    case ED_OPCODE:
	pOprog = (PROG_CODE *)ch->desc->pEdit;
	sprintf( buf, "%d", pOprog ? pOprog->vnum : 0 );
	break;
    case ED_RPCODE:
	pRprog = (PROG_CODE *)ch->desc->pEdit;
	sprintf( buf, "%d", pRprog ? pRprog->vnum : 0 );
	break;

/*
  *  End char *olc_ed_vnum ******************************************************************
  */

/*
  *  bool show_commands ********************************************************************
  */
  
// Right after
	case ED_MPCODE:
	    show_olc_cmds( ch, mpedit_table );
	    break;
// Add the following 6 lines
	case ED_OPCODE:
	    show_olc_cmds( ch, opedit_table );
	    break;
	case ED_RPCODE:
	    show_olc_cmds( ch, rpedit_table );
	    break;

/*
  *  End bool show_commands ****************************************************************
  */

/*
  *  const struct olc_cmd_type redit_table[] **************************************************
  */
// Add following 2 lines
    {	"addrprog",	redit_addrprog	},
    {	"delrprog",	redit_delrprog	},

/*
  *  End const struct olc_cmd_type redit_table[] **********************************************
  */

/*
  *  const struct olc_cmd_type oedit_table[] ***************************************************
  */

// Add following 2 lines
    {	"addoprog",	oedit_addoprog	},
    {	"deloprog",	oedit_deloprog	},

/*
  *  End const struct olc_cmd_type oedit_table[] **********************************************
  */

/*
  *  const struct editor_cmd_type editor_table[] **************************************************
  */
//  Add following 2 lines
    {	"opcode",	do_opedit	},
    {	"rpcode",	do_rpedit	},

/*
  *  End const struct editor_cmd_type editor_table[] **********************************************
  */

/************************************************************************************************
  *                                                   End olc.c                                                           *
  ************************************************************************************************/

/************************************************************************************************
  *                                                       olc.h                                                               *
  ************************************************************************************************/

// After
#define ED_MPCODE       5
// Add the following 2 lines
#define ED_OPCODE       6
#define ED_RPCODE       7

// In the interpreter prototypes section, add the following 2 lines
void    opedit          args( ( CHAR_DATA *ch, char *argument ) );
void    rpedit          args( ( CHAR_DATA *ch, char *argument ) );

// In the interpreter table prototypes section, add the following 2 lines
extern const struct olc_cmd_type        opedit_table[];
extern const struct olc_cmd_type        rpedit_table[];

// In the editor commands section, add the following 2 lines
DECLARE_DO_FUN( do_opedit       );
DECLARE_DO_FUN( do_rpedit       ); 

// In the room editor prototypes section, add the following 2 lines
DECLARE_OLC_FUN( redit_addrprog		);
DECLARE_OLC_FUN( redit_delrprog		);

// In the object editor prototypes section, add the following 2 lines
DECLARE_OLC_FUN( oedit_addoprog		);
DECLARE_OLC_FUN( oedit_deloprog		);

// In the macros section, add the following 2 lines
#define EDIT_OPCODE(Ch, Code)   ( Code = (PROG_CODE*)Ch->desc->pEdit )
#define EDIT_RPCODE(Ch, Code)   ( Code = (PROG_CODE*)Ch->desc->pEdit )

// Find
char *          mprog_type_to_name       args ( ( int type ) );
// And replace it with the following line
char *          prog_type_to_name       args ( ( int type ) );

// In the prototypes section, add the following 8 lines
PROG_LIST	*new_oprog		args ( ( void ) );
void		free_oprog		args ( ( PROG_LIST *op ) );
PROG_LIST	*new_rprog		args ( ( void ) );
void		free_rprog		args ( ( PROG_LIST *rp ) );
PROG_CODE	*new_opcode		args ( ( void ) );
void		free_opcode		args ( ( PROG_CODE *pOcode ) );
PROG_CODE	*new_rpcode		args ( ( void ) );
void		free_rpcode		args ( ( PROG_CODE *pRcode ) );

// Add all remaining lines in this olc.h section to the end of the file.
/* Objprog editor */
DECLARE_OLC_FUN( opedit_create		);
DECLARE_OLC_FUN( opedit_code		);
DECLARE_OLC_FUN( opedit_show		);
DECLARE_OLC_FUN( opedit_list		);

/* Roomprog editor */
DECLARE_OLC_FUN( rpedit_create		);
DECLARE_OLC_FUN( rpedit_code		);
DECLARE_OLC_FUN( rpedit_show		);
DECLARE_OLC_FUN( rpedit_list		);

/************************************************************************************************
  *                                                    End olc.h                                                           *
  ************************************************************************************************/
  
/************************************************************************************************
  *                                                    olc_act.c                                                           *
  ************************************************************************************************/

/*
 * const struct olc_help_type help_table[] = **********************************************
 */
 
// Add following 2 lines
    {	"oprog",	oprog_flags,	 "ObjProgram flags."		 },
    {	"rprog",	rprog_flags,	 "RoomProgram flags."		 },

/*
 * End const struct olc_help_type help_table[] = ******************************************
 */

/*
 * REDIT( redit_show ) ***********************************************************************
 */
 
 // After
 CHAR_DATA		*rch;
 // Add the following line
 PROG_LIST		*list;
 
 // Right before the last
return FALSE;
// Add the following 22 lines
    if ( pRoom->rprogs )
    {
	int cnt;

	sprintf(buf, "\n\rROOMPrograms for [%5d]:\n\r", pRoom->vnum);
	send_to_char( buf, ch );

	for (cnt=0, list=pRoom->rprogs; list; list=list->next)
	{
		if (cnt ==0)
		{
			send_to_char ( " Number Vnum Trigger Phrase\n\r", ch );
			send_to_char ( " ------ ---- ------- ------\n\r", ch );
		}

		sprintf(buf, "[%5d] %4d %7s %s\n\r", cnt,
			list->vnum,prog_type_to_name(list->trig_type),
			list->trig_phrase);
		send_to_char( buf, ch );
		cnt++;
	}
    }

/*
 * End REDIT( redit_show ) *******************************************************************
 */

/*
 * OEDIT( oedit_show ) ***********************************************************************
 */

// After
AFFECT_DATA		*paf;
// Add the following line
PROG_LIST			*list;

// Right before the last
return FALSE;
// Add the following 22 lines
    if ( pObj->oprogs )
    {
	int cnt;

	sprintf(buf, "\n\rOBJPrograms for [%5d]:\n\r", pObj->vnum);
	send_to_char( buf, ch );

	for (cnt=0, list=pObj->oprogs; list; list=list->next)
	{
		if (cnt ==0)
		{
			send_to_char ( " Number Vnum Trigger Phrase\n\r", ch );
			send_to_char ( " ------ ---- ------- ------\n\r", ch );
		}

		sprintf(buf, "[%5d] %4d %7s %s\n\r", cnt,
			list->vnum,prog_type_to_name(list->trig_type),
			list->trig_phrase);
		send_to_char( buf, ch );
		cnt++;
	}
    }
 
 /*
 * End OEDIT( oedit_show ) *****************************************************************
 */
 
// Add all remaining lines in this olc_act.c section to the end of the file
OEDIT ( oedit_addoprog )
{
  int value;
  OBJ_INDEX_DATA *pObj;
  PROG_LIST *list;
  PROG_CODE *code;
  char trigger[MAX_STRING_LENGTH];
  char phrase[MAX_STRING_LENGTH];
  char num[MAX_STRING_LENGTH];

  EDIT_OBJ(ch, pObj);
  argument=one_argument(argument, num);
  argument=one_argument(argument, trigger);
  argument=one_argument(argument, phrase);

  if (!is_number(num) || trigger[0] =='\0' || phrase[0] =='\0' )
  {
        send_to_char("Syntax:   addoprog [vnum] [trigger] [phrase]\n\r",ch);
        return FALSE;
  }

  if ( (value = flag_value (oprog_flags, trigger) ) == NO_FLAG)
  {
        send_to_char("Valid flags are:\n\r",ch);
        show_help( ch, "oprog");
        return FALSE;
  }

  if ( ( code =get_prog_index (atoi(num), PRG_OPROG ) ) == NULL)
  {
        send_to_char("No such OBJProgram.\n\r",ch);
        return FALSE;
  }

  list                  = new_oprog();
  list->vnum            = atoi(num);
  list->trig_type       = value;
  list->trig_phrase     = str_dup(phrase);
  list->code            = code->code;
  SET_BIT(pObj->oprog_flags,value);
  list->next            = pObj->oprogs;
  pObj->oprogs          = list;

  send_to_char( "Oprog Added.\n\r",ch);
  return TRUE;
}

OEDIT ( oedit_deloprog )
{
    OBJ_INDEX_DATA *pObj;
    PROG_LIST *list;
    PROG_LIST *list_next;
    char oprog[MAX_STRING_LENGTH];
    int value;
    int cnt = 0;

    EDIT_OBJ(ch, pObj);

    one_argument( argument, oprog );
    if (!is_number( oprog ) || oprog[0] == '\0' )
    {
       send_to_char("Syntax:  deloprog [#oprog]\n\r",ch);
       return FALSE;
    }

    value = atoi ( oprog );

    if ( value < 0 )
    {
        send_to_char("Only non-negative oprog-numbers allowed.\n\r",ch);
        return FALSE;
    }

    if ( !(list= pObj->oprogs) )
    {
        send_to_char("OEdit:  Non existant oprog.\n\r",ch);
        return FALSE;
    }

    if ( value == 0 )
    {
	REMOVE_BIT(pObj->oprog_flags, pObj->oprogs->trig_type);
        list = pObj->oprogs;
        pObj->oprogs = list->next;
        free_oprog( list );
    }
    else
    {
        while ( (list_next = list->next) && (++cnt < value ) )
                list = list_next;

        if ( list_next )
        {
		REMOVE_BIT(pObj->oprog_flags, list_next->trig_type);
                list->next = list_next->next;
                free_oprog(list_next);
        }
        else
        {
                send_to_char("No such oprog.\n\r",ch);
                return FALSE;
        }
    }

    send_to_char("Oprog removed.\n\r", ch);
    return TRUE;
}

REDIT ( redit_addrprog )
{
  int value;
  ROOM_INDEX_DATA *pRoom;
  PROG_LIST *list;
  PROG_CODE *code;
  char trigger[MAX_STRING_LENGTH];
  char phrase[MAX_STRING_LENGTH];
  char num[MAX_STRING_LENGTH];

  EDIT_ROOM(ch, pRoom);
  argument=one_argument(argument, num);
  argument=one_argument(argument, trigger);
  argument=one_argument(argument, phrase);

  if (!is_number(num) || trigger[0] =='\0' || phrase[0] =='\0' )
  {
        send_to_char("Syntax:   addrprog [vnum] [trigger] [phrase]\n\r",ch);
        return FALSE;
  }

  if ( (value = flag_value (rprog_flags, trigger) ) == NO_FLAG)
  {
        send_to_char("Valid flags are:\n\r",ch);
        show_help( ch, "rprog");
        return FALSE;
  }

  if ( ( code =get_prog_index (atoi(num), PRG_RPROG ) ) == NULL)
  {
        send_to_char("No such ROOMProgram.\n\r",ch);
        return FALSE;
  }

  list                  = new_rprog();
  list->vnum            = atoi(num);
  list->trig_type       = value;
  list->trig_phrase     = str_dup(phrase);
  list->code            = code->code;
  SET_BIT(pRoom->rprog_flags,value);
  list->next            = pRoom->rprogs;
  pRoom->rprogs          = list;

  send_to_char( "Rprog Added.\n\r",ch);
  return TRUE;
}

REDIT ( redit_delrprog )
{
    ROOM_INDEX_DATA *pRoom;
    PROG_LIST *list;
    PROG_LIST *list_next;
    char rprog[MAX_STRING_LENGTH];
    int value;
    int cnt = 0;

    EDIT_ROOM(ch, pRoom);

    one_argument( argument, rprog );
    if (!is_number( rprog ) || rprog[0] == '\0' )
    {
       send_to_char("Syntax:  delrprog [#rprog]\n\r",ch);
       return FALSE;
    }

    value = atoi ( rprog );

    if ( value < 0 )
    {
        send_to_char("Only non-negative rprog-numbers allowed.\n\r",ch);
        return FALSE;
    }

    if ( !(list= pRoom->rprogs) )
    {
        send_to_char("REdit:  Non existant rprog.\n\r",ch);
        return FALSE;
    }

    if ( value == 0 )
    {
	REMOVE_BIT(pRoom->rprog_flags, pRoom->rprogs->trig_type);
        list = pRoom->rprogs;
        pRoom->rprogs = list->next;
        free_rprog( list );
    }
    else
    {
        while ( (list_next = list->next) && (++cnt < value ) )
                list = list_next;

        if ( list_next )
        {
		REMOVE_BIT(pRoom->rprog_flags, list_next->trig_type);
                list->next = list_next->next;
                free_rprog(list_next);
        }
        else
        {
                send_to_char("No such rprog.\n\r",ch);
                return FALSE;
        }
    }

    send_to_char("Rprog removed.\n\r", ch);
    return TRUE;
}

/************************************************************************************************
  *                                                End olc_act.c                                                       *
  ************************************************************************************************/

/************************************************************************************************
  *                                                  olc_save.c                                                          *
  ************************************************************************************************/

// Right before
/*****************************************************************************
 Name:          save_mobile
 Purpose:       Save one mobile to file, new format -- Hugin
 Called by:     save_mobiles (below).
 ****************************************************************************/ 
// Add the following 39 lines

void save_objprogs( FILE *fp, AREA_DATA *pArea )
{
	PROG_CODE *pOprog;
        int i;

        fprintf(fp, "#OBJPROGS\n");

	for( i = pArea->min_vnum; i <= pArea->max_vnum; i++ )
        {
          if ( (pOprog = get_prog_index(i, PRG_OPROG) ) != NULL)
		{
		          fprintf(fp, "#%d\n", i);
		          fprintf(fp, "%s~\n", fix_string(pOprog->code));
		}
        }

        fprintf(fp,"#0\n\n");
        return;
}

void save_roomprogs( FILE *fp, AREA_DATA *pArea )
{
	PROG_CODE *pRprog;
        int i;

        fprintf(fp, "#ROOMPROGS\n");

	for( i = pArea->min_vnum; i <= pArea->max_vnum; i++ )
        {
          if ( (pRprog = get_prog_index(i,PRG_RPROG) ) != NULL)
		{
		          fprintf(fp, "#%d\n", i);
		          fprintf(fp, "%s~\n", fix_string(pRprog->code));
		}
        }

        fprintf(fp,"#0\n\n");
        return;
}

/*
  * void save_area ***************************************************************************
  */
// After
    save_mobprogs( fp, pArea );
// Add the following 2 lines
    save_objprogs( fp, pArea );
    save_roomprogs( fp, pArea );

/*
  * End void save_area **********************************************************************
  */

/*
  * void save_object *************************************************************************
  */
// After
char buf[MAX_STRING_LENGTH];
// Add the following line
PROG_LIST *pOprog;

// Before the last
return;
// Add the following 6 lines
    for (pOprog = pObjIndex->oprogs; pOprog; pOprog = pOprog->next)
    {
        fprintf(fp, "O %s %d %s~\n",
        prog_type_to_name(pOprog->trig_type), pOprog->vnum,
                pOprog->trig_phrase);
    }

/*
  * End void save_object *********************************************************************
  */

/*
  * void save_rooms ***************************************************************************
  */
// Right after
int door;
// Add the following line
PROG_LIST *pRprog;

// Right before
		fprintf( fp, "S\n" );
            }
        }
    }
    fprintf( fp, "#0\n\n\n\n" );
    return;
}
// Add the following 6 lines
for (pRprog = pRoomIndex->rprogs; pRprog; pRprog = pRprog->next)
{
	 fprintf(fp, "R %s %d %s~\n",
	 prog_type_to_name(pRprog->trig_type), pRprog->vnum,
	 pRprog->trig_phrase);
}

/*
  * End void save_rooms ***********************************************************************
  */

/************************************************************************************************
  *                                                End olc_save.c                                                     *
  ************************************************************************************************/

/************************************************************************************************
  *                                                    recycle.c                                                           *
  ************************************************************************************************/

// After
/* stuff for recycling mobprograms */
PROG_LIST *mprog_free;
// Add the following 2 lines
PROG_LIST *oprog_free;
PROG_LIST *rprog_free;

// Add all following lines in this recycle.c section to the end of the file.
PROG_LIST *new_oprog(void)
{
   static PROG_LIST op_zero;
   PROG_LIST *op;

   if (oprog_free == NULL)
       op = alloc_perm(sizeof(*op));
   else
   {
       op = oprog_free;
       oprog_free=oprog_free->next;
   }

   *op = op_zero;
   op->vnum             = 0;
   op->trig_type        = 0;
   op->code             = str_dup("");
   VALIDATE(op);
   return op;
}

void free_oprog(PROG_LIST *op)
{
   if (!IS_VALID(op))
      return;

   INVALIDATE(op);
   op->next = oprog_free;
   oprog_free = op;
}

PROG_LIST *new_rprog(void)
{
   static PROG_LIST rp_zero;
   PROG_LIST *rp;

   if (rprog_free == NULL)
       rp = alloc_perm(sizeof(*rp));
   else
   {
       rp = rprog_free;
       rprog_free=rprog_free->next;
   }

   *rp = rp_zero;
   rp->vnum             = 0;
   rp->trig_type        = 0;
   rp->code             = str_dup("");
   VALIDATE(rp);
   return rp;
}

void free_rprog(PROG_LIST *rp)
{
   if (!IS_VALID(rp))
      return;

   INVALIDATE(rp);
   rp->next = rprog_free;
   rprog_free = rp;
}

/************************************************************************************************
  *                                                 End recycle.c                                                       *
  ************************************************************************************************/

/************************************************************************************************
  *                                                      string.c                                                             *
  ************************************************************************************************/

/*
  * void string_add ***************************************************************************
  */
  
// Right after
    if ( *argument == '~' || *argument == '@' )
    {
	if ( ch->desc->editor == ED_MPCODE ) /* for the mobprogs */
	{
		MOB_INDEX_DATA *mob;
		int hash;
		PROG_LIST *mpl;
		PROG_CODE *mpc;

		EDIT_MPCODE(ch, mpc);

		if ( mpc != NULL )
			for ( hash = 0; hash < MAX_KEY_HASH; hash++ )
				for ( mob = mob_index_hash[hash]; mob; mob = mob->next )
					for ( mpl = mob->mprogs; mpl; mpl = mpl->next )
						if ( mpl->vnum == mpc->vnum )
						{
							sprintf( buf, "Fixing mob %d.\n\r", mob->vnum );
							send_to_char( buf, ch );
							mpl->code = mpc->code;
						}
	}
// Add all remaining lines in this string.c section
	if ( ch->desc->editor == ED_OPCODE ) /* for the objprogs */
	{
		OBJ_INDEX_DATA *obj;
		int hash;
		PROG_LIST *opl;
		PROG_CODE *opc;

		EDIT_OPCODE(ch, opc);

		if ( opc != NULL )
			for ( hash = 0; hash < MAX_KEY_HASH; hash++ )
				for ( obj = obj_index_hash[hash]; obj; obj = obj->next )
					for ( opl = obj->oprogs; opl; opl = opl->next )
						if ( opl->vnum == opc->vnum )
						{
							sprintf( buf, "Fixing object %d.\n\r", obj->vnum );
							send_to_char( buf, ch );
							opl->code = opc->code;
						}
	}

	if ( ch->desc->editor == ED_RPCODE ) /* for the roomprogs */
	{
		ROOM_INDEX_DATA *room;
		int hash;
		PROG_LIST *rpl;
		PROG_CODE *rpc;

		EDIT_RPCODE(ch, rpc);

		if ( rpc != NULL )
			for ( hash = 0; hash < MAX_KEY_HASH; hash++ )
				for ( room = room_index_hash[hash]; room; room = room->next )
					for ( rpl = room->rprogs; rpl; rpl = rpl->next )
						if ( rpl->vnum == rpc->vnum )
						{
							sprintf( buf, "Fixing room %d.\n\r", room->vnum );
							send_to_char( buf, ch );
							rpl->code = rpc->code;
						}
	}
	
/************************************************************************************************
  *                                                  End string.c                                                         *
  ************************************************************************************************/

/************************************************************************************************
  *                                                      tables.c                                                           *
  ************************************************************************************************/

// Add all lines in this tables.c section to the end of the file
const struct flag_type oprog_flags[] =
{
    {	"act",			TRIG_ACT,		TRUE	},
    {	"fight",		TRIG_FIGHT,		TRUE	},
    {	"give",			TRIG_GIVE,		TRUE	},
    {   "greet",		TRIG_GRALL,		TRUE	},
    {	"random",		TRIG_RANDOM,		TRUE	},
    {   "speech",		TRIG_SPEECH,		TRUE	},
    {	"exall",		TRIG_EXALL,		TRUE	},
    {	"delay",		TRIG_DELAY,		TRUE	},
    {	"drop",		TRIG_DROP,		TRUE	},
    {	"get",		TRIG_GET,		TRUE	},
    {	"sit",		TRIG_SIT,		TRUE	},
    {	NULL,			0,			TRUE	},
};

const struct flag_type rprog_flags[] =
{
    {	"act",			TRIG_ACT,		TRUE	},
    {	"fight",		TRIG_FIGHT,		TRUE	},
    {	"drop",			TRIG_DROP,		TRUE	},
    {	"greet",		TRIG_GRALL,		TRUE	},
    {	"random",		TRIG_RANDOM,		TRUE	},
    {	"speech",		TRIG_SPEECH,		TRUE	},
    {	"exall",		TRIG_EXALL,		TRUE	},
    {	"delay",		TRIG_DELAY,		TRUE	},
    {	NULL,			0,			TRUE	},
};

/************************************************************************************************
  *                                                   End tables.c                                                       *
  ************************************************************************************************/

/************************************************************************************************
  *                                                      tables.h                                                           *
  ************************************************************************************************/

// In the flag tables section, add the following 2 lines
extern	const	struct	flag_type	oprog_flags[];
extern	const	struct	flag_type	rprog_flags[];

/************************************************************************************************
  *                                                  End tables.h                                                        *
  ************************************************************************************************/

/************************************************************************************************
  *                                                  update.c                                                             *
  ************************************************************************************************/

/*
  * void obj_update *****************************************************************************
  */
// Right before
	if ( obj->timer <= 0 || --obj->timer > 0 )
	    continue;
// Add the following 18 lines
	/*
	 * Oprog triggers!
	 */
	if ( obj->in_room || (obj->carried_by && obj->carried_by->in_room))
	{
	    if ( HAS_TRIGGER_OBJ( obj, TRIG_DELAY )
	      && obj->oprog_delay > 0 )
	    {
	        if ( --obj->oprog_delay <= 0 )
		    p_percent_trigger( NULL, obj, NULL, NULL, NULL, NULL, TRIG_DELAY );
	    }
	    else if ( ((obj->in_room && !obj->in_room->area->empty)
	    	|| obj->carried_by ) && HAS_TRIGGER_OBJ( obj, TRIG_RANDOM ) )
		    p_percent_trigger( NULL, obj, NULL, NULL, NULL, NULL, TRIG_RANDOM );
	 }
	/* Make sure the object is still there before proceeding */
	if ( !obj )
	    continue;

/*
 * End void obj_update ***********************************************************************
 */
 
/************************************************************************************************
  *                                              End update.c                                                          *
  ************************************************************************************************/