1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00

biter_battles_v2/feeding

This commit is contained in:
MewMew 2019-03-15 21:50:49 +01:00
parent 0c60f3eb49
commit 9b442dbd9b
4 changed files with 103 additions and 29 deletions

View File

@ -87,6 +87,11 @@ local function init_forces(surface)
global.spectator_rejoin_delay = {} global.spectator_rejoin_delay = {}
global.spy_fish_timeout = {} global.spy_fish_timeout = {}
global.force_area = {} global.force_area = {}
global.bb_total_food = {}
global.bb_evolution = {}
global.bb_evasion = {}
global.bb_threat_income = {}
global.bb_threat = {}
for _, force in pairs(game.forces) do for _, force in pairs(game.forces) do
game.forces[force.name].technologies["artillery"].enabled = false game.forces[force.name].technologies["artillery"].enabled = false
@ -96,6 +101,11 @@ local function init_forces(surface)
game.forces[force.name].set_ammo_damage_modifier("shotgun-shell", 1) game.forces[force.name].set_ammo_damage_modifier("shotgun-shell", 1)
game.forces[force.name].research_queue_enabled = true game.forces[force.name].research_queue_enabled = true
global.spy_fish_timeout[force.name] = 0 global.spy_fish_timeout[force.name] = 0
global.bb_total_food[force.name] = 0
global.bb_evolution[force.name] = 0
global.bb_evasion[force.name] = 0
global.bb_threat_income[force.name] = 0
global.bb_threat[force.name] = 0
end end
global.game_lobby_active = true global.game_lobby_active = true

View File

@ -0,0 +1,69 @@
local event = require 'utils.event'
local food_values = {
["automation-science-pack"] = {value = 100, name = "automation science"},
["logistic-science-pack"] = {value = 292, name = "logistic science"},
["military-science-pack"] = {value = 1225, name = "military science"},
["chemical-science-pack"] = {value = 2392, name = "chemical science"},
["production-science-pack"] = {value = 8000, name = "production science"},
["utility-science-pack"] = {value = 13875, name = "utility science"},
["space-science-pack"] = {value = 42000, name = "space science"},
}
local threat_values = {
["small_biter"] = 1,
["medium_biter"] = 3,
["big_biter"] = 5,
["behemoth_biter"] = 10,
["small_spitter"] = 1,
["medium_spitter"] = 3,
["big_spitter"] = 5,
["behemoth_spitter"] = 10
}
local force_translation = {
["south_biters"] = "south",
["north_biters"] = "north"
}
local enemy_team_of = {
["north"] = "south",
["south"] = "north"
}
local function feed_biters(player, food)
game.print(food_values[food].name)
local enemy_team = enemy_team_of[player.force.name]
global.bb_threat[enemy_team] = global.bb_threat[enemy_team] + food_values[food].value
global.bb_total_food[enemy_team] = global.bb_total_food[enemy_team] + food_values[food].value
global.bb_evolution[enemy_team] = math.ceil(global.bb_total_food[enemy_team] * 0.001)
--global.bb_total_food = {}
--global.bb_evolution = {}
--global.bb_evasion = {}
--global.bb_threat_income = {}
--global.bb_threat = {}
end
--Biter Evasion
local function on_entity_damaged(event)
if not event.entity.valid then return end
if math.random(1,2) == 1 then return end
if event.entity.type ~= "unit" then return end
event.entity.health = event.entity.health + event.final_damage_amount
end
--Biter Threat Value Reduction
local function on_entity_died(event)
if not event.entity.valid then return end
if threat_values[event.entity.name] then
global.bb_threat[event.entity.force.name] = global.bb_threat[event.entity.force.name] - threat_values[event.entity.name]
return
end
end
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_entity_died, on_entity_died)
return feed_biters

View File

@ -1,6 +1,7 @@
local event = require 'utils.event' local event = require 'utils.event'
local spy_fish = require "maps.biter_battles_v2.spy_fish" local spy_fish = require "maps.biter_battles_v2.spy_fish"
local feed_the_biters = require "maps.biter_battles_v2.feeding"
local food_names = { local food_names = {
["automation-science-pack"] = "automation science", ["automation-science-pack"] = "automation science",
@ -12,21 +13,11 @@ local food_names = {
["space-science-pack"] = "space science" ["space-science-pack"] = "space science"
} }
local food_values = {
["automation-science-pack"] = 100,
["logistic-science-pack"] = 292,
["military-science-pack"] = 1225,
["chemical-science-pack"] = 2392,
["production-science-pack"] = 8000,
["utility-science-pack"] = 13875,
["space-science-pack"] = 42000
}
local gui_values = { local gui_values = {
[1] = {force = "north", c1 = "Team North", c2 = "JOIN NORTH", [1] = {force = "north", c1 = "Team North", c2 = "JOIN NORTH", n1 = "join_north_button",
t1 = "Evolution of the North side biters. Can go beyond 100% for endgame modifiers.", t1 = "Evolution of the North side biters. Can go beyond 100% for endgame modifiers.",
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99}}, t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.55, g = 0.55, b = 0.99}, color2 = {r = 0.66, g = 0.66, b = 0.99}},
[2] = {force = "south", c1 = "Team South", c2 = "JOIN SOUTH", [2] = {force = "south", c1 = "Team South", c2 = "JOIN SOUTH", n1 = "join_south_button",
t1 = "Evolution of the South side biters. Can go beyond 100% for endgame modifiers.", t1 = "Evolution of the South side biters. Can go beyond 100% for endgame modifiers.",
t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44}} t2 = "Threat causes biters to attack. Reduces when biters are slain.", color1 = {r = 0.99, g = 0.33, b = 0.33}, color2 = {r = 0.99, g = 0.44, b = 0.44}}
} }
@ -47,17 +38,17 @@ local function create_first_join_gui(player)
if not global.game_lobby_timeout then global.game_lobby_timeout = 5999940 end if not global.game_lobby_timeout then global.game_lobby_timeout = 5999940 end
if global.game_lobby_timeout - game.tick < 0 then global.game_lobby_active = false end if global.game_lobby_timeout - game.tick < 0 then global.game_lobby_active = false end
local frame = player.gui.left.add { type = "frame", name = "bb_main_gui", direction = "vertical" } local frame = player.gui.left.add { type = "frame", name = "bb_main_gui", direction = "vertical" }
local b = frame.add{ type = "label", caption = "Defend your team's rocket silo!" } local b = frame.add{ type = "label", caption = "Defend your Rocket Silo!" }
b.style.font = "default-bold" b.style.font = "heading-1"
b.style.font_color = {r=0.98, g=0.66, b=0.22} b.style.font_color = {r=0.98, g=0.66, b=0.22}
local b = frame.add { type = "label", caption = "Feed the enemy team's biters to gain advantage!" } local b = frame.add { type = "label", caption = "Feed the enemy team's biters to gain advantage!" }
b.style.font = "default-bold" b.style.font = "heading-2"
b.style.font_color = {r=0.98, g=0.66, b=0.22} b.style.font_color = {r=0.98, g=0.66, b=0.22}
for _, gui_value in pairs(gui_values) do for _, gui_value in pairs(gui_values) do
local t = frame.add { type = "table", column_count = 3 } local t = frame.add { type = "table", column_count = 3 }
local l = t.add { type = "label", caption = gui_value.c1} local l = t.add { type = "label", caption = gui_value.c1}
l.style.font = "default-bold" l.style.font = "heading-2"
l.style.font_color = gui_value.color1 l.style.font_color = gui_value.color1
local l = t.add { type = "label", caption = " - "} local l = t.add { type = "label", caption = " - "}
local l = t.add { type = "label", caption = #game.forces[gui_value.force].connected_players .. " Players "} local l = t.add { type = "label", caption = #game.forces[gui_value.force].connected_players .. " Players "}
@ -76,6 +67,7 @@ local function create_first_join_gui(player)
for _, p in pairs(game.forces.north.connected_players) do for _, p in pairs(game.forces.north.connected_players) do
local l = t.add({type = "label", caption = p.name}) local l = t.add({type = "label", caption = p.name})
l.style.font_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 = {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 = "heading-2"
end end
local b = frame.add { type = "sprite-button", name = gui_value.n1, caption = c } local b = frame.add { type = "sprite-button", name = gui_value.n1, caption = c }
b.style.font = "default-large-bold" b.style.font = "default-large-bold"
@ -102,10 +94,10 @@ local function create_main_gui(player)
s.tooltip = {"",food_tooltips[x]} s.tooltip = {"",food_tooltips[x]}
s.style.minimal_height = 42 s.style.minimal_height = 42
s.style.minimal_width = 42 s.style.minimal_width = 42
s.style.top_padding = 1 s.style.top_padding = 0
s.style.left_padding = 1 s.style.left_padding = 0
s.style.right_padding = 1 s.style.right_padding = 0
s.style.bottom_padding = 1 s.style.bottom_padding = 0
x = x + 1 x = x + 1
end end
end end
@ -129,11 +121,11 @@ local function create_main_gui(player)
end end
local t = frame.add { type = "table", column_count = 4 } local t = frame.add { type = "table", column_count = 4 }
local l = t.add { type = "label", caption = "Evolution:"} local l = t.add { type = "label", caption = "Evo:"}
--l.style.minimal_width = 25 --l.style.minimal_width = 25
l.tooltip = gui_value.t1 l.tooltip = gui_value.t1
local l = t.add { type = "label", caption = "100%"} local l = t.add { type = "label", caption = global.bb_evolution[gui_value.force]}
l.style.minimal_width = 40 l.style.minimal_width = 38
l.style.font_color = gui_value.color2 l.style.font_color = gui_value.color2
l.style.font = "default-bold" l.style.font = "default-bold"
l.tooltip = gui_value.t1 l.tooltip = gui_value.t1
@ -141,12 +133,12 @@ local function create_main_gui(player)
local l = t.add { type = "label", caption = "Threat: "} local l = t.add { type = "label", caption = "Threat: "}
l.style.minimal_width = 25 l.style.minimal_width = 25
l.tooltip = gui_value.t2 l.tooltip = gui_value.t2
local l = t.add { type = "label", caption = "35326"} local l = t.add { type = "label", caption = global.bb_threat[gui_value.force]}
l.style.font_color = gui_value.color2 l.style.font_color = gui_value.color2
l.style.font = "default-bold" l.style.font = "default-bold"
l.style.minimal_width = 25 l.style.minimal_width = 25
l.tooltip = gui_value.t2 l.tooltip = gui_value.t2
frame.add { type = "label", caption = "---------------------------------"} frame.add { type = "label", caption = "-----------------------------"}
end end
local t = frame.add { type = "table", column_count = 2 } local t = frame.add { type = "table", column_count = 2 }
@ -176,7 +168,6 @@ end
local function refresh_gui() local function refresh_gui()
for _, player in pairs(game.connected_players) do for _, player in pairs(game.connected_players) do
if player.gui.left["bb_main_gui"] then if player.gui.left["bb_main_gui"] then
player.gui.left["bb_main_gui"].destroy()
create_main_gui(player) create_main_gui(player)
end end
end end
@ -204,6 +195,7 @@ local function join_team(player, force_name)
local p = surface.find_non_colliding_position("player", game.forces[force_name].get_spawn_position(surface), 8, 0.5) local p = surface.find_non_colliding_position("player", game.forces[force_name].get_spawn_position(surface), 8, 0.5)
player.teleport(p, surface) player.teleport(p, surface)
player.force = game.forces[force_name] player.force = game.forces[force_name]
refresh_gui()
local p = game.permissions.get_group("Default") local p = game.permissions.get_group("Default")
p.add_player(player.name) p.add_player(player.name)
game.print("Team " .. player.force.name .. " player " .. player.name .. " is no longer spectating.", {r=0.98, g=0.66, b=0.22}) game.print("Team " .. player.force.name .. " player " .. player.name .. " is no longer spectating.", {r=0.98, g=0.66, b=0.22})
@ -220,7 +212,8 @@ local function join_team(player, force_name)
player.insert {name = 'firearm-magazine', count = 16} player.insert {name = 'firearm-magazine', count = 16}
player.insert {name = 'iron-gear-wheel', count = 4} player.insert {name = 'iron-gear-wheel', count = 4}
player.insert {name = 'iron-plate', count = 8} player.insert {name = 'iron-plate', count = 8}
global.chosen_team[player.name] = force_name global.chosen_team[player.name] = force_name
refresh_gui()
end end
local function spectate(player) local function spectate(player)
@ -270,7 +263,7 @@ local function on_gui_click(event)
if name == "raw-fish" then spy_fish(player) return end if name == "raw-fish" then spy_fish(player) return end
if food_names[name] then if food_names[name] then
--feed_the_biters(player, name) feed_the_biters(player, name)
return return
end end

View File

@ -124,9 +124,11 @@ local function on_chunk_generated(event)
generate_rainbow_ore(event) generate_rainbow_ore(event)
if event.area.left_top.y == -160 and event.area.left_top.x == -160 then if event.area.left_top.y == -160 and event.area.left_top.x == -160 then
for _, e in pairs(surface.find_entities_filtered({area = {{-10,-10},{10,10}}})) do local area = {{-10,-10},{10,10}}
for _, e in pairs(surface.find_entities_filtered({area = area})) do
if e.name ~= "player" then e.destroy() end if e.name ~= "player" then e.destroy() end
end end
surface.destroy_decoratives({area = area})
end end
end end