Help understanding how dest_buf works...

Posted by Nick Cash on Tue 18 Mar 2003 11:57 PM — 2 posts, 6,768 views.

USA #0
I know I asked this before, and you said it was a destination buffer but I have an example from my SWR based MUD and I just wanted to ask a few questions. First I'll put in the example...


switch( ch->substate )
{
default:

if ( arg[0] == '\0' )
{
send_to_char( "&RUsage: Makeblade <name>\n\r&w", ch);
return;
}

checktool = FALSE;
checkdura = FALSE;
checkbatt = FALSE;
checkoven = FALSE;

if ( !IS_SET( ch->in_room->room_flags, ROOM_FACTORY ) )
{
send_to_char( "&RYou need to be in a factory or workshop to do that.\n\r", ch);
return;
}

for ( obj = ch->last_carrying; obj; obj = obj->prev_content )
{
if (obj->item_type == ITEM_TOOLKIT)
checktool = TRUE;
if (obj->item_type == ITEM_DURASTEEL)
checkdura = TRUE;
if (obj->item_type == ITEM_BATTERY)
checkbatt = TRUE;

if (obj->item_type == ITEM_OVEN)
checkoven = TRUE;
}

if ( !checktool )
{
send_to_char( "&RYou need toolkit to make a vibro-blade.\n\r", ch);
return;
}

if ( !checkdura )
{
send_to_char( "&RYou need something to make it out of.\n\r", ch);
return;
}

if ( !checkbatt )
{
send_to_char( "&RYou need a power source for your blade.\n\r", ch);
return;
}

if ( !checkoven )
{
send_to_char( "&RYou need a small furnace to heat the metal.\n\r", ch);
return;
}

chance = IS_NPC(ch) ? ch->top_level
: (int) (ch->pcdata->learned[gsn_makeblade]);
if ( number_percent( ) < chance )
{
send_to_char( "&GYou begin the long process of crafting a vibroblade.\n\r", ch);
act( AT_PLAIN, "$n takes $s tools and a small oven and begins to work on something.", ch,
NULL, argument , TO_ROOM );
add_timer ( ch , TIMER_DO_FUN , 25 , do_makeblade , 1 );
ch->dest_buf = str_dup(arg);
return;
}
send_to_char("&RYou can't figure out how to fit the parts together.\n\r",ch);
learn_from_failure( ch, gsn_makeblade );
return;

case 1:
if ( !ch->dest_buf )
return;
strcpy(arg, ch->dest_buf);
DISPOSE( ch->dest_buf);
break;

case SUB_TIMER_DO_ABORT:
DISPOSE( ch->dest_buf );
ch->substate = SUB_NONE;
send_to_char("&RYou are interupted and fail to finish your work.\n\r", ch);
return;
}

ch->substate = SUB_NONE;

Alright, there is more code but that is the section I have questions on. And yes, I know this is a timer....

Question 1: What exactly is dest_buf used for?

Question 2: Some codes like this use dest_buf_2, how do I know of I need to use dest_buf_2?

Question 3: Dest_buf and dest_buf_2 are defined as void, shouldn't they be defined with other values?

Question 4: Could I switch the ch->substate in the switch statement to ch->cusstate? I'm making a code that involves a lot of timers and I just wanted to make sure I knew how all of this stuff worked so I didn't sit there for hours wondering why.

Thanks for any and all help. I really appreciate it.
Amended on Tue 18 Mar 2003 11:59 PM by Nick Cash
Australia Forum Administrator #1
I haven't looked in great detail, but will try to answer in part.

  1. It is used to hold a pointer to various temporary things, like the description you are editing, or the character you have morphed to.
  2. This is probably because the author knew dest_buf was, or might be, in use at the same time. I can't see dest_buf_2 in stock SMAUG, so the SWR author might have chosen another pointer to be on the safe side.
  3. Because they can be pointers to different things, eg. MORPH_DATA, CHAR_DATA. It is more logical to use a pointer to void, rather than confusing people by choosing a specific pointer and then overriding it. Also, a pointer to void doesn't need casting.
  4. Can't answer that one.