2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
2016-08-10 21:50:00 -06:00
|
|
|
#include "DataDefs.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#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
|
|
|
|
2016-08-10 21:50:00 -06:00
|
|
|
#include "df/map_block.h"
|
2012-01-11 09:17:25 -07:00
|
|
|
#include "df/unit.h"
|
2014-08-01 07:45:23 -06:00
|
|
|
#include "df/unit_action.h"
|
2016-08-10 21:50:00 -06:00
|
|
|
#include "df/unit_relationship_type.h"
|
2016-03-10 04:37:57 -07:00
|
|
|
#include "df/units_other_id.h"
|
2016-08-10 21:50:00 -06:00
|
|
|
#include "df/world.h"
|
2012-01-11 09:17:25 -07:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2014-08-01 07:45:23 -06:00
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
using namespace DFHack;
|
2014-08-01 07:45:23 -06:00
|
|
|
using namespace df::enums;
|
2011-10-06 19:53:58 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("fastdwarf");
|
2013-09-30 03:19:51 -06:00
|
|
|
DFHACK_PLUGIN_IS_ENABLED(active);
|
2014-12-06 16:47:35 -07:00
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
using df::global::debug_turbospeed; // not required
|
2013-09-30 03:19:51 -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
|
|
|
{
|
2014-08-01 07:45:23 -06:00
|
|
|
if (debug_turbospeed)
|
|
|
|
*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
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-06-06 10:00:33 -06:00
|
|
|
if (enable_teledwarf) do
|
2012-08-20 20:18:39 -06:00
|
|
|
{
|
2012-10-04 19:14:50 -06:00
|
|
|
// skip dwarves that are dragging creatures or being dragged
|
2016-08-10 21:50:00 -06:00
|
|
|
if ((unit->relationship_ids[df::unit_relationship_type::Draggee] != -1) ||
|
|
|
|
(unit->relationship_ids[df::unit_relationship_type::Dragger] != -1))
|
2012-10-04 19:20:35 -06:00
|
|
|
break;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
|
|
|
// skip dwarves that are following other units
|
2016-08-10 21:50:00 -06:00
|
|
|
if (unit->following != 0)
|
2012-10-04 19:20:35 -06:00
|
|
|
break;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
2012-10-06 02:40:46 -06:00
|
|
|
// skip unconscious units
|
|
|
|
if (unit->counters.unconscious > 0)
|
|
|
|
break;
|
|
|
|
|
2014-08-01 07:45:23 -06:00
|
|
|
// don't do anything if the dwarf isn't going anywhere
|
|
|
|
if (!unit->pos.isValid() || !unit->path.dest.isValid() || unit->pos == unit->path.dest) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-06 09:48:32 -06:00
|
|
|
if (!Units::teleport(unit, unit->path.dest))
|
2012-10-04 19:20:35 -06:00
|
|
|
break;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
2012-10-06 02:40:46 -06:00
|
|
|
unit->path.path.clear();
|
2021-06-06 10:00:33 -06:00
|
|
|
} while (0);
|
2014-08-01 07:45:23 -06:00
|
|
|
|
|
|
|
if (enable_fastdwarf)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < unit->actions.size(); i++)
|
|
|
|
{
|
|
|
|
df::unit_action *action = unit->actions[i];
|
|
|
|
switch (action->type)
|
|
|
|
{
|
2018-04-06 00:18:15 -06:00
|
|
|
case unit_action_type::None:
|
|
|
|
break;
|
2014-08-01 07:45:23 -06:00
|
|
|
case unit_action_type::Move:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.move.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Attack:
|
2014-09-27 18:47:27 -06:00
|
|
|
// Attacks are executed when timer1 reaches zero, which will be
|
|
|
|
// on the following tick.
|
2020-03-30 01:00:41 -06:00
|
|
|
if (action->data.attack.timer1 > 1)
|
|
|
|
action->data.attack.timer1 = 1;
|
2014-09-27 18:47:27 -06:00
|
|
|
// Attack actions are completed, and new ones generated, when
|
2014-11-25 10:30:25 -07:00
|
|
|
// timer2 reaches zero.
|
2020-03-30 01:00:41 -06:00
|
|
|
if (action->data.attack.timer2 > 1)
|
|
|
|
action->data.attack.timer2 = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
2014-11-25 10:30:25 -07:00
|
|
|
case unit_action_type::HoldTerrain:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.holdterrain.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Climb:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.climb.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Job:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.job.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
// could also patch the unit->job.current_job->completion_timer
|
|
|
|
break;
|
|
|
|
case unit_action_type::Talk:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.talk.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Unsteady:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.unsteady.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Dodge:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.dodge.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Recover:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.recover.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::StandUp:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.standup.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::LieDown:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.liedown.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::Job2:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.job2.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
// could also patch the unit->job.current_job->completion_timer
|
|
|
|
break;
|
|
|
|
case unit_action_type::PushObject:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.pushobject.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
|
|
|
case unit_action_type::SuckBlood:
|
2020-03-30 01:00:41 -06:00
|
|
|
action->data.suckblood.timer = 1;
|
2014-08-01 07:45:23 -06:00
|
|
|
break;
|
2018-04-06 00:18:15 -06:00
|
|
|
case unit_action_type::Jump:
|
|
|
|
case unit_action_type::ReleaseTerrain:
|
|
|
|
case unit_action_type::Parry:
|
|
|
|
case unit_action_type::Block:
|
|
|
|
case unit_action_type::HoldItem:
|
|
|
|
case unit_action_type::ReleaseItem:
|
2021-03-25 15:20:33 -06:00
|
|
|
default:
|
2018-04-06 00:18:15 -06:00
|
|
|
break;
|
2014-08-01 07:45:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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-17 06:57:14 -06:00
|
|
|
if (parameters.size() > 2)
|
|
|
|
return CR_WRONG_USAGE;
|
2012-10-04 19:14:50 -06:00
|
|
|
|
2012-10-17 06:57:14 -06:00
|
|
|
if ((parameters.size() == 1) || (parameters.size() == 2))
|
2012-10-04 19:14:50 -06:00
|
|
|
{
|
|
|
|
if (parameters.size() == 2)
|
|
|
|
{
|
|
|
|
if (parameters[1] == "0")
|
|
|
|
enable_teledwarf = false;
|
|
|
|
else if (parameters[1] == "1")
|
|
|
|
enable_teledwarf = true;
|
|
|
|
else
|
2012-10-17 06:57:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
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;
|
2014-08-01 07:45:23 -06:00
|
|
|
if (debug_turbospeed)
|
|
|
|
*debug_turbospeed = false;
|
2012-10-04 19:14:50 -06:00
|
|
|
}
|
|
|
|
else if (parameters[0] == "1")
|
|
|
|
{
|
2012-08-20 20:18:39 -06:00
|
|
|
enable_fastdwarf = true;
|
2014-08-01 07:45:23 -06:00
|
|
|
if (debug_turbospeed)
|
|
|
|
*debug_turbospeed = false;
|
2012-08-20 20:18:39 -06:00
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
else if (parameters[0] == "2")
|
|
|
|
{
|
2014-08-01 07:45:23 -06:00
|
|
|
if (debug_turbospeed)
|
2012-10-04 19:14:50 -06:00
|
|
|
{
|
|
|
|
enable_fastdwarf = false;
|
2014-08-01 07:45:23 -06:00
|
|
|
*debug_turbospeed = true;
|
2012-10-04 19:14:50 -06:00
|
|
|
}
|
|
|
|
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-17 06:57:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2011-10-27 22:22:07 -06:00
|
|
|
}
|
2012-10-04 19:14:50 -06:00
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
active = enable_fastdwarf || enable_teledwarf;
|
|
|
|
|
2012-10-04 19:14:50 -06:00
|
|
|
out.print("Current state: fast = %d, teleport = %d.\n",
|
2014-08-01 07:45:23 -06:00
|
|
|
(debug_turbospeed && *debug_turbospeed) ? 2 : (enable_fastdwarf ? 1 : 0),
|
2012-10-04 19:14:50 -06:00
|
|
|
enable_teledwarf ? 1 : 0);
|
2011-10-06 19:53:58 -06:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:19:51 -06:00
|
|
|
DFhackCExport command_result plugin_enable ( color_ostream &out, bool enable )
|
|
|
|
{
|
|
|
|
if (active != enable)
|
|
|
|
{
|
|
|
|
active = enable_fastdwarf = enable;
|
|
|
|
enable_teledwarf = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2022-07-25 11:22:23 -06:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"fastdwarf",
|
|
|
|
"Dwarves teleport and/or finish jobs instantly.",
|
|
|
|
fastdwarf));
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2011-10-06 19:53:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|