private MapResourceInfo findAndDecryptFilePartSafe(EOriginalMapFilePartType partType) throws MapLoadException { Optional<MapResourceInfo> filePart = findAndDecryptFilePart(partType); if (filePart.isPresent()) { return filePart.get(); } else { throw new MapLoadException("No " + partType + " information available in mapfile!"); } }
private String readMapQuestTip() throws MapLoadException { if (mapQuestTip != null) { return mapQuestTip; } return findAndDecryptFilePart(EOriginalMapFilePartType.QUEST_TIP).map(filePart -> { mapQuestTip = readCStrFrom(filePart.offset, filePart.size); return mapQuestTip; }).orElse(""); }
String readMapQuestText() throws MapLoadException { if (mapQuestText != null) { return mapQuestText; } return findAndDecryptFilePart(EOriginalMapFilePartType.QUEST_TEXT) .map(filePart -> { mapQuestText = readCStrFrom(filePart.offset, filePart.size); return mapQuestText; }) .orElse(""); }
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); } } }
void readBuildings() throws MapLoadException { hasBuildings = false; Optional<MapResourceInfo> filePartOptional = findAndDecryptFilePart(EOriginalMapFilePartType.BUILDINGS);