Refactoring a table insert into reaction_entry.

develop
Eric Wald 2015-03-15 16:02:29 -06:00
parent 11d65b4f2d
commit 81c2a6e79f
1 changed files with 64 additions and 64 deletions

@ -149,7 +149,7 @@ function select_order(stockpile)
screen:show() screen:show()
end end
function reaction_entry(job_type, values, name) function reaction_entry(reactions, job_type, values, name)
local order = df.manager_order:new() local order = df.manager_order:new()
-- These defaults differ from the newly created order's. -- These defaults differ from the newly created order's.
order:assign{ order:assign{
@ -165,10 +165,10 @@ function reaction_entry(job_type, values, name)
order:assign(values) order:assign(values)
end end
return { table.insert(reactions, {
name = name or df.job_type.attrs[job_type].caption, name = name or df.job_type.attrs[job_type].caption,
order = order, order = order,
} })
end end
function resource_reactions(reactions, job_type, mat_info, keys, items, options) function resource_reactions(reactions, job_type, mat_info, keys, items, options)
@ -191,7 +191,7 @@ function resource_reactions(reactions, job_type, mat_info, keys, items, options)
end end
values.item_subtype = itemid values.item_subtype = itemid
table.insert(reactions, reaction_entry(job_type, values, start.." "..mat_info.adjective..item_name)) reaction_entry(reactions, job_type, values, start.." "..mat_info.adjective..item_name)
end end
end end
end end
@ -204,7 +204,7 @@ function material_reactions(reactions, itemtypes, mat_info)
line = line.." "..row[3] line = line.." "..row[3]
end end
table.insert(reactions, reaction_entry(row[1], mat_info.management, line)) reaction_entry(reactions, row[1], mat_info.management, line)
end end
end end
@ -252,11 +252,11 @@ function collect_reactions()
materials.leather.clothing_flag = "LEATHER" materials.leather.clothing_flag = "LEATHER"
-- Collection and Entrapment -- Collection and Entrapment
table.insert(result, reaction_entry(job_types.CollectWebs)) reaction_entry(result, job_types.CollectWebs)
table.insert(result, reaction_entry(job_types.CollectSand)) reaction_entry(result, job_types.CollectSand)
table.insert(result, reaction_entry(job_types.CollectClay)) reaction_entry(result, job_types.CollectClay)
table.insert(result, reaction_entry(job_types.CatchLiveLandAnimal)) reaction_entry(result, job_types.CatchLiveLandAnimal)
table.insert(result, reaction_entry(job_types.CatchLiveFish)) reaction_entry(result, job_types.CatchLiveFish)
-- Cutting, encrusting, and metal extraction. -- Cutting, encrusting, and metal extraction.
local rock_types = df.global.world.raws.inorganics local rock_types = df.global.world.raws.inorganics
@ -264,36 +264,36 @@ function collect_reactions()
local material = rock_types[rock_id].material local material = rock_types[rock_id].material
local rock_name = material.state_adj.Solid local rock_name = material.state_adj.Solid
if material.flags.IS_STONE or material.flags.IS_GEM then if material.flags.IS_STONE or material.flags.IS_GEM then
table.insert(result, reaction_entry(job_types.CutGems, { reaction_entry(result, job_types.CutGems, {
mat_type = 0, mat_type = 0,
mat_index = rock_id, mat_index = rock_id,
}, "Cut "..rock_name)) }, "Cut "..rock_name)
table.insert(result, reaction_entry(job_types.EncrustWithGems, { reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0, mat_type = 0,
mat_index = rock_id, mat_index = rock_id,
item_category = {finished_goods = true}, item_category = {finished_goods = true},
}, "Encrust Finished Goods With "..rock_name)) }, "Encrust Finished Goods With "..rock_name)
table.insert(result, reaction_entry(job_types.EncrustWithGems, { reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0, mat_type = 0,
mat_index = rock_id, mat_index = rock_id,
item_category = {furniture = true}, item_category = {furniture = true},
}, "Encrust Furniture With "..rock_name)) }, "Encrust Furniture With "..rock_name)
table.insert(result, reaction_entry(job_types.EncrustWithGems, { reaction_entry(result, job_types.EncrustWithGems, {
mat_type = 0, mat_type = 0,
mat_index = rock_id, mat_index = rock_id,
item_category = {ammo = true}, item_category = {ammo = true},
}, "Encrust Ammo With "..rock_name)) }, "Encrust Ammo With "..rock_name)
end end
if #rock_types[rock_id].metal_ore.mat_index > 0 then if #rock_types[rock_id].metal_ore.mat_index > 0 then
table.insert(result, reaction_entry(job_types.SmeltOre, {mat_type = 0, mat_index = rock_id}, "Smelt "..rock_name.." Ore")) reaction_entry(result, job_types.SmeltOre, {mat_type = 0, mat_index = rock_id}, "Smelt "..rock_name.." Ore")
end end
if #rock_types[rock_id].thread_metal.mat_index > 0 then if #rock_types[rock_id].thread_metal.mat_index > 0 then
table.insert(result, reaction_entry(job_types.ExtractMetalStrands, {mat_type = 0, mat_index = rock_id})) reaction_entry(result, job_types.ExtractMetalStrands, {mat_type = 0, mat_index = rock_id})
end end
end end
@ -311,28 +311,28 @@ function collect_reactions()
management = {mat_type = glass_id}, management = {mat_type = glass_id},
}) })
table.insert(result, reaction_entry(job_types.CutGlass, {mat_type = glass_id}, "Cut "..glass_name)) reaction_entry(result, job_types.CutGlass, {mat_type = glass_id}, "Cut "..glass_name)
table.insert(result, reaction_entry(job_types.EncrustWithGlass, { reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id, mat_type = glass_id,
item_category = {finished_goods = true}, item_category = {finished_goods = true},
}, "Encrust Finished Goods With "..glass_name)) }, "Encrust Finished Goods With "..glass_name)
table.insert(result, reaction_entry(job_types.EncrustWithGlass, { reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id, mat_type = glass_id,
item_category = {furniture = true}, item_category = {furniture = true},
}, "Encrust Furniture With "..glass_name)) }, "Encrust Furniture With "..glass_name)
table.insert(result, reaction_entry(job_types.EncrustWithGlass, { reaction_entry(result, job_types.EncrustWithGlass, {
mat_type = glass_id, mat_type = glass_id,
item_category = {ammo = true}, item_category = {ammo = true},
}, "Encrust Ammo With "..glass_name)) }, "Encrust Ammo With "..glass_name)
end end
end end
-- Dyeing -- Dyeing
table.insert(result, reaction_entry(job_types.DyeThread)) reaction_entry(result, job_types.DyeThread)
table.insert(result, reaction_entry(job_types.DyeCloth)) reaction_entry(result, job_types.DyeCloth)
-- Sew Image -- Sew Image
local cloth_mats = {materials.cloth, materials.silk, materials.yarn, materials.leather} local cloth_mats = {materials.cloth, materials.silk, materials.yarn, materials.leather}
@ -344,45 +344,45 @@ function collect_reactions()
material_reactions(result, {{job_types.DecorateWith, "Decorate With"}}, spec) material_reactions(result, {{job_types.DecorateWith, "Decorate With"}}, spec)
end end
table.insert(result, reaction_entry(job_types.MakeTotem)) reaction_entry(result, job_types.MakeTotem)
table.insert(result, reaction_entry(job_types.ButcherAnimal)) reaction_entry(result, job_types.ButcherAnimal)
table.insert(result, reaction_entry(job_types.MillPlants)) reaction_entry(result, job_types.MillPlants)
table.insert(result, reaction_entry(job_types.MakePotashFromLye)) reaction_entry(result, job_types.MakePotashFromLye)
table.insert(result, reaction_entry(job_types.MakePotashFromAsh)) reaction_entry(result, job_types.MakePotashFromAsh)
-- Kitchen -- Kitchen
table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 2}, "Prepare Easy Meal")) reaction_entry(result, job_types.PrepareMeal, {mat_type = 2}, "Prepare Easy Meal")
table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 3}, "Prepare Fine Meal")) reaction_entry(result, job_types.PrepareMeal, {mat_type = 3}, "Prepare Fine Meal")
table.insert(result, reaction_entry(job_types.PrepareMeal, {mat_type = 4}, "Prepare Lavish Meal")) reaction_entry(result, job_types.PrepareMeal, {mat_type = 4}, "Prepare Lavish Meal")
if v34 then if v34 then
-- Brew Drink -- Brew Drink
table.insert(result, reaction_entry(job_types.BrewDrink)) reaction_entry(result, job_types.BrewDrink)
end end
-- Weaving -- Weaving
table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {plant = true}}, "Weave Thread into Cloth")) reaction_entry(result, job_types.WeaveCloth, {material_category = {plant = true}}, "Weave Thread into Cloth")
table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {silk = true}}, "Weave Thread into Silk")) reaction_entry(result, job_types.WeaveCloth, {material_category = {silk = true}}, "Weave Thread into Silk")
table.insert(result, reaction_entry(job_types.WeaveCloth, {material_category = {yarn = true}}, "Weave Yarn into Cloth")) reaction_entry(result, job_types.WeaveCloth, {material_category = {yarn = true}}, "Weave Yarn into Cloth")
-- Extracts, farmer's workshop, and wood burning -- Extracts, farmer's workshop, and wood burning
table.insert(result, reaction_entry(job_types.ExtractFromPlants)) reaction_entry(result, job_types.ExtractFromPlants)
table.insert(result, reaction_entry(job_types.ExtractFromRawFish)) reaction_entry(result, job_types.ExtractFromRawFish)
table.insert(result, reaction_entry(job_types.ExtractFromLandAnimal)) reaction_entry(result, job_types.ExtractFromLandAnimal)
table.insert(result, reaction_entry(job_types.PrepareRawFish)) reaction_entry(result, job_types.PrepareRawFish)
table.insert(result, reaction_entry(job_types.MakeCheese)) reaction_entry(result, job_types.MakeCheese)
table.insert(result, reaction_entry(job_types.MilkCreature)) reaction_entry(result, job_types.MilkCreature)
table.insert(result, reaction_entry(job_types.ShearCreature)) reaction_entry(result, job_types.ShearCreature)
table.insert(result, reaction_entry(job_types.SpinThread)) reaction_entry(result, job_types.SpinThread)
table.insert(result, reaction_entry(job_types.MakeLye)) reaction_entry(result, job_types.MakeLye)
table.insert(result, reaction_entry(job_types.ProcessPlants)) reaction_entry(result, job_types.ProcessPlants)
if v34 then if v34 then
table.insert(result, reaction_entry(job_types.ProcessPlantsBag)) reaction_entry(result, job_types.ProcessPlantsBag)
end end
table.insert(result, reaction_entry(job_types.ProcessPlantsVial)) reaction_entry(result, job_types.ProcessPlantsVial)
table.insert(result, reaction_entry(job_types.ProcessPlantsBarrel)) reaction_entry(result, job_types.ProcessPlantsBarrel)
table.insert(result, reaction_entry(job_types.MakeCharcoal)) reaction_entry(result, job_types.MakeCharcoal)
table.insert(result, reaction_entry(job_types.MakeAsh)) reaction_entry(result, job_types.MakeAsh)
-- Reactions defined in the raws. -- Reactions defined in the raws.
-- Not all reactions are allowed to the civilization. -- Not all reactions are allowed to the civilization.
@ -397,7 +397,7 @@ function collect_reactions()
for _, reaction_id in ipairs(entity.entity_raw.workshops.permitted_reaction_id) do for _, reaction_id in ipairs(entity.entity_raw.workshops.permitted_reaction_id) do
local reaction = df.global.world.raws.reactions[reaction_id] local reaction = df.global.world.raws.reactions[reaction_id]
local name = string.gsub(reaction.name, "^.", string.upper) local name = string.gsub(reaction.name, "^.", string.upper)
table.insert(result, reaction_entry(job_types.CustomReaction, {reaction_name = reaction.code}, name)) reaction_entry(result, job_types.CustomReaction, {reaction_name = reaction.code}, name)
end end
-- Metal forging -- Metal forging
@ -412,7 +412,7 @@ function collect_reactions()
} }
if material.flags.IS_METAL then if material.flags.IS_METAL then
table.insert(result, reaction_entry(job_types.StudWith, mat_flags.management, "Stud With "..rock_name)) reaction_entry(result, job_types.StudWith, mat_flags.management, "Stud With "..rock_name)
if material.flags.ITEMS_WEAPON then if material.flags.ITEMS_WEAPON then
-- Todo: Are these really the right flags to check? -- Todo: Are these really the right flags to check?
@ -525,7 +525,7 @@ function collect_reactions()
end end
-- Traction Bench -- Traction Bench
table.insert(result, reaction_entry(job_types.ConstructTractionBench)) reaction_entry(result, job_types.ConstructTractionBench)
-- Non-metal weapons -- Non-metal weapons
resource_reactions(result, job_types.MakeWeapon, materials.wood, entity.resources.weapon_type, itemdefs.weapons, { resource_reactions(result, job_types.MakeWeapon, materials.wood, entity.resources.weapon_type, itemdefs.weapons, {
@ -649,7 +649,7 @@ function collect_reactions()
end end
-- Bed, specified as wooden. -- Bed, specified as wooden.
table.insert(result, reaction_entry(job_types.ConstructBed, materials.wood.management)) reaction_entry(result, job_types.ConstructBed, materials.wood.management)
-- Windows -- Windows
for _, mat_info in ipairs(glasses) do for _, mat_info in ipairs(glasses) do
@ -659,7 +659,7 @@ function collect_reactions()
end end
-- Rock Mechanisms -- Rock Mechanisms
table.insert(result, reaction_entry(job_types.ConstructMechanisms, materials.rock.management)) reaction_entry(result, job_types.ConstructMechanisms, materials.rock.management)
resource_reactions(result, job_types.AssembleSiegeAmmo, materials.wood, entity.resources.siegeammo_type, itemdefs.siege_ammo, { resource_reactions(result, job_types.AssembleSiegeAmmo, materials.wood, entity.resources.siegeammo_type, itemdefs.siege_ammo, {
verb = "Assemble", verb = "Assemble",
@ -718,8 +718,8 @@ function collect_reactions()
end end
-- Siege engine parts -- Siege engine parts
table.insert(result, reaction_entry(job_types.ConstructCatapultParts, materials.wood.management)) reaction_entry(result, job_types.ConstructCatapultParts, materials.wood.management)
table.insert(result, reaction_entry(job_types.ConstructBallistaParts, materials.wood.management)) reaction_entry(result, job_types.ConstructBallistaParts, materials.wood.management)
for _, mat in ipairs{materials.wood, materials.bone} do for _, mat in ipairs{materials.wood, materials.bone} do
resource_reactions(result, job_types.MakeAmmo, mat, entity.resources.ammo_type, itemdefs.ammo, { resource_reactions(result, job_types.MakeAmmo, mat, entity.resources.ammo_type, itemdefs.ammo, {
@ -736,7 +736,7 @@ function collect_reactions()
end end
-- Melt a Metal Object -- Melt a Metal Object
table.insert(result, reaction_entry(job_types.MeltMetalObject)) reaction_entry(result, job_types.MeltMetalObject)
return result return result
end end