From 6be752454d637e3076f9428e9f39055c2de654c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 02:16:08 +0200 Subject: [PATCH 1/7] Check zone plugin parameters better --- plugins/zone.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index ce610128b..9bd0e8c03 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -1856,14 +1856,18 @@ command_result df_zone (color_ostream &out, vector & parameters) // if followed by another parameter, check if it's numeric if(i < parameters.size()-1) { - stringstream ss(parameters[i+1]); - int new_building = -1; - ss >> new_building; - if(new_building != -1) + auto & str = parameters[i+1]; + if(str.size() > 0 && str[0] >= '0' && str[0] <= '9') { - i++; - target_building = new_building; - out << "Assign selected unit(s) to building #" << target_building <> new_building; + if(new_building != -1) + { + i++; + target_building = new_building; + out << "Assign selected unit(s) to building #" << target_building < Date: Thu, 12 Jul 2012 02:17:01 +0200 Subject: [PATCH 2/7] Eliminate magic numbers from the fixnaked script. --- scripts/devel/fixnaked.lua | 79 +++++++++++++++----------------------- 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/scripts/devel/fixnaked.lua b/scripts/devel/fixnaked.lua index 0f0a4507d..5bb113347 100644 --- a/scripts/devel/fixnaked.lua +++ b/scripts/devel/fixnaked.lua @@ -1,58 +1,41 @@ function fixnaked() local total_fixed = 0 -local total_uncovered = 0 -local total_noshirt = 0 -local total_noshoes = 0 +local total_removed = 0 for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do if fnUnit.race == df.global.ui.race_id then - local listEvents = fnUnit.status.recent_events - --for lkey,lvalue in pairs(listEvents) do - -- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity) - --end + local listEvents = fnUnit.status.recent_events + --for lkey,lvalue in pairs(listEvents) do + -- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity) + --end - local found = 1 - local fixed = 0 - while found == 1 do - local events = fnUnit.status.recent_events - found = 0 - for k,v in pairs(events) do - if v.type == 109 then - events:erase(k) - found = 1 - total_uncovered = total_uncovered + 1 - fixed = 1 - break - end - if v.type == 110 then - events:erase(k) - found = 1 - total_noshirt = total_noshirt + 1 - fixed = 1 - break - end - if v.type == 111 then - events:erase(k) - found = 1 - total_noshoes = total_noshoes + 1 - fixed = 1 - break - end - end - end - if fixed == 1 then - total_fixed = total_fixed + 1 - print(total_fixed, total_uncovered+total_noshirt+total_noshoes,dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit))) - end - end + local found = 1 + local fixed = 0 + while found == 1 do + local events = fnUnit.status.recent_events + found = 0 + for k,v in pairs(events) do + if v.type == df.unit_thought_type.Uncovered + or v.type == df.unit_thought_type.NoShirt + or v.type == df.unit_thought_type.NoShoes + or v.type == df.unit_thought_type.NoCloak + or v.type == df.unit_thought_type.OldClothing + or v.type == df.unit_thought_type.TatteredClothing + or v.type == df.unit_thought_type.RottedClothing then + events:erase(k) + found = 1 + total_removed = total_removed + 1 + fixed = 1 + break + end + end + end + if fixed == 1 then + total_fixed = total_fixed + 1 + print(total_fixed, total_removed, dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit))) + end + end end -print("thought 109 = "..df.unit_thought_type[109]) -print("thought 110 = "..df.unit_thought_type[110]) -print("thought 111 = "..df.unit_thought_type[111]) print("Total Fixed: "..total_fixed) -print("Total thoughts removed: "..total_uncovered) -print("Total thoughts removed: "..total_noshirt) -print("Total thoughts removed: "..total_noshoes) - end fixnaked() From 1c9194d1c46cdbb2d91dc1f540f51e8266d3c117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 02:24:32 +0200 Subject: [PATCH 3/7] While installing scripts, do not copy ~ files. --- scripts/devel/fixnaked.lua => fixnaked.lua | 0 library/CMakeLists.txt | 5 ++++- 2 files changed, 4 insertions(+), 1 deletion(-) rename scripts/devel/fixnaked.lua => fixnaked.lua (100%) diff --git a/scripts/devel/fixnaked.lua b/fixnaked.lua similarity index 100% rename from scripts/devel/fixnaked.lua rename to fixnaked.lua diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 75485ff22..bbf22611b 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -330,7 +330,10 @@ install(DIRECTORY lua/ FILES_MATCHING PATTERN "*.lua") install(DIRECTORY ${dfhack_SOURCE_DIR}/scripts - DESTINATION ${DFHACK_DATA_DESTINATION}) + DESTINATION ${DFHACK_DATA_DESTINATION} + FILES_MATCHING PATTERN "*.lua" + PATTERN "*.rb" + ) # Unused for so long that it's not even relevant now... if(BUILD_DEVEL) From f0393a62f5f60f539c84650e4f9ae1fce2ab50a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 02:27:10 +0200 Subject: [PATCH 4/7] Move fixnaked to the proper place --- fixnaked.lua | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 fixnaked.lua diff --git a/fixnaked.lua b/fixnaked.lua deleted file mode 100644 index 5bb113347..000000000 --- a/fixnaked.lua +++ /dev/null @@ -1,41 +0,0 @@ -function fixnaked() -local total_fixed = 0 -local total_removed = 0 - -for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do - if fnUnit.race == df.global.ui.race_id then - local listEvents = fnUnit.status.recent_events - --for lkey,lvalue in pairs(listEvents) do - -- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity) - --end - - local found = 1 - local fixed = 0 - while found == 1 do - local events = fnUnit.status.recent_events - found = 0 - for k,v in pairs(events) do - if v.type == df.unit_thought_type.Uncovered - or v.type == df.unit_thought_type.NoShirt - or v.type == df.unit_thought_type.NoShoes - or v.type == df.unit_thought_type.NoCloak - or v.type == df.unit_thought_type.OldClothing - or v.type == df.unit_thought_type.TatteredClothing - or v.type == df.unit_thought_type.RottedClothing then - events:erase(k) - found = 1 - total_removed = total_removed + 1 - fixed = 1 - break - end - end - end - if fixed == 1 then - total_fixed = total_fixed + 1 - print(total_fixed, total_removed, dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit))) - end - end -end -print("Total Fixed: "..total_fixed) -end -fixnaked() From 493b059f4c1b8d86895972cb15d99680e8253e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 02:51:00 +0200 Subject: [PATCH 5/7] Reset terminal to sane state after exiting on linux - without clearing the scrollback. --- package/linux/dfhack | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package/linux/dfhack b/package/linux/dfhack index d8790eac1..ef708932f 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -14,8 +14,6 @@ # DF_GDB_OPTS: Options to pass to gdb, if it's being run # DF_VALGRIND_OPTS: Options to pass to valgrind, if it's being run # DF_HELGRIND_OPTS: Options to pass to helgrind, if it's being run -# DF_RESET_OPTS: Options to pass the reset command at the end of -# this script # DF_POST_CMD: Shell command to be run at very end of script DF_DIR=$(dirname "$0") @@ -68,7 +66,7 @@ case "$1" in esac # Reset terminal to sane state in case of a crash -# reset $DF_RESET_OPTS +printf '\033[3g\033[0m\033[?25h\033(B\017\033%%G' if [ -n "$DF_POST_CMD" ]; then eval $DF_POST_CMD From a4194cc5b965b87e47651002beacaa8aa592a754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 11:54:03 +0200 Subject: [PATCH 6/7] Even more derp. --- scripts/fixnaked.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/fixnaked.lua diff --git a/scripts/fixnaked.lua b/scripts/fixnaked.lua new file mode 100644 index 000000000..3f1ee6fdd --- /dev/null +++ b/scripts/fixnaked.lua @@ -0,0 +1,41 @@ +function fixnaked() +local total_fixed = 0 +local total_removed = 0 + +for fnUnitCount,fnUnit in ipairs(df.global.world.units.all) do + if fnUnit.race == df.global.ui.race_id then + local listEvents = fnUnit.status.recent_events + --for lkey,lvalue in pairs(listEvents) do + -- print(df.unit_thought_type[lvalue.type],lvalue.type,lvalue.age,lvalue.subtype,lvalue.severity) + --end + + local found = 1 + local fixed = 0 + while found == 1 do + local events = fnUnit.status.recent_events + found = 0 + for k,v in pairs(events) do + if v.type == df.unit_thought_type.Uncovered + or v.type == df.unit_thought_type.NoShirt + or v.type == df.unit_thought_type.NoShoes + or v.type == df.unit_thought_type.NoCloak + or v.type == df.unit_thought_type.OldClothing + or v.type == df.unit_thought_type.TatteredClothing + or v.type == df.unit_thought_type.RottedClothing then + events:erase(k) + found = 1 + total_removed = total_removed + 1 + fixed = 1 + break + end + end + end + if fixed == 1 then + total_fixed = total_fixed + 1 + print(total_fixed, total_removed, dfhack.TranslateName(dfhack.units.getVisibleName(fnUnit))) + end + end +end +print("Total Fixed: "..total_fixed) +end +fixnaked() From aee15db75fdb4cb812788e13db4c83da6672d951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 12 Jul 2012 13:00:01 +0200 Subject: [PATCH 7/7] Even better handling of terminal reset on linux --- package/linux/dfhack | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package/linux/dfhack b/package/linux/dfhack index ef708932f..cfb57153e 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -31,6 +31,9 @@ if [ -r "./$RC" ]; then . "./$RC" fi +# Save current terminal settings +old_tty_settings=$(stty -g) + # Now run export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"./stonesense/deplibs":"./hack" @@ -65,8 +68,9 @@ case "$1" in ;; esac -# Reset terminal to sane state in case of a crash -printf '\033[3g\033[0m\033[?25h\033(B\017\033%%G' +# Restore previous terminal settings +stty "$old_tty_settings" +echo -e "\n" if [ -n "$DF_POST_CMD" ]; then eval $DF_POST_CMD