summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-05-12 20:54:26 +0400
committerAlexander Gavrilov2012-05-12 20:54:26 +0400
commitc6b52067bd90a2f7832a94a74cfd0e4ec0a8641c (patch)
treeda5b1e17673f11fdf8c62bf7b674e925e114d83b
parent60bb486abac5d79f0fc9053739b6ec52dfa8519f (diff)
downloaddfhack-c6b52067bd90a2f7832a94a74cfd0e4ec0a8641c.tar.gz
dfhack-c6b52067bd90a2f7832a94a74cfd0e4ec0a8641c.tar.bz2
dfhack-c6b52067bd90a2f7832a94a74cfd0e4ec0a8641c.tar.xz
Request designation rescan in auto-growing burrows.
This improves performance of burrowed miners digging 1-wide tunnels.
-rw-r--r--LUA_API.rst2
-rw-r--r--Lua API.html2
-rw-r--r--library/include/DataFuncs.h17
-rw-r--r--library/include/LuaTools.h14
-rw-r--r--plugins/burrows.cpp19
5 files changed, 44 insertions, 10 deletions
diff --git a/LUA_API.rst b/LUA_API.rst
index 093dd943..d8d53a4d 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -1066,7 +1066,7 @@ Events:
Emitted when a burrow might have been renamed either through
the game UI, or ``renameBurrow()``.
-* ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype)``
+* ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)``
Emitted when a tile might have been dug out. Only tracked if the
auto-growing burrows feature is enabled.
diff --git a/Lua API.html b/Lua API.html
index b6242712..846299a3 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -1245,7 +1245,7 @@ module file is still necessary for <tt class="docutils literal">require</tt> to
<p>Emitted when a burrow might have been renamed either through
the game UI, or <tt class="docutils literal">renameBurrow()</tt>.</p>
</li>
-<li><p class="first"><tt class="docutils literal">onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype)</tt></p>
+<li><p class="first"><tt class="docutils literal">onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)</tt></p>
<p>Emitted when a tile might have been dug out. Only tracked if the
auto-growing burrows feature is enabled.</p>
</li>
diff --git a/library/include/DataFuncs.h b/library/include/DataFuncs.h
index 8b917ad7..aff04128 100644
--- a/library/include/DataFuncs.h
+++ b/library/include/DataFuncs.h
@@ -143,6 +143,23 @@ INSTANTIATE_WRAPPERS(4, (OSTREAM_ARG,A1,A2,A3,A4), (out,vA1,vA2,vA3,vA4),
INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5))
INSTANTIATE_WRAPPERS(5, (A1,A2,A3,A4,A5), (vA1,vA2,vA3,vA4,vA5),
LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3); LOAD_ARG(A4); LOAD_ARG(A5);)
+INSTANTIATE_WRAPPERS(5, (OSTREAM_ARG,A1,A2,A3,A4,A5), (out,vA1,vA2,vA3,vA4,vA5),
+ LOAD_OSTREAM(out); LOAD_ARG(A1); LOAD_ARG(A2);
+ LOAD_ARG(A3); LOAD_ARG(A4); LOAD_ARG(A5);)
+#undef FW_TARGS
+
+#define FW_TARGS class A1, class A2, class A3, class A4, class A5, class A6
+INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5,A6))
+INSTANTIATE_WRAPPERS(6, (A1,A2,A3,A4,A5,A6), (vA1,vA2,vA3,vA4,vA5,vA6),
+ LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3);
+ LOAD_ARG(A4); LOAD_ARG(A5); LOAD_ARG(A6);)
+INSTANTIATE_WRAPPERS(6, (OSTREAM_ARG,A1,A2,A3,A4,A5,A6), (out,vA1,vA2,vA3,vA4,vA5,vA6),
+ LOAD_OSTREAM(out); LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3);
+ LOAD_ARG(A4); LOAD_ARG(A5); LOAD_ARG(A6);)
+#undef FW_TARGS
+
+#define FW_TARGS class A1, class A2, class A3, class A4, class A5, class A6, class A7
+INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5,A6,A7))
#undef FW_TARGS
#undef FW_TARGSC
diff --git a/library/include/LuaTools.h b/library/include/LuaTools.h
index c3a7921c..a52db257 100644
--- a/library/include/LuaTools.h
+++ b/library/include/LuaTools.h
@@ -424,3 +424,17 @@ namespace DFHack {namespace Lua {
name##_event.invoke(out, 4); \
} \
}
+
+#define DEFINE_LUA_EVENT_5(name, handler, arg_type1, arg_type2, arg_type3, arg_type4, arg_type5) \
+ static DFHack::Lua::Notification name##_event(df::wrap_function(handler, true)); \
+ void name(color_ostream &out, arg_type1 arg1, arg_type2 arg2, arg_type3 arg3, arg_type4 arg4, arg_type5 arg5) { \
+ handler(out, arg1, arg2, arg3, arg4, arg5); \
+ if (auto state = name##_event.get_state()) { \
+ DFHack::Lua::Push(state, arg1); \
+ DFHack::Lua::Push(state, arg2); \
+ DFHack::Lua::Push(state, arg3); \
+ DFHack::Lua::Push(state, arg4); \
+ DFHack::Lua::Push(state, arg5); \
+ name##_event.invoke(out, 5); \
+ } \
+ }
diff --git a/plugins/burrows.cpp b/plugins/burrows.cpp
index a6df3524..9ff902c3 100644
--- a/plugins/burrows.cpp
+++ b/plugins/burrows.cpp
@@ -153,10 +153,10 @@ static int next_job_id_save = 0;
static std::map<int,DigJob> diggers;
static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos,
- df::tiletype old_tile, df::tiletype new_tile);
+ df::tiletype old_tile, df::tiletype new_tile, df::unit *worker);
-DEFINE_LUA_EVENT_4(onDigComplete, handle_dig_complete,
- df::job_type, df::coord, df::tiletype, df::tiletype);
+DEFINE_LUA_EVENT_5(onDigComplete, handle_dig_complete,
+ df::job_type, df::coord, df::tiletype, df::tiletype, df::unit*);
static void detect_digging(color_ostream &out)
{
@@ -179,10 +179,7 @@ static void detect_digging(color_ostream &out)
if (new_tile != it->second.old_tile)
{
- onDigComplete(out, it->second.job, pos, it->second.old_tile, new_tile);
-
- //if (worker && !worker->job.current_job)
- // worker->counters.think_counter = worker->counters.job_counter = 0;
+ onDigComplete(out, it->second.job, pos, it->second.old_tile, new_tile, worker);
}
}
@@ -370,7 +367,7 @@ static void add_walls_to_burrows(color_ostream &out, std::vector<df::burrow*> &b
}
static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos,
- df::tiletype old_tile, df::tiletype new_tile)
+ df::tiletype old_tile, df::tiletype new_tile, df::unit *worker)
{
if (!isWalkable(new_tile))
return;
@@ -390,9 +387,11 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
return;
MapExtras::MapCache mc;
+ bool changed = false;
if (!isWalkable(old_tile))
{
+ changed = true;
add_walls_to_burrows(out, to_grow, mc, pos+df::coord(-1,-1,0), pos+df::coord(1,1,0));
if (isWalkableUp(new_tile))
@@ -407,6 +406,7 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
if (LowPassable(new_tile) && !LowPassable(old_tile))
{
+ changed = true;
add_to_burrows(to_grow, pos-df::coord(0,0,1));
if (tileShape(new_tile) == tiletype_shape::RAMP_TOP)
@@ -415,6 +415,9 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
pos+df::coord(-1,-1,-1), pos+df::coord(1,1,-1));
}
}
+
+ if (changed && worker && !worker->job.current_job)
+ Job::checkDesignationsNow();
}
static void renameBurrow(color_ostream &out, df::burrow *burrow, std::string name)