private int writeBuildable() { ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep(); // Write buildable bool[] landBuildable = simRep.getDataTiles().getSimLandBuildable(); int numTiles = simRep.getNumXTiles(); byte tru = 0xFF; byte fal = 0x00; for (int x = 0; x < numTiles; x++) { for (int z = 0; z < numTiles; z++) { int index = (x * numTiles + z); if (landBuildable[index]) { binWriter.Write(tru); } else { binWriter.Write(fal); } } } ExportTo360.mECF.addChunk((int)eXSD_ChunkID.cXSD_Buildable, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; return(landBuildable.Length * sizeof(byte)); }
private int writeTileType() { ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep(); // Write tile types int numTiles = simRep.getNumXTiles(); int obstructionArraySize = numTiles * numTiles; SimTerrainType.loadTerrainTileTypes(); int tileTypeArraySize = obstructionArraySize; byte[] tileTypeArray = new byte[tileTypeArraySize]; for (int x = 0; x < numTiles; x++) { for (int z = 0; z < numTiles; z++) { int index = (x * numTiles + z); //if we have a tile type override, use it int typeOverride = TerrainGlobals.getEditor().getSimRep().getDataTiles().getJaggedTileType(z, x); if (typeOverride > 0) { tileTypeArray[index] = (byte)typeOverride; } else { // Get each tile's dominant texture index int dominantTextureIndex = TerrainGlobals.getEditor().giveDominantTextureAtTile(x, z, simRep); tileTypeArray[index] = 0; if (dominantTextureIndex != -1) { byte numTypes = (byte)SimTerrainType.mTerrainTileTypes.mTypes.Count; string dominantTextureType = SimTerrainType.mTextureList[dominantTextureIndex].TileType; // Find the dominant texture's type for (byte typeIndex = 0; typeIndex < numTypes; typeIndex++) { if (SimTerrainType.mTerrainTileTypes.mTypes[typeIndex].Name == dominantTextureType) { tileTypeArray[index] = typeIndex; break; } } } } } } binWriter.Write(tileTypeArray); ExportTo360.mECF.addChunk((int)eXSD_ChunkID.cXSD_TileTypes, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; return(tileTypeArray.Length); }
private int writeObstructions() { ECF.ECFChunkHolder chunkHolder = new ECF.ECFChunkHolder(); chunkHolder.mDataMemStream = new MemoryStream(); BinaryWriter binWriter = new BinaryWriter(chunkHolder.mDataMemStream); BTerrainSimRep simRep = TerrainGlobals.getEditor().getSimRep(); // Write obstructions bool[] landObstructions = simRep.getDataTiles().getSimLandObstructions(); int numTiles = simRep.getNumXTiles(); int obstructionArraySize = numTiles * numTiles; byte[] obstructionsFlags = new byte[obstructionArraySize]; bool[] alreadyDone = new bool[numTiles * numTiles]; for (int i = 0; i < numTiles * numTiles; i++) { alreadyDone[i] = false; } for (int x = 0; x < numTiles; x++) { for (int z = 0; z < numTiles; z++) { int index = (x * numTiles + z); bool obstructsLand = simRep.getDataTiles().isLandObstructedComposite(x, z); bool obstructsFlood = simRep.getDataTiles().isFloodObstructed(x, z); bool obstructsScarab = simRep.getDataTiles().isScarabObstructed(x, z); obstructionsFlags[index] = 0; if (obstructsLand && obstructsFlood && obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Flood_Scarab; } else if (obstructsLand && obstructsFlood && !obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Flood; } else if (obstructsLand && !obstructsFlood && obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land_Scarab; } else if (obstructsLand && !obstructsFlood && !obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Land; } else if (!obstructsLand && obstructsFlood && obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Flood_Scarab; } else if (!obstructsLand && obstructsFlood && !obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Flood; } else if (!obstructsLand && !obstructsFlood && obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cObstrtuction_Scarab; } else if (!obstructsLand && !obstructsFlood && !obstructsScarab) { obstructionsFlags[index] = (byte)BTerrainSimRep.eObstructionType.cNoObstruction; } } } binWriter.Write(obstructionsFlags); ExportTo360.mECF.addChunk((int)eXSD_ChunkID.cXSD_Obstructions, chunkHolder, binWriter.BaseStream.Length); binWriter.Close(); binWriter = null; chunkHolder.Close(); chunkHolder = null; return(obstructionsFlags.Length); }