/** * Reads in the Map Data / Landscape and MapObjects like trees */ void readMapData() throws MapLoadException { MapResourceInfo filePart = findAndDecryptFilePartSafe(EOriginalMapFilePartType.AREA); // - file position int pos = filePart.offset; // - height and width are the same int widthHeight = readBEIntFrom(pos); pos += 4; // - init size of MapData mapData.setWidthHeight(widthHeight); // - points to read int dataCount = widthHeight * widthHeight; for (int i = 0; i < dataCount; i++) { mapData.setLandscapeHeight(i, readByteFrom(pos++)); mapData.setLandscape(i, readByteFrom(pos++)); mapData.setMapObject(i, readByteFrom(pos++)); readByteFrom(pos++); // - which Player is the owner of this position mapData.setAccessible(i, mapContent[pos++]); mapData.setResources(i, readHighNibbleFrom(pos), readLowNibbleFrom(pos)); pos++; } }
void readSettlers() throws MapLoadException { Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.SETTLERS); if (filePartOptional.isPresent()) { MapResourceInfo filePart = filePartOptional.get(); // - file position int pos = filePart.offset; // - Number of buildings int settlerCount = readBEIntFrom(pos); pos += 4; // - safety check if ((settlerCount * 6 > filePart.size) || (settlerCount < 0)) { throw new MapLoadException("wrong number of settlers in map File: " + settlerCount); } // - read all Stacks for (int i = 0; i < settlerCount; i++) { int party = readByteFrom(pos++); int settlerType = readByteFrom(pos++); int posX = readBEWordFrom(pos); pos += 2; int posY = readBEWordFrom(pos); pos += 2; // ------------- // - update data mapData.setSettler(posX, posY, settlerType, party); } } }
void readStacks() throws MapLoadException { Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.STACKS); if (filePartOptional.isPresent()) { MapResourceInfo filePart = filePartOptional.get(); // - file position int pos = filePart.offset; // - Number of buildings int stackCount = readBEIntFrom(pos); pos += 4; // - safety check if ((stackCount * 8 > filePart.size) || (stackCount < 0)) { throw new MapLoadException("wrong number of stacks in map File: " + stackCount); } // - read all Stacks for (int i = 0; i < stackCount; i++) { int posX = readBEWordFrom(pos); pos += 2; int posY = readBEWordFrom(pos); pos += 2; int stackType = readByteFrom(pos++); int count = readByteFrom(pos++); pos += 2; // not used - maybe: padding to size of 8 (2 INTs) // ------------- // - update data mapData.setStack(posX, posY, stackType, count); } } }
int party = readByteFrom(pos++); // - Party starts with 0 int buildingType = readByteFrom(pos++); int posX = readBEWordFrom(pos); pos += 2;