package TerrainData import BitSet import MapBounds import Execute /** Saves data about each terraintile on the map inside a hashtable */ constant xCells = ((playableMin.x - playableMax.x).abs() / 128.).round() constant yCells = ((playableMin.y - playableMax.y).abs() / 128.).round() constant tileMap = InitHashtable() public enum TileModifier NORMAL BLOCK BLUGOO ORANGEGOO RESERVED public tuple ebrtile(int x, int y, int key, int currentType, int lastType, bitset modifiers) /** Returns the tile below that position */ public function vec3.getEBRTile() returns ebrtile return this.toVec2().getEBRTile() /** Returns the tile below that position */ public function vec2.getEBRTile() returns ebrtile return tileMap.loadTile((this.x/128.).round(),(this.y/128.).round()) /** Returns the tile below that position */ public function getTile(int x, int y) returns ebrtile return tileMap.loadTile(x,y) /** Adds and saves the given modifier to the tiles */ public function ebrtile.hasModifier(TileModifier modifier) returns boolean return this.modifiers.get(modifier castTo int) /** Adds and saves the given modifier to the tiles */ public function ebrtile.addModifier(TileModifier modifier) tileMap.saveInt(this.key, 3, this.modifiers.set(modifier castTo int).val) /** Removed and saves the given modifier to the tiles */ public function ebrtile.removeModifier(TileModifier modifier) tileMap.saveInt(this.key, 3, this.modifiers.reset(modifier castTo int).val) /** Changes the terraintype of this tile if it is not reserved */ public function ebrtile.setType(int ttype) if not this.hasModifier(TileModifier.RESERVED) SetTerrainType(this.x * 128., this.y * 128., ttype, -1, 1, 0) tileMap.saveInt(this.key, 2, this.currentType) tileMap.saveInt(this.key, 1, ttype) function hashtable.loadTile(int x, int y) returns ebrtile let key = x * xCells + y return ebrtile(x, y, key, this.loadInt(key, 1), this.loadInt(key, 2), bitset(this.loadInt(key, 3))) function hashtable.saveTile(ebrtile tile) this.saveInt(tile.key, 0, tile.key) this.saveInt(tile.key, 1, tile.currentType) this.saveInt(tile.key, 2, tile.lastType) this.saveInt(tile.key, 3, tile.modifiers.val) init var realPos = playableMin while realPos.x < playableMax.x execute() -> while realPos.y < playableMax.y execute() -> let x = (realPos.x/128.).round() let y = (realPos.y/128.).round() tileMap.saveTile(ebrtile(x, y, x * xCells + y, GetTerrainType(realPos.x, realPos.y), GetTerrainType(realPos.x, realPos.y), bitset(TileModifier.NORMAL castTo int))) realPos.y += 128. realPos.x += 128.