diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index eaeef9bf4..21156ac0a 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -766,7 +766,7 @@ static df::unit *getAnyUnit(df::viewscreen *top) { case df::viewscreen_petst::List: if (!vector_get(screen->is_vermin, screen->cursor)) - return (df::unit*)vector_get(screen->animal, screen->cursor); + return vector_get(screen->animal, screen->cursor).unit; return NULL; case df::viewscreen_petst::SelectTrainer: diff --git a/plugins/ruby/building.rb b/plugins/ruby/building.rb index 3f8842b44..59f715515 100644 --- a/plugins/ruby/building.rb +++ b/plugins/ruby/building.rb @@ -51,12 +51,14 @@ module DFHack 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 + subtype = TrapType.int(subtype) if subtype.kind_of?(::Symbol) and type == :Trap bld.setSubtype(subtype) bld.setCustomType(custom) case type when :Furnace; bld.melt_remainder[world.raws.inorganics.length] = 0 when :Coffin; bld.initBurialFlags when :Trap; bld.unk_cc = 500 if bld.trap_type == :PressurePlate + when :Floodgate; bld.gate_flags.closed = true end bld end diff --git a/plugins/ruby/item.rb b/plugins/ruby/item.rb index 032c0d8cf..fc840f7ad 100644 --- a/plugins/ruby/item.rb +++ b/plugins/ruby/item.rb @@ -4,9 +4,14 @@ module DFHack # arg similar to unit.rb/unit_find; no arg = 'k' menu def item_find(what=:selected, y=nil, z=nil) if what == :selected - if curview._rtti_classname == :viewscreen_itemst + case curview._rtti_classname + when :viewscreen_itemst ref = curview.entry_ref[curview.cursor_pos] ref.item_tg if ref.kind_of?(GeneralRefItem) + when :viewscreen_storesst # z/stocks + if curview.in_group_mode == 0 and curview.in_right_list == 1 + curview.items[curview.item_cursor] + end else case ui.main.mode when :LookAround diff --git a/plugins/ruby/map.rb b/plugins/ruby/map.rb index 9629c3f9e..371614704 100644 --- a/plugins/ruby/map.rb +++ b/plugins/ruby/map.rb @@ -198,7 +198,7 @@ module DFHack def dig(mode=:Default) if mode == :Smooth - if tilemat != :SOIL and caption !~ /smooth|pillar|fortification/i and # XXX caption.. + if (tilemat == :STONE or tilemat == :MINERAL) and caption !~ /smooth|pillar|fortification/i and # XXX caption.. designation.smooth == 0 and (designation.hidden or not df.world.job_list.find { |j| # the game removes 'smooth' designation as soon as it assigns a job, if we # re-set it the game may queue another :DetailWall that will carve a fortification diff --git a/plugins/ruby/ruby.rb b/plugins/ruby/ruby.rb index aeae101d3..81b73b7ce 100644 --- a/plugins/ruby/ruby.rb +++ b/plugins/ruby/ruby.rb @@ -119,6 +119,14 @@ module DFHack @onstatechange_list.delete b end + # same as onstatechange_register, but auto-unregisters if the block returns true + def onstatechange_register_once + handle = onstatechange_register { |st| + onstatechange_unregister(handle) if yield(st) + } + end + + # this method is called by dfhack every 'onstatechange' def onstatechange(newstate) @onstatechange_list ||= [] diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index 5289229a6..139a375b2 100644 --- a/plugins/ruby/unit.rb +++ b/plugins/ruby/unit.rb @@ -12,9 +12,15 @@ module DFHack ref.unit_tg if ref.kind_of?(GeneralRefUnit) when :viewscreen_unitlistst v = curview - # TODO fix xml to use enums everywhere - page = DFHack::ViewscreenUnitlistst_TPage.int(v.page) - v.units[page][v.cursor_pos[page]] + v.units[v.page][v.cursor_pos[v.page]] + when :viewscreen_petst + v = curview + case v.mode + when :List + v.animal[v.cursor].unit if !v.is_vermin[v.cursor] + when :SelectTrainer + v.trainer_unit[v.trainer_cursor] + end else case ui.main.mode when :ViewUnits @@ -48,7 +54,7 @@ module DFHack } end - def unit_iscitizen(u) + def unit_iscitizen(u) u.race == ui.race_id and u.civ_id == ui.civ_id and !u.flags1.dead and !u.flags1.merchant and !u.flags1.forest and !u.flags1.diplomat and !u.flags2.resident and !u.flags3.ghostly and !u.curse.add_tags1.OPPOSED_TO_LIFE and !u.curse.add_tags1.CRAZED and diff --git a/plugins/sort.cpp b/plugins/sort.cpp index 4b2bf7bbd..95ae109a8 100644 --- a/plugins/sort.cpp +++ b/plugins/sort.cpp @@ -356,7 +356,7 @@ DEFINE_SORT_HANDLER(unit_sorters, pet, "/List", animals) std::vector units; for (size_t i = 0; i < animals->animal.size(); i++) - units.push_back(animals->is_vermin[i] ? NULL : (df::unit*)animals->animal[i]); + units.push_back(animals->is_vermin[i] ? NULL : animals->animal[i].unit); if (compute_order(*pout, L, top, &order, units)) {