#!/usr/bin/ruby # Usage # $ ./fa_calc 歯車 # $ ./fa_calc 水パック '2.0/24' | sed 's/^\s*//' | sort @items = { '石炭' => { :type => :mate, }, '石' => { :type => :mate, }, '水' => { :type => :mate, }, '鉄板' => { :type => :mate, }, '銅板' => { :type => :mate, }, '鋼材' => { :type => :mate, }, '硫黄' => { :type => :prod, :num => 2, :time => 1, :parts => [ { :name => '水', :num => 30, }, { :name => '石油ガス', :num => 30, }, ], }, 'プラ棒' => { :type => :prod, :num => 2, :time => 1, :parts => [ { :name => '石油ガス', :num => 20, }, { :name => '石炭', :num => 1, }, ], }, '鉄筋' => { :type => :prod, :num => 2, :time => 0.5, :parts => [ { :name => '鉄板', :num => 1, }, ], }, '歯車' => { :type => :prod, :time => 0.5, :parts => [ { :name => '鉄板', :num => 2, }, ], }, '銅線' => { :type => :prod, :num => 2, :time => 0.5, :parts => [ { :name => '銅板', :num => 1, }, ], }, '緑基板' => { :type => :prod, :time => 0.5, :parts => [ { :name => '鉄板', :num => 1, }, { :name => '銅線', :num => 3, }, ], }, 'エンジン' => { :type => :prod, :time => 10, :parts => [ { :name => '鋼材', :num => 1, }, { :name => '歯車', :num => 1, }, { :name => 'パイプ', :num => 2, }, ], }, '赤基板' => { :type => :prod, :time => 6, :parts => [ { :name => '緑基板', :num => 2, }, { :name => 'プラ棒', :num => 2, }, { :name => '銅線', :num => 4, }, ], }, '赤パック' => { :type => :prod, :time => 5, :parts => [ { :name => '銅板', :num => 1, }, { :name => '歯車', :num => 1, }, ], }, '緑パック' => { :type => :prod, :time => 6, :parts => [ { :name => 'インサータ', :num => 1, }, { :name => 'ベルト', :num => 1, }, ], }, '水パック' => { :type => :prod, :time => 24, :parts => [ { :name => 'エンジン', :num => 2, }, { :name => '赤基板', :num => 3, }, { :name => '硫黄', :num => 1, }, ], }, '灰パック' => { :type => :prod, :time => 10, :parts => [ { :name => '貫通弾', :num => 1, }, { :name => '手榴弾', :num => 1, }, { :name => '壁', :num => 2, }, ], }, '紫パック' => { :type => :prod, :time => 21, :parts => [ { :name => '赤モジュール', :num => 1, }, { :name => '電気炉', :num => 1, }, { :name => 'レール', :num => 30, }, ], }, '石油ガス' => { :type => :mate, }, 'ベルト' => { :type => :prod, :num => 2, :time => 0.5, :parts => [ { :name => '鉄板', :num => 1, }, { :name => '歯車', :num => 1, }, ], }, 'パイプ' => { :type => :prod, :time => 0.5, :parts => [ { :name => '鉄板', :num => 1, }, ], }, 'インサータ' => { :type => :prod, :time => 0.5, :parts => [ { :name => '緑基板', :num => 1, }, { :name => '鉄板', :num => 1, }, { :name => '歯車', :num => 1, }, ], }, 'レール' => { :type => :prod, :num => 2, :time => 0.5, :parts => [ { :name => '石', :num => 1, }, { :name => '鉄筋', :num => 1, }, { :name => '鋼材', :num => 1, }, ], }, 'レンガ' => { :type => :mate, }, '電気炉' => { :type => :prod, :time => 5, :parts => [ { :name => '鋼材', :num => 10, }, { :name => 'レンガ', :num => 10, }, { :name => '赤基板', :num => 5, }, ], }, '赤モジュール' => { :type => :prod, :time => 15, :parts => [ { :name => '緑基板', :num => 5, }, { :name => '赤基板', :num => 5, }, ], }, '通常弾' => { :type => :prod, :time => 1, :parts => [ { :name => '鉄板', :num => 4, }, ], }, '貫通弾' => { :type => :prod, :time => 15, :parts => [ { :name => '通常弾', :num => 1, }, { :name => '銅板', :num => 5, }, { :name => '鋼材', :num => 1, }, ], }, '手榴弾' => { :type => :prod, :time => 8, :parts => [ { :name => '鉄板', :num => 5, }, { :name => '石炭', :num => 10, }, ], }, '壁' => { :type => :prod, :time => 0.5, :parts => [ { :name => 'レンガ', :num => 5, }, ], }, } def disasm(part_name, num = 1) prod = @items[part_name] parts = { :name => part_name, :num => (num = num.to_f), } if(prod[:type] == :mate) parts[:type] = :mate else parts[:type] = :prod parts[:list] = [] prod_num = (prod[:num] || 1).to_f parts[:macs] = prod[:time] * num / prod_num prod[:parts].each {|part| parts[:list] << disasm(part[:name], part[:num] * num / prod_num) } end return(parts) end def show(parts, n = 0) if(parts[:type] == :mate) puts('%s%s: %s %5.2f' % ["\t" * n, parts[:type], parts[:name], parts[:num]]) else puts('%s%s: %s %5.2f macs:%5.2f' % ["\t" * n, parts[:type], parts[:name], parts[:num], parts[:macs]]) parts[:list].each {|part| show(part, n + 1) } end end part_name = ARGV[0] num = eval(ARGV[1] || '1').to_f puts("[%s x %5.2f]" % [part_name, num]) parts = disasm(part_name, num) show(parts) __END__