ruby: add spawn_water/spawn_magma methods to MapTile

develop
jj 2012-08-03 16:54:40 +02:00
parent f400591080
commit c1bcd270e9
2 changed files with 51 additions and 13 deletions

@ -107,6 +107,31 @@ module DFHack
Tiletype::Direction[tiletype] Tiletype::Direction[tiletype]
end end
def shape_caption
TiletypeShape::Caption[shape]
end
def shape_basic
TiletypeShape::BasicShape[shape]
end
def shape_passablelow
TiletypeShape::PassableLow[shape]
end
def shape_passablehigh
TiletypeShape::PassableHigh[shape]
end
def shape_passableflow
TiletypeShape::PassableFlow[shape]
end
def shape_walkable
TiletypeShape::Walkable[shape]
end
# return all veins for current mapblock # return all veins for current mapblock
def all_veins def all_veins
mapblock.block_events.grep(BlockSquareEventMineralst) mapblock.block_events.grep(BlockSquareEventMineralst)
@ -162,5 +187,28 @@ module DFHack
def inspect def inspect
"#<MapTile pos=[#@x, #@y, #@z] shape=#{shape} tilemat=#{tilemat} material=#{mat_info.token}>" "#<MapTile pos=[#@x, #@y, #@z] shape=#{shape} tilemat=#{tilemat} material=#{mat_info.token}>"
end end
def spawn_liquid(quantity, is_magma=false, flowing=true)
designation.flow_size = quantity
designation.liquid_type = (is_magma ? :Magma : :Water)
designation.flow_forbid = true if is_magma or quantity >= 4
if flowing
mapblock.flags.update_liquid = true
mapblock.flags.update_liquid_twice = true
zf = df.world.map.z_level_flags[z]
zf.update = true
zf.update_twice = true
end
end
def spawn_water(quantity=7)
spawn_liquid(quantity)
end
def spawn_magma(quantity=7)
spawn_liquid(quantity, true)
end
end end
end end

@ -12,26 +12,16 @@ when 'here'
end end
$magma_sources.each { |x, y, z| $magma_sources.each { |x, y, z|
if tile = df.map_tile_at(x, y, z) and DFHack::TiletypeShape::PassableFlow[tile.shape] if tile = df.map_tile_at(x, y, z) and tile.shape_passableflow
des = tile.designation des = tile.designation
des.flow_size += 1 if des.flow_size < 7 tile.spawn_magma(des.flow_size + 1) if des.flow_size < 7
des.liquid_type = 1
des.flow_forbid = true
mf = tile.mapblock.flags
mf.update_liquid = true
mf.update_liquid_twice = true
zf = df.world.map.z_level_flags[z]
zf.update = true
zf.update_twice = true
end end
} }
} }
if df.cursor.x != -30000 if df.cursor.x != -30000
if tile = df.map_tile_at(df.cursor) if tile = df.map_tile_at(df.cursor)
if DFHack::TiletypeShape::PassableFlow[tile.shape] if tile.shape_passableflow
$magma_sources << [df.cursor.x, df.cursor.y, df.cursor.z] $magma_sources << [df.cursor.x, df.cursor.y, df.cursor.z]
else else
puts "Impassable tile: I'm afraid I can't do that, Dave" puts "Impassable tile: I'm afraid I can't do that, Dave"