@@ -163,39 +163,43 @@ function SpawnLiquid:decreaseLiquidLevel()
163163 self .level = math.max (self .level - 1 , 1 )
164164end
165165
166+ local function isFlowPassable (pos )
167+ local tt = dfhack .maps .getTileType (pos )
168+ local tile = dfhack .maps .getTileFlags (pos )
169+ return tt and tile and df .tiletype_shape .attrs [df .tiletype .attrs [tt ].shape ].passable_flow
170+ end
171+
166172function SpawnLiquid :spawn (pos )
167- if dfhack .maps .isValidTilePos (pos ) and dfhack .maps .isTileVisible (pos ) then
168- local map_block = dfhack .maps .getTileBlock (pos )
169-
170- if self .mode == SpawnLiquidMode .CLEAN then
171- local tile = dfhack .maps .getTileFlags (pos )
172-
173- tile .water_salt = false
174- tile .water_stagnant = false
175- elseif self .type == df .tiletype .RiverSource then
176- if self .mode == SpawnLiquidMode .REMOVE then
177- local commands = {
178- ' f' , ' any' , ' ;' ,
179- ' f' , ' sp' , ' river_source' , ' ;' ,
180- ' p' , ' any' , ' ;' ,
181- ' p' , ' s' , ' floor' , ' ;' ,
182- ' p' , ' sp' , ' normal' , ' ;' ,
183- ' p' , ' m' , ' stone' , ' ;' ,
184- }
185- dfhack .run_command (' tiletypes-command' , table.unpack (commands ))
186- dfhack .run_command (' tiletypes-here' , ' --quiet' , (' --cursor=%d,%d,%d' ):format (pos2xyz (pos )))
187- liquids .spawnLiquid (pos , 0 , df .tile_liquid .Water )
188- else
189- map_block .tiletype [pos .x % 16 ][pos .y % 16 ] = df .tiletype .RiverSource
190- liquids .spawnLiquid (pos , 7 , df .tile_liquid .Water )
191- end
173+ if not dfhack .maps .isValidTilePos (pos ) or not dfhack .maps .isTileVisible (pos ) or not isFlowPassable (pos ) then
174+ return
175+ end
176+
177+ local map_block = dfhack .maps .getTileBlock (pos )
178+
179+ if self .mode == SpawnLiquidMode .CLEAN then
180+ local tile = dfhack .maps .getTileFlags (pos )
181+
182+ tile .water_salt = false
183+ tile .water_stagnant = false
184+ elseif self .type == df .tiletype .RiverSource then
185+ if self .mode == SpawnLiquidMode .REMOVE then
186+ local commands = {
187+ ' f' , ' any' , ' ;' ,
188+ ' f' , ' sp' , ' river_source' , ' ;' ,
189+ ' p' , ' any' , ' ;' ,
190+ ' p' , ' s' , ' floor' , ' ;' ,
191+ ' p' , ' sp' , ' normal' , ' ;' ,
192+ ' p' , ' m' , ' stone' , ' ;' ,
193+ }
194+ dfhack .run_command (' tiletypes-command' , table.unpack (commands ))
195+ dfhack .run_command (' tiletypes-here' , ' --quiet' , (' --cursor=%d,%d,%d' ):format (pos2xyz (pos )))
196+ liquids .spawnLiquid (pos , 0 , df .tile_liquid .Water )
192197 else
193- liquids .spawnLiquid (pos , self :getLiquidLevel (pos ), self .type )
198+ map_block .tiletype [pos .x % 16 ][pos .y % 16 ] = df .tiletype .RiverSource
199+ liquids .spawnLiquid (pos , 7 , df .tile_liquid .Water )
194200 end
195-
196- -- Regardless of spawning or removing liquids, we need to reindex to
197- -- ensure pathability is up to date.
198- df .global .world .reindex_pathfinding = true
201+ else
202+ liquids .spawnLiquid (pos , self :getLiquidLevel (pos ), self .type )
199203 end
200204end
201205
0 commit comments