@Override public IMapData getMapData() throws MapLoadException { loadMapContent(EMapStartResources.HIGH_GOODS, null); OriginalMapFileContent mapData = mapContent.mapData; mapData.calculateBlockedPartitions(); return mapData; }
OriginalMapFileContentReader(InputStream originalMapFile) throws IOException { // - init players mapData.setPlayerCount(1); // - read File into buffer mapContent = getBytesFromInputStream(originalMapFile); }
@Override public String getMapId() { return mapContent.getChecksum() + getMapName(); }
/** * 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++; } }
private void readPlayerInfo() throws MapLoadException { MapResourceInfo filePart = findAndDecryptFilePartSafe(EOriginalMapFilePartType.PLAYER_INFO); // - file position int pos = filePart.offset; for (int i = 0; i < mapData.getPlayerCount(); i++) { int nation = readBEIntFrom(pos); pos += 4; int startX = readBEIntFrom(pos); pos += 4; int startY = readBEIntFrom(pos); pos += 4; String playerName = readCStrFrom(pos, 33); pos += 33; mapData.setPlayer(i, startX, startY, nation, playerName); } }
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(""); }
void reOpen(InputStream originalMapFile) throws IOException { // - read File into buffer mapContent = getBytesFromInputStream(originalMapFile); // - reset Crypt Info for (MapResourceInfo element : resources.values()) { element.resetDecryptedFlag(); } }
@Override public String getDescription() { try { return mapContent.readMapQuestText(); } catch (MapLoadException e) { return ""; } }
public void setPlayerCount(int count) { mapPlayerInfos = new MapPlayerInfo[count]; for (int i = 0; i < count; i++) { // - init new player with "random" start position mapPlayerInfos[i] = new MapPlayerInfo(20 + i * 10, 20 + i * 10); } }
@Override public MainGridWithUiSettings loadMainGrid(PlayerSetting[] playerSettings) throws MapLoadException { return loadMainGrid(playerSettings, EMapStartResources.HIGH_GOODS); }
public OriginalMapFileContent(int widthHeight) { setWidthHeight(widthHeight); }
public void addStartTowerMaterialsAndSettlers(EMapStartResources startResources) { addStartTowerMaterialsAndSettlers(startResources, null); }
@Override public int getMaxPlayers() { return mapContent.mapData.getPlayerCount(); }
@Override public short[] getImage() { return mapContent.getPreviewImage(); }
void freeBuffer() { mapContent = null; mapData.freeBuffer(); }
void readBasicMapInformation() throws MapLoadException { this.readBasicMapInformation(0, 0); }
boolean isChecksumValid() { // - read Checksum from File int fileChecksum = readBEIntFrom(0); mapData.fileChecksum = fileChecksum; // - make "count" a Multiple of four int count = mapContent.length & 0xFFFFFFFC; int currentChecksum = 0; // - Map Content starts at Byte 8 for (int i = 8; i < count; i += 4) { // - read DWord int currentInt = (mapContent[i] & 0xFF) | ((mapContent[i + 1] & 0xFF) << 8) | ((mapContent[i + 2] & 0xFF) << 16) | ((mapContent[i + 3] & 0xFF) << 24); // - using: Logic Right-Shift-Operator: >>> currentChecksum = ((currentChecksum >>> 31) | ((currentChecksum << 1) ^ currentInt)); } // - return TRUE if the checksum is OK! return (currentChecksum == fileChecksum); }
private Optional<MapResourceInfo> findAndDecryptFilePart(EOriginalMapFilePartType partType) throws MapLoadException { MapResourceInfo filePart = findResource(partType); if ((filePart == null) || (filePart.size == 0)) { return Optional.empty(); } // Decrypt this resource if necessary filePart.doDecrypt(); // Call consumer return Optional.of(filePart); }
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!"); } }
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(""); }