Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
robert
Wanderer


Joined: 25 Feb 2004
Posts: 98

PostPosted: Tue Dec 29, 2009 7:22 pm   

CMud import/export map zone.
 
Hey All,

Does anyone know some import/export map zones or something like that functionality is in the works or if there is a way to do it? I am starting to map the same mud with a friend, but it is hard for us to transfer over new areas mapped and such. The only way I have seen is to just send him the entire new map, but if I mapped a new zone, and he mapped a different new zone, I don't know how we can get in sync.

Thanks!
Reply with quote
masterkrueger
Wanderer


Joined: 24 Jan 2010
Posts: 65
Location: Hamburg

PostPosted: Tue Apr 27, 2010 6:32 pm   
 
same question here, 6 years later ^^ i use zMUD on my PC and Laptop and need a clean and save way to transfer the files. i.e. wich files are really necessary... and so on :)

Thanks too :)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Apr 27, 2010 7:43 pm   
 
The current beta version does not have any method for exporting or importing specific zones or subsets of maps. If I recall correctly, that is on the ToDo list.

As for Masterkrueger's question, the map itself is contained in the .dbm file in your session folder. I believe the mapper configuration is in the .zfg file. Are you only talking about transfering the map? If you want to transfer the session files, then you should just copy the entire session folder, and any package files you use (probably in the "packages" folder).

I'm not sure what you mean by "6 years later"?
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Apr 27, 2010 8:59 pm   
 
I think he means that a long long time ago, zMUD used to use a separate *.map file for each "zone". This was changed when the mapper started using a real database and all zones were stored within the same database file. There is currently no way to just import or export a single "zone" in the mapper. This was removed a long time ago and there are no plans to add it back. The external "MapConvert" program will eventually have a "pro" version that will be able to import/export zones, but there is no ETA for that.

However, masterkrueger is asking a different question I think...

First (1) do NOT reply to old posts like this. If you have a question, create a new post. It is considered bad forum practice on *any* Internet forum to resurrect old posts like this, especially when your question really doesn't have anything to do with the original post.

(2) Install CMUD and zMUD into different directories on your computer. When you run CMUD, use the zMUD Import command (in the File menu) to import your zMUD sessions. That will copy the necessary files from your old zMUD directory into your new CMUD directory. Once you are done with the zMUD Import then you don't need your zMUD directory anymore, although you should probably make a backup of it before deleting it in case you need it again in the future.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Wed Apr 28, 2010 12:52 pm   
 
Rahab wrote:
I'm not sure what you mean by "6 years later"?

I think he was making a mistake by looking at the persons join date as the post date rather than the post date, I just made the same mistake myself. Doh!
_________________
Taz :)
Reply with quote
masterkrueger
Wanderer


Joined: 24 Jan 2010
Posts: 65
Location: Hamburg

PostPosted: Thu Apr 29, 2010 6:04 pm   
 
Sorry for reactivating an old post, but it was the first post i found that matches my problem (now i see it doesn't) and correct i was looking on the wrong date stamp :)
But i would agree Zugg, to look better ;) but i did not know there was such a feature long ago...
I installed CMUD and zMUD in different folders and imported the zMUD database. I think i'll have to work some time with CMUD to get everything up and working again.
There are many things with the mapper that is not working like in zMUD before (i think it is my configuration that is not right).

But thanks for you answers! I see if i really have problems with this great tools i will get support.
Reply with quote
samio1221@gmail.com
Newbie


Joined: 02 Mar 2020
Posts: 4

PostPosted: Mon Mar 02, 2020 6:44 am   
 
I made a script that extracts and imports zones (zone info, room/objects, and exitlinks) into another map. I used this when remapping the grid on my map.
It is a python script, so you need to have python installed and/or be somewhat familiar with how to run it. I would also recommend installing sqlite3 or some sqlite3 browser so you can confirm the data.
And of course always backup your data and confirm the contents in between transfers.

It takes 3 params in the __main__:
1. old map db
2. new map db
3. list of zone nums to import from old map db

I just had it import about 20 or 30 zones consisting of about 10,000 rooms, and it took about 5 or 10 minutes.
If you mark placeholder zones on the new map named as "Available", it will prioritize using those zones and recycle the rooms/links in those zones first before creating new unique entries.
I've pasted the code here if you want to try it.


import sqlite3
from sqlite3 import Error

def ZoneTbl_EXE():
global zoneName
global newZoneID
zoneDict={}
roomDict={}
exitDict={}
""" Create database connection """
selectItems="*"
ZoneQuery = "SELECT "+selectItems+" FROM ZoneTbl WHERE ZoneID='"+str(ZoneID)+"'"
print("oldDB: ZoneQuery: ",ZoneQuery)

"""Grabbing oldDB ZoneTbl info"""
try:
oldDBCon = sqlite3.connect(oldDB)
cur = oldDBCon.cursor()
cur.execute(ZoneQuery)
rows = cur.fetchall()
header = [description[0] for description in cur.description]
for rownum in range(len(rows)):
for i in range(len(rows[rownum])):
zoneDict[header[i]]=rows[rownum][i]
zoneName=zoneDict['Name']
#print(zoneDict)
except Error:
print(Error)
finally:
oldDBCon.close()

"""Checking if zoneName exists. If not, create it"""
try:
ZoneQuery = 'Select * from ZoneTbl WHERE Name = "'+zoneName+'"'
print("Zone Check: '"+zoneName+"'. NewDB Query: "+ZoneQuery)
zoneCon = sqlite3.connect(newDB)
objCon = sqlite3.connect(newDB)
exitCon = sqlite3.connect(newDB)
zoneCur = zoneCon.cursor()
zoneCur.execute(ZoneQuery)
rows = zoneCur.fetchall()

"""if (len(rows)<=) then the zone doesn't exist: proceed to create it"""
if (int(len(rows))<=0):
"""If newDB has 'Available' placeholder zones, use that zone instead of creating new zone"""
ZoneQuery = 'Select [ZoneId] FROM ZoneTbl WHERE Name = "'+"Available"+'"'
print("Zone Check: '"+zoneName+"'. Doesn't exist. Checking for unused 'Available' zones. NewDB Query: "+ZoneQuery)
zoneCur.execute(ZoneQuery)
zones = zoneCur.fetchall()
zoneHeader = [description[0] for description in zoneCur.description]
if (int(len(zones))>0):
print("Available zones detected...")
#print("zoneHeader: ",zoneHeader)
#print("zones: ",zones)
for zone in zones:
zoneDict={}
#print("Zone: ",zone)
for z in range(len(zone)):
zoneDict[zoneHeader[z]]=zone[z]
newZoneID=zoneDict['ZoneId']

#Update all associated entries in ObjectTbl to have Name='Available'
ObjectQuery = 'SELECT [ObjId] FROM ObjectTbl WHERE ZoneId = "'+str(zoneDict['ZoneId'])+'"'
print("ObjectQuery: ",ObjectQuery)
objCur = objCon.cursor()
objCur.execute(ObjectQuery)
rooms=objCur.fetchall()
roomHeader = [description[0] for description in objCur.description]
for room in rooms:
for r in range(len(room)):
roomDict[roomHeader[r]]=room[r]
ObjectQuery='UPDATE ObjectTbl SET Name="'+"Available"+'" WHERE ObjId = "'+str(roomDict['ObjId'])+'"'
print("ObjectQuery: ",ObjectQuery)
objCur.execute(ObjectQuery)
objCon.commit()

#Update all associated entries in ExitTbl to have Name='Available'
ExitQuery='SELECT [ExitId] FROM ExitTbl WHERE FromID="'+str(roomDict['ObjId'])+'"'
print("ExitQuery: ",ExitQuery)
exitCur = exitCon.cursor()
exitCur.execute(ExitQuery)
exits=exitCur.fetchall()
exitHeader = [description[0] for description in exitCur.description]
for exit in exits:
exitDict={}
for e in range(len(exit)):
exitDict[exitHeader[e]]=exit[e]
ExitQuery='UPDATE ExitTbl SET Name="'+"Available"+'" WHERE FromID="'+str(roomDict['ObjId'])+'" AND ExitId="'+str(exitDict['ExitId'])+'"'
print("ExitQuery: ",ExitQuery)
exitCur.execute(ExitQuery)
exitCon.commit()

ZoneQuery = 'UPDATE ZoneTBL SET Name="'+str(zoneName)+'" WHERE ZoneId="'+str(zoneDict['ZoneId'])+'"'
print("ZoneQuery : ",ZoneQuery)
zoneCur.execute(ZoneQuery)
zoneCon.commit()
#break
else:
InsertStatement = 'INSERT INTO ZoneTBL (Name) VALUES ("'+zoneName+'")'
print("Creating new zone into newDB: ",InsertStatement)
zoneCur.execute(InsertStatement)
zoneCon.commit()
newZoneID=zoneCur.lastrowid
print("New Zone created. NewZoneID:",newZoneID)
print("New ZoneID: ",newZoneID)
else:
print("ZoneName: ",zoneName," already exists!")

except Error:
print(Error)
finally:
oldDBCon.close()
zoneCon.close()
objCon.close()
exitCon.close()


def ObjectTbl_EXE():
selectItems="ZoneID,ObjId,Name,IDName,X,Y,Z,Dx,Dy,ExitX,ExitY,ExitZ,Cost,Color,LabelDir"
itemDict={}
items=[]
header=[]
newRoomNumsNeeded=0
newRoomNums=[]
nextNewObjID=0

#Retrieve data from oldDB
ObjectQuery = "SELECT "+selectItems+" FROM ObjectTbl WHERE ZoneID='"+str(ZoneID)+"'"
try:
objCon = sqlite3.connect(oldDB)
objCur = objCon.cursor()
objCur.execute(ObjectQuery)
rows = objCur.fetchall()
ObjectTblHeader = [description[0] for description in objCur.description]

#Create dictionary for each row result, and add to items list
for row in rows:
#maintain list of old room nums
for i in range(len(row)):
itemDict[ObjectTblHeader[i]]=row[i]
oldRoomNums.append(itemDict['ObjId'])
items.append(itemDict.copy())
itemDict.clear()
#print("--------------------------------------------------------")
except Error:
print(Error)
finally:
objCon.close()

#Identify Available ObjId's
#Available ObjId's in newRoomNums list. If not enough, then nextNewObjID will be >0
newRoomNumsNeeded=len(oldRoomNums)
try:
ObjectQuery = 'Select [ObjId] FROM ObjectTbl WHERE Name = "'+"Available"+'"'
print("ObjectTbl Check: Checking for unused 'Available' objects. NewDB Query: "+ObjectQuery)
objCon = sqlite3.connect(newDB)
objCur = objCon.cursor()
objCur.execute(ObjectQuery)
availRooms = objCur.fetchall()
roomHeader = [description[0] for description in objCur.description]

if (int(len(availRooms))>0):
print("roomHeader: ",roomHeader)
print("rooms: ",availRooms)
for room in availRooms:
itemDict={}
#print("Zone: ",zone)
for r in range(len(room)):
itemDict[roomHeader[r]]=room[r]
newRoomNums.append(itemDict['ObjId'])
newRoomNumsNeeded=newRoomNumsNeeded-1
if newRoomNumsNeeded==0:
break
if newRoomNumsNeeded>0:
"""Create dummy entry in newDB's ObjectTbl, without db.commit(), to identify next autoincrement ID keynum"""
ObjectQuery="INSERT INTO OBJECTTBL (Name) VALUES ("+'"'+"DummyName"+'"'+")"
objCur.execute(ObjectQuery)
nextNewObjID=objCur.lastrowid
print(zoneName + " | " + str(newZoneID) + " | " + "NextNewObjID: " + str(nextNewObjID))
except Error:
print(Error)
finally:
objCon.close()


#Create dictionary for old/new room lookup
AvailRooms=newRoomNums.copy()
for i in range(len(oldRoomNums)):
oldRoomNum=oldRoomNums[i]
if len(newRoomNums):
newRoomNum=newRoomNums.pop(0)
else:
newRoomNum=nextNewObjID+i-len(AvailRooms)
roomLookup_byOldRoom[str(oldRoomNum)] = newRoomNum
print("List of oldRoomNums:",oldRoomNums)
print("RoomLookup_byOldRoom Dict:",roomLookup_byOldRoom)
print("----------------------------------------------------------------------------------------------------------------")


"""Create SQL INSERT/UPDATE statements"""
newRoomNums=AvailRooms.copy()
print("AvailRooms: ",AvailRooms)
Query=""
for item in items:
#print("Item: ",item," || ObjId: ",item['ObjId'])
if roomLookup_byOldRoom[str(item['ObjId'])] in AvailRooms:
Query = "UPDATE ObjectTbl SET "
else:
Query = "INSERT INTO ObjectTbl (" + ",".join(ObjectTblHeader) + ")"
Query = Query + " VALUES ("
#comma separated

for key in item:
#comma separated
if "UPDATE" in Query:
if Query[-1]!=" ":
Query=Query+","
else:
if Query[-1]!="(":
Query=Query+","

if "UPDATE" in Query:
Query = Query + str(key) + '='

"""Insert using new values"""
if key=="ZoneID":
Query=Query+str(newZoneID)
elif key=="ObjId":
oldRoomNum=item[key]
Query=Query+str(roomLookup_byOldRoom[str(oldRoomNum)])
elif key in ["Name","IDName"]:
Query=Query+'"'+str(item[key])+'"'
elif item[key]:
Query=Query+str(item[key])
elif key in ['X','Y','Z','Dx','Dy','ExitX','ExitY','ExitZ']:
Query=Query+"0"
else:
Query=Query+'""'

if "UPDATE" in Query:
Query=Query+' WHERE ObjId="'+str(roomLookup_byOldRoom[str(item['ObjId'])])+'"'
else:
Query = Query + ");"

print(Query)
try:
objCon = sqlite3.connect(newDB)
objCur = objCon.cursor()
objCur.execute(Query)
objCon.commit()
except Error:
print(Error)
finally:
objCon.close()

print("----------------------------------------------------------------------------------------------------------------")



def ExitTbl_EXE():
selectItems="ExitId,ExitIdTo,FromID,ToID,ExitKindID,Name,DirType,DirToType,Flags,UserID"
#selectItems="*"
"""list of dictionaries containing results"""
exits=[]
"""dictionary for individual row results"""
exitItem={}
exitDict={}
queryValues=[]
newExitNums=[]

#Calculate how many exits are needed
for fromID in roomLookup_byOldRoom:
ExitQuery = "SELECT "+selectItems+" FROM ExitTbl WHERE FromID='"+fromID+"'"
try:
exitCon = sqlite3.connect(oldDB)
exitCur = exitCon.cursor()
exitCur.execute(ExitQuery)
rows = exitCur.fetchall()
exitHeader = [description[0] for description in exitCur.description]

#Create dictionary for each row result, and add to items list
for row in rows:
for i in range(len(row)):
exitItem[exitHeader[i]]=row[i]
oldExitNums.append(exitItem['ExitId'])
exits.append(exitItem.copy())
exitItem.clear()
#print("----------------------------------------------------------------------------------------------------------------")
except Error:
print(Error)
finally:
exitCon.close()
numExits = len(exits)
numExitsNeeded=numExits
#Calculate how many 'Available' exitid's there are.
#Identify Available ObjId's
#Available ObjId's in newRoomNums list. If not enough, then nextNewObjID will be >0
try:
ExitQuery = 'Select [ExitId] FROM ExitTbl WHERE Name = "'+"Available"+'"'
print("ExitTbl Check: Checking for unused 'Available' exits. NewDB Query: "+ExitQuery)
exitCon = sqlite3.connect(newDB)
exitCur = exitCon.cursor()
exitCur.execute(ExitQuery)
availExits = exitCur.fetchall()
header = [description[0] for description in exitCur.description]

if (int(len(availExits))>0):
print("header: ",header)
print("availExits: ",availExits)
for exit in availExits:
exitDict={}
for e in range(len(exit)):
exitDict[header[e]]=exit[e]
newExitNums.append(exitDict['ExitId'])
numExitsNeeded=numExitsNeeded-1
if numExitsNeeded==0:
break
if numExitsNeeded>0:
ExitQuery="INSERT INTO ExitTbl (Name) VALUES ("+'"'+"DummyName"+'"'+")"
exitCon = sqlite3.connect(newDB)
exitCur = exitCon.cursor()
exitCur.execute(ExitQuery)
nextNewExitID=exitCur.lastrowid
print(zoneName + " | " + str(newZoneID) + " | " + "nextNewExitID: " + str(nextNewExitID))
except Error:
print(Error)
finally:
exitCon.close()

#Create dictionary for old/new room lookup
AvailExits=newExitNums.copy()
for i in range(len(oldExitNums)):
oldExitNum=oldExitNums[i]
if len(newExitNums):
newExitNum=newExitNums.pop(0)
else:
newExitNum=nextNewExitID+i-len(AvailExits)
exitLookup_byOldRoom[str(oldExitNum)] = newExitNum
print("List of oldExitNums:",oldExitNums)
print("exitLookup_byOldRoom Dict:",exitLookup_byOldRoom)
print("----------------------------------------------------------------------------------------------------------------")


"""
#Create old/new lookup dictionary
for i in range(len(oldExitNums)):
oldExit=oldExitNums[i]
exitLookup_byOldRoom[str(oldExit)]=int(nextNewExitID)+i
exitLookup_byNewRoom[int(nextNewExitID)+i]=str(oldExit)
"""

"""Create SQL INSERT statements"""

"""Create SQL INSERT/UPDATE statements"""
newExitNums=AvailExits.copy()
print("AvailExits: ",AvailExits)
Query=""
for exit in exits:
#print("Item: ",item," || ObjId: ",item['ObjId'])
if exitLookup_byOldRoom[str(exit['ExitId'])] in AvailExits:
Query = "UPDATE ExitTbl SET "
else:
Query = "INSERT INTO ExitTbl (" + ",".join(exitHeader) + ")"
Query = Query + " VALUES ("
#comma separated

for key in exit:
#comma separated
if "UPDATE" in Query:
if Query[-1]!=" ":
Query=Query+","
else:
if Query[-1]!="(":
Query=Query+","

if "UPDATE" in Query:
Query = Query + str(key) + '='

#Insert using new values
if key=="ExitId":
Query=Query+str(exitLookup_byOldRoom[str(exit[key])])
elif key=="ExitIdTo" and str(exit[key]) in exitLookup_byOldRoom.keys():
Query=Query+str(exitLookup_byOldRoom[str(exit[key])])
elif key=="ExitIdTo" and str(exit[key]) not in exitLookup_byOldRoom.keys():
Query=Query+str(exitLookup_byOldRoom[str(exit['ExitId'])])
elif key=="FromID":
Query=Query+str(roomLookup_byOldRoom[str(exit[key])])
elif key=="ToID" and str(exit[key]) in roomLookup_byOldRoom.keys():
Query=Query+str(roomLookup_byOldRoom[str(exit[key])])
elif key=="ToID" and str(exit[key]) not in roomLookup_byOldRoom.keys():
Query=Query+str(roomLookup_byOldRoom[str(exit['FromID'])])
elif key=="Name":
Query=Query+'"'+str(exit[key])+'"'
else:
Query=Query+str(exit[key])

if "UPDATE" in Query:
Query=Query+' WHERE ExitId="'+str(exitLookup_byOldRoom[str(exit['ExitId'])])+'"'
else:
Query = Query + ");"

print(Query)
try:
exitCon = sqlite3.connect(newDB)
exitCur = exitCon.cursor()
exitCur.execute(Query)
exitCon.commit()
except Error:
print(Error)
finally:
exitCon.close()
print("----------------------------------------------------------------------------------------------------------------")



if __name__ == '__main__':
oldDB="Full path to /MyMudOld.dbm"
newDB="Full path to /MyMudNew.dbm"
zoneList=[]
param="print"
zoneName=""
newZoneID=0
oldRoomNums=[]
roomLookup_byOldRoom={}
roomLookup_byNewRoom={}

oldExitNums=[]
exitLookup_byOldRoom={}
exitLookup_byNewRoom={}

#List of Zones
#zoneList.extend([51,533,496,528])


print("----------------------------------------------------------------------------------------------------------------")
print("Transferring zones: ",zoneList)
for ZoneID in zoneList:
zoneName=""
newZoneID=0
oldRoomNums=[]
roomLookup_byOldRoom={}
roomLookup_byNewRoom={}

oldExitNums=[]
exitLookup_byOldRoom={}
exitLookup_byNewRoom={}

ZoneTbl_EXE()
print("Global newZoneID: ",newZoneID)

#"""
print("----------------------------------------------------------------------------------------------------------------")
if newZoneID>0:
ObjectTbl_EXE()
print("----------------------------------------------------------------------------------------------------------------")
ExitTbl_EXE()
print("----------------------------------------------------------------------------------------------------------------")
else:
print("ObjectTbl & ExitTbl Queries skipped because ZoneName already exists!> "+zoneName)
print("----------------------------------------------------------------------------------------------------------------")
#"""

print("Zone Transfer Complete!")
print("----------------------------------------------------------------------------------------------------------------")
Reply with quote
Delvalle
Newbie


Joined: 08 Apr 2020
Posts: 1

PostPosted: Wed Apr 08, 2020 1:31 pm   
 
That might be a difficulty. While at this time i've only moved a half dozen or so zones into the mapper, the mud I play/that i'm writing this for (TorilMud) has a map of rooms twice that size - Even an unsigned int for roomid wouldn't be able to handle the entire map.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net