Guest User

importZMap.js

a guest
Oct 10th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. conn = new ActiveXObject("ADODB.Connection");
  3. rs = new ActiveXObject("ADODB.Recordset");
  4. function loadTbl(table_name) {
  5.     var ret = {};
  6.     rs.Open("SELECT * FROM " + table_name, conn);
  7.     if (!rs.bof) {
  8.         rs.MoveFirst();
  9.         while (!rs.eof) {
  10.             var row = {};
  11.             for (var i = 0; i < rs.fields.count; i++)
  12.                 row[rs.fields(i).name] = rs.fields(i).value;
  13.             ret[rs.fields(0).value] = row;
  14.             rs.MoveNext();
  15.         }
  16.     }
  17.     rs.Close();
  18.     return ret;
  19. }
  20.  
  21. function sign(x) {
  22.     return typeof x === 'number' ? x ? x < 0 ? -1 : 1 : x === x ? 0 : NaN : NaN;
  23. }
  24. function loadZMap(filepath) {
  25.     conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath);
  26.    
  27.     var zones = loadTbl("ZoneTbl");
  28.     var rooms = loadTbl("ObjectTbl");
  29.     var dirs = loadTbl("DirTbl");
  30.     var exits = loadTbl("ExitTbl");
  31.    
  32.     var total_rooms = 0;
  33.    
  34.     jmc.parse(jmc.CommandChar + "mapper clear");
  35.    
  36.     for (var id in dirs) {
  37.         var dir = dirs[id];
  38.         var rev = dirs[dir.RevId];
  39.         jmc.parse(jmc.CommandChar + "mapper add direction {" + dirs[id].DirName + "} " + sign(dir.Dx) + " " + sign(-dir.Dy) + " " + sign(dir.Dz) + "  {" + rev.DirName + "}");
  40.     }
  41.    
  42.     jmc.showme("Loading rooms");
  43.     for (var rid in rooms) {
  44.         var room = rooms[rid];
  45.         if (room.KindID != 0) //'Room'
  46.             continue;
  47.         room.Desc = "";
  48.         jmc.parse(jmc.CommandChar + "mapper autoid {" + room.Name + "} {" + room.Desc + "} {} PrimaryId");
  49.         var secondary = room.ObjId;
  50.         var primary = jmc.GetVar("PrimaryId");
  51.         if (primary.indexOf('.') >= 0)
  52.             primary = primary.substr(0, primary.indexOf('.'));
  53.         var id = primary + "." + secondary;
  54.         rooms[rid]['jmcId'] = id;
  55.        
  56.         jmc.parse(jmc.CommandChar + "mapper add room " + id + " {" + room.Name + "} {" + room.Desc + "} {} {} {}");
  57.        
  58.         total_rooms += 1;
  59.     }
  60.    
  61.     jmc.showme("Total rooms: " + total_rooms + ", loading exits");
  62.     for (var eid in exits) {
  63.         var exit = exits[eid];
  64.         var fromid = rooms[exit.FromID].jmcId;
  65.         var toid =  rooms[exit.ToID].jmcId;
  66.         var dir = dirs[exit.DirType + 1];
  67.         if (!fromid) {
  68.             jmc.showme("Can't find from-room: <" + exit.FromID + "> (" + dir.DirName + ")");
  69.             continue;
  70.         }
  71.         if (!toid) {
  72.             jmc.showme("Can't find to-room: <" + exit.ToID + "> (" + dir.DirName + ")");
  73.             continue;
  74.         }
  75.         jmc.parse(jmc.CommandChar + "mapper add exit " + fromid + " {" + dir.DirName + "} " + toid);
  76.     }
  77.     jmc.showme("Done.");
  78.    
  79.     conn.Close();
  80. }
  81.  
  82. /* usage:
  83.    - copy importZMap.js to ./settings
  84.    - copy <worldname>.mdb from zMUD to ./zmap.mdb
  85.    - execute in jmc:
  86.      #use importZMap.js
  87.      #scri loadZMap("zmap.mdb")
  88.      #mapper write z.map
  89. */
Add Comment
Please, Sign In to add comment