diff options
| author | jj@jj | 2012-08-12 22:13:01 +0200 |
|---|---|---|
| committer | jj | 2012-08-12 22:36:54 +0200 |
| commit | 5a880d619c6e51093ff06bf7d8b99e672740bc76 (patch) | |
| tree | 1d4fd7c7b999745bb4ce84a1ee5c46ea3a72065a /plugins/ruby | |
| parent | 7cc100b26e501f039ab02ef7a1ec8b841510faab (diff) | |
| download | dfhack-5a880d619c6e51093ff06bf7d8b99e672740bc76.tar.gz dfhack-5a880d619c6e51093ff06bf7d8b99e672740bc76.tar.bz2 dfhack-5a880d619c6e51093ff06bf7d8b99e672740bc76.tar.xz | |
ruby: add MapTile#dig, tweak unit_iscitizen
Diffstat (limited to 'plugins/ruby')
| -rw-r--r-- | plugins/ruby/README | 3 | ||||
| -rw-r--r-- | plugins/ruby/map.rb | 5 | ||||
| -rw-r--r-- | plugins/ruby/unit.rb | 60 |
3 files changed, 42 insertions, 26 deletions
diff --git a/plugins/ruby/README b/plugins/ruby/README index 8a473f33..c9a84fb3 100644 --- a/plugins/ruby/README +++ b/plugins/ruby/README @@ -213,8 +213,7 @@ Find the raws name of the plant under cursor p df.world.raws.plants.all[plant.mat_index].id Dig a channel under the cursor - df.map_designation_at(df.cursor).dig = :Channel - df.map_block_at(df.cursor).flags.designated = true + df.map_tile_at(df.cursor).dig(:Channel) Spawn 2/7 magma on the tile of the dwarf nicknamed 'hotfeet' hot = df.unit_citizens.find { |u| u.name.nickname == 'hotfeet' } diff --git a/plugins/ruby/map.rb b/plugins/ruby/map.rb index c99d5b88..dccea729 100644 --- a/plugins/ruby/map.rb +++ b/plugins/ruby/map.rb @@ -188,6 +188,11 @@ module DFHack "#<MapTile pos=[#@x, #@y, #@z] shape=#{shape} tilemat=#{tilemat} material=#{mat_info.token}>" end + def dig(mode=:Default) + designation.dig = mode + mapblock.flags.designated = true + end + def spawn_liquid(quantity, is_magma=false, flowing=true) designation.flow_size = quantity designation.liquid_type = (is_magma ? :Magma : :Water) diff --git a/plugins/ruby/unit.rb b/plugins/ruby/unit.rb index ebcf249d..1a619c5c 100644 --- a/plugins/ruby/unit.rb +++ b/plugins/ruby/unit.rb @@ -41,48 +41,60 @@ module DFHack # returns an Array of all units that are current fort citizen (dwarves, on map, not hostile) def unit_citizens - race = ui.race_id - civ = ui.civ_id world.units.active.find_all { |u| - u.race == race and u.civ_id == civ and !u.flags1.dead and !u.flags1.merchant 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 - u.mood != :Berserk - # TODO check curse ; currently this should keep vampires, but may include werebeasts + unit_iscitizen(u) } end + 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.diplomat and !u.flags2.resident and !u.flags3.ghostly and + !u.curse.add_tags1.OPPOSED_TO_LIFE and !u.curse.add_tags1.CRAZED and + u.mood != :Berserk + # TODO check curse ; currently this should keep vampires, but may include werebeasts + end + # list workers (citizen, not crazy / child / inmood / noble) def unit_workers - unit_citizens.find_all { |u| - u.mood == :None and - u.profession != :CHILD and - u.profession != :BABY and - # TODO MENIAL_WORK_EXEMPTION_SPOUSE - !unit_entitypositions(u).find { |pos| pos.flags[:MENIAL_WORK_EXEMPTION] } + world.units.active.find_all { |u| + unit_isworker(u) } end + def unit_isworker(u) + unit_iscitizen(u) and + u.mood == :None and + u.profession != :CHILD and + u.profession != :BABY and + # TODO MENIAL_WORK_EXEMPTION_SPOUSE + !unit_entitypositions(u).find { |pos| pos.flags[:MENIAL_WORK_EXEMPTION] } + end + # list currently idle workers def unit_idlers - unit_workers.find_all { |u| - # current_job includes eat/drink/sleep/pickupequip - !u.job.current_job and - # filter 'attend meeting' - not u.specific_refs.find { |s| s.type == :ACTIVITY } and - # filter soldiers (TODO check schedule) - u.military.squad_index == -1 and - # filter 'on break' - not u.status.misc_traits.find { |t| t.id == :OnBreak } + world.units.active.find_all { |u| + unit_isidler(u) } end + def unit_isidler(u) + unit_isworker(u) and + # current_job includes eat/drink/sleep/pickupequip + !u.job.current_job and + # filter 'attend meeting' + not u.specific_refs.find { |s| s.type == :ACTIVITY } and + # filter soldiers (TODO check schedule) + u.military.squad_index == -1 and + # filter 'on break' + not u.status.misc_traits.find { |t| t.id == :OnBreak } + end + def unit_entitypositions(unit) list = [] - return list if not hf = world.history.figures.binsearch(unit.hist_figure_id) + return list if not hf = unit.hist_figure_tg hf.entity_links.each { |el| next if el._rtti_classname != :histfig_entity_link_positionst - next if not ent = world.entities.all.binsearch(el.entity_id) + next if not ent = el.entity_tg next if not pa = ent.positions.assignments.binsearch(el.assignment_id) next if not pos = ent.positions.own.binsearch(pa.position_id) list << pos |
