summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhercules/tmx_converter.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/hercules/tmx_converter.py b/hercules/tmx_converter.py
index 5e864de..a6b0943 100755
--- a/hercules/tmx_converter.py
+++ b/hercules/tmx_converter.py
@@ -32,6 +32,10 @@ import traceback
dump_all = False # wall of text
check_mobs = True # mob_db.txt
+WMEM = []
+WTAR = []
+WERR = []
+WASC = []
# lower case versions of everything except 'spawn' and 'warp'
other_object_types = set([
@@ -65,6 +69,11 @@ NPC_IMPORTS = '_import.txt'
NPC_MASTER_IMPORTS = NPC_IMPORTS
NPC_MASTER_ANCHORS = '_anchors.txt'
+# Search for array[?][key]==search in an array of dicts
+# Returns the dictionary, or returns "ERROR"
+def dl_search(array, key, search):
+ return next((item for item in array if item[key] == search), "ERROR")
+
class State(object):
pass
State.INITIAL = State()
@@ -327,6 +336,7 @@ class ContentHandler(xml.sax.ContentHandler):
self.warps.write(line)
def endElement(self, name):
+ global check_mobs, dump_all, WERR, WMEM, WTAR
if dump_all:
print('</%s>' % name)
@@ -399,8 +409,38 @@ class ContentHandler(xml.sax.ContentHandler):
print("Legacy warp object")
except:
pass
+ obj_name = "#%s_%s_%s" % (self.base, obj.x, obj.y)
+ tar_name = "#%s_%s_%s" % (self.base, obj.dest_x, obj.dest_y)
+ # Something points here already?
+ if (obj_name in WTAR):
+ # FIXME: Parse the origin
+ #dst=dl_search(WASC, 0, tar_name)
+ ori=dl_search(WASC, 1, obj_name)
+ if (ori == "ERROR"):
+ WERR.append("ILLEGAL %s" % obj_name)
+ else:
+ if (ori[0] == tar_name):
+ WERR.append(obj_name)
+ #else:
+ # WERR.append("Okayish %s" % obj_name)
+ pass
+ # Going to somewhere which warps?
+ if (tar_name in WMEM):
+ # FIXME: Parse the destination
+ #WERR.append(obj_name)
+ ori=dl_search(WASC, 0, tar_name)
+ if (ori == "ERROR"):
+ WERR.append("ILLEGAL %s" % obj_name)
+ else:
+ if (ori[1] == obj_name):
+ WERR.append(obj_name)
+ #else:
+ # WERR.append("Okayish %s" % obj_name)
+ pass
+ WTAR.append(tar_name)
+ WMEM.append(obj_name)
+ WASC.append([obj_name, tar_name])
if (obj.npc_id == u'WARP'):
- obj_name = "#%s_%s_%s" % (self.base, obj.x, obj.y)
if (obj.dest_map.lower() in ["slide", "self"]):
self.warps.write(
SEPARATOR.join([
@@ -529,6 +569,9 @@ def main(argv):
traceback.print_exc()
map_conf.write(")\n")
sys.stdout.write('\033[2K\nDone: %i maps converted.\n' % map_count)
+ for err in WERR:
+ sys.stdout.write("\033[21;31;1mWarning, Possible Infinite Warp: %s\n" % err)
+ sys.stdout.write("\033[0;21mWMEM %d WERR %d\033[0m" % (len(WMEM), len(WERR)))
sys.stdout.flush()
with open(posixpath.join(npc_dir, NPC_MASTER_ANCHORS), 'w') as out:
out.write('// %s\n\n' % MESSAGE)
@@ -545,6 +588,7 @@ def main(argv):
for line in npc_master:
out.write(line)
out.write('"%s",\n' % posixpath.join(SERVER_NPCS, NPC_MASTER_ANCHORS))
+ print("")
if __name__ == '__main__':
main(sys.argv)