Update fastdwarf to work properly in 0.40

develop
Quietust 2014-08-01 08:45:23 -05:00
parent 612bcc65c8
commit 2928f15629
2 changed files with 75 additions and 24 deletions

@ -1 +1 @@
Subproject commit 1d8e0709572b2adb69ee99025b6c227d687773c9 Subproject commit 60ae817c40fb366460412b6b659bb1228836f8bf

@ -8,13 +8,17 @@
#include "DataDefs.h" #include "DataDefs.h"
#include "df/world.h" #include "df/world.h"
#include "df/unit.h" #include "df/unit.h"
#include "df/unit_action.h"
#include "df/map_block.h" #include "df/map_block.h"
using std::string; using std::string;
using std::vector; using std::vector;
using namespace DFHack; using namespace DFHack;
using namespace df::enums;
using df::global::world; using df::global::world;
using df::global::debug_turbospeed;
// dfhack interface // dfhack interface
DFHACK_PLUGIN("fastdwarf"); DFHACK_PLUGIN("fastdwarf");
@ -26,8 +30,8 @@ static bool enable_teledwarf = false;
DFhackCExport command_result plugin_shutdown ( color_ostream &out ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
if (df::global::debug_turbospeed) if (debug_turbospeed)
*df::global::debug_turbospeed = false; *debug_turbospeed = false;
return CR_OK; return CR_OK;
} }
@ -51,22 +55,8 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
if (!Units::isCitizen(unit)) if (!Units::isCitizen(unit))
continue; continue;
if (enable_fastdwarf && !enable_teledwarf )
{
if (unit->counters.job_counter > 0)
unit->counters.job_counter = 0;
// could also patch the unit->job.current_job->completion_timer
}
if (enable_teledwarf) do if (enable_teledwarf) do
{ {
// don't do anything if the dwarf isn't going anywhere
if (!unit->pos.isValid() || !unit->path.dest.isValid() || unit->pos == unit->path.dest) {
if ( enable_fastdwarf && unit->counters.job_counter > 0 )
unit->counters.job_counter = 0;
break;
}
// skip dwarves that are dragging creatures or being dragged // skip dwarves that are dragging creatures or being dragged
if ((unit->relations.draggee_id != -1) || (unit->relations.dragger_id != -1)) if ((unit->relations.draggee_id != -1) || (unit->relations.dragger_id != -1))
break; break;
@ -79,6 +69,11 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
if (unit->counters.unconscious > 0) if (unit->counters.unconscious > 0)
break; break;
// 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;
}
// make sure source and dest map blocks are valid // make sure source and dest map blocks are valid
auto old_occ = Maps::getTileOccupancy(unit->pos); auto old_occ = Maps::getTileOccupancy(unit->pos);
auto new_occ = Maps::getTileOccupancy(unit->path.dest); auto new_occ = Maps::getTileOccupancy(unit->path.dest);
@ -106,6 +101,62 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
unit->pos = unit->path.dest; unit->pos = unit->path.dest;
unit->path.path.clear(); unit->path.path.clear();
} while (0); } while (0);
if (enable_fastdwarf)
{
for (size_t i = 0; i < unit->actions.size(); i++)
{
df::unit_action *action = unit->actions[i];
switch (action->type)
{
case unit_action_type::Move:
action->data.move.timer = 1;
break;
case unit_action_type::Attack:
action->data.attack.timer1 = 1;
action->data.attack.timer2 = 1;
break;
case unit_action_type::Hold:
action->data.hold.timer = 1;
break;
case unit_action_type::Climb:
action->data.climb.timer = 1;
break;
case unit_action_type::Job:
action->data.job.timer = 1;
// could also patch the unit->job.current_job->completion_timer
break;
case unit_action_type::Talk:
action->data.talk.timer = 1;
break;
case unit_action_type::Unsteady:
action->data.unsteady.timer = 1;
break;
case unit_action_type::Dodge:
action->data.dodge.timer = 1;
break;
case unit_action_type::Recover:
action->data.recover.timer = 1;
break;
case unit_action_type::StandUp:
action->data.standup.timer = 1;
break;
case unit_action_type::LieDown:
action->data.liedown.timer = 1;
break;
case unit_action_type::Job2:
action->data.job2.timer = 1;
// could also patch the unit->job.current_job->completion_timer
break;
case unit_action_type::PushObject:
action->data.pushobject.timer = 1;
break;
case unit_action_type::SuckBlood:
action->data.suckblood.timer = 1;
break;
}
}
}
} }
return CR_OK; return CR_OK;
} }
@ -131,21 +182,21 @@ static command_result fastdwarf (color_ostream &out, vector <string> & parameter
if (parameters[0] == "0") if (parameters[0] == "0")
{ {
enable_fastdwarf = false; enable_fastdwarf = false;
if (df::global::debug_turbospeed) if (debug_turbospeed)
*df::global::debug_turbospeed = false; *debug_turbospeed = false;
} }
else if (parameters[0] == "1") else if (parameters[0] == "1")
{ {
enable_fastdwarf = true; enable_fastdwarf = true;
if (df::global::debug_turbospeed) if (debug_turbospeed)
*df::global::debug_turbospeed = false; *debug_turbospeed = false;
} }
else if (parameters[0] == "2") else if (parameters[0] == "2")
{ {
if (df::global::debug_turbospeed) if (debug_turbospeed)
{ {
enable_fastdwarf = false; enable_fastdwarf = false;
*df::global::debug_turbospeed = true; *debug_turbospeed = true;
} }
else else
{ {
@ -160,7 +211,7 @@ static command_result fastdwarf (color_ostream &out, vector <string> & parameter
active = enable_fastdwarf || enable_teledwarf; active = enable_fastdwarf || enable_teledwarf;
out.print("Current state: fast = %d, teleport = %d.\n", out.print("Current state: fast = %d, teleport = %d.\n",
(df::global::debug_turbospeed && *df::global::debug_turbospeed) ? 2 : (enable_fastdwarf ? 1 : 0), (debug_turbospeed && *debug_turbospeed) ? 2 : (enable_fastdwarf ? 1 : 0),
enable_teledwarf ? 1 : 0); enable_teledwarf ? 1 : 0);
return CR_OK; return CR_OK;