1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

Merge pull request #37 from ComfyFactory/cave_choppy_and_mtn_updates

Cave Choppy and Mtn Updates
This commit is contained in:
Gerkiz 2021-05-04 19:54:40 +02:00 committed by GitHub
commit 24636b0629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 370 additions and 33 deletions

View File

@ -143,8 +143,8 @@ require 'modules.autostash'
--require 'maps.railway_troopers.main'
--![[You fell in a dark cave, will you survive?]]--
--require 'maps.cave_choppy.main'
--require 'maps.cave_miner'
--require 'maps.cave_choppy.cave_miner'
--require 'maps.cave_miner_v2.main'
--![[Hungry boxes eat your items, but reward you with new territory to build.]]--

View File

@ -1,18 +1,16 @@
--luacheck: ignore
--choppy-- mewmew made this --
-- modified by gerkiz
-- By gerkiz
require 'modules.dynamic_landfill'
require 'modules.satellite_score'
require 'modules.spawners_contain_biters'
require 'functions.create_entity_chain'
require 'functions.create_tile_chain'
--require "maps.choppy_map_intro"
local unearthing_worm = require 'functions.unearthing_worm'
local unearthing_biters = require 'functions.unearthing_biters'
local tick_tack_trap = require 'functions.tick_tack_trap'
local Module = require 'modules.infinity_chest'
local Module = require 'infinity_chest'
local Simplex = require 'utils.simplex_noise'.d2
local Event = require 'utils.event'
local table_insert = table.insert

View File

@ -0,0 +1,265 @@
local Public = {}
local Event = require 'utils.event'
local Token = require 'utils.token'
local Gui = require 'utils.gui'
local Task = require 'utils.task'
local Global = require 'utils.global'
local format = string.format
local chests = {}
local chests_next = {}
Global.register(
{chests = chests, chests_next = chests_next},
function(tbl)
chests = tbl.chests
chests_next = tbl.chests_next
end
)
local chest_gui_frame_name = Gui.uid_name()
local chest_content_table_name = Gui.uid_name()
function Public.create_chest(surface, position, storage)
local entity = surface.create_entity {name = 'infinity-chest', position = position, force = 'neutral'}
chests[entity.unit_number] = {entity = entity, storage = storage}
return entity
end
local function built_entity(event)
local entity = event.created_entity
if not entity or not entity.valid or entity.name ~= 'infinity-chest' then
return
end
entity.active = false
chests[entity.unit_number] = {entity = entity, storage = {}}
end
local function get_stack_size(name)
local proto = game.item_prototypes[name]
if not proto then
log('item prototype ' .. name .. ' not found')
return 1
end
return proto.stack_size
end
local function do_item(name, count, inv, storage)
local size = get_stack_size(name)
local diff = count - size
if diff == 0 then
return
end
local new_amount = 0
if diff > 0 then
inv.remove({name = name, count = diff})
local prev = storage[name] or 0
new_amount = prev + diff
elseif diff < 0 then
local prev = storage[name]
if not prev then
return
end
diff = math.min(prev, -diff)
local inserted = inv.insert({name = name, count = diff})
new_amount = prev - inserted
end
if new_amount == 0 then
storage[name] = nil
else
storage[name] = new_amount
end
end
local function tick()
local chest_id, chest_data = next(chests, chests_next[1])
chests_next[1] = chest_id
if not chest_id then
return
end
local entity = chest_data.entity
if not entity or not entity.valid then
chests[chest_id] = nil
else
local storage = chest_data.storage
local inv = entity.get_inventory(1) --defines.inventory.chest
local contents = inv.get_contents()
for name, count in pairs(contents) do
do_item(name, count, inv, storage)
end
for name, _ in pairs(storage) do
if not contents[name] then
do_item(name, 0, inv, storage)
end
end
end
end
local function create_chest_gui_content(frame, player, chest)
local storage = chest.storage
local inv = chest.entity.get_inventory(1).get_contents()
local grid = frame[chest_content_table_name]
if grid then
grid.clear()
else
grid = frame.add {type = 'table', name = chest_content_table_name, column_count = 10, style = 'slot_table'}
end
for name, count in pairs(storage) do
local number = count + (inv[name] or 0)
grid.add {
type = 'sprite-button',
sprite = 'item/' .. name,
number = number,
tooltip = name,
--style = 'slot_button'
enabled = false
}
end
for name, count in pairs(inv) do
if not storage[name] then
grid.add {
type = 'sprite-button',
sprite = 'item/' .. name,
number = count,
tooltip = name,
--style = 'slot_button'
enabled = false
}
end
end
player.opened = frame
end
local chest_gui_content_callback
chest_gui_content_callback =
Token.register(
function(data)
local player = data.player
if not player or not player.valid then
return
end
local opened = data.opened
if not opened or not opened.valid then
return
end
local entity = data.chest.entity
if not entity.valid then
player.opened = nil
opened.destroy()
return
end
if not player.connected then
player.opened = nil
opened.destroy()
return
end
create_chest_gui_content(opened, player, data.chest)
Task.set_timeout_in_ticks(60, chest_gui_content_callback, data)
end
)
local function gui_opened(event)
if not event.gui_type == defines.gui_type.entity then
return
end
local entity = event.entity
if not entity or not entity.valid or entity.name ~= 'infinity-chest' then
return
end
local chest = chests[entity.unit_number]
if not chest then
return
end
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local frame =
player.gui.center.add {
type = 'frame',
name = chest_gui_frame_name,
caption = 'Infinite Storage Chest',
direction = 'vertical'
}
local text =
frame.add {
type = 'label',
caption = format(
'This chest stores unlimited quantity of items (up to 48 different item types).\nThe chest is best used with an inserter to add / remove items.\nIf the chest is mined or destroyed the items are lost.'
)
}
text.style.single_line = false
local content_header = frame.add {type = 'label', caption = 'Content'}
content_header.style.font = 'default-listbox'
create_chest_gui_content(frame, player, chest)
Task.set_timeout_in_ticks(60, chest_gui_content_callback, {player = player, chest = chest, opened = frame})
end
Event.add(defines.events.on_built_entity, built_entity)
Event.add(defines.events.on_robot_built_entity, built_entity)
Event.add(defines.events.on_tick, tick)
Event.add(defines.events.on_gui_opened, gui_opened)
Event.add(
defines.events.on_player_died,
function(event)
local player = game.get_player(event.player_index or 0)
if not player or not player.valid then
return
end
local element = player.gui.center
if element and element.valid then
element = element[chest_gui_frame_name]
if element and element.valid then
element.destroy()
end
end
end
)
Gui.on_custom_close(
chest_gui_frame_name,
function(event)
event.element.destroy()
end
)
return Public

View File

@ -1,22 +1,15 @@
--luacheck: ignore
-- Cave Miner -- mewmew made this --
-- modified by Gerkiz --
-- By Gerkiz
require 'choppy'
require 'forest_world'
require 'player_elevator'
require 'modules.rocks_broken_paint_tiles'
require 'cave_miner_kaboomsticks'
--require "modules.satellite_score"
--require "modules.explosive_biters"
--require "modules.spawners_contain_biters"
--require "modules.teleporting_worms"
--require "modules.splice_double"
--require "modules.biters_double_damage"
local enable_fishbank_terminal = true
local simplex_noise = require 'utils.simplex_noise'.d2
local Event = require 'utils.event'
local Module = require 'modules.infinity_chest'
local Module = require 'infinity_chest'
local market_items = require 'cave_miner_market_items'
local Map = require 'modules.map_info'
@ -1914,6 +1907,14 @@ local function on_market_item_purchased(event)
end
end
local function disable_tech()
game.forces.player.technologies['spidertron'].enabled = false
game.forces.player.technologies['spidertron'].researched = false
game.forces.player.technologies['optics'].researched = true
game.forces.player.technologies['artillery'].researched = false
game.forces.player.technologies['atomic-bomb'].enabled = false
end
local function on_init()
local T = Map.Pop_info()
T.main_caption = 'Cave Choppy'
@ -1951,6 +1952,8 @@ local function on_init()
]])
T.main_caption_color = {r = 150, g = 150, b = 0}
T.sub_caption_color = {r = 0, g = 150, b = 0}
disable_tech()
end
Event.on_init(on_init)

View File

@ -13,11 +13,13 @@ local fallout_width = 64
local fallout_debris = {}
for x = fallout_width * -1 - 32, fallout_width + 32, 1 do
for y = fallout_width * -1 - 32, fallout_width + 32, 1 do
local position = {x = x, y = y}
local fallout = sqrt(position.x ^ 2 + position.y ^ 2)
if fallout > fallout_width then
fallout_debris[#fallout_debris + 1] = {position.x, position.y}
if x < -31 or x > 31 then
for y = fallout_width * -1 - 32, fallout_width + 32, 1 do
local position = {x = x, y = y}
local fallout = sqrt(position.x ^ 2 + position.y ^ 2)
if fallout > fallout_width then
fallout_debris[#fallout_debris + 1] = {position.x, position.y}
end
end
end
end
@ -32,7 +34,7 @@ local reconstruct_all_trains =
)
local function get_tile_name()
local main_tile_name = 'tutorial-grid'
local main_tile_name = 'black-refined-concrete'
local modded = is_game_modded()
if modded then
if game.active_mods['Krastorio2'] then
@ -200,6 +202,50 @@ local function input_filtered(wagon_inventory, chest, chest_inventory, free_slot
end
end
local remove_lights_token =
Token.register(
function(data)
local id = data.id
if id then
rendering.destroy(id)
end
end
)
function Public.glimpse_of_lights(icw)
local surface = WPT.get('loco_surface')
if not surface or not surface.valid then
return
end
local hazardous_debris = icw.hazardous_debris
if not hazardous_debris then
return
end
local text = rendering.draw_text
local position = fallout_debris[random(1, size_of_debris)]
local p = {x = position[1], y = position[2]}
local get_tile = surface.get_tile(p)
if get_tile.valid and get_tile.name == 'out-of-map' then
local id =
text {
text = '',
surface = surface,
target = position,
color = {r = 1, g = 1, b = 0},
orientation = random(0, 100) * 0.01,
scale = 0.4,
font = 'heading-1',
alignment = 'center',
scale_with_zoom = false
}
Task.set_timeout_in_ticks(300, remove_lights_token, {id = id})
end
end
function Public.hazardous_debris(icw)
local speed = icw.speed
local surface = WPT.get('loco_surface')
@ -214,15 +260,6 @@ function Public.hazardous_debris(icw)
local create = surface.create_entity
for _ = 1, 16 * speed, 1 do
local position = fallout_debris[random(1, size_of_debris)]
local p = {x = position[1], y = position[2]}
local get_tile = surface.get_tile(p)
if get_tile.valid and get_tile.name == 'out-of-map' then
create({name = 'blue-laser', position = position, force = 'neutral', target = {position[1], position[2] + fallout_width * 2}, speed = speed})
end
end
for _ = 1, 16 * speed, 1 do
local position = fallout_debris[random(1, size_of_debris)]
local p = {x = position[1], y = position[2]}

View File

@ -97,6 +97,7 @@ local function on_tick()
if tick % 10 == 0 then
Functions.item_transfer(icw)
Functions.hazardous_debris(icw)
Functions.glimpse_of_lights(icw)
end
if tick % 240 == 0 then
Functions.update_minimap(icw)

View File

@ -1084,7 +1084,7 @@ local function gui_click(event)
player.name .. ' has bought the locomotive health modifier for ' .. format_number(item.price, true) .. ' coins.'
}
)
this.locomotive_max_health = this.locomotive_max_health + 4000 * item.stack
this.locomotive_max_health = this.locomotive_max_health + (this.locomotive_max_health * 0.5 * item.stack)
local m = this.locomotive_health / this.locomotive_max_health
if this.carriages then

View File

@ -64,6 +64,10 @@ function Public.add(surface, position, chest)
container.insert({name = 'coin', count = random(1, 128)})
elseif random(1, 128) == 1 then
container.insert({name = 'coin', count = random(1, 256)})
elseif random(1, 256) == 1 then
container.insert({name = 'coin', count = random(1, 512)})
elseif random(1, 512) == 1 then
container.insert({name = 'coin', count = random(1, 1024)})
end
for _ = 1, 3, 1 do

View File

@ -734,6 +734,35 @@ function Public.global_pool(players, count)
return
end
local damage_player_over_time_token =
Token.register(
function(data)
local player = data.player
local damage = data.damage
if not player.character or not player.character.valid then
return
end
player.character.health = player.character.health - damage
player.character.surface.create_entity({name = 'water-splash', position = player.position})
end
)
--- Damages a player over time.
function Public.damage_player_over_time(player, amount, damage)
if not player or not player.valid then
return
end
amount = amount or 5
damage = damage or 10
local tick = 20
for _ = 1, amount, 1 do
Task.set_timeout_in_ticks(tick, damage_player_over_time_token, {player = player, damage = damage})
tick = tick + 15
damage = damage + 10
end
end
--- Distributes the global xp pool to every connected player.
function Public.distribute_pool()
local count = #game.connected_players

View File

@ -1098,8 +1098,8 @@ local function on_player_used_capsule(event)
elseif object.obj_to_create == 'warp-gate' then
player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface)
rpg_t[player.index].mana = 0
player.character.health = 10
player.character.surface.create_entity({name = 'water-splash', position = player.position})
Functions.damage_player_over_time(player, 10)
player.play_sound {path = 'utility/armor_insert', volume_modifier = 1}
p(({'rpg_main.warped_ok'}), Color.info)
rpg_t[player.index].mana = rpg_t[player.index].mana - object.mana_cost
elseif projectile_types[obj_name] then -- projectiles