Advertisement
Guest User

setair.lua

a guest
Aug 8th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.88 KB | None | 0 0
  1. local args = {...}
  2.  
  3. function setair (values)
  4.   if not dfhack.isMapLoaded() then
  5.     dfhack.color (COLOR_RED)
  6.     dfhack.print("Error: This script requires a Fortress Mode embark to be loaded.")
  7.     dfhack.color(COLOR_RESET)
  8.     dfhack.println()
  9.     return
  10.   end
  11.  
  12.   local max_x, max_y, max_z = dfhack.maps.getTileSize()
  13.   local lastvalueindex = -1
  14.   function lenTable (subject)
  15.     local len = 0
  16.     for iter in pairs(subject) do
  17.       len = len + 1
  18.     end
  19.     return len
  20.   end
  21.  
  22.   local lengthofArgs = lenTable(values)
  23.   function getNextValue ()
  24.     lastvalueindex  = lastvalueindex + 1
  25.     return tonumber(values[1+(lastvalueindex % lengthofArgs)])
  26.   end
  27.    
  28.   function Is_Air_Tile (x, y, z)
  29.     local tile_type
  30.     local block = dfhack.maps.getBlock (math.floor (x / 16), math.floor (y / 16), z)
  31.     local region_offset = block.region_offset [block.designation [0][0].biome]
  32.     local result = true
  33.  
  34.     for i = 0, 15 do
  35.       for k = 0, 15 do
  36.         if dfhack.maps.getTileBiomeRgn (x, y, max_z - 1 - z) ~= nil then   
  37.           tile_type = dfhack.maps.getTileType (x + k, y + i, z)
  38.           if tile_type > df.tiletype.Void and
  39.              tile_type ~= df.tiletype.OpenSpace and
  40.              (tile_type < df.tiletype.BurningTreeTrunk or
  41.               tile_type > df.tiletype.BurningTreeCapFloor) and
  42.              (tile_type < df.tiletype.TreeRootSloping or
  43.               tile_type > df.tiletype.TreeDeadTrunkInterior) and
  44.              (tile_type < df.tiletype.ConstructedFloor or
  45.               tile_type > df.tiletype.ConstructedRamp) and
  46.              (tile_type < df.tiletype.ConstructedFloorTrackN or
  47.               tile_type > df.tiletype.ConstructedFloorTrackNSEW) and
  48.              (tile_type < df.tiletype.ConstructedRampTrackN or
  49.               tile_type > df.tiletype.ConstructedRampTrackNSEW) then
  50.               result = false
  51.               break
  52.           end
  53.         end
  54.        
  55.         if region_offset ~= block.region_offset [block.designation [k][i].biome] then  --  Air tiles have uniform offsets (even when they are shears)
  56.           result = false
  57.           break
  58.         end    
  59.       end
  60.      
  61.       if not result then
  62.         break
  63.       end
  64.     end
  65.    
  66.     if result and region_offset ~= 0 then
  67.       dfhack.println ("Shear at " .. tostring (x) .. ", " .. tostring (y) .. ", " .. tostring (z))
  68.     end
  69.    
  70.     return result
  71.   end
  72.  
  73.   local block
  74.   local offsetbiome = 0
  75.   for l = 0, max_z - 1 do
  76.     for i = 0, math.floor (max_y - 1) / 16 do
  77.       for k = 0, math.floor ((max_x - 1) / 16) do
  78.         if i==0 and k==0 then
  79.         end
  80.         if not Is_Air_Tile (k * 16, i * 16, max_z - 1 - l) then    
  81.           break
  82.         end
  83.        
  84.         block = dfhack.maps.getBlock (k, i, max_z - 1 - l)
  85.         offsetbiome = getNextValue()
  86. --      dfhack.println("offsetbiome is " .. tostring(offsetbiome))
  87.         for m = 0, 15 do
  88.           for n = 0, 15 do
  89.             block.region_offset [block.designation [n][m].biome] = offsetbiome
  90.           end
  91.         end
  92.       end
  93.     end
  94.   end
  95. end
  96.  
  97. setair (args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement