diff --git a/plugins/ruby/plugins/buildbed.rb b/plugins/ruby/plugins/buildbed.rb new file mode 100644 index 000000000..5e544c826 --- /dev/null +++ b/plugins/ruby/plugins/buildbed.rb @@ -0,0 +1,87 @@ +module DFHack +def self.buildbedhere + suspend { + raise 'where to ?' if cursor.x < 0 + + # TODO tweak that more + item = world.items.all.find { |i| + i.kind_of?(ItemBedst) and + i.itemrefs.empty? and + i.jobs.empty? + } + raise 'no free bed, build more !' if not item + + puts 'alloc c++' + job = Job.cpp_new + joblink = JobListLink.cpp_new + jobitemref = JobItemRef.cpp_new + refbuildingholder = GeneralRefBuildingHolderst.cpp_new + building = BuildingBedst.cpp_new + itemtjobs = Item_TJobs.cpp_new + + puts 'update global counters' + # TODO + buildingid = world.buildings.all[-1].id + 1 + jobid = df.job_next_id + df.job_next_id = jobid+1 + + puts 'init objects' + job.id = jobid + job.list_link = joblink + job.job_type = :ConstructBuilding + job.unk2 = -1 # XXX + job.pos = cursor + job.completion_timer = -1 + # unk4a/4b uninit + job.mat_type = item.mat_type + job.mat_index = item.mat_index + job.unk5 = -1 + job.unk6 = -1 + job.item_subtype = -1 + job.hist_figure_id = -1 + job.items << jobitemref + job.references << refbuildingholder + + lastjob = world.job_list + lastjob = lastjob.next while lastjob.next + lastjob.next = joblink + joblink.prev = lastjob + joblink.item = job + + jobitemref.item = item + jobitemref.role = :Hauled + jobitemref.job_item_idx = -1 + + refbuildingholder.building_id = buildingid + + building.x1 = building.x2 = building.centerx = cursor.x + building.y1 = building.y2 = building.centery = cursor.y + building.z = cursor.z + building.mat_type = item.mat_type + building.mat_index = item.mat_index + building.race = ui.race_id + building.id = buildingid + building.jobs << job + building.anon_3 = -1 + building.anon_4 = -1 + + itemtjobs.unk1 = 2 + itemtjobs.job = job + + item.flags.in_job = true + item.jobs << itemtjobs + + puts 'update vectors' + world.buildings.all << building + # XXX + world.buildings.other[0] << building + world.buildings.other[4] << building + world.buildings.other[8] << building + world.buildings.other[9] << building + world.buildings.other[10] << building + world.buildings.other[32] << building + # not in bad + + } +end +end diff --git a/plugins/ruby/ruby-memstruct.rb b/plugins/ruby/ruby-memstruct.rb index 3b30b0e9d..53a4158fc 100644 --- a/plugins/ruby/ruby-memstruct.rb +++ b/plugins/ruby/ruby-memstruct.rb @@ -111,7 +111,13 @@ class Compound < MemStruct def _cpp_init _fields_ancestors.each { |n, o, s| s._at(@_memaddr+o)._cpp_init } end - def _set(h) ; h.each { |k, v| send("_#{k}=", v) } ; end + def _set(h) + case h + when Hash; h.each { |k, v| send("_#{k}=", v) } + when Compound; _fields.each { |n, o, s| send("#{n}=", h.send(n)) } + else raise 'wut?' + end + end def _fields ; self.class._fields.to_a ; end def _fields_ancestors ; self.class._fields_ancestors.to_a ; end def _rtti_classname ; self.class._rtti_classname ; end @@ -695,7 +701,7 @@ end # return the vtable pointer from the cpp rtti name def self.rtti_getvtable(cppname) unless v = @rtti_n2v[cppname] - v = get_vtable(cppname) + v = get_vtable(cppname.to_s) @rtti_n2v[cppname] = v @rtti_v2n[v] = cppname if v != 0 end