commit 727668b63ec000e170d4418096f9c7c7e5634272 Author: npc-strider Date: Mon Aug 24 19:00:26 2020 +0800 0.1.0: Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84b6122 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pdn diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..fb45781 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 npc_strider + +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. \ No newline at end of file diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 0000000..8ef79f7 --- /dev/null +++ b/changelog.txt @@ -0,0 +1,5 @@ +--------------------------------------------------------------------------------------------------- +Version: 0.1.0 +Date: 2020-08-24 + Features: + - Initial release \ No newline at end of file diff --git a/clean_changelog.sh b/clean_changelog.sh new file mode 100644 index 0000000..ac7ed5d --- /dev/null +++ b/clean_changelog.sh @@ -0,0 +1,2 @@ +sed -i -e 's/\t/ /g' -e 's/\s*$//' changelog.txt +#from factorioforums: https://forums.factorio.com/viewtopic.php?f=25&t=67140 \ No newline at end of file diff --git a/control.lua b/control.lua new file mode 100644 index 0000000..e7e2c8b --- /dev/null +++ b/control.lua @@ -0,0 +1,204 @@ + +local util = require("util") +local crash_site = require("crash-site") + +local ship_parts = +{ + { + name = "crash-site-assembling-machine", + variations = 2, + angle_deviation = 0.07, + max_distance = 40, + min_separation = 16, + fire_count = 1 + }, + { + name = "crash-site-lab-repaired", + angle_deviation = 0.07, + max_distance = 15, + fire_count = 0 + }, + { + name = "crash-site-generator", + angle_deviation = 0.06, + max_distance = 15, + fire_count = 0 + }, + { + name = "crash-site-chest", + variations = 2, + angle_deviation = 0.075, + max_distance = 40, + min_separation = 16, + fire_count = 0 + } +} + +local random = math.random + +local rotate = function(offset, angle) + local x = offset[1] + local y = offset[2] + local rotated_x = x * math.cos(angle) - y * math.sin(angle) + local rotated_y = x * math.sin(angle) + y * math.cos(angle) + return {rotated_x, rotated_y} +end + +local get_name = function(part, k) + if not part.variations then return part.name end + local variant = k or random(part.variations) + return part.name.."-"..variant +end + +local get_lifetime = function(offset) + --Generally, close to the ship, last longer. + local distance = ((offset[1] * offset[1]) + (offset[2] * offset[2])) ^ 0.5 + local time = random(60 * 20, 60 * 30) - math.min(distance * 100, 15 * 60) + return time +end + +local get_random_position = function(box, x_scale, y_scale) + local x_scale = x_scale or 1 + local y_scale = y_scale or 1 + local x1 = box.left_top.x + local y1 = box.left_top.y + local x2 = box.right_bottom.x + local y2 = box.right_bottom.y + local x = ((x2 - x1) * x_scale * (random() - 0.5)) + ((x1 + x2) / 2) + local y = ((y2 - y1) * y_scale * (random() - 0.5)) + ((y1 + y2) / 2) + return {x, y} +end + +local entry_angle = 0.70 +local random = math.random +local get_offset = function(part) + local angle = entry_angle + ((random() - 0.5) * part.angle_deviation) + angle = angle - 0.25 + angle = angle * math.pi * 2 + local distance = 8 + (random() * (part.max_distance or 40)) + local offset = rotate({distance, 0}, angle) + return offset +end + +script.on_init(function() + if remote.interfaces.freeplay then + remote.call("freeplay", "set_disable_crashsite", false) -- That's the point of this mod... to have a crashsite, so we're force enabling it + end +end) + + +script.on_event(defines.events.on_player_created, function(event) + if not global.init_ran then + global.init_ran = true + + if remote.interfaces.freeplay then + -- game.print("FREEPLAY") + local player = game.players[event.player_index] + local surface = player.surface + local sps = surface.find_entities_filtered{position = player.force.get_spawn_position(surface), radius = 250, name = "crash-site-spaceship"} -- Just to confirm the spaceship loc + local position = sps[1].position + + local wreck_parts = {} + + for k, part in pairs (ship_parts) do + for k = 1, (part.variations or 1) do + local name = get_name(part, k) + if game.entity_prototypes[name.."-repaired-player"] then + name=name.."-repaired-player" + else + name=name.."-player" + end + -- local name_ = get_name(part, k, "-repaired") + for i = 1, part.repeat_count or 1 do + + local part_position + local count = 0 + local offset + while true do + offset = get_offset(part) + local x = (position[1] or position.x) + offset[1] + local y = (position[2] or position.y) + offset[2] + part_position = {x, y} + if surface.can_place_entity + { + name = name, + position = part_position, + force = "player", + build_check_type = defines.build_check_type.ghost_place, + forced = true + } then + -- game.print(count.. " " .. k .. " " .. surface.count_entities_filtered{position = part_position, radius = part.min_separation, limit = 1, type = game.entity_prototypes[name_].type}) + + if not part.min_separation then + break + elseif surface.count_entities_filtered{position = part_position, radius = part.min_separation, limit = 1, type = game.entity_prototypes[name].type} == 0 then + break + else + end + end + count = count + 1 + if count > 40 then + part_position = surface.find_non_colliding_position(name, part_position, 50, 4) + break + end + end + + if part_position then + local entity = surface.create_entity({ + name = name, + position = part_position, + force = "player" + }) + -- Something dumb happening with simple-entity and a position that is not constant. Have to use repaired variant of entity! + + local type = game.entity_prototypes[name].type + if type == "assembling-machine" then + entity.health = entity.health/6 + elseif type == "lab" then + entity.health = entity.health/1.5 + elseif type == "container" then + local count = random(0,2) + if count > 0 then + entity.insert({name="repair-pack",count=count}) + end + end + + if entity.get_output_inventory() and #entity.get_output_inventory() > 0 then + wreck_parts[entity.unit_number] = entity + end + + for k, entity in pairs (surface.find_entities_filtered{type = {"tree", "simple-entity"}, position = part_position, radius = 1 + entity.get_radius()}) do + if entity.type == "tree" then + entity.die() + else + entity.destroy() + end + end + + if part.fire_count then + for k = 1, part.fire_count do + surface.create_entity + { + name = "crash-site-fire-flame", + position = get_random_position(entity.bounding_box) + } + local explosions = surface.create_entity + { + name = "crash-site-fire-smoke", + position = get_random_position(entity.bounding_box) + } + explosions.time_to_live = get_lifetime(offset) + explosions.time_to_next_effect = random(30) + end + end + + end + end + end + end + + else + -- game.print("NOT FREEPLAY") + end + end +end) diff --git a/crash_entities.txt b/crash_entities.txt new file mode 100644 index 0000000..6b23364 --- /dev/null +++ b/crash_entities.txt @@ -0,0 +1,11 @@ +crash-site-spaceship-wreck-small-{1..6} +crash-site-spaceship-wreck-medium-{1..3} +crash-site-spaceship-wreck-big-{1,2} +crash-site-spaceship +crash-site-chest-{1,2} GOOD +crash-site-generator YES +--- crash-site-electric-pole NO DO NOT PUT THIS ONE IN (INVISIBLE POLES) +crash-site-assembling-machine-{1,2}-repaired GOOD +crash-site-assembling-machine-{1,2}-broken GOOD +crash-site-lab-repaired GOOD +crash-site-lab-broken GOOD \ No newline at end of file diff --git a/data.lua b/data.lua new file mode 100644 index 0000000..cd9862d --- /dev/null +++ b/data.lua @@ -0,0 +1,75 @@ +--[[ Copyright (c) 2020 npc_strider + * For direct use of code or graphics, credit is appreciated. See LICENSE.txt for more information. + * This mod may contain modified code sourced from base/core Factorio + * + * data.lua + * Recipes!! +--]] + +require("util") + +local function make_wreck_item(name,order) + return { + type = "item", + name = name.."-player", + icon = "__base__/graphics/icons/"..name..".png", + icon_size = 64, icon_mipmaps = 4, + subgroup = "crash-site", + order = "z[crash-site-spaceship]-"..order, + place_result = name.."-player", + stack_size = 1, + flags = {"hidden"} + } +end + +local entity = { + {"crash-site-generator","electric-energy-interface"}, + {"crash-site-lab-repaired","lab"} +} + +for i=1,2 do + entity[#entity+1] = {"crash-site-assembling-machine-"..i.."-repaired","assembling-machine"} + entity[#entity+1] = {"crash-site-chest-"..i,"container"} +end + +for i=1, #entity do + local e = entity[i] + local newname = e[1].."-player" + + local entity_player = util.table.deepcopy(data.raw[e[2]][e[1]]) + entity_player.name = newname + + if e[1] == "crash-site-generator" then + entity_player.energy_source = { + type = "electric", + buffer_capacity = "2.5MJ", + usage_priority = "tertiary", + input_flow_limit = "0kW", + output_flow_limit = "200kW" + } + entity_player.energy_production = "200kW" + entity_player.energy_usage = "0kW" + end + + entity_player.flags = {"placeable-neutral", "placeable-player", "player-creation", "not-rotatable"} -- I think all of them aren't rotatable - need to check some time + entity_player.localised_name = {"entity-name."..e[1]} + if entity_player.minable and not entity_player.minable.result then + entity_player.minable.result = newname + else + entity_player.minable = {mining_time = 0.2, result = newname} + end + + + local split = {} + for match in (newname.."-"):gmatch("(.-)-") do + split[#split+1] = match + end + + local item_player + + item_player = util.table.deepcopy(data.raw["item"][e[1]]) + item_player.name = newname + item_player.place_result = newname + + data:extend({entity_player,item_player}) +end \ No newline at end of file diff --git a/info.json b/info.json new file mode 100644 index 0000000..5719c4e --- /dev/null +++ b/info.json @@ -0,0 +1,11 @@ +{ + "name": "Extended_Crashsite", + "version": "0.1.0", + "factorio_version": "1.0", + "title": "Extended crash site", + "author": "npc_strider(morley376)", + "contact": "", + "homepage": "http://steamcommunity.com/id/morley376", + "dependencies": ["base >= 1.0.0"], + "description": "The crash site now has basic assemblers, lab, fuel cell and containers from the spaceship" +} \ No newline at end of file diff --git a/make.sh b/make.sh new file mode 100644 index 0000000..e6ec95a --- /dev/null +++ b/make.sh @@ -0,0 +1,6 @@ +v=$(grep "\"version\"" info.json | sed 's|.*:||;s|[",]||g;s| ||g') +n=$(grep "\"name\"" info.json | sed 's|.*:||;s|[",]||g;s| ||g') +#echo ${n}_${v}.zip + +powershell -c "\$files = Get-ChildItem -Path . -Exclude .git,*.sh,.pdn,.gitignore +Compress-Archive -Path \$files -DestinationPath ../${n}_${v}.zip" \ No newline at end of file diff --git a/thumbnail.png b/thumbnail.png new file mode 100644 index 0000000..2424699 Binary files /dev/null and b/thumbnail.png differ