Commits

mcc committed 83464d7

Also handle breed

Comments (0)

Files changed (1)

 					while tank:
 						if not tank.nodeName == "tank":
 							continue
-						gid = int(tank.getAttribute("gid"))
-						if options.debug > 1:
-							print("\tLoading: Create tank %d" % gid)
-						t = Genome(gid, True)
-						t.generation_count = int(tank.getAttribute("gc"))
-						spawn = tank.firstChild # Iter spawns
-						while spawn:
-							s = Spec(gid, True)
-							sid = int(spawn.getAttribute("sid"))
-							s.sid = sid
-							if options.debug > 1:
-								print("\t\tLoading: Create spec %d" % sid)
-							s.board = Board(int(spawn.getAttribute("mapx")), int(spawn.getAttribute("mapy")), True)
-							s.board.str = spawn.getAttribute("map")
-							e = spawn.getElementsByTagName("e")[0].firstChild # Iter entities
-							while e:
-								c = int(e.getAttribute("c"))
-								x = int(e.getAttribute("x"))
-								y = int(e.getAttribute("y"))
-								if c == 1:
-									s.board.px = x
-									s.board.py = y
-								elif c == 2:
-									s.board.ex = x
-									s.board.ey = y
-								e = e.nextSibling
-							t.specs[sid] = s
-							t.specs_stack.append(s)
-							spawn = spawn.nextSibling
-						t.id_generator = max(t.id_generator, sid)
-						t.last_valid = t.specs_stack[0]
-						t.specs_stack.reverse()
-						self.alltanks[gid] = t
+						self.unarchiveTank(tank)
 						tank = tank.nextSibling
-					
 				elif node.nodeName == "twhy":
 					if options.debug > 1:
 						print("Loading: TWHY")
 					self.report(node)
 					gid = int(node.getAttribute("gid"))
 					sid = int(node.getAttribute("sid"))
-					t = self.alltanks[gid]
-					s = top(t.specs_stack)
-					if s and s.sid == sid:
-						if options.debug > 1:
-							print("\tLoading: Popping gid %d, sid %d" % (gid, sid))
-						s.checked = True # In case report botched.
-						t.specs_stack.pop()
+					if self.alltanks.has_key(gid):
+						t = self.alltanks[gid]
+						s = top(t.specs_stack)
+						if s and s.sid == sid:
+							if options.debug > 1:
+								print("\tLoading: Popping gid %d, sid %d" % (gid, sid))
+							s.checked = True # In case report botched.
+							t.specs_stack.pop()
+					else:
+						print("BOTCHED TWHY gid: %d" % gid)
 					
 				elif node.nodeName == "breed":
 					if options.debug > 1:
 						print("Loading: BREED")
+					self.unarchiveTank(node)
 				node = node.nextSibling
 			
 			self.tanks = {}
 				if options.shelf_size <= 0 or i-1 < options.shelf_size:
 					self.tanks[i] = t
 	
+	def unarchiveTank(self, tank):
+		gid = int(tank.getAttribute("gid"))
+		if options.debug > 1:
+			print("\tLoading: Create tank %d" % gid)
+		t = Genome(gid, True)
+		t.generation_count = int(tank.getAttribute("gc"))
+		spawn = tank.firstChild # Iter spawns
+		while spawn:
+			s = Spec(gid, True)
+			sid = int(spawn.getAttribute("sid"))
+			s.sid = sid
+			if options.debug > 1:
+				print("\t\tLoading: Create spec %d" % sid)
+			s.board = Board(int(spawn.getAttribute("mapx")), int(spawn.getAttribute("mapy")), True)
+			s.board.str = spawn.getAttribute("map")
+			e = spawn.getElementsByTagName("e")[0].firstChild # Iter entities
+			while e:
+				c = int(e.getAttribute("c"))
+				x = int(e.getAttribute("x"))
+				y = int(e.getAttribute("y"))
+				if c == 1:
+					s.board.px = x
+					s.board.py = y
+				elif c == 2:
+					s.board.ex = x
+					s.board.ey = y
+				e = e.nextSibling
+			t.specs[sid] = s
+			t.specs_stack.append(s)
+			spawn = spawn.nextSibling
+		t.id_generator = max(t.id_generator, sid)
+		t.last_valid = t.specs_stack[0]
+		t.specs_stack.reverse()
+		self.alltanks[gid] = t
+	
 	def any(self, post_obj):
 		if player_hits(post_obj) > options.shelf_after:
 			return randomfromdict(self.alltanks)