From dfa3a520fd2e7243413d5dc38d253fd17e072c1e Mon Sep 17 00:00:00 2001
From: Kelly Martin
Date: Sun, 21 Oct 2012 16:34:13 -0500
Subject: [PATCH 01/55] sync structures
---
library/xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/xml b/library/xml
index b9b2e8c6d..e06438924 160000
--- a/library/xml
+++ b/library/xml
@@ -1 +1 @@
-Subproject commit b9b2e8c6d2141f13966ed965b3f3ffe924e527db
+Subproject commit e06438924929a8ecab751c0c233dad5767e91f7e
From dd89baf6f88b5e111dbe21b24a2f951f0799a5e2 Mon Sep 17 00:00:00 2001
From: jj
Date: Mon, 12 Nov 2012 19:18:03 +0100
Subject: [PATCH 02/55] add raw mmap/mprotect access
---
library/Process-darwin.cpp | 27 ++++++++++++++++++++++++-
library/Process-linux.cpp | 27 ++++++++++++++++++++++++-
library/Process-windows.cpp | 39 +++++++++++++++++++++++++++++++++++++
library/include/MemAccess.h | 21 ++++++++++++++++++++
4 files changed, 112 insertions(+), 2 deletions(-)
diff --git a/library/Process-darwin.cpp b/library/Process-darwin.cpp
index d081c8c5c..72311e83a 100644
--- a/library/Process-darwin.cpp
+++ b/library/Process-darwin.cpp
@@ -304,4 +304,29 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
result=mprotect((void *)range.start, (size_t)range.end-(size_t)range.start,protect);
return result==0;
-}
\ No newline at end of file
+}
+
+// returns -1 on error
+void* Process::memAlloc(const int length)
+{
+ return mmap(0, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
+}
+
+int Process::memDealloc(const void *ptr, const int length)
+{
+ return munmap(ptr, length);
+}
+
+int Process::memProtect(const void *ptr, const int length, const int prot)
+{
+ int prot_native = 0;
+
+ if (prot & Process::MemProt::READ)
+ prot_native |= PROT_READ;
+ if (prot & Process::MemProt::WRITE)
+ prot_native |= PROT_WRITE;
+ if (prot & Process::MemProt::EXEC)
+ prot_native |= PROT_EXEC;
+
+ return mprotect(ptr, length, prot_native);
+}
diff --git a/library/Process-linux.cpp b/library/Process-linux.cpp
index 046b7696d..c3995a2aa 100644
--- a/library/Process-linux.cpp
+++ b/library/Process-linux.cpp
@@ -235,4 +235,29 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
result=mprotect((void *)range.start, (size_t)range.end-(size_t)range.start,protect);
return result==0;
-}
\ No newline at end of file
+}
+
+// returns -1 on error
+void* Process::memAlloc(const int length)
+{
+ return mmap(0, length, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+}
+
+int Process::memDealloc(void *ptr, const int length)
+{
+ return munmap(ptr, length);
+}
+
+int Process::memProtect(void *ptr, const int length, const int prot)
+{
+ int prot_native = 0;
+
+ if (prot & Process::MemProt::READ)
+ prot_native |= PROT_READ;
+ if (prot & Process::MemProt::WRITE)
+ prot_native |= PROT_WRITE;
+ if (prot & Process::MemProt::EXEC)
+ prot_native |= PROT_EXEC;
+
+ return mprotect(ptr, length, prot_native);
+}
diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp
index 6f79236f9..cfa0b688d 100644
--- a/library/Process-windows.cpp
+++ b/library/Process-windows.cpp
@@ -473,3 +473,42 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
return result;
}
+
+void* Process::memAlloc(const int length)
+{
+ void *ret;
+ // returns 0 on error
+ ret = VirtualAlloc(0, length, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ if (!ret)
+ ret = (void*)-1;
+ return ret;
+}
+
+int Process::memDealloc(const void *ptr, const int length)
+{
+ // can only free the whole region at once
+ // vfree returns 0 on error
+ return !VirtualFree(ptr, 0, MEM_RELEASE)
+}
+
+int Process::memProtect(const void *ptr, const int length, const int prot)
+{
+ int prot_native = 0;
+ int old_prot = 0;
+
+ // only support a few constant combinations
+ if (prot == 0)
+ prot_native = PAGE_NOACCESS;
+ else if (prot == Process::MemProt::READ)
+ prot_native = PAGE_READONLY;
+ else if (prot == Process::MemProt::READ | Process::MemProt::WRITE)
+ prot_native = PAGE_READWRITE;
+ else if (prot == Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXECUTE)
+ prot_native = PAGE_EXECUTE_READWRITE;
+ else if (prot == Process::MemProt::READ | Process::MemProt::EXECUTE)
+ prot_native = PAGE_EXECUTE_READ;
+ else
+ return -1;
+
+ return !VirtualProtect(ptr, length, prot_native, &old_prot);
+}
diff --git a/library/include/MemAccess.h b/library/include/MemAccess.h
index 22f15eecf..31647a25e 100644
--- a/library/include/MemAccess.h
+++ b/library/include/MemAccess.h
@@ -291,6 +291,27 @@ namespace DFHack
/// write a possibly read-only memory area
bool patchMemory(void *target, const void* src, size_t count);
+
+ /// allocate new memory pages for code or stuff
+ /// returns -1 on error (0 is a valid address)
+ void* memAlloc(const int length);
+
+ /// free memory pages from memAlloc
+ /// should have length = alloced length for portability
+ /// returns 0 on success
+ int memDealloc(void *ptr, const int length);
+
+ /// change memory page permissions
+ /// prot is a bitwise OR of the MemProt enum
+ /// returns 0 on success
+ int memProtect(void *ptr, const int length, const int prot);
+
+ enum MemProt {
+ READ = 1,
+ WRITE = 2,
+ EXEC = 4
+ };
+
private:
VersionInfo * my_descriptor;
PlatformSpecific *d;
From 72912edf58ea562592f00c8bab308c13529427a2 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Fri, 16 Nov 2012 18:45:51 +0400
Subject: [PATCH 03/55] Ensure AddPersistentData won't create duplicate ids.
If anything messes around with the histfig vector between calls.
---
library/modules/World.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/library/modules/World.cpp b/library/modules/World.cpp
index f3283c3a3..9ae4266b2 100644
--- a/library/modules/World.cpp
+++ b/library/modules/World.cpp
@@ -197,11 +197,15 @@ PersistentDataItem World::AddPersistentData(const std::string &key)
std::vector &hfvec = df::historical_figure::get_vector();
df::historical_figure *hfig = new df::historical_figure();
- hfig->id = next_persistent_id--;
+ hfig->id = next_persistent_id;
hfig->name.has_name = true;
hfig->name.first_name = key;
memset(hfig->name.words, 0xFF, sizeof(hfig->name.words));
+ if (!hfvec.empty())
+ hfig->id = std::min(hfig->id, hfvec[0]->id-1);
+ next_persistent_id = hfig->id-1;
+
hfvec.insert(hfvec.begin(), hfig);
persistent_index.insert(T_persistent_item(key, -hfig->id));
From 423c1224248195fa22d72781b7b26fa84e9dd2c7 Mon Sep 17 00:00:00 2001
From: jj
Date: Fri, 16 Nov 2012 17:39:08 +0100
Subject: [PATCH 04/55] ruby: fix unit_find for advmode
---
plugins/ruby/unit.rb | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb
index 4fbf75d8d..4c638b1a9 100644
--- a/plugins/ruby/unit.rb
+++ b/plugins/ruby/unit.rb
@@ -21,7 +21,7 @@ module DFHack
when :SelectTrainer
v.trainer_unit[v.trainer_cursor]
end
- else
+ when :viewscreen_dwarfmodest
case ui.main.mode
when :ViewUnits
# nobody selected => idx == 0
@@ -33,6 +33,15 @@ module DFHack
else
ui.follow_unit_tg if ui.follow_unit != -1
end
+ when :viewscreen_dungeonmodest
+ case ui_advmode.menu
+ when :Default
+ world.units.active[0]
+ else
+ unit_find(cursor) # XXX
+ end
+ when :viewscreen_dungeon_monsterstatusst
+ curview.unit
end
elsif what.kind_of?(Integer)
# search by id
From 342badac982d63b3c600c5307624e3a4402a93f8 Mon Sep 17 00:00:00 2001
From: jj
Date: Fri, 16 Nov 2012 17:46:41 +0100
Subject: [PATCH 05/55] scripts/superdwarf: advmode support
---
NEWS | 1 +
scripts/superdwarf.rb | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 48aaf26a2..4ccb1d18d 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ DFHack future
- fastdwarf: new mode using debug flags, and some internal consistency fixes.
- added a small stand-alone utility for applying and removing binary patches.
- removebadthoughts: add --dry-run option
+ - superdwarf: work in adventure mode too
New scripts:
- binpatch: the same as the stand-alone binpatch.exe, but works at runtime.
- region-pops: displays animal populations of the region and allows tweaking them.
diff --git a/scripts/superdwarf.rb b/scripts/superdwarf.rb
index 7f5296b74..6277db97f 100644
--- a/scripts/superdwarf.rb
+++ b/scripts/superdwarf.rb
@@ -8,7 +8,12 @@ when 'add'
if u = df.unit_find
$superdwarf_ids |= [u.id]
- $superdwarf_onupdate ||= df.onupdate_register(1) {
+ if df.gamemode == :ADVENTURE
+ onupdate_delay = nil
+ else
+ onupdate_delay = 1
+ end
+ $superdwarf_onupdate ||= df.onupdate_register(onupdate_delay) {
if $superdwarf_ids.empty?
df.onupdate_unregister($superdwarf_onupdate)
$superdwarf_onupdate = nil
From 2401be1b3b4ed423542e232deeafa8406ffc79b8 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Fri, 16 Nov 2012 22:48:49 +0400
Subject: [PATCH 06/55] Add an api function to retrieve unit skill experience.
---
Lua API.html | 21 +++++++++++++++++++++
Lua API.rst | 4 ++++
library/LuaApi.cpp | 1 +
library/include/modules/Units.h | 2 ++
library/modules/Units.cpp | 18 ++++++++++++++++++
5 files changed, 46 insertions(+)
diff --git a/Lua API.html b/Lua API.html
index d2e0da1ef..04af5d672 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -1109,6 +1109,12 @@ above operations accordingly. If enabled, pauses and zooms to position.
dfhack.job.printItemDetails(jobitem,idx)
Prints info about the job item.
+dfhack.job.getGeneralRef(job, type)
+Searches for a general_ref with the given type.
+
+dfhack.job.getSpecificRef(job, type)
+Searches for a specific_ref with the given type.
+
dfhack.job.getHolder(job)
Returns the building holding the job.
@@ -1147,6 +1153,12 @@ the flags in the job item.
dfhack.units.getPosition(unit)
Returns true x,y,z of the unit, or nil if invalid; may be not equal to unit.pos if caged.
+dfhack.units.getGeneralRef(unit, type)
+Searches for a general_ref with the given type.
+
+dfhack.units.getSpecificRef(unit, type)
+Searches for a specific_ref with the given type.
+
dfhack.units.getContainer(unit)
Returns the container (cage) item or nil.
@@ -1209,6 +1221,9 @@ is true, subtracts the rust penalty.
dfhack.units.getEffectiveSkill(unit, skill)
Computes the effective rating for the given skill, taking into account exhaustion, pain etc.
+dfhack.units.getExperience(unit, skill[, total])
+Returns the experience value for the given skill. If total is true, adds experience implied by the current rating.
+
dfhack.units.computeMovementSpeed(unit)
Computes number of frames * 100 it takes the unit to move in its current state of mind and body.
@@ -1403,6 +1418,12 @@ burrows, or the presence of invaders.
+dfhack.buildings.getGeneralRef(building, type)
+Searches for a general_ref with the given type.
+
+dfhack.buildings.getSpecificRef(building, type)
+Searches for a specific_ref with the given type.
+
dfhack.buildings.setOwner(item,unit)
Replaces the owner of the building. If unit is nil, removes ownership.
Returns false in case of error.
diff --git a/Lua API.rst b/Lua API.rst
index 126bc7f9d..4087ff0aa 100644
--- a/Lua API.rst
+++ b/Lua API.rst
@@ -970,6 +970,10 @@ Units module
Computes the effective rating for the given skill, taking into account exhaustion, pain etc.
+* ``dfhack.units.getExperience(unit, skill[, total])``
+
+ Returns the experience value for the given skill. If ``total`` is true, adds experience implied by the current rating.
+
* ``dfhack.units.computeMovementSpeed(unit)``
Computes number of frames * 100 it takes the unit to move in its current state of mind and body.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index b186316a8..a4ebbea5b 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -1180,6 +1180,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, getAge),
WRAPM(Units, getNominalSkill),
WRAPM(Units, getEffectiveSkill),
+ WRAPM(Units, getExperience),
WRAPM(Units, computeMovementSpeed),
WRAPM(Units, getProfessionName),
WRAPM(Units, getCasteProfessionName),
diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h
index 93e11afb1..c2eb7ca18 100644
--- a/library/include/modules/Units.h
+++ b/library/include/modules/Units.h
@@ -238,6 +238,8 @@ DFHACK_EXPORT double getAge(df::unit *unit, bool true_age = false);
DFHACK_EXPORT int getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust = false);
DFHACK_EXPORT int getEffectiveSkill(df::unit *unit, df::job_skill skill_id);
+DFHACK_EXPORT int getExperience(df::unit *unit, df::job_skill skill_id, bool total = false);
+
DFHACK_EXPORT int computeMovementSpeed(df::unit *unit);
struct NoblePosition {
diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp
index ddbb8cb79..b19399c6c 100644
--- a/library/modules/Units.cpp
+++ b/library/modules/Units.cpp
@@ -909,6 +909,24 @@ int Units::getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust
return 0;
}
+int Units::getExperience(df::unit *unit, df::job_skill skill_id, bool total)
+{
+ CHECK_NULL_POINTER(unit);
+
+ if (!unit->status.current_soul)
+ return 0;
+
+ auto skill = binsearch_in_vector(unit->status.current_soul->skills, &df::unit_skill::id, skill_id);
+ if (!skill)
+ return 0;
+
+ int xp = skill->experience;
+ // exact formula used by the game:
+ if (total && skill->rating > 0)
+ xp += 500*skill->rating + 100*skill->rating*(skill->rating - 1)/2;
+ return xp;
+}
+
int Units::getEffectiveSkill(df::unit *unit, df::job_skill skill_id)
{
/*
From d506dd713717aedb4ef98a087834845c13ac92c7 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Fri, 16 Nov 2012 22:51:07 +0400
Subject: [PATCH 07/55] Add a tweak to speed up melee squad training.
---
NEWS | 2 +
dfhack.init-example | 3 +
library/xml | 2 +-
plugins/tweak.cpp | 189 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 195 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 48aaf26a2..39b4ccf02 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,8 @@ DFHack future
- fastdwarf: new mode using debug flags, and some internal consistency fixes.
- added a small stand-alone utility for applying and removing binary patches.
- removebadthoughts: add --dry-run option
+ New tweaks:
+ - tweak military-training: speed up melee squad training up to 10x (depends on unit count).
New scripts:
- binpatch: the same as the stand-alone binpatch.exe, but works at runtime.
- region-pops: displays animal populations of the region and allows tweaking them.
diff --git a/dfhack.init-example b/dfhack.init-example
index 885849c33..8fafa4cf4 100644
--- a/dfhack.init-example
+++ b/dfhack.init-example
@@ -133,6 +133,9 @@ tweak military-stable-assign
# in same list, color units already assigned to squads in brown & green
tweak military-color-assigned
+# remove inverse dependency of squad training speed on unit list size and use more sparring
+tweak military-training
+
#######################################################
# Apply binary patches at runtime #
# #
diff --git a/library/xml b/library/xml
index 327a9662b..9b4dc47a5 160000
--- a/library/xml
+++ b/library/xml
@@ -1 +1 @@
-Subproject commit 327a9662be81627ebcbb3aea11ffbca3e536b7ee
+Subproject commit 9b4dc47a54c8b15db2f30fbf926deb8c1bf992f6
diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp
index b4a435421..c2309a3ee 100644
--- a/plugins/tweak.cpp
+++ b/plugins/tweak.cpp
@@ -51,6 +51,12 @@
#include "df/squad_position.h"
#include "df/job.h"
#include "df/general_ref_building_holderst.h"
+#include "df/unit_health_info.h"
+#include "df/activity_entry.h"
+#include "df/activity_event_combat_trainingst.h"
+#include "df/activity_event_individual_skill_drillst.h"
+#include "df/activity_event_skill_demonstrationst.h"
+#include "df/activity_event_sparringst.h"
#include
@@ -128,6 +134,8 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector counters2.exhaustion <= 2000 && // actually 4000, but leave a gap
+ (unit->status2.able_grasp_impair > 0 || unit->status2.able_grasp == 0) &&
+ (!unit->health || (unit->health->flags.whole&0x7FF) == 0) &&
+ (!unit->job.current_job || unit->job.current_job != job_type::Rest);
+}
+
+struct military_training_ct_hook : df::activity_event_combat_trainingst {
+ typedef df::activity_event_combat_trainingst interpose_base;
+
+ DEFINE_VMETHOD_INTERPOSE(void, process, (df::unit *unit))
+ {
+ auto act = df::activity_entry::find(activity_id);
+ int cur_neid = act ? act->next_event_id : 0;
+ int cur_oc = organize_counter;
+
+ INTERPOSE_NEXT(process)(unit);
+
+ // Shorten the time it takes to organize stuff, so that in
+ // reality it remains the same instead of growing proportionally
+ // to the unit count.
+ if (organize_counter > cur_oc && organize_counter > 0)
+ organize_counter = adjust_unit_divisor(organize_counter);
+
+ if (act && act->next_event_id > cur_neid)
+ {
+ // New events were added. Check them.
+ for (size_t i = 0; i < act->events.size(); i++)
+ {
+ auto event = act->events[i];
+ if (event->flags.bits.dismissed || event->event_id < cur_neid)
+ continue;
+
+ if (auto sp = strict_virtual_cast(event))
+ {
+ // Sparring has a problem in that all of its participants decrement
+ // the countdown variable. Fix this by multiplying it by the member count.
+ sp->countdown = sp->countdown * sp->participants.hist_figure_ids.size();
+ }
+ else if (auto sd = strict_virtual_cast(event))
+ {
+ // Adjust initial counter values
+ sd->train_countdown = adjust_unit_divisor(sd->train_countdown);
+ sd->wait_countdown = adjust_unit_divisor(sd->wait_countdown);
+
+ // Check if the game selected the most skilled unit as the teacher
+ auto &units = sd->participants.participant_ids;
+ int maxv = -1, cur_xp = -1, minv = 0;
+ int best = -1;
+ size_t spar = 0;
+
+ for (size_t j = 0; j < units.size(); j++)
+ {
+ auto unit = df::unit::find(units[j]);
+ if (!unit) continue;
+ int xp = Units::getExperience(unit, sd->skill, true);
+ if (units[j] == sd->unit_id)
+ cur_xp = xp;
+ if (j == 0 || xp < minv)
+ minv = xp;
+ if (xp > maxv) {
+ maxv = xp;
+ best = j;
+ }
+ if (can_spar(unit))
+ spar++;
+ }
+
+ color_ostream_proxy out(Core::getInstance().getConsole());
+
+ // If the xp gap is low, sometimes replace with sparring
+ if ((maxv - minv) < 64*15 && spar == units.size() &&
+ random_int(20) >= 5 + (maxv-minv)/64)
+ {
+ out.print("Replacing demonstration with sparring.\n");
+
+ if (auto spar = df::allocate())
+ {
+ spar->event_id = sd->event_id;
+ spar->activity_id = sd->activity_id;
+ spar->parent_event_id = sd->parent_event_id;
+ spar->flags = sd->flags;
+ spar->participants = sd->participants;
+ spar->building_id = sd->building_id;
+ spar->countdown = 300*units.size();
+
+ delete sd;
+ act->events[i] = spar;
+
+ continue;
+ }
+ }
+
+ // If the teacher has less xp than somebody else, switch
+ if (best >= 0 && maxv > cur_xp)
+ {
+ out.print("Replacing teacher %d (%d xp) with %d (%d xp)\n",
+ sd->unit_id, cur_xp, units[best], maxv);
+
+ sd->hist_figure_id = sd->participants.hist_figure_ids[best];
+ sd->unit_id = units[best];
+ }
+ }
+ }
+ }
+ }
+};
+
+IMPLEMENT_VMETHOD_INTERPOSE(military_training_ct_hook, process);
+
+struct military_training_sd_hook : df::activity_event_skill_demonstrationst {
+ typedef df::activity_event_skill_demonstrationst interpose_base;
+
+ DEFINE_VMETHOD_INTERPOSE(void, process, (df::unit *unit))
+ {
+ int cur_oc = organize_counter;
+ int cur_tc = train_countdown;
+
+ INTERPOSE_NEXT(process)(unit);
+
+ // Shorten the counters if they changed
+ if (organize_counter > cur_oc && organize_counter > 0)
+ organize_counter = adjust_unit_divisor(organize_counter);
+ if (train_countdown > cur_tc)
+ train_countdown = adjust_unit_divisor(train_countdown);
+ }
+};
+
+IMPLEMENT_VMETHOD_INTERPOSE(military_training_sd_hook, process);
+
+static bool is_done(df::activity_event *event, df::unit *unit)
+{
+ return event->flags.bits.dismissed ||
+ binsearch_index(event->participants.participant_ids, unit->id) < 0;
+}
+
+struct military_training_sp_hook : df::activity_event_sparringst {
+ typedef df::activity_event_sparringst interpose_base;
+
+ DEFINE_VMETHOD_INTERPOSE(void, process, (df::unit *unit))
+ {
+ INTERPOSE_NEXT(process)(unit);
+
+ // Since there are no counters to fix, repeat the call
+ int cnt = (DF_GLOBAL_FIELD(ui, unit_action_divisor, 10)+5) / 10;
+ for (int i = 1; i < cnt && !is_done(this, unit); i++)
+ INTERPOSE_NEXT(process)(unit);
+ }
+};
+
+IMPLEMENT_VMETHOD_INTERPOSE(military_training_sp_hook, process);
+
+struct military_training_id_hook : df::activity_event_individual_skill_drillst {
+ typedef df::activity_event_individual_skill_drillst interpose_base;
+
+ DEFINE_VMETHOD_INTERPOSE(void, process, (df::unit *unit))
+ {
+ INTERPOSE_NEXT(process)(unit);
+
+ // Since there are no counters to fix, repeat the call
+ int cnt = (DF_GLOBAL_FIELD(ui, unit_action_divisor, 10)+5) / 10;
+ for (int i = 1; i < cnt && !is_done(this, unit); i++)
+ INTERPOSE_NEXT(process)(unit);
+ }
+};
+
+IMPLEMENT_VMETHOD_INTERPOSE(military_training_id_hook, process);
+
static void enable_hook(color_ostream &out, VMethodInterposeLinkBase &hook, vector ¶meters)
{
if (vector_get(parameters, 1) == "disable")
@@ -835,6 +1017,13 @@ static command_result tweak(color_ostream &out, vector ¶meters)
{
enable_hook(out, INTERPOSE_HOOK(military_assign_hook, render), parameters);
}
+ else if (cmd == "military-training")
+ {
+ enable_hook(out, INTERPOSE_HOOK(military_training_ct_hook, process), parameters);
+ enable_hook(out, INTERPOSE_HOOK(military_training_sd_hook, process), parameters);
+ enable_hook(out, INTERPOSE_HOOK(military_training_sp_hook, process), parameters);
+ enable_hook(out, INTERPOSE_HOOK(military_training_id_hook, process), parameters);
+ }
else
return CR_WRONG_USAGE;
From cbe37417518ac1757ca783c73863851c8e02ac5e Mon Sep 17 00:00:00 2001
From: Kelly Martin
Date: Fri, 16 Nov 2012 13:09:05 -0600
Subject: [PATCH 08/55] Check all depots for trader requested, not just the
last one.
---
plugins/autolabor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp
index 44984cfdb..909adc04f 100644
--- a/plugins/autolabor.cpp
+++ b/plugins/autolabor.cpp
@@ -964,7 +964,7 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
else if (building_type::TradeDepot == type)
{
df::building_tradedepotst* depot = (df::building_tradedepotst*) build;
- trader_requested = depot->trade_flags.bits.trader_requested;
+ trader_requested = trader_requested || depot->trade_flags.bits.trader_requested;
if (print_debug)
{
if (trader_requested)
From a6fba3daf24ce9633d9fccd985178a1d5780a64c Mon Sep 17 00:00:00 2001
From: Kelly Martin
Date: Fri, 16 Nov 2012 13:44:38 -0600
Subject: [PATCH 09/55] const void* -> void* in memDealloc and memProtect for
Windows too
---
library/Process-windows.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp
index cfa0b688d..ff180025e 100644
--- a/library/Process-windows.cpp
+++ b/library/Process-windows.cpp
@@ -484,14 +484,14 @@ void* Process::memAlloc(const int length)
return ret;
}
-int Process::memDealloc(const void *ptr, const int length)
+int Process::memDealloc(void *ptr, const int length)
{
// can only free the whole region at once
// vfree returns 0 on error
return !VirtualFree(ptr, 0, MEM_RELEASE)
}
-int Process::memProtect(const void *ptr, const int length, const int prot)
+int Process::memProtect(void *ptr, const int length, const int prot)
{
int prot_native = 0;
int old_prot = 0;
From 2b087a7081ab2eca6181a86a37e2f5b481815918 Mon Sep 17 00:00:00 2001
From: jj
Date: Fri, 16 Nov 2012 20:49:30 +0100
Subject: [PATCH 10/55] fix windows typos
---
library/Process-windows.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp
index cfa0b688d..fdef9e225 100644
--- a/library/Process-windows.cpp
+++ b/library/Process-windows.cpp
@@ -484,28 +484,28 @@ void* Process::memAlloc(const int length)
return ret;
}
-int Process::memDealloc(const void *ptr, const int length)
+int Process::memDealloc(void *ptr, const int length)
{
// can only free the whole region at once
// vfree returns 0 on error
- return !VirtualFree(ptr, 0, MEM_RELEASE)
+ return !VirtualFree(ptr, 0, MEM_RELEASE);
}
-int Process::memProtect(const void *ptr, const int length, const int prot)
+int Process::memProtect(void *ptr, const int length, const int prot)
{
int prot_native = 0;
- int old_prot = 0;
+ DWORD old_prot = 0;
// only support a few constant combinations
if (prot == 0)
prot_native = PAGE_NOACCESS;
else if (prot == Process::MemProt::READ)
prot_native = PAGE_READONLY;
- else if (prot == Process::MemProt::READ | Process::MemProt::WRITE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::WRITE))
prot_native = PAGE_READWRITE;
- else if (prot == Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXECUTE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXEC))
prot_native = PAGE_EXECUTE_READWRITE;
- else if (prot == Process::MemProt::READ | Process::MemProt::EXECUTE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::EXEC))
prot_native = PAGE_EXECUTE_READ;
else
return -1;
From 648abee28595f17b711e94f2a89e22fc65c70378 Mon Sep 17 00:00:00 2001
From: Kelly Martin
Date: Fri, 16 Nov 2012 13:50:38 -0600
Subject: [PATCH 11/55] EXECUTE -> EXEC and add parenthesis to make MSVC whine
less.
---
library/Process-windows.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp
index ff180025e..6846ccccf 100644
--- a/library/Process-windows.cpp
+++ b/library/Process-windows.cpp
@@ -488,7 +488,7 @@ int Process::memDealloc(void *ptr, const int length)
{
// can only free the whole region at once
// vfree returns 0 on error
- return !VirtualFree(ptr, 0, MEM_RELEASE)
+ return !VirtualFree(ptr, 0, MEM_RELEASE);
}
int Process::memProtect(void *ptr, const int length, const int prot)
@@ -501,11 +501,11 @@ int Process::memProtect(void *ptr, const int length, const int prot)
prot_native = PAGE_NOACCESS;
else if (prot == Process::MemProt::READ)
prot_native = PAGE_READONLY;
- else if (prot == Process::MemProt::READ | Process::MemProt::WRITE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::WRITE))
prot_native = PAGE_READWRITE;
- else if (prot == Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXECUTE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXEC))
prot_native = PAGE_EXECUTE_READWRITE;
- else if (prot == Process::MemProt::READ | Process::MemProt::EXECUTE)
+ else if (prot == (Process::MemProt::READ | Process::MemProt::EXEC))
prot_native = PAGE_EXECUTE_READ;
else
return -1;
From e2b9b703a07d88fcad9a8f4f61057a44f12644ba Mon Sep 17 00:00:00 2001
From: Quietust
Date: Fri, 16 Nov 2012 15:33:36 -0600
Subject: [PATCH 12/55] Get rid of tabs
---
CMakeLists.txt | 12 +-
library/CMakeLists.txt | 38 +-
library/Core.cpp | 8 +-
library/Hooks-windows.cpp | 66 +--
library/MacPool.mm | 14 +-
library/Process-darwin.cpp | 60 +--
library/include/Console.h | 14 +-
library/include/DataDefs.h | 2 +-
library/include/TileTypes.h | 2 +-
library/include/modules/Graphic.h | 90 ++--
library/modules/Graphic.cpp | 74 ++--
plugins/cleanowned.cpp | 2 +-
plugins/devel/memview.cpp | 240 +++++------
plugins/devel/nestboxes.cpp | 74 ++--
plugins/devel/rprobe.cpp | 24 +-
plugins/devel/stockcheck.cpp | 360 ++++++++--------
plugins/devel/stripcaged.cpp | 64 +--
plugins/dfstream.cpp | 2 +-
plugins/filltraffic.cpp | 2 +-
plugins/forceequip.cpp | 682 +++++++++++++++---------------
plugins/reactionhooks.cpp | 26 +-
plugins/workflow.cpp | 6 +-
plugins/zone.cpp | 164 +++----
23 files changed, 1013 insertions(+), 1013 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 41c38bd44..0165d9964 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,7 +121,7 @@ ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS)
ADD_DEFINITIONS(-DLUA_BUILD_AS_DLL)
if(APPLE)
- add_definitions(-D_DARWIN)
+ add_definitions(-D_DARWIN)
elseif(UNIX)
add_definitions(-D_LINUX)
elseif(WIN32)
@@ -181,11 +181,11 @@ endif()
# Packaging with CPack!
IF(UNIX)
- if(APPLE)
- SET(CPACK_GENERATOR "ZIP")
- else()
- SET(CPACK_GENERATOR "TGZ")
- endif()
+ if(APPLE)
+ SET(CPACK_GENERATOR "ZIP")
+ else()
+ SET(CPACK_GENERATOR "TGZ")
+ endif()
ELSEIF(WIN32)
SET(CPACK_GENERATOR "ZIP")
ENDIF()
diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt
index b141e9fa5..f67b6fe44 100644
--- a/library/CMakeLists.txt
+++ b/library/CMakeLists.txt
@@ -167,7 +167,7 @@ IF(UNIX)
IF(BUILD_EGGY)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY})
ELSEIF(APPLE)
- LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN})
+ LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN})
ELSE()
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX})
ENDIF()
@@ -235,7 +235,7 @@ ENDIF()
IF(UNIX)
SET(PROJECT_LIBS rt dl dfhack-md5 dfhack-tinyxml dfhack-tinythread)
IF(APPLE)
- SET(PROJECT_LIBS dl dfhack-md5 dfhack-tinyxml dfhack-tinythread)
+ SET(PROJECT_LIBS dl dfhack-md5 dfhack-tinyxml dfhack-tinythread)
ENDIF()
ELSE(WIN32)
#FIXME: do we really need psapi?
@@ -273,14 +273,14 @@ ENDIF()
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
IF(APPLE)
- SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
- SET(CXX_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/libstdc++.6.dylib)
- SET(ZIP_LIBRARY /usr/lib/libz.dylib)
- TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY})
- TARGET_LINK_LIBRARIES(dfhack ${CXX_LIBRARY})
- TARGET_LINK_LIBRARIES(dfhack ${ZIP_LIBRARY})
- SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0)
- SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
+ SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
+ SET(CXX_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/libstdc++.6.dylib)
+ SET(ZIP_LIBRARY /usr/lib/libz.dylib)
+ TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY})
+ TARGET_LINK_LIBRARIES(dfhack ${CXX_LIBRARY})
+ TARGET_LINK_LIBRARIES(dfhack ${ZIP_LIBRARY})
+ SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0)
+ SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
ENDIF()
TARGET_LINK_LIBRARIES(dfhack protobuf-lite clsocket lua ${PROJECT_LIBS})
@@ -290,20 +290,20 @@ TARGET_LINK_LIBRARIES(dfhack-client protobuf-lite clsocket)
TARGET_LINK_LIBRARIES(dfhack-run dfhack-client)
if(APPLE)
- add_custom_command(TARGET dfhack-run COMMAND ${dfhack_SOURCE_DIR}/package/darwin/fix-libs.sh WORKING_DIRECTORY ../ COMMENT "Fixing library dependencies...")
+ add_custom_command(TARGET dfhack-run COMMAND ${dfhack_SOURCE_DIR}/package/darwin/fix-libs.sh WORKING_DIRECTORY ../ COMMENT "Fixing library dependencies...")
endif()
IF(UNIX)
- if (APPLE)
- install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack
- DESTINATION .)
- install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack-run
- DESTINATION .)
+ if (APPLE)
+ install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack
+ DESTINATION .)
+ install(PROGRAMS ${dfhack_SOURCE_DIR}/package/darwin/dfhack-run
+ DESTINATION .)
else()
- # On linux, copy our version of the df launch script which sets LD_PRELOAD
- install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack
+ # On linux, copy our version of the df launch script which sets LD_PRELOAD
+ install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack
DESTINATION .)
- install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack-run
+ install(PROGRAMS ${dfhack_SOURCE_DIR}/package/linux/dfhack-run
DESTINATION .)
endif()
ELSE()
diff --git a/library/Core.cpp b/library/Core.cpp
index 26c0acbb0..fd96d5601 100644
--- a/library/Core.cpp
+++ b/library/Core.cpp
@@ -375,7 +375,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve
" reload PLUGIN|all - Reload a plugin or all loaded plugins.\n"
);
- con.print("\nDFHack version " DFHACK_VERSION ".\n");
+ con.print("\nDFHack version " DFHACK_VERSION ".\n");
}
else if (parts.size() == 1)
{
@@ -747,13 +747,13 @@ void fIOthread(void * iodata)
else if(ret)
{
// a proper, non-empty command was entered
- fprintf(stderr,"Adding command to history\n");
+ fprintf(stderr,"Adding command to history\n");
main_history.add(command);
- fprintf(stderr,"Saving history\n");
+ fprintf(stderr,"Saving history\n");
main_history.save("dfhack.history");
}
- fprintf(stderr,"Running command\n");
+ fprintf(stderr,"Running command\n");
auto rv = core->runCommand(con, command);
diff --git a/library/Hooks-windows.cpp b/library/Hooks-windows.cpp
index 1e6679855..c8bd22dda 100644
--- a/library/Hooks-windows.cpp
+++ b/library/Hooks-windows.cpp
@@ -271,39 +271,39 @@ DFhackCExport vPtr SDL_SetVideoMode(int width, int height, int bpp, uint32_t fla
static int (*_SDL_UpperBlit)(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect) = 0;
DFhackCExport int SDL_UpperBlit(DFHack::DFSDL_Surface* src, DFHack::DFSDL_Rect* srcrect, DFHack::DFSDL_Surface* dst, DFHack::DFSDL_Rect* dstrect)
{
- if ( dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 )
- {
- DFHack::Core & c = DFHack::Core::getInstance();
- DFHack::Graphic* g = c.getGraphic();
- DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h);
-
- if ( ov != NULL )
- {
- if ( ov->paintOver )
- {
- _SDL_UpperBlit(src, srcrect, dst, dstrect);
- }
-
- DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect;
- dstrect2->x = dstrect->x;
- dstrect2->y = dstrect->y;
- dstrect2->w = dstrect->w;
- dstrect2->h = dstrect->h;
-
- if ( ov->dstResize != NULL )
- {
- DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize;
- dstrect2->x += r->x;
- dstrect2->y += r->y;
- dstrect2->w += r->w;
- dstrect2->h += r->h;
- }
-
- int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2);
- delete dstrect2;
- return result;
- }
- }
+ if ( dstrect != NULL && dstrect->h != 0 && dstrect->w != 0 )
+ {
+ DFHack::Core & c = DFHack::Core::getInstance();
+ DFHack::Graphic* g = c.getGraphic();
+ DFHack::DFTileSurface* ov = g->Call(dstrect->x/dstrect->w, dstrect->y/dstrect->h);
+
+ if ( ov != NULL )
+ {
+ if ( ov->paintOver )
+ {
+ _SDL_UpperBlit(src, srcrect, dst, dstrect);
+ }
+
+ DFHack::DFSDL_Rect* dstrect2 = new DFHack::DFSDL_Rect;
+ dstrect2->x = dstrect->x;
+ dstrect2->y = dstrect->y;
+ dstrect2->w = dstrect->w;
+ dstrect2->h = dstrect->h;
+
+ if ( ov->dstResize != NULL )
+ {
+ DFHack::DFSDL_Rect* r = (DFHack::DFSDL_Rect*)ov->dstResize;
+ dstrect2->x += r->x;
+ dstrect2->y += r->y;
+ dstrect2->w += r->w;
+ dstrect2->h += r->h;
+ }
+
+ int result = _SDL_UpperBlit(ov->surface, ov->rect, dst, dstrect2);
+ delete dstrect2;
+ return result;
+ }
+ }
return _SDL_UpperBlit(src, srcrect, dst, dstrect);
}
diff --git a/library/MacPool.mm b/library/MacPool.mm
index 2453aca29..8f26543e9 100644
--- a/library/MacPool.mm
+++ b/library/MacPool.mm
@@ -9,14 +9,14 @@
NSAutoreleasePool *thePool;
int create_pool() {
- fprintf(stderr,"Creating autorelease pool\n");
- thePool = [[NSAutoreleasePool alloc] init];
- return 1;
+ fprintf(stderr,"Creating autorelease pool\n");
+ thePool = [[NSAutoreleasePool alloc] init];
+ return 1;
}
int destroy_pool() {
- fprintf(stderr,"Draining and releasing autorelease pool\n");
- [thePool drain];
- [thePool release];
- return 0;
+ fprintf(stderr,"Draining and releasing autorelease pool\n");
+ [thePool drain];
+ [thePool release];
+ return 0;
}
\ No newline at end of file
diff --git a/library/Process-darwin.cpp b/library/Process-darwin.cpp
index 72311e83a..2e2be277b 100644
--- a/library/Process-darwin.cpp
+++ b/library/Process-darwin.cpp
@@ -50,13 +50,13 @@ using namespace DFHack;
Process::Process(VersionInfoFactory * known_versions)
{
int target_result;
-
+
char path[1024];
char *real_path;
- uint32_t size = sizeof(path);
- if (_NSGetExecutablePath(path, &size) == 0) {
- real_path = realpath(path, NULL);
- }
+ uint32_t size = sizeof(path);
+ if (_NSGetExecutablePath(path, &size) == 0) {
+ real_path = realpath(path, NULL);
+ }
identified = false;
my_descriptor = 0;
@@ -166,29 +166,29 @@ void Process::getMemRanges( vector & ranges )
(vm_region_info_t)&info, &info_count, &object);
if (kr == KERN_SUCCESS) {
if (info.reserved==1) {
- address += vmsize;
- continue;
+ address += vmsize;
+ continue;
}
Dl_info dlinfo;
int dlcheck;
dlcheck = dladdr((const void*)address, &dlinfo);
if (dlcheck==0) {
- dlinfo.dli_fname = "";
+ dlinfo.dli_fname = "";
}
-
+
t_memrange temp;
- strncpy( temp.name, dlinfo.dli_fname, 1023 );
- temp.name[1023] = 0;
- temp.start = (void *) address;
- temp.end = (void *) (address+vmsize);
- temp.read = (info.protection & VM_PROT_READ);
- temp.write = (info.protection & VM_PROT_WRITE);
- temp.execute = (info.protection & VM_PROT_EXECUTE);
- temp.shared = info.shared;
- temp.valid = true;
- ranges.push_back(temp);
-
- fprintf(stderr,
+ strncpy( temp.name, dlinfo.dli_fname, 1023 );
+ temp.name[1023] = 0;
+ temp.start = (void *) address;
+ temp.end = (void *) (address+vmsize);
+ temp.read = (info.protection & VM_PROT_READ);
+ temp.write = (info.protection & VM_PROT_WRITE);
+ temp.execute = (info.protection & VM_PROT_EXECUTE);
+ temp.shared = info.shared;
+ temp.valid = true;
+ ranges.push_back(temp);
+
+ fprintf(stderr,
"%08x-%08x %8uK %c%c%c/%c%c%c %11s %6s %10s uwir=%hu sub=%u dlname: %s\n",
address, (address + vmsize), (vmsize >> 10),
(info.protection & VM_PROT_READ) ? 'r' : '-',
@@ -203,7 +203,7 @@ void Process::getMemRanges( vector & ranges )
info.user_wired_count,
info.reserved,
dlinfo.dli_fname);
-
+
address += vmsize;
} else if (kr != KERN_INVALID_ADDRESS) {
@@ -277,15 +277,15 @@ uint32_t Process::getTickCount()
string Process::getPath()
{
- char path[1024];
+ char path[1024];
char *real_path;
- uint32_t size = sizeof(path);
- if (_NSGetExecutablePath(path, &size) == 0) {
- real_path = realpath(path, NULL);
- }
- std::string path_string(real_path);
- int last_slash = path_string.find_last_of("/");
- std::string directory = path_string.substr(0,last_slash);
+ uint32_t size = sizeof(path);
+ if (_NSGetExecutablePath(path, &size) == 0) {
+ real_path = realpath(path, NULL);
+ }
+ std::string path_string(real_path);
+ int last_slash = path_string.find_last_of("/");
+ std::string directory = path_string.substr(0,last_slash);
return directory;
}
diff --git a/library/include/Console.h b/library/include/Console.h
index 8d848135a..2f2f68cfa 100644
--- a/library/include/Console.h
+++ b/library/include/Console.h
@@ -65,20 +65,20 @@ namespace DFHack
bool save (const char * filename)
{
std::ofstream outfile (filename);
- //fprintf(stderr,"Save: Initialized stream\n");
+ //fprintf(stderr,"Save: Initialized stream\n");
if(outfile.bad())
return false;
- //fprintf(stderr,"Save: Iterating...\n");
+ //fprintf(stderr,"Save: Iterating...\n");
for(auto iter = history.begin();iter < history.end(); iter++)
{
- //fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
+ //fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
outfile << *iter << std::endl;
- //fprintf(stderr,"Save: Flushing\n");
- outfile.flush();
+ //fprintf(stderr,"Save: Flushing\n");
+ outfile.flush();
}
- //fprintf(stderr,"Save: Closing\n");
+ //fprintf(stderr,"Save: Closing\n");
outfile.close();
- //fprintf(stderr,"Save: Done\n");
+ //fprintf(stderr,"Save: Done\n");
return true;
}
/// add a command to the history
diff --git a/library/include/DataDefs.h b/library/include/DataDefs.h
index 32ffabc32..3591be045 100644
--- a/library/include/DataDefs.h
+++ b/library/include/DataDefs.h
@@ -35,7 +35,7 @@ distribution.
// Stop some MS stupidity
#ifdef interface
- #undef interface
+ #undef interface
#endif
typedef struct lua_State lua_State;
diff --git a/library/include/TileTypes.h b/library/include/TileTypes.h
index 48c10146a..f46cf2f2c 100644
--- a/library/include/TileTypes.h
+++ b/library/include/TileTypes.h
@@ -41,7 +41,7 @@ namespace DFHack
struct
{
//Maybe should add 'up' and 'down' for Z-levels?
- unsigned char north,south,west,east;
+ unsigned char north,south,west,east;
};
inline TileDirection()
diff --git a/library/include/modules/Graphic.h b/library/include/modules/Graphic.h
index a4b2dad10..8ee9c33b0 100644
--- a/library/include/modules/Graphic.h
+++ b/library/include/modules/Graphic.h
@@ -36,55 +36,55 @@ distribution.
namespace DFHack
{
- // SDL stuff
- typedef signed short SINT16;
- typedef struct
- {
- int16_t x, y;
- uint16_t w, h;
- } DFSDL_Rect;
- typedef struct
- {
- uint32_t flags;
- void* format; // PixelFormat*
- int w, h;
- int pitch;
- void* pixels;
- void* userdata; // as far as i could see DF doesnt use this
- int locked;
- void* lock_data;
- DFSDL_Rect clip_rect;
- void* map;
- int refcount;
- } DFSDL_Surface;
+ // SDL stuff
+ typedef signed short SINT16;
+ typedef struct
+ {
+ int16_t x, y;
+ uint16_t w, h;
+ } DFSDL_Rect;
+ typedef struct
+ {
+ uint32_t flags;
+ void* format; // PixelFormat*
+ int w, h;
+ int pitch;
+ void* pixels;
+ void* userdata; // as far as i could see DF doesnt use this
+ int locked;
+ void* lock_data;
+ DFSDL_Rect clip_rect;
+ void* map;
+ int refcount;
+ } DFSDL_Surface;
- // =========
- struct DFTileSurface
- {
- bool paintOver; // draw over original tile?
- DFSDL_Surface* surface; // from where it should be drawn
- DFSDL_Rect* rect; // from which coords (NULL to draw whole surface)
- DFSDL_Rect* dstResize; // if not NULL dst rect will be resized (x/y/w/h will be added to original dst)
- };
+ // =========
+ struct DFTileSurface
+ {
+ bool paintOver; // draw over original tile?
+ DFSDL_Surface* surface; // from where it should be drawn
+ DFSDL_Rect* rect; // from which coords (NULL to draw whole surface)
+ DFSDL_Rect* dstResize; // if not NULL dst rect will be resized (x/y/w/h will be added to original dst)
+ };
- class DFHACK_EXPORT Graphic : public Module
- {
- public:
- Graphic();
- ~Graphic();
- bool Finish()
- {
- return true;
- }
- bool Register(DFTileSurface* (*func)(int,int));
- bool Unregister(DFTileSurface* (*func)(int,int));
- DFTileSurface* Call(int x, int y);
+ class DFHACK_EXPORT Graphic : public Module
+ {
+ public:
+ Graphic();
+ ~Graphic();
+ bool Finish()
+ {
+ return true;
+ }
+ bool Register(DFTileSurface* (*func)(int,int));
+ bool Unregister(DFTileSurface* (*func)(int,int));
+ DFTileSurface* Call(int x, int y);
- private:
- struct Private;
- Private *d;
- };
+ private:
+ struct Private;
+ Private *d;
+ };
}
diff --git a/library/modules/Graphic.cpp b/library/modules/Graphic.cpp
index 4188df2b8..e965bc7e1 100644
--- a/library/modules/Graphic.cpp
+++ b/library/modules/Graphic.cpp
@@ -48,63 +48,63 @@ Module* DFHack::createGraphic()
struct Graphic::Private
{
- bool Started;
- vector funcs;
+ bool Started;
+ vector funcs;
};
Graphic::Graphic()
{
- d = new Private;
+ d = new Private;
- d->Started = true;
+ d->Started = true;
}
Graphic::~Graphic()
{
- delete d;
+ delete d;
}
bool Graphic::Register(DFTileSurface* (*func)(int,int))
{
- d->funcs.push_back(func);
- return true;
+ d->funcs.push_back(func);
+ return true;
}
bool Graphic::Unregister(DFTileSurface* (*func)(int,int))
{
- if ( d->funcs.empty() ) return false;
-
- vector::iterator it = d->funcs.begin();
- while ( it != d->funcs.end() )
- {
- if ( *it == func )
- {
- d->funcs.erase(it);
- return true;
- }
- it++;
- }
-
- return false;
+ if ( d->funcs.empty() ) return false;
+
+ vector::iterator it = d->funcs.begin();
+ while ( it != d->funcs.end() )
+ {
+ if ( *it == func )
+ {
+ d->funcs.erase(it);
+ return true;
+ }
+ it++;
+ }
+
+ return false;
}
// This will return first DFTileSurface it can get (or NULL if theres none)
DFTileSurface* Graphic::Call(int x, int y)
{
- if ( d->funcs.empty() ) return NULL;
-
- DFTileSurface* temp = NULL;
-
- vector::iterator it = d->funcs.begin();
- while ( it != d->funcs.end() )
- {
- temp = (*it)(x,y);
- if ( temp != NULL )
- {
- return temp;
- }
- it++;
- }
-
- return NULL;
+ if ( d->funcs.empty() ) return NULL;
+
+ DFTileSurface* temp = NULL;
+
+ vector::iterator it = d->funcs.begin();
+ while ( it != d->funcs.end() )
+ {
+ temp = (*it)(x,y);
+ if ( temp != NULL )
+ {
+ return temp;
+ }
+ it++;
+ }
+
+ return NULL;
}
\ No newline at end of file
diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp
index cd01fd616..28314d3f0 100644
--- a/plugins/cleanowned.cpp
+++ b/plugins/cleanowned.cpp
@@ -117,7 +117,7 @@ command_result df_cleanowned (color_ostream &out, vector & parameters)
else if (item->flags.bits.on_ground)
{
df::item_type type = item->getType();
- if(type == item_type::MEAT ||
+ if(type == item_type::MEAT ||
type == item_type::FISH ||
type == item_type::VERMIN ||
type == item_type::PET ||
diff --git a/plugins/devel/memview.cpp b/plugins/devel/memview.cpp
index 29b8403f8..a43e6a7bf 100644
--- a/plugins/devel/memview.cpp
+++ b/plugins/devel/memview.cpp
@@ -17,16 +17,16 @@ static tthread::mutex* mymutex=0;
struct memory_data
{
- void * addr;
- size_t len;
- size_t refresh;
- int state;
- uint8_t *buf,*lbuf;
- vector ranges;
+ void * addr;
+ size_t len;
+ size_t refresh;
+ int state;
+ uint8_t *buf,*lbuf;
+ vector ranges;
}memdata;
enum HEXVIEW_STATES
{
- STATE_OFF,STATE_ON
+ STATE_OFF,STATE_ON
};
command_result memview (color_ostream &out, vector & parameters);
@@ -34,151 +34,151 @@ DFHACK_PLUGIN("memview");
DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands)
{
- commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview));
- memdata.state=STATE_OFF;
- mymutex=new tthread::mutex;
+ commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview));
+ memdata.state=STATE_OFF;
+ mymutex=new tthread::mutex;
return CR_OK;
}
size_t convert(const std::string& p,bool ishex=false)
{
- size_t ret;
- std::stringstream conv;
- if(ishex)
- conv<>ret;
- return ret;
+ size_t ret;
+ std::stringstream conv;
+ if(ishex)
+ conv<>ret;
+ return ret;
}
bool isAddr(uint32_t *trg,vector & ranges)
{
- if(trg[0]%4==0)
- for(size_t i=0;i & ranges)
{
const size_t page_size=16;
- for(size_t i=0;i31)&&(buf[j+i]<128)) //only printable ascii
- con.print("%c",buf[j+i]);
- else
- con.print(".");
- //con.print("\n");
- }
- con.print("\n");
+ }
+ if(lbuf[j+i]!=buf[j+i])
+ con.print("*%02X",buf[j+i]); //if modfied show a star
+ else
+ con.print(" %02X",buf[j+i]);
+ }
+ con.reset_color();
+ con.print(" | ");
+ for(size_t j=0;(j31)&&(buf[j+i]<128)) //only printable ascii
+ con.print("%c",buf[j+i]);
+ else
+ con.print(".");
+ //con.print("\n");
+ }
+ con.print("\n");
}
void Deinit()
{
- if(memdata.state==STATE_ON)
- {
- memdata.state=STATE_OFF;
- delete [] memdata.buf;
- delete [] memdata.lbuf;
- }
+ if(memdata.state==STATE_ON)
+ {
+ memdata.state=STATE_OFF;
+ delete [] memdata.buf;
+ delete [] memdata.lbuf;
+ }
}
DFhackCExport command_result plugin_onupdate (color_ostream &out)
{
- mymutex->lock();
- if(memdata.state==STATE_OFF)
- {
- mymutex->unlock();
- return CR_OK;
- }
- //Console &con=out;
- uint64_t time2 = GetTimeMs64();
- uint64_t delta = time2-timeLast;
+ mymutex->lock();
+ if(memdata.state==STATE_OFF)
+ {
+ mymutex->unlock();
+ return CR_OK;
+ }
+ //Console &con=out;
+ uint64_t time2 = GetTimeMs64();
+ uint64_t delta = time2-timeLast;
- if(memdata.refresh!=0)
- if(deltaunlock();
- return CR_OK;
- }
- timeLast = time2;
+ if(memdata.refresh!=0)
+ if(deltaunlock();
+ return CR_OK;
+ }
+ timeLast = time2;
- Core::getInstance().p->read(memdata.addr,memdata.len,memdata.buf);
- outputHex(memdata.buf,memdata.lbuf,memdata.len,(size_t)memdata.addr,out,memdata.ranges);
+ Core::getInstance().p->read(memdata.addr,memdata.len,memdata.buf);
+ outputHex(memdata.buf,memdata.lbuf,memdata.len,(size_t)memdata.addr,out,memdata.ranges);
memcpy(memdata.lbuf, memdata.buf, memdata.len);
- if(memdata.refresh==0)
- Deinit();
- mymutex->unlock();
- return CR_OK;
+ if(memdata.refresh==0)
+ Deinit();
+ mymutex->unlock();
+ return CR_OK;
}
command_result memview (color_ostream &out, vector & parameters)
{
- mymutex->lock();
- Core::getInstance().p->getMemRanges(memdata.ranges);
- memdata.addr=(void *)convert(parameters[0],true);
- if(memdata.addr==0)
- {
- Deinit();
- memdata.state=STATE_OFF;
- mymutex->unlock();
- return CR_OK;
- }
- else
- {
- Deinit();
- bool isValid=false;
- for(size_t i=0;iunlock();
- return CR_OK;
- }
- memdata.state=STATE_ON;
- }
- if(parameters.size()>1)
- memdata.len=convert(parameters[1]);
- else
- memdata.len=20*16;
+ mymutex->lock();
+ Core::getInstance().p->getMemRanges(memdata.ranges);
+ memdata.addr=(void *)convert(parameters[0],true);
+ if(memdata.addr==0)
+ {
+ Deinit();
+ memdata.state=STATE_OFF;
+ mymutex->unlock();
+ return CR_OK;
+ }
+ else
+ {
+ Deinit();
+ bool isValid=false;
+ for(size_t i=0;iunlock();
+ return CR_OK;
+ }
+ memdata.state=STATE_ON;
+ }
+ if(parameters.size()>1)
+ memdata.len=convert(parameters[1]);
+ else
+ memdata.len=20*16;
- if(parameters.size()>2)
- memdata.refresh=convert(parameters[2]);
- else
- memdata.refresh=0;
+ if(parameters.size()>2)
+ memdata.refresh=convert(parameters[2]);
+ else
+ memdata.refresh=0;
- memdata.buf=new uint8_t[memdata.len];
- memdata.lbuf=new uint8_t[memdata.len];
- Core::getInstance().p->getMemRanges(memdata.ranges);
- mymutex->unlock();
- return CR_OK;
+ memdata.buf=new uint8_t[memdata.len];
+ memdata.lbuf=new uint8_t[memdata.len];
+ Core::getInstance().p->getMemRanges(memdata.ranges);
+ mymutex->unlock();
+ return CR_OK;
}
DFhackCExport command_result plugin_shutdown (color_ostream &out)
{
- mymutex->lock();
- Deinit();
- delete mymutex;
- mymutex->unlock();
- return CR_OK;
+ mymutex->lock();
+ Deinit();
+ delete mymutex;
+ mymutex->unlock();
+ return CR_OK;
}
diff --git a/plugins/devel/nestboxes.cpp b/plugins/devel/nestboxes.cpp
index 42c3c0660..8c51b57ae 100644
--- a/plugins/devel/nestboxes.cpp
+++ b/plugins/devel/nestboxes.cpp
@@ -35,32 +35,32 @@ static bool enabled = false;
static void eggscan(color_ostream &out)
{
- CoreSuspender suspend;
-
- for (int i = 0; i < world->buildings.all.size(); ++i)
- {
- df::building *build = world->buildings.all[i];
- auto type = build->getType();
- if (df::enums::building_type::NestBox == type)
- {
+ CoreSuspender suspend;
+
+ for (int i = 0; i < world->buildings.all.size(); ++i)
+ {
+ df::building *build = world->buildings.all[i];
+ auto type = build->getType();
+ if (df::enums::building_type::NestBox == type)
+ {
bool fertile = false;
- df::building_nest_boxst *nb = virtual_cast(build);
- if (nb->claimed_by != -1)
+ df::building_nest_boxst *nb = virtual_cast(build);
+ if (nb->claimed_by != -1)
{
df::unit* u = df::unit::find(nb->claimed_by);
- if (u && u->relations.pregnancy_timer > 0)
+ if (u && u->relations.pregnancy_timer > 0)
fertile = true;
}
for (int j = 1; j < nb->contained_items.size(); j++)
{
df::item* item = nb->contained_items[j]->item;
- if (item->flags.bits.forbid != fertile)
- {
- item->flags.bits.forbid = fertile;
- out << item->getStackSize() << " eggs " << (fertile ? "forbidden" : "unforbidden.") << endl;
- }
+ if (item->flags.bits.forbid != fertile)
+ {
+ item->flags.bits.forbid = fertile;
+ out << item->getStackSize() << " eggs " << (fertile ? "forbidden" : "unforbidden.") << endl;
+ }
}
- }
+ }
}
}
@@ -68,12 +68,12 @@ static void eggscan(color_ostream &out)
DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands)
{
if (world && ui) {
- commands.push_back(
- PluginCommand("nestboxes", "Derp.",
- nestboxes, false,
- "Derp.\n"
- )
- );
+ commands.push_back(
+ PluginCommand("nestboxes", "Derp.",
+ nestboxes, false,
+ "Derp.\n"
+ )
+ );
}
return CR_OK;
}
@@ -92,28 +92,28 @@ DFhackCExport command_result plugin_onupdate(color_ostream &out)
if ((++cnt % 5) != 0)
return CR_OK;
- eggscan(out);
+ eggscan(out);
return CR_OK;
}
static command_result nestboxes(color_ostream &out, vector & parameters)
{
- CoreSuspender suspend;
- bool clean = false;
+ CoreSuspender suspend;
+ bool clean = false;
int dump_count = 0;
int good_egg = 0;
- if (parameters.size() == 1) {
- if (parameters[0] == "enable")
- enabled = true;
- else if (parameters[0] == "disable")
- enabled = false;
- else
- return CR_WRONG_USAGE;
- } else {
- out << "Plugin " << (enabled ? "enabled" : "disabled") << "." << endl;
- }
- return CR_OK;
+ if (parameters.size() == 1) {
+ if (parameters[0] == "enable")
+ enabled = true;
+ else if (parameters[0] == "disable")
+ enabled = false;
+ else
+ return CR_WRONG_USAGE;
+ } else {
+ out << "Plugin " << (enabled ? "enabled" : "disabled") << "." << endl;
+ }
+ return CR_OK;
}
diff --git a/plugins/devel/rprobe.cpp b/plugins/devel/rprobe.cpp
index 805489d5e..9591fa8f1 100644
--- a/plugins/devel/rprobe.cpp
+++ b/plugins/devel/rprobe.cpp
@@ -67,10 +67,10 @@ command_result rprobe (color_ostream &out, vector & parameters)
// Embark screen active: estimate using world geology data
VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen());
-
- if (!screen)
- return CR_WRONG_USAGE;
-
+
+ if (!screen)
+ return CR_WRONG_USAGE;
+
if (!world || !world->world_data)
{
out.printerr("World data is not available.\n");
@@ -78,9 +78,9 @@ command_result rprobe (color_ostream &out, vector & parameters)
}
- if (parameters.size() == 2)
+ if (parameters.size() == 2)
{
- if (parameters[0] == "rai")
+ if (parameters[0] == "rai")
set_field = 0;
else if (parameters[0] == "veg")
set_field = 1;
@@ -97,7 +97,7 @@ command_result rprobe (color_ostream &out, vector & parameters)
else
return CR_WRONG_USAGE;
- if (screen->biome_highlighted)
+ if (screen->biome_highlighted)
to_set = screen->biome_idx;
else
to_set = 0;
@@ -110,7 +110,7 @@ command_result rprobe (color_ostream &out, vector & parameters)
coord2d cur_region = screen->region_pos;
// Compute biomes
- for (int i = 0; i < screen->biome_rgn.size(); i++)
+ for (int i = 0; i < screen->biome_rgn.size(); i++)
{
coord2d rg = screen->biome_rgn[i];
@@ -140,7 +140,7 @@ command_result rprobe (color_ostream &out, vector & parameters)
" geo_index: " << rd->geo_index <<
" landmass_id: " << rd->landmass_id <<
" flags: " << hex << rd->flags.as_int() << dec << endl;
- out <<
+ out <<
"rai: " << rd->rainfall << " " <<
"veg: " << rd->vegetation << " " <<
"tem: " << rd->temperature << " " <<
@@ -148,17 +148,17 @@ command_result rprobe (color_ostream &out, vector & parameters)
"dra: " << rd->drainage << " " <<
"sav: " << rd->savagery << " " <<
"sal: " << rd->salinity;
-
+
int32_t *p = (int32_t *)rd;
int c = sizeof(*rd) / sizeof(int32_t);
for (int j = 0; j < c; j++) {
- if (j % 8 == 0)
+ if (j % 8 == 0)
out << endl << setfill('0') << setw(8) << hex << (int)(rd+j) << ": ";
out << " " << setfill('0') << setw(8) << hex << p[j];
}
out << setfill(' ') << setw(0) << dec << endl;
}
-
+
return CR_OK;
}
diff --git a/plugins/devel/stockcheck.cpp b/plugins/devel/stockcheck.cpp
index 57be4b126..666db0d79 100644
--- a/plugins/devel/stockcheck.cpp
+++ b/plugins/devel/stockcheck.cpp
@@ -38,12 +38,12 @@ DFHACK_PLUGIN("stockcheck");
DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands)
{
if (world && ui) {
- commands.push_back(
- PluginCommand("stockcheck", "Check for unprotected rottable items.",
- stockcheck, false,
- "Scan world for items that are susceptible to rot. Currently just lists the items.\n"
- )
- );
+ commands.push_back(
+ PluginCommand("stockcheck", "Check for unprotected rottable items.",
+ stockcheck, false,
+ "Scan world for items that are susceptible to rot. Currently just lists the items.\n"
+ )
+ );
}
return CR_OK;
}
@@ -54,90 +54,90 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
}
struct StockpileInfo {
- building_stockpilest* sp;
- int size;
- int free;
- int x1, x2, y1, y2, z;
+ building_stockpilest* sp;
+ int size;
+ int free;
+ int x1, x2, y1, y2, z;
public:
- StockpileInfo(building_stockpilest *sp_) : sp(sp_)
- {
- MapExtras::MapCache mc;
-
- z = sp_->z;
- x1 = sp_->room.x;
- x2 = sp_->room.x + sp_->room.width;
- y1 = sp_->room.y;
- y2 = sp_->room.y + sp_->room.height;
- int e = 0;
- size = 0;
- free = 0;
- for (int y = y1; y < y2; y++)
- for (int x = x1; x < x2; x++)
- if (sp_->room.extents[e++] == 1)
- {
- size++;
- DFCoord cursor (x,y,z);
- uint32_t blockX = x / 16;
- uint32_t tileX = x % 16;
- uint32_t blockY = y / 16;
- uint32_t tileY = y % 16;
- MapExtras::Block * b = mc.BlockAt(cursor/16);
- if(b && b->is_valid())
- {
- auto &block = *b->getRaw();
- df::tile_occupancy &occ = block.occupancy[tileX][tileY];
- if (!occ.bits.item)
- free++;
- }
- }
- }
-
- bool isFull() { return free == 0; }
-
- bool canHold(df::item *i)
- {
- return false;
- }
-
- bool inStockpile(df::item *i)
- {
- df::item *container = Items::getContainer(i);
- if (container)
- return inStockpile(container);
-
- if (i->pos.z != z) return false;
- if (i->pos.x < x1 || i->pos.x >= x2 ||
- i->pos.y < y1 || i->pos.y >= y2) return false;
- int e = (i->pos.x - x1) + (i->pos.y - y1) * sp->room.width;
- return sp->room.extents[e] == 1;
- }
-
- int getId() { return sp->id; }
+ StockpileInfo(building_stockpilest *sp_) : sp(sp_)
+ {
+ MapExtras::MapCache mc;
+
+ z = sp_->z;
+ x1 = sp_->room.x;
+ x2 = sp_->room.x + sp_->room.width;
+ y1 = sp_->room.y;
+ y2 = sp_->room.y + sp_->room.height;
+ int e = 0;
+ size = 0;
+ free = 0;
+ for (int y = y1; y < y2; y++)
+ for (int x = x1; x < x2; x++)
+ if (sp_->room.extents[e++] == 1)
+ {
+ size++;
+ DFCoord cursor (x,y,z);
+ uint32_t blockX = x / 16;
+ uint32_t tileX = x % 16;
+ uint32_t blockY = y / 16;
+ uint32_t tileY = y % 16;
+ MapExtras::Block * b = mc.BlockAt(cursor/16);
+ if(b && b->is_valid())
+ {
+ auto &block = *b->getRaw();
+ df::tile_occupancy &occ = block.occupancy[tileX][tileY];
+ if (!occ.bits.item)
+ free++;
+ }
+ }
+ }
+
+ bool isFull() { return free == 0; }
+
+ bool canHold(df::item *i)
+ {
+ return false;
+ }
+
+ bool inStockpile(df::item *i)
+ {
+ df::item *container = Items::getContainer(i);
+ if (container)
+ return inStockpile(container);
+
+ if (i->pos.z != z) return false;
+ if (i->pos.x < x1 || i->pos.x >= x2 ||
+ i->pos.y < y1 || i->pos.y >= y2) return false;
+ int e = (i->pos.x - x1) + (i->pos.y - y1) * sp->room.width;
+ return sp->room.extents[e] == 1;
+ }
+
+ int getId() { return sp->id; }
};
static command_result stockcheck(color_ostream &out, vector & parameters)
{
- CoreSuspender suspend;
-
- std::vector stockpiles;
-
- for (int i = 0; i < world->buildings.all.size(); ++i)
- {
- df::building *build = world->buildings.all[i];
- auto type = build->getType();
- if (df::enums::building_type::Stockpile == type)
- {
- building_stockpilest *sp = virtual_cast(build);
- StockpileInfo *spi = new StockpileInfo(sp);
- stockpiles.push_back(spi);
- }
-
- }
-
- std::vector &items = world->items.other[items_other_id::IN_PLAY];
-
- // Precompute a bitmask with the bad flags
+ CoreSuspender suspend;
+
+ std::vector stockpiles;
+
+ for (int i = 0; i < world->buildings.all.size(); ++i)
+ {
+ df::building *build = world->buildings.all[i];
+ auto type = build->getType();
+ if (df::enums::building_type::Stockpile == type)
+ {
+ building_stockpilest *sp = virtual_cast(build);
+ StockpileInfo *spi = new StockpileInfo(sp);
+ stockpiles.push_back(spi);
+ }
+
+ }
+
+ std::vector &items = world->items.other[items_other_id::IN_PLAY];
+
+ // Precompute a bitmask with the bad flags
df::item_flags bad_flags;
bad_flags.whole = 0;
@@ -145,30 +145,30 @@ static command_result stockcheck(color_ostream &out, vector & parameter
F(dump); F(forbid); F(garbage_collect);
F(hostile); F(on_fire); F(rotten); F(trader);
F(in_building); F(construction); F(artifact1);
- F(spider_web); F(owned); F(in_job);
+ F(spider_web); F(owned); F(in_job);
#undef F
for (size_t i = 0; i < items.size(); i++)
{
df::item *item = items[i];
- if (item->flags.whole & bad_flags.whole)
+ if (item->flags.whole & bad_flags.whole)
continue;
- // we really only care about MEAT, FISH, FISH_RAW, PLANT, CHEESE, FOOD, and EGG
+ // we really only care about MEAT, FISH, FISH_RAW, PLANT, CHEESE, FOOD, and EGG
- df::item_type typ = item->getType();
- if (typ != df::enums::item_type::MEAT &&
- typ != df::enums::item_type::FISH &&
- typ != df::enums::item_type::FISH_RAW &&
- typ != df::enums::item_type::PLANT &&
- typ != df::enums::item_type::CHEESE &&
- typ != df::enums::item_type::FOOD &&
- typ != df::enums::item_type::EGG)
- continue;
+ df::item_type typ = item->getType();
+ if (typ != df::enums::item_type::MEAT &&
+ typ != df::enums::item_type::FISH &&
+ typ != df::enums::item_type::FISH_RAW &&
+ typ != df::enums::item_type::PLANT &&
+ typ != df::enums::item_type::CHEESE &&
+ typ != df::enums::item_type::FOOD &&
+ typ != df::enums::item_type::EGG)
+ continue;
- df::item *container = 0;
- df::unit *holder = 0;
- df::building *building = 0;
+ df::item *container = 0;
+ df::unit *holder = 0;
+ df::building *building = 0;
for (size_t i = 0; i < item->general_refs.size(); i++)
{
@@ -177,106 +177,106 @@ static command_result stockcheck(color_ostream &out, vector & parameter
switch (ref->getType())
{
case general_ref_type::CONTAINED_IN_ITEM:
- container = ref->getItem();
+ container = ref->getItem();
break;
case general_ref_type::UNIT_HOLDER:
- holder = ref->getUnit();
+ holder = ref->getUnit();
break;
case general_ref_type::BUILDING_HOLDER:
- building = ref->getBuilding();
+ building = ref->getBuilding();
break;
default:
break;
- }
- }
+ }
+ }
- df::item *nextcontainer = container;
- df::item *lastcontainer = 0;
+ df::item *nextcontainer = container;
+ df::item *lastcontainer = 0;
- while(nextcontainer) {
- df::item *thiscontainer = nextcontainer;
- nextcontainer = 0;
- for (size_t i = 0; i < thiscontainer->general_refs.size(); i++)
- {
- df::general_ref *ref = thiscontainer->general_refs[i];
+ while(nextcontainer) {
+ df::item *thiscontainer = nextcontainer;
+ nextcontainer = 0;
+ for (size_t i = 0; i < thiscontainer->general_refs.size(); i++)
+ {
+ df::general_ref *ref = thiscontainer->general_refs[i];
- switch (ref->getType())
- {
- case general_ref_type::CONTAINED_IN_ITEM:
- lastcontainer = nextcontainer = ref->getItem();
- break;
+ switch (ref->getType())
+ {
+ case general_ref_type::CONTAINED_IN_ITEM:
+ lastcontainer = nextcontainer = ref->getItem();
+ break;
- case general_ref_type::UNIT_HOLDER:
- holder = ref->getUnit();
- break;
+ case general_ref_type::UNIT_HOLDER:
+ holder = ref->getUnit();
+ break;
- case general_ref_type::BUILDING_HOLDER:
- building = ref->getBuilding();
- break;
+ case general_ref_type::BUILDING_HOLDER:
+ building = ref->getBuilding();
+ break;
default:
break;
- }
- }
- }
-
- if (holder)
- continue; // carried items do not rot as far as i know
-
- if (building) {
- df::building_type btype = building->getType();
- if (btype == df::enums::building_type::TradeDepot ||
- btype == df::enums::building_type::Wagon)
- continue; // items in trade depot or the embark wagon do not rot
-
- if (typ == df::enums::item_type::EGG && btype ==df::enums::building_type::NestBox)
- continue; // eggs in nest box do not rot
- }
-
- int canHoldCount = 0;
- StockpileInfo *current = 0;
-
- for (int idx = 0; idx < stockpiles.size(); idx++)
- {
- StockpileInfo *spi = stockpiles[idx];
- if (spi->canHold(item)) canHoldCount++;
- if (spi->inStockpile(item)) current=spi;
- }
-
- if (current)
- continue;
-
- std::string description;
- item->getItemDescription(&description, 0);
- out << " * " << description;
+ }
+ }
+ }
+
+ if (holder)
+ continue; // carried items do not rot as far as i know
+
+ if (building) {
+ df::building_type btype = building->getType();
+ if (btype == df::enums::building_type::TradeDepot ||
+ btype == df::enums::building_type::Wagon)
+ continue; // items in trade depot or the embark wagon do not rot
+
+ if (typ == df::enums::item_type::EGG && btype ==df::enums::building_type::NestBox)
+ continue; // eggs in nest box do not rot
+ }
+
+ int canHoldCount = 0;
+ StockpileInfo *current = 0;
+
+ for (int idx = 0; idx < stockpiles.size(); idx++)
+ {
+ StockpileInfo *spi = stockpiles[idx];
+ if (spi->canHold(item)) canHoldCount++;
+ if (spi->inStockpile(item)) current=spi;
+ }
+
+ if (current)
+ continue;
+
+ std::string description;
+ item->getItemDescription(&description, 0);
+ out << " * " << description;
if (container) {
- std::string containerDescription;
- container->getItemDescription(&containerDescription, 0);
- out << ", in container " << containerDescription;
- if (lastcontainer) {
- std::string lastcontainerDescription;
- lastcontainer->getItemDescription(&lastcontainerDescription, 0);
- out << ", in container " << lastcontainerDescription;
- }
- }
-
- if (holder) {
- out << ", carried";
- }
-
- if (building) {
- out << ", in building " << building->id << " (type=" << building->getType() << ")";
- }
-
- out << ", flags=" << std::hex << item->flags.whole << std::dec;
- out << endl;
-
- }
-
- return CR_OK;
+ std::string containerDescription;
+ container->getItemDescription(&containerDescription, 0);
+ out << ", in container " << containerDescription;
+ if (lastcontainer) {
+ std::string lastcontainerDescription;
+ lastcontainer->getItemDescription(&lastcontainerDescription, 0);
+ out << ", in container " << lastcontainerDescription;
+ }
+ }
+
+ if (holder) {
+ out << ", carried";
+ }
+
+ if (building) {
+ out << ", in building " << building->id << " (type=" << building->getType() << ")";
+ }
+
+ out << ", flags=" << std::hex << item->flags.whole << std::dec;
+ out << endl;
+
+ }
+
+ return CR_OK;
}
diff --git a/plugins/devel/stripcaged.cpp b/plugins/devel/stripcaged.cpp
index a7683a9bb..30d0b0d2b 100644
--- a/plugins/devel/stripcaged.cpp
+++ b/plugins/devel/stripcaged.cpp
@@ -61,11 +61,11 @@ bool isContainedInItem(df::unit* unit)
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands)
{
- commands.push_back(PluginCommand(
- "stripcaged", "strip caged units of all items",
- df_stripcaged, false,
- "Clears forbid and sets dump for the inventories of all caged units."
- ));
+ commands.push_back(PluginCommand(
+ "stripcaged", "strip caged units of all items",
+ df_stripcaged, false,
+ "Clears forbid and sets dump for the inventories of all caged units."
+ ));
return CR_OK;
}
@@ -77,39 +77,39 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
command_result df_stripcaged(color_ostream &out, vector & parameters)
{
CoreSuspender suspend;
- bool keeparmor = true;
+ bool keeparmor = true;
- if (parameters.size() == 1 && parameters[0] == "dumparmor")
- {
- out << "Dumping armor too" << endl;
- keeparmor = false;
- }
+ if (parameters.size() == 1 && parameters[0] == "dumparmor")
+ {
+ out << "Dumping armor too" << endl;
+ keeparmor = false;
+ }
- size_t count = 0;
+ size_t count = 0;
for (size_t i=0; i < world->units.all.size(); i++)
{
df::unit* unit = world->units.all[i];
- if (isContainedInItem(unit))
- {
- for (size_t j=0; j < unit->inventory.size(); j++)
- {
- df::unit_inventory_item* uii = unit->inventory[j];
- if (uii->item)
- {
- if (keeparmor && (uii->item->isArmorNotClothing() || uii->item->isClothing()))
- continue;
- std::string desc;
- uii->item->getItemDescription(&desc,0);
- out << "Item " << desc << " dumped." << endl;
- uii->item->flags.bits.forbid = 0;
- uii->item->flags.bits.dump = 1;
- count++;
- }
- }
- }
- }
+ if (isContainedInItem(unit))
+ {
+ for (size_t j=0; j < unit->inventory.size(); j++)
+ {
+ df::unit_inventory_item* uii = unit->inventory[j];
+ if (uii->item)
+ {
+ if (keeparmor && (uii->item->isArmorNotClothing() || uii->item->isClothing()))
+ continue;
+ std::string desc;
+ uii->item->getItemDescription(&desc,0);
+ out << "Item " << desc << " dumped." << endl;
+ uii->item->flags.bits.forbid = 0;
+ uii->item->flags.bits.dump = 1;
+ count++;
+ }
+ }
+ }
+ }
- out << count << " items marked for dumping" << endl;
+ out << count << " items marked for dumping" << endl;
return CR_OK;
}
diff --git a/plugins/dfstream.cpp b/plugins/dfstream.cpp
index 1ed906881..19334abae 100644
--- a/plugins/dfstream.cpp
+++ b/plugins/dfstream.cpp
@@ -323,7 +323,7 @@ public:
auto_renderer_decorator & operator=(renderer_decorator *p) {
reset();
this->p = p;
- return *this;
+ return *this;
}
renderer_decorator * get() {
diff --git a/plugins/filltraffic.cpp b/plugins/filltraffic.cpp
index 6e87fd854..eeacc8781 100644
--- a/plugins/filltraffic.cpp
+++ b/plugins/filltraffic.cpp
@@ -1,7 +1,7 @@
// Wide-area traffic designation utility.
// Flood-fill from cursor or fill entire map.
-#include //For toupper().
+#include //For toupper().
#include //for min().
#include