def is_within_sector(self, user_id, sector_x, sector_y, target_x, target_y, building_id):
		size = structure.get_structure_size(building_id)
		tx, ty = int(target_x // 1), int(target_y // 1)
		if tx == 59 or ty == 59:
			return False
		
		your_sector = self.sector_by_user[user_id]
		
		return sector_x == your_sector[0] and sector_y == your_sector[1]
	def is_touching_other_building(self, user_id, sector_x, sector_y, target_x, target_y, building_id):
		size = structure.get_structure_size(building_id)
		buildings = self.get_all_buildings_of_player_SLOW(user_id)
		tx = int(target_x // 1)
		ty = int(target_y // 1)
		
		occupied = {}
		for building in buildings:
			x, y = building.getModelXY()
			x = int(x // 1)
			y = int(y // 1)
			bsize = structure.get_structure_size(building.btype)
			for px in range(x - 1, x + bsize + 1):
				for py in range(y - 1, y + bsize + 1):
					occupied[(px, py)] = building.btype
		
		for px in range(tx, tx + size):
			for py in range(ty, ty + size):
				if occupied.get((px, py)) != None:
					return True
					
		return False
	def remove_structure(self, sector, x, y):
		x += sector[0] * 60
		y += sector[1] * 60
		
		i = 0
		buildings = self.buildings_by_sector[sector]
		while i < len(buildings):
			building = buildings[i]
			bx, by = building.getModelXY()
			bx = int(bx // 1)
			by = int(by // 1)
			
			if bx == x and by == y:
				self.buildings_by_sector[sector] = buildings[:i] + buildings[i + 1:]
				size = structure.get_structure_size(building.type)
				for px in range(size):
					for py in range(size):
						key = (bx + px, by + py)
						if key in self.buildings_by_coord:
							self.buildings_by_coord.pop(key)
				break
			i += 1
	def add_structure(self, user_id, type, sx, sy, x, y):
		# TODO: determine if building already exists by alternate means
		
		ax = sx * 60 + x
		ay = sy * 60 + y
		size = structure.get_structure_size(type)
		
		s = structure.create(user_id, type, ax, ay)
		sector = (sx, sy)
		#list = self.buildings_by_sector.get(sector, [])
		#self.buildings_by_sector[sector] = list
		
		north = ay
		south = ay + size - 1
		west = ax
		east = ax + size - 1
		
		sector_north = north // 60
		sector_south = south // 60
		sector_west = west // 60
		sector_east = east // 60
		
		footprint = []
		remove_these = []
		for px in range(size):
			for py in range(size):
				f = (ax + px, ay + py)
				footprint.append(f)
		
		for f in footprint:
			self.buildings_by_coord[f] = s
	
		for sector_x in range(sector_west, sector_east + 1):
			for sector_y in range(sector_north, sector_south + 1):
				list = self.buildings_by_sector.get(sector, [])
				self.buildings_by_sector[sector] = list
				list.append(s)