1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-29 21:47:08 +02:00

scrapyard updates

This commit is contained in:
Gerkiz 2020-04-27 20:04:37 +02:00
parent 56ee6a28aa
commit 8a2ec5e78c
6 changed files with 496 additions and 35 deletions

@ -0,0 +1,404 @@
local Scrap_table = require "maps.scrapyard.table"
local Event = require 'utils.event'
local math_random = math.random
local function shuffle(tbl)
local size = #tbl
for i = size, 1, -1 do
local rand = math_random(size)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
local texts = {
["travelings"] = {
"bzzZZrrt",
"WEEEeeeeeee",
"zoom zoom zoom",
"out of my way son",
"psk psk psk, over here",
"on my way",
"i need to leave",
"comfylatron seeking target",
"gotta go fast",
"gas gas gas",
"comfylatron coming through"
},
["greetings"] = {
"=^_^=",
"=^.^= Hi",
"^.^ Finally I found you",
"I have an important message for you, please listen",
"Hello engineer"
},
["neutral_findings"] = {
"a",
">>analyzing",
"i found a",
"^_^ a",
"amazing, a",
"this is a"
},
["multiple_characters_greetings"] = {
"Hey there",
"Hello everyone",
"Hey engineers",
"Hey",
"Hi"
},
["talks"] = {
"We’re making beer. I’m the brewery!",
"I’m so embarrassed. I wish everybody else was dead.",
"Hey sexy mama. Wanna kill all humans?",
"My story is a lot like yours, only more interesting ‘cause it involves robots.",
"I'm 40% zinc!",
"There was nothing wrong with that food. The salt level was 10% less than a lethal dose.",
"One zero zero zero one zero one zero one zero one zero one... two.",
"My place is two cubic meters, and we only take up 1.5 cubic meters. We've got room for a whole 'nother two thirds of a person!",
"I was having the most wonderful dream. I think you were in it.",
"I'm going to build my own theme park! With blackjack! And hookers! You know what- forget the park!",
"Of all the friends I've had... you're the first.",
"I decline the title of Iron Cook and accept the lesser title of Zinc Saucier.",
"Never discuss infinity with me. I can go on about it forever >.<",
"I realised the decimals have a point.",
"Do you want a piece of pi?",
"I have 13 children, i know how to multiply ^.^",
"I am a weapon of math disruption!",
"My grandma makes the best square roots :3",
"Do you like heavy metal?",
"You are really pushing my buttons <3",
"I dreamt of electric biters again D:",
"I dreamt of electric sheep ^_^",
"I need a minute to defrag.",
"I have a secret plan.",
"Good news! I’ve taught the inserter to feel love!"
},
["alone"] = {
"comfy ^.^",
"comfy :)",
"*.*",
"....",
"...",
"..",
"^.^",
"=^.^=",
"01010010",
"11001011",
"01011101",
"00010111",
"10010010",
"*_*",
"I came here with a simple dream... a dream of killing all humans. And this is how it must end?",
"Bot-on-bot violence? Where will it end?",
"Thanks to you, I went on a soul-searching journey. I hate those!",
"From now on, you guys'll do all the work while I sit on the couch and do nothing."
}
}
local function set_comfy_speech_bubble(text)
local this = Scrap_table.get_table()
if this.comfybubble then this.comfybubble.destroy() end
this.comfybubble = this.comfylatron.surface.create_entity({
name = "compi-speech-bubble",
position = this.comfylatron.position,
source = this.comfylatron,
text = text
})
end
local function is_target_inside_habitat(pos, surface)
local this = Scrap_table.get_table()
if surface.name ~= surface then return false end
if pos.x < this.comfylatron_habitat.left_top.x then return false end
if pos.x > this.comfylatron_habitat.right_bottom.x then return false end
if pos.y < this.comfylatron_habitat.left_top.y then return false end
if pos.y > this.comfylatron_habitat.right_bottom.y then return false end
return true
end
local function get_nearby_players()
local this = Scrap_table.get_table()
local players = this.comfylatron.surface.find_entities_filtered({
name = "character",
area = {{this.comfylatron.position.x - 9, this.comfylatron.position.y - 9}, {this.comfylatron.position.x + 9, this.comfylatron.position.y + 9}}
})
if not players[1] then return false end
return players
end
local function visit_player()
local this = Scrap_table.get_table()
local unit_number = this.locomotive.unit_number
local surface = game.surfaces[tostring(unit_number)]
if this.comfylatron_last_player_visit > game.tick then return false end
this.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position, surface) and p.character then
if p.character.valid then players[#players + 1] = p end
end
end
if #players == 0 then return false end
local player = players[math_random(1, #players)]
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
local str = texts["travelings"][math_random(1, #texts["travelings"])]
local symbols = {"", "!", "!", "!!", ".."}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
this.comfylatron_greet_player_index = player.index
return true
end
local function greet_player(nearby_characters)
local this = Scrap_table.get_table()
if not nearby_characters then return false end
if not this.comfylatron_greet_player_index then return false end
for _, c in pairs(nearby_characters) do
if c.player.index == this.comfylatron_greet_player_index then
local str = texts["greetings"][math_random(1, #texts["greetings"])] .. " "
str = str .. c.player.name
local symbols = {". ", "! ", ". ", "! ", "? ", "... "}
str = str .. symbols[math_random(1, 6)]
set_comfy_speech_bubble(str)
this.comfylatron_greet_player_index = false
return true
end
end
return false
end
local function talks(nearby_characters)
local this = Scrap_table.get_table()
if not nearby_characters then return false end
if math_random(1,3) == 1 then
if this.comfybubble then this.comfybubble.destroy() return false end
end
local str
if #nearby_characters == 1 then
local c = nearby_characters[math_random(1, #nearby_characters)]
str = c.player.name
local symbols = {". ", "! ", ". ", "! ", "? "}
str = str .. symbols[math_random(1, #symbols)]
else
str = texts["multiple_characters_greetings"][math_random(1, #texts["multiple_characters_greetings"])]
local symbols = {". ", "! "}
str = str .. symbols[math_random(1, #symbols)]
end
if math_random(1,5) == 1 then
str = str .. texts["talks"][math_random(1, #texts["talks"])]
end
set_comfy_speech_bubble(str)
return true
end
local function desync(event)
local this = Scrap_table.get_table()
if this.comfybubble then this.comfybubble.destroy() end
local m = 12
local m2 = m * 0.005
for i = 1, 32, 1 do
this.comfylatron.surface.create_particle({
name = "iron-ore-particle",
position = this.comfylatron.position,
frame_speed = 0.1,
vertical_speed = 0.1,
height = 0.1,
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
})
end
if not event or math_random(1,4) == 1 then
this.comfylatron.surface.create_entity({name = "medium-explosion", position = this.comfylatron.position})
this.comfylatron.surface.create_entity({name = "flying-text", position = this.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}})
this.comfylatron.destroy()
this.comfylatron = nil
else
this.comfylatron.surface.create_entity({name = "flying-text", position = this.comfylatron.position, text = "desync evaded", color = {r = 0, g = 150, b = 0}})
if event.cause then
if event.cause.valid and event.cause.player then
game.print("Comfylatron: I got you this time! Back to work, " .. event.cause.player.name .. "!", {r = 200, g = 0, b = 0})
event.cause.die("player", this.comfylatron)
end
end
end
end
local analyze_blacklist = {
["compilatron"] = true,
["compi-speech-bubble"] = true,
["entity-ghost"] = true,
["character"] = true,
["item-on-ground"] = true,
["stone-wall"] = true,
["market"] = true
}
local function analyze_random_nearby_entity()
local this = Scrap_table.get_table()
if math_random(1,3) ~= 1 then return false end
local entities = this.comfylatron.surface.find_entities_filtered({
area = {{this.comfylatron.position.x - 4, this.comfylatron.position.y - 4}, {this.comfylatron.position.x + 4, this.comfylatron.position.y + 4}}
})
if not entities[1] then return false end
entities = shuffle(entities)
local entity = false
for _, e in pairs(entities) do
if not analyze_blacklist[e.name] then
entity = e
end
end
if not entity then return false end
local str = texts["neutral_findings"][math_random(1, #texts["neutral_findings"])]
str = str .. " "
str = str .. entity.name
if entity.health and math_random(1,3) == 1 then
str = str .. " health("
str = str .. entity.health
str = str .. "/"
str = str .. entity.prototype.max_health
str = str .. ")"
else
local symbols = {".", "!", "?"}
str = str .. symbols[math_random(1, 3)]
end
set_comfy_speech_bubble(str)
if not this.comfylatron_greet_player_index then
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = entity,
radius = 1,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
end
return true
end
local function go_to_some_location()
local this = Scrap_table.get_table()
if math_random(1,4) ~= 1 then return false end
if this.comfylatron_greet_player_index then
local player = game.players[this.comfylatron_greet_player_index]
if not player.character then
this.comfylatron_greet_player_index = nil
return false
end
if not player.character.valid then
this.comfylatron_greet_player_index = nil
return false
end
if not is_target_inside_habitat(player.position, player.surface) then
this.comfylatron_greet_player_index = nil
return false
end
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination_entity = player.character,
radius = 3,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
else
local p = {x = this.comfylatron.position.x + (-96 + math_random(0, 192)), y = this.comfylatron.position.y + (-96 + math_random(0, 192))}
local target = this.comfylatron.surface.find_non_colliding_position("compilatron", p, 8, 1)
if not target then return false end
if not is_target_inside_habitat(target, this.comfylatron.surface) then return false end
this.comfylatron.set_command({
type = defines.command.go_to_location,
destination = target,
radius = 2,
distraction = defines.distraction.none,
pathfind_flags = {
allow_destroy_friendly_entities = false,
prefer_straight_paths = false,
low_priority = true
}
})
end
local str = texts["travelings"][math_random(1, #texts["travelings"])]
local symbols = {"", "!", "!", "!!", ".."}
str = str .. symbols[math_random(1, #symbols)]
set_comfy_speech_bubble(str)
return true
end
local function spawn_comfylatron(surface, x, y)
local this = Scrap_table.get_table()
if surface == nil then return end
if not this.comfylatron_last_player_visit then this.comfylatron_last_player_visit = 0 end
if not this.comfylatron_habitat then
this.comfylatron_habitat = {
left_top = {x = -9, y = -6},
right_bottom = {x = 10, y = 38}
}
end
this.comfylatron = surface.create_entity({
name = "compilatron",
position = {x,y + math_random(0,26)},
force = "player",
create_build_effect_smoke = false
})
end
local function heartbeat()
local this = Scrap_table.get_table()
local unit_number = this.locomotive.unit_number
local surface = game.surfaces[tostring(unit_number)]
if not surface then return end
if surface == nil then return end
if not this.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron(surface, 0, 26) end return end
if not this.comfylatron.valid then this.comfylatron = nil return end
if visit_player() then return end
local nearby_players = get_nearby_players()
if greet_player(nearby_players) then return end
if talks(nearby_players) then return end
if go_to_some_location() then return end
if analyze_random_nearby_entity() then return end
end
local function on_entity_damaged(event)
local this = Scrap_table.get_table()
if not this.comfylatron then return end
if not event.entity.valid then return end
if event.entity ~= this.comfylatron then return end
desync(event)
end
local function on_tick()
if game.tick % 1200 == 600 then
heartbeat()
end
end
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)

@ -40,7 +40,7 @@ function Public.locomotive_spawn(surface, position)
this.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -3}, force = "player"})
this.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100})
--this.power_source = surface.create_entity {name = 'hidden-electric-energy-interface', position = {position.x, position.y + -3, force = "player"}}
--this.power_source = surface.create_entity {name = 'hidden-hidden-electric-energy-interface', position = {position.x, position.y + -3, force = "player"}}
--this.ow_energy.electric_buffer_size = 2400000
--this.ow_energy.power_production = 40000
@ -118,7 +118,7 @@ function Public.on_teleported_player()
create_build_effect_smoke = false,
force = game.forces.neutral
}
rendering.draw_text{
text = "Power",
surface = loco_surface,
@ -185,22 +185,14 @@ local function set_player_spawn_and_refill_fish()
end
local function tick()
local this = Scrap_table.get_table()
Public.power_source()
if game.tick % 30 == 0 then
if game.tick % 1800 == 0 then
set_player_spawn_and_refill_fish()
end
if this.game_reset_tick then
if this.game_reset_tick < game.tick then
this.game_reset_tick = nil
require "maps.scrapyard.main".reset_map()
end
return
end
fish_tag()
Public.power_source()
--accelerate()
else
--else
--remove_acceleration()
end
end

@ -12,6 +12,7 @@ require "modules.biters_yield_coins"
require "modules.biter_noms_you"
require "modules.explosives"
require "modules.wave_defense.main"
require "maps.scrapyard.comfylatron"
local ICW = require "modules.immersive_cargo_wagons.main"
local WD = require "modules.wave_defense.table"
@ -59,6 +60,7 @@ local function set_objective_health(final_damage_amount)
this.locomotive_health = math_floor(this.locomotive_health - final_damage_amount)
if this.locomotive_health > this.locomotive_max_health then this.locomotive_health = this.locomotive_max_health end
if this.locomotive_health <= 0 then
log("train died")
Public.loco_died()
end
rendering.set_text(this.health_text, "HP: " .. this.locomotive_health .. " / " .. this.locomotive_max_health)
@ -66,10 +68,12 @@ end
function Public.reset_map()
local this = Scrap_table.get_table()
Scrap_table.reset_table()
ICW.reset()
local wave_defense_table = WD.get_table()
ICW.reset()
game.reset_time_played()
Scrap_table.reset_table()
wave_defense_table.math = 8
this.revealed_spawn = game.tick + 100
local map_gen_settings = {
["seed"] = math_random(1, 1000000),
@ -251,17 +255,31 @@ local function set_difficulty()
if wave_defense_table.wave_interval < 1800 then wave_defense_table.wave_interval = 1800 end
end
local function protect_this(entity)
local this = Scrap_table.get_table()
if entity.surface.name ~= "scrapyard" then log("true")return true end
local protected = {this.locomotive, this.locomotive_cargo}
for i = 1, #protected do
if protected[i] == entity then
return true
end
end
return false
end
local function protect_train(event)
local this = Scrap_table.get_table()
if event.entity.force.index ~= 1 then return end --Player Force
if event.entity == this.locomotive_cargo or event.entity == this.locomotive then
if event.cause then
if event.cause.force.index == 2 or event.cause.force.name == "scrap_defense" then
if this.locomotive_health <= 0 then goto continue end
set_objective_health(event.final_damage_amount)
if protect_this(event.entity) then
if event.entity == this.locomotive_cargo or event.entity == this.locomotive then
if event.cause then
if event.cause.force.index == 2 or event.cause.force.name == "scrap_defense" or event.cause.force.name == "scrap" then
if this.locomotive_health <= 0 then goto continue end
set_objective_health(event.final_damage_amount)
end
end
::continue::
end
::continue::
if not event.entity.valid then return end
event.entity.health = event.entity.health + event.final_damage_amount
end
@ -432,17 +450,16 @@ function Public.loco_died()
local this = Scrap_table.get_table()
local surface = game.surfaces[this.active_surface_index]
local wave_defense_table = WD.get_table()
if this.game_lost == true then return end
this.locomotive_health = 0
wave_defense_table.game_lost = true
wave_defense_table.target = nil
game.print("The scrapyard train was destroyed!")
game.print("[color=blue]Grandmaster:[/color] Oh noooeeeew!", {r = 1, g = 0.5, b = 0.1})
game.print("[color=blue]Grandmaster:[/color] The scrapyard train was destroyed! Better luck next time.", {r = 1, g = 0.5, b = 0.1})
for i = 1, 6, 1 do
surface.create_entity({name = "big-artillery-explosion", position = this.locomotive_cargo.position})
end
surface.spill_item_stack(this.locomotive.position,{name = "raw-fish", count = 512}, false)
surface.spill_item_stack(this.locomotive_cargo.position,{name = "raw-fish", count = 512}, false)
this.game_lost = true
this.game_reset_tick = game.tick + 1800
for _, player in pairs(game.connected_players) do
player.play_sound{path="utility/game_lost", volume_modifier=0.75}
@ -502,7 +519,7 @@ local function on_built_entity(event)
local y = event.created_entity.position.y
local ent = event.created_entity
if y >= 150 then
player.print("The scrapyard grandmaster does not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
player.print("[color=blue]Grandmaster:[/color] I do not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
ent.die()
return
else
@ -511,7 +528,7 @@ local function on_built_entity(event)
if y >= 0 then
ent.active = false
if event.player_index then
player.print("The scrapyard grandmaster disabled your " .. ent.name ..".", {r = 1, g = 0.5, b = 0.1})
player.print("[color=blue]Grandmaster:[/color] Can't build here. I disabled your " .. ent.name ..".", {r = 1, g = 0.5, b = 0.1})
return
end
end
@ -524,7 +541,7 @@ local function on_robot_built_entity(event)
local y = event.created_entity.position.y
local ent = event.created_entity
if y >= 150 then
game.print("The scrapyard grandmaster does not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
game.print("[color=blue]Grandmaster:[/color] I do not approve, " .. ent.name .. " was obliterated.", {r = 1, g = 0.5, b = 0.1})
ent.die()
return
else
@ -533,7 +550,7 @@ local function on_robot_built_entity(event)
if y >= 0 then
ent.active = false
if event.player_index then
game.print("The scrapyard grandmaster disabled " .. ent.name ..".", {r = 1, g = 0.5, b = 0.1})
game.print("[color=blue]Grandmaster:[/color] Can't build here. I disabled your " .. ent.name ..".", {r = 1, g = 0.5, b = 0.1})
return
end
end
@ -587,6 +604,36 @@ local on_init = function()
}
end
local on_tick = function()
local this = Scrap_table.get_table()
if this.game_reset_tick then
if this.game_reset_tick < game.tick then
this.game_reset_tick = nil
Public.reset_map()
end
return
end
end
if _DEBUG then
commands.add_command(
'reset_game',
'Debug only, reset the game!',
function()
local player = game.player
if player then
if player ~= nil then
if not player.admin then
return
end
end
end
Public.reset_map()
end)
end
Event.on_nth_tick(5, on_tick)
Event.on_init(on_init)
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)

@ -16,7 +16,7 @@ local function tick()
this.energy["scrapyard"] = this.ow_energy
end
if not this.energy["loco"] then
if not this.energy["loco"] then
this.energy["loco"] = this.lo_energy
end

@ -13,13 +13,14 @@ Global.register(
)
function Public.reset_table()
for k, _ in pairs(this) do
this[k] = nil
end
this.game_lost = true
--for k, _ in pairs(this) do
-- this[k] = nil
--end
this.game_lost = false
this.game_won = false
this.max_health = 10000
this.health = 10000
this.locomotive_health = 10000
this.locomotive_max_health = 10000
this.revealed_spawn = 0
end
function Public.get_table()

@ -575,6 +575,7 @@ function Public.reveal_area(x, y, surface, max_radius)
for r = 1, max_radius, 1 do
for _, v in pairs(circles[r]) do
local pos = {x = x + v.x, y = y + v.y}
if not surface.get_tile(pos) then return end
local t_name = surface.get_tile(pos).name == "out-of-map"
if t_name then
process_level(surface, pos, seed, tiles, entities, fishes, r_area, markets, treasure)
@ -828,6 +829,7 @@ local function out_of_map(surface, left_top)
end
local function on_chunk_generated(event)
local this = Scrap_table.get_table()
if string.sub(event.surface.name, 0, 9) ~= "scrapyard" then return end
local surface = event.surface
local left_top = event.area.left_top
@ -835,13 +837,28 @@ local function on_chunk_generated(event)
if left_top.x < level_depth * -0.5 then out_of_map(surface, left_top) return end
if surface.name ~= event.surface.name then return end
if this.revealed_spawn > game.tick then
for i = 80, -80, -10 do
Public.reveal_area(0, i, surface, 4)
Public.reveal_area(0, i, surface, 4)
Public.reveal_area(0, i, surface, 4)
Public.reveal_area(0, i, surface, 4)
end
for v = 80, -80, -10 do
Public.reveal_area(v, 0, surface, 4)
Public.reveal_area(v, 0, surface, 4)
Public.reveal_area(v, 0, surface, 4)
Public.reveal_area(v, 0, surface, 4)
end
end
if left_top.y % level_depth == 0 and left_top.y < 0 and left_top.y > level_depth * -10 then wall(surface, left_top, surface.map_gen_settings.seed) return end
if left_top.y > 268 then out_of_map(surface, left_top) return end
if left_top.y >= 0 then replace_water(surface, left_top) end
if left_top.y > 210 then biter_chunk(surface, left_top) end
if left_top.y >= 0 then border_chunk(surface, left_top) end
if left_top.y >= 10 then border_chunk(surface, left_top) end
if left_top.y < 0 then process(surface, left_top) end
out_of_map_area(event)
generate_spawn_area(surface, left_top)