From c04c8ec5f25a248401c83abdf53788b52c1d7fa2 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Tue, 20 Feb 2007 22:05:44 +0000 Subject: [PATCH] attrib_set() --- game/txt/hlp/cobra_func.hlp | 28 ++++++++++++++++++++++++---- src/function.c | 1 + src/fundb.c | 33 +++++++++++++++++++++++++++++++++ win32/funs.h | 1 + 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/game/txt/hlp/cobra_func.hlp b/game/txt/hlp/cobra_func.hlp index 68ca47b..4cea943 100644 --- a/game/txt/hlp/cobra_func.hlp +++ b/game/txt/hlp/cobra_func.hlp @@ -511,6 +511,23 @@ When given a second argument of "on" (or "off"), attempts to lock (unlock) the specified attribute, as per @atrlock. +& ATTRIB_SET() + attrib_set(/[, ]) + + Sets or clears an attribute. With a value, it sets the attribute, + without one, it clears the attribute. This is an easier-to-read + replacement for the old set(, :) notation, + and a less destructive replacement for wipe() that won't destroy + entire attribute trees in one shot. + + If there is a second argument, then attrib_set() will create an + attribute, even if the second argument is empty (in which case + attrib_set() will create an empty attribute). This means that + attrib_set(me/foo,%0) will _always_ create an attribute. + + Of course, if the empty_attrs configuration option is turned off, + then the above paragraph doesn't apply. See @config attribs. + & BAND() band(,,...) @@ -3038,9 +3055,10 @@ for an object named "Test", preferring a thing over other types. flags, set attributes, and many other things. The two arguments to the function are the same as the arguments that would appear on either side of the '=' in @set. This function returns nothing. - - Note that you can't clear an attribute with set(), though - you can make it an empty attribute. Use wipe() to clear attributes. + + The attribute setting ability of set() is deprecated. You should + use attrib_set() instead; it's easier to read, and allows you to + clear attributes, too. & SETDIFF() setdiff(, [, ][, ][, ]) @@ -4121,7 +4139,9 @@ for an object named "Test", preferring a thing over other types. & WIPE() wipe(/) - This function is equivalent to @wipe. It returns nothing. + This function is equivalent to @wipe. It returns nothing. Like + @wipe, this function will destroy entire attribute trees; for + more judicious deletion, use attrib_set(). & WORDPOS() wordpos(, [, ]) diff --git a/src/function.c b/src/function.c index a8fde26..c725706 100644 --- a/src/function.c +++ b/src/function.c @@ -287,6 +287,7 @@ FUNTAB flist[] = { {"ARABIC2ROMAN", fun_arabictoroman, 1, 1, FN_REG}, {"ART", fun_art, 1, 1, FN_REG}, {"ATRLOCK", fun_atrlock, 1, 2, FN_REG}, + {"ATTRIB_SET", fun_attrib_set, 1, -2, FN_REG}, {"BAND", fun_band, 1, INT_MAX, FN_REG}, {"BASECONV", fun_baseconv, 3, 3, FN_REG}, {"BEEP", fun_beep, 0, 1, FN_REG}, diff --git a/src/fundb.c b/src/fundb.c index 8b9ef7d..5cc8e04 100644 --- a/src/fundb.c +++ b/src/fundb.c @@ -1816,6 +1816,39 @@ FUNCTION(fun_wipe) do_wipe(executor, args[0]); } +/* ARGSUSED */ +FUNCTION(fun_attrib_set) +{ + dbref thing; + char *s; + + if (!FUNCTION_SIDE_EFFECTS) { + safe_str(T(e_disabled), buff, bp); + return; + } + if (!command_check_byname(executor, "ATTRIB_SET") || fun->flags & FN_NOSIDEFX) { + safe_str(T(e_perm), buff, bp); + safe_str(T(e_perm), buff, bp); + return; + } + s = strchr(args[0], '/'); + if (!s) { + safe_str(T("#-1 BAD ARGUMENT FORMAT TO ATTRIB_SET"), buff, bp); + return; + } + *s++ = '\0'; + thing = match_thing(executor, args[0]); + if (!GoodObject(thing)) { + safe_str(T(e_notvis), buff, bp); + return; + } + if (nargs == 1) { + do_set_atr(thing, s, NULL, executor, 1); + } else { + do_set_atr(thing, s, args[1], executor, 1); + } +} + /* -------------------------------------------------------------------------- * Misc functions: TEL diff --git a/win32/funs.h b/win32/funs.h index 1caf416..0210388 100644 --- a/win32/funs.h +++ b/win32/funs.h @@ -21,6 +21,7 @@ FUNCTION_PROTO(fun_atan); FUNCTION_PROTO(fun_atan2); FUNCTION_PROTO(fun_atat); FUNCTION_PROTO(fun_atrlock); +FUNCTION_PROTO(fun_attrib_set); FUNCTION_PROTO(fun_band); FUNCTION_PROTO(fun_baseconv); FUNCTION_PROTO(fun_beep); -- 2.30.2