The Vassign command

Original author: Samson
Ported to SmaugWiz by Zanthoris

Installation Instructions
-------------------------

1. In act_wiz.cpp add the following code:

/* Consolidated *assign function. 
 * Assigns room/obj/mob ranges and initializes new zone - Samson 2-12-99 
 */
void do_vassign (CCharacter *ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    char arg3[MAX_INPUT_LENGTH];
    int lo, hi;
    CCharacter *victim, *mob;
    CRoomIndexData *room;
    CMobIndexData *pMobIndex;
    CObjIndexData *pObjIndex;
    CObjData *obj;
    CAreaData *tarea;
    char	 filename[256];

    set_char_color( AT_IMMORT, ch );

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
    argument = one_argument( argument, arg3 );
    lo = atoi( arg2 );  hi = atoi( arg3 );
    
    if ( arg1[0] == '\0' || lo < 0 || hi < 0 )
    {
        ch->SendText("Syntax: vassign <who> <low> <high>\n\r");
        return;
    }
    if ( (victim = get_char_world( ch, arg1 )) == NULL )
    {
        ch->SendText("They don't seem to be around.\n\r");
        return;
    }
    if (victim->IsNpc() || victim->GetTrustLevel () < LEVEL_CREATOR )
    {
        ch->SendText("They wouldn't know what to do with a vnum range.\n\r");
        return;
    }
    if ( victim->GetPcData()->area && lo != 0 )
    {
	ch->SendText("You cannot assign them a range, they already have one!\n\r");
	return;
    }	 
    if ( lo > hi )
    {
        ch->SendText("Unacceptable vnum range.\n\r");
        return;
    }
    if ( lo == 0 )
        hi = 0;
    victim->GetPcData()->r_range_lo = lo;
    victim->GetPcData()->r_range_hi = hi;
    victim->GetPcData()->o_range_lo = lo;
    victim->GetPcData()->o_range_hi = hi;
    victim->GetPcData()->m_range_lo = lo;
    victim->GetPcData()->m_range_hi = hi;
    assign_area( victim );
    ch->SendText("Done.\n\r");
    victim->SendTextf("%s has assigned you the vnum range %d - %d.\n\r", ch->GetName(), lo, hi );
    assign_area( victim );	/* Put back by Thoric on 02/07/96 */

    if (!victim->GetArea())
    {
        bug( "vassign: assign_area failed", 0 );
        return;
    }

    tarea=victim->GetArea();
    
	CAreaData &Area = *victim->GetArea();
    if (lo == 0)				/* Scryn 8/12/95 */
    {

	Area.ClrLoaded();
    Area.SetDeleted();
    }
    else
    {
	Area.SetLoaded();
    Area.ClrDeleted();
    }

    /* Initialize first and last rooms in range */
    room = make_room( lo );
    if ( !room )
    {
	bug( "do_vassign: make_room failed to initialize first room.", 0 );
	return;
    }
    room->SetArea(tarea);

    room = make_room(hi);
    if (!room)
    {
	bug( "do_vassign: make_room failed to initialize last room.", 0 );
	return;
    }
    room->SetArea(tarea);

    /* Initialize first mob in range */
    pMobIndex = make_mobile( lo, 0, "first mob" );
    if (!pMobIndex)
    {
        ch->SendText( "do_vassign: make_mobile failed to initialize first mob." );
        return;
    }
    mob = create_mobile( pMobIndex );
    mob->SendToRoom(room);
    /* Initialize last mob in range */
    pMobIndex = make_mobile( hi, 0, "last mob" );
    if (!pMobIndex)
    {
        ch->SendText("do_vassign: make_mobile failed to initialize last mob.");
        return;
    }
    mob = create_mobile( pMobIndex );
	mob->SendToRoom (room);
    /* Initialize first obj in range */
    pObjIndex = make_object(lo, 0, "first obj");
    if ( !pObjIndex )
    {
        ch->SendText( "do_vassign: make_object failed to initialize first obj." );
        return;
    }
    obj = create_object(pObjIndex, 0);
    obj_to_room(obj, room);

    /* Initialize last obj in range */
    pObjIndex = make_object(hi, 0, "last obj");
    if (!pObjIndex)
    {
        ch->SendText("do_vassign: make_object failed to initialize last obj.");
        return;
    }
    obj = create_object(pObjIndex, 0);
    obj_to_room(obj, room);

    /* Save character and newly created zone */
    save_char_obj( victim );

     if(!Area.IsDeleted())
    {
       sprintf( filename, "%s%s", BUILD_DIR, tarea->GetName);
       fold_area(tarea, FA_BUILD);
    }

    set_char_color( AT_IMMORT, ch );
    ch->SendTextf("Vnum range set for %s and initialized.\n\r", victim->GetName());  
    return;
}

2. In smaug.h look for the following line:

   DECLARE_DO_FUN(do_value);

   after the above line add the following line:

   DECLARE_DO_FUN(do_vassign);

3.  In skills.cpp look for:

    if (!str_cmp (name, "do_value"))		return do_value;

    and add this line below it:
 
    if (!str_cmp (name, "do_vassign"))		return do_vassign;
    
    also in skills.cpp look for:

    if (skill == do_value)			return "do_value";

    and add:

    if (skill == do_vassign)		return "do_vassign";

3. Make clean, recompile.

4. Create a beep command, setting it to the desired level or just put the following
in your commands.dat file:

#COMMAND
Name        vassign~
Code        do_vassign
Position    0
Level       61
Log         1
End

This code simply consolidates the function of the rassign, oassign, and
massign commands. It then goes to the last specified vnum and initializes
it with placeholder data. The zone and the player are then saved. For this
reason, it is not a good idea to issue this command on someone who already
has a zone being built. Safeguards are in place, but one never knows what
could happen. If you're setup so that builders can only build rooms at first,
you can still use this code. Just be sure your mob and object editing 
commands are restricted above the level of your room editing commands, etc.

Updated 1-6-00:
After discovering that the area doesn't retain the vnums assigned without
making placeholders at both ends, I've updated the command to now create
the first mob and object in the zone as well. So now this thing should
properly reserve the entire vnum range for rooms, mobs, and objects.

*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

This snippet was written for and tested on SmaugWiz version 2.01, I cannot guarantee that
it will work in previous versions without some modification (though I expect it will).  If
you have problems with this snippet let me know!

-=Zanthoris=-

zanthoris@hotmail.com
telnet:\\zanthoris.dhs.org:4000
http:\\zanthoris.home.dhs.org