2012-06-24 13:41:43 -06:00
|
|
|
# grow crops in farm plots. ex: growcrops helmet_plump 20
|
|
|
|
|
|
|
|
material = $script_args[0]
|
|
|
|
count_max = $script_args[1].to_i
|
|
|
|
count_max = 100 if count_max == 0
|
|
|
|
|
|
|
|
# cache information from the raws
|
|
|
|
@raws_plant_name ||= {}
|
|
|
|
@raws_plant_growdur ||= {}
|
|
|
|
if @raws_plant_name.empty?
|
|
|
|
df.world.raws.plants.all.each_with_index { |p, idx|
|
|
|
|
@raws_plant_name[idx] = p.id
|
|
|
|
@raws_plant_growdur[idx] = p.growdur
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-06-29 06:09:11 -06:00
|
|
|
inventory = Hash.new(0)
|
|
|
|
df.world.items.other[:SEEDS].each { |seed|
|
|
|
|
next if not seed.flags.in_building
|
2012-11-12 07:29:44 -07:00
|
|
|
next if not seed.general_refs.find { |ref| ref._rtti_classname == :general_ref_building_holderst }
|
2012-06-29 06:09:11 -06:00
|
|
|
next if seed.grow_counter >= @raws_plant_growdur[seed.mat_index]
|
|
|
|
inventory[seed.mat_index] += 1
|
|
|
|
}
|
|
|
|
|
2012-06-24 13:41:43 -06:00
|
|
|
if !material or material == 'help' or material == 'list'
|
|
|
|
# show a list of available crop types
|
2012-06-29 06:09:11 -06:00
|
|
|
inventory.sort_by { |mat, c| c }.each { |mat, c|
|
2012-06-24 13:41:43 -06:00
|
|
|
name = df.world.raws.plants.all[mat].id
|
|
|
|
puts " #{name} #{c}"
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2012-06-29 06:09:11 -06:00
|
|
|
mat = df.match_rawname(material, inventory.keys.map { |k| @raws_plant_name[k] })
|
2012-06-24 13:41:43 -06:00
|
|
|
unless wantmat = @raws_plant_name.index(mat)
|
|
|
|
raise "invalid plant material #{material}"
|
|
|
|
end
|
|
|
|
|
2012-06-29 06:09:11 -06:00
|
|
|
count = 0
|
2012-06-25 09:06:37 -06:00
|
|
|
df.world.items.other[:SEEDS].each { |seed|
|
|
|
|
next if seed.mat_index != wantmat
|
|
|
|
next if not seed.flags.in_building
|
2012-11-12 07:29:44 -07:00
|
|
|
next if not seed.general_refs.find { |ref| ref._rtti_classname == :general_ref_building_holderst }
|
2012-06-25 09:06:37 -06:00
|
|
|
next if seed.grow_counter >= @raws_plant_growdur[seed.mat_index]
|
|
|
|
seed.grow_counter = @raws_plant_growdur[seed.mat_index]
|
2012-06-29 06:09:11 -06:00
|
|
|
count += 1
|
2012-06-24 13:41:43 -06:00
|
|
|
}
|
2012-06-29 06:09:11 -06:00
|
|
|
puts "Grown #{count} #{mat}"
|
2012-06-24 13:41:43 -06:00
|
|
|
end
|