mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-29 21:47:08 +02:00
color changing, additional resources
This commit is contained in:
parent
e977648c9a
commit
dd677c5766
@ -53,7 +53,9 @@ local function on_console_chat(event)
|
||||
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)
|
||||
if force.name ~= player.force.name then
|
||||
force.print(event.message, player.chat_color)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
11
modules/towny/combat_balance.lua
Normal file
11
modules/towny/combat_balance.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local Public = {}
|
||||
|
||||
function Public.fish(event)
|
||||
if event.item.name ~= "raw-fish" then return end
|
||||
local player = game.players[event.player_index]
|
||||
--local player_max_health = player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus
|
||||
--if player.character.health >= player_max_health then return end
|
||||
player.character.health = player.character.health - 70
|
||||
end
|
||||
|
||||
return Public
|
@ -1,18 +1,19 @@
|
||||
local Town_center = require "modules.towny.town_center"
|
||||
local Team = require "modules.towny.team"
|
||||
local Connected_building = require "modules.towny.connected_building"
|
||||
local Combat_balance = require "modules.towny.combat_balance"
|
||||
require "modules.global_chat_toggle"
|
||||
--local Market = require "modules.towny.market"
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
Team.set_player_color(player)
|
||||
|
||||
if player.force.index ~= 1 then return end
|
||||
|
||||
Team.set_player_to_homeless(player)
|
||||
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})
|
||||
player.print("Towny is enabled! To found your town, place down a stone furnace.", {255, 255, 0})
|
||||
player.print("To ally or settle with another player, drop a fish on their market or character. Coal will yield the opposite result.", {255, 255, 0})
|
||||
|
||||
if player.online_time == 0 then
|
||||
Team.give_homeless_items(player)
|
||||
@ -36,6 +37,10 @@ local function on_player_respawned(event)
|
||||
Team.give_homeless_items(player)
|
||||
end
|
||||
|
||||
local function on_player_used_capsule(event)
|
||||
Combat_balance.fish(event)
|
||||
end
|
||||
|
||||
local function on_built_entity(event)
|
||||
if Town_center.found(event) then return end
|
||||
Connected_building.prevent_isolation(event)
|
||||
@ -79,12 +84,17 @@ local function on_player_dropped_item(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_console_command(event)
|
||||
Team.set_town_color(event)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
global.towny = {}
|
||||
global.towny.requests = {}
|
||||
global.towny.town_centers = {}
|
||||
global.towny.cooldowns = {}
|
||||
global.towny.size_of_town_centers = 0
|
||||
game.difficulty_settings.technology_price_multiplier = 0.5
|
||||
game.difficulty_settings.technology_price_multiplier = 0.25
|
||||
|
||||
local p = game.permissions.create_group("Homeless")
|
||||
for action_name, _ in pairs(defines.input_action) do
|
||||
@ -120,6 +130,7 @@ end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.on_init(on_init)
|
||||
Event.add(defines.events.on_console_command, on_console_command)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_respawned, on_player_respawned)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
@ -127,4 +138,5 @@ Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
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_dropped_item, on_player_dropped_item)
|
||||
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
|
@ -2,12 +2,44 @@ local Public = {}
|
||||
|
||||
local item_drop_radius = 2
|
||||
|
||||
function Public.set_player_color(player)
|
||||
if player.force.index == 1 then
|
||||
player.color = {150, 150, 150}
|
||||
player.chat_color = {150, 150, 150}
|
||||
return
|
||||
end
|
||||
local town_center = global.towny.town_centers[player.force.name]
|
||||
if not town_center then return end
|
||||
player.color = town_center.color
|
||||
player.chat_color = town_center.color
|
||||
end
|
||||
|
||||
function Public.set_town_color(event)
|
||||
if event.command ~= "color" then return end
|
||||
local player = game.players[event.player_index]
|
||||
if player.force.index == 1 then
|
||||
player.color = {150, 150, 150}
|
||||
player.chat_color = {150, 150, 150}
|
||||
return
|
||||
end
|
||||
local town_center = global.towny.town_centers[player.name]
|
||||
if not town_center then
|
||||
Public.set_player_color(player)
|
||||
return
|
||||
end
|
||||
|
||||
town_center.color = {player.color.r, player.color.g, player.color.b}
|
||||
rendering.set_color(town_center.town_caption, town_center.color)
|
||||
for _, p in pairs(player.force.players) do
|
||||
Public.set_player_color(player)
|
||||
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)
|
||||
player.tag = ""
|
||||
player.color = town_center.color
|
||||
player.chat_color = town_center.color
|
||||
Public.set_player_color(player)
|
||||
end
|
||||
|
||||
function Public.give_homeless_items(player)
|
||||
@ -19,8 +51,7 @@ function Public.set_player_to_homeless(player)
|
||||
player.force = game.forces.player
|
||||
game.permissions.get_group("Homeless").add_player(player)
|
||||
player.tag = "[Homeless]"
|
||||
player.color = {150, 150, 150}
|
||||
player.chat_color = {150, 150, 150}
|
||||
Public.set_player_color(player)
|
||||
end
|
||||
|
||||
local function ally_homeless(player, target)
|
||||
|
@ -6,7 +6,7 @@ local table_insert = table.insert
|
||||
|
||||
local min_distance_to_spawn = 1
|
||||
local square_min_distance_to_spawn = min_distance_to_spawn ^ 2
|
||||
local town_radius = 32
|
||||
local town_radius = 30
|
||||
local radius_between_towns = town_radius * 4
|
||||
|
||||
local colors = {}
|
||||
@ -74,10 +74,29 @@ 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 additional_resource_vectors = {}
|
||||
additional_resource_vectors[1] = {}
|
||||
for x = 10, 22, 1 do
|
||||
for y = -4, 4, 1 do
|
||||
table_insert(additional_resource_vectors[1], {x, y})
|
||||
end
|
||||
end
|
||||
additional_resource_vectors[2] = {}
|
||||
for _, vector in pairs(additional_resource_vectors[1]) do table_insert(additional_resource_vectors[2], {vector[1] * -1, vector[2]}) end
|
||||
additional_resource_vectors[3] = {}
|
||||
for y = 10, 22, 1 do
|
||||
for x = -4, 4, 1 do
|
||||
table_insert(additional_resource_vectors[3], {x, y})
|
||||
end
|
||||
end
|
||||
additional_resource_vectors[4] = {}
|
||||
for _, vector in pairs(additional_resource_vectors[3]) do table_insert(additional_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,
|
||||
["resource"] = true,
|
||||
["cliff"] = true,
|
||||
}
|
||||
|
||||
@ -99,7 +118,7 @@ local function draw_town_spawn(player_name)
|
||||
local position = market.position
|
||||
local surface = market.surface
|
||||
|
||||
local area = {{position.x - town_radius, position.y - town_radius}, {position.x + town_radius, position.y + town_radius}}
|
||||
local area = {{position.x - (town_radius + 1), position.y - (town_radius + 1)}, {position.x + (town_radius + 1), position.y + (town_radius + 1)}}
|
||||
|
||||
for _, e in pairs(surface.find_entities_filtered({area = area, force = "neutral"})) do
|
||||
if not clear_blacklist_types[e.type] then
|
||||
@ -129,7 +148,8 @@ local function draw_town_spawn(player_name)
|
||||
|
||||
for _, vector in pairs(turret_vectors) do
|
||||
local p = {position.x + vector[1], position.y + vector[2]}
|
||||
if surface.can_place_entity({name = "gun-turret", position = p, force = player_name}) then
|
||||
p = surface.find_non_colliding_position("gun-turret", p, 32, 1)
|
||||
if p then
|
||||
local turret = surface.create_entity({name = "gun-turret", position = p, force = player_name})
|
||||
turret.insert({name = "firearm-magazine", count = 16})
|
||||
end
|
||||
@ -141,12 +161,13 @@ 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]}
|
||||
if not surface.get_tile(p).collides_with("resource-layer") then
|
||||
p = surface.find_non_colliding_position(ores[i], p, 32, 1)
|
||||
if p then
|
||||
surface.create_entity({name = ores[i], position = p, amount = 1500})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for _, item_stack in pairs(starter_supplies) do
|
||||
local m1 = -8 + math_random(0, 16)
|
||||
local m2 = -8 + math_random(0, 16)
|
||||
@ -158,6 +179,45 @@ local function draw_town_spawn(player_name)
|
||||
inventory.insert(item_stack)
|
||||
end
|
||||
end
|
||||
|
||||
local vector_indexes = {1,2,3,4}
|
||||
table.shuffle_table(vector_indexes)
|
||||
|
||||
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-01", p, 32, 1)
|
||||
if p then
|
||||
surface.create_entity({name = "tree-01", position = p})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local area = {{position.x - town_radius * 1.5, position.y - town_radius * 1.5}, {position.x + town_radius * 1.5, position.y + town_radius * 1.5}}
|
||||
if surface.count_tiles_filtered({name = {"water", "deepwater"}, area = area}) == 0 then
|
||||
for _, vector in pairs(additional_resource_vectors[vector_indexes[2]]) do
|
||||
local p = {position.x + vector[1], position.y + vector[2]}
|
||||
if surface.get_tile(p).name ~= "out-of-map" then
|
||||
surface.set_tiles({{name = "water", position = p}})
|
||||
end
|
||||
end
|
||||
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)
|
||||
if p then
|
||||
surface.create_entity({name = "uranium-ore", position = p, amount = 1500})
|
||||
end
|
||||
end
|
||||
local vectors = additional_resource_vectors[vector_indexes[4]]
|
||||
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)
|
||||
if p then
|
||||
surface.create_entity({name = "crude-oil", position = p, amount = 500000})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function is_valid_location(surface, entity)
|
||||
@ -257,10 +317,24 @@ function Public.found(event)
|
||||
|
||||
local surface = entity.surface
|
||||
|
||||
if global.towny.cooldowns[player.index] then
|
||||
if game.tick < global.towny.cooldowns[player.index] then
|
||||
surface.create_entity({
|
||||
name = "flying-text",
|
||||
position = entity.position,
|
||||
text = "Town founding is on cooldown for " .. math.ceil((global.towny.cooldowns[player.index] - game.tick) / 3600) .. " minutes.",
|
||||
color = {r=0.77, g=0.0, b=0.0}
|
||||
})
|
||||
player.insert({name = "stone-furnace", count = 1})
|
||||
entity.destroy()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if not is_valid_location(surface, entity) then
|
||||
player.insert({name = "stone-furnace", count = 1})
|
||||
entity.destroy()
|
||||
return
|
||||
return true
|
||||
end
|
||||
|
||||
Team.add_new_force(player_name)
|
||||
@ -285,7 +359,7 @@ function Public.found(event)
|
||||
}
|
||||
|
||||
town_center.town_caption = rendering.draw_text{
|
||||
text = player.name .. "'s town",
|
||||
text = player.name .. "'s Town",
|
||||
surface = surface,
|
||||
target = town_center.market,
|
||||
target_offset = {0, -3.25},
|
||||
@ -306,7 +380,9 @@ function Public.found(event)
|
||||
|
||||
player.force.set_spawn_position({x = town_center.market.position.x, y = town_center.market.position.y + 4}, surface)
|
||||
|
||||
game.print(">> " .. player.name .. " has founded a new town!", {255, 255, 0})
|
||||
global.towny.cooldowns[player.index] = game.tick + 3600 * 15
|
||||
|
||||
game.print(">> " .. player.name .. " has founded a new town!", {255, 255, 0})
|
||||
return true
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user