Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Apr 24, 2013
2 parents 0efbc74 + c9776f4 commit df6355a
Show file tree
Hide file tree
Showing 33 changed files with 1,625 additions and 1,362 deletions.
17 changes: 17 additions & 0 deletions Compile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ extra options.
You can also use a cmake-friendly IDE like KDevelop 4 or the cmake-gui
program.

Fixing the libstdc++ version bug
================================

When compiling dfhack yourself, it builds against your system libc.
When Dwarf Fortress runs, it uses a libstdc++ shipped with the binary, which
is usually way older, and incompatible with your dfhack. This manifests with
the error message::

./libs/Dwarf_Fortress: /pathToDF/libs/libstdc++.so.6: version
`GLIBCXX_3.4.15' not found (required by ./hack/libdfhack.so)

To fix this, simply remove the libstdc++ shipped with DF, it will fall back
to your system lib and everything will work fine::

cd /path/to/DF/
rm libs/libstdc++.so.6

========
Mac OS X
========
Expand Down
7 changes: 6 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ DFHack future
- restrictice - Restrict traffic on squares above visible ice.
New scripts:
- masspit: designate caged creatures in a zone for pitting
- locate_ore: scan the map for unmined ore veins
- multicmd: run a sequence of dfhack commands, separated by ';'
Misc improvements:
- exterminate: renamed from slayrace, add help message
- exterminate: renamed from slayrace, add help message, add butcher mode
- autoSyndrome: disable by default
- ruby: add df.dfhack_run "somecommand"
- magmasource: rename to source, allow water/magma sources/drains

DFHack v0.34.11-r3

Expand Down
60 changes: 46 additions & 14 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ use in your farming plots.
With a seed type, the script will grow 100 of these seeds, ready to be
harvested. You can change the number with a 2nd argument.

For exemple, to grow 40 plump helmet spawn:
For example, to grow 40 plump helmet spawn:
::

growcrops plump 40
Expand Down Expand Up @@ -1900,9 +1900,10 @@ such as vampires, it also sets animal.vanish_countdown to 2.
An alternate mode is selected by adding a 2nd argument to the command,
``magma``. In this case, a column of 7/7 magma is generated on top of the
targets until they die (Warning: do not call on magma-safe creatures. Also,
using this mode for birds is not recommanded.)
using this mode on birds is not recommanded.)

Will target any unit on a revealed tile of the map, including ambushers.
Will target any unit on a revealed tile of the map, including ambushers,
but ignore caged/chained creatures.

Ex::

Expand All @@ -1917,24 +1918,32 @@ To purify all elves on the map with fire (may have side-effects)::
exterminate elve magma


magmasource
===========
Create an infinite magma source on a tile.
source
======
Create an infinite magma or water source or drain on a tile.

This script registers a map tile as a magma source, and every 12 game ticks
that tile receives 1 new unit of flowing magma.
This script registers a map tile as a liquid source, and every 12 game ticks
that tile receives or remove 1 new unit of flow based on the configuration.

Place the game cursor where you want to create the source (must be a
flow-passable tile, and not too high in the sky) and call::

magmasource here
source add [magma|water] [0-7]

To add more than 1 unit everytime, call the command again.
The number argument is the target liquid level (0 = drain, 7 = source).

To delete one source, place the cursor over its tile and use ``delete-here``.
To remove all placed sources, call ``magmasource stop``.
To add more than 1 unit everytime, call the command again on the same spot.

With no argument, this command shows an help message and list existing sources.
To delete one source, place the cursor over its tile and use ``delete``.
To remove all existing sources, call ``source clear``.

The ``list`` argument shows all existing sources.

Ex::

source add water - water source
source add magma 7 - magma source
source add water 0 - water drain

masspit
=======
Expand Down Expand Up @@ -2066,7 +2075,7 @@ Note that the script does not enforce anything, and will let you create
boulders of toad blood and stuff like that.
However the ``list`` mode will only show 'normal' materials.

Exemples::
Examples::

create-items boulders COAL_BITUMINOUS 12
create-items plant tail_pig
Expand All @@ -2075,6 +2084,20 @@ Exemples::
create-items bar CREATURE:CAT:SOAP
create-items bar adamantine

locate-ore
==========
Scan the map for metal ores.

Finds and designate for digging one tile of a specific metal ore.
Only works for native metal ores, does not handle reaction stuff (eg STEEL).

When invoked with the ``list`` argument, lists metal ores available on the map.

Examples::
locate-ore list
locate-ore hematite
locate-ore iron

soundsense-season
=================

Expand All @@ -2086,6 +2109,15 @@ This script registers a hook that prints the appropriate string
to gamelog.txt on every map load to fix this. For best results
call the script from ``dfhack.init``.

multicmd
========
Run multiple dfhack commands. The argument is split around the
character ; and all parts are run sequencially as independent
dfhack commands. Useful for hotkeys.

Example::
multicmd locate-ore iron ; digv

=======================
In-game interface tools
=======================
Expand Down
19 changes: 10 additions & 9 deletions dfhack.init-example
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ tweak military-color-assigned
# remove inverse dependency of squad training speed on unit list size and use more sparring
tweak military-training

# enable autoSyndrome
autoSyndrome enable

###########
# Scripts #
###########
Expand All @@ -149,23 +152,21 @@ fix/cloth-stockpile enable

#######################################################
# Apply binary patches at runtime #
# #
# Commented out by default; enable the ones you want. #
#######################################################

# Bug 5994 - items teleported when removing a construction
#binpatch apply deconstruct-teleport
#binpatch apply deconstruct-heapfall
binpatch apply deconstruct-teleport
binpatch apply deconstruct-heapfall

# Bug 4406 - hospital overstocking on all items
#binpatch apply hospital-overstocking
binpatch apply hospital-overstocking

# Bug 808 - custom reactions completely using up all of their reagents
#binpatch apply custom-reagent-size
binpatch apply custom-reagent-size

# Bug 4530 - marksdwarves not training when quiver full of combat-only ammo
#binpatch apply training-ammo
binpatch apply training-ammo

# Bug 1445 - weapon racks broken, armor stand capacity too low
#binpatch apply weaponrack-unassign
#binpatch apply armorstand-capacity
binpatch apply weaponrack-unassign
binpatch apply armorstand-capacity
5 changes: 4 additions & 1 deletion plugins/autoSyndrome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ reaction_duck
Next, start a new fort in a new world, build a duck workshop, then have someone become a duck.
*/

bool enabled = true;
bool enabled = false;

DFHACK_PLUGIN("autoSyndrome");

Expand Down Expand Up @@ -279,6 +279,9 @@ void processJob(color_ostream& out, void* jobPtr) {
}
}

if ( workerId == -1 )
return;

int32_t workerIndex = df::unit::binsearch_index(df::global::world->units.all, workerId);
if ( workerIndex < 0 ) {
out.print("%s line %d: Couldn't find unit %d.\n", __FILE__, __LINE__, workerId);
Expand Down
6 changes: 3 additions & 3 deletions plugins/dig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
" Also follows the stone between z-levels with stairs, like 'digl x' would.\n"
));
commands.push_back(PluginCommand("digexp","Select or designate an exploratory pattern. Use 'digexp ?' for help.",digexp));
commands.push_back(PluginCommand("digcircle","Dig designate a circle (filled or hollow) with given radius.",digcircle));
commands.push_back(PluginCommand("digcircle","Dig designate a circle (filled or hollow) with given diameter.",digcircle));
//commands.push_back(PluginCommand("digauto","Mark a tile for continuous digging.",autodig));
commands.push_back(PluginCommand("digtype", "Dig all veins of a given type.", digtype,Gui::cursor_hotkey,
"For every tile on the map of the same vein type as the selected tile, this command designates it to have the same designation as the selected tile. If the selected tile has no designation, they will be dig designated.\n"
Expand Down Expand Up @@ -120,7 +120,7 @@ bool dig (MapExtras::MapCache & MCache,
if(tileMaterial(tt) == tiletype_material::CONSTRUCTION && !des.bits.hidden)
return false;
df::tiletype_shape ts = tileShape(tt);
if (ts == tiletype_shape::EMPTY)
if (ts == tiletype_shape::EMPTY && !des.bits.hidden)
return false;
if(!des.bits.hidden)
{
Expand Down Expand Up @@ -293,7 +293,7 @@ command_result digcircle (color_ostream &out, vector <string> & parameters)
"\n"
"After you have set the options, the command called with no options\n"
"repeats with the last selected parameters:\n"
"'digcircle filled 3' = Dig a filled circle with radius = 3.\n"
"'digcircle filled 3' = Dig a filled circle with diameter = 3.\n"
"'digcircle' = Do it again.\n"
);
return CR_OK;
Expand Down
27 changes: 22 additions & 5 deletions plugins/ruby/README
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ The help string displayed in dfhack 'ls' command is the first line of the
script, if it is a comment (ie starts with '# ').


Calling dfhack commands
-----------------------

The ruby plugin allows the calling of arbitrary dfhack commands, as if typed
directly on the dfhack prompt.
However due to locks and stuff, the dfhack command is delayed until the current
ruby command is finished, so it is restricted to interactive uses.
It is possible to call the method many times, this will queue dfhack commands
to be run in order.

df.dfhack_run "reveal"


Ruby helper functions
---------------------

Expand Down Expand Up @@ -107,7 +120,7 @@ eg 'gob' for 'GOBLIN' or 'coal' for 'COAL_BITUMINOUS', hence the name.
df.building_construct(bld, item_list)
Allocates a new building in DF memory, define its position / dimensions, and
create a dwarf job to construct it from the given list of items.
See buildings.rb/buildbed for an exemple.
See buildings.rb/buildbed for an example.

df.each_tree(material) { |t| }
Iterates over every tree of the given material (eg 'maple').
Expand Down Expand Up @@ -137,13 +150,17 @@ To stop being called, use:
The same mechanism is available for 'onstatechange', but the
SC_BEGIN_UNLOAD event is not propagated to the ruby handler.

Available states:
:WORLD_LOADED, :WORLD_UNLOADED, :MAP_LOADED, :MAP_UNLOADED,
:VIEWSCREEN_CHANGED, :CORE_INITIALIZED, :PAUSED, :UNPAUSED


C++ object manipulation
-----------------------

The ruby classes defined in ruby-autogen.rb are accessors to the underlying
df C++ objects in-memory. To allocate a new C++ object for use in DF, use the
RubyClass.cpp_new method (see buildings.rb for exemples), works for Compounds
RubyClass.cpp_new method (see buildings.rb for examples), works for Compounds
only.
A special Compound DFHack::StlString is available for allocating a single c++
stl::string, so that you can call vmethods that take a string pointer argument
Expand Down Expand Up @@ -186,10 +203,10 @@ Pointer fields are automatically dereferenced ; so a vector of pointer to
Units will yield Units directly. NULL pointers yield the 'nil' value.


Exemples
Examples
--------

For more complex exemples, check the dfhack/scripts/*.rb files.
For more complex examples, check the dfhack/scripts/*.rb files.

Show info on the currently selected unit ('v' or 'k' DF menu)
p df.unit_find.flags1
Expand Down Expand Up @@ -240,7 +257,7 @@ which differ between Windows and Linux. Linux and Macosx are the same, as they
both use gcc).
It is stored inside the build directory (eg build/plugins/ruby/ruby-autogen.rb)

For exemple,
For example,
<ld:global-type ld:meta="struct-type" type-name="unit">
<ld:field type-name="language_name" name="name" ld:meta="global"/>
<ld:field name="custom_profession" ld:meta="primitive" ld:subtype="stl-string"/>
Expand Down
2 changes: 2 additions & 0 deletions plugins/ruby/building.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def building_alloc(type, subtype=-1, custom=-1)
raise "invalid building type #{type.inspect}" if not cls
bld = cls.cpp_new
bld.race = ui.race_id
subtype = ConstructionType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Construction
subtype = SiegeengineType.int(subtype) if subtype.kind_of?(::Symbol) and type == :SiegeEngine
subtype = WorkshopType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Workshop
subtype = FurnaceType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Furnace
subtype = CivzoneType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Civzone
Expand Down
16 changes: 15 additions & 1 deletion plugins/ruby/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,21 @@ def all_veins
def vein
# last vein wins
all_veins.reverse.find { |v|
(v.tile_bitmask.bits[@dy] & (1 << @dx)) > 0
v.tile_bitmask.bits[@dy][@dx] > 0
}
end

# return the first BlockBurrow this tile is in (nil if none)
def burrow
mapblock.block_burrows.find { |b|
b.tile_bitmask.bits[@dy][@dx] > 0
}
end

# return the array of BlockBurrow this tile is in
def all_burrows
mapblock.block_burrows.find_all { |b|
b.tile_bitmask.bits[@dy][@dx] > 0
}
end

Expand Down
7 changes: 4 additions & 3 deletions plugins/ruby/ruby-autogen-defs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def _cpp_init
_fields_ancestors.each { |n, o, s| s._at(@_memaddr+o)._cpp_init }
end
def _cpp_delete
_fields_ancestors.each { |n, o, s| s._at(@_memaddr+o)._cpp_delete }
# cannot call delete on compound members (would call free on member address)
#_fields_ancestors.each { |n, o, s| s._at(@_memaddr+o)._cpp_delete }
DFHack.free(@_memaddr)
@_memaddr = nil # turn future segfaults in harmless ruby exceptions
end
Expand Down Expand Up @@ -642,7 +643,7 @@ def initialize(tglen, tg)
@_tg = tg
end
# XXX DF uses stl::deque<some_struct>, so to have a C binding we'd need to single-case every
# possible struct size, like for StlVector. Just ignore it for now, deque are rare enough.
# possible struct size, like for StlVector. Just ignore it for now, deques are rare enough.
def inspect ; "#<StlDeque>" ; end
end

Expand Down Expand Up @@ -676,7 +677,7 @@ def []=(idx, v)
def inspect
out = "#<DfFlagarray"
each_with_index { |e, idx|
out << " #{_indexenum.sym(idx)}" if e
out << " #{_indexenum ? _indexenum.sym(idx) : idx}" if e
}
out << '>'
end
Expand Down
Loading

0 comments on commit df6355a

Please sign in to comment.