Skip to content

Commit

Permalink
* Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
avosirenfal committed Jan 9, 2017
0 parents commit 1d18126
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 0 deletions.
273 changes: 273 additions & 0 deletions Extended_Research_1.0.0/data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
require('ir_util')

-- tech is the name of a tech (e.g. 'gun-turret-damage')
-- tiers is how many tiers you want
-- final_resource_count is the cost of the last research in this tree
-- mod_func is a callable that takes (absolute_index, added_index) where absolute_index is
-- the index from 1 to the highest research tier (including vanilla research at the beginning), and
-- added_index is the index from 1 to to (highest research tier - number of vanilla researches)
-- mod_func should return overwrites for the clone_existing_data function (generally the effects={} table)
local function add_research_tiers(tech_name, tiers, final_resource_count, mod_func)
local base_tech = nil
local highest = nil
local escaped_tech_name = string.gsub(tech_name, "([^%w])", "%%%1")
local pattern = string.format('^%s%%-(%%d+)$', escaped_tech_name)

-- find the highest level of this tech to base everything else off of (icon, etc)
for _, raw_tech in pairs(data.raw.technology) do
-- lua only has psuedo-regex with very limited power (see http://lua-users.org/wiki/PatternsTutorial)
if(raw_tech.name == tech_name) then
if(highest == nil) then
base_tech = raw_tech
highest = 1
end
else
local m = string.match(raw_tech.name, pattern)

if(m ~= nil) then
m = tonumber(m)

if(highest == nil or m > highest) then
base_tech = raw_tech
highest = m
end
end
end
end

local add_tiers = tiers - highest

if(add_tiers <= 0) then
error(string.format('Tech "%s" already has at least %d tiers', tech_name, tiers))
end

-- we get one extra to start costs off at the existing value
local costs = quadratrix(base_tech.unit.count, final_resource_count, add_tiers+1)
local added = 1

for i=1, add_tiers do
local replace = mod_func(i+highest, i)
local prev = i+highest-1

if(prev ~= 1) then
prev = string.format('%s-%d', tech_name, prev)
else
prev = tech_name
end

replace = clone_existing_data(replace, {
['__partial__'] = true,
['name'] = string.format('%s-%d', tech_name, i+highest),
['prerequisites'] = {prev},
['unit'] = {
count = costs[i+1],
time = 15,
},
})
-- unit should always be partial when cloning onto the tech tree
replace['unit']['__partial__'] = true

local add = {clone_existing_data(base_tech, replace)}

data:extend(add)
end
end

-----------------------

add_research_tiers('gun-turret-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "turret-attack",
turret_id = "gun-turret",
modifier = 0.25, --+ (0.1 * added_index),
}
},
}
end)

add_research_tiers('bullet-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "bullet",
modifier = 0.35,
}
},
}
end)

add_research_tiers('bullet-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "gun-speed",
ammo_category = "bullet",
modifier = 0.3,
}
},
}
end)

add_research_tiers('laser-turret-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "laser-turret",
modifier = 0.3,
}
},
}
end)

add_research_tiers('laser-turret-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "gun-speed",
ammo_category = "laser-turret",
modifier = 0.3,
}
},
}
end)

add_research_tiers('combat-robot-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "combat-robot-laser",
modifier = 0.3,
},
{
type = "ammo-damage",
ammo_category = "combat-robot-beam",
modifier = 0.3,
},
},
}
end)

add_research_tiers('worker-robots-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "worker-robot-speed",
modifier = 0.5,
}
},
}
end)

add_research_tiers('worker-robots-storage', 20, 25000, function(index, added_index)
if(index <= 10) then
modifierLevel = 2
elseif(index <= 15) then
modifierLevel = 3
elseif(index <= 20) then
modifierLevel = 4
else
error('wat')
end

return {
effects = {
{
type = "worker-robot-storage",
modifier = modifierLevel,
}
},
}
end)

add_research_tiers('shotgun-shell-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "shotgun-shell",
modifier = 0.3,
}
},
}
end)

add_research_tiers('shotgun-shell-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "gun-speed",
ammo_category = "shotgun-shell",
modifier = 0.25,
}
},
}
end)

add_research_tiers('flamethrower-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "flame-thrower",
modifier = 0.35,
},
{
type = "turret-attack",
turret_id = "flamethrower-turret",
modifier = 0.35,
}
},
}
end)

add_research_tiers('grenade-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "grenade",
modifier = 0.2,
}
},
}
end)

add_research_tiers('rocket-damage', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "ammo-damage",
ammo_category = "rocket",
modifier = 0.2,
}
},
}
end)

add_research_tiers('rocket-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "gun-speed",
ammo_category = "rocket",
modifier = 0.4,
}
},
}
end)

add_research_tiers('research-speed', 20, 25000, function(index, added_index)
return {
effects = {
{
type = "laboratory-speed",
modifier = 0.5 + (0.1 * index),
}
},
}
end)
9 changes: 9 additions & 0 deletions Extended_Research_1.0.0/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Extended_Research",
"version": "1.0.0",
"title": "Extended_Research",
"author": "Sirenfal",
"description": "Adds much longer research paths",
"dependencies": ["base >= 0.14.0"],
"factorio_version": "0.14.0"
}
62 changes: 62 additions & 0 deletions Extended_Research_1.0.0/ir_util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require('util')

function ms_to_ticks(ms)
return math.ceil(ms / (1000 / 60))
end

local function _clone_onto(source, override, partial)
local partial = partial or false

if(override['__partial__'] ~= nil) then
partial = true
override['__partial__'] = nil
else
return override
end

-- TODO: handle numeric-only arrays specially here (merge properly if partial)

for k,v in pairs(override) do
if(source[k] ~= nil and type(source[k]) == 'table') then
source[k] = _clone_onto(source[k], v, true)
else
-- __partial__ will leak for tables here, but who cares?
source[k] = v
end
end

return source
end

-- each key will fully replace that key unless __partial__ is in the table, in which case
-- it will be merged with any keys from this table replacing keys in the source table
-- partial true/false is recursive after each occurence
function clone_existing_data(entry, data)
if(entry == nil) then
error('Tried to clone non-existant data key')
end

local new = table.deepcopy(entry)
local partial = data['__partial__'] ~= nil
data['__partial__'] = true

return _clone_onto(new, data, partial)
end

-- thanks ecx
function quadratrix(start, final, count)
if(not (final > start)) then
error('Final must be higher than start')
end

local ret = {start}
local multiplier = (final - start) / ((count - 1) ^ 2)

for i=2, count-1 do
table.insert(ret, math.floor(multiplier * ((i-1) ^ 2) + start))
end

table.insert(ret, final)

return ret
end
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 avosirenfal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 1d18126

Please sign in to comment.