summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorPetr Mrázek2012-07-09 01:13:07 +0200
committerPetr Mrázek2012-07-09 01:13:07 +0200
commita5977db443aeaa3cf64ab341e254efdb05bd5519 (patch)
tree3ca401d05bb109a3c0b1ef721599007988b230b5 /library
parent6975f643fc4917b84e501189657bcbfaec3ca982 (diff)
parentc20951c30bd089da4a6d348265a851bc577e7fc3 (diff)
downloaddfhack-a5977db443aeaa3cf64ab341e254efdb05bd5519.tar.gz
dfhack-a5977db443aeaa3cf64ab341e254efdb05bd5519.tar.bz2
dfhack-a5977db443aeaa3cf64ab341e254efdb05bd5519.tar.xz
Merge https://github.com/jjyg/dfhack
Diffstat (limited to 'library')
-rw-r--r--library/Core.cpp16
-rw-r--r--library/PluginManager.cpp2
-rw-r--r--library/include/Core.h5
-rw-r--r--library/include/PluginManager.h4
-rw-r--r--library/lua/dfhack.lua2
-rw-r--r--library/lua/utils.lua12
-rw-r--r--library/modules/Materials.cpp6
7 files changed, 34 insertions, 13 deletions
diff --git a/library/Core.cpp b/library/Core.cpp
index 09344135..826576b7 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -281,7 +281,7 @@ static command_result runLuaScript(color_ostream &out, std::string name, vector<
return ok ? CR_OK : CR_FAILURE;
}
-static command_result runRubyScript(PluginManager *plug_mgr, std::string name, vector<string> &args)
+static command_result runRubyScript(color_ostream &out, PluginManager *plug_mgr, std::string name, vector<string> &args)
{
std::string rbcmd = "$script_args = [";
for (size_t i = 0; i < args.size(); i++)
@@ -290,7 +290,7 @@ static command_result runRubyScript(PluginManager *plug_mgr, std::string name, v
rbcmd += "load './hack/scripts/" + name + ".rb'";
- return plug_mgr->eval_ruby(rbcmd.c_str());
+ return plug_mgr->eval_ruby(out, rbcmd.c_str());
}
command_result Core::runCommand(color_ostream &out, const std::string &command)
@@ -632,7 +632,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
if (fileExists(filename + ".lua"))
res = runLuaScript(con, first, parts);
else if (plug_mgr->eval_ruby && fileExists(filename + ".rb"))
- res = runRubyScript(plug_mgr, first, parts);
+ res = runRubyScript(con, plug_mgr, first, parts);
else
con.printerr("%s is not a recognized command.\n", first.c_str());
}
@@ -752,6 +752,7 @@ Core::Core()
misc_data_mutex=0;
last_world_data_ptr = NULL;
last_local_map_ptr = NULL;
+ last_pause_state = false;
top_viewscreen = NULL;
screen_window = NULL;
server = NULL;
@@ -1116,6 +1117,15 @@ int Core::Update()
}
}
+ if (df::global::pause_state)
+ {
+ if (*df::global::pause_state != last_pause_state)
+ {
+ onStateChange(out, last_pause_state ? SC_UNPAUSED : SC_PAUSED);
+ last_pause_state = *df::global::pause_state;
+ }
+ }
+
// Execute per-frame handlers
onUpdate(out);
diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp
index a314883e..ff752431 100644
--- a/library/PluginManager.cpp
+++ b/library/PluginManager.cpp
@@ -188,7 +188,7 @@ bool Plugin::load(color_ostream &con)
plugin_shutdown = (command_result (*)(color_ostream &)) LookupPlugin(plug, "plugin_shutdown");
plugin_onstatechange = (command_result (*)(color_ostream &, state_change_event)) LookupPlugin(plug, "plugin_onstatechange");
plugin_rpcconnect = (RPCService* (*)(color_ostream &)) LookupPlugin(plug, "plugin_rpcconnect");
- plugin_eval_ruby = (command_result (*)(const char*)) LookupPlugin(plug, "plugin_eval_ruby");
+ plugin_eval_ruby = (command_result (*)(color_ostream &, const char*)) LookupPlugin(plug, "plugin_eval_ruby");
index_lua(plug);
this->name = *plug_name;
plugin_lib = plug;
diff --git a/library/include/Core.h b/library/include/Core.h
index 653298d8..d25beef5 100644
--- a/library/include/Core.h
+++ b/library/include/Core.h
@@ -75,7 +75,9 @@ namespace DFHack
SC_MAP_UNLOADED = 3,
SC_VIEWSCREEN_CHANGED = 4,
SC_CORE_INITIALIZED = 5,
- SC_BEGIN_UNLOAD = 6
+ SC_BEGIN_UNLOAD = 6,
+ SC_PAUSED = 7,
+ SC_UNPAUSED = 8
};
// Core is a singleton. Why? Because it is closely tied to SDL calls. It tracks the global state of DF.
@@ -228,6 +230,7 @@ namespace DFHack
// for state change tracking
void *last_local_map_ptr;
df::viewscreen *top_viewscreen;
+ bool last_pause_state;
// Very important!
bool started;
diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h
index 5da9fc92..22171a15 100644
--- a/library/include/PluginManager.h
+++ b/library/include/PluginManager.h
@@ -209,7 +209,7 @@ namespace DFHack
command_result (*plugin_onupdate)(color_ostream &);
command_result (*plugin_onstatechange)(color_ostream &, state_change_event);
RPCService* (*plugin_rpcconnect)(color_ostream &);
- command_result (*plugin_eval_ruby)(const char*);
+ command_result (*plugin_eval_ruby)(color_ostream &, const char*);
};
class DFHACK_EXPORT PluginManager
{
@@ -238,7 +238,7 @@ namespace DFHack
{
return all_plugins.size();
}
- command_result (*eval_ruby)(const char*);
+ command_result (*eval_ruby)(color_ostream &, const char*);
// DATA
private:
tthread::mutex * cmdlist_mutex;
diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua
index d56d4df6..86ea1459 100644
--- a/library/lua/dfhack.lua
+++ b/library/lua/dfhack.lua
@@ -39,6 +39,8 @@ if dfhack.is_core_context then
SC_MAP_UNLOADED = 3
SC_VIEWSCREEN_CHANGED = 4
SC_CORE_INITIALIZED = 5
+ SC_PAUSED = 7
+ SC_UNPAUSED = 8
end
-- Error handling
diff --git a/library/lua/utils.lua b/library/lua/utils.lua
index f303091d..38a1e6c4 100644
--- a/library/lua/utils.lua
+++ b/library/lua/utils.lua
@@ -57,10 +57,10 @@ function is_container(obj)
end
-- Make a sequence of numbers in 1..size
-function make_index_sequence(size)
+function make_index_sequence(istart,iend)
local index = {}
- for i=1,size do
- index[i] = i
+ for i=istart,iend do
+ index[i-istart+1] = i
end
return index
end
@@ -114,7 +114,7 @@ function make_sort_order(data,ordering)
end
-- Make an order table
- local index = make_index_sequence(size)
+ local index = make_index_sequence(1,size)
-- Sort the ordering table
table.sort(index, function(ia,ib)
@@ -379,7 +379,7 @@ function prompt_yes_no(msg,default)
elseif string.match(rv,'^[Nn]') then
return false
elseif rv == 'abort' then
- qerror('User abort in utils.prompt_yes_no()')
+ qerror('User abort')
elseif rv == '' and default ~= nil then
return default
end
@@ -393,7 +393,7 @@ function prompt_input(prompt,check,quit_str)
while true do
local rv = dfhack.lineedit(prompt)
if rv == quit_str then
- return nil
+ qerror('User abort')
end
local rtbl = table.pack(check(rv))
if rtbl[1] then
diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp
index f8f99f81..50cf21a9 100644
--- a/library/modules/Materials.cpp
+++ b/library/modules/Materials.cpp
@@ -293,6 +293,12 @@ std::string MaterialInfo::getToken()
switch (mode) {
case Builtin:
+ if (material->id == "COAL") {
+ if (index == 0)
+ return "COAL:COKE";
+ else if (index == 1)
+ return "COAL:CHARCOAL";
+ }
return material->id;
case Inorganic:
return "INORGANIC:" + inorganic->id;