1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-17 20:58:13 +02:00
This commit is contained in:
MewMew 2019-04-15 20:19:32 +02:00
parent 185f729d4b
commit a35c92dc05
4 changed files with 181 additions and 43 deletions

View File

@ -1,6 +1,8 @@
-- fish defender -- by mewmew --
require "maps.fish_defender.map_intro"
require "maps.fish_defender.shotgun_buff"
require "modules.rocket_launch_always_yields_science"
require "modules.launch_fish_to_win"
require "modules.biters_yield_coins"
@ -506,6 +508,19 @@ local function wake_up_the_biters(surface)
})
end
local function damage_entity_outside_of_fence(e)
if not e.health then return end
if e.force.name == "neutral" then return end
if e.type == "unit" or e.type == "unit-spawner" then return end
e.surface.create_entity({name = "water-splash", position = e.position})
if e.type == "entity-ghost" then e.destroy() return end
e.health = e.health - math_random(math.floor(e.prototype.max_health * 0.05), math.floor(e.prototype.max_health * 0.1))
if e.health <= 0 then e.die("enemy") end
end
local function biter_attack_wave()
if not global.market then return end
if global.wave_grace_period then return end
@ -555,17 +570,8 @@ local function biter_attack_wave()
end
end
local units = surface.find_entities_filtered({force = "player", area = {{160, -256},{360, 256}}})
for _, unit in pairs(units) do
if unit.health then
unit.health = unit.health - math_random(75, 125)
surface.create_entity({name = "water-splash", position = unit.position})
if unit.health <= 0 then unit.die("enemy") end
else
if unit.type == "entity-ghost" then
unit.destroy()
end
end
for _, e in pairs(surface.find_entities_filtered({area = {{160, -256},{360, 256}}})) do
damage_entity_outside_of_fence(e)
end
local spawn_x = 242
@ -964,9 +970,7 @@ local function on_player_joined_game(event)
game.map_settings.enemy_evolution.pollution_factor = 0
game.map_settings.pollution.enabled = false
game.forces["player"].technologies["atomic-bomb"].enabled = false
game.forces.player.set_ammo_damage_modifier("shotgun-shell", 1)
game.forces["player"].technologies["atomic-bomb"].enabled = false
global.entity_limits = {
["gun-turret"] = {placed = 1, limit = 1, str = "gun turret", slot_price = 75},
@ -984,8 +988,8 @@ local function on_player_joined_game(event)
game.forces["player"].set_cease_fire("decoratives", true)
global.comfylatron_habitat = {
left_top = {x = -1250, y = -1250},
right_bottom = {x = -60, y = 1250}
left_top = {x = -1500, y = -1500},
right_bottom = {x = -80, y = 1500}
}
global.fish_defense_init_done = true

View File

@ -0,0 +1,28 @@
local event = require 'utils.event'
local gain_multiplier = 4
local function on_research_finished(event)
local research = event.research
local force_name = research.force.name
if not global.shotgun_shell_damage_modifier_old[force_name] then global.shotgun_shell_damage_modifier_old[force_name] = game.forces[force_name].get_ammo_damage_modifier("shotgun-shell") - 0.1 end
if string.sub(research.name, 0, 26) == "physical-projectile-damage" then
local current_damage = game.forces[force_name].get_ammo_damage_modifier("shotgun-shell")
local vanilla_gain = current_damage - global.shotgun_shell_damage_modifier_old[force_name]
local additional_gain = vanilla_gain * (gain_multiplier - 1)
game.forces[force_name].set_ammo_damage_modifier("shotgun-shell", current_damage + additional_gain)
end
global.shotgun_shell_damage_modifier_old[force_name] = game.forces[force_name].get_ammo_damage_modifier("shotgun-shell")
end
local function on_init()
game.forces.player.set_ammo_damage_modifier("shotgun-shell", 1)
global.shotgun_shell_damage_modifier_old = {}
end
event.on_init(on_init)
event.add(defines.events.on_research_finished, on_research_finished)

View File

@ -13,10 +13,14 @@ end
local texts = {
["travelings"] = {
"bzzZZrrt",
"vroooOOm",
"WEEEeeeeeee",
"out of my way son",
"comfylatron coming through",
"on my way",
"i need to leave",
"comfylatron seeking target",
"gotta go fast",
"gas gas gas",
"comfylatron coming through"
},
["greetings"] = {
"=^_^=",
@ -47,7 +51,7 @@ local texts = {
"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... zero one zero one one zero zero one... two.",
"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!",
@ -68,18 +72,19 @@ local texts = {
"Good news! I’ve taught the inserter to feel love!"
},
["alone"] = {
"where did you go fren ;_;",
"where did everyone go..",
"where are you °_°",
"where is everyone",
"where am i",
"think i'm lost",
"comfylatron derping out *.*",
"comfy ^.^",
"comfy :)",
"*.*",
"....",
"...",
"..",
"^.^",
"=^.^=",
"01010010",
"11001011",
"01011101",
"00010111",
"10010010",
"*_*"
}
}
@ -113,7 +118,7 @@ end
local function visit_player()
if global.comfylatron_last_player_visit > game.tick then return false end
global.comfylatron_last_player_visit = game.tick + math_random(10800, 18000)
global.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
local players = {}
for _, p in pairs(game.connected_players) do
@ -164,7 +169,9 @@ end
local function talks(nearby_characters)
if not nearby_characters then return false end
if math_random(1,3) == 1 then
if global.comfybubble then global.comfybubble.destroy() return false end
end
local str
if #nearby_characters == 1 then
local c = nearby_characters[math_random(1, #nearby_characters)]
@ -182,31 +189,56 @@ local function talks(nearby_characters)
return true
end
local function desync()
if global.comfybubble then global.comfybubble.destroy() end
local m = 12
local m2 = m * 0.005
for i = 1, 32, 1 do
global.comfylatron.surface.create_entity({
name = "iron-ore-particle",
position = global.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
global.comfylatron.surface.create_entity({name = "medium-explosion", position = global.comfylatron.position})
global.comfylatron.surface.create_entity({name = "flying-text", position = global.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}})
global.comfylatron.destroy()
global.comfylatron = nil
end
local function alone()
if math_random(1,5) == 1 then global.comfybubble.destroy() return true end
if math_random(1,3) == 1 then
if global.comfybubble then global.comfybubble.destroy() return true end
end
if math_random(1,128) == 1 then
global.comfybubble.destroy()
global.comfylatron.surface.create_entity({name = "medium-explosion", position = global.comfylatron.position})
global.comfylatron.surface.create_entity({name = "flying-text", position = global.comfylatron.position, text = "desync", color = {r = 150, g = 0, b = 0}})
global.comfylatron.destroy()
global.comfylatron = nil
desync()
return true
end
set_comfy_speech_bubble(texts["alone"][math_random(1, #texts["alone"])])
return true
end
local analyze_blacklist = {
["compilatron"] = true,
["compi-speech-bubble"] = true,
["entity-ghost"] = true,
["item-on-ground"] = true
}
local function analyze_random_nearby_entity()
if math_random(1,2) ~= 1 then return false end
if math_random(1,3) ~= 1 then return false end
local entities = global.comfylatron.surface.find_entities_filtered({
area = {{global.comfylatron.position.x - 5, global.comfylatron.position.y - 5}, {global.comfylatron.position.x + 5, global.comfylatron.position.y + 5}}
area = {{global.comfylatron.position.x - 4, global.comfylatron.position.y - 4}, {global.comfylatron.position.x + 4, global.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 e.name ~= "compilatron" and e.name ~= "compi-speech-bubble" then
if not analyze_blacklist[e.name] then
entity = e
end
end
@ -244,8 +276,62 @@ local function analyze_random_nearby_entity()
return true
end
local function go_to_some_location()
if math_random(1,4) ~= 1 then return false end
if global.comfylatron_greet_player_index then
local player = game.players[global.comfylatron_greet_player_index]
if not player.character then
global.comfylatron_greet_player_index = nil
return false
end
if not player.character.valid then
global.comfylatron_greet_player_index = nil
return false
end
if not is_target_inside_habitat(player.position) then
global.comfylatron_greet_player_index = nil
return false
end
global.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 = global.comfylatron.position.x + (-96 + math_random(0, 192)), y = global.comfylatron.position.y + (-96 + math_random(0, 192))}
local target = global.comfylatron.surface.find_non_colliding_position("compilatron", p, 8, 1)
if not target then return false end
if not is_target_inside_habitat(target) then return false end
global.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()
if global.comfylatron_disabled then return end
if global.comfylatron_disabled then return false end
if global.comfylatron then
if global.comfylatron.valid then
global.comfylatron.die("enemy")
@ -258,9 +344,18 @@ local function spawn_comfylatron()
right_bottom = {x = 512, y = 512}
}
end
local player = game.connected_players[math_random(1, #game.connected_players)]
local players = {}
for _, p in pairs(game.connected_players) do
if is_target_inside_habitat(p.position) 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)]
local position = player.surface.find_non_colliding_position("compilatron", player.position, 16, 1)
if not position then return end
if not position then return false end
global.comfylatron = player.surface.create_entity({
name = "compilatron",
position = position,
@ -279,20 +374,29 @@ local function spawn_comfylatron()
end
local function heartbeat()
if not global.comfylatron then spawn_comfylatron() return end
if not global.comfylatron then if math_random(1,4) == 1 then spawn_comfylatron() end return end
if not global.comfylatron.valid then global.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
if alone() then return end
end
local function on_entity_damaged(event)
if not global.comfylatron then return end
if not event.entity.valid then return end
if event.entity ~= global.comfylatron then return end
desync()
end
local function on_tick()
if game.tick % 1800 == 900 then
if game.tick % 900 == 450 then
heartbeat()
end
end
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_tick, on_tick)

View File

@ -41,7 +41,9 @@ local function on_player_died(event)
return
end
if cause.name == "player" then
if cause.name == "player" then
if not player.name then return end
if not cause.player.name then return end
game.print(player.name .. tag .. " was killed by " .. cause.player.name " " .. cause.player.tag .. ".", message_color)
return
end