From 2939a3d507f0bbf4759bc1c7fb40a4b2c1968806 Mon Sep 17 00:00:00 2001 From: Vatiken Date: Sat, 3 Mar 2012 00:10:32 +0000 Subject: [PATCH] The basis for 'oset' --- lib/world/trg/12.trg | 16 +++++++ src/act.h | 1 + src/act.wizard.c | 41 ++++++++++++++++ src/dg_variables.c | 48 +++++++++++++++++++ src/genobj.c | 110 +++++++++++++++++++++++++++++++++++++++++++ src/genobj.h | 4 ++ src/interpreter.c | 1 + 7 files changed, 221 insertions(+) diff --git a/lib/world/trg/12.trg b/lib/world/trg/12.trg index 9af535b..472325d 100644 --- a/lib/world/trg/12.trg +++ b/lib/world/trg/12.trg @@ -1137,6 +1137,22 @@ else %send% %actor% The switch says, 'Fine... fine.' end ~ +#1279 +OSET test trigger~ +0 j 100 +~ +wait 2 sec +say Yeah, I can sharpen this. +wait 2 sec +emote chips away at %object.shortdesc%. +set short %object.shortdesc% sharpened by '%self.name%' +nop %object.oset(apply damroll 1)% +nop %object.oset(shortdesc %short%)% +wait 2 sec +give %object.name.car% %actor.name% +wait 1 sec +say There ya go! +~ #1280 Mob Raid~ 2 b 100 diff --git a/src/act.h b/src/act.h index 24384be..34d3c4b 100644 --- a/src/act.h +++ b/src/act.h @@ -322,6 +322,7 @@ ACMD(do_goto); ACMD(do_invis); ACMD(do_links); ACMD(do_load); +ACMD(do_oset); ACMD(do_peace); ACMD(do_plist); ACMD(do_purge); diff --git a/src/act.wizard.c b/src/act.wizard.c index 5dd67f0..92dcfbe 100644 --- a/src/act.wizard.c +++ b/src/act.wizard.c @@ -27,6 +27,7 @@ #include "genzon.h" /* for real_zone_by_thing */ #include "class.h" #include "genolc.h" +#include "genobj.h" #include "fight.h" #include "house.h" #include "modify.h" @@ -5030,3 +5031,43 @@ ACMD(do_recent) *(tmstr + strlen(tmstr) - 1) = '\0'; send_to_char(ch, "Current Server Time: %-19.19s\r\nShowing %d players since last copyover/reboot\r\n", tmstr, hits); } + + +ACMD(do_oset) +{ + char arg[MAX_INPUT_LENGTH]; + char arg2[MAX_INPUT_LENGTH]; + struct obj_data *obj; + bool success = TRUE; + + argument = one_argument(argument, arg); + + if (!*arg) + send_to_char(ch, "oset what?\r\n"); + else if (!(obj = get_obj_in_list_vis(ch, arg, NULL, ch->carrying)) && + !(obj = get_obj_in_list_vis(ch, arg, NULL, world[IN_ROOM(ch)].contents))) + send_to_char(ch, "You don't seem to have %s %s.\r\n", AN(arg), arg); + else { + argument = one_argument(argument, arg2); + + if (!*arg2) + send_to_char(ch, "What?\r\n"); + else { + if (is_abbrev(arg2, "alias") && (success = oset_alias(obj, argument))) + send_to_char(ch, "Object alias set to %s.\r\n", argument); + else if (is_abbrev(arg2, "longdesc") && (success = oset_long_description(obj, argument))) + send_to_char(ch, "Object long description set to %s.\r\n", argument); + else if (is_abbrev(arg2, "shortdesc") && (success = oset_short_description(obj, argument))) + send_to_char(ch, "Object short description set to %s.\r\n", argument); + else if (is_abbrev(arg2, "apply") && (success = oset_apply(obj, argument))) + send_to_char(ch, "Object apply set to %s.\r\n", argument); + else { + if (!success) + send_to_char(ch, "%s was unsuccessful.\r\n", arg2); + else + send_to_char(ch, "Unknown argument: %s.\r\n", arg2); + return; + } + } + } +} diff --git a/src/dg_variables.c b/src/dg_variables.c index 72ea3fd..4b19610 100644 --- a/src/dg_variables.c +++ b/src/dg_variables.c @@ -25,6 +25,7 @@ #include "class.h" #include "quest.h" #include "act.h" +#include "genobj.h" /* Utility functions */ @@ -132,6 +133,43 @@ int char_has_item(char *item, struct char_data *ch) return 1; } +static int handle_oset(struct obj_data * obj, char * argument) +{ + int i = 0; + bool found = FALSE; + char value[MAX_INPUT_LENGTH]; + + struct oset_handler { + const char * type; + bool (* name)(struct obj_data *, char *); + } handler[] = { + { "alias", oset_alias }, + { "apply", oset_apply }, + { "longdesc", oset_long_description }, + { "shortdesc", oset_short_description}, + { "\n", NULL } + }; + + if (!obj || !*argument) + return 0; + + argument = one_argument(argument, value); + + while (*handler[i].type != '\n') { + if (is_abbrev(value, handler[i].type)) { + found = TRUE; + break; + } + i++; + } + + if (!found) + return 0; + + handler[i].name(obj, argument); + return 1; +} + int text_processed(char *field, char *subfield, struct trig_var_data *vd, char *str, size_t slen) { @@ -1200,6 +1238,16 @@ o->contains) ? "1" : "0")); *str = '\0'; } break; + case 'o': + if (!str_cmp(field, "oset")) { + if (subfield && *subfield) { + if (handle_oset(o, subfield)) + strcpy(str, "1"); + else + strcpy(str, "0"); + } + } + break; case 'r': if (!str_cmp(field, "room")) { if (obj_room(o) != NOWHERE) diff --git a/src/genobj.c b/src/genobj.c index 1187e66..c0b3b96 100644 --- a/src/genobj.c +++ b/src/genobj.c @@ -11,11 +11,13 @@ #include "utils.h" #include "db.h" #include "shop.h" +#include "constants.h" #include "genolc.h" #include "genobj.h" #include "genzon.h" #include "dg_olc.h" #include "handler.h" +#include "interpreter.h" #include "boards.h" /* for board_info */ @@ -474,3 +476,111 @@ int delete_object(obj_rnum rnum) return rnum; } + +/* oset handling, this location should be temporary */ +bool oset_alias(struct obj_data *obj, char * argument) +{ + static int max_len = 64; + int i = GET_OBJ_RNUM(obj); + + skip_spaces(&argument); + + if (strlen(argument) > max_len) + return FALSE; + + if (obj->name && obj->name != obj_proto[i].name) + free(obj->name); + + obj->name = strdup(argument); + + return TRUE; +} + +bool oset_apply(struct obj_data *obj, char * argument) +{ + int i = 0, apply = -1, location = -1, mod = 0, empty = -1, value; + char arg[MAX_INPUT_LENGTH]; + + argument = one_argument(argument, arg); + + skip_spaces(&argument); + + if ((value = atoi(argument)) == 0) + return FALSE; + + while (*apply_types[i] != '\n') { + if (is_abbrev(apply_types[i], arg)) { + apply = i; + break; + } + i++; + } + + if (apply == -1) + return FALSE; + + for (i = 0; i < MAX_OBJ_AFFECT; i++) { + if (obj->affected[i].location == apply) { + location = i; + mod = obj->affected[i].modifier; + break; + } else if (obj->affected[i].location == APPLY_NONE && empty == -1) { + empty = i; + } + } + + /* No slot already using APPLY_XXX, so use an empty one... if available */ + if (location == -1) + location = empty; + + /* There is no slot already using our APPLY_XXX type, and no empty slots either */ + if (location == -1) + return FALSE; + + obj->affected[location].modifier = mod + value; + + /* Our modifier is set at 0, so lets just clear the apply location so that it may + * be reused at a later point */ + if (obj->affected[location].modifier != 0) + obj->affected[location].location = apply; + else + obj->affected[location].location = APPLY_NONE; + + return TRUE; +} + +bool oset_short_description(struct obj_data *obj, char * argument) +{ + static int max_len = 64; + int i = GET_OBJ_RNUM(obj); + + skip_spaces(&argument); + + if (strlen(argument) > max_len) + return FALSE; + + if (obj->short_description && obj->short_description != obj_proto[i].short_description) + free(obj->short_description); + + obj->short_description = strdup(argument); + + return TRUE; +} + +bool oset_long_description(struct obj_data *obj, char * argument) +{ + static int max_len = 128; + int i = GET_OBJ_RNUM(obj); + + skip_spaces(&argument); + + if (strlen(argument) > max_len) + return FALSE; + + if (obj->description && obj->description != obj_proto[i].description) + free(obj->description); + + obj->description = strdup(argument); + + return TRUE; +} diff --git a/src/genobj.h b/src/genobj.h index 991ed21..a829efc 100644 --- a/src/genobj.h +++ b/src/genobj.h @@ -23,5 +23,9 @@ obj_rnum index_object(struct obj_data *obj, obj_vnum ovnum, obj_rnum ornum); obj_rnum add_object(struct obj_data *, obj_vnum ovnum); int copy_object_main(struct obj_data *to, struct obj_data *from, int free_object); int delete_object(obj_rnum); +bool oset_alias(struct obj_data *obj, char * argument); +bool oset_apply(struct obj_data *obj, char * argument); +bool oset_short_description(struct obj_data *obj, char * argument); +bool oset_long_description(struct obj_data *obj, char * argument); #endif /* _GENOBJ_H_ */ diff --git a/src/interpreter.c b/src/interpreter.c index 9ce1d74..39cd4a5 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -230,6 +230,7 @@ cpp_extern const struct command_info cmd_info[] = { { "olc" , "olc" , POS_DEAD , do_show_save_list, LVL_BUILDER, 0 }, { "olist" , "olist" , POS_DEAD , do_oasis_list, LVL_BUILDER, SCMD_OASIS_OLIST }, { "oedit" , "oedit" , POS_DEAD , do_oasis_oedit, LVL_BUILDER, 0 }, + { "oset" , "oset" , POS_DEAD , do_oset, LVL_BUILDER, 0 }, { "ocopy" , "ocopy" , POS_DEAD , do_oasis_copy, LVL_GOD, CON_OEDIT }, { "put" , "p" , POS_RESTING , do_put , 0, 0 },