Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
Update bob compatibility, check for ingredients before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Afforess committed Apr 15, 2016
1 parent 4715e74 commit ef6b218
Show file tree
Hide file tree
Showing 12 changed files with 358 additions and 256 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 1.0.2
VERSION := 1.0.3
NAME := marathon

all: clean build install_mod
Expand Down
78 changes: 72 additions & 6 deletions data-updates.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
if bobmods and bobmods.config then
function update_recipe(name, values)
local recipe = data.raw.recipe[name]
if recipe then
for key, value in pairs(values) do
recipe[key] = value

function marathon.update_recipe(name, values)
local recipe = data.raw.recipe[name]
if recipe then
for key, value in pairs(values) do
recipe[key] = value
end
end
end

function marathon.replace_recipe_item(recipe, prev_name, new_name)
local doit = false
local amount = 0
if data.raw.recipe[recipe] and data.raw.item[new_name] then
local ingredients = data.raw.recipe[recipe].ingredients
for i = 1, #ingredients do
local ingredient_item = ingredients[i]
if ingredient_item[1] == prev_name then
ingredient_item[1] = new_name
elseif ingredient_item.name == prev_name then
ingredient_item.name = new_name
end
end
end
end

function marathon.add_new_recipe_item(recipe, item)
local item_name
if item.name then
item_name = item.name
else
item_name = item[1]
end

if data.raw.recipe[recipe] and data.raw.item[item_name] then
for _, ingredient_item in pairs(data.raw.recipe[recipe].ingredients) do
if ingredient_item[1] == item_name then
return
elseif ingredient_item.name == item_name then
return
end
end
table.insert(data.raw.recipe[recipe].ingredients, item)
end
end

function marathon.add_recipe_item(recipe, item)
local addit = true
local item_name
if item.name then
item_name = item.name
else
item_name = item[1]
end
local item_amount
if item.amount then
item_amount = item.amount
else
item_amount = item[2]
end
if data.raw.recipe[recipe] and data.raw.item[item_name] then
for _, ingredient_item in pairs(data.raw.recipe[recipe].ingredients) do
if ingredient_item[1] == item_name then
ingredient_item[2] = ingredient_item[2] + item_amount
return
elseif ingredient_item.name == item_name then
ingredient_item.amount = ingredient_item.amount + item_amount
return
end
end
table.insert(data.raw.recipe[recipe].ingredients, item)
end
end

if bobmods and bobmods.config then
require("prototypes.bobsmods.item")
require("prototypes.bobsmods.recipe-chemistry")
require("prototypes.bobsmods.recipe-circuit")
Expand Down
2 changes: 2 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ require("prototypes.recipe-production")
require("prototypes.recipe-science")
require("prototypes.recipe-smelting")
require("prototypes.recipe-weapon")

marathon = {}
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marathon",
"version": "1.0.2",
"version": "1.0.3",
"title": "Marathon Mod",
"author": "Benoit Girard & Afforess",
"contributors": ["Wulfson", "KeepOnDigging", "gheift"],
Expand All @@ -20,5 +20,5 @@
"? bobpower >= 0.12.6",
"? bobtech >= 0.12.4",
"? bobwarfare >= 0.12.9"
]
]
}
18 changes: 9 additions & 9 deletions prototypes/bobsmods/recipe-chemistry.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

update_recipe("alumina",
marathon.update_recipe("alumina",
{
energy_required = 6,
result_count = 6,
Expand All @@ -9,8 +9,8 @@ update_recipe("alumina",
}
})

if bobmods.config.plates.BatteryUpdate then
update_recipe("battery",
if bobmods.config.plates.BatteryUpdate and data.raw.item["lead-plate"] and data.raw.item["sulfuric-acid"] then
marathon.update_recipe("battery",
{
ingredients = {
{type="item", name="lead-plate", amount=4},
Expand All @@ -20,7 +20,7 @@ if bobmods.config.plates.BatteryUpdate then
})
end

update_recipe("coal-cracking",
marathon.update_recipe("coal-cracking",
{
energy_required = 6,
ingredients = {
Expand All @@ -32,36 +32,36 @@ update_recipe("coal-cracking",
}
})

update_recipe("ferric-chloride-solution",
marathon.update_recipe("ferric-chloride-solution",
{
energy_required = 5,
results = {
{type="fluid", name="ferric-chloride-solution", amount=3}
}
})

update_recipe("liquid-fuel",
marathon.update_recipe("liquid-fuel",
{
energy_required = 3,
ingredients = {
{type="fluid", name="light-oil", amount=3}
}
})

update_recipe("lithium-chloride",
marathon.update_recipe("lithium-chloride",
{
energy_required = 2,
ingredients = {
{type="fluid", name="lithia-water", amount=5}
}
})

update_recipe("sulfur-2",
marathon.update_recipe("sulfur-2",
{
energy_required = 1.5
})

update_recipe("sulfuric-acid-2",
marathon.update_recipe("sulfuric-acid-2",
{
ingredients = {
{type="fluid", name="water", amount=1},
Expand Down
Loading

0 comments on commit ef6b218

Please sign in to comment.