1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
players can no longer get stuck inside market
global / team chat toggle button
min distance between towns increased
misc fixes
This commit is contained in:
MewMew 2019-12-18 09:17:33 +01:00
parent 2b61911eb9
commit e977648c9a
4 changed files with 151 additions and 46 deletions

View File

@ -0,0 +1,64 @@
local function toggle(player)
if not player.gui.top.global_chat_toggle then return end
local button = player.gui.top.global_chat_toggle
if button.caption == "Global Chat" then
button.caption = "Team Chat"
button.tooltip = "Chat messages are only sent to your team."
button.style.font_color = {r=0.77, g=0.77, b=0.0}
return
end
button.caption = "Global Chat"
button.tooltip = "Chat messages are sent to everyone."
button.style.font_color = {r=0.0, g=0.77, b=0.0}
end
local function create_gui_button(player)
if player.gui.top.global_chat_toggle then return end
local b = player.gui.top.add({
type = "sprite-button",
name = "global_chat_toggle",
caption = "",
})
b.style.font = "heading-2"
b.style.minimal_width = 100
b.style.minimal_height = 38
b.style.maximal_height = 38
b.style.padding = 1
b.style.margin = 0
toggle(player)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
create_gui_button(player)
end
local function on_gui_click(event)
if not event then return end
if not event.element then return end
if not event.element.valid then return end
local player = game.players[event.element.player_index]
if event.element.name ~= "global_chat_toggle" then return end
toggle(player)
end
local function on_console_chat(event)
if not event.message then return end
if not event.player_index then return end
local player = game.players[event.player_index]
if not player.gui.top.global_chat_toggle then return end
local button = player.gui.top.global_chat_toggle
if button.caption ~= "Global Chat" then return end
for _, force in pairs(game.forces) do
force.print(event.message, player.chat_color)
end
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -1,6 +1,7 @@
local Town_center = require "modules.towny.town_center"
local Team = require "modules.towny.team"
local Connected_building = require "modules.towny.connected_building"
require "modules.global_chat_toggle"
--local Market = require "modules.towny.market"
local function on_player_joined_game(event)
@ -9,19 +10,23 @@ local function on_player_joined_game(event)
if player.force.index ~= 1 then return end
Team.set_player_to_homeless(player)
player.print("Towny is enabled on this server!", {255, 255, 0})
player.print("Towny is enabled!", {255, 255, 0})
player.print("Place a stone furnace, to found a new town center. Or join a town by visiting another player's center.", {255, 255, 0})
player.print("Or join a town by visiting another player's center.", {255, 255, 0})
if player.online_time == 0 then
Team.give_homeless_items(player)
return
end
if not global.towny.requests[player.index] then return end
if global.towny.requests[player.index] ~= "kill-character" then return end
if player.character then
if player.character.valid then
player.character.die()
end
end
global.towny.requests[player.index] = nil
end
local function on_player_respawned(event)
@ -76,7 +81,7 @@ end
local function on_init()
global.towny = {}
global.towny.homeless_requests = {}
global.towny.requests = {}
global.towny.town_centers = {}
global.towny.size_of_town_centers = 0
game.difficulty_settings.technology_price_multiplier = 0.5

View File

@ -1,5 +1,7 @@
local Public = {}
local item_drop_radius = 2
function Public.add_player_to_town(player, town_center)
player.force = town_center.market.force
game.permissions.get_group("Default").add_player(player)
@ -21,41 +23,41 @@ function Public.set_player_to_homeless(player)
player.chat_color = {150, 150, 150}
end
function Public.ally_town(player, item)
local position = item.position
local surface = player.surface
local area = {{position.x - 2.5, position.y - 2.5}, {position.x + 2.5, position.y + 2.5}}
local function ally_homeless(player, target)
local requesting_force = player.force
local target = false
for _, e in pairs(surface.find_entities_filtered({type = {"character", "market"}, area = area})) do
if e.force.name ~= requesting_force.name then
target = e
break
end
end
if not target then return end
local target_force = target.force
if requesting_force.index ~= 1 and target_force.index ~= 1 then return end
if requesting_force.index == 1 and target_force.index == 1 then return true end
if requesting_force.index == 1 then
global.towny.homeless_requests[player.index] = target_force.name
global.towny.requests[player.index] = target_force.name
game.print(">> " .. player.name .. " wants to settle in " .. target_force.name .. " Town!", {255, 255, 0})
return
return true
end
if target_force.index == 1 then
if target.type ~= "character" then return end
if target_force.index == 1 then
if target.type ~= "character" then return true end
local target_player = target.player
if not target_player then return end
if not global.towny.homeless_requests[target_player.index] then return end
if global.towny.homeless_requests[target_player.index] == player.force.name then
game.print(">> " .. player.name .. " has accepted " .. target_player.name .. " into their Town!", {255, 255, 0})
Public.add_player_to_town(target_player, global.towny.town_centers[player.name])
end
return
if not target_player then return true end
global.towny.requests[player.index] = target_player.name
if global.towny.requests[target_player.index] then
if global.towny.requests[target_player.index] == player.force.name then
game.print(">> " .. player.name .. " has accepted " .. target_player.name .. " into their Town!", {255, 255, 0})
Public.add_player_to_town(target_player, global.towny.town_centers[player.name])
return true
end
end
game.print(">> " .. player.name .. " is inviting " .. target_player.name .. " into their Town!", {255, 255, 0})
return true
end
end
local function ally_neighbour_towns(player, target)
local requesting_force = player.force
local target_force = target.force
if target_force.get_friend(requesting_force) and requesting_force.get_friend(target_force) then return end
@ -67,10 +69,30 @@ function Public.ally_town(player, item)
end
end
function Public.ally_town(player, item)
local position = item.position
local surface = player.surface
local area = {{position.x - item_drop_radius, position.y - item_drop_radius}, {position.x + item_drop_radius, position.y + item_drop_radius}}
local target = false
for _, e in pairs(surface.find_entities_filtered({type = {"character", "market"}, area = area})) do
if e.force.name ~= requesting_force.name then
target = e
break
end
end
if not target then return end
if ally_homeless(player, target) then return end
ally_neighbour_towns(player, target)
end
function Public.declare_war(player, item)
local position = item.position
local surface = player.surface
local area = {{position.x - 2.5, position.y - 2.5}, {position.x + 2.5, position.y + 2.5}}
local area = {{position.x - item_drop_radius, position.y - item_drop_radius}, {position.x + item_drop_radius, position.y + item_drop_radius}}
local requesting_force = player.force
local target = surface.find_entities_filtered({type = {"character", "market"}, area = area})[1]
@ -84,7 +106,7 @@ function Public.declare_war(player, item)
if player.name ~= target.force.name then
Public.set_player_to_homeless(player)
game.print(">> " .. player.name .. " has abandoned " .. target_force.name .. "'s Town!", {255, 255, 0})
global.towny.homeless_requests[player.index] = nil
global.towny.requests[player.index] = nil
end
if player.name == target.force.name then
if target.type ~= "character" then return end
@ -97,6 +119,8 @@ function Public.declare_war(player, item)
return
end
if requesting_force.index == 1 then return end
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})
@ -119,7 +143,11 @@ function Public.kill_force(force_name)
surface.create_entity({name = "big-artillery-explosion", position = market.position})
for _, player in pairs(force.players) do
if player.character then player.character.die() end
if player.character then
player.character.die()
else
global.towny.requests[player.index] = "kill-character"
end
player.force = game.forces.player
end

View File

@ -4,9 +4,10 @@ local Public = {}
local math_random = math.random
local table_insert = table.insert
local min_distance_to_spawn = 64
local min_distance_to_spawn = 1
local square_min_distance_to_spawn = min_distance_to_spawn ^ 2
local town_radius = 32
local radius_between_towns = town_radius * 4
local colors = {}
local c1 = 250
@ -73,6 +74,8 @@ for _, vector in pairs(resource_vectors[1]) do table_insert(resource_vectors[3],
resource_vectors[4] = {}
for _, vector in pairs(resource_vectors[1]) do table_insert(resource_vectors[4], {vector[1], vector[2] * -1}) end
local market_collide_vectors = {{-1, 1},{0, 1},{1, 1},{1, 0},{1, -1}}
local clear_blacklist_types = {
["simple-entity"] = true,
["cliff"] = true,
@ -100,7 +103,7 @@ local function draw_town_spawn(player_name)
for _, e in pairs(surface.find_entities_filtered({area = area, force = "neutral"})) do
if not clear_blacklist_types[e.type] then
e.destroy()
--e.destroy()
end
end
@ -117,7 +120,6 @@ local function draw_town_spawn(player_name)
end
end
for _, vector in pairs(town_wall_vectors) do
local p = {position.x + vector[1], position.y + vector[2]}
if surface.can_place_entity({name = "stone-wall", position = p, force = player_name}) then
@ -127,8 +129,10 @@ local function draw_town_spawn(player_name)
for _, vector in pairs(turret_vectors) do
local p = {position.x + vector[1], position.y + vector[2]}
local turret = surface.create_entity({name = "gun-turret", position = p, force = player_name})
turret.insert({name = "firearm-magazine", count = 16})
if surface.can_place_entity({name = "gun-turret", position = p, force = player_name}) then
local turret = surface.create_entity({name = "gun-turret", position = p, force = player_name})
turret.insert({name = "firearm-magazine", count = 16})
end
end
local ores = {"iron-ore", "copper-ore", "stone", "coal"}
@ -157,14 +161,18 @@ local function draw_town_spawn(player_name)
end
local function is_valid_location(surface, entity)
if not surface.can_place_entity({name = "market", position = entity.position}) then
surface.create_entity({
name = "flying-text",
position = entity.position,
text = "Position is obstructed!",
color = {r=0.77, g=0.0, b=0.0}
})
return
for _, vector in pairs(market_collide_vectors) do
local p = {entity.position.x + vector[1], entity.position.y + vector[2]}
if not surface.can_place_entity({name = "iron-chest", position = p}) then
surface.create_entity({
name = "flying-text",
position = entity.position,
text = "Position is obstructed!",
color = {r=0.77, g=0.0, b=0.0}
})
return
end
end
if global.towny.size_of_town_centers > 48 then
@ -187,8 +195,8 @@ local function is_valid_location(surface, entity)
return
end
local area = {{entity.position.x - town_radius * 2, entity.position.y - town_radius * 2}, {entity.position.x + town_radius * 2, entity.position.y + town_radius * 2}}
if surface.count_entities_filtered({area = area, type = "market"}) > 0 then
local area = {{entity.position.x - radius_between_towns, entity.position.y - radius_between_towns}, {entity.position.x + radius_between_towns, entity.position.y + radius_between_towns}}
if surface.count_entities_filtered({area = area, name = "market"}) > 0 then
surface.create_entity({
name = "flying-text",
position = entity.position,