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-10-04 19:14:50 -06:00
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Maps.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/world.h"
|
|
|
|
#include "df/unit.h"
|
2012-10-04 19:14:50 -06:00
|
|
|
#include "df/map_block.h"
|
2012-01-11 09:17:25 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
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-10-04 19:14:50 -06:00
|
|
|
static bool enable_fastdwarf = false;
|
|
|
|
static bool enable_teledwarf = false;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-10-06 19:53:58 -06:00
|
|
|
{
|
2012-10-04 19:14:50 -06:00
|
|
|
if (df::global::debug_turbospeed)
|
|
|
|
*df::global::debug_turbospeed = false;
|
2011-10-06 19:53:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
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-10-04 19:14:50 -06:00
|
|
|
// do we even need to do anything at all?
|
|
|
|
if (!enable_fastdwarf && !enable_teledwarf)
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
// make sure the world is actually loaded
|
|
|
|
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-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
df::map_block *old_block, *new_block;
|
|
|
|
for (size_t i = 0; i < world->units.active.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit *unit = world->units.active[i];
|
|
|
|
// citizens only
|
|
|
|
if (!Units::isCitizen(unit))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (enable_fastdwarf)
|
2012-08-20 20:18:39 -06:00
|
|
|
{
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
if (unit->counters.job_counter > 0)
|
2012-08-20 20:18:39 -06:00
|
|
|
unit->counters.job_counter = 0;
|
|
|
|
// could also patch the unit->job.current_job->completion_timer
|
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
if (enable_teledwarf)
|
2012-08-20 20:18:39 -06:00
|
|
|
{
|
2012-10-04 19:14:50 -06:00
|
|
|
// don't do anything if the dwarf isn't going anywhere
|
|
|
|
if (unit->path.dest.x == -30000)
|
2012-08-20 20:18:39 -06:00
|
|
|
continue;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
// skip dwarves that are dragging creatures or being dragged
|
|
|
|
if ((unit->relations.draggee_id != -1) || (unit->relations.dragger_id != -1))
|
2012-08-20 20:18:39 -06:00
|
|
|
continue;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
// skip dwarves that are following other units
|
2012-08-20 20:18:39 -06:00
|
|
|
if (unit->relations.following != 0)
|
|
|
|
continue;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
old_block = Maps::getTileBlock(unit->pos.x, unit->pos.y, unit->pos.z);
|
|
|
|
new_block = Maps::getTileBlock(unit->path.dest.x, unit->path.dest.y, unit->path.dest.z);
|
|
|
|
// just to be safe, prevent the dwarf from being moved to an unallocated map block!
|
|
|
|
if (!old_block || !new_block)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// clear appropriate occupancy flags at old tile
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
// this is technically wrong, but the game will recompute this as needed
|
|
|
|
old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit_grounded = 0;
|
|
|
|
else
|
|
|
|
old_block->occupancy[unit->pos.x & 0xF][unit->pos.y & 0xF].bits.unit = 0;
|
|
|
|
|
|
|
|
// if there's already somebody standing at the destination, then force the unit to lay down
|
|
|
|
if (new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit)
|
|
|
|
unit->flags1.bits.on_ground = 1;
|
|
|
|
|
|
|
|
// set appropriate occupancy flags at new tile
|
|
|
|
if (unit->flags1.bits.on_ground)
|
|
|
|
new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit_grounded = 1;
|
|
|
|
else
|
|
|
|
new_block->occupancy[unit->path.dest.x & 0xF][unit->path.dest.y & 0xF].bits.unit = 1;
|
|
|
|
|
|
|
|
// move unit to destination
|
2012-08-20 20:18:39 -06:00
|
|
|
unit->pos.x = unit->path.dest.x;
|
|
|
|
unit->pos.y = unit->path.dest.y;
|
|
|
|
unit->pos.z = unit->path.dest.z;
|
|
|
|
}
|
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-10-04 19:14:50 -06:00
|
|
|
if (parameters.size() > 2) {
|
|
|
|
out.print("Incorrect usage.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters.size() <= 2)
|
|
|
|
{
|
|
|
|
if (parameters.size() == 2)
|
|
|
|
{
|
|
|
|
if (parameters[1] == "0")
|
|
|
|
enable_teledwarf = false;
|
|
|
|
else if (parameters[1] == "1")
|
|
|
|
enable_teledwarf = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.print("Incorrect usage.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-08-20 20:18:39 -06:00
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
else
|
|
|
|
enable_teledwarf = false;
|
|
|
|
if (parameters[0] == "0")
|
|
|
|
{
|
2012-08-20 20:18:39 -06:00
|
|
|
enable_fastdwarf = false;
|
2012-10-04 19:14:50 -06:00
|
|
|
if (df::global::debug_turbospeed)
|
|
|
|
*df::global::debug_turbospeed = false;
|
|
|
|
}
|
|
|
|
else if (parameters[0] == "1")
|
|
|
|
{
|
2012-08-20 20:18:39 -06:00
|
|
|
enable_fastdwarf = true;
|
2012-10-04 19:14:50 -06:00
|
|
|
if (df::global::debug_turbospeed)
|
|
|
|
*df::global::debug_turbospeed = false;
|
2012-08-20 20:18:39 -06:00
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
else if (parameters[0] == "2")
|
|
|
|
{
|
|
|
|
if (df::global::debug_turbospeed)
|
|
|
|
{
|
|
|
|
enable_fastdwarf = false;
|
|
|
|
*df::global::debug_turbospeed = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.print("Speed level 2 not available.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-08-20 20:18:39 -06:00
|
|
|
}
|
2011-10-06 19:53:58 -06:00
|
|
|
else
|
2012-10-04 19:14:50 -06:00
|
|
|
{
|
|
|
|
out.print("Incorrect usage.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-10-27 22:22:07 -06:00
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
out.print("Current state: fast = %d, teleport = %d.\n",
|
|
|
|
(df::global::debug_turbospeed && *df::global::debug_turbospeed) ? 2 : (enable_fastdwarf ? 1 : 0),
|
|
|
|
enable_teledwarf ? 1 : 0);
|
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,
|
2012-10-04 19:14:50 -06:00
|
|
|
"fastdwarf: make dwarves faster.\n"
|
2012-08-20 20:18:39 -06:00
|
|
|
"Usage:\n"
|
2012-10-04 19:14:50 -06:00
|
|
|
" fastdwarf <speed> (tele)\n"
|
|
|
|
"Valid values for speed:\n"
|
|
|
|
" * 0 - Make dwarves move and work at standard speed.\n"
|
|
|
|
" * 1 - Make dwarves move and work at maximum speed.\n"
|
|
|
|
" * 2 - Make ALL creatures move and work at maximum speed.\n"
|
|
|
|
"Valid values for (tele):\n"
|
|
|
|
" * 0 - Disable dwarf teleportation (default)\n"
|
|
|
|
" * 1 - Make dwarves teleport to their destinations instantly.\n"
|
2012-08-20 20:18:39 -06:00
|
|
|
));
|
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|