1515#include " df/map_block_column.h"
1616#include " df/plant.h"
1717#include " df/plant_raw.h"
18- #include " df/plant_root_tile.h"
19- #include " df/plant_tree_info.h"
20- #include " df/plant_tree_tile.h"
2118#include " df/world.h"
2219
2320using std::string;
@@ -249,48 +246,6 @@ command_result df_createplant(color_ostream &out, const df::coord &pos, const pl
249246 return CR_OK;
250247}
251248
252- static bool plant_in_cuboid (const df::plant *plant, const cuboid &bounds)
253- { // Will detect tree tiles
254- if (bounds.containsPos (plant->pos ))
255- return true ;
256- else if (!plant->tree_info )
257- return false ;
258-
259- auto &pos = plant->pos ;
260- auto &t = *(plant->tree_info );
261-
262- // Northwest x/y pos of tree bounds
263- int x_NW = pos.x - (t.dim_x >> 1 );
264- int y_NW = pos.y - (t.dim_y >> 1 );
265-
266- if (!cuboid (std::max (0 , x_NW), std::max (0 , y_NW), std::max (0 , pos.z - t.roots_depth ),
267- x_NW + t.dim_x , y_NW + t.dim_y , pos.z + t.body_height - 1 ).clamp (bounds).isValid ())
268- { // No intersection of tree bounds with cuboid
269- return false ;
270- }
271-
272- int xy_size = t.dim_x * t.dim_y ;
273- // Iterate tree body
274- for (int z_idx = 0 ; z_idx < t.body_height ; z_idx++)
275- for (int xy_idx = 0 ; xy_idx < xy_size; xy_idx++)
276- if ((t.body [z_idx][xy_idx].whole & 0x7F ) != 0 && // Any non-blocked
277- bounds.containsPos (x_NW + xy_idx % t.dim_x , y_NW + xy_idx / t.dim_x , pos.z + z_idx))
278- {
279- return true ;
280- }
281-
282- // Iterate tree roots
283- for (int z_idx = 0 ; z_idx < t.roots_depth ; z_idx++)
284- for (int xy_idx = 0 ; xy_idx < xy_size; xy_idx++)
285- if ((t.roots [z_idx][xy_idx].whole & 0x7F ) != 0 && // Any non-blocked
286- bounds.containsPos (x_NW + xy_idx % t.dim_x , y_NW + xy_idx / t.dim_x , pos.z - z_idx - 1 ))
287- {
288- return true ;
289- }
290-
291- return false ;
292- }
293-
294249command_result df_grow (color_ostream &out, const cuboid &bounds, const plant_options &options, vector<int32_t > *filter = nullptr )
295250{
296251 if (!bounds.isValid ())
@@ -312,7 +267,7 @@ command_result df_grow(color_ostream &out, const cuboid &bounds, const plant_opt
312267 {
313268 if (ENUM_ATTR (plant_type, is_shrub, plant->type ))
314269 continue ; // Shrub
315- else if (!plant_in_cuboid (plant, bounds))
270+ else if (!Maps::isPlantInBox (plant, bounds))
316271 continue ; // Outside cuboid
317272 else if (do_filter && (vector_contains (*filter, (int32_t )plant->material ) == options.filter_ex ))
318273 continue ; // Filtered out
@@ -459,7 +414,7 @@ command_result df_removeplant(color_ostream &out, const cuboid &bounds, const pl
459414 continue ; // Not removing saplings
460415 }
461416
462- if (!plant_in_cuboid (&plant, bounds))
417+ if (!Maps::isPlantInBox (&plant, bounds))
463418 continue ; // Outside cuboid
464419 else if (do_filter && (vector_contains (*filter, (int32_t )plant.material ) == options.filter_ex ))
465420 continue ; // Filtered out
@@ -577,7 +532,7 @@ command_result df_plant(color_ostream &out, vector<string> ¶meters)
577532 DEBUG (log, out).print (" pos_1 = (%d, %d, %d)\n pos_2 = (%d, %d, %d)\n " ,
578533 pos_1.x , pos_1.y , pos_1.z , pos_2.x , pos_2.y , pos_2.z );
579534
580- if (!Core::getInstance (). isMapLoaded ())
535+ if (!Maps::IsValid ())
581536 {
582537 out.printerr (" Map not loaded!\n " );
583538 return CR_FAILURE;
0 commit comments