1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00

ore veins rewrite, nighttime, fixes

This commit is contained in:
MewMew 2019-10-18 07:01:14 +02:00
parent 47477431b9
commit 61cfdac8a1
8 changed files with 139 additions and 45 deletions

View File

@ -68,7 +68,7 @@ market.equipment = {
market.defense = { market.defense = {
["stone-wall"] = {value = 4, rarity = 1}, ["stone-wall"] = {value = 4, rarity = 1},
["gate"] = {value = 8, rarity = 1}, ["gate"] = {value = 8, rarity = 1},
["repair-pack"] = {value = 10, rarity = 1}, ["repair-pack"] = {value = 8, rarity = 1},
["gun-turret"] = {value = 64, rarity = 1}, ["gun-turret"] = {value = 64, rarity = 1},
["laser-turret"] = {value = 1024, rarity = 6}, ["laser-turret"] = {value = 1024, rarity = 6},
["flamethrower-turret"] = {value = 2048, rarity = 6}, ["flamethrower-turret"] = {value = 2048, rarity = 6},

View File

@ -8,6 +8,12 @@ function locomotive_spawn(surface, position)
global.locomotive_cargo = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + 3}, force = "player"}) global.locomotive_cargo = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + 3}, force = "player"})
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 8}) global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 8})
rendering.draw_light({
sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0,
oriented = true, color = {255,255,255}, target = global.locomotive,
surface = surface, visible = true, only_in_alt_mode = false,
})
global.locomotive.color = {0, 255, 0} global.locomotive.color = {0, 255, 0}
global.locomotive.minable = false global.locomotive.minable = false
global.locomotive_cargo.minable = false global.locomotive_cargo.minable = false
@ -58,9 +64,20 @@ local function set_player_spawn_and_refill_fish()
game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface) game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface)
end end
local function set_daytime()
if not global.locomotive_cargo then return end
if not global.locomotive_cargo.valid then return end
local p = global.locomotive_cargo.position.y
local t = math.abs(global.locomotive_cargo.position.y) * 0.02
if t > 0.5 then t = 0.5 end
global.locomotive_cargo.surface.daytime = t
game.print(t)
end
local function tick() local function tick()
if game.tick % 30 == 0 then if game.tick % 30 == 0 then
fish_tag() fish_tag()
--set_daytime()
accelerate() accelerate()
if game.tick % 1800 == 0 then if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish() set_player_spawn_and_refill_fish()

View File

@ -58,6 +58,8 @@ function reset_map()
local surface = game.surfaces[global.active_surface_index] local surface = game.surfaces[global.active_surface_index]
surface.freeze_daytime = true
surface.daytime = 0.5
surface.request_to_generate_chunks({0,0}, 2) surface.request_to_generate_chunks({0,0}, 2)
surface.force_generate_chunk_requests() surface.force_generate_chunk_requests()
@ -76,6 +78,7 @@ function reset_map()
game.map_settings.enemy_expansion.settler_group_min_size = 16 game.map_settings.enemy_expansion.settler_group_min_size = 16
game.map_settings.pollution.enabled = false game.map_settings.pollution.enabled = false
game.forces.player.technologies["landfill"].enabled = false
game.forces.player.technologies["railway"].researched = true game.forces.player.technologies["railway"].researched = true
game.forces.player.set_spawn_position({-2, 16}, surface) game.forces.player.set_spawn_position({-2, 16}, surface)
@ -84,9 +87,13 @@ function reset_map()
reset_wave_defense() reset_wave_defense()
global.wave_defense.surface_index = global.active_surface_index global.wave_defense.surface_index = global.active_surface_index
global.wave_defense.target = global.locomotive_cargo global.wave_defense.target = global.locomotive_cargo
global.wave_defense.side_target_search_radius = 512 global.wave_defense.side_target_search_radius = 768
global.wave_defense.game_lost = false global.wave_defense.game_lost = false
for _, p in pairs(game.connected_players) do
if p.character then p.character.disable_flashlight() end
end
end end
local function protect_train(event) local function protect_train(event)
@ -209,14 +216,20 @@ local function on_research_finished(event)
end end
local function on_player_joined_game(event) local function on_player_joined_game(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
if player.character then player.character.disable_flashlight() end
local surface = game.surfaces[global.active_surface_index] local surface = game.surfaces[global.active_surface_index]
global.wave_defense.surface_index = global.active_surface_index
global.wave_defense.target = global.locomotive_cargo
global.wave_defense.side_target_search_radius = 768
global.player_modifiers[player.index].character_mining_speed_modifier["mountain_fortress"] = 0.5 global.player_modifiers[player.index].character_mining_speed_modifier["mountain_fortress"] = 0.5
update_player_modifiers(player) update_player_modifiers(player)
--20 Players for maximum difficulty --20 Players for maximum difficulty
global.wave_defense.wave_interval = 3600 - #game.connected_players * 180 global.wave_defense.wave_interval = 3600 - #game.connected_players * 90
if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end if global.wave_defense.wave_interval < 1800 then global.wave_defense.wave_interval = 1800 end
if player.online_time == 0 then if player.online_time == 0 then
@ -237,10 +250,16 @@ local function on_player_joined_game(event)
end end
end end
local function on_player_respawned(event)
local player = game.players[event.player_index]
if player.character then player.character.disable_flashlight() end
end
local function on_init(surface) local function on_init(surface)
global.rocks_yield_ore_maximum_amount = 250 global.rocks_yield_ore_maximum_amount = 999
global.rocks_yield_ore_base_amount = 50 global.rocks_yield_ore_base_amount = 50
global.rocks_yield_ore_distance_modifier = 0.04 global.rocks_yield_ore_distance_modifier = 0.03
global.map_info = {} global.map_info = {}
global.map_info.main_caption = "Mountain Fortress" global.map_info.main_caption = "Mountain Fortress"
@ -255,14 +274,19 @@ local function on_init(surface)
"Mining productivity research, will overhaul your mining equipment,\n", "Mining productivity research, will overhaul your mining equipment,\n",
"reinforcing your pickaxe as well as increasing the size of your backpack.\n", "reinforcing your pickaxe as well as increasing the size of your backpack.\n",
"\n", "\n",
"As you dig, you will encounter impassable dark chasms.\n", "As you dig, you will encounter impassable dark chasms or rivers.\n",
"Some explosives may cause parts of the ceiling to crumble,\n", "Some explosives may cause parts of the ceiling to crumble,\n",
"filling the void, creating new ways.\n", "filling the void, creating new ways.\n",
"All they need is a container and a well aimed shot.\n", "All they need is a container and a well aimed shot.\n",
}) })
global.explosion_cells_destructible_tiles = { global.explosion_cells_destructible_tiles = {
["out-of-map"] = 1500, ["out-of-map"] = 2000,
["water"] = 1500,
["water-green"] = 1500,
["deepwater-green"] = 1500,
["deepwater"] = 1500,
["water-shallow"] = 1000,
} }
reset_map() reset_map()
@ -275,5 +299,6 @@ event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity) event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
event.add(defines.events.on_research_finished, on_research_finished) event.add(defines.events.on_research_finished, on_research_finished)
event.add(defines.events.on_player_joined_game, on_player_joined_game) event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_player_respawned, on_player_respawned)
require "modules.rocks_yield_ore" require "modules.rocks_yield_ore"

View File

@ -312,8 +312,8 @@ local room_weights = {
{func = room.tons_of_trees, weight = 15}, {func = room.tons_of_trees, weight = 15},
{func = room.tons_of_rocks, weight = 35}, {func = room.tons_of_rocks, weight = 35},
{func = room.quad_rocks, weight = 10}, {func = room.quad_rocks, weight = 7},
{func = room.three_rocks, weight = 5}, {func = room.three_rocks, weight = 3},
{func = room.single_rock, weight = 8}, {func = room.single_rock, weight = 8},
{func = room.checkerboard_ore, weight = 7}, {func = room.checkerboard_ore, weight = 7},

View File

@ -27,6 +27,7 @@ end
local function on_entity_damaged(event) local function on_entity_damaged(event)
if not event.entity.valid then return end if not event.entity.valid then return end
if event.entity.force.index ~= 3 then return end
if not entity_whitelist[event.entity.name] then return end if not entity_whitelist[event.entity.name] then return end
global.entities_regenerate_health[tostring(event.entity.position.x) .. "_" .. tostring(event.entity.position.y)] = {last_damage = game.tick, entity = event.entity} global.entities_regenerate_health[tostring(event.entity.position.x) .. "_" .. tostring(event.entity.position.y)] = {last_damage = game.tick, entity = event.entity}
end end

View File

@ -10,8 +10,9 @@ local valid_entities = {
local rock_mining_chance_weights = { local rock_mining_chance_weights = {
{"iron-ore", 25}, {"iron-ore", 25},
{"copper-ore",18}, {"copper-ore",18},
{"rainbow",15},
{"coal",14}, {"coal",14},
{"stone",10}, {"stone",8},
{"uranium-ore",3} {"uranium-ore",3}
} }
@ -22,11 +23,13 @@ for _, t in pairs (rock_mining_chance_weights) do
end end
end end
local rainbow_ores = {"iron-ore", "copper-ore", "stone", "coal"}
local size_raffle = { local size_raffle = {
{"huge", 33, 42}, {"huge", 33, 42},
{"big", 17, 32}, {"big", 17, 32},
{"", 8, 16}, {"", 8, 16},
{"tiny", 3, 7} {"tiny", 5, 11},
} }
local ore_prints = { local ore_prints = {
@ -34,41 +37,85 @@ local ore_prints = {
["iron-ore"] = {"shiny", "Iron"}, ["iron-ore"] = {"shiny", "Iron"},
["copper-ore"] = {"glimmering", "Copper"}, ["copper-ore"] = {"glimmering", "Copper"},
["uranium-ore"] = {"glowing", "Uranium"}, ["uranium-ore"] = {"glowing", "Uranium"},
["stone"] = {"solid", "Stone"} ["stone"] = {"solid", "Stone"},
["rainbow"] = {"glitter", "Rainbow ore"},
} }
local function on_player_mined_entity(event)
local entity = event.entity local function get_amount(position)
if not entity.valid then return end local distance_to_center = math.sqrt(position.x^2 + position.y^2) * 4 + 1500
if valid_entities[entity.name] then local m = (75 + math_random(0, 50)) * 0.01
if math_random(1,128) == 1 then return distance_to_center * m
local player = game.players[event.player_index] end
local p = {x = entity.position.x, y = entity.position.y}
local tile_distance_to_center = p.x^2 + p.y^2 local function draw_chain(surface, count, ore, ore_entities, ore_positions)
local radius = 32 local vectors = {{0,-1},{-1,0},{1,0},{0,1}}
if entity.surface.count_entities_filtered{area={{p.x - radius,p.y - radius},{p.x + radius,p.y + radius}}, type="resource", limit=1} == 0 then local r = math_random(1, #ore_entities)
local size = size_raffle[math_random(1, #size_raffle)] local position = {x = ore_entities[r].position.x, y = ore_entities[r].position.y}
local ore = ore_raffle[math_random(1, #ore_raffle)] for _ = 1, count, 1 do
player.print("You notice something " .. ore_prints[ore][1] .. " underneath the rubble covered floor. It's a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!!", { r=0.98, g=0.66, b=0.22}) table.shuffle_table(vectors)
tile_distance_to_center = math.sqrt(tile_distance_to_center) for i = 1, 4, 1 do
local ore_entities_placed = 0 local p = {x = position.x + vectors[i][1], y = position.y + vectors[i][2]}
local modifier_raffle = {{0,-1},{-1,0},{1,0},{0,1}} if surface.can_place_entity({name = "coal", position = p, amount = 1}) then
while ore_entities_placed < math_random(size[2],size[3]) do if not ore_positions[p.x .. "_" .. p.y] then
local a = math.floor((math_random(tile_distance_to_center*4, tile_distance_to_center*5)) / 1 + ore_entities_placed * 0.5) + 1 position.x = p.x
for x = 1, 150, 1 do position.y = p.y
local m = modifier_raffle[math_random(1,#modifier_raffle)] ore_positions[p.x .. "_" .. p.y] = true
local pos = {x = p.x + m[1], y = p.y + m[2]} local name = ore
if entity.surface.can_place_entity({name=ore, position=pos, amount=a}) then if ore == "rainbow" then name = rainbow_ores[math_random(1, #rainbow_ores)] end
entity.surface.create_entity {name=ore, position=pos, amount=a} ore_entities[#ore_entities + 1] = {name = name, position = p, amount = get_amount(position)}
p = pos break
break
end
end
ore_entities_placed = ore_entities_placed + 1
end end
end end
end end
end end
end end
local function ore_vein(event)
local surface = event.entity.surface
local size = size_raffle[math_random(1, #size_raffle)]
local ore = ore_raffle[math_random(1, #ore_raffle)]
local player = game.players[event.player_index]
for _, p in pairs(game.connected_players) do
if p.index == player.index then
p.print("You notice something " .. ore_prints[ore][1] .. " underneath the rubble covered floor. It's a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!!", { r=0.98, g=0.66, b=0.22})
else
game.print(player.name .. " found a " .. size[1] .. " vein of " .. ore_prints[ore][2] .. "!", { r=0.98, g=0.66, b=0.22})
end
end
local ore_entities = {{name = ore, position = {x = event.entity.position.x, y = event.entity.position.y}, amount = get_amount(event.entity.position)}}
if ore == "rainbow" then
ore_entities = {{name = rainbow_ores[math_random(1, #rainbow_ores)], position = {x = event.entity.position.x, y = event.entity.position.y}, amount = get_amount(event.entity.position)}}
end
local ore_positions = {[event.entity.position.x .. "_" .. event.entity.position.y] = true}
local count = math_random(size[2], size[3])
for _ = 1, 128, 1 do
local c = math_random(math.floor(size[2] * 0.25) + 1, size[2])
if count < c then c = count end
local placed_ore_count = #ore_entities
draw_chain(surface, c, ore, ore_entities, ore_positions)
count = count - (#ore_entities - placed_ore_count)
if count <= 0 then break end
end
game.print(#ore_entities)
for _, e in pairs(ore_entities) do surface.create_entity(e) end
end
local function on_player_mined_entity(event)
if not event.entity.valid then return end
if not valid_entities[event.entity.name] then return end
if math_random(1,512) ~= 1 then return end
ore_vein(event)
end
event.add(defines.events.on_player_mined_entity, on_player_mined_entity) event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -352,6 +352,8 @@ local function draw_gui(player, forced)
end end
local function draw_level_text(player) local function draw_level_text(player)
if not player.character then return end
if global.rpg[player.index].text then if global.rpg[player.index].text then
rendering.destroy(global.rpg[player.index].text) rendering.destroy(global.rpg[player.index].text)
global.rpg[player.index].text = nil global.rpg[player.index].text = nil
@ -676,11 +678,13 @@ end
local function on_player_joined_game(event) local function on_player_joined_game(event)
local player = game.players[event.player_index] local player = game.players[event.player_index]
if not global.rpg[player.index] then rpg_reset_player(player) return end if not global.rpg[player.index] then rpg_reset_player(player) end
for _, p in pairs(game.connected_players) do
draw_level_text(p)
end
draw_gui_char_button(player) draw_gui_char_button(player)
if not player.character then return end if not player.character then return end
update_player_stats(player) update_player_stats(player)
draw_level_text(player)
end end
local function on_init(event) local function on_init(event)

View File

@ -288,7 +288,7 @@ local function get_commmands(group)
commands[#commands + 1] = { commands[#commands + 1] = {
type = defines.command.attack_area, type = defines.command.attack_area,
destination = {x = global.wave_defense.target.position.x, y = global.wave_defense.target.position.y}, destination = {x = target_position.x, y = target_position.y},
radius = 8, radius = 8,
distraction = defines.distraction.by_enemy distraction = defines.distraction.by_enemy
} }