@ -1,13 +1,5 @@
// (un)designate matching plants for gathering/cutting
# include <set>
# include "Core.h"
# include "Console.h"
# include "Export.h"
# include "PluginManager.h"
# include "PluginManager.h"
# include "DataDefs.h"
# include "TileTypes.h"
# include "TileTypes.h"
# include "MiscUtils.h"
# include "df/map_block.h"
# include "df/map_block.h"
# include "df/map_block_column.h"
# include "df/map_block_column.h"
@ -76,48 +68,38 @@ enum class selectability {
// result in the plants not being usable for farming or even collectable at all).
// result in the plants not being usable for farming or even collectable at all).
//selectability selectablePlant(color_ostream &out, const df::plant_raw *plant, bool farming)
//selectability selectablePlant(color_ostream &out, const df::plant_raw *plant, bool farming)
selectability selectablePlant ( const df : : plant_raw * plant , bool farming )
selectability selectablePlant ( const df : : plant_raw * plant , bool farming ) {
{
const DFHack : : MaterialInfo basic_mat = DFHack : : MaterialInfo ( plant - > material_defs . type [ plant_material_def : : basic_mat ] , plant - > material_defs . idx [ plant_material_def : : basic_mat ] ) ;
const DFHack : : MaterialInfo basic_mat = DFHack : : MaterialInfo ( plant - > material_defs . type [ plant_material_def : : basic_mat ] , plant - > material_defs . idx [ plant_material_def : : basic_mat ] ) ;
bool outOfSeason = false ;
bool outOfSeason = false ;
selectability result = selectability : : Nonselectable ;
selectability result = selectability : : Nonselectable ;
if ( plant - > flags . is_set ( plant_raw_flags : : TREE ) )
if ( plant - > flags . is_set ( plant_raw_flags : : TREE ) ) {
{
// out.print("%s is a selectable tree\n", plant->id.c_str());
// out.print("%s is a selectable tree\n", plant->id.c_str());
if ( farming ) {
if ( farming )
{
return selectability : : Nonselectable ;
return selectability : : Nonselectable ;
}
}
else
else {
{
return selectability : : Selectable ;
return selectability : : Selectable ;
}
}
}
}
else if ( plant - > flags . is_set ( plant_raw_flags : : GRASS ) )
else if ( plant - > flags . is_set ( plant_raw_flags : : GRASS ) ) {
{
// out.print("%s is a non selectable Grass\n", plant->id.c_str());
// out.print("%s is a non selectable Grass\n", plant->id.c_str());
return selectability : : Grass ;
return selectability : : Grass ;
}
}
if ( farming & & plant - > material_defs . type [ plant_material_def : : seed ] = = - 1 )
if ( farming & & plant - > material_defs . type [ plant_material_def : : seed ] = = - 1 ) {
{
return selectability : : Nonselectable ;
return selectability : : Nonselectable ;
}
}
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) | |
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) | |
basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) )
basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) ) {
{
// out.print("%s is edible\n", plant->id.c_str());
// out.print("%s is edible\n", plant->id.c_str());
if ( farming ) {
if ( farming )
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) ) {
{
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) )
{
result = selectability : : Selectable ;
result = selectability : : Selectable ;
}
}
}
}
else
else {
{
return selectability : : Selectable ;
return selectability : : Selectable ;
}
}
}
}
@ -126,38 +108,30 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming)
plant - > flags . is_set ( plant_raw_flags : : MILL ) | |
plant - > flags . is_set ( plant_raw_flags : : MILL ) | |
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_VIAL ) | |
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_VIAL ) | |
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_BARREL ) | |
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_BARREL ) | |
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_STILL_VIAL ) )
plant - > flags . is_set ( plant_raw_flags : : EXTRACT_STILL_VIAL ) ) {
{
// out.print("%s is thread/mill/extract\n", plant->id.c_str());
// out.print("%s is thread/mill/extract\n", plant->id.c_str());
if ( farming ) {
if ( farming )
{
result = selectability : : Selectable ;
result = selectability : : Selectable ;
}
}
else
else {
{
return selectability : : Selectable ;
return selectability : : Selectable ;
}
}
}
}
if ( basic_mat . material - > reaction_product . id . size ( ) > 0 | |
if ( basic_mat . material - > reaction_product . id . size ( ) > 0 | |
basic_mat . material - > reaction_class . size ( ) > 0 )
basic_mat . material - > reaction_class . size ( ) > 0 ) {
{
// out.print("%s has a reaction\n", plant->id.c_str());
// out.print("%s has a reaction\n", plant->id.c_str());
if ( farming ) {
if ( farming )
{
result = selectability : : Selectable ;
result = selectability : : Selectable ;
}
}
else
else {
{
return selectability : : Selectable ;
return selectability : : Selectable ;
}
}
}
}
for ( size_t i = 0 ; i < plant - > growths . size ( ) ; i + + )
for ( size_t i = 0 ; i < plant - > growths . size ( ) ; i + + ) {
{
if ( plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS | | // Only trees have seed growths in vanilla, but raws can be modded...
if ( plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS | | // Only trees have seed growths in vanilla, but raws can be modded...
plant - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH )
plant - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH ) {
{
const DFHack : : MaterialInfo growth_mat = DFHack : : MaterialInfo ( plant - > growths [ i ] - > mat_type , plant - > growths [ i ] - > mat_index ) ;
const DFHack : : MaterialInfo growth_mat = DFHack : : MaterialInfo ( plant - > growths [ i ] - > mat_type , plant - > growths [ i ] - > mat_index ) ;
if ( ( plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS & &
if ( ( plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS & &
( growth_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) | |
( growth_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) | |
@ -167,13 +141,10 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming)
{
{
bool seedSource = plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS ;
bool seedSource = plant - > growths [ i ] - > item_type = = df : : item_type : : SEEDS ;
if ( plant - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH )
if ( plant - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH ) {
{
for ( size_t k = 0 ; growth_mat . material - > reaction_product . material . mat_type . size ( ) ; k + + ) {
for ( size_t k = 0 ; growth_mat . material - > reaction_product . material . mat_type . size ( ) ; k + + )
{
if ( growth_mat . material - > reaction_product . material . mat_type [ k ] = = plant - > material_defs . type [ plant_material_def : : seed ] & &
if ( growth_mat . material - > reaction_product . material . mat_type [ k ] = = plant - > material_defs . type [ plant_material_def : : seed ] & &
growth_mat . material - > reaction_product . material . mat_index [ k ] = = plant - > material_defs . idx [ plant_material_def : : seed ] )
growth_mat . material - > reaction_product . material . mat_index [ k ] = = plant - > material_defs . idx [ plant_material_def : : seed ] ) {
{
seedSource = true ;
seedSource = true ;
break ;
break ;
}
}
@ -182,24 +153,20 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming)
if ( * cur_year_tick > = plant - > growths [ i ] - > timing_1 & &
if ( * cur_year_tick > = plant - > growths [ i ] - > timing_1 & &
( plant - > growths [ i ] - > timing_2 = = - 1 | |
( plant - > growths [ i ] - > timing_2 = = - 1 | |
* cur_year_tick < = plant - > growths [ i ] - > timing_2 ) )
* cur_year_tick < = plant - > growths [ i ] - > timing_2 ) ) {
{
// out.print("%s has an edible seed or a stockpile growth\n", plant->id.c_str());
// out.print("%s has an edible seed or a stockpile growth\n", plant->id.c_str());
if ( ! farming | | seedSource ) {
if ( ! farming | | seedSource )
{
return selectability : : Selectable ;
return selectability : : Selectable ;
}
}
}
}
else
else {
{
if ( ! farming | | seedSource ) {
if ( ! farming | | seedSource )
{
outOfSeason = true ;
outOfSeason = true ;
}
}
}
}
}
}
}
}
/* else if (plant->growths[i]->behavior.bits.has_seed) // This code designates beans, etc. when DF doesn't, but plant gatherers still fail to collect anything, so it's useless: bug #0006940.
/* else if (plant->growths[i]->behavior.bits.has_seed) // This code designates beans, etc. when DF doesn't, but plant gatherers still fail to collect anything, so it's useless: bug #0006940.
{
{
const DFHack : : MaterialInfo seed_mat = DFHack : : MaterialInfo ( plant - > material_defs . type [ plant_material_def : : seed ] , plant - > material_defs . idx [ plant_material_def : : seed ] ) ;
const DFHack : : MaterialInfo seed_mat = DFHack : : MaterialInfo ( plant - > material_defs . type [ plant_material_def : : seed ] , plant - > material_defs . idx [ plant_material_def : : seed ] ) ;
@ -220,14 +187,12 @@ selectability selectablePlant(const df::plant_raw *plant, bool farming)
} */
} */
}
}
if ( outOfSeason )
if ( outOfSeason ) {
{
// out.print("%s has an out of season growth\n", plant->id.c_str());
// out.print("%s has an out of season growth\n", plant->id.c_str());
return selectability : : OutOfSeason ;
return selectability : : OutOfSeason ;
}
}
else
else {
{
// out.printerr("%s cannot be gathered\n", plant->id.c_str());
// out.printerr("%s cannot be gathered\n", plant->id.c_str());
return result ;
return result ;
}
}
}
}
@ -241,17 +206,17 @@ bool ripe(int32_t x, int32_t y, int32_t start, int32_t end) {
}
}
// Looks in the picked growths vector to see if a matching growth has been marked as picked.
// Looks in the picked growths vector to see if a matching growth has been marked as picked.
bool picked ( const df : : plant * plant , int32_t growth_subtype ) {
bool picked ( const df : : plant * plant , int32_t growth_subtype ) {
df : : world_data * world_data = world - > world_data ;
df : : world_data * world_data = world - > world_data ;
df : : world_site * site = df : : world_site : : find ( plotinfo - > site_id ) ;
df : : world_site * site = df : : world_site : : find ( plotinfo - > site_id ) ;
int32_t pos_x = site - > global_min_x + plant - > pos . x / 48 ;
int32_t pos_x = site - > global_min_x + plant - > pos . x / 48 ;
int32_t pos_y = site - > global_min_y + plant - > pos . y / 48 ;
int32_t pos_y = site - > global_min_y + plant - > pos . y / 48 ;
size_t id = pos_x + pos_y * 16 * world_data - > world_width ;
size_t id = pos_x + pos_y * 16 * world_data - > world_width ;
df : : world_object_data * object_data = df : : world_object_data : : find ( id ) ;
df : : world_object_data * object_data = df : : world_object_data : : find ( id ) ;
if ( ! object_data ) {
if ( ! object_data ) {
return false ;
return false ;
}
}
df : : map_block_column * column = world - > map . map_block_columns [ ( plant - > pos . x / 16 ) * world - > map . x_count_block + ( plant - > pos . y / 16 ) ] ;
df : : map_block_column * column = world - > map . map_block_columns [ ( plant - > pos . x / 16 ) * world - > map . x_count_block + ( plant - > pos . y / 16 ) ] ;
for ( size_t i = 0 ; i < object_data - > picked_growths . x . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < object_data - > picked_growths . x . size ( ) ; i + + ) {
if ( object_data - > picked_growths . x [ i ] = = plant - > pos . x & &
if ( object_data - > picked_growths . x [ i ] = = plant - > pos . x & &
@ -266,13 +231,12 @@ bool picked(const df::plant *plant, int32_t growth_subtype) {
return false ;
return false ;
}
}
bool designate ( const df : : plant * plant , bool farming ) {
bool designate ( const df : : plant * plant , bool farming ) {
df : : plant_raw * plant_raw = world - > raws . plants . all [ plant - > material ] ;
df : : plant_raw * plant_raw = world - > raws . plants . all [ plant - > material ] ;
const DFHack : : MaterialInfo basic_mat = DFHack : : MaterialInfo ( plant_raw - > material_defs . type [ plant_material_def : : basic_mat ] , plant_raw - > material_defs . idx [ plant_material_def : : basic_mat ] ) ;
const DFHack : : MaterialInfo basic_mat = DFHack : : MaterialInfo ( plant_raw - > material_defs . type [ plant_material_def : : basic_mat ] , plant_raw - > material_defs . idx [ plant_material_def : : basic_mat ] ) ;
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) | |
if ( basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_RAW ) | |
basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) )
basic_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) ) {
{
return Designations : : markPlant ( plant ) ;
return Designations : : markPlant ( plant ) ;
}
}
@ -280,26 +244,22 @@ bool designate(const df::plant *plant, bool farming) {
plant_raw - > flags . is_set ( plant_raw_flags : : MILL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : MILL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_VIAL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_VIAL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_BARREL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_BARREL ) | |
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_STILL_VIAL ) )
plant_raw - > flags . is_set ( plant_raw_flags : : EXTRACT_STILL_VIAL ) ) {
{
if ( ! farming ) {
if ( ! farming ) {
return Designations : : markPlant ( plant ) ;
return Designations : : markPlant ( plant ) ;
}
}
}
}
if ( basic_mat . material - > reaction_product . id . size ( ) > 0 | |
if ( basic_mat . material - > reaction_product . id . size ( ) > 0 | |
basic_mat . material - > reaction_class . size ( ) > 0 )
basic_mat . material - > reaction_class . size ( ) > 0 ) {
{
if ( ! farming ) {
if ( ! farming ) {
return Designations : : markPlant ( plant ) ;
return Designations : : markPlant ( plant ) ;
}
}
}
}
for ( size_t i = 0 ; i < plant_raw - > growths . size ( ) ; i + + )
for ( size_t i = 0 ; i < plant_raw - > growths . size ( ) ; i + + ) {
{
if ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS | | // Only trees have seed growths in vanilla, but raws can be modded...
if ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS | | // Only trees have seed growths in vanilla, but raws can be modded...
plant_raw - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH )
plant_raw - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH ) {
{
const DFHack : : MaterialInfo growth_mat = DFHack : : MaterialInfo ( plant_raw - > growths [ i ] - > mat_type , plant_raw - > growths [ i ] - > mat_index ) ;
const DFHack : : MaterialInfo growth_mat = DFHack : : MaterialInfo ( plant_raw - > growths [ i ] - > mat_type , plant_raw - > growths [ i ] - > mat_index ) ;
if ( ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS & &
if ( ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS & &
( growth_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) | |
( growth_mat . material - > flags . is_set ( material_flags : : EDIBLE_COOKED ) | |
@ -309,13 +269,10 @@ bool designate(const df::plant *plant, bool farming) {
{
{
bool seedSource = plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS ;
bool seedSource = plant_raw - > growths [ i ] - > item_type = = df : : item_type : : SEEDS ;
if ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH )
if ( plant_raw - > growths [ i ] - > item_type = = df : : item_type : : PLANT_GROWTH ) {
{
for ( size_t k = 0 ; growth_mat . material - > reaction_product . material . mat_type . size ( ) ; k + + ) {
for ( size_t k = 0 ; growth_mat . material - > reaction_product . material . mat_type . size ( ) ; k + + )
{
if ( growth_mat . material - > reaction_product . material . mat_type [ k ] = = plant_raw - > material_defs . type [ plant_material_def : : seed ] & &
if ( growth_mat . material - > reaction_product . material . mat_type [ k ] = = plant_raw - > material_defs . type [ plant_material_def : : seed ] & &
growth_mat . material - > reaction_product . material . mat_index [ k ] = = plant_raw - > material_defs . idx [ plant_material_def : : seed ] )
growth_mat . material - > reaction_product . material . mat_index [ k ] = = plant_raw - > material_defs . idx [ plant_material_def : : seed ] ) {
{
seedSource = true ;
seedSource = true ;
break ;
break ;
}
}
@ -324,8 +281,7 @@ bool designate(const df::plant *plant, bool farming) {
bool istree = ( tileMaterial ( Maps : : getTileBlock ( plant - > pos ) - > tiletype [ plant - > pos . x % 16 ] [ plant - > pos . y % 16 ] ) = = tiletype_material : : TREE ) ;
bool istree = ( tileMaterial ( Maps : : getTileBlock ( plant - > pos ) - > tiletype [ plant - > pos . x % 16 ] [ plant - > pos . y % 16 ] ) = = tiletype_material : : TREE ) ;
bool isripe = ripe ( plant - > pos . x , plant - > pos . y , plant_raw - > growths [ i ] - > timing_1 , plant_raw - > growths [ i ] - > timing_2 ) ;
bool isripe = ripe ( plant - > pos . x , plant - > pos . y , plant_raw - > growths [ i ] - > timing_1 , plant_raw - > growths [ i ] - > timing_2 ) ;
if ( ( ! farming | | seedSource ) & & ( istree | | isripe ) & & ! picked ( plant , i ) )
if ( ( ! farming | | seedSource ) & & ( istree | | isripe ) & & ! picked ( plant , i ) ) {
{
return Designations : : markPlant ( plant ) ;
return Designations : : markPlant ( plant ) ;
}
}
}
}
@ -335,8 +291,7 @@ bool designate(const df::plant *plant, bool farming) {
return false ;
return false ;
}
}
command_result df_getplants ( color_ostream & out , vector < string > & parameters )
command_result df_getplants ( color_ostream & out , vector < string > & parameters ) {
{
string plantMatStr = " " ;
string plantMatStr = " " ;
std : : vector < selectability > plantSelections ;
std : : vector < selectability > plantSelections ;
std : : vector < size_t > collectionCount ;
std : : vector < size_t > collectionCount ;
@ -348,16 +303,14 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
plantSelections . resize ( world - > raws . plants . all . size ( ) ) ;
plantSelections . resize ( world - > raws . plants . all . size ( ) ) ;
collectionCount . resize ( world - > raws . plants . all . size ( ) ) ;
collectionCount . resize ( world - > raws . plants . all . size ( ) ) ;
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + )
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + ) {
{
plantSelections [ i ] = selectability : : Unselected ;
plantSelections [ i ] = selectability : : Unselected ;
collectionCount [ i ] = 0 ;
collectionCount [ i ] = 0 ;
}
}
bool anyPlantsSelected = false ;
bool anyPlantsSelected = false ;
for ( size_t i = 0 ; i < parameters . size ( ) ; i + + )
for ( size_t i = 0 ; i < parameters . size ( ) ; i + + ) {
{
if ( parameters [ i ] = = " help " | | parameters [ i ] = = " ? " )
if ( parameters [ i ] = = " help " | | parameters [ i ] = = " ? " )
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
else if ( parameters [ i ] = = " -t " )
else if ( parameters [ i ] = = " -t " )
@ -374,23 +327,18 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
verbose = true ;
verbose = true ;
else if ( parameters [ i ] = = " -f " )
else if ( parameters [ i ] = = " -f " )
farming = true ;
farming = true ;
else if ( parameters [ i ] = = " -n " )
else if ( parameters [ i ] = = " -n " ) {
{
if ( parameters . size ( ) > i + 1 ) {
if ( parameters . size ( ) > i + 1 )
{
maxCount = atoi ( parameters [ i + 1 ] . c_str ( ) ) ;
maxCount = atoi ( parameters [ i + 1 ] . c_str ( ) ) ;
if ( maxCount > = 1 )
if ( maxCount > = 1 ) {
{
i + + ; // We've consumed the next parameter, so we need to progress the iterator.
i + + ; // We've consumed the next parameter, so we need to progress the iterator.
}
}
else
else {
{
out . printerr ( " -n requires a positive integer parameter! \n " ) ;
out . printerr ( " -n requires a positive integer parameter! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
}
}
else
else {
{
out . printerr ( " -n requires a positive integer parameter! \n " ) ;
out . printerr ( " -n requires a positive integer parameter! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
@ -398,55 +346,45 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
else
else
plantNames . insert ( toUpper ( parameters [ i ] ) ) ;
plantNames . insert ( toUpper ( parameters [ i ] ) ) ;
}
}
if ( treesonly & & shrubsonly )
if ( treesonly & & shrubsonly ) {
{
out . printerr ( " Cannot specify both -t and -s at the same time! \n " ) ;
out . printerr ( " Cannot specify both -t and -s at the same time! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
if ( treesonly & & farming )
if ( treesonly & & farming ) {
{
out . printerr ( " Cannot specify both -t and -f at the same time! \n " ) ;
out . printerr ( " Cannot specify both -t and -f at the same time! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
if ( all & & exclude )
if ( all & & exclude ) {
{
out . printerr ( " Cannot specify both -a and -x at the same time! \n " ) ;
out . printerr ( " Cannot specify both -a and -x at the same time! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
if ( all & & plantNames . size ( ) )
if ( all & & plantNames . size ( ) ) {
{
out . printerr ( " Cannot specify -a along with plant IDs! \n " ) ;
out . printerr ( " Cannot specify -a along with plant IDs! \n " ) ;
return CR_WRONG_USAGE ;
return CR_WRONG_USAGE ;
}
}
CoreSuspender suspend ;
CoreSuspender suspend ;
for ( size_t i = 0 ; i < world - > raws . plants . all . size ( ) ; i + + )
for ( size_t i = 0 ; i < world - > raws . plants . all . size ( ) ; i + + ) {
{
df : : plant_raw * plant = world - > raws . plants . all [ i ] ;
df : : plant_raw * plant = world - > raws . plants . all [ i ] ;
if ( all ) {
if ( all )
// plantSelections[i] = selectablePlant(out, plant, farming);
{
// plantSelections[i] = selectablePlant(out, plant, farming);
plantSelections [ i ] = selectablePlant ( plant , farming ) ;
plantSelections [ i ] = selectablePlant ( plant , farming ) ;
}
}
else if ( plantNames . find ( plant - > id ) ! = plantNames . end ( ) )
else if ( plantNames . find ( plant - > id ) ! = plantNames . end ( ) ) {
{
plantNames . erase ( plant - > id ) ;
plantNames . erase ( plant - > id ) ;
// plantSelections[i] = selectablePlant(out, plant, farming);
// plantSelections[i] = selectablePlant(out, plant, farming);
plantSelections [ i ] = selectablePlant ( plant , farming ) ;
plantSelections [ i ] = selectablePlant ( plant , farming ) ;
switch ( plantSelections [ i ] )
switch ( plantSelections [ i ] ) {
{
case selectability : : Grass :
case selectability : : Grass :
out . printerr ( " %s is a grass and cannot be gathered \n " , plant - > id . c_str ( ) ) ;
out . printerr ( " %s is a grass and cannot be gathered \n " , plant - > id . c_str ( ) ) ;
break ;
break ;
case selectability : : Nonselectable :
case selectability : : Nonselectable :
if ( farming )
if ( farming ) {
{
out . printerr ( " %s does not have any parts that can be gathered for seeds for farming \n " , plant - > id . c_str ( ) ) ;
out . printerr ( " %s does not have any parts that can be gathered for seeds for farming \n " , plant - > id . c_str ( ) ) ;
}
}
else
else {
{
out . printerr ( " %s does not have any parts that can be gathered \n " , plant - > id . c_str ( ) ) ;
out . printerr ( " %s does not have any parts that can be gathered \n " , plant - > id . c_str ( ) ) ;
}
}
break ;
break ;
@ -463,8 +401,7 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
}
}
}
}
}
}
if ( plantNames . size ( ) > 0 )
if ( plantNames . size ( ) > 0 ) {
{
out . printerr ( " Invalid plant ID(s): " ) ;
out . printerr ( " Invalid plant ID(s): " ) ;
for ( set < string > : : const_iterator it = plantNames . begin ( ) ; it ! = plantNames . end ( ) ; it + + )
for ( set < string > : : const_iterator it = plantNames . begin ( ) ; it ! = plantNames . end ( ) ; it + + )
out . printerr ( " %s " , it - > c_str ( ) ) ;
out . printerr ( " %s " , it - > c_str ( ) ) ;
@ -472,33 +409,27 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
return CR_FAILURE ;
return CR_FAILURE ;
}
}
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + )
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + ) {
{
if ( plantSelections [ i ] = = selectability : : OutOfSeason | |
if ( plantSelections [ i ] = = selectability : : OutOfSeason | |
plantSelections [ i ] = = selectability : : Selectable )
plantSelections [ i ] = = selectability : : Selectable ) {
{
anyPlantsSelected = true ;
anyPlantsSelected = true ;
break ;
break ;
}
}
}
}
if ( ! anyPlantsSelected )
if ( ! anyPlantsSelected ) {
{
out . print ( " Valid plant IDs: \n " ) ;
out . print ( " Valid plant IDs: \n " ) ;
for ( size_t i = 0 ; i < world - > raws . plants . all . size ( ) ; i + + )
for ( size_t i = 0 ; i < world - > raws . plants . all . size ( ) ; i + + ) {
{
df : : plant_raw * plant = world - > raws . plants . all [ i ] ;
df : : plant_raw * plant = world - > raws . plants . all [ i ] ;
// switch (selectablePlant(out, plant, farming))
// switch (selectablePlant(out, plant, farming))
switch ( selectablePlant ( plant , farming ) ) {
switch ( selectablePlant ( plant , farming ) )
{
case selectability : : Grass :
case selectability : : Grass :
case selectability : : Nonselectable :
case selectability : : Nonselectable :
continue ;
continue ;
case selectability : : OutOfSeason :
case selectability : : OutOfSeason :
{
{
if ( ! treesonly )
if ( ! treesonly ) {
{
out . print ( " * (shrub) %s - %s is out of season \n " , plant - > id . c_str ( ) , plant - > name . c_str ( ) ) ;
out . print ( " * (shrub) %s - %s is out of season \n " , plant - > id . c_str ( ) , plant - > name . c_str ( ) ) ;
}
}
break ;
break ;
@ -523,22 +454,19 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
}
}
count = 0 ;
count = 0 ;
for ( size_t i = 0 ; i < world - > plants . all . size ( ) ; i + + )
for ( size_t i = 0 ; i < world - > plants . all . size ( ) ; i + + ) {
{
const df : : plant * plant = world - > plants . all [ i ] ;
const df : : plant * plant = world - > plants . all [ i ] ;
df : : map_block * cur = Maps : : getTileBlock ( plant - > pos ) ;
df : : map_block * cur = Maps : : getTileBlock ( plant - > pos ) ;
int x = plant - > pos . x % 16 ;
int x = plant - > pos . x % 16 ;
int y = plant - > pos . y % 16 ;
int y = plant - > pos . y % 16 ;
if ( plantSelections [ plant - > material ] = = selectability : : OutOfSeason | |
if ( plantSelections [ plant - > material ] = = selectability : : OutOfSeason | |
plantSelections [ plant - > material ] = = selectability : : Selectable )
plantSelections [ plant - > material ] = = selectability : : Selectable ) {
{
if ( exclude | |
if ( exclude | |
plantSelections [ plant - > material ] = = selectability : : OutOfSeason )
plantSelections [ plant - > material ] = = selectability : : OutOfSeason )
continue ;
continue ;
}
}
else
else {
{
if ( ! exclude )
if ( ! exclude )
continue ;
continue ;
}
}
@ -553,37 +481,29 @@ command_result df_getplants (color_ostream &out, vector <string> & parameters)
continue ;
continue ;
if ( collectionCount [ plant - > material ] > = maxCount )
if ( collectionCount [ plant - > material ] > = maxCount )
continue ;
continue ;
if ( deselect & & Designations : : unmarkPlant ( plant ) )
if ( deselect & & Designations : : unmarkPlant ( plant ) ) {
{
collectionCount [ plant - > material ] + + ;
collectionCount [ plant - > material ] + + ;
+ + count ;
+ + count ;
}
}
if ( ! deselect & & designate ( plant , farming ) )
if ( ! deselect & & designate ( plant , farming ) ) {
{
// out.print("Designated %s at (%i, %i, %i), %d\n", world->raws.plants.all[plant->material]->id.c_str(), plant->pos.x, plant->pos.y, plant->pos.z, (int)i);
// out.print("Designated %s at (%i, %i, %i), %d\n", world->raws.plants.all[plant->material]->id.c_str(), plant->pos.x, plant->pos.y, plant->pos.z, (int)i);
collectionCount [ plant - > material ] + + ;
collectionCount [ plant - > material ] + + ;
+ + count ;
+ + count ;
}
}
}
}
if ( count )
if ( count & & verbose ) {
{
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + ) {
if ( verbose )
{
for ( size_t i = 0 ; i < plantSelections . size ( ) ; i + + )
{
if ( collectionCount [ i ] > 0 )
if ( collectionCount [ i ] > 0 )
out . print ( " Updated %d %s designations. \n " , ( int ) collectionCount [ i ] , world - > raws . plants . all [ i ] - > id . c_str ( ) ) ;
out . print ( " Updated %d %s designations. \n " , ( int ) collectionCount [ i ] , world - > raws . plants . all [ i ] - > id . c_str ( ) ) ;
}
}
out . print ( " \n " ) ;
out . print ( " \n " ) ;
}
}
}
out . print ( " Updated %d plant designations. \n " , ( int ) count ) ;
out . print ( " Updated %d plant designations. \n " , ( int ) count ) ;
return CR_OK ;
return CR_OK ;
}
}
DFhackCExport command_result plugin_init ( color_ostream & out , vector < PluginCommand > & commands )
DFhackCExport command_result plugin_init ( color_ostream & out , vector < PluginCommand > & commands ) {
{
commands . push_back ( PluginCommand (
commands . push_back ( PluginCommand (
" getplants " ,
" getplants " ,
" Designate trees for chopping and shrubs for gathering. " ,
" Designate trees for chopping and shrubs for gathering. " ,
@ -591,7 +511,6 @@ DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCom
return CR_OK ;
return CR_OK ;
}
}
DFhackCExport command_result plugin_shutdown ( color_ostream & out )
DFhackCExport command_result plugin_shutdown ( color_ostream & out ) {
{
return CR_OK ;
return CR_OK ;
}
}