RoomCreator.c

nightmare3_mudos_v1/lib/std/obj/RoomCreator.c · 3.8 KB

From the archive nightmare3_mudos_v1.tar.gz

Download the archive   « Back to the archive contents

#include <std.h>

inherit OBJECT;

static private string __Short, __Long, __File;
static private mapping __Actions, __Items, __Smells, __Listens, __Objects;

void create() {
    Object::create();
    set_name("roomcreator");
    set_id( ({ "roomcreator" }) );
    set_adjectives( ({ "silly" }) );
    set_short("a room creator");
    set_long("A room creator")
    set_prevent_get( (: "remove" :) );
    set_prevent_put( (: "remove" :) );
    set_prevent_drop( (: "remove" :) );
    set_invis(1);
    set_mass(0);
    set_value(0);
    __Actions = ([]);
    __Items = ([]);
    __Smells = ([]);
    __Listens = ([]);
    __Objects = ([]);
}
    
void create_room(string str) {
    string file;

    file = absolute_path((string)this_player()->get_path(), str);
    if(!((int)master()->valid_write(file, this_player()))) {
        this_object()->remove();
        return;
      }
    __File = file;
    main_menu();
    primary_prompt();
    input_to("main_cmd");
  }

static void primary_prompt() { message("prompt","\nCommand: ",this_player()); }

static private void main_menu() {
    message("info", "\n%^INITTERM%^The Nightmare Mudlib Room Creator "
      "\t\tDescartes of Borg 1993", this_player());
    message("info", sprintf("\n%s", center(sprintf("File name: %s", __File))),
      this_player());
    if(__Short) message("info", sprintf("\n\n%%^BOLD%%^Short:%%^RESET%%^ "
      "%s", __Short), this_player());
    else message("info","\n\n%^BOLD%^No short description set.",this_player());
    if(__Long) message("info", sprintf("\n\nLong:\n%s", 
      describe_long()), this_player());
    else message("info", "\n\n%^BOLD%^No long description set.",this_player());
    message("info", \n\n\t\tedit: L)ong description, S)hort description",
      this_player());
    message("info", "\tcreate/remove: a)ctions, i)tems, l)istens, o)bjects, "
      "s)mells", this_player());
}

static private string describe_long() {
    string *items;
    string ret;
    int i, j, x;

    i = sizeof(items = keys(__Items));
    ret = __Long;
    while(i--) {
        if(stringp(items[i]) && (x = strsrch(__Long, items[i])) != -1)
          ret = replace_string(ret, items[i], sprintf("%%^BOLD%%^GREEN%%^%s"
            "%%^RESET%%^", items[i]));
        else if(pointerp(items[i])) {
            j = sizeof(items[i]);
            while(j--) 
              if((x = strsrch(__Long, items[i][j])) != -1)
                ret = replace_string(ret, items[i][j],
                  sprintf("%%^BOLD%%^GREEN%%^%s%%^RESET%%^", items[i][j]));
	  }
    }
    return ret;
}

static void main_cmd(string str) {
    string *tmp;
    string args;

    if(str == "" || !str) {
        message("info", "\n%^RED%^Invalid room creator command.", 
          this_player());
        primary_prompt();
        input_to("main_cmd");
        return;
    }
    str = (tmp = explode(str, " "))[0][0..0];
    if(sizeof(tmp) > 1) args = implode(tmp, " ");
    else args = "";
    switch(str) {
        case "a": actions(args); return;
        case "h": help(args); return;
        case "i": items(args); return;
        case "l": listens(args); return;
        case "L": edit_long(); return;
        case "o": Objects(args); return;
        case "s": smells(args); return;
        case "S": short(args); return;
    }
}

static private void edit_long() {
    if(__Long) write_file("/tmp/"+(string)this_player()->query_name()+
      ".RoomCreator", wrap(__Long, 75));
    message("info", "\n%^INITTERM%^Long description for: "+__File,
      this_player());
    this_player()->edit("/tmp/"+(string)this_player()->query_name()+
      ".RoomCreator", "change_long", this_object());
}

void change_long() {
    string str;

    if(str = read_file("/tmp/"+(string)this_player()->query_name()+
      ".RoomCreator")) __Long = replace_string(str, "\n", " ");
    main_menu();
    primary_prompt();
    input_to("main_cmd");
}

Site Stats

Snippets: 1791
Codebases: 571