diff --git a/config/advanced_starting_items.lua b/config/advanced_starting_items.lua new file mode 100644 index 00000000..0847ac6d --- /dev/null +++ b/config/advanced_starting_items.lua @@ -0,0 +1,90 @@ +--- This file is used to setup the map starting settings and the items players will start with + +--- These are called factories because they return another function +-- use these as a simple methods of adding new items +-- they will do most of the work for you +-- ['item-name']=factory(params) + +-- Use these to adjust for ticks ie game.tick < 5*minutes +local seconds, minutes, hours = 60, 3600, 216000 + +--- Use to make a split point for the number of items given based on time +-- ['stone-furnace']=cutoff_time(5*minutes,4,0) -- before 5 minutes give four items after 5 minutes give none +local function cutoff_time(time,before,after) + return function(amount_made,items_made,player) + if game.tick < time then return before + else return after + end + end +end + +--- Use to make a split point for the number of items given based on amount made +-- ['firearm-magazine']=cutoff_amount_made(100,10,0) -- give 10 items until 100 items have been made +local function cutoff_amount_made(amount,before,after) + return function(amount_made,items_made,player) + if amount_made < amount then return before + else return after + end + end +end + +--- Same as above but will not give any items if x amount has been made of another item, useful for tiers +-- ['light-armor']=cutoff_amount_made_unless(5,0,1,'heavy-armor',5) -- give light armor once 5 have been made unless 5 heavy armor has been made +local function cutoff_amount_made_unless(amount,before,after,second_item,second_amount) + return function(amount_made,items_made,player) + if items_made(second_item) < second_amount then + if amount_made < amount then return before + else return after + end + else return 0 + end + end +end + +-- Use for mass production items where you want the amount to change based on the amount already made +-- ['iron-plate']=scale_amount_made(5*minutes,10,10) -- for first 5 minutes give 10 items then after apply a factor of 10 +local function scale_amount_made(amount,before,scalar) + return function(amount_made,items_made,player) + if amount_made < amount then return before + else return (amount_made*scalar)/math.pow(game.tick/minutes,2) + end + end +end + +--[[ + Common values + game.tick is the amount of time the game has been on for + amount_made is the amount of that item which has been made + items_made('item-name') will return the amount of any item made + player is the player who just spawned + hours, minutes, seconds are the number of ticks in each unit of time +]] + +return { + skip_intro=true, -- skips the intro given in the default factorio free play scenario + friendly_fire=false, -- weather players will be able to attack each other on the same force + enemy_expansion=false, -- a catch all for in case the map settings file fails to load + chart_radius=10*32, -- the number of tiles that will be charted when the map starts + items = { -- items and there condition for being given + -- ['item-name'] = function(amount_made,production_stats,player) return end -- 0 means no items given + -- Plates + ['iron-plate']=scale_amount_made(100,10,10), + ['copper-plate']=scale_amount_made(100,0,8), + ['steel-plate']=scale_amount_made(100,0,4), + -- Secondary Items + ['electronic-circuit']=scale_amount_made(1000,0,6), + ['iron-gear-wheel']=scale_amount_made(1000,0,6), + -- Starting Items + ['burner-mining-drill']=cutoff_time(5*minutes,4,0), + ['stone-furnace']=cutoff_time(5*minutes,4,0), + -- Armor + ['light-armor']=cutoff_amount_made_unless(5,0,1,'heavy-armor',5), + ['heavy-armor']=cutoff_amount_made(5,0,1), + -- Weapon + ['pistol']=cutoff_amount_made_unless(0,1,1,'submachine-gun',5), + ['submachine-gun']=cutoff_amount_made(5,0,1), + -- Ammo + ['firearm-magazine']=cutoff_amount_made_unless(100,10,0,'piercing-rounds-magazine',100), + ['piercing-rounds-magazine']=cutoff_amount_made(100,0,10), + } +} \ No newline at end of file diff --git a/config/file_loader.lua b/config/file_loader.lua index db6b68bc..ee4cc877 100644 --- a/config/file_loader.lua +++ b/config/file_loader.lua @@ -17,7 +17,8 @@ return { -- QoL Addons 'modules.addons.chat-popups', 'modules.addons.damage-popups', - 'modules.addons.death-markers', + 'modules.addons.death-logger', + 'modules.addons.advanced-starting-items', -- Config Files 'config.command_auth_admin', -- commands tagged with admin_only are blocked for non admins 'config.command_auth_runtime_disable', -- allows commands to be enabled and disabled during runtime diff --git a/modules/addons/advanced-starting-items.lua b/modules/addons/advanced-starting-items.lua new file mode 100644 index 00000000..f402e5dc --- /dev/null +++ b/modules/addons/advanced-starting-items.lua @@ -0,0 +1,34 @@ +--- Adds a better method of player starting items based on production levels. +local Event = require 'utils.event' +local Game = require 'utils.game' +local config = require 'config.advanced_starting_items' +local items = config.items + +Event.add(defines.events.on_player_created, function(event) + local player = Game.get_player_by_index(event.player_index) + -- game init settings + if event.player_index == 1 then + player.force.friendly_fire = config.friendly_fire + game.map_settings.enemy_expansion.enabled = config.enemy_expansion + local r = config.chart_radius + local p = player.position + player.force.chart(player.surface, {{p.x-r, p.y-r}, {p.x+r, p.y+r}}) + end + -- spawn items + for item,callback in pairs(items) do + if type(callback) == 'function' then + local stats = player.force.item_production_statistics + local made = stats.get_input_count(item) + local success,count = pcall(callback,made,stats.get_input_count,player) + if success and count > 0 then + player.insert{name=item,count=count} + end + end + end +end) + +Event.on_init(function() + remote.call('freeplay','set_created_items',{}) + remote.call('freeplay','set_chart_distance',0) + remote.call('freeplay','set_skip_intro',config.skip_intro) +end) \ No newline at end of file diff --git a/modules/factorio-control.lua b/modules/factorio-control.lua index 147dfb14..13557506 100644 --- a/modules/factorio-control.lua +++ b/modules/factorio-control.lua @@ -40,6 +40,14 @@ Event.add(defines.events.on_player_created, function(event) local r = global.chart_distance or 200 player.force.chart(player.surface, {{player.position.x - r, player.position.y - r}, {player.position.x + r, player.position.y + r}}) + if not global.skip_intro then + if game.is_multiplayer() then + player.print({"msg-intro"}) + else + game.show_message_dialog{text = {"msg-intro"}} + end + end + silo_script.on_event(event) end) diff --git a/old/modules/AdvancedStartingItems/control.lua b/old/modules/DONE/AdvancedStartingItems/control.lua similarity index 100% rename from old/modules/AdvancedStartingItems/control.lua rename to old/modules/DONE/AdvancedStartingItems/control.lua diff --git a/old/modules/AdvancedStartingItems/softmod.json b/old/modules/DONE/AdvancedStartingItems/softmod.json similarity index 100% rename from old/modules/AdvancedStartingItems/softmod.json rename to old/modules/DONE/AdvancedStartingItems/softmod.json