1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

many tweaks

This commit is contained in:
MewMew 2019-12-19 17:11:13 +01:00
parent 2569958b43
commit b4d9623809
5 changed files with 96 additions and 16 deletions

View File

@ -48,7 +48,7 @@ local function on_player_died(event)
return
end
if cause.name == "tank" then
if cause.type == "car" then
local driver = cause.get_driver()
if driver.player then
game.print(player.name .. tag .. " was killed by " .. driver.player.name .. " " .. player.tag .. ".", message_color)

View File

@ -1,6 +1,6 @@
local Public = {}
local connection_radius = 5
local connection_radius = 7
local entity_type_whitelist = {
["accumulator"] = true,

View File

@ -103,9 +103,28 @@ local function on_gui_click(event)
Info.close(event)
end
local function on_player_died(event)
local player = game.players[event.player_index]
if not player.character then return end
if not player.character.valid then return end
Team.reveal_entity_to_all(player.character)
end
local minute_actions = {
[60 * 5] = Team.update_town_chart_tags,
[60 * 10] = Team.set_all_player_colors,
}
local function on_nth_tick(event)
local tick = game.tick % 3600
if not minute_actions[tick] then return end
minute_actions[tick]()
end
local function on_init()
global.towny = {}
global.towny.requests = {}
global.towny.request_cooldowns = {}
global.towny.town_centers = {}
global.towny.cooldowns = {}
global.towny.size_of_town_centers = 0
@ -126,6 +145,7 @@ end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.on_nth_tick(60, on_nth_tick)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_console_command, on_console_command)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
@ -138,4 +158,5 @@ Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
Event.add(defines.events.on_player_dropped_item, on_player_dropped_item)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_player_died, on_player_died)

View File

@ -35,6 +35,12 @@ function Public.set_town_color(event)
end
end
function Public.set_all_player_colors()
for _, p in pairs(game.connected_players) do
Public.set_player_color(p)
end
end
function Public.add_player_to_town(player, town_center)
player.force = town_center.market.force
game.permissions.get_group("Default").add_player(player)
@ -175,7 +181,52 @@ function Public.declare_war(player, item)
requesting_force.set_friend(target_force, false)
target_force.set_friend(requesting_force, false)
game.print(">> Town " .. requesting_force.name .. " has set " .. target_force.name .. " as their foe!", {255, 255, 0})
game.print(">> " .. player.name .. " has dropped the coal! Town " .. target_force.name .. " and " .. requesting_force.name .. " are now at war!", {255, 255, 0})
end
local radius = 48
function Public.reveal_entity_to_all(entity)
local chart_area = {{entity.position.x - radius, entity.position.y - radius}, {entity.position.x + radius, entity.position.y + radius}}
local surface = entity.surface
for _, force in pairs(game.forces) do
force.chart(surface, chart_area)
end
end
local function delete_chart_tag_for_all_forces(market)
local forces = game.forces
local position = market.position
local surface = market.surface
for _, force in pairs(forces) do
local tags = force.find_chart_tags(surface, {{position.x - 0.1, position.y - 0.1}, {position.x + 0.1, position.y + 0.1}})
local tag = tags[1]
if tag then
if tag.icon.name == "stone-furnace" then
tag.destroy()
end
end
end
end
local function add_chart_tag(force, market)
local position = market.position
local tags = force.find_chart_tags(market.surface, {{position.x - 0.1, position.y - 0.1}, {position.x + 0.1, position.y + 0.1}})
if tags[1] then return end
force.add_chart_tag(market.surface, {icon = {type = 'item', name = 'stone-furnace'}, position = position, text = market.force.name .. "'s Town"})
end
function Public.update_town_chart_tags()
local town_centers = global.towny.town_centers
local forces = game.forces
for _, town_center in pairs(town_centers) do
local market = town_center.market
for _, force in pairs(forces) do
if force.is_chunk_visible(market.surface, town_center.chunk_position) then
add_chart_tag(force, market)
end
end
end
end
function Public.add_new_force(force_name)
@ -202,11 +253,15 @@ function Public.kill_force(force_name)
end
player.force = game.forces.player
end
for _, e in pairs(surface.find_entities_filtered({force = force_name})) do
if e.health then
if e.valid then
if e.health > 0 then e.active = false end
if e.valid then
if e.type == "wall" or e.type == "gate" then
e.die()
else
if e.health then
if e.health > 0 then e.active = false end
end
end
end
end
@ -216,6 +271,9 @@ function Public.kill_force(force_name)
global.towny.town_centers[force_name] = nil
global.towny.size_of_town_centers = global.towny.size_of_town_centers - 1
delete_chart_tag_for_all_forces(market)
Public.reveal_entity_to_all(market)
game.print(">> " .. force_name .. "'s town has fallen!", {255, 255, 0})
end

View File

@ -6,12 +6,12 @@ local table_insert = table.insert
local min_distance_to_spawn = 96
local square_min_distance_to_spawn = min_distance_to_spawn ^ 2
local town_radius = 30
local town_radius = 28
local radius_between_towns = 160
local colors = {}
local c1 = 250
local c2 = 175
local c2 = 200
local c3 = -25
for v = c1, c2, c3 do
table.insert(colors, {0, 0, v})
@ -149,7 +149,7 @@ local function draw_town_spawn(player_name)
for _, vector in pairs(turret_vectors) do
local p = {position.x + vector[1], position.y + vector[2]}
p = surface.find_non_colliding_position("gun-turret", p, 32, 1)
p = surface.find_non_colliding_position("gun-turret", p, 64, 1)
if p then
local turret = surface.create_entity({name = "gun-turret", position = p, force = player_name})
turret.insert({name = "firearm-magazine", count = 16})
@ -162,7 +162,7 @@ local function draw_town_spawn(player_name)
for i = 1, 4, 1 do
for _, vector in pairs(resource_vectors[i]) do
local p = {position.x + vector[1], position.y + vector[2]}
p = surface.find_non_colliding_position(ores[i], p, 32, 1)
p = surface.find_non_colliding_position(ores[i], p, 64, 1)
if p then
surface.create_entity({name = ores[i], position = p, amount = 1500})
end
@ -173,7 +173,7 @@ local function draw_town_spawn(player_name)
local m1 = -8 + math_random(0, 16)
local m2 = -8 + math_random(0, 16)
local p = {position.x + m1, position.y + m2}
p = surface.find_non_colliding_position("wooden-chest", p, 32, 1)
p = surface.find_non_colliding_position("wooden-chest", p, 64, 1)
if p then
local e = surface.create_entity({name = "wooden-chest", position = p, force = player_name})
local inventory = e.get_inventory(defines.inventory.chest)
@ -188,7 +188,7 @@ local function draw_town_spawn(player_name)
for _, vector in pairs(additional_resource_vectors[vector_indexes[1]]) do
if math_random(1, 6) == 1 then
local p = {position.x + vector[1], position.y + vector[2]}
p = surface.find_non_colliding_position(tree, p, 32, 1)
p = surface.find_non_colliding_position(tree, p, 64, 1)
if p then
surface.create_entity({name = tree, position = p})
end
@ -206,7 +206,7 @@ local function draw_town_spawn(player_name)
end
for _, vector in pairs(additional_resource_vectors[vector_indexes[3]]) do
local p = {position.x + vector[1], position.y + vector[2]}
p = surface.find_non_colliding_position("uranium-ore", p, 32, 1)
p = surface.find_non_colliding_position("uranium-ore", p, 64, 1)
if p then
surface.create_entity({name = "uranium-ore", position = p, amount = 1500})
end
@ -215,7 +215,7 @@ local function draw_town_spawn(player_name)
for _ = 1, 3, 1 do
local vector = vectors[math_random(1, #vectors)]
local p = {position.x + vector[1], position.y + vector[2]}
p = surface.find_non_colliding_position("crude-oil", p, 32, 1)
p = surface.find_non_colliding_position("crude-oil", p, 64, 1)
if p then
surface.create_entity({name = "crude-oil", position = p, amount = 500000})
end
@ -343,6 +343,7 @@ function Public.found(event)
global.towny.town_centers[player_name] = {}
local town_center = global.towny.town_centers[player_name]
town_center.market = surface.create_entity({name = "market", position = entity.position, force = player_name})
town_center.chunk_position = {math.floor(town_center.market.position.x / 32), math.floor(town_center.market.position.y / 32)}
town_center.max_health = 1000
town_center.health = town_center.max_health
town_center.color = colors[math_random(1, #colors)]