1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-18 03:21:36 +02:00

cave_miner > globals to locals, fish bank disabled by default; anarchy mode map

This commit is contained in:
MewMew 2019-01-07 23:57:02 +01:00
parent 537854fcc2
commit 61ed82fee6
9 changed files with 690 additions and 148 deletions

View File

@ -19,14 +19,14 @@ require "score"
--require "maps.modules.launch_10000_fish_to_win"
--require "maps.modules.dynamic_landfill"
--require "maps.modules.restrictive_fluid_mining"
--require "maps.modules.fluids_are_explosive"
require "maps.modules.fluids_are_explosive"
--require "maps.modules.explosives_are_explosive"
--require "maps.modules.railgun_enhancer"
-----------------------------
---- enable maps here ----
--require "maps.biter_battles"
--require "maps.cave_miner"
require "maps.cave_miner"
--require "maps.labyrinth"
--require "maps.spooky_forest"
--require "maps.nightfall"
@ -35,11 +35,12 @@ require "score"
--require "maps.spiral_troopers"
--require "maps.fish_defender"
--require "maps.crossing"
--require "maps.anarchy" --WIP
--require "maps.spaghettorio"
--require "maps.deep_jungle"
--require "maps.lost_desert"
--require "maps.empty_map"
require "maps.custom_start"
--require "maps.custom_start"
-----------------------------
local Event = require 'utils.event'

View File

@ -172,6 +172,22 @@ local function on_gui_click(event)
local name = event.element.name
local frame = player.gui.left["group_frame"]
if name == "group_button" then
if frame then
frame.destroy()
else
build_group_gui(player)
end
end
if not event.element.valid then return end
if name == "close_group_frame" then
frame.destroy()
end
if not event.element.valid then return end
if not frame then return end
if name == "create_new_group" then
local new_group_name = frame.frame2.group_table.new_group_name.text
local new_group_description = frame.frame2.group_table.new_group_description.text
@ -243,19 +259,7 @@ local function on_gui_click(event)
return
end
end
end
if name == "group_button" then
if frame then
frame.destroy()
else
build_group_gui(player)
end
end
if name == "close_group_frame" then
frame.destroy()
end
end
end
Event.add(defines.events.on_gui_click, on_gui_click)

137
maps/anarchy.lua Normal file
View File

@ -0,0 +1,137 @@
--anarchy mode map -- by mewmew --
require "maps.anarchy_map_intro"
require "maps.modules.anarchy_mode"
local simplex_noise = require 'utils.simplex_noise'
simplex_noise = simplex_noise.d2
local event = require 'utils.event'
local table_insert = table.insert
local math_random = math.random
local map_functions = require "maps.tools.map_functions"
local function set_unique_player_force(player)
if not game.forces[player.name] then
game.create_force(player.name)
end
player.force = game.forces[player.name]
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not global.map_init_done then
game.map_settings.enemy_expansion.enabled = false
game.map_settings.enemy_evolution.time_factor = 0
game.map_settings.enemy_evolution.pollution_factor = 0
--game.map_settings.pollution.enabled = false
global.map_init_done = true
end
if player.online_time == 0 then
set_unique_player_force(player)
player.insert{name = 'iron-axe', count = 1}
player.insert{name = 'iron-plate', count = 32}
end
end
local function on_built_entity(event)
local entity = event.created_entity
if not entity.valid then return end
local distance_to_center = math.sqrt(entity.position.x^2 + entity.position.y^2)
if distance_to_center > 64 then return end
local surface = entity.surface
surface.create_entity({name = "flying-text", position = entity.position, text = "Spawn is protected from building.", color = {r=0.88, g=0.1, b=0.1}})
local player = game.players[event.player_index]
player.insert({name = entity.name, count = 1})
if global.score then
if global.score[player.force.name] then
if global.score[player.force.name].players[player.name] then
global.score[player.force.name].players[player.name].built_entities = global.score[player.force.name].players[player.name].built_entities - 1
end
end
end
entity.destroy()
end
local function on_chunk_generated(event)
local surface = event.surface
local left_top = event.area.left_top
--[[
local entities = surface.find_entities_filtered({area = event.area, force = "enemy"})
for _, entity in pairs(entities) do
entity.destroy()
end
local entities = {}
]]
for x = 0, 31, 1 do
for y = 0, 31, 1 do
local pos = {x = left_top.x + x, y = left_top.y + y}
if math_random(1, 50000) == 1 then
map_functions.draw_entity_circle(pos, "stone", surface, 6, true, 1000000)
map_functions.draw_entity_circle(pos, "coal", surface, 12, true, 1000000)
map_functions.draw_entity_circle(pos, "copper-ore", surface, 18, true, 1000000)
map_functions.draw_entity_circle(pos, "iron-ore", surface, 24, true, 1000000)
map_functions.draw_noise_tile_circle(pos, "water", surface, 4)
end
--[[
if math_random(1, 75000) == 1 and pos.x^2 + pos.y^2 > 60000 then
if surface.can_place_entity({name = "biter-spawner", position = pos}) then
if math_random(1, 4) == 1 then
table_insert(entities, {name = "spitter-spawner", position = pos})
else
table_insert(entities, {name = "biter-spawner", position = pos})
end
end
end
]]
end
end
--[[
for _, entity in pairs(entities) do
surface.create_entity(entity)
end
]]
if not global.spawn_generated and left_top.x <= -96 then
map_functions.draw_noise_tile_circle({x = 0, y = 0}, "stone-path", surface, 33)
map_functions.draw_noise_tile_circle({x = 0, y = 0}, "concrete", surface, 11)
global.spawn_generated = true
end
end
local function on_player_respawned(event)
local player = game.players[event.player_index]
player.insert{name = 'iron-axe', count = 1}
player.insert{name = 'iron-plate', count = 32}
end
----------share chat -------------------
local function on_console_chat(event)
if not event.message then return end
if not event.player_index then return end
local player = game.players[event.player_index]
local color = {}
color = player.color
color.r = color.r * 0.6 + 0.35
color.g = color.g * 0.6 + 0.35
color.b = color.b * 0.6 + 0.35
color.a = 1
for _, target_player in pairs(game.connected_players) do
if target_player.name ~= player.name then
if target_player.force ~= player.force then
target_player.print(player.name .. ": ".. event.message, color)
end
end
end
end
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_console_chat, on_console_chat)
event.add(defines.events.on_player_respawned, on_player_respawned)
event.add(defines.events.on_built_entity, on_built_entity)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_chunk_generated, on_chunk_generated)

View File

@ -0,0 +1,59 @@
local event = require 'utils.event'
local main_caption = " --Anarchy-- "
local sub_caption = " finally.. true freedum.. "
local info = [[
No rules.
Anything goes.
Use to [Group] button to form alliances.
]]
local function create_map_intro(player)
local frame = player.gui.left.add {type = "frame", name = "map_intro_frame", direction = "vertical"}
local t = frame.add {type = "table", column_count = 1}
local tt = t.add {type = "table", column_count = 3}
local l = tt.add {type = "label", caption = main_caption}
l.style.font = "default-frame"
l.style.font_color = {r=0.8, g=0.3, b=0.45}
l.style.top_padding = 6
l.style.bottom_padding = 6
local l = tt.add {type = "label", caption = sub_caption}
l.style.font = "default"
l.style.font_color = {r=0.9, g=0.9, b=0.2}
l.style.minimal_width = 280
local b = tt.add {type = "button", caption = "X", name = "close_map_intro_frame", align = "right"}
b.style.font = "default"
b.style.minimal_height = 30
b.style.minimal_width = 30
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
local tt = t.add {type = "table", column_count = 1}
local frame = t.add {type = "frame"}
local l = frame.add {type = "label", caption = info}
l.style.single_line = false
l.style.font_color = {r=0.95, g=0.95, b=0.95}
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
create_map_intro(player)
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
if event.element.name == "close_map_intro_frame" then player.gui.left["map_intro_frame"].destroy() end
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -2,11 +2,16 @@
--You can use /c map_pregen() command to pre-generate the world before playing to avoid any possible microstutter while playing.--
--Use /c spaghetti() to play without bots.
local enable_fishbank_terminal = false
require "maps.cave_miner_kaboomsticks"
require "maps.tools.map_pregen"
local simplex_noise = require 'utils.simplex_noise'
local Event = require 'utils.event'
local market_items = require "maps.cave_miner_market_items"
local math_random = math.random
local spawn_dome_size = 10000
local darkness_messages = {
"Something is lurking in the dark...",
@ -98,7 +103,7 @@ end
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math.random(size)
local rand = math_random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
@ -234,7 +239,7 @@ local function refresh_gui()
end
local function treasure_chest(position, distance_to_center)
local math_random = math.random
local chest_raffle = {}
local chest_loot = {
{{name = "steel-axe", count = math_random(1,3)}, weight = 2, evolution_min = 0.0, evolution_max = 0.5},
@ -374,7 +379,7 @@ local function treasure_chest(position, distance_to_center)
{{name = "gun-turret", count = math_random(2,6)}, weight = 3, evolution_min = 0.2, evolution_max = 0.9}
}
distance_to_center = distance_to_center - global.spawn_dome_size
distance_to_center = distance_to_center - spawn_dome_size
if distance_to_center < 1 then
distance_to_center = 0.1
else
@ -395,8 +400,8 @@ local function treasure_chest(position, distance_to_center)
local e = game.surfaces[1].create_entity({name=n, position=position, force="player"})
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math.random(3,5), 1 do
local loot = chest_raffle[math.random(1,#chest_raffle)]
for x = 1, math_random(3,5), 1 do
local loot = chest_raffle[math_random(1,#chest_raffle)]
i.insert(loot)
end
end
@ -408,22 +413,22 @@ function rare_treasure_chest(position)
local rare_treasure_chest_raffle_table = {}
local rare_treasure_chest_loot_weights = {}
table.insert(rare_treasure_chest_loot_weights, {{name = 'combat-shotgun', count = 1},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-shotgun-shell', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'flamethrower', count = 1},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket-launcher', count = 1},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'flamethrower-ammo', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math.random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'flamethrower-ammo', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'rocket', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'explosive-rocket', count = math_random(16,48)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'modular-armor', count = 1},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'power-armor', count = 1},1})
table.insert(rare_treasure_chest_loot_weights, {{name = 'uranium-rounds-magazine', count = math.random(16,48)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math.random(64,128)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'uranium-rounds-magazine', count = math_random(16,48)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'piercing-rounds-magazine', count = math_random(64,128)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun', count = 1},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun-dart', count = math.random(16,48)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'railgun-dart', count = math_random(16,48)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'exoskeleton-equipment', count = 1},2})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math.random(8,16)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math.random(4,8)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math.random(4,8)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'defender-capsule', count = math_random(8,16)},5})
table.insert(rare_treasure_chest_loot_weights, {{name = 'distractor-capsule', count = math_random(4,8)},4})
table.insert(rare_treasure_chest_loot_weights, {{name = 'destroyer-capsule', count = math_random(4,8)},3})
table.insert(rare_treasure_chest_loot_weights, {{name = 'atomic-bomb', count = 1},1})
for _, t in pairs (rare_treasure_chest_loot_weights) do
for x = 1, t[2], 1 do
@ -434,62 +439,65 @@ function rare_treasure_chest(position)
local e = game.surfaces[1].create_entity {name="steel-chest",position=p, force="player"}
e.minable = false
local i = e.get_inventory(defines.inventory.chest)
for x = 1, math.random(2,3), 1 do
local loot = rare_treasure_chest_raffle_table[math.random(1,#rare_treasure_chest_raffle_table)]
for x = 1, math_random(2,3), 1 do
local loot = rare_treasure_chest_raffle_table[math_random(1,#rare_treasure_chest_raffle_table)]
i.insert(loot)
end
end
local function secret_shop(pos)
local secret_market_items = {
{price = {{"raw-fish", math.random(250,450)}}, offer = {type = 'give-item', item = 'combat-shotgun'}},
{price = {{"raw-fish", math.random(250,450)}}, offer = {type = 'give-item', item = 'flamethrower'}},
{price = {{"raw-fish", math.random(75,125)}}, offer = {type = 'give-item', item = 'rocket-launcher'}},
{price = {{"raw-fish", math.random(2,4)}}, offer = {type = 'give-item', item = 'piercing-rounds-magazine'}},
{price = {{"raw-fish", math.random(8,16)}}, offer = {type = 'give-item', item = 'uranium-rounds-magazine'}},
{price = {{"raw-fish", math.random(8,16)}}, offer = {type = 'give-item', item = 'piercing-shotgun-shell'}},
{price = {{"raw-fish", math.random(6,12)}}, offer = {type = 'give-item', item = 'flamethrower-ammo'}},
{price = {{"raw-fish", math.random(8,16)}}, offer = {type = 'give-item', item = 'rocket'}},
{price = {{"raw-fish", math.random(10,20)}}, offer = {type = 'give-item', item = 'explosive-rocket'}},
{price = {{"raw-fish", math.random(15,30)}}, offer = {type = 'give-item', item = 'explosive-cannon-shell'}},
{price = {{"raw-fish", math.random(25,35)}}, offer = {type = 'give-item', item = 'explosive-uranium-cannon-shell'}},
{price = {{"raw-fish", math.random(20,40)}}, offer = {type = 'give-item', item = 'cluster-grenade'}},
{price = {{"raw-fish", math.random(1,3)}}, offer = {type = 'give-item', item = 'land-mine'}},
{price = {{"raw-fish", math.random(250,500)}}, offer = {type = 'give-item', item = 'modular-armor'}},
{price = {{"raw-fish", math.random(1500,3000)}}, offer = {type = 'give-item', item = 'power-armor'}},
{price = {{"raw-fish", math.random(15000,20000)}}, offer = {type = 'give-item', item = 'power-armor-mk2'}},
{price = {{"raw-fish", math.random(4000,7000)}}, offer = {type = 'give-item', item = 'fusion-reactor-equipment'}},
{price = {{"raw-fish", math.random(50,100)}}, offer = {type = 'give-item', item = 'battery-equipment'}},
{price = {{"raw-fish", math.random(700,1100)}}, offer = {type = 'give-item', item = 'battery-mk2-equipment'}},
{price = {{"raw-fish", math.random(400,700)}}, offer = {type = 'give-item', item = 'belt-immunity-equipment'}},
{price = {{"raw-fish", math.random(12000,16000)}}, offer = {type = 'give-item', item = 'night-vision-equipment'}},
{price = {{"raw-fish", math.random(300,500)}}, offer = {type = 'give-item', item = 'exoskeleton-equipment'}},
{price = {{"raw-fish", math.random(350,500)}}, offer = {type = 'give-item', item = 'personal-roboport-equipment'}},
{price = {{"raw-fish", math.random(25,50)}}, offer = {type = 'give-item', item = 'construction-robot'}},
{price = {{"raw-fish", math.random(250,450)}}, offer = {type = 'give-item', item = 'energy-shield-equipment'}},
{price = {{"raw-fish", math.random(350,550)}}, offer = {type = 'give-item', item = 'personal-laser-defense-equipment'}},
{price = {{"raw-fish", math.random(125,250)}}, offer = {type = 'give-item', item = 'railgun'}},
{price = {{"raw-fish", math.random(2,4)}}, offer = {type = 'give-item', item = 'railgun-dart'}},
{price = {{"raw-fish", math.random(100,175)}}, offer = {type = 'give-item', item = 'loader'}},
{price = {{"raw-fish", math.random(200,350)}}, offer = {type = 'give-item', item = 'fast-loader'}},
{price = {{"raw-fish", math.random(400,600)}}, offer = {type = 'give-item', item = 'express-loader'}}
{price = {{"raw-fish", math_random(250,450)}}, offer = {type = 'give-item', item = 'combat-shotgun'}},
{price = {{"raw-fish", math_random(250,450)}}, offer = {type = 'give-item', item = 'flamethrower'}},
{price = {{"raw-fish", math_random(75,125)}}, offer = {type = 'give-item', item = 'rocket-launcher'}},
{price = {{"raw-fish", math_random(2,4)}}, offer = {type = 'give-item', item = 'piercing-rounds-magazine'}},
{price = {{"raw-fish", math_random(8,16)}}, offer = {type = 'give-item', item = 'uranium-rounds-magazine'}},
{price = {{"raw-fish", math_random(8,16)}}, offer = {type = 'give-item', item = 'piercing-shotgun-shell'}},
{price = {{"raw-fish", math_random(6,12)}}, offer = {type = 'give-item', item = 'flamethrower-ammo'}},
{price = {{"raw-fish", math_random(8,16)}}, offer = {type = 'give-item', item = 'rocket'}},
{price = {{"raw-fish", math_random(10,20)}}, offer = {type = 'give-item', item = 'explosive-rocket'}},
{price = {{"raw-fish", math_random(15,30)}}, offer = {type = 'give-item', item = 'explosive-cannon-shell'}},
{price = {{"raw-fish", math_random(25,35)}}, offer = {type = 'give-item', item = 'explosive-uranium-cannon-shell'}},
{price = {{"raw-fish", math_random(20,40)}}, offer = {type = 'give-item', item = 'cluster-grenade'}},
{price = {{"raw-fish", math_random(1,3)}}, offer = {type = 'give-item', item = 'land-mine'}},
{price = {{"raw-fish", math_random(250,500)}}, offer = {type = 'give-item', item = 'modular-armor'}},
{price = {{"raw-fish", math_random(1500,3000)}}, offer = {type = 'give-item', item = 'power-armor'}},
{price = {{"raw-fish", math_random(15000,20000)}}, offer = {type = 'give-item', item = 'power-armor-mk2'}},
{price = {{"raw-fish", math_random(4000,7000)}}, offer = {type = 'give-item', item = 'fusion-reactor-equipment'}},
{price = {{"raw-fish", math_random(50,100)}}, offer = {type = 'give-item', item = 'battery-equipment'}},
{price = {{"raw-fish", math_random(700,1100)}}, offer = {type = 'give-item', item = 'battery-mk2-equipment'}},
{price = {{"raw-fish", math_random(400,700)}}, offer = {type = 'give-item', item = 'belt-immunity-equipment'}},
{price = {{"raw-fish", math_random(12000,16000)}}, offer = {type = 'give-item', item = 'night-vision-equipment'}},
{price = {{"raw-fish", math_random(300,500)}}, offer = {type = 'give-item', item = 'exoskeleton-equipment'}},
{price = {{"raw-fish", math_random(350,500)}}, offer = {type = 'give-item', item = 'personal-roboport-equipment'}},
{price = {{"raw-fish", math_random(25,50)}}, offer = {type = 'give-item', item = 'construction-robot'}},
{price = {{"raw-fish", math_random(250,450)}}, offer = {type = 'give-item', item = 'energy-shield-equipment'}},
{price = {{"raw-fish", math_random(350,550)}}, offer = {type = 'give-item', item = 'personal-laser-defense-equipment'}},
{price = {{"raw-fish", math_random(125,250)}}, offer = {type = 'give-item', item = 'railgun'}},
{price = {{"raw-fish", math_random(2,4)}}, offer = {type = 'give-item', item = 'railgun-dart'}},
{price = {{"raw-fish", math_random(100,175)}}, offer = {type = 'give-item', item = 'loader'}},
{price = {{"raw-fish", math_random(200,350)}}, offer = {type = 'give-item', item = 'fast-loader'}},
{price = {{"raw-fish", math_random(400,600)}}, offer = {type = 'give-item', item = 'express-loader'}}
}
secret_market_items = shuffle(secret_market_items)
local surface = game.surfaces[1]
local market = surface.create_entity {name = "market", position = pos}
market.destructible = false
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 2% Bank Fee'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}})
market.destructible = false
for i = 1, math.random(8,12), 1 do
if enable_fishbank_terminal then
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 1% Bank Fee'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}})
end
for i = 1, math_random(8,12), 1 do
market.add_market_item(secret_market_items[i])
end
end
local function on_chunk_generated(event)
if not global.noise_seed then global.noise_seed = math.random(1,5000000) end
if not global.noise_seed then global.noise_seed = math_random(1,5000000) end
local surface = game.surfaces[1]
local noise = {}
local tiles = {}
@ -559,9 +567,9 @@ local function on_chunk_generated(event)
current_noise_seed_add = noise_seed_add
tile_to_insert = false
if tile_distance_to_center > global.spawn_dome_size then
if tile_distance_to_center > spawn_dome_size then
if tile_distance_to_center > (global.spawn_dome_size + 5000) * (cave_noise_3 * 0.05 + 1.1) then
if tile_distance_to_center > (spawn_dome_size + 5000) * (cave_noise_3 * 0.05 + 1.1) then
if cave_noise > 1 then
tile_to_insert = "deepwater"
table.insert(fish_positions, {pos_x,pos_y})
@ -613,7 +621,7 @@ local function on_chunk_generated(event)
if tile_to_insert == false then
if cave_noise < m1 and cave_noise > m1*-1 then
tile_to_insert = "dirt-7"
if cave_noise < 0.06 and cave_noise > -0.06 and noise[1] > 0.4 and tile_distance_to_center > global.spawn_dome_size + 5000 then
if cave_noise < 0.06 and cave_noise > -0.06 and noise[1] > 0.4 and tile_distance_to_center > spawn_dome_size + 5000 then
table.insert(enemy_can_place_worm_positions, {pos_x,pos_y})
table.insert(enemy_can_place_worm_positions, {pos_x,pos_y})
table.insert(enemy_can_place_worm_positions, {pos_x,pos_y})
@ -625,13 +633,13 @@ local function on_chunk_generated(event)
table.insert(enemy_building_positions, {pos_x,pos_y})
else
table.insert(rock_positions, {pos_x,pos_y})
if math.random(1,3) == 1 then table.insert(enemy_worm_positions, {pos_x,pos_y}) end
if math_random(1,3) == 1 then table.insert(enemy_worm_positions, {pos_x,pos_y}) end
end
if cave_noise_2 > 0.85 and tile_distance_to_center > global.spawn_dome_size + 25000 then
if math.random(1,48) == 1 then
if cave_noise_2 > 0.85 and tile_distance_to_center > spawn_dome_size + 25000 then
if math_random(1,48) == 1 then
local p = surface.find_non_colliding_position("crude-oil",{pos_x,pos_y}, 5,1)
if p then
surface.create_entity {name="crude-oil", position=p, amount=math.floor(math.random(25000+tile_distance_to_center*0.5,50000+tile_distance_to_center),0)}
surface.create_entity {name="crude-oil", position=p, amount=math.floor(math_random(25000+tile_distance_to_center*0.5,50000+tile_distance_to_center),0)}
end
end
end
@ -652,7 +660,7 @@ local function on_chunk_generated(event)
end
end
if tile_distance_to_center < global.spawn_dome_size * (cave_noise_3 * 0.05 + 1.1) then
if tile_distance_to_center < spawn_dome_size * (cave_noise_3 * 0.05 + 1.1) then
if tile_to_insert == false then table.insert(rock_positions, {pos_x,pos_y}) end
tile_to_insert = "dirt-7"
end
@ -662,13 +670,13 @@ local function on_chunk_generated(event)
table.insert(fish_positions, {pos_x,pos_y})
else
tile_to_insert = "grass-1"
if cave_noise_3 > 0 and tile_distance_to_center + 3000 < global.spawn_dome_size then
if cave_noise_3 > 0 and tile_distance_to_center + 3000 < spawn_dome_size then
table.insert(spawn_tree_positions, {pos_x,pos_y})
end
end
end
if tile_distance_to_center < global.spawn_dome_size and tile_distance_to_center > global.spawn_dome_size - 500 and tile_to_insert == "grass-1" then
if tile_distance_to_center < spawn_dome_size and tile_distance_to_center > spawn_dome_size - 500 and tile_to_insert == "grass-1" then
table.insert(rock_positions, {pos_x,pos_y})
end
@ -682,35 +690,35 @@ local function on_chunk_generated(event)
surface.set_tiles(tiles,true)
for _, k in pairs(treasure_chest_positions) do
if math.random(1,800)==1 then
if math_random(1,800)==1 then
treasure_chest(k[1], k[2])
end
end
for _, p in pairs(rare_treasure_chest_positions) do
if math.random(1,100)==1 then
if math_random(1,100)==1 then
rare_treasure_chest(p)
end
end
for _, p in pairs(rock_positions) do
local x = math.random(1,100)
local x = math_random(1,100)
if x < global.rock_density then
surface.create_entity {name=global.rock_raffle[math.random(1,#global.rock_raffle)], position=p}
surface.create_entity {name=global.rock_raffle[math_random(1,#global.rock_raffle)], position=p}
end
--[[
local z = 1
if p[2] % 2 == 1 then z = 0 end
if p[1] % 2 == z then
surface.create_entity {name=global.rock_raffle[math.random(1,#global.rock_raffle)], position=p}
surface.create_entity {name=global.rock_raffle[math_random(1,#global.rock_raffle)], position=p}
end
]]--
end
for _, p in pairs(enemy_building_positions) do
if math.random(1,50)==1 then
if math_random(1,50)==1 then
local pos = surface.find_non_colliding_position("biter-spawner", p, 8, 1)
if pos then
if math.random(1,3) == 1 then
if math_random(1,3) == 1 then
surface.create_entity {name="spitter-spawner",position=pos}
else
surface.create_entity {name="biter-spawner",position=pos}
@ -720,33 +728,33 @@ local function on_chunk_generated(event)
end
for _, p in pairs(enemy_worm_positions) do
if math.random(1,300)==1 then
if math_random(1,300)==1 then
local tile_distance_to_center = math.sqrt(p[1]^2 + p[2]^2)
if tile_distance_to_center > global.worm_free_zone_radius then
local raffle_index = math.ceil((tile_distance_to_center-global.worm_free_zone_radius)*0.01, 0)
if raffle_index < 1 then raffle_index = 1 end
if raffle_index > 10 then raffle_index = 10 end
local entity_name = worm_raffle_table[raffle_index][math.random(1,#worm_raffle_table[raffle_index])]
local entity_name = worm_raffle_table[raffle_index][math_random(1,#worm_raffle_table[raffle_index])]
surface.create_entity {name=entity_name, position=p}
end
end
end
for _, p in pairs(enemy_can_place_worm_positions) do
if math.random(1,30)==1 then
if math_random(1,30)==1 then
local tile_distance_to_center = math.sqrt(p[1]^2 + p[2]^2)
if tile_distance_to_center > global.worm_free_zone_radius then
local raffle_index = math.ceil((tile_distance_to_center-global.worm_free_zone_radius)*0.01, 0)
if raffle_index < 1 then raffle_index = 1 end
if raffle_index > 10 then raffle_index = 10 end
local entity_name = worm_raffle_table[raffle_index][math.random(1,#worm_raffle_table[raffle_index])]
local entity_name = worm_raffle_table[raffle_index][math_random(1,#worm_raffle_table[raffle_index])]
if surface.can_place_entity({name=entity_name, position=p}) then surface.create_entity {name=entity_name, position=p} end
end
end
end
for _, p in pairs(fish_positions) do
if math.random(1,16)==1 then
if math_random(1,16)==1 then
if surface.can_place_entity({name="fish",position=p}) then
surface.create_entity {name="fish",position=p}
end
@ -754,7 +762,7 @@ local function on_chunk_generated(event)
end
for _, p in pairs(secret_shop_locations) do
if math.random(1,10)==1 then
if math_random(1,10)==1 then
if surface.count_entities_filtered{area={{p[1]-125,p[2]-125},{p[1]+125,p[2]+125}}, name="market", limit=1} == 0 then
secret_shop(p)
end
@ -762,13 +770,13 @@ local function on_chunk_generated(event)
end
for _, p in pairs(spawn_tree_positions) do
if math.random(1,6)==1 then
if math_random(1,6)==1 then
surface.create_entity {name="tree-04",position=p}
end
end
for _, p in pairs(extra_tree_positions) do
if math.random(1,20)==1 then
if math_random(1,20)==1 then
surface.create_entity {name="tree-02",position=p}
end
end
@ -794,14 +802,14 @@ local function hunger_update(player, food_value)
global.player_hunger[player.name] = player_hunger_spawn_value
player.character.die("player")
local t = {" ate too much and exploded.", " should have gone on a diet.", " needs to work on their bad eating habbits.", " should have skipped dinner today."}
game.print(player.name .. t[math.random(1,#t)], { r=0.75, g=0.0, b=0.0})
game.print(player.name .. t[math_random(1,#t)], { r=0.75, g=0.0, b=0.0})
end
if global.player_hunger[player.name] < 1 then
global.player_hunger[player.name] = player_hunger_spawn_value
player.character.die("player")
local t = {" ran out of foodstamps.", " starved.", " should not have skipped breakfast today."}
game.print(player.name .. t[math.random(1,#t)], { r=0.75, g=0.0, b=0.0})
game.print(player.name .. t[math_random(1,#t)], { r=0.75, g=0.0, b=0.0})
end
if player.character then
@ -839,8 +847,6 @@ local function on_player_joined_game(event)
game.map_settings.enemy_evolution.destroy_factor = 0.004
global.spawn_dome_size = 20000
global.cave_miner_map_info = [[
Delve deep for greater treasures, but also face increased dangers.
Mining productivity research, will overhaul your mining equipment,
@ -877,7 +883,7 @@ Darkness is a hazard in the mines, stay near your lamps..
global.rock_density = 62 ---- insert value up to 100
global.rock_raffle = {"sand-rock-big","sand-rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-big","rock-huge"}
global.worm_free_zone_radius = math.sqrt(global.spawn_dome_size) + 40
global.worm_free_zone_radius = math.sqrt(spawn_dome_size) + 40
global.biter_spawn_schedule = {}
@ -921,10 +927,10 @@ local function spawn_cave_inhabitant(pos, target_position)
if not pos.y then return nil end
local surface = game.surfaces[1]
local tile_distance_to_center = math.sqrt(pos.x^2 + pos.y^2)
local rock_inhabitants_index = math.ceil((tile_distance_to_center-math.sqrt(global.spawn_dome_size))*0.015, 0)
local rock_inhabitants_index = math.ceil((tile_distance_to_center-math.sqrt(spawn_dome_size))*0.015, 0)
if rock_inhabitants_index < 1 then rock_inhabitants_index = 1 end
if rock_inhabitants_index > #rock_inhabitants then rock_inhabitants_index = #rock_inhabitants end
local entity_name = rock_inhabitants[rock_inhabitants_index][math.random(1,#rock_inhabitants[rock_inhabitants_index])]
local entity_name = rock_inhabitants[rock_inhabitants_index][math_random(1,#rock_inhabitants[rock_inhabitants_index])]
local p = surface.find_non_colliding_position(entity_name , pos, 6, 0.5)
local biter = 1
if p then biter = surface.create_entity {name=entity_name, position=p} end
@ -973,20 +979,20 @@ local function biter_attack_event()
local position = {x = player.position.x, y = player.position.y}
local p = find_first_entity_spiral_scan(position, {"rock-huge", "rock-big", "sand-rock-big"}, 32)
if p then
if p.x^2 + p.y^2 > global.spawn_dome_size then table.insert(valid_positions, p) end
if p.x^2 + p.y^2 > spawn_dome_size then table.insert(valid_positions, p) end
end
end
end
if valid_positions[1] then
if #valid_positions == 1 then
for x = 1, global.biter_spawn_amount_raffle[math.random(1,#global.biter_spawn_amount_raffle)],1 do
for x = 1, global.biter_spawn_amount_raffle[math_random(1,#global.biter_spawn_amount_raffle)],1 do
table.insert(global.biter_spawn_schedule, {game.tick + 20*x, valid_positions[1]})
end
end
if #valid_positions > 1 then
for y = math.random(1,2), #valid_positions, 2 do
for y = math_random(1,2), #valid_positions, 2 do
if y > #valid_positions then break end
for x = 1, global.biter_spawn_amount_raffle[math.random(1,#global.biter_spawn_amount_raffle)],1 do
for x = 1, global.biter_spawn_amount_raffle[math_random(1,#global.biter_spawn_amount_raffle)],1 do
table.insert(global.biter_spawn_schedule, {game.tick + 20*x, valid_positions[y]})
end
end
@ -1005,11 +1011,11 @@ local function darkness_events()
for _, biter in pairs(biters_found) do
biter.set_command({type=defines.command.attack, target=p.character, distraction=defines.distraction.none})
end
p.character.damage(math.random(global.darkness_threat_level[p.name]*2,global.darkness_threat_level[p.name]*3),"enemy")
p.character.damage(math_random(global.darkness_threat_level[p.name]*2,global.darkness_threat_level[p.name]*3),"enemy")
end
end
if global.darkness_threat_level[p.name] == 2 then
p.print(darkness_messages[math.random(1,#darkness_messages)],{ r=0.65, g=0.0, b=0.0})
p.print(darkness_messages[math_random(1,#darkness_messages)],{ r=0.65, g=0.0, b=0.0})
end
global.darkness_threat_level[p.name] = global.darkness_threat_level[p.name] + 1
end
@ -1019,7 +1025,7 @@ local function darkness_checks()
for _, p in pairs (game.connected_players) do
if p.character then p.character.disable_flashlight() end
local tile_distance_to_center = math.sqrt(p.position.x^2 + p.position.y^2)
if tile_distance_to_center < math.sqrt(global.spawn_dome_size) then
if tile_distance_to_center < math.sqrt(spawn_dome_size) then
global.darkness_threat_level[p.name] = 0
else
if p.character and p.character.driving == true then
@ -1090,7 +1096,7 @@ local function on_tick(event)
end
refresh_gui()
if math.random(1,2) == 1 then biter_attack_event() end
if math_random(1,2) == 1 then biter_attack_event() end
end
if game.tick == 30 then
@ -1099,6 +1105,12 @@ local function on_tick(event)
local market = surface.create_entity {name = "market", position = p}
market.destructible = false
if enable_fishbank_terminal then
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 1% Bank Fee'}})
market.add_market_item({price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}})
end
for _, item in pairs(market_items.spawn) do
market.add_market_item(item)
end
@ -1121,13 +1133,19 @@ local function on_marked_for_deconstruction(event)
end
end
local treasure_chest_messages = {
"You notice an old crate within the rubble. It's filled with treasure!",
"You find a chest underneath the broken rocks. It's filled with goodies!",
"We has found the precious!"
}
local function pre_player_mined_item(event)
local surface = game.surfaces[1]
local player = game.players[event.player_index]
if math.random(1,12) == 1 then
if math_random(1,12) == 1 then
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
for x = 1, math.random(6, 10), 1 do
for x = 1, math_random(6, 10), 1 do
table.insert(global.biter_spawn_schedule, {game.tick + 15*x, event.entity.position})
end
end
@ -1140,26 +1158,26 @@ local function pre_player_mined_item(event)
event.entity.destroy()
local distance_to_center = rock_position.x ^ 2 + rock_position.y ^ 2
if math.random(1, 150) == 1 then
if math_random(1, 250) == 1 then
treasure_chest(rock_position, distance_to_center)
player.print("You notice an old crate within the rubble. It´s filled with treasure!", { r=0.98, g=0.66, b=0.22})
player.print(treasure_chest_messages[math_random(1, #treasure_chest_messages)], { r=0.98, g=0.66, b=0.22})
end
local tile_distance_to_center = math.sqrt(rock_position.x^2 + rock_position.y^2)
if tile_distance_to_center > 1450 then tile_distance_to_center = 1450 end
if math.random(1,3) == 1 then hunger_update(player, -1) end
if math_random(1,3) == 1 then hunger_update(player, -1) end
surface.spill_item_stack(player.position,{name = "raw-fish", count = math.random(3,4)},true)
local bonus_amount = math.ceil((tile_distance_to_center - math.sqrt(global.spawn_dome_size)) * 0.10, 0)
surface.spill_item_stack(player.position,{name = "raw-fish", count = math_random(3,4)},true)
local bonus_amount = math.ceil((tile_distance_to_center - math.sqrt(spawn_dome_size)) * 0.10, 0)
if bonus_amount < 1 then bonus_amount = 0 end
local amount = (math.random(45,55) + bonus_amount)*(1+game.forces.player.mining_drill_productivity_bonus)
local amount = (math_random(45,55) + bonus_amount)*(1+game.forces.player.mining_drill_productivity_bonus)
amount = math.round(amount, 0)
amount_of_stone = math.round(amount * 0.15,0)
global.stats_ores_found = global.stats_ores_found + amount + amount_of_stone
local mined_loot = global.rock_mining_raffle_table[math.random(1,#global.rock_mining_raffle_table)]
local mined_loot = global.rock_mining_raffle_table[math_random(1,#global.rock_mining_raffle_table)]
if amount > global.ore_spill_cap then
surface.spill_item_stack(rock_position,{name = mined_loot, count = global.ore_spill_cap},true)
amount = amount - global.ore_spill_cap
@ -1187,23 +1205,23 @@ local function pre_player_mined_item(event)
global.stats_rocks_broken = global.stats_rocks_broken + 1
refresh_gui()
if math.random(1,32) == 1 then
if math_random(1,32) == 1 then
local p = {x = rock_position.x, y = rock_position.y}
local tile_distance_to_center = p.x^2 + p.y^2
if tile_distance_to_center > global.spawn_dome_size + 100 then
if tile_distance_to_center > spawn_dome_size + 100 then
local radius = 32
if surface.count_entities_filtered{area={{p.x - radius,p.y - radius},{p.x + radius,p.y + radius}}, type="resource", limit=1} == 0 then
local size_raffle = {{"huge", 33, 42},{"big", 17, 32},{"", 8, 16},{"tiny", 3, 7}}
local size = size_raffle[math.random(1,#size_raffle)]
local size = size_raffle[math_random(1,#size_raffle)]
local ore_prints = {coal = {"dark", "Coal"}, ["iron-ore"] = {"shiny", "Iron"}, ["copper-ore"] = {"glimmering", "Copper"}, ["uranium-ore"] = {"glowing", "Uranium"}}
player.print("You notice something " .. ore_prints[mined_loot][1] .. " underneath the rubble covered floor. It´s a " .. size[1] .. " vein of " .. ore_prints[mined_loot][2] .. "!!", { r=0.98, g=0.66, b=0.22})
player.print("You notice something " .. ore_prints[mined_loot][1] .. " underneath the rubble covered floor. It's a " .. size[1] .. " vein of " .. ore_prints[mined_loot][2] .. "!!", { r=0.98, g=0.66, b=0.22})
tile_distance_to_center = math.sqrt(tile_distance_to_center)
local ore_entities_placed = 0
local modifier_raffle = {{0,-1},{-1,0},{1,0},{0,1}}
while ore_entities_placed < math.random(size[2],size[3]) do
local a = math.ceil((math.random(tile_distance_to_center*4, tile_distance_to_center*5)) / 1 + ore_entities_placed * 0.5, 0)
while ore_entities_placed < math_random(size[2],size[3]) do
local a = math.ceil((math_random(tile_distance_to_center*4, tile_distance_to_center*5)) / 1 + ore_entities_placed * 0.5, 0)
for x = 1, 150, 1 do
local m = modifier_raffle[math.random(1,#modifier_raffle)]
local m = modifier_raffle[math_random(1,#modifier_raffle)]
local pos = {x = p.x + m[1], y = p.y + m[2]}
if surface.can_place_entity({name=mined_loot, position=pos, amount=a}) then
surface.create_entity {name=mined_loot, position=pos, amount=a}
@ -1224,10 +1242,10 @@ local function on_player_mined_entity(event)
event.buffer.clear()
end
if event.entity.name == "fish" then
if math.random(1,2) == 1 then
if math_random(1,2) == 1 then
local player = game.players[event.player_index]
local health = player.character.health
player.character.damage(math.random(50,150),"enemy")
player.character.damage(math_random(50,150),"enemy")
if not player.character then
game.print(player.name .. " should have kept their hands out of the foggy lake waters.",{ r=0.75, g=0.0, b=0.0} )
else
@ -1235,14 +1253,15 @@ local function on_player_mined_entity(event)
player.print("You got bitten by an angry cave piranha.",{ r=0.75, g=0.0, b=0.0})
else
local messages = {"Ouch.. That hurt! Better be careful now.", "Just a fleshwound.", "Better keep those hands to yourself or you might loose them."}
player.print(messages[math.random(1,#messages)],{ r=0.75, g=0.0, b=0.0})
player.print(messages[math_random(1,#messages)],{ r=0.75, g=0.0, b=0.0})
end
end
end
end
end
local function on_entity_damaged(event)
local function on_entity_damaged(event)
if not event.entity.valid then return end
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
local rock_is_alive = true
if event.force.name == "enemy" then
@ -1263,19 +1282,19 @@ local function on_entity_damaged(event)
else
global.damaged_rocks[tostring(event.entity.position.x) .. tostring(event.entity.position.y)] = nil
if event.force.name == "player" then
if math.random(1,12) == 1 then
for x = 1, math.random(6,10), 1 do
if math_random(1,12) == 1 then
for x = 1, math_random(6,10), 1 do
table.insert(global.biter_spawn_schedule, {game.tick + 10*x, event.entity.position})
end
end
end
local p = {x = event.entity.position.x, y = event.entity.position.y}
local drop_amount = math.random(4, 8)
local drop_amount = math_random(4, 8)
event.entity.destroy()
game.surfaces[1].spill_item_stack(p,{name = "stone", count = drop_amount},true)
local drop_amount_ore = math.random(16, 32)
local ore = global.rock_mining_raffle_table[math.random(1, #global.rock_mining_raffle_table)]
local drop_amount_ore = math_random(16, 32)
local ore = global.rock_mining_raffle_table[math_random(1, #global.rock_mining_raffle_table)]
game.surfaces[1].spill_item_stack(p,{name = ore, count = drop_amount_ore},true)
global.stats_rocks_broken = global.stats_rocks_broken + 1
@ -1294,7 +1313,7 @@ local function on_player_respawned(event)
end
local function on_research_finished(event)
game.forces.player.manual_mining_speed_modifier = game.forces.player.mining_drill_productivity_bonus * 5
game.forces.player.manual_mining_speed_modifier = game.forces.player.mining_drill_productivity_bonus * 4
game.forces.player.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 500
refresh_gui()
end
@ -1340,7 +1359,8 @@ local bank_messages = {
"9 out of 10 felines only trust in Fishbank."
}
local function on_market_item_purchased(event)
local function on_market_item_purchased(event)
if not enable_fishbank_terminal then return end
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
@ -1356,7 +1376,7 @@ local function on_market_item_purchased(event)
if fish_removed == 0 then return end
global.fish_bank[player.name] = global.fish_bank[player.name] + fish_removed
player.print(fish_removed .. " Fish deposited into your account. Your balance is " .. global.fish_bank[player.name] .. ".", {r=0.10, g=0.75, b=0.5})
player.print(bank_messages[math.random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
player.print(bank_messages[math_random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
player.surface.create_entity({name = "flying-text", position = player.position, text = tostring(fish_removed .. " Fish deposited"), color = {r=0.10, g=0.75, b=0.5}})
end
@ -1380,7 +1400,7 @@ local function on_market_item_purchased(event)
end
global.fish_bank[player.name] = global.fish_bank[player.name] - (fish_withdrawn + fee)
player.print(fish_withdrawn .. " Fish withdrawn from your account. Your balance is " .. global.fish_bank[player.name] .. ".", { r=0.10, g=0.75, b=0.5})
player.print(bank_messages[math.random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
player.print(bank_messages[math_random(1,#bank_messages)], { r=0.77, g=0.77, b=0.77})
player.surface.create_entity({name = "flying-text", position = player.position, text = tostring(fish_withdrawn .. " Fish withdrawn"), color = {r=0.10, g=0.75, b=0.5}})
end

View File

@ -1,8 +1,5 @@
local items = {}
items.spawn = {
{price = {}, offer = {type = 'nothing', effect_description = 'Deposit Fish'}},
{price = {}, offer = {type = 'nothing', effect_description = 'Withdraw Fish - 1% Bank Fee'}},
{price = {}, offer = {type = 'nothing', effect_description = 'Show Account Balance'}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail', count = 4}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail-signal', count = 2}},
{price = {{"raw-fish", 5}}, offer = {type = 'give-item', item = 'rail-chain-signal', count = 2}},

View File

@ -4,6 +4,7 @@ local event = require 'utils.event'
require "maps.fish_defender_map_intro"
require "maps.modules.rocket_launch_always_yields_science"
require "maps.modules.launch_10000_fish_to_win"
global.fish_in_space_needed = 100000
require "maps.modules.biters_yield_coins"
require "maps.modules.railgun_enhancer"
@ -673,7 +674,7 @@ local function refresh_market_offers()
{price = {{"coin", 125}}, offer = {type = 'give-item', item = 'night-vision-equipment', count = 1}},
{price = {{"coin", 200}}, offer = {type = 'give-item', item = 'belt-immunity-equipment', count = 1}},
{price = {{"coin", 250}}, offer = {type = 'give-item', item = 'personal-roboport-equipment', count = 1}},
{price = {{"coin", 20}}, offer = {type = 'give-item', item = 'construction-robot', count = 1}}
{price = {{"coin", 35}}, offer = {type = 'give-item', item = 'construction-robot', count = 1}}
}
for _, item in pairs(market_items) do

View File

@ -0,0 +1,320 @@
-- Anarchy mode - by mewmew
-- all players have their own force
-- create a tag group to form alliances
-- empty groups will be deleted
local event = require 'utils.event'
local function build_group_gui(player)
local group_name_width = 160
local description_width = 220
local members_width = 90
local member_columns = 3
local actions_width = 60
local total_height = 350
if not player.gui.top["anarchy_group_button"] then
local b = player.gui.top.add({type = "button", name = "anarchy_group_button", caption = global.player_group[player.name], tooltip = "Join / Create a group"})
b.style.font_color = {r = 0.77, g = 0.77, b = 0.77}
b.style.font = "default-bold"
b.style.minimal_height = 38
b.style.minimal_width = 38
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
end
if player.online_time < 1 then return end
if player.gui.left["anarchy_group_frame"] then player.gui.left["anarchy_group_frame"].destroy() end
local frame = player.gui.left.add({type = "frame", name = "anarchy_group_frame", direction = "vertical"})
frame.style.minimal_height = total_height
local t = frame.add({type = "table", column_count = 5})
local headings = {{"Title", group_name_width}, {"Description", description_width}, {"Members", members_width * member_columns}, {"", actions_width*2 - 30}}
for _, h in pairs (headings) do
local l = t.add({ type = "label", caption = h[1]})
l.style.font_color = { r=0.98, g=0.66, b=0.22}
l.style.font = "default-listbox"
l.style.top_padding = 6
l.style.minimal_height = 40
l.style.minimal_width = h[2]
l.style.maximal_width = h[2]
end
local b = t.add {type = "button", caption = "X", name = "close_group_frame", align = "right"}
b.style.font = "default"
b.style.minimal_height = 30
b.style.minimal_width = 30
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
local scroll_pane = frame.add({ type = "scroll-pane", name = "scroll_pane", direction = "vertical", horizontal_scroll_policy = "never", vertical_scroll_policy = "auto"})
scroll_pane.style.maximal_height = total_height - 50
scroll_pane.style.minimal_height = total_height - 50
local t = scroll_pane.add({type = "table", name = "groups_table", column_count = 4})
for _, h in pairs (headings) do
local l = t.add({ type = "label", caption = ""})
l.style.minimal_width = h[2]
l.style.maximal_width = h[2]
end
for _, group in pairs (global.tag_groups) do
local l = t.add({ type = "label", caption = group.name})
l.style.font = "default-bold"
l.style.top_padding = 16
l.style.bottom_padding = 16
l.style.minimal_width = group_name_width
l.style.maximal_width = group_name_width
local color = game.players[group.founder].color
color = {r = color.r * 0.6 + 0.4, g = color.g * 0.6 + 0.4, b = color.b * 0.6 + 0.4, a = 1}
l.style.font_color = color
l.style.single_line = false
local l = t.add({ type = "label", caption = group.description})
l.style.top_padding = 16
l.style.bottom_padding = 16
l.style.minimal_width = description_width
l.style.maximal_width = description_width
l.style.font_color = {r = 0.90, g = 0.90, b = 0.90}
l.style.single_line = false
local tt = t.add({ type = "table", column_count = member_columns})
for _, p in pairs (game.connected_players) do
if group.name == global.player_group[p.name] then
local l = tt.add({ type = "label", caption = p.name})
local color = {r = p.color.r * 0.6 + 0.4, g = p.color.g * 0.6 + 0.4, b = p.color.b * 0.6 + 0.4, a = 1}
l.style.font_color = color
--l.style.minimal_width = members_width
l.style.maximal_width = members_width * 2
end
end
local tt = t.add({ type = "table", name = group.name, column_count = 2})
if player.admin == true or group.founder == player.name then
local b = tt.add({ type = "button", caption = "Delete"})
b.style.font = "default-bold"
b.style.minimal_width = actions_width
b.style.maximal_width = actions_width
else
local l = tt.add({ type = "label", caption = ""})
l.style.minimal_width = actions_width
l.style.maximal_width = actions_width
end
if group.name ~= global.player_group[player.name] then
local b = tt.add({ type = "button", caption = "Join"})
b.style.font = "default-bold"
b.style.minimal_width = actions_width
b.style.maximal_width = actions_width
else
local b = tt.add({ type = "button", caption = "Leave"})
b.style.font = "default-bold"
b.style.minimal_width = actions_width
b.style.maximal_width = actions_width
end
end
local frame2 = frame.add({type = "frame", name = "frame2"})
local t = frame2.add({type = "table", name = "group_table", column_count = 3})
local textfield = t.add({ type = "textfield", name = "new_group_name", text = "Name" })
textfield.style.minimal_width = group_name_width
local textfield = t.add({ type = "textfield", name = "new_group_description", text = "Description" })
textfield.style.minimal_width = description_width + members_width * member_columns
local b = t.add({type = "button", name = "create_new_group", caption = "Create"})
b.style.minimal_width = actions_width*2 - 12
b.style.font = "default-bold"
end
local function refresh_gui()
for _, p in pairs(game.connected_players) do
if p.gui.left["anarchy_group_frame"] then
local frame = p.gui.left["anarchy_group_frame"]
local new_group_name = frame.frame2.group_table.new_group_name.text
local new_group_description = frame.frame2.group_table.new_group_description.text
build_group_gui(p)
local frame = p.gui.left["anarchy_group_frame"]
frame.frame2.group_table.new_group_name.text = new_group_name
frame.frame2.group_table.new_group_description.text = new_group_description
end
end
end
local function set_alliance_for_player(player)
if not global.tag_groups then return end
if not global.player_group then return end
local player_group = global.player_group[player.name]
if player_group == "[Group]" then set_unique_player_force(player) return end
if not global.tag_groups[player_group] then set_unique_player_force(player) return end
local group_founder = global.tag_groups[player_group].founder
player.force = game.forces[group_founder]
end
local function request_alliance(requesting_player, accepting_player)
for _, player in pairs(game.players) do
if player.gui.center[requesting_player.name] then accepting_player.gui.center[requesting_player.name].destroy() end
end
local frame = accepting_player.gui.center.add({type = "frame", caption = requesting_player.name .. " wants to join your group.", name = requesting_player.name})
frame.add({type = "button", caption = "Accept"})
frame.add({type = "button", caption = "Deny"})
end
local function check_for_double_founder(founder)
for _, group in pairs(global.tag_groups) do
if group.founder == founder then return true end
end
return false
end
local function join_group(group_owner, player)
global.player_group[player.name] = global.player_group[group_owner]
local str = "[" .. group
str = str .. "]"
player.gui.top["anarchy_group_button"].caption = str
player.tag = str
if game.tick - global.join_spam_protection[player.name] > 600 then
local color = {r = player.color.r * 0.7 + 0.3, g = player.color.g * 0.7 + 0.3, b = player.color.b * 0.7 + 0.3, a = 1}
game.print(player.name .. " has joined " .. founder .. "'s group " .. '"' .. group .. '"', color)
global.join_spam_protection[player.name] = game.tick
end
refresh_gui()
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
local name = event.element.name
if event.element.caption == "Accept" then
local requesting_player = game.players[event.element.parent.name]
join_group(player, requesting_player)
end
if event.element.caption == "Deny" then
event.element.destroy()
game.print()
return
end
local frame = player.gui.left["anarchy_group_frame"]
if name == "create_new_group" then
if check_for_double_founder(player.name) then
player.print("You can not own more than one group.", { r=0.90, g=0.0, b=0.0})
return
end
local new_group_name = frame.frame2.group_table.new_group_name.text
local new_group_description = frame.frame2.group_table.new_group_description.text
if new_group_name ~= "" and new_group_name ~= "Name" and new_group_description ~= "Description" then
if string.len(new_group_name) > 32 then
player.print("Group name is too long. 32 characters maximum.", { r=0.90, g=0.0, b=0.0})
return
end
if string.len(new_group_description) > 128 then
player.print("Description is too long. 128 characters maximum.", { r=0.90, g=0.0, b=0.0})
return
end
global.tag_groups[new_group_name] = {name = new_group_name, description = new_group_description, founder = player.name}
local color = {r = player.color.r * 0.7 + 0.3, g = player.color.g * 0.7 + 0.3, b = player.color.b * 0.7 + 0.3, a = 1}
game.print(player.name .. " has founded a new group!", color)
game.print('>> ' .. new_group_name, { r=0.98, g=0.66, b=0.22})
game.print(new_group_description, { r=0.85, g=0.85, b=0.85})
frame.frame2.group_table.new_group_name.text = "Name"
frame.frame2.group_table.new_group_description.text = "Description"
global.player_group[player.name] = new_group_name
refresh_gui()
return
end
end
local p = event.element.parent
if p then p = p.parent end
if p then
if p.name == "groups_table" then
if event.element.type == "button" and event.element.caption == "Join" then
local founder = global.tag_groups[event.element.parent.name].founder
if founder == player.name then
return
else
request_alliance(player, game.players[founder])
end
end
if event.element.type == "button" and event.element.caption == "Delete" then
for _, p in pairs(game.players) do
if global.player_group[p.name] then
if global.player_group[p.name] == event.element.parent.name then
global.player_group[p.name] = "[Group]"
p.gui.top["anarchy_group_button"].caption = "[Group]"
p.tag = ""
end
end
end
game.print(player.name .. ' deleted group "' .. event.element.parent.name .. '"')
global.tag_groups[event.element.parent.name] = nil
refresh_gui()
return
end
if event.element.type == "button" and event.element.caption == "Leave" then
if global.player_group[player.name] == event.element.parent.name then return end
global.player_group[player.name] = "[Group]"
player.gui.top["anarchy_group_button"].caption = "[Group]"
player.tag = ""
refresh_gui()
return
end
end
end
if name == "anarchy_group_button" then
if frame then
frame.destroy()
else
build_group_gui(player)
end
end
if name == "close_group_frame" then
frame.destroy()
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if player.gui.left["group_frame"] then player.gui.left["group_frame"].destroy() end
if player.gui.top["group_button"] then player.gui.top["group_button"].destroy() end
if not global.player_group then global.player_group = {} end
if not global.player_group[player.name] then global.player_group[player.name] = "[Group]" end
if not global.join_spam_protection then global.join_spam_protection = {} end
if not global.join_spam_protection[player.name] then global.join_spam_protection[player.name] = game.tick end
if not global.tag_groups then global.tag_groups = {} end
if player.online_time < 10 then
build_group_gui(player)
end
end
event.add(defines.events.on_gui_click, on_gui_click)
event.add(defines.events.on_player_joined_game, on_player_joined_game)

View File

@ -1,7 +1,7 @@
-- launch 10000 fish into space to win the game -- by mewmew
local event = require 'utils.event'
local fish_in_space_needed = 10000
global.fish_in_space_needed = 10000
local function fish_in_space_toggle_button(player)
if player.gui.top["fish_in_space_toggle"] then return end
@ -22,7 +22,7 @@ local function fish_in_space_gui(player)
if player.gui.left["fish_in_space"] then player.gui.left["fish_in_space"].destroy() end
if global.fish_in_space >= fish_in_space_needed then
if global.fish_in_space >= global.fish_in_space_needed then
local frame = player.gui.left.add({type = "frame", name = "fish_in_space", direction = "vertical"})
local label = frame.add({type = "label", caption = "All the fish have been evacuated to cat planet!!"})
label.style.font = "default-listbox"
@ -36,13 +36,16 @@ local function fish_in_space_gui(player)
local label = frame.add({type = "label", caption = "Good Job!! =^.^="})
label.style.font = "default-listbox"
label.style.font_color = { r=0.98, g=0.66, b=0.22}
local label = frame.add({type = "label", caption = '(do "/c game.player.surface.peaceful_mode = false" to continue the map)'})
label.style.font = "default"
label.style.font_color = { r=0.77, g=0.77, b=0.77}
else
local frame = player.gui.left.add({type = "frame", name = "fish_in_space"})
local label = frame.add({type = "label", caption = "Fish rescued: "})
label.style.font_color = {r=0.11, g=0.8, b=0.44}
local progress = global.fish_in_space / fish_in_space_needed
local progress = global.fish_in_space / global.fish_in_space_needed
if progress > 1 then progress = 1 end
local progressbar = frame.add({ type = "progressbar", value = progress})
progressbar.style.minimal_width = 100
@ -80,7 +83,7 @@ local function on_rocket_launched(event)
if not global.fish_in_space then global.fish_in_space = 0 end
global.fish_in_space = global.fish_in_space + launched_fish_count
if global.fish_in_space <= fish_in_space_needed then
if global.fish_in_space <= global.fish_in_space_needed then
game.print(launched_fish_count .. " fish have been saved.", {r=0.11, g=0.8, b=0.44})
end
@ -89,7 +92,7 @@ local function on_rocket_launched(event)
end
if not global.fish_in_space_win_condition then
if global.fish_in_space >= fish_in_space_needed then
if global.fish_in_space >= global.fish_in_space_needed then
event.rocket_silo.surface.peaceful_mode = true
global.fish_in_space_win_condition = true
for _, player in pairs(game.connected_players) do