summaryrefslogtreecommitdiff
path: root/plugins/ruby
diff options
context:
space:
mode:
authorjj2012-09-02 01:38:58 +0200
committerjj2012-09-02 01:38:58 +0200
commita4c028b3b7c3ff709ece1b23d8641de6703fdb07 (patch)
treeb9a128ef04d76ff1e41e9e517e45387f0f5897ec /plugins/ruby
parentacdf0ffb42e6196cf85d36228ed247b2dae357ad (diff)
downloaddfhack-a4c028b3b7c3ff709ece1b23d8641de6703fdb07.tar.gz
dfhack-a4c028b3b7c3ff709ece1b23d8641de6703fdb07.tar.bz2
dfhack-a4c028b3b7c3ff709ece1b23d8641de6703fdb07.tar.xz
ruby: buildings tweaks
Diffstat (limited to 'plugins/ruby')
-rw-r--r--plugins/ruby/building.rb41
-rw-r--r--plugins/ruby/ruby-autogen-defs.rb24
2 files changed, 56 insertions, 9 deletions
diff --git a/plugins/ruby/building.rb b/plugins/ruby/building.rb
index d71a909c..398301b7 100644
--- a/plugins/ruby/building.rb
+++ b/plugins/ruby/building.rb
@@ -211,15 +211,13 @@ module DFHack
# link bld into other rooms if it is inside their extents
def building_linkrooms(bld)
- didstuff = false
world.buildings.other[:ANY_FREE].each { |ob|
next if !ob.is_room or ob.z != bld.z
next if !ob.room.extents or !ob.isExtentShaped or ob.room.extents[ob.room.width*(bld.y1-ob.room.y)+(bld.x1-ob.room.x)] == 0
- didstuff = true
+ ui.equipment.update.buildings = true
ob.children << bld
bld.parents << ob
}
- ui.equipment.update.buildings = true if didstuff
end
# link the building into the world, set map data, link rooms, bld.id
@@ -276,6 +274,43 @@ module DFHack
building_createdesign(bld, rough)
end
+ # construct an abstract building (stockpile, farmplot, ...)
+ def building_construct_abstract(bld)
+ if bld.getType == :Stockpile
+ max = df.world.buildings.other[:STOCKPILE].map { |s| s.stockpile_number }.max
+ bld.stockpile_number = max.to_i + 1
+ end
+ building_link bld
+ if !bld.flags.exists
+ bld.flags.exists = true
+ bld.initFarmSeasons
+ end
+ end
+
+ def building_setowner(bld, unit)
+ return unless bld.is_room
+ return if bld.owner == unit
+
+ if bld.owner
+ if idx = bld.owner.owned_buildings.index { |ob| ob.id == bld.id }
+ bld.owner.owned_buildings.delete_at(idx)
+ end
+ if spouse = bld.owner.relations.spouse_tg and
+ idx = spouse.owned_buildings.index { |ob| ob.id == bld.id }
+ spouse.owned_buildings.delete_at(idx)
+ end
+ end
+ bld.owner = unit
+ if unit
+ unit.owned_buildings << bld
+ if spouse = bld.owner.relations.spouse_tg and
+ !spouse.owned_buildings.index { |ob| ob.id == bld.id } and
+ bld.canUseSpouseRoom
+ spouse.owned_buildings << bld
+ end
+ end
+ end
+
# creates a job to deconstruct the building
def building_deconstruct(bld)
job = Job.cpp_new
diff --git a/plugins/ruby/ruby-autogen-defs.rb b/plugins/ruby/ruby-autogen-defs.rb
index 87474679..9312bb69 100644
--- a/plugins/ruby/ruby-autogen-defs.rb
+++ b/plugins/ruby/ruby-autogen-defs.rb
@@ -133,6 +133,8 @@ module DFHack
def _field_names ; _fields_ancestors.map { |n, o, s| n } ; end
def _rtti_classname ; self.class._rtti_classname ; end
def _sizeof ; self.class._sizeof ; end
+ def ==(o) ; o.kind_of?(Compound) and o._memaddr == _memaddr ; end
+
@@inspecting = {} # avoid infinite recursion on mutually-referenced objects
def inspect
cn = self.class.name.sub(/^DFHack::/, '')
@@ -289,12 +291,12 @@ module DFHack
# XXX shaky...
def _set(v)
- if v.kind_of?(Pointer)
- DFHack.memory_write_int32(@_memaddr, v._getp)
- elsif v.kind_of?(MemStruct)
- DFHack.memory_write_int32(@_memaddr, v._memaddr)
- else
- _get._set(v)
+ case v
+ when Pointer; DFHack.memory_write_int32(@_memaddr, v._getp)
+ when MemStruct; DFHack.memory_write_int32(@_memaddr, v._memaddr)
+ when Integer; DFHack.memory_write_int32(@_memaddr, v)
+ when nil; DFHack.memory_write_int32(@_memaddr, 0)
+ else _get._set(v)
end
end
@@ -328,6 +330,16 @@ module DFHack
self
end
+ def _set(v)
+ case v
+ when Pointer; DFHack.memory_write_int32(@_memaddr, v._getp)
+ when MemStruct; DFHack.memory_write_int32(@_memaddr, v._memaddr)
+ when Integer; DFHack.memory_write_int32(@_memaddr, v)
+ when nil; DFHack.memory_write_int32(@_memaddr, 0)
+ else raise "cannot PointerAry._set(#{v.inspect})"
+ end
+ end
+
def [](i)
addr = _getp(i)
return if addr == 0