public MapHolder requestMapView(int topX, int topY, int sizeX, int sizeY) { //TODO: Throw exception LOG.Debug(uidString + "RequestMapView has been called"); if (topX < 0 || topY < 0 || sizeX < 0 || sizeY < 0) { LOG.Error("Map boundries set to negative values!"); return null; // throw new Exception("Values cannot be < 0"); } if (currentMap != null && topX >= currentMap.mapHolder.X && topY >= currentMap.mapHolder.Y && (topX + sizeX) <= (currentMap.mapHolder.X + currentMap.mapHolder.SizeX) && (topY + sizeY) <= (currentMap.mapHolder.Y + currentMap.mapHolder.SizeY)) { //This is part of current map int[,] map = new int[sizeX, sizeY]; int dispX = topX - currentMap.mapHolder.X; int dispY = topY - currentMap.mapHolder.Y; for (int i = 0; i<sizeX; i++){ for (int j = 0; j<sizeY; j++){ map[i,j] = currentMap.mapHolder.Map[i+dispX,j+dispY]; } } LOG.Debug(uidString + " Retreiving existing part of map"); return new MapHolder(map,topX,topY); } else { if (parent != null) { LOG.Debug(uidString + " Retreiving map form parent"); if (currentMap != null) { parent.pushMapUpdate(currentMap.mapHolder); } MapHolder parentView = parent.requestMapView(topX, topY, sizeX, sizeY); if (parentView == null) { currentMap = null; return null; } else { currentMap = new MapVault(parentView); } return new MapHolder(currentMap.mapHolder); } else { LOG.Error(uidString + " Requested map part does not exist!"); return null; // throw new Exception("No such map"); } } }
public void initializeMap(int sizeX, int sizeY) { int[,] map = prepareArray(sizeX, sizeY, Map.UNKNOWN_MAP_STATE); currentMap = new MapVault(new MapHolder( map, 0, 0)); LOG.Info(uidString + " Map has been initialized [" + sizeX + "x" + sizeY + "]"); }