foundationI_fluffos_v1/
foundationI_fluffos_v1/bin/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/ChangeLog.old/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/Win32/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/compat/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/compat/simuls/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/include/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/clone/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/command/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/data/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/etc/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/include/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/inherit/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/inherit/master/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/log/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/compiler/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/efuns/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/single/tests/operators/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/testsuite/u/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/tmp/
foundationI_fluffos_v1/fluffos-2.9-ds2.12/windows/
foundationI_fluffos_v1/lib/
foundationI_fluffos_v1/lib/cmds/ambassador/
foundationI_fluffos_v1/lib/cmds/database/
foundationI_fluffos_v1/lib/cmds/soul/
foundationI_fluffos_v1/lib/daemon/include/
foundationI_fluffos_v1/lib/daemon/save/
foundationI_fluffos_v1/lib/daemon/services/
foundationI_fluffos_v1/lib/daemon/soul/
foundationI_fluffos_v1/lib/doc/build/
foundationI_fluffos_v1/lib/doc/build/room/
foundationI_fluffos_v1/lib/doc/build/virtual/
foundationI_fluffos_v1/lib/doc/driver/
foundationI_fluffos_v1/lib/doc/efun/
foundationI_fluffos_v1/lib/doc/etc/
foundationI_fluffos_v1/lib/doc/help/creator/
foundationI_fluffos_v1/lib/doc/help/hm/
foundationI_fluffos_v1/lib/doc/help/user/
foundationI_fluffos_v1/lib/doc/lpc/basic/
foundationI_fluffos_v1/lib/doc/lpc/data_types/
foundationI_fluffos_v1/lib/doc/lpc/etc/
foundationI_fluffos_v1/lib/doc/lpc/intermediate/
foundationI_fluffos_v1/lib/doc/lpc/types/
foundationI_fluffos_v1/lib/doc/mudlib/
foundationI_fluffos_v1/lib/doc/mudlib/features/
foundationI_fluffos_v1/lib/domains/Examples/etc/
foundationI_fluffos_v1/lib/domains/Examples/room/
foundationI_fluffos_v1/lib/domains/Examples/virtual/
foundationI_fluffos_v1/lib/domains/Examples/virtual/exaA/
foundationI_fluffos_v1/lib/domains/Examples/virtual/exaB/
foundationI_fluffos_v1/lib/domains/Examples/weapon/
foundationI_fluffos_v1/lib/domains/Standard/
foundationI_fluffos_v1/lib/domains/Standard/pools/
foundationI_fluffos_v1/lib/domains/Standard/std/
foundationI_fluffos_v1/lib/domains/Standard/xtra/
foundationI_fluffos_v1/lib/include/
foundationI_fluffos_v1/lib/news/
foundationI_fluffos_v1/lib/secure/cfg/
foundationI_fluffos_v1/lib/secure/cmds/adm/
foundationI_fluffos_v1/lib/secure/cmds/ambassador/
foundationI_fluffos_v1/lib/secure/cmds/mortal/
foundationI_fluffos_v1/lib/secure/etc/
foundationI_fluffos_v1/lib/secure/etc/approval/
foundationI_fluffos_v1/lib/secure/etc/elections/
foundationI_fluffos_v1/lib/secure/etc/mudlib/
foundationI_fluffos_v1/lib/secure/etc/quests/
foundationI_fluffos_v1/lib/secure/save/daemon/
foundationI_fluffos_v1/lib/secure/save/postal/d/descartes/
foundationI_fluffos_v1/lib/secure/save/users/d/
foundationI_fluffos_v1/lib/secure/std/
foundationI_fluffos_v1/lib/std/obj/
foundationI_fluffos_v1/lib/std/room/
foundationI_fluffos_v1/lib/std/user/
foundationI_fluffos_v1/lib/std/virtual/
foundationI_fluffos_v1/old/
foundationI_fluffos_v1/win32/
/*    /daemon/help.c
 *    from Nightmare IV
 *    daemon handling mud help functions and help interface
 *    created by Descartes of Borg 940420
 */

#include <std.h>
#include <daemons.h>
#include <dirs.h>
#include "help.h"

inherit DAEMON;

varargs void help(string topic, string category, int menu) {
    if(!topic) topic = "*general";
    else if(topic[0] == '*') help_menu(topic, 0, 0);
    else cmd_help(topic, category, menu);
}

static void help_menu(string category, string *topics, int ind) {
    string tmp;
    int i, maxi, x;

    if(!topics && !(topics = query_topics(category))) {
        message("help", "\nInvalid help category.", this_player());
        message("prompt", "\nSelection: ", this_player());
        input_to("select_topic", category, topics, ind);
        return;
    }
    if((maxi = ind+40) > sizeof(topics)) maxi = sizeof(topics);
    if(!(int)this_player()->query_env("NO_CLEAR"))
    message("info", sprintf("\n%%^INITTERM%%^Category: %%^GREEN%%^"
      "%s%%^RESET%%^    \t%s System Help    \t"
      "Page: %d\n", category, mud_name(), ind/40+1),
      this_player());
    else
    message("info", sprintf("\nCategory: %%^GREEN%%^"
      "%s%%^RESET%%^    \t%s System Help    \t"
      "Page: %d\n", category, mud_name(), ind/40+1),
      this_player());
    i = ind;
    while(i < maxi) {
        if((x = i + 4) >=maxi) x = maxi;
        tmp = "";
        while(i < x) {
            tmp += arrange_string(topics[i], 17);
            i++;
        }
        message("info", tmp, this_player());
    }
    message("info", sprintf("\n%%^CYAN%%^Available categories:\n%s",
      format_page(query_categories(), 3)), this_player());
    message("info", "\nTo choose another category, enter the name of "
      "the category.", this_player());
    message("info", "To view help on any of the above topics, "
      "enter the name of the topic.", this_player());
    message("info", "To see the next page of topics, enter the "
      "<return> key.", this_player());
    message("info", "To quit from help, enter \"q\" alone.",
      this_player());
    message("prompt", "Selection: ", this_player());
    input_to("select_topic", category, topics, ind);
}

static void select_topic(string str, string category, string *topics,int ind) {
    if(str == "") {
        if(ind+40 < sizeof(topics)) help_menu(category, topics, ind+40);
        else help_menu(category, topics, ind);
        return;
      }
    else if(str == "q") {
        message("help", "\nExit from help.", this_player());
        return;
      }
    else help(str, category, 1);
  }

static string *query_categories() {
    string *tmp;

    tmp = ({ "*player general", "*player commands", "*abilities" });
    if((string)this_player()->query_guild()) tmp += ({ "*guild commands" });
    if(high_mortalp(this_player()) || creatorp(this_player()))
      tmp += ({ "*high mortal general", "*high mortal commands" });
    if(ambassadorp(this_player()))
      tmp += ({ "*ambassador general", "*ambassador commands" });
    if(creatorp(this_player())) 
      tmp += ({ "*creator general", "*creator commands" });
    if(adminp(this_player())) tmp += ({ "*admin commands" }); 
    return tmp;
  }

static string *query_topics(string category) {
    string tmp;

    switch(category) {
    case "*player general": return get_dir(DIR_USER_HELP+"/");
    case "*creator general":
        if(!creatorp(this_player())) return 0;
        else return get_dir(DIR_CREATOR_HELP+"/");
    case "*ambassador general":
        if(!creatorp(this_player()) && !adminp(this_player())) return 0;
        else return get_dir(DIR_AMBASSADOR_HELP+"/");
    case "*high mortal general":
        if(!creatorp(this_player()) && !high_mortalp(this_player())) return 0;
        else return get_dir(DIR_HM_HELP+"/");
    case "*player commands":
        return (string *)CMD_D->query_commands(DIR_MORTAL_CMDS);
    case "*abilities":
        return (string *)CMD_D->query_commands(DIR_CLASS_CMDS);
    case "*guild commands":
        if(!(tmp = (string)this_player()->query_guild())) return 0;
        else return (string *)CMD_D->query_commands(DIR_GUILD_CMDS+"/"+tmp);
    case "*creator commands":
        if(!creatorp(this_player())) return 0;
        return (string *)CMD_D->query_commands(DIR_CREATOR_CMDS) +
          (string *)CMD_D->query_commands(DIR_SYSTEM_CMDS) +
          (string *)CMD_D->query_commands(DIR_AMBASSADOR_CMDS);
    case "*high mortal commands":
        if(!creatorp(this_player()) && !high_mortalp(this_player())) return 0;
        return (string *)CMD_D->query_commands(DIR_HM_CMDS);
    case "*ambassador commands":
        if(!creatorp(this_player()) && !ambassadorp(this_player())) return 0;
        return (string *)CMD_D->query_commands(DIR_AMBASSADOR_CMDS) +
          (string *)CMD_D->query_commands(DIR_SYSTEM_CMDS);
    case "*admin commands":
        if(!adminp(this_player())) return 0;
        else return (string *)CMD_D->query_commands(DIR_ADMIN_CMDS);
    default: return 0;
    }
  }

void cmd_help(string topic, string category, int menu) {
    object ob;
    string *tmp;
    int i;

    if(category) {
        if(member_array(category, query_categories()) == -1) {
            message("help", sprintf("Category %s not available.",
              category), this_player());
            if(menu) {
                message("prompt", "\nHit <return> to continue: ", 
                  this_player());
                input_to("menu_return", category);
	      }
	  }
        else if(!find_help(topic, category, menu)) {
            message("help", sprintf("The help topic %s does not exist in "
              "the category %s.", topic, category), this_player());
            if(menu) {
                message("prompt", "\nHit <return> to continue: ",
                  this_player());
                input_to("menu_return", category);
	      }
	  }
        return;
      }
    else {
        i = sizeof(tmp = query_categories());
        while(i--) if(find_help(topic, tmp[i], menu)) return;
        if((ob = present(topic, this_player())) &&
          function_exists("help", ob)) {
            ob->help();
            return;
	  }
        else if((ob = present(topic, environment(this_player()))) &&
          function_exists("help", ob)) {
            ob->help();
            return;
	  }
        message("help", sprintf("No help available for the topic %s.",
          topic), this_player());
        if(menu) {
            message("prompt", "\nHit <return> to continue: ", this_player());
            input_to("menu_return", category);
	  }
        return;
      }
  }

static int find_help(string topic, string category, int menu) {
    object ob;
    string str;
    mixed tmp;

    switch(category) {
    case "*player general":
        if(!file_exists(tmp = DIR_USER_HELP+"/"+topic)) return 0;
        break;
    case "*player commands":
        if(!file_exists(tmp = DIR_MORTAL_CMDS+"/_"+topic+".c")) return 0;
        if(!(ob = load_object(tmp)) || !function_exists("help", ob))
          return 0;
        tmp = ob;
        break;
    case "*abilities":
        if(!file_exists(tmp = DIR_CLASS_CMDS+"/_"+topic+".c")) return 0;
        if(!(ob = load_object(tmp)) || !function_exists("help", ob))
          return 0;
        tmp = ob;
        break;
    case "*creator general":
        if(!file_exists(tmp = DIR_CREATOR_HELP+"/"+topic)) return 0;
        break;
    case "*creator commands":
        if(file_exists(tmp = DIR_CREATOR_CMDS+"/_"+topic+".c") &&
          (ob = load_object(tmp)) && function_exists("help", ob)) tmp = ob;
        else if(file_exists(tmp = DIR_SYSTEM_CMDS+"/_"+topic+".c") &&
          (ob = load_object(tmp)) && function_exists("help", ob)) tmp = ob;
        else if(file_exists(tmp = DIR_AMBASSADOR_CMDS+"/_"+topic+".c") &&
          (ob = load_object(tmp)) && function_exists("help", ob)) tmp = ob;
        else return 0;
        break;
    case "*ambassador general":
        if(!file_exists(tmp = DIR_AMBASSADOR_HELP+"/"+topic)) return 0;
        break; 
    case "*ambassador commands":
        if(file_exists(tmp = DIR_AMBASSADOR_CMDS+"/_"+topic+".c") &&
          (ob = load_object(tmp)) && function_exists("help", ob)) tmp = ob;
        else if(file_exists(tmp = DIR_SYSTEM_CMDS+"/_"+topic+".c") &&
          (ob = load_object(tmp)) && function_exists("help", ob)) tmp = ob;
        else return 0;
        break;
    case "*high mortal general":
        if(!file_exists(tmp = DIR_HM_HELP+"/"+topic)) return 0;
        break;
    case "*high mortal commands":  
        if(!file_exists(tmp = DIR_HM_CMDS+"/_"+topic+".c")) return 0;
        if(!(ob = load_object(tmp)) || !function_exists("help", ob))
          return 0;
        tmp = ob;
        break;
    case "*guild commands":
        if(!file_exists(tmp = sprintf("%s/%s/_%s.c", DIR_GUILD_CMDS,
          (string)this_player()->query_guild(), topic))) return 0;
        if(!(ob = load_object(tmp)) || !function_exists("help", ob))
          return 0;
        tmp = ob;
        break;
    case "*admin commands":
        if(!adminp(this_player())) return 0;
        if(!file_exists(tmp = DIR_ADMIN_CMDS+"/_"+topic+".c")) return 0;
        if(!(ob = load_object(tmp)) || !function_exists("help", ob))
          return 0;
        tmp = ob;
        break; 
      }
    if(!(int)this_player()->query_env("NO_CLEAR"))
    message("info", sprintf("\n%%^INITTERM%%^Topic: %%^GREEN%%^%s"
      "%%^RESET%%^  \t%s System Help \tCategory: %%^GREEN%%^%s\n", 
      topic, mud_name(), category), this_player());
    else
    message("info", sprintf("\nTopic: %%^GREEN%%^%s"
      "%%^RESET%%^  \t%s System Help \tCategory: %%^GREEN%%^%s\n",
      topic, mud_name(), category), this_player());
    if(objectp(tmp)) {
        tmp->help();
        if(menu) {
            message("prompt", "\nHit <return> to continue: ", this_player());
            input_to("menu_return", category);
        }
    }
    else this_player()->more(tmp, "help", (menu ? (: "endmore" :) : 0),
      (menu ? category : 0));
    return 1;
  }

static void menu_return(string duh, string category) {
    if(duh != "q") help(category);
}

void endmore(string category) {
    message("prompt", "\nHit <return> to continue: ", this_player());
    input_to("menu_return", category);
}