2011-10-06 19:53:58 -06:00
// foo
// vi:expandtab:sw=4
# include <iostream>
# include <vector>
# include <map>
# include <stddef.h>
# include <assert.h>
# include <string.h>
using namespace std ;
# include <dfhack/Core.h>
# include <dfhack/Console.h>
# include <dfhack/Export.h>
# include <dfhack/PluginManager.h>
# include <dfhack/VersionInfo.h>
2011-12-02 02:56:40 -07:00
# include <dfhack/modules/Units.h>
2011-10-06 19:53:58 -06:00
using namespace DFHack ;
// dfhack interface
DFhackCExport const char * plugin_name ( void )
{
return " fastdwarf " ;
}
DFhackCExport command_result plugin_shutdown ( Core * c )
{
return CR_OK ;
}
static int enable_fastdwarf ;
DFhackCExport command_result plugin_onupdate ( Core * c )
{
if ( ! enable_fastdwarf )
return CR_OK ;
2011-12-02 02:56:40 -07:00
df_unit * cre ;
DFHack : : Units * cr = c - > getUnits ( ) ;
static vector < df_unit * > * v = cr - > creatures ;
2011-10-27 22:22:07 -06:00
uint32_t race = cr - > GetDwarfRaceIndex ( ) ;
uint32_t civ = cr - > GetDwarfCivId ( ) ;
if ( ! v )
{
c - > con . printerr ( " Unable to locate creature vector. Fastdwarf cancelled. \n " ) ;
2011-10-06 19:53:58 -06:00
}
2011-10-27 22:22:07 -06:00
for ( unsigned i = 0 ; i < v - > size ( ) ; + + i )
{
2011-10-06 19:53:58 -06:00
cre = v - > at ( i ) ;
2011-10-27 22:22:07 -06:00
if ( cre - > race = = race & & cre - > civ = = civ & & cre - > job_counter > 0 )
2011-10-06 19:53:58 -06:00
cre - > job_counter = 0 ;
2011-10-27 22:22:07 -06:00
// could also patch the cre->current_job->counter
2011-10-06 19:53:58 -06:00
}
return CR_OK ;
}
static command_result fastdwarf ( Core * c , vector < string > & parameters )
{
2011-10-27 22:22:07 -06:00
if ( parameters . size ( ) = = 1 & & ( parameters [ 0 ] = = " 0 " | | parameters [ 0 ] = = " 1 " ) )
{
2011-10-06 19:53:58 -06:00
if ( parameters [ 0 ] = = " 0 " )
enable_fastdwarf = 0 ;
else
enable_fastdwarf = 1 ;
c - > con . print ( " fastdwarf %sactivated. \n " , ( enable_fastdwarf ? " " : " de " ) ) ;
2011-10-27 22:22:07 -06:00
}
else
{
c - > con . print ( " Makes your minions move at ludicrous speeds. \n Activate with 'fastdwarf 1', deactivate with 'fastdwarf 0'. \n Current state: %d. \n " , enable_fastdwarf ) ;
2011-10-06 19:53:58 -06:00
}
return CR_OK ;
}
DFhackCExport command_result plugin_init ( Core * c , std : : vector < PluginCommand > & commands )
{
commands . clear ( ) ;
commands . push_back ( PluginCommand ( " fastdwarf " ,
" enable/disable fastdwarf (parameter=0/1) " ,
fastdwarf ) ) ;
return CR_OK ;
}