2011-12-31 04:48:42 -07:00
# include "Core.h"
2012-01-15 13:54:14 -07:00
# include "Console.h"
# include "Export.h"
# include "PluginManager.h"
2012-09-28 17:06:22 -06:00
# include "modules/MapCache.h"
2012-01-11 09:17:25 -07:00
2012-01-15 13:54:14 -07:00
# include "DataDefs.h"
2012-01-11 09:17:25 -07:00
# include "df/ui.h"
# include "df/world.h"
# include "df/unit.h"
using std : : string ;
using std : : vector ;
2011-10-06 19:53:58 -06:00
using namespace DFHack ;
2012-01-11 09:17:25 -07:00
using df : : global : : world ;
using df : : global : : ui ;
2011-10-06 19:53:58 -06:00
// dfhack interface
2012-02-21 10:19:17 -07:00
DFHACK_PLUGIN ( " fastdwarf " ) ;
2011-10-06 19:53:58 -06:00
2012-03-10 04:55:42 -07:00
DFhackCExport command_result plugin_shutdown ( color_ostream & out )
2011-10-06 19:53:58 -06:00
{
return CR_OK ;
}
2012-08-20 20:18:39 -06:00
static bool enable_fastdwarf = false ;
static bool enable_teledwarf = false ;
2011-10-06 19:53:58 -06:00
2012-03-10 04:55:42 -07:00
DFhackCExport command_result plugin_onupdate ( color_ostream & out )
2011-10-06 19:53:58 -06:00
{
2012-03-31 19:46:17 -06:00
// check run conditions
2012-08-20 20:18:39 -06:00
if ( ! world | | ! world - > map . block_index )
2012-03-31 19:46:17 -06:00
{
2012-08-20 20:18:39 -06:00
enable_fastdwarf = enable_teledwarf = false ;
2011-10-06 19:53:58 -06:00
return CR_OK ;
2012-03-31 19:46:17 -06:00
}
2012-01-11 09:17:25 -07:00
int32_t race = ui - > race_id ;
int32_t civ = ui - > civ_id ;
2012-08-20 20:18:39 -06:00
if ( enable_fastdwarf ) {
for ( size_t i = 0 ; i < world - > units . all . size ( ) ; i + + )
{
df : : unit * unit = world - > units . all [ i ] ;
if ( unit - > race = = race & & unit - > civ_id = = civ & & unit - > counters . job_counter > 0 )
unit - > counters . job_counter = 0 ;
// could also patch the unit->job.current_job->completion_timer
}
}
if ( enable_teledwarf ) {
2012-09-28 17:06:22 -06:00
MapExtras : : MapCache * MCache = new MapExtras : : MapCache ( ) ;
2012-08-20 20:18:39 -06:00
for ( size_t i = 0 ; i < world - > units . all . size ( ) ; i + + )
{
df : : unit * unit = world - > units . all [ i ] ;
if ( unit - > race ! = race | | unit - > civ_id ! = civ | | unit - > path . dest . x = = - 30000 )
continue ;
if ( unit - > relations . draggee_id ! = - 1 | | unit - > relations . dragger_id ! = - 1 )
continue ;
if ( unit - > relations . following ! = 0 )
continue ;
2012-09-28 17:06:22 -06:00
MapExtras : : Block * block = MCache - > BlockAtTile ( unit - > pos ) ;
df : : coord2d pos ( unit - > pos . x % 16 , unit - > pos . y % 16 ) ;
df : : tile_occupancy occ = block - > OccupancyAt ( pos ) ;
occ . bits . unit = 0 ;
2012-09-28 17:17:12 -06:00
occ . bits . unit_grounded = 0 ;
2012-09-28 17:06:22 -06:00
block - > setOccupancyAt ( pos , occ ) ;
2012-08-20 20:18:39 -06:00
//move immediately to destination
unit - > pos . x = unit - > path . dest . x ;
unit - > pos . y = unit - > path . dest . y ;
unit - > pos . z = unit - > path . dest . z ;
}
2012-09-28 17:06:22 -06:00
MCache - > WriteAll ( ) ;
delete MCache ;
2011-10-06 19:53:58 -06:00
}
return CR_OK ;
}
2012-03-10 04:55:42 -07:00
static command_result fastdwarf ( color_ostream & out , vector < string > & parameters )
2011-10-06 19:53:58 -06:00
{
2012-08-20 20:18:39 -06:00
if ( parameters . size ( ) = = 1 ) {
if ( parameters [ 0 ] = = " 0 " ) {
2012-09-28 14:36:37 -06:00
enable_fastdwarf = false ;
2012-08-20 20:18:39 -06:00
enable_teledwarf = false ;
} else if ( parameters [ 0 ] = = " 1 " ) {
2012-09-28 14:36:37 -06:00
enable_fastdwarf = true ;
2012-08-20 20:18:39 -06:00
enable_teledwarf = false ;
} else {
out . print ( " Incorrect usage. \n " ) ;
return CR_OK ;
}
} else if ( parameters . size ( ) = = 2 ) {
if ( parameters [ 0 ] = = " 0 " ) {
enable_fastdwarf = false ;
} else if ( parameters [ 0 ] = = " 1 " ) {
enable_fastdwarf = true ;
} else {
out . print ( " Incorrect usage. \n " ) ;
return CR_OK ;
}
if ( parameters [ 1 ] = = " 0 " ) {
enable_teledwarf = false ;
} else if ( parameters [ 1 ] = = " 1 " ) {
enable_teledwarf = true ;
} else {
out . print ( " Incorrect usage. \n " ) ;
return CR_OK ;
}
} else if ( parameters . size ( ) = = 0 ) {
//print status
2012-09-28 14:36:37 -06:00
out . print ( " Current state: fast = %d, teleport = %d. \n " , enable_fastdwarf , enable_teledwarf ) ;
2012-08-20 20:18:39 -06:00
} else {
out . print ( " Incorrect usage. \n " ) ;
return CR_OK ;
}
/*if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1"))
2011-10-27 22:22:07 -06:00
{
2011-10-06 19:53:58 -06:00
if ( parameters [ 0 ] = = " 0 " )
enable_fastdwarf = 0 ;
else
enable_fastdwarf = 1 ;
2012-03-10 04:55:42 -07:00
out . print ( " fastdwarf %sactivated. \n " , ( enable_fastdwarf ? " " : " de " ) ) ;
2011-10-27 22:22:07 -06:00
}
else
{
2012-03-10 04:55:42 -07:00
out . print ( " Makes your minions move at ludicrous speeds. \n "
2012-01-11 09:17:25 -07:00
" Activate with 'fastdwarf 1', deactivate with 'fastdwarf 0'. \n "
" Current state: %d. \n " , enable_fastdwarf ) ;
2012-08-20 20:18:39 -06:00
} */
2011-10-06 19:53:58 -06:00
return CR_OK ;
}
2012-03-10 04:55:42 -07:00
DFhackCExport command_result plugin_init ( color_ostream & out , std : : vector < PluginCommand > & commands )
2011-10-06 19:53:58 -06:00
{
commands . push_back ( PluginCommand ( " fastdwarf " ,
2012-08-20 20:18:39 -06:00
" enable/disable fastdwarf and teledwarf (parameters=0/1) " ,
fastdwarf , false ,
" fastdwarf: controls speedydwarf and teledwarf. Speedydwarf makes dwarves move quickly and perform tasks quickly. Teledwarf makes dwarves move instantaneously, but do jobs at the same speed. \n "
" Usage: \n "
" fastdwarf 0 0: disable both speedydwarf and teledwarf \n "
" fastdwarf 0 1: disable speedydwarf, enable teledwarf \n "
" fastdwarf 1 0: enable speedydwarf, disable teledwarf \n "
" fastdwarf 1 1: enable speedydwarf, enable teledwarf \n "
" fastdwarf 0: disable speedydwarf, disable teledwarf \n "
" fastdwarf 1: enable speedydwarf, disable teledwarf \n "
) ) ;
2011-10-06 19:53:58 -06:00
return CR_OK ;
}