added tech mining-tool unlock & inf. durability

This commit is contained in:
Peter 2019-01-11 18:47:43 +08:00
parent d4e39a6ebf
commit 2dce2d07a1
6 changed files with 222 additions and 3 deletions

152
017_science/control.lua Normal file
View File

@ -0,0 +1,152 @@
if settings.startup["017-axe"].value then
local function generate_axes()
-- game.print("gen_ax")
global.axe_techs = {}
for _, axe in pairs(game.item_prototypes) do
if axe.attack_range then
global.axe_techs[#global.axe_techs+1] = {axe.name,axe.speed}
end
end
end
local function ax_gen()
if global.axe_techs == nil then
generate_axes()
else
-- game.print("ax_gen")
for f, force in pairs(game.forces) do
for _, technology in pairs(force.technologies) do
local name = force.name
if highest_speed == nil then
highest_speed = {}
end
if highest_speed[name] == nil then
highest_speed[name] = {"iron-axe",2.5}
end
if technology.researched then
for _=1, #global.axe_techs do
for i=1, #technology.effects do
if technology.effects[i].recipe == global.axe_techs[_][1] then
if highest_speed[name][2] < global.axe_techs[_][2] then
highest_speed[name] = global.axe_techs[_]
end
end
end
end
end
end
end
end
end
local function give_ax(event)
local player = game.players[event.player_index]
-- game.print("give_ax")
if highest_speed == nil then
ax_gen()
end
if highest_speed[player.force.name] == nil then
ax_gen()
else
axe_name = highest_speed[player.force.name][1]
for _=1, #global.axe_techs do
local item = global.axe_techs[_][1]
if item ~= axe_name then
player.remove_item(item)
end
end
if axe_name == nil then
player.insert{name="iron-axe", count = 1}
else
player.insert{name=axe_name, count = 1}
end
end
end
local function ax_research(event)
local technology = event.research
ax_gen()
for _, player in pairs(technology.force.players) do
event.player_index = player.index
for _=1, #global.axe_techs do
player.remove_item(global.axe_techs[_][1])
end
give_ax(event)
end
end
script.on_init(function()
global.axe_techs = {}
generate_axes()
end)
-- init_game
-- script.on_configuration_changed(function() configuration_changed = 1 game.print("changed") end)
-- script.on_event(defines.events.on_player_created, generate_axes)
script.on_event(defines.events.on_player_created, function(event) give_ax(event) end)
script.on_event(defines.events.on_force_created, function(event) ax_gen(event) end)
script.on_event(defines.events.on_forces_merged, function(event) ax_gen(event) end)
script.on_configuration_changed(function(event)
generate_axes()
ax_gen()
end)
-- game
script.on_event(defines.events.on_research_finished, ax_gen)
script.on_event(defines.events.on_research_finished, ax_research)
script.on_event(defines.events.on_player_tool_inventory_changed, give_ax)
-- script.on_event(defines.events.on_player_trash_inventory_changed, give_ax)
-- script.on_event(defines.events.on_player_main_inventory_changed, give_ax)
script.on_event(defines.events.on_player_main_inventory_changed, function(event) game.players[event.player_index].remove_item("017-mine") end)
script.on_event(defines.events.on_player_cursor_stack_changed, function(event)
local player = game.players[event.player_index]
if player.cursor_stack.valid_for_read then
-- game.print(axe)
-- game.print(player.cursor_stack.name)
if player.cursor_stack.name == highest_speed[player.force.name][1] then
player.clean_cursor()
end
end
end)
script.on_event(defines.events.on_player_dropped_item, function(event)
for _=1, #global.axe_techs do
if event.entity.valid then
if event.entity.stack.name == global.axe_techs[_][1] then
give_ax(event)
event.entity.destroy()
end
end
end
end)
script.on_event(defines.events.on_player_crafted_item, function(event)
if event.item_stack.name == "017-mine" then
give_ax(event)
game.players[event.player_index].print("Updated mining tool!")
end
end)
--debug
-- commands.add_command("axe_techs", "debug: regenerate list of axes", function(command)
-- generate_axes()
-- for _=1, #global.axe_techs do game.player.print(global.axe_techs[_][1] .. " | " .. global.axe_techs[_][2]) end
-- end)
-- commands.add_command("list_axes", "debug: list all valid axes", function(command)
-- if global.axe_techs == nil then
-- game.player.print("ERROR: not generated")
-- else
-- for _=1, #global.axe_techs do
-- game.player.print(global.axe_techs[_][1] .. " | " .. global.axe_techs[_][2])
-- end
-- for _, h in pairs(highest_speed) do
-- game.player.print("highest speed: " .. h[1] .. " | " .. h[2] .. " (force" .. _ .. ")")
-- end
-- end
-- end)
end

View File

@ -17,6 +17,7 @@ for _, mod in pairs(data.raw.module) do
end
end
--overrides
local function recipe_change(table, condition, replace)
for _=1, #table do
if table[_][1] == condition then
@ -66,6 +67,29 @@ end
prerequisites(data.raw["technology"]["rocket-silo"].prerequisites, "rocket-speed-5", nil)
--player equipment changes
--https://forums.factorio.com/viewtopic.php?t=6059
if settings.startup["017-durability"].value then
for _, axe in pairs(data.raw["mining-tool"]) do
axe.durability = math.huge
end
for _, armor in pairs(data.raw["armor"]) do
armor.durability = math.huge
end
end
if settings.startup["017-axe"].value then
for _, axe in pairs(data.raw["mining-tool"]) do
for i, r in pairs(data.raw["recipe"]) do
if data.raw["recipe"][i].result == axe.name then
data.raw["recipe"][i].hidden = true
data.raw["recipe"][i].ingredients = {}
end
end
end
end
--HUGE THANKS to Dimava for the following changes
--Added options for some changes (for modded users)

View File

@ -1,6 +1,6 @@
{
"name": "017_science",
"version": "0.0.9",
"version": "0.0.10",
"factorio_version": "0.16",
"title": "0.17 science conversion",
"author": "npc_strider(morley376)",

View File

@ -3,6 +3,7 @@ science-pack-1=Automation science pack
science-pack-2=Logistics science pack
science-pack-3=Chemical science pack
high-tech-science-pack=Utility science pack
017-mine=Request a new mining-tool
[mod-setting-name]
017-drill=Ore hardness simplification
@ -10,10 +11,14 @@ high-tech-science-pack=Utility science pack
017-assem-lim=Remove assembler item limit
017-old-science=Enable old science recipes
017-recipes-changes=Misc. recipe changes in 0.17
017-durability=Infinite armor/tool durability
017-axe=mining-tool (axe) removal
[mod-setting-description]
017-drill=(Default enabled) Toggle FFF-266 mining changes (removed hardness). This mod makes all vanilla ore hardness = 1 and makes the burner-mining-drill mining_power = 3, which may break modded ore gating.
017-smelting=(Default enabled) Toggle V's smelting changes (https://forums.factorio.com/viewtopic.php?t=64219#p392508). This mod may break ratios for modded recipes using vanilla and modded items.
017-assem-lim=(Default enabled) Toggle the assembly limit removal. This mod affects all assembling-machines and may affect modded crafting stations based on this entity, which may use the limit as a form of gating.
017-old-science=(Default disabled) Toggle the old science recipes (0.16), including LDS. When disabled it removes the ability to use the vanilla science and LDS recipes (except SP 1 & 2) but allows existing crafting machines to continue using the recipe until manually changed.
017-recipes-changes=(Default enabled) atomic-bomb and power-armor-mk2 recipe changes
017-recipes-changes=(Default enabled) atomic-bomb and power-armor-mk2 recipe changes
017-durability=(Default enabled) All armor now have inf. durability (https://forums.factorio.com/viewtopic.php?p=384185#p384185). Axes also have inf. durability to reflect the removal of mining-tool items.
017-axe=(Default enabled) IMPORTANT NOTE: It is highly recomended that infinite durability is enabled when using this option to prevent duplicate items. Implements the FFF-266 changes as best as possible. Instead of mining-tools being crafted, they are inserted and locked to the player's tool slot when they're researched. The best mining-tool is used over lower speed ones.

View File

@ -120,4 +120,30 @@ data:extend(
icon = "__017_science__/graphics/icons/LDS.png",
icon_size = 32
}
})
})
--Mining
if settings.startup["017-axe"].value then
data:extend(
{
{
type = "recipe",
name = "017-mine",
energy = 0.025,
ingredients = {},
result = "017-mine",
icon = "__base__/graphics/icons/iron-axe.png",
icon_size = 32
},
{
type = "item",
name = "017-mine",
localised_description = {"item-description.mining-tool"},
icon = "__base__/graphics/icons/iron-axe.png",
icon_size = 32,
flags = {"goes-to-main-inventory"},
subgroup = "tool",
order = "a[mining]-a[iron-axe]",
stack_size = 1
}
})
end

View File

@ -29,5 +29,17 @@ data:extend(
name = "017-recipes-changes",
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "017-axe",
setting_type = "startup",
default_value = true
},
{
type = "bool-setting",
name = "017-durability",
setting_type = "startup",
default_value = true
}
})