2012-03-10 12:40:55 -07:00
// Map feature manager - list features and discover/undiscover individual ones
# include "Core.h"
# include "Console.h"
# include "Export.h"
# include "PluginManager.h"
# include "DataDefs.h"
# include "df/world.h"
# include "df/feature_init.h"
# include <stdlib.h>
using std : : vector ;
using std : : string ;
using std : : endl ;
using namespace DFHack ;
using namespace df : : enums ;
using df : : global : : world ;
static command_result feature ( color_ostream & out , vector < string > & parameters )
{
CoreSuspender suspend ;
if ( parameters . empty ( ) )
return CR_WRONG_USAGE ;
string cmd = parameters [ 0 ] ;
if ( cmd = = " list " )
{
if ( parameters . size ( ) ! = 1 )
return CR_WRONG_USAGE ;
2012-03-14 00:56:30 -06:00
for ( size_t i = 0 ; i < world - > cur_savegame . map_features . size ( ) ; i + + )
2012-03-10 12:40:55 -07:00
{
2012-03-14 00:56:30 -06:00
df : : feature_init * feature_init = world - > cur_savegame . map_features [ i ] ;
2012-03-10 12:40:55 -07:00
string name ;
feature_init - > getName ( & name ) ;
out . print ( " Feature #%i ( \" %s \" , type %s) is %s \n " , i , name . c_str ( ) , ENUM_KEY_STR ( feature_type , feature_init - > getType ( ) ) , feature_init - > flags . is_set ( feature_init_flags : : Discovered ) ? " discovered " : " hidden " ) ;
}
}
else if ( cmd = = " show " )
{
if ( parameters . size ( ) ! = 2 )
return CR_WRONG_USAGE ;
size_t i = atoi ( parameters [ 1 ] . c_str ( ) ) ;
2012-03-14 00:56:30 -06:00
if ( ( i < 0 ) | | ( i > = world - > cur_savegame . map_features . size ( ) ) )
2012-03-10 12:40:55 -07:00
{
out . print ( " No such feature! \n " ) ;
return CR_FAILURE ;
}
2012-03-14 00:56:30 -06:00
df : : feature_init * feature_init = world - > cur_savegame . map_features [ i ] ;
2012-03-10 12:40:55 -07:00
if ( feature_init - > flags . is_set ( feature_init_flags : : Discovered ) )
{
out . print ( " Selected feature is already discovered! \n " ) ;
return CR_OK ;
}
feature_init - > flags . set ( feature_init_flags : : Discovered ) ;
string name ;
feature_init - > getName ( & name ) ;
out . print ( " Feature #%i ( \" %s \" , type %s) is now discovered \n " , i , name . c_str ( ) , ENUM_KEY_STR ( feature_type , feature_init - > getType ( ) ) ) ;
}
else if ( cmd = = " hide " )
{
if ( parameters . size ( ) ! = 2 )
return CR_WRONG_USAGE ;
size_t i = atoi ( parameters [ 1 ] . c_str ( ) ) ;
2012-03-14 00:56:30 -06:00
if ( ( i < 0 ) | | ( i > = world - > cur_savegame . map_features . size ( ) ) )
2012-03-10 12:40:55 -07:00
{
out . print ( " No such feature! \n " ) ;
return CR_FAILURE ;
}
2012-03-14 00:56:30 -06:00
df : : feature_init * feature_init = world - > cur_savegame . map_features [ i ] ;
2012-03-10 12:40:55 -07:00
if ( ! feature_init - > flags . is_set ( feature_init_flags : : Discovered ) )
{
out . print ( " Selected feature is already hidden! \n " ) ;
return CR_OK ;
}
feature_init - > flags . clear ( feature_init_flags : : Discovered ) ;
string name ;
feature_init - > getName ( & name ) ;
out . print ( " Feature #%i ( \" %s \" , type %s) is now hidden \n " , i , name . c_str ( ) , ENUM_KEY_STR ( feature_type , feature_init - > getType ( ) ) ) ;
}
else return CR_WRONG_USAGE ;
return CR_OK ;
}
DFHACK_PLUGIN ( " feature " ) ;
DFhackCExport command_result plugin_init ( color_ostream & out , std : : vector < PluginCommand > & commands )
{
commands . clear ( ) ;
commands . push_back ( PluginCommand (
2012-03-11 15:45:41 -06:00
" feature " , " List or manage map features. " , feature , false ,
2012-03-10 12:40:55 -07:00
" feature list \n "
" Lists all map features in the region. \n "
" feature show <ID> \n "
" Marks the specified map feature as discovered. \n "
" feature hide <ID> \n "
" Marks the specified map feature as undiscovered. \n "
) ) ;
return CR_OK ;
}
DFhackCExport command_result plugin_shutdown ( color_ostream & out )
{
return CR_OK ;
}