Re: C Interpreter engine (DG's UID_CHAR) Baggett/DOOMer on Tue, Feb 03, 1998 at 02:04:01AM -0600

From: Eric Green (thrytis@IMAXX.NET)
Date: 02/03/98


On Tue, Feb 03, 1998 at 02:04:01AM -0600, Akuma/Chris Baggett/DOOMer wrote:
>
> has anyone found a decent use for the idea behind
> DG's  UID_CHAR  stuff?
> it's used mainly in the find_char/obj/room functions
> and works like this (stock):
> Char's Id = Idnum  and Idnum's are allowed up to ROOM_ID_BASE
> which is 50000 stock.  from there, ROOM_ID_BASE to max_id default
>  (100k stock)
> is the ROOM_ID_BASE+Real Room Vnum (rnum)
> ie,  Limbo (vnum 1, rnum 1)  would have an ID of
> (stock) 50001.  In the DG code i've
> seen a few good uses of these, but i've already created
> my own way of doing this.  for example,
> stock perform_wear won't equip you with a GRAB item, or a WIELD item
> (i don't believe so anyway) so I just added that ability, whereas
> DG used do_weild(ch, buf, 0, 0);  with buf being
> UID_CHAR (\e) and then the ID number.
>
> I haven't found any other good uses.  Only good use I see is
> being able to have access to a specific mob/object through
> function calls.

There is a need to have a specific handle to each object (mob/item/room)
in the game for the scripts to be able to access an object.  The pointers
to the objects are not unique (since the memory can be freed and reused
for a different object), so i extended the scheme used by the player system
to give all objects a unique identifier (UID).  Players just use their
idnum, mobs and objects are assigned in order from a certain base point
which shouldn't conflict with a player's idnum (for normal conditions).
Rooms were numbered from ROOM_ID_BASE + rnum since it makes lookups fast
(no need to hash).

These UIDs need to be passed through the command interpreters, so scripts
can do things like "kill <exactly that annoying player>".  The UID_CHAR
is used so there is no confusion between the sword with a UID of 2000
and the "sword of year 2000 compliance".  I choose \e for the character
because players can't type it (it is filtered in process_input).

After i had implemented this for scripts, i found some other uses for it.
For do_wear, i used the UID string in the call do_wield so all the checking
could be done in one place, instead of split up the checks into two places,
only to forget to update both places when new checks were added.

It is used in the search command and in casting because they use a delayed
event.  The target must be saved until the event fires, and just using a
pointer to the target would not be safe (because of lack of uniqueness).

It is used in do_echo because i use sub_write instead of act.  (sub_write
allows for improved echos and emotes... different people in the room
will see different messages, depending on who or what the emote is directed
at.)

Of course, there could be alternate solutions to the last three uses.  I
just used the UIDs because it was there, it was an easy solution, and it
is relatively efficient (with hashing at least).


\e2  (Eric)


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST