1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-28 23:06:38 +02:00

Expanse updated to 2.0 - vanilla

This commit is contained in:
hanakocz 2024-10-09 21:35:16 +02:00 committed by Gerkiz
parent 351dbd2c16
commit de9c9bb03b
4 changed files with 76 additions and 58 deletions

View File

@ -39,12 +39,12 @@ local function reward_tokens(expanse, entity)
if chance > 0 then
chance = math.floor(chance * 1000)
if math.random(1, 1000) <= chance then
entity.surface.spill_item_stack(entity.position, { name = 'coin', count = 1 }, true, nil, false)
entity.surface.spill_item_stack({position = entity.position, stack = { name = 'coin', count = 1 }, enable_looted = true, allow_belts = false})
end
end
if count > 0 then
for _ = 1, count, 1 do
entity.surface.spill_item_stack(entity.position, { name = 'coin', count = 1 }, true, nil, false)
entity.surface.spill_item_stack({position = entity.position, stack = { name = 'coin', count = 1 }, enable_looted = true, allow_belts = false})
end
end
end
@ -102,7 +102,7 @@ local function get_left_top(expanse, position)
local surface = game.surfaces.expanse
for _, v in pairs(vectors) do
local tile = surface.get_tile({ position.x + v[1], position.y + v[2] })
local tile = surface.get_tile(position.x + v[1], position.y + v[2])
if tile.name == 'out-of-map' then
local left_top = tile.position
left_top.x = left_top.x - left_top.x % expanse.square_size
@ -129,7 +129,7 @@ local function is_container_position_valid(expanse, position)
if
game.surfaces.expanse.count_entities_filtered(
{
name = 'logistic-chest-requester',
name = 'requester-chest',
force = 'neutral',
area = { { left_top.x - 1, left_top.y - 1 }, { left_top.x + expanse.square_size + 1, left_top.y + expanse.square_size + 1 } }
}
@ -146,33 +146,37 @@ local function create_costs_render(entity, name, offset)
rendering.draw_sprite {
sprite = 'virtual-signal/signal-grey',
surface = entity.surface,
target = entity,
target = {
entity = entity,
offset = { offset, -1.5 }
},
x_scale = 1.1,
y_scale = 1.1,
render_layer = '190',
target_offset = { offset, -1.5 },
only_in_alt_mode = true
}
local id2 =
rendering.draw_sprite {
sprite = 'item/' .. name,
surface = entity.surface,
target = entity,
target = {
entity = entity,
offset = { offset, -1.5 }
},
x_scale = 0.75,
y_scale = 0.75,
render_layer = '191',
target_offset = { offset, -1.5 },
only_in_alt_mode = true
}
return { id, id2 }
end
local function remove_one_render(container, key)
if rendering.is_valid(container.price[key].render[1]) then
rendering.destroy(container.price[key].render[1])
if container.price[key].render[1].valid then
container.price[key].render[1].destroy()
end
if rendering.is_valid(container.price[key].render[2]) then
rendering.destroy(container.price[key].render[2])
if container.price[key].render[2].valid then
container.price[key].render[2].destroy()
end
end
@ -183,7 +187,7 @@ local function remove_old_renders(container)
end
function Public.spawn_units(spawner)
local evolution = game.forces.enemy.evolution_factor
local evolution = game.forces.enemy.get_evolution_factor(spawner.surface)
local position = spawner.position
for i = 1, 4 + math.floor(8 * evolution), 1 do
local biter_roll = BiterRaffle.roll('mixed', evolution)
@ -197,7 +201,7 @@ function Public.get_item_tooltip(name)
end
function Public.invasion_numbers()
local evo = game.forces.enemy.evolution_factor
local evo = game.forces.enemy.get_evolution_factor(game.surfaces.expanse)
return { candidates = 3 + math.floor(evo * 10), groups = 1 + math.floor(evo * 4) }
end
@ -228,7 +232,7 @@ function Public.invasion_trigger(event)
local surface = event.surface
local position = event.position
local round = event.round
local evolution = game.forces.enemy.evolution_factor
local evolution = game.forces.enemy.get_evolution_factor(surface)
local biters = {}
for i = 1, 5 + math.floor(30 * evolution) + round * 5, 1 do
local biter_roll = BiterRaffle.roll('mixed', evolution)
@ -284,10 +288,10 @@ local function plan_invasion(expanse, invasion_numbers)
for ii = 1, rounds, 1 do
schedule_biters(expanse, surface, position, 120 + (ii - 1) * 300, ii)
end
rendering.set_time_to_live(candidates[i].render, 122 * 60 + rounds * 300)
candidates[i].render.time_to_live = ( 122 * 60 + rounds * 300)
end
for j = invasion_numbers.groups + 1, #candidates, 1 do
rendering.set_time_to_live(candidates[j].render, 122 * 60)
candidates[j].render.time_to_live = ( 122 * 60)
end
expanse.invasion_candidates = {}
end
@ -336,7 +340,7 @@ function Public.expand(expanse, left_top)
for _, position in pairs(positions) do
if is_container_position_valid(expanse, position) then
local e = surface.create_entity({ name = 'logistic-chest-requester', position = position, force = 'neutral' })
local e = surface.create_entity({ name = 'requester-chest', position = position, force = 'neutral' })
e.destructible = false
e.minable = false
end
@ -352,9 +356,9 @@ function Public.expand(expanse, left_top)
surface.create_entity({ name = 'crude-oil', position = { a - 4, a - 4 }, amount = 1500000 })
Task.set_timeout_in_ticks(30, delay_infini_tree_token, { surface = surface, position = { a - 4, a + 4 } })
surface.create_entity({ name = 'big-rock', position = { a + 4, a - 4 } })
surface.spill_item_stack({ a, a + 2 }, { name = 'coin', count = 1 }, false, nil, false)
surface.spill_item_stack({ a + 0.5, a + 2.5 }, { name = 'coin', count = 1 }, false, nil, false)
surface.spill_item_stack({ a - 0.5, a + 2.5 }, { name = 'coin', count = 1 }, false, nil, false)
surface.spill_item_stack({position = {a, a + 2}, stack = { name = 'coin', count = 1 }, enable_looted = false, allow_belts = false})
surface.spill_item_stack({position = { a + 0.5, a + 2.5 }, stack = { name = 'coin', count = 1 }, enable_looted = false, allow_belts = false})
surface.spill_item_stack({position = { a - 0.5, a + 2.5 }, stack = { name = 'coin', count = 1 }, enable_looted = false, allow_belts = false})
for x = 0, square_size, 1 do
for y = 0, square_size, 1 do
@ -404,7 +408,7 @@ local function get_remaining_budget(container)
end
function Public.set_container(expanse, entity)
if entity.name ~= 'logistic-chest-requester' then
if entity.name ~= 'requester-chest' then
return
end
if not expanse.containers[entity.unit_number] then
@ -420,8 +424,7 @@ function Public.set_container(expanse, entity)
local inventory = container.entity.get_inventory(defines.inventory.chest)
if not inventory.is_empty() then
local contents = inventory.get_contents()
if contents['coin'] then
if inventory.get_item_count('coin') > 0 then
local count_removed = inventory.remove({ name = 'coin', count = 1 })
if count_removed > 0 then
expanse.cost_stats['coin'] = (expanse.cost_stats['coin'] or 0) + count_removed
@ -432,7 +435,7 @@ function Public.set_container(expanse, entity)
game.print({ 'expanse.chest_reset', { 'expanse.gps', math.floor(entity.position.x), math.floor(entity.position.y), 'expanse' } })
end
end
if contents['infinity-chest'] then
if inventory.get_item_count('infinity-chest') > 0 then
remove_old_renders(container)
container.price = {}
end
@ -456,8 +459,11 @@ function Public.set_container(expanse, entity)
local expansion_position = { x = expanse.containers[entity.unit_number].left_top.x + a, y = expanse.containers[entity.unit_number].left_top.y + a }
expanse.containers[entity.unit_number] = nil
if not inventory.is_empty() then
for name, count in pairs(inventory.get_contents()) do
entity.surface.spill_item_stack(entity.position, { name = name, count = count }, true, nil, false)
for index = 1, #inventory, 1 do
local slot = inventory[index]
if slot.valid_for_read then
entity.surface.spill_item_stack({position = entity.position, stack = slot, enable_looted = true, allow_belts = false})
end
end
end
reward_tokens(expanse, entity)
@ -465,13 +471,21 @@ function Public.set_container(expanse, entity)
entity.die()
return expansion_position
end
for slot = 1, 30, 1 do
entity.clear_request_slot(slot)
local logi = container.entity.get_logistic_point(0)
for i = 1, 256, 1 do
if logi.get_section(i) then
logi.remove_section(i)
end
end
for slot, item_stack in pairs(container.price) do
container.entity.set_request_slot(item_stack, slot)
logi.add_section()
local section = logi.get_section(1)
for slot = 1, #container.price, 1 do
if #container.price >= slot then
local item = container.price[slot]
section.set_slot(slot, {value = item.name, min = item.count, import_from = 'nauvis'})
end
end
end

View File

@ -15,6 +15,7 @@ local Map_info = require 'modules.map_info'
local Gui = require 'utils.gui'
local format_number = require 'util'.format_number
local Autostash = require 'modules.autostash'
local FT = require 'utils.functions.flying_texts'
local expanse = {
events = {
@ -41,7 +42,7 @@ local function create_button(player)
{
type = 'sprite-button',
name = main_button_name,
sprite = 'item/logistic-chest-requester',
sprite = 'item/requester-chest',
tooltip = 'Show Expanse statistics!'
}
)
@ -236,6 +237,7 @@ local function container_opened(event)
if expansion_position then
local player = game.players[event.player_index]
local surface = game.get_surface(player.surface.name)
if not surface or not surface.valid then return end
local colored_player_name = { 'expanse.colored_text', player.color.r * 0.6 + 0.35, player.color.g * 0.6 + 0.35, player.color.b * 0.6 + 0.35, player.name }
game.print({ 'expanse.tile_unlock', colored_player_name, { 'expanse.gps', math.floor(expansion_position.x), math.floor(expansion_position.y), 'expanse' } })
expanse.size = (expanse.size or 1) + 1
@ -284,8 +286,8 @@ local function uranium_mining(entity)
local acid = tank.get_fluid_count('sulfuric-acid')
if acid > 5 then
tank.remove_fluid { name = 'sulfuric-acid', amount = 4 }
entity.surface.spill_item_stack(entity.position, { name = 'uranium-ore', count = 2 }, true, nil, true)
entity.surface.create_entity { name = 'flying-text', position = tank.position, text = '-4 [fluid=sulfuric-acid]', color = { r = 0.88, g = 0.02, b = 0.02 } }
entity.surface.spill_item_stack({position = entity.position, stack ={ name = 'uranium-ore', count = 2 }, enable_looted = true, allow_belts = true})
FT.flying_text(nil, entity.surface, tank.position, '-4 [fluid=sulfuric-acid]', { r = 0.88, g = 0.02, b = 0.02 })
end
end
end
@ -298,8 +300,8 @@ local function infini_rock(entity)
local a = math.floor(expanse.square_size * 0.5)
if entity.position.x == a + 4 and entity.position.y == a - 4 then
entity.surface.create_entity({ name = 'big-rock', position = { a + 4, a - 4 } })
entity.surface.spill_item_stack(entity.position, { name = inf_ores[math.random(1, 4)], count = math.random(80, 160) }, true, nil, true)
entity.surface.spill_item_stack(entity.position, { name = 'stone', count = math.random(5, 15) }, true, nil, true)
entity.surface.spill_item_stack({position = entity.position, stack ={ name = inf_ores[math.random(1, 4)], count = math.random(80, 160) }, enable_looted = true, allow_belts = true})
entity.surface.spill_item_stack({position = entity.position, stack = { name = 'stone', count = math.random(5, 15) }, enable_looted = true, allow_belts = true})
uranium_mining(entity)
end
end
@ -327,7 +329,7 @@ local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.online_time == 0 then
local surface = game.surfaces.expanse
player.teleport(surface.find_non_colliding_position('character', { expanse.square_size * 0.5, expanse.square_size * 0.5 }, 32, 0.5), surface)
player.teleport(surface.find_non_colliding_position('character', { expanse.square_size * 0.5, expanse.square_size * 0.5 }, 32, 0.5) or {0,0}, surface)
end
create_button(player)
end
@ -347,7 +349,7 @@ local function on_pre_player_left_game(event)
local removed_count = inventory.remove({ name = 'coin', count = 999999 })
if removed_count > 0 then
for _ = 1, removed_count, 1 do
player.surface.spill_item_stack(player.position, { name = 'coin', count = 1 }, false, nil, false)
player.surface.spill_item_stack({position = player.position, stack = { name = 'coin', count = 1 }, enable_looted = false, allow_belts = false})
end
game.print({ 'expanse.tokens_dropped', player.name, { 'expanse.gps', math.floor(player.position.x), math.floor(player.position.y), player.surface.name } })
end

View File

@ -50,15 +50,13 @@ local item_worths = {
['tank'] = 4096,
['logistic-robot'] = 256,
['construction-robot'] = 256,
['logistic-chest-active-provider'] = 256,
['logistic-chest-passive-provider'] = 256,
['logistic-chest-storage'] = 256,
['logistic-chest-buffer'] = 512,
['logistic-chest-requester'] = 512,
['active-provider-chest'] = 256,
['passive-provider-chest'] = 256,
['storage-chest'] = 256,
['buffer-chest'] = 512,
['requester-chest'] = 512,
['roboport'] = 2048,
['small-lamp'] = 16,
['red-wire'] = 4,
['green-wire'] = 4,
['arithmetic-combinator'] = 16,
['decider-combinator'] = 16,
['constant-combinator'] = 16,
@ -177,7 +175,7 @@ local item_worths = {
['power-armor'] = 4096,
['power-armor-mk2'] = 32768,
['solar-panel-equipment'] = 256,
['fusion-reactor-equipment'] = 8192,
['fission-reactor-equipment'] = 8192,
['energy-shield-equipment'] = 512,
['energy-shield-mk2-equipment'] = 4096,
['battery-equipment'] = 128,
@ -221,7 +219,7 @@ end
function Public.roll_item_stack(remaining_budget, blacklist, value_blacklist)
if remaining_budget <= 0 then
return
return false
end
local raffle_keys = get_raffle_keys()
local item_name = false
@ -259,9 +257,11 @@ local function roll_item_stacks(remaining_budget, max_slots, blacklist, value_bl
break
end
local item_stack = Public.roll_item_stack(remaining_budget, blacklist, value_blacklist)
item_stack_set[i] = item_stack
remaining_budget = remaining_budget - item_stack.count * item_worths[item_stack.name]
item_stack_set_worth = item_stack_set_worth + item_stack.count * item_worths[item_stack.name]
if item_stack then
item_stack_set[i] = item_stack
remaining_budget = remaining_budget - item_stack.count * item_worths[item_stack.name]
item_stack_set_worth = item_stack_set_worth + item_stack.count * item_worths[item_stack.name]
end
end
return item_stack_set, item_stack_set_worth
@ -269,10 +269,10 @@ end
function Public.roll(budget, max_slots, blacklist, value_blacklist)
if not budget then
return
return {}
end
if not max_slots then
return
return {}
end
local b, vb
@ -289,7 +289,7 @@ function Public.roll(budget, max_slots, blacklist, value_blacklist)
budget = math_floor(budget)
if budget == 0 then
return
return {}
end
local final_stack_set

View File

@ -3,6 +3,9 @@
local Event = require 'utils.event'
local Server = require 'utils.server'
local Global = require 'utils.global'
if script.active_mods['space-age'] then
error('Satellite Score Module can be used only while the Space Age mod is not enabled. (Most likely you try to run scenario not compatible with Space Age, try disabling it in Mods.)', 2)
end
local this = {}
Global.register(
@ -62,8 +65,7 @@ local function satellites_in_space_gui(player)
if progress > 1 then
progress = 1
end
local progressbar = frame.add({ type = 'progressbar', value = progress })
progressbar.style = 'achievement_progressbar'
local progressbar = frame.add({ type = 'progressbar', value = progress, style = 'achievement_progressbar' })
progressbar.style.minimal_width = 100
progressbar.style.maximal_width = 100
progressbar.style.height = 20
@ -81,7 +83,7 @@ local function satellites_in_space_gui(player)
end
local function on_rocket_launched(event)
local rocket_inventory = event.rocket.get_inventory(defines.inventory.rocket)
local rocket_inventory = event.rocket.cargo_pod.get_inventory(defines.inventory.cargo_unit)
local c = rocket_inventory.get_item_count('satellite')
if c == 0 then
return
@ -174,4 +176,4 @@ end
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_rocket_launched, on_rocket_launched)
Event.add(defines.events.on_rocket_launch_ordered, on_rocket_launched)