From bc55b99e7ab24255589ab49c3d80e9e2f3f35e47 Mon Sep 17 00:00:00 2001 From: Dysoch Date: Mon, 16 Feb 2015 10:18:27 +0100 Subject: [PATCH] Dynamic Config --- CORE-DyTech-Core/locale/en/entity-names.cfg | 6 - CORE-DyTech-Script/control.lua | 165 ++++++++++++++++++ MAIN-DyTech-Dynamics/config.lua | 14 ++ MAIN-DyTech-Dynamics/control.lua | 19 +- MAIN-DyTech-Dynamics/data-updates.lua | 10 +- .../database/research-system.lua | 6 +- MAIN-DyTech-Dynamics/info.json | 2 +- MAIN-DyTech-Dynamics/script-locale/en.cfg | 14 +- MAIN-DyTech-Dynamics/scripts/rs-functions.lua | 17 +- 9 files changed, 231 insertions(+), 22 deletions(-) create mode 100644 CORE-DyTech-Script/control.lua create mode 100644 MAIN-DyTech-Dynamics/config.lua diff --git a/CORE-DyTech-Core/locale/en/entity-names.cfg b/CORE-DyTech-Core/locale/en/entity-names.cfg index e1ab28e0..e97684e3 100644 --- a/CORE-DyTech-Core/locale/en/entity-names.cfg +++ b/CORE-DyTech-Core/locale/en/entity-names.cfg @@ -158,12 +158,6 @@ sand=Sand lava-600=Lava Pool lava-1400=Lava Pool lava-2800=Lava Pool -metallurgy-machine-gear=Gear Presser -metallurgy-machine-wire=Wire Presser -metallurgy-machine-circuit=Circuit Presser -metallurgy-machine-ammo-basic=Basic Ammo Presser -metallurgy-machine-ammo-advanced=Advanced Ammo Presser -metallurgy-machine-tools=Tool Presser super-ore=Super Ore Formation lava-handler=Lava Handler pipe-mainline=Mainline Pipe diff --git a/CORE-DyTech-Script/control.lua b/CORE-DyTech-Script/control.lua new file mode 100644 index 00000000..41589560 --- /dev/null +++ b/CORE-DyTech-Script/control.lua @@ -0,0 +1,165 @@ +require "defines" + +--[[Debug Functions]]-- +debug_master = false -- Master switch for debugging, shows most things! +function debug(str) + if debug_master then + PlayerPrint(str) + end +end + +function PlayerPrint(message) + for _,player in pairs(game.players) do + player.print(message) + end +end + +game.oninit(function() + +end) + +game.onsave(function() + +end) + +game.onload(function() + +end) + +game.onevent(defines.events.onplayercrafteditem, function(event) + if not glob.CraftedItems then glob.CraftedItems = {} end + if not glob.CraftedItems[event.itemstack.name] then + glob.CraftedItems[event.itemstack.name] = event.itemstack.count + debug("No CraftedItems ("..tostring(event.itemstack.name)..")") + else + glob.CraftedItems[event.itemstack.name] = glob.CraftedItems[event.itemstack.name] + event.itemstack.count + debug("CraftedItems increased by "..tostring(event.itemstack.count).." ("..tostring(event.itemstack.name)..")") + end +end) + +game.onevent(defines.events.onplayermineditem, function(event) + if not glob.MinedItems then glob.MinedItems = {} end + if not glob.MinedItems[event.itemstack.name] then + glob.MinedItems[event.itemstack.name] = event.itemstack.count + debug("MinedItems not found".." ("..tostring(event.itemstack.name)..")") + else + glob.MinedItems[event.itemstack.name] = glob.MinedItems[event.itemstack.name] + event.itemstack.count + debug("MinedItems increased by "..tostring(event.itemstack.count).." ("..tostring(event.itemstack.name)..")") + end +end) + +game.onevent(defines.events.onrobotmined, function(event) + if not glob.RobotMinedItems then glob.RobotMinedItems = {} end + if not glob.RobotMinedItems[event.itemstack.name] then + glob.RobotMinedItems[event.itemstack.name] = event.itemstack.count + debug("RobotMinedItems not found".." ("..tostring(event.itemstack.name)..")") + else + glob.RobotMinedItems[event.itemstack.name] = glob.RobotMinedItems[event.itemstack.name] + event.itemstack.count + debug("RobotMinedItems increased by "..tostring(event.itemstack.count).." ("..tostring(event.itemstack.name)..")") + end +end) + +game.onevent(defines.events.onentitydied, function(event) + if not glob.EntityDied then glob.EntityDied = {} end + if not glob.EntityDied[event.entity.name] then + glob.EntityDied[event.entity.name] = 1 + debug("EntityDied not found".." ("..tostring(event.entity.name)..")") + else + glob.EntityDied[event.entity.name] = glob.EntityDied[event.entity.name] + 1 + debug("EntityDied increased by 1".." ("..tostring(event.entity.name)..")") + end +end) + +game.onevent(defines.events.onsectorscanned, function(event) + if not glob.SectorScanned then + glob.SectorScanned = 1 + else + glob.SectorScanned = glob.SectorScanned + 1 + end +end) + +game.onevent(defines.events.onmarkedfordeconstruction, function(event) + if not glob.MarkedForDeconstruction then glob.MarkedForDeconstruction = {} end + if not glob.MarkedForDeconstruction[event.entity.name] then + glob.MarkedForDeconstruction[event.entity.name] = 1 + debug("MarkedForDeconstruction not found ("..tostring(event.entity.name)..")") + else + glob.MarkedForDeconstruction[event.entity.name] = glob.MarkedForDeconstruction[event.entity.name] + 1 + debug("MarkedForDeconstruction increased by 1 ("..tostring(event.entity.name)..")") + end +end) + +game.onevent(defines.events.oncanceleddeconstruction, function(event) + if not glob.CanceledDeconstruction then glob.CanceledDeconstruction = {} end + if not glob.CanceledDeconstruction[event.entity.name] then + glob.CanceledDeconstruction[event.entity.name] = 1 + debug("CanceledDeconstruction not found ("..tostring(event.entity.name)..")") + else + glob.CanceledDeconstruction[event.entity.name] = glob.CanceledDeconstruction[event.entity.name] + 1 + debug("CanceledDeconstruction increased by 1 ("..tostring(event.entity.name)..")") + end +end) + +game.onevent(defines.events.onpickedupitem, function(event) + if not glob.PickedItems then glob.PickedItems = {} end + if not glob.PickedItems[event.itemstack.name] then + glob.PickedItems[event.itemstack.name] = event.itemstack.count + debug("PickedItems not found ("..tostring(event.itemstack.name)..")") + else + glob.PickedItems[event.itemstack.name] = glob.PickedItems[event.itemstack.name] + event.itemstack.count + debug("PickedItems increased by "..tostring(event.itemstack.count).." ("..tostring(event.itemstack.name)..")") + end +end) + +game.onevent(defines.events.ontick, function(event) + if not glob.timer then glob.timer={seconds=0, minutes=0, hours=0} end + if event.tick%60==0 then + glob.timer.seconds = glob.timer.seconds + 1 + end + if glob.timer.seconds==60 then + glob.timer.seconds = 0 + glob.timer.minutes = glob.timer.minutes + 1 + end + if glob.timer.minutes==60 then + glob.timer.minutes = 0 + glob.timer.hours = glob.timer.hours + 1 + end +end) + +game.onevent(defines.events.onbuiltentity, function(event) + if not glob.BuildEntity then glob.BuildEntity = {} end + if glob.BuildEntity[event.createdentity.name] then + glob.BuildEntity[event.createdentity.name] = glob.BuildEntity[event.createdentity.name] + 1 + debug("BuildEntity increased by 1 ("..tostring(event.createdentity.name)..")") + else + glob.BuildEntity[event.createdentity.name] = 1 + debug("BuildEntity not found ("..tostring(event.createdentity.name)..")") + end +end) + +game.onevent(defines.events.onrobotbuiltentity, function(event) + if not glob.RobotBuildEntity then glob.RobotBuildEntity = {} end + if glob.RobotBuildEntity[event.createdentity.name] then + glob.RobotBuildEntity[event.createdentity.name] = glob.RobotBuildEntity[event.createdentity.name] + 1 + debug("RobotBuildEntity increased by 1 ("..tostring(event.createdentity.name)..")") + else + glob.RobotBuildEntity[event.createdentity.name] = 1 + debug("RobotBuildEntity not found ("..tostring(event.createdentity.name)..")") + end +end) + +game.onevent(defines.events.onchunkgenerated, function(event) + if not glob.ChunkGenerated then + glob.ChunkGenerated = 1 + else + glob.ChunkGenerated = glob.ChunkGenerated + 1 + end + if debug_chunks then debug("Chunk Generated, chunks counter is now "..tostring(glob.ChunkGenerated)) end +end) + +remote.addinterface("DyTech-Script", +{ + Timer = function(name) + return glob.timer[name] + end +}) \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/config.lua b/MAIN-DyTech-Dynamics/config.lua new file mode 100644 index 00000000..7f30e9f5 --- /dev/null +++ b/MAIN-DyTech-Dynamics/config.lua @@ -0,0 +1,14 @@ +-- Welcome to the config file of DyTech-Dynamic! +-- Here you can switch any module on or off! +-- The general rule is: TRUE is on, FALSE is off! + +--[[ Research System Toggle ]]-- +-- This is the toggle for the Research System. +-- This system will set all technologies to not unlock a recipe, +-- and lets the Research Handle it! +Research_System = true + +--[[ Extra Toggles for the Research System ]]-- +-- This toggle is for having time as a requirement. +-- Meaning: a recipe can only be unlocked after a specific time has passed. +Research_System_Time_Usage = true diff --git a/MAIN-DyTech-Dynamics/control.lua b/MAIN-DyTech-Dynamics/control.lua index 2af0e37d..9938c1db 100644 --- a/MAIN-DyTech-Dynamics/control.lua +++ b/MAIN-DyTech-Dynamics/control.lua @@ -1,4 +1,5 @@ require "defines" +require "config" require "database/research" require "scripts/rs-functions" require "scripts/test-functions" @@ -32,8 +33,9 @@ game.onload(function() end) game.onevent(defines.events.onresearchstarted, function(event) -if not glob.science then glob.science=0 end -debug("Research Started ("..tostring(event.research)..")") +if Research_System then + if not glob.science then glob.science=0 end + debug("Research Started ("..tostring(event.research)..")") if ResearchDatabase.research[event.research] then debug("Research found in database") for counter, ingredients in pairs(ResearchDatabase.research[event.research]) do @@ -41,11 +43,13 @@ debug("Research Started ("..tostring(event.research)..")") debug("Research added to science counter ("..tostring(ingredients/10)..") Total now: "..tostring(glob[counter])) end end +end end) game.onevent(defines.events.onresearchfinished, function(event) -if not glob.science then glob.science=0 end -debug("Research Finished ("..tostring(event.research)..")") +if Research_System then + if not glob.science then glob.science=0 end + debug("Research Finished ("..tostring(event.research)..")") if ResearchDatabase.research[event.research] then debug("Research found in database") for counter, ingredients in pairs(ResearchDatabase.research[event.research]) do @@ -53,6 +57,7 @@ debug("Research Finished ("..tostring(event.research)..")") debug("Research added to science counter ("..tostring((ingredients/10)*9)..") Total now: "..tostring(glob[counter])) end end +end end) remote.addinterface("DyTech-Dynamics", @@ -69,6 +74,10 @@ remote.addinterface("DyTech-Dynamics", end, RSRemote = function(name) - RSF.RSUnlock(name) + if Research_System then + RSF.RSUnlock(name) + else + PlayerPrint({"rs-disabled"}) + end end }) \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/data-updates.lua b/MAIN-DyTech-Dynamics/data-updates.lua index d6e3037b..75a4dfbf 100644 --- a/MAIN-DyTech-Dynamics/data-updates.lua +++ b/MAIN-DyTech-Dynamics/data-updates.lua @@ -1,3 +1,5 @@ +require "config" + function RemoveFromTech(Name, Recipe) for k, v in pairs(data.raw["technology"][Name].effects) do if v.recipe == Recipe then table.remove(data.raw["technology"][Name].effects, k) end @@ -5,6 +7,8 @@ function RemoveFromTech(Name, Recipe) end end -RemoveFromTech("automation", "assembling-machine-1") -RemoveFromTech("automation", "long-handed-inserter") -RemoveFromTech("automation", "iron-gear-wheel") \ No newline at end of file +if Research_System then + RemoveFromTech("automation", "assembling-machine-1") + RemoveFromTech("automation", "long-handed-inserter") + RemoveFromTech("automation", "iron-gear-wheel") +end \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/database/research-system.lua b/MAIN-DyTech-Dynamics/database/research-system.lua index 0c914a59..a373bf4d 100644 --- a/MAIN-DyTech-Dynamics/database/research-system.lua +++ b/MAIN-DyTech-Dynamics/database/research-system.lua @@ -7,7 +7,7 @@ module("RSDatabase") ItemUnlock = { - ["IronGear"]={Name="iron-gear-wheel", Points=2}, - ["LongInserter"]={Name="long-handed-inserter", Points=3}, - ["Assembling1"]={Name="assembling-machine-1", Points=5}, + ["IronGear"]={Name="iron-gear-wheel", Points=2, Hour=0, Minute=10}, + ["LongInserter"]={Name="long-handed-inserter", Points=3, Hour=0, Minute=15}, + ["Assembling1"]={Name="assembling-machine-1", Points=5, Hour=0, Minute=15}, } \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/info.json b/MAIN-DyTech-Dynamics/info.json index f8608999..894e9686 100644 --- a/MAIN-DyTech-Dynamics/info.json +++ b/MAIN-DyTech-Dynamics/info.json @@ -5,5 +5,5 @@ "title":"MAIN-DyTech-Dynamics", "homepage":"http://www.factorioforums.com/forum/viewforum.php?f=43", "description":"This Main Module of DyTech holds all scripted things. Dynamic System, Modular Tools and many more are included!", - "dependencies": ["? CORE-DyTech-Core >= 1.1.0", "? MAIN-DyTech-Machine >= 1.0.1", "? MAIN-DyTech-Power >= 1.0.0", "? MAIN-DyTech-War >= 1.0.0", "base"] + "dependencies": ["CORE-DyTech-Script >= 1.0.0", "? CORE-DyTech-Core >= 1.1.0", "? MAIN-DyTech-Machine >= 1.0.1", "? MAIN-DyTech-Power >= 1.0.0", "? MAIN-DyTech-War >= 1.0.0", "base"] } \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/script-locale/en.cfg b/MAIN-DyTech-Dynamics/script-locale/en.cfg index c70a9f16..c06c0e81 100644 --- a/MAIN-DyTech-Dynamics/script-locale/en.cfg +++ b/MAIN-DyTech-Dynamics/script-locale/en.cfg @@ -1,2 +1,14 @@ not-enough-points=You don't have enough Science Points to unlock this item! -unlocked=You had enough points, so you have unlocked \ No newline at end of file +not-enough-time=Not enough time has passed to unlock this recipe. Please try again later! +unlocked=You had enough points, so you have unlocked +rs-disabled=Research System is NOT ENABLED!!!!! Enable it to use it! + + + + + + + +iron-gear-wheel=Iron Gear Wheel +assembling-machine-1=Assembling machine 1 +long-handed-inserter=Long Handed Inserter \ No newline at end of file diff --git a/MAIN-DyTech-Dynamics/scripts/rs-functions.lua b/MAIN-DyTech-Dynamics/scripts/rs-functions.lua index 6732b1e0..04278545 100644 --- a/MAIN-DyTech-Dynamics/scripts/rs-functions.lua +++ b/MAIN-DyTech-Dynamics/scripts/rs-functions.lua @@ -5,9 +5,20 @@ function RSUnlock(Name) if not glob.Unlocked[Name] then local info = RSDatabase.ItemUnlock[Name] if glob.science >= info.Points then - game.player.force.recipes[info.Name].enabled = true - PlayerPrint({"unlocked", {info.Name, {"!"}}}) - glob.Unlocked[Name] = true + if Research_System_Time_Usage then + if info.Hour <= remote.call("DyTech-Script", "Timer", "hours") and info.Minute <= remote.call("DyTech-Script", "Timer", "minutes") then + game.player.force.recipes[info.Name].enabled = true + PlayerPrint({"unlocked", {info.Name, {"!"}}}) + glob.Unlocked[Name] = true + else + PlayerPrint({"not-enough-time"}) + break + end + else + game.player.force.recipes[info.Name].enabled = true + PlayerPrint({"unlocked", {info.Name, {"!"}}}) + glob.Unlocked[Name] = true + end else PlayerPrint({"not-enough-points"}) end