dsIIr4/bin/
dsIIr4/extra/creremote/
dsIIr4/extra/wolfpaw/
dsIIr4/lib/cmds/admins/
dsIIr4/lib/cmds/common/
dsIIr4/lib/cmds/creators/include/
dsIIr4/lib/cmds/creators/include/SCCS/
dsIIr4/lib/daemon/services/
dsIIr4/lib/doc/
dsIIr4/lib/domains/Ylsrim/
dsIIr4/lib/domains/Ylsrim/adm/
dsIIr4/lib/domains/Ylsrim/armor/
dsIIr4/lib/domains/Ylsrim/broken/
dsIIr4/lib/domains/Ylsrim/fish/
dsIIr4/lib/domains/Ylsrim/meal/
dsIIr4/lib/domains/Ylsrim/npc/
dsIIr4/lib/domains/Ylsrim/virtual/
dsIIr4/lib/domains/Ylsrim/weapon/
dsIIr4/lib/domains/campus/adm/
dsIIr4/lib/domains/campus/etc/
dsIIr4/lib/domains/campus/meals/
dsIIr4/lib/domains/campus/npc/
dsIIr4/lib/domains/campus/save/
dsIIr4/lib/domains/campus/txt/
dsIIr4/lib/domains/campus/txt/ai/charles/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/
dsIIr4/lib/domains/campus/txt/ai/charles/bak2/bak1/
dsIIr4/lib/domains/campus/txt/ai/charly/
dsIIr4/lib/domains/campus/txt/ai/charly/bak/
dsIIr4/lib/domains/campus/txt/jenny/
dsIIr4/lib/domains/default/creator/
dsIIr4/lib/domains/default/doors/
dsIIr4/lib/domains/default/etc/
dsIIr4/lib/domains/default/virtual/
dsIIr4/lib/domains/default/weap/
dsIIr4/lib/domains/town/virtual/
dsIIr4/lib/lib/comp/
dsIIr4/lib/lib/lvs/
dsIIr4/lib/lib/user/
dsIIr4/lib/lib/virtual/
dsIIr4/lib/log/
dsIIr4/lib/obj/book_source/
dsIIr4/lib/obj/include/
dsIIr4/lib/realms/template/
dsIIr4/lib/realms/template/adm/
dsIIr4/lib/realms/template/area/armor/
dsIIr4/lib/realms/template/area/npc/
dsIIr4/lib/realms/template/area/obj/
dsIIr4/lib/realms/template/area/room/
dsIIr4/lib/realms/template/area/weap/
dsIIr4/lib/realms/template/bak/
dsIIr4/lib/realms/template/cmds/
dsIIr4/lib/save/
dsIIr4/lib/save/kills/o/
dsIIr4/lib/secure/cfg/classes/
dsIIr4/lib/secure/cmds/creators/include/
dsIIr4/lib/secure/cmds/players/
dsIIr4/lib/secure/cmds/players/include/
dsIIr4/lib/secure/daemon/include/
dsIIr4/lib/secure/lib/
dsIIr4/lib/secure/lib/include/
dsIIr4/lib/secure/lib/net/include/
dsIIr4/lib/secure/lib/std/
dsIIr4/lib/secure/modules/
dsIIr4/lib/secure/npc/
dsIIr4/lib/secure/obj/include/
dsIIr4/lib/secure/room/
dsIIr4/lib/secure/save/
dsIIr4/lib/secure/save/boards/
dsIIr4/lib/secure/save/players/g/
dsIIr4/lib/secure/tmp/
dsIIr4/lib/secure/verbs/creators/
dsIIr4/lib/shadows/
dsIIr4/lib/spells/
dsIIr4/lib/std/board/
dsIIr4/lib/std/lib/
dsIIr4/lib/tmp/
dsIIr4/lib/verbs/admins/include/
dsIIr4/lib/verbs/common/
dsIIr4/lib/verbs/common/include/
dsIIr4/lib/verbs/creators/include/
dsIIr4/lib/verbs/players/include/SCCS/
dsIIr4/lib/verbs/rooms/
dsIIr4/lib/verbs/rooms/include/
dsIIr4/lib/www/
dsIIr4/v22.2b14-dsouls2/
dsIIr4/v22.2b14-dsouls2/ChangeLog.old/
dsIIr4/v22.2b14-dsouls2/Win32/
dsIIr4/v22.2b14-dsouls2/compat/
dsIIr4/v22.2b14-dsouls2/compat/simuls/
dsIIr4/v22.2b14-dsouls2/include/
dsIIr4/v22.2b14-dsouls2/mudlib/
dsIIr4/v22.2b14-dsouls2/testsuite/
dsIIr4/v22.2b14-dsouls2/testsuite/clone/
dsIIr4/v22.2b14-dsouls2/testsuite/command/
dsIIr4/v22.2b14-dsouls2/testsuite/data/
dsIIr4/v22.2b14-dsouls2/testsuite/etc/
dsIIr4/v22.2b14-dsouls2/testsuite/include/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/
dsIIr4/v22.2b14-dsouls2/testsuite/inherit/master/
dsIIr4/v22.2b14-dsouls2/testsuite/log/
dsIIr4/v22.2b14-dsouls2/testsuite/single/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/compiler/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/efuns/
dsIIr4/v22.2b14-dsouls2/testsuite/single/tests/operators/
dsIIr4/v22.2b14-dsouls2/testsuite/u/
dsIIr4/v22.2b14-dsouls2/tmp/
dsIIr4/win32/
/*    /secure/cmds/admins/addemote.c
 *    From the Dead Souls V Object Library
 *    A sane command for doing emote addition
 *    Created by Descartes of Borg 961208
 *    Version: @(#) addemote.c 1.2@(#)
 *    Last modified: 96/12/14
 */

#include <lib.h>
#include <daemons.h>
#include <message_class.h>

inherit LIB_DAEMON;

static void MainMenu();
static void EditErrorMessage(string emote);
static void ShowEmote(string emote);
static void AddEmote(string emote);
static void AddRule(string rule, string emote);

static void EnterEmote(string emote, string array emotes) {
    int x = to_int(emote);

    if( x < 1 || x > sizeof(emotes) ) {
	if( member_array(emote, emotes) == -1 ) {
	    if( emote[0] == 'q' ) {
		return;
	    }
	    MainMenu();
	    return;
	}
    }
    else {
	emote = emotes[x-1];
    }
    ShowEmote(emote);
}

static void EnterEditChoice(string str, string array rules, string emote) {
    int x = to_int(str);

    if( x < 1 || x > sizeof(rules) ) {
	if( member_array(str, rules) == -1 ) {
	    if( !str || str == "" ) {
		MainMenu();
		return;
	    }
	    if( str[0] == 'q' ) {
		return;
	    }
	    else if( str[0] == 'e' ) {
		EditErrorMessage(emote);
		return;
	    }
	    else if( str[0] == 'a' ) {
		this_player()->eventPrint("Enter verb rule: ", MSG_PROMPT);
		input_to((: AddRule :), emote);
		return;
	    }
	    else {
		ShowEmote(emote);
		return;
	    }
	}
	AddRule(str, emote);
    }
    else {
	AddRule(rules[x-1], emote);
    }
}

static void AddAdverbs(string adv, string emote, string array rules,
  string array verbs, string msg) {
    string array adverbs;

    if( !adv || adv == "" ) {
	adverbs = ({});
    }
    else {
	adverbs = map(explode(adv, ","), (: trim :));
    }
    foreach(string rule in rules) {
	SOUL_D->AddRule(emote, rule, ({ verbs, msg }), adverbs);
    }
    this_player()->eventPrint("Emote '" + emote + "' added.");
}

static void AddMessage(string msg, string emote, string array rules,
  string array verbs) {
    if( !msg || msg == "" ) {
	this_player()->eventPrint("Which message? [q to quit] ", MSG_PROMPT);
	input_to((: AddMessage :), emote, rules, verbs);
	return;
    }
    if( lower_case(msg) == "q" ) {
	this_player()->eventPrint("Addition of rule aborted.");
	return;
    }
    this_player()->eventPrint("Enter adverbs: ", MSG_PROMPT);
    input_to((: AddAdverbs :), emote, rules, verbs, msg);
}

static void AddVerbs(string list, string emote, string array rules) {
    string array verbs = map(explode(list, ","), (: trim :));

    this_player()->eventPrint("Enter message: ", MSG_PROMPT);
    input_to((: AddMessage :), emote, rules, verbs);
}

static void AddRule(string rule, string emote) {
    string array rules = map(explode(rule, ","), (: trim :));

    if( !sizeof(rules) ) {
	rules = ({ "" });
    }
    this_player()->eventPrint("Enter the verbs: ", MSG_PROMPT);
    input_to((: AddVerbs :), emote, rules);
}

static void AddErrorMessage(string msg, string emote) {
    if( !msg || msg == "" ) {
	this_player()->eventPrint("Which message? [q to quit] ", MSG_PROMPT);
	input_to((: AddErrorMessage :), emote);
	return;
    }
    if( !emote || emote == "" ) {
	this_player()->eventPrint("Which emote? [q to quit] ", MSG_PROMPT);
	input_to((: AddEmote :));
	return;
    }	
    emote = lower_case(emote);
    if( lower_case(msg) == "q" ) {
	this_player()->eventPrint("Addition of emote aborted.");
	return;
    }
    SOUL_D->AddVerb(emote, msg);
    this_player()->eventPrint("Enter a parser rule for " + emote + ": ",
      MSG_PROMPT);
    input_to((: AddRule :), emote);
}

static void AddEmote(string emote) {
    if( !emote || emote == "" ) {
	this_player()->eventPrint("Which emote? [q to quit] ", MSG_PROMPT);
	input_to((: AddEmote :));
	return;
    }
    emote = lower_case(emote);
    if( emote == "q" ) {
	this_player()->eventPrint("Addition of emote aborted.");
	return;
    }
    this_player()->eventPrint("Enter error message: ", MSG_PROMPT);
    input_to((: AddErrorMessage :), emote);
}

static void MainMenu() {
    string array emotes = SOUL_D->GetEmotes();
    string array display = allocate(sizeof(emotes));
    int array screen = this_player()->GetScreen() || ({ 80, 25 });
    string tmp;
    int i;

    tmp = center("Dead Souls V Emote Editor", screen[0]) + "\n";
    for(i=0; i<sizeof(display); i++) {
	display[i] = "[" + (i+1) + "] " + emotes[i];
    }
    tmp += format_page(display, screen[0]/17) + "\n";
    this_player()->eventPrint(tmp, MSG_SYSTEM);
    this_player()->eventPrint("Enter an emote or 'q' to quit: ", MSG_PROMPT);
    input_to((: EnterEmote :), emotes);
}

static void EditErrorMessage(string emote) {
    this_player()->eventPrint("Enter new error message: ", MSG_PROMPT);
    input_to(function(string str, string emote) {
	  if( str && str != "" ) {
	      SOUL_D->SetErrorMessage(emote, str);
	  }
	  ShowEmote(emote);
      }, emote);
}

static void ShowEmote(string emote) {
    string err = SOUL_D->GetErrorMessage(emote);
    mapping rules = SOUL_D->GetRules(emote);
    int array screen = this_player()->GetScreen() || ({ 80, 25 });
    string tmp = center("Dead Souls V Emote Editor", screen[0]) + "\n\n";
    string array rule_array = allocate(sizeof(rules));
    int i = 0;

    tmp += "%^GREEN%^Emote%^RESET%^: " + emote + "\n";
    tmp += "%^GREEN%^Error Message%^RESET%^: " + err + "\n";
    tmp += "%^GREEN%^Rules%^RESET%^:\n";
    foreach(string rule, mixed array data in rules) {
	rule_array[i] = rule;
	tmp += "[" + (i+1) + "] \"" + rule + "\": " + data[1][1] + "\n";
	tmp += "  Adverbs: " + wrap(item_list(data[0]), screen[0]) + "\n";
	i++;
    }
    this_player()->eventPage(explode(tmp, "\n"), MSG_SYSTEM,
      function(mixed args) {
	  string tmp = "Enter rule to edit, 'a' to "
	  "add rule, 'e' to edit error "
	  "msg, or 'q' to quit: ";

	  this_player()->eventPrint(tmp, MSG_PROMPT);
	  input_to((: EnterEditChoice :), args...);
      }, ({ rule_array, emote }));
}

mixed cmd(string args) {
    if( !args || args == "" ) {
	this_player()->eventPrint("Enter emote name: ", MSG_PROMPT);
	input_to((: AddEmote :));
    }
    else if( args[0] == '-' ) {
	if( args == "-edit" ) {
	    MainMenu();
	}
	else if( args == "-add") {
	    this_player()->eventPrint("Enter emote name: ", MSG_PROMPT);
	    input_to((: AddEmote :));
	}
	else {
	    MainMenu();
	}
    }
    else {
	if( member_array(args, SOUL_D->GetEmotes()) == -1 ) {
	    AddEmote(args);
	}
	else {
	    ShowEmote(args);
	}
    }
    return 1;
}

string GetHelp(string str) {
    return ("Syntax: <addemote>\n"
      "        <addemote EMOTE>\n"
      "        <addemote -edit>\n"
      "        <addemote -add>\n\n"
      "Used to add and edit emotes in the soul daemon using complex "
      "rules and the Dead Souls V messaging system.  In order to add "
      "a new emote using this command, you need to know the following "
      "information:\n"
      "\t* Verb parse rule\n"
      "\t* Verbs to be conjugated in the message\n"
      "\t* The messaging system generic format for the message\n"
      "\t* Any adverbs supported specially for the message\n\n"
      "The verb parse rule is a set of tokens governing how the "
      "command should be entered. The only tokens supported by the "
      "soul are LIV (for one living thing), LVS (for one to many living "
      "things), and STR (for any arbitrary string).  In addition, the "
      "rule can contains prepositions like to, at, on, about, etc.  "
      "For example, to allow a player to do <smile at descartes>, you "
      "need the parse rule <at LIV> or <at LVS>.  <smile oddly at "
      "descartes> would be <STR at LIV> or <STR at LVS>.\n"
      "In general, you should allow players to enter in commands using "
      "correct English and a syntax without prepositions.  For "
      "example, since we have <at LVS>, we should also allow "
      "<LVS>.  To support identical rules like this, when the "
      "<addemote> command asks for a parser rule, you can enter in "
      "multiple identical rules on the same line, separated by "
      "commas:\n"
      "Enter parser rule: at LVS,LVS\n\n"
      "The next step is defining which verbs need conjugating in your "
      "message for the emote.  With the smile emote, the only verb is "
      "\"smile\".  However, for more complex emotes, you may have "
      "multiple verbs which need conjugating.  Just enter them as a "
      "comma separated list.  For example, if you have an emote that "
      "should print the message \"Descartes rants and raves.\", then "
      "you will need to enter the verbs rant and rave:\n"
      "Enter verbs: rant,rave\n\n"
      "The next step is specifying the message that gets shown.  Your "
      "message uses place holders, also called tokens, to stand in "
      "for bits of the message that change depending on point of "
      "view.  In the rant and rave example, Descartes would see:\n"
      "You rant and rave.\n"
      "Everyone else sees:\n"
      "Descartes rants and raves.\n"
      "The only thing that stays the same is the word \"and\".  You "
      "need tokens to stand for the rest.  A full list of tokens is "
      "specified in <help messaging> and they all begin with a $ sign.  "
      "One extremely important thing to remember is that you need "
      "the exact same number of $agent_verb or $target_verb tokens in "
      "your message as the number of verbs you specified for "
      "conjugation.  In the rant and rave example, I need two verb "
      "tokens to match up with my two verbs I am conjugating.  They "
      "will be handled in the order they appear.  In other words, the "
      "rant verb will match to the first verb token, and the rave "
      "verb will match to the second verb token.  Verb tokens count "
      "as any combination of $agent_verb and $target_verb:\n"
      "Enter message: $agent_name $agent_verb and $agent_verb.\n\n"
      "The last thing you need to enter is a list of adverbs.  "
      "As with other lists, this list is comma separated.  And as with "
      "other bits of this system, it has a little complexity to it.  "
      "If you do not enter anything, then no adverbs are used for this "
      "rule.  In fact, you must specify a STR token in the rule for "
      "adverbs to be relevant.  If you do specify an STR rule, you "
      "should specify something on the adverb line.  Any adverbs you "
      "enter are considered special adverbs just for this rule.  If "
      "you wish the general list of adverbs to be available as well, "
      "you can enter a - as one of the adverbs.  If you wish the "
      "player to be able to add anything that comes to mind, enter "
      "a *:\n"
      "Enter adverbs: -");
}