#include <lib.h> #include <vendor_types.h> inherit LIB_ITEM; string original, digested; mapping AreaMap = ([]); mapping RawMap = ([]); mapping Genders = ([ 0 : "neutral", 1 : "male", 2 : "female" ]); mapping Directions = ([ 0 : "north", 1 : "east", 2 : "south", 3 : "west", 4 : "up", 5 : "down", 6 : "northeast", 7 : "northwest", 8 : "southeast", 9 : "southwest", 10 : "somewhere" ]); mapping Types = ([ 1 : "LIB_ITEM", 2 : "LIB_ITEM", 3 : "LIB_ITEM", 4 : "LIB_ITEM", 5 : "LIB_ITEM", 6 : "LIB_ITEM", 7 : "LIB_ITEM", 8 : "LIB_ITEM", 9 : "LIB_ARMOR", 10 : "LIB_POTION", 11 : "LIB_ITEM", 12 : "LIB_BED", 13 : "LIB_ITEM", 14 : "LIB_ITEM", 15 : "LIB_STORAGE", 16 : "LIB_ITEM", 17 : "LIB_MEAL", 18 : "LIB_ITEM", 19 : "LIB_MEAL", 20 : "LIB_PILE", 21 : "LIB_ITEM", 22 : "LIB_ITEM", 23 : "LIB_ITEM", 24 : "LIB_ITEM", 25 : "LIB_ITEM", 26 : "LIB_ITEM", 44 : "LIB_ITEM" ]); string gdirection, cle, val; int item_type, extra_flags, wear_flags; int tmp1, tmp2, tmp3; mixed value_1, value_2, value_3, value_4, value_5; int weight, cost, cost_per_day; int lock, key, room, direction; int ok, ok2; void create(){ ::create(); SetKeyName("converter"); SetId( ({"device"}) ); SetAdjectives( ({"conversion"}) ); SetShort("a conversion device"); SetLong("This is an object that lets you convert Smaug areas into Dead Souls domains."); SetMass(200); SetDollarCost(10); SetVendorType(VT_TREASURE); } void init(){ ::init(); add_action("ConvertArea","convert"); add_action("Report","report"); } int Report(string str){ print_long_string(this_player(),"vnums: "+item_list(keys(AreaMap)),1); if(str == "both" || str == "area") print_long_string(this_player(),"%^RED%^AreaMap: "+identify(AreaMap),1); if(str == "both" || str == "raw") print_long_string(this_player(),"%^GREEN%^RAWMap: "+identify(RawMap),1); if(sscanf(str,"%*d")) this_object()->DisplayVnum(str); return 1; } int DisplayVnum(string str){ if(!str || !AreaMap[str]){ write("No such vnum in this area."); return 1; } print_long_string(this_player(),"vnum "+str+":\n"+identify(AreaMap[str]),1); return 1; } int ConvertArea(string arg){ string tmp, str, name, prefix; int i; string *rooms_arr; string *obs_arr; string *delimiters = ({ "#AREA", "#VERSION", "#AUTHOR", "#RANGES", "#RESETMSG", "#FLAGS", "#ECONOMY", "#CLIMATE", "#HELPS", "#MOBILES", "#OBJECTS", "#ROOMS", "#RESETS", "#SHOPS", "#REPAIRS", "#SPECIALS", "#$" }); string *new_delimiters = ({}); string *segmented = ({}); if(!arg || sscanf(arg,"%s %s",str, name) != 2){ write("convert FILE AREA"); return 1; } if(!str || !file_exists(str)){ write("No such area file exists."); return 1; } original = read_file(str); digested = original; foreach(string element in delimiters){ tmp = replace_string(element,"#","0^0"); //tc("tmp: "+tmp); digested = replace_string(digested,element,tmp); new_delimiters += ({ tmp }); } segmented = explode(digested,"0^0"); //print_long_string(this_player(),identify(segmented),1); foreach(mixed element in segmented){ string *minced = explode(element,"\n"); if(!RawMap) RawMap = ([]); RawMap[minced[0]] = minced[1..]; } ///// // ITEMS ///// tmp = implode(RawMap["OBJECTS"],"\n"); prefix = "/domains/"+name+"/obj/"; obs_arr = explode(tmp,"#"); foreach(mixed block in obs_arr){ string *ob_id; string *lines = explode(block,"\n"); string short, long, ob_name; string header = ""; ok = 0; //tc("block: "+block); if(block && sizeof(lines) > 1){ ob_id = explode(truncate(lines[1],1)," "); if(!sizeof(ob_id)) continue; ob_name = ob_id[0]; short = truncate(lines[2],1); long = ""; for(i=2;i < sizeof(lines);i++){ int num = i; if(sscanf(lines[i],"%d %d %d %d",value_1, value_2, value_3, value_4) == 4){ ok = 1; } else if(sscanf(lines[i],"%d %d %d",tmp1, tmp2, tmp3) == 3){ if(ok){ weight = tmp1; cost = tmp2; cost_per_day = tmp3; } else { item_type = tmp1; extra_flags = tmp2; wear_flags = tmp3; } } if(lines[i] == "E"){ for(num = i+2; num < sizeof(lines);num++){ if(lines[num] == "~") break; long += lines[num]+" "; } break; } } } header += "#include <lib.h>\n\n"; header += "inherit "+(Types[item_type] || "LIB_ITEM")+";\n\n"; header += "static void create() {\n"; header += " ::create();\n"; header += " SetKeyName(\""+ob_name+"\");\n"; header += " SetId( "+identify(ob_id)+" );\n"; header += " SetShort(\""+short+"\");\n"; header += " SetLong(\""+long+"\");\n"; header += " SetMass("+weight+");\n"; header += " SetBaseCost("+cost+");\n"; header += "}\nvoid init(){\n::init();\n}\n"; //print_long_string(this_player(), header, 1); //tc("file above was: "+prefix+lines[0]+"_"+ob_name+".c"); if(directory_exists(truncate(prefix,1))){ write_file(prefix+lines[0]+"_"+ob_name+".c",header,1); } if(!AreaMap) AreaMap = ([]); if(!AreaMap[lines[0]]) AreaMap[lines[0]] = ([ prefix+lines[0]+"_"+ob_name+".c" : header ]); else AreaMap[lines[0]][prefix+lines[0]+"_"+ob_name+".c"] = header; } ///// // MOBS ///// tmp = implode(RawMap["MOBILES"],"\n"); prefix = "/domains/"+name+"/npc/"; obs_arr = explode(tmp,"#"); foreach(mixed block in obs_arr){ string *ob_id; string *lines = explode(block,"\n"); string short, long, ob_name; string header = ""; ok = 0; ok2 = 0; //tc("block: "+block); if(block && sizeof(lines) > 1){ ob_id = explode(truncate(lines[1],1)," "); if(!sizeof(ob_id)) continue; ob_name = ob_id[0]; short = truncate(lines[2],1); long = ""; for(i=0;i < sizeof(lines);i++){ int num = i; if(!ok && sscanf(lines[i],"%d %d %d %s %s",value_1, value_2, value_3, value_4, value_5) == 5){ ok =1; } if( ok == 1 && sizeof(explode(lines[i]," ")) == 3 && sscanf(lines[i],"%d %d %d",value_2, value_3, value_4) == 3){ //tc("Gender: "+value_4); ok++; } if(!ok2 && i > 3){ if(i > 4 && lines[i] == "~"){ ok2 = 1; continue; } if(lines[i] != "~") long += lines[i]+" "; } } header += "#include <lib.h>\n\n"; header += "inherit LIB_SENTIENT;\n\n"; header += "static void create(){\n"; header += " ::create();\n"; header += " SetKeyName(\""+ob_name+"\");\n"; header += " SetId( "+identify(ob_id)+" );\n"; header += " SetShort(\""+short+"\");\n"; header += " SetLong(\""+long+"\");\n"; header += " SetLevel("+value_1+");\n"; header += " SetRace(\"human\");\n"; header += " SetNoCondition(1);\n"; header += " SetGender(\""+Genders[value_4]+"\");\n"; header += "}\nvoid init(){\n::init();\n}\n"; //print_long_string(this_player(), header, 1); //tc("file above was: "+prefix+lines[0]+"_"+ob_name+".c"); if(directory_exists(truncate(prefix,1))){ write_file(prefix+lines[0]+"_"+ob_name+".c",header,1); } if(!AreaMap) AreaMap = ([]); if(!AreaMap[lines[0]]) AreaMap[lines[0]] = ([ prefix+lines[0]+"_"+ob_name+".c" : header ]); else AreaMap[lines[0]][prefix+lines[0]+"_"+ob_name+".c"] = header; } } ///// // ROOMS ///// tmp = implode(RawMap["ROOMS"],"\n"); prefix = "/domains/"+name+"/room/"; rooms_arr = explode(tmp,"#"); foreach(mixed block in rooms_arr){ string *lines = explode(block,"\n"); string short, long; string header = "#include <lib.h>\n"; header += "#include <rooms.h>\n\n"; header += "inherit LIB_ROOM;\n\n"; header += "void create() {\n"; header += " room::create();\n"; header += " SetClimate(\"indoors\");\n"; header += " SetAmbientLight(30);\n"; short = truncate(lines[1],1); long = ""; for(i=2;i < sizeof(lines);i++){ if(lines[i] == "~") break; long += lines[i]+" "; } header += " SetShort(\""+short+"\");\n"; header += " SetLong(\""+long+"\");\n"; header += " SetExits( ([\n"; for(i=i;i < sizeof(lines);i++){ //int lock, key, room, direction; lock = key = room = direction = 0; if(lines[i] == "S") break; if(sscanf(lines[i],"%d %d %d",lock, key, room) == 3){ if(sscanf(lines[i+1],"D%d",direction)){ if(room == 0){ gdirection = Directions[direction]; continue; } else header += " \""+Directions[direction]+"\" : \""+prefix+room+"\",\n"; } else if(sizeof(gdirection) > 1){ if(room != 0) header += " \""+gdirection+"\" : \""+prefix+room+"\",\n"; gdirection = ""; } } } header += " ]) );\n"; header += " SetInventory( ([\n"; if(AreaMap && AreaMap[lines[0]]) foreach(cle, val in AreaMap[lines[0]]){ if(!grepp(val,"LIB_ROOM")){ header += " \""+cle+"\" : 1,\n"; } } header += " ]) );\n"; header += "}\n"; header += "void init(){\n"; header += " ::init();\n"; header += "}\n"; //print_long_string(this_player(),header,1); //tc("file above was: "+prefix+lines[0]+".c"); if(directory_exists(truncate(prefix,1))){ write_file(prefix+lines[0]+".c",header,1); } if(!AreaMap) AreaMap = ([]); if(!AreaMap[lines[0]]) AreaMap[lines[0]] = ([ prefix+lines[0]+".c" : header ]); else AreaMap[lines[0]][prefix+lines[0]+".c"] = header; } return 1; }