Skip to content

Commit

Permalink
Dynamic Config
Browse files Browse the repository at this point in the history
  • Loading branch information
Dysoch committed Feb 16, 2015
1 parent c9c05d9 commit bc55b99
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 22 deletions.
6 changes: 0 additions & 6 deletions CORE-DyTech-Core/locale/en/entity-names.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
165 changes: 165 additions & 0 deletions CORE-DyTech-Script/control.lua
Original file line number Diff line number Diff line change
@@ -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
})
14 changes: 14 additions & 0 deletions MAIN-DyTech-Dynamics/config.lua
Original file line number Diff line number Diff line change
@@ -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
19 changes: 14 additions & 5 deletions MAIN-DyTech-Dynamics/control.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "defines"
require "config"
require "database/research"
require "scripts/rs-functions"
require "scripts/test-functions"
Expand Down Expand Up @@ -32,27 +33,31 @@ 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
glob[counter]=glob[counter]+(ingredients/10)
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
glob[counter]=glob[counter]+((ingredients/10)*9)
debug("Research added to science counter ("..tostring((ingredients/10)*9)..") Total now: "..tostring(glob[counter]))
end
end
end
end)

remote.addinterface("DyTech-Dynamics",
Expand All @@ -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
})
10 changes: 7 additions & 3 deletions MAIN-DyTech-Dynamics/data-updates.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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
break
end
end

RemoveFromTech("automation", "assembling-machine-1")
RemoveFromTech("automation", "long-handed-inserter")
RemoveFromTech("automation", "iron-gear-wheel")
if Research_System then
RemoveFromTech("automation", "assembling-machine-1")
RemoveFromTech("automation", "long-handed-inserter")
RemoveFromTech("automation", "iron-gear-wheel")
end
6 changes: 3 additions & 3 deletions MAIN-DyTech-Dynamics/database/research-system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
2 changes: 1 addition & 1 deletion MAIN-DyTech-Dynamics/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
14 changes: 13 additions & 1 deletion MAIN-DyTech-Dynamics/script-locale/en.cfg
Original file line number Diff line number Diff line change
@@ -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
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
17 changes: 14 additions & 3 deletions MAIN-DyTech-Dynamics/scripts/rs-functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc55b99

Please sign in to comment.