1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00

Fixed issue with invalid force for limited radar

Fixed issue with determining if market is placeable
Allow entities to be placed within the initial town square
Fixed info to remove reference to small plane
Fixed issue with no messages when can't place item due to building restrictions
Fixed issue with inability to place new towns near enemy spawners or turrets
Fixed issue with market listings breaking when special features disabled due to deprecation of computer item
Fixed issue with mining sound missing for big-crash-site-# entities (in mod)
Default to showing entity info for players (alt-info on chests)
This commit is contained in:
klugemonkey 2021-02-07 23:01:20 -08:00
parent c3354a4cb9
commit 29b3a89b33
7 changed files with 80 additions and 77 deletions

View File

@ -37,12 +37,13 @@ local function on_player_joined_game(event)
player.game_view_settings.show_minimap = false
player.game_view_settings.show_map_view_options = false
player.game_view_settings.show_entity_info = true
--player.game_view_settings.show_side_menu = false
Info.toggle_button(player)
Info.show(player)
Team.set_player_color(player)
if player.force ~= game.forces["player"] then return end
if player.force ~= game.forces.player then return end
-- setup outlanders
Team.set_player_to_outlander(player)
@ -108,15 +109,15 @@ local function on_init()
end
local tick_actions = {
[60 * 0] = Radar.reset, -- each minute, at 00 seconds
[60 * 5] = Team.update_town_chart_tags, -- each minute, at 05 seconds
[60 * 10] = Team.set_all_player_colors, -- each minute, at 10 seconds
[60 * 15] = Fish.reproduce, -- each minute, at 15 seconds
[60 * 0] = Radar.reset, -- each minute, at 00 seconds
[60 * 5] = Team.update_town_chart_tags, -- each minute, at 05 seconds
[60 * 10] = Team.set_all_player_colors, -- each minute, at 10 seconds
[60 * 15] = Fish.reproduce, -- each minute, at 15 seconds
[60 * 25] = Biters.unit_groups_start_moving, -- each minute, at 25 seconds
[60 * 30] = Radar.reset, -- each minute, at 30 seconds
[60 * 45] = Biters.validate_swarms, -- each minute, at 45 seconds
[60 * 50] = Biters.swarm, -- each minute, at 50 seconds
[60 * 55] = Pollution.market_scent -- each minute, at 55 seconds
[60 * 30] = Radar.reset, -- each minute, at 30 seconds
[60 * 45] = Biters.validate_swarms, -- each minute, at 45 seconds
[60 * 50] = Biters.swarm, -- each minute, at 50 seconds
[60 * 55] = Pollution.market_scent -- each minute, at 55 seconds
}
local function on_nth_tick(event)

View File

@ -2,6 +2,7 @@ local Public = {}
local Table = require 'modules.scrap_towny_ffa.table'
local town_radius = 27
local connection_radius = 7
local neutral_whitelist = {
@ -61,7 +62,7 @@ local entity_type_whitelist = {
["wall"] = true,
}
local function is_position_isolated(surface, force, position)
local function isolated(surface, force, position)
local position_x = position.x
local position_y = position.y
local area = { { position_x - connection_radius, position_y - connection_radius }, { position_x + connection_radius, position_y + connection_radius } }
@ -70,7 +71,7 @@ local function is_position_isolated(surface, force, position)
for _, e in pairs(surface.find_entities_filtered({ area = area, force = force.name })) do
if entity_type_whitelist[e.type] then
count = count + 1
if count > 1 then return end
if count > 1 then return false end -- are there more than one team entities in the area?
end
end
@ -119,42 +120,54 @@ function Public.near_town(position, surface, radius)
if town_center ~= nil then
local market = town_center.market
if in_range(position, market.position, radius) and market.surface == surface then
--log("near town")
return true
end
end
end
--log("not near town")
return false
end
local function in_town(force, position)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
if town_center ~= nil then
local center = town_center.market.position
if position.x >= center.x - town_radius and position.x <= center.x + town_radius then
if position.y >= center.y - town_radius and position.y <= center.y + town_radius then
return true
end
end
end
return false
end
local function prevent_isolation_entity(event, player)
local p = player or nil
local entity = event.created_entity
local position = entity.position
if not entity.valid then return end
local entity_name = entity.name
local item = event.item
if item == nil then return end
local item_name = item.name
local force = entity.force
if force == game.forces["player"] then return end
if force == game.forces.player then return end
if force == game.forces["rogue"] then return end
local surface = entity.surface
local error = false
if is_position_isolated(surface, force, entity.position) then
if not in_town(force, position) and isolated(surface, force, position) then
error = true
entity.destroy()
if entity_name ~= "entity-ghost" and entity_name ~= "tile-ghost" then
refund_item(event, item_name)
end
return true
--return true
end
if error == true then
if p ~= nil then
p.play_sound({ path = "utility/cannot_build", position = p.position, volume_modifier = 0.75 })
else
error_floaty(surface, entity.position, "Building is not connected to town!")
end
error_floaty(surface, position, "Building is not connected to town!")
end
end
@ -176,7 +189,7 @@ local function prevent_isolation_tile(event, player)
for _, t in pairs(tiles) do
local old_tile = t.old_tile
position = t.position
if is_position_isolated(surface, force, position) then
if not in_town(force, position) and isolated(surface, force, position) then
error = true
surface.set_tiles({ { name = old_tile.name, position = position } }, true)
if tile.name ~= "tile-ghost" then
@ -187,9 +200,8 @@ local function prevent_isolation_tile(event, player)
if error == true then
if p ~= nil then
p.play_sound({ path = "utility/cannot_build", position = p.position, volume_modifier = 0.75 })
else
error_floaty(surface, position, "Tile is not connected to town!")
end
error_floaty(surface, position, "Tile is not connected to town!")
end
end
@ -216,9 +228,8 @@ local function restrictions(event, player)
if error == true then
if p ~= nil then
p.play_sound({ path = "utility/cannot_build", position = p.position, volume_modifier = 0.75 })
else
error_floaty(surface, position, "Can't build near town!")
end
error_floaty(surface, position, "Can't build near town!")
end
if not neutral_whitelist[entity.type] then return end

View File

@ -9,7 +9,9 @@ The local inhabitants are indifferent to you at first, so long as you don't buil
by foreign technology. In fact, they get quite aggressive at the scent of it. If you were to hurt any of the natives you will be
brandished a rogue until your untimely death or until you find better digs.
To create a new town or outpost simply place a furnace down in a suitable spot while possessing a "small-plane" token item.
To create a new town or outpost simply place a furnace down in a suitable spot that is not near any other towns or obstructed.
The world seems to be limited in size with uninhabitable zones on four sides. News towns can only be built within these
borders and you must leave room for the town's size (radius of 27) when placing a new town.
TIP: It's best to find a spot far from existing towns and pollution, as enemies will become aggressive once you form a town.
Once a town is formed, members may invite other players and teams using a raw fish. To invite another player, drop a fish

View File

@ -1,9 +1,11 @@
local Public = {}
function Public.reset()
for index = 1, #game.forces, 1 do
for index = 1, table.size(game.forces), 1 do
local force = game.forces[index]
force.clear_chart("nauvis")
if force ~= nil then
force.clear_chart("nauvis")
end
end
end

View File

@ -68,17 +68,17 @@ local function set_offers(town_center)
if town_center.max_health < 500000 then
special_offers[1] = { { { "coin", town_center.max_health * 0.1 } }, "Upgrade Town Center Health" }
else
special_offers[1] = { { { "computer", 1 } }, "Maximum Health upgrades reached!" }
special_offers[1] = { { { "coin", 1 } }, "Maximum Health upgrades reached!" }
end
if force.character_inventory_slots_bonus <= 100 then
special_offers[2] = { { { "coin", (force.character_inventory_slots_bonus / 5 + 1) * 50 } }, "Upgrade Backpack +5 Slot" }
else
special_offers[2] = { { { "computer", 1 } }, "Maximum Backpack upgrades reached!" }
special_offers[2] = { { { "coin", 1 } }, "Maximum Backpack upgrades reached!" }
end
if town_center.upgrades.mining_prod < 10 then
special_offers[3] = { { { "coin", (town_center.upgrades.mining_prod + 1) * 400 } }, "Upgrade Mining Productivity +10%" }
else
special_offers[3] = { { { "computer", 1 } }, "Maximum Mining upgrades reached!" }
special_offers[3] = { { { "coin", 1 } }, "Maximum Mining upgrades reached!" }
end
local laser_turret = "Laser Turret Slot [#" .. tostring(town_center.upgrades.laser_turret.slots + 1) .. "]"
special_offers[4] = { { { "coin", 1000 + (town_center.upgrades.laser_turret.slots * 50) } }, laser_turret }
@ -185,9 +185,7 @@ local function on_tick(_)
local area = { left_top = { bb.left_top.x - 2, bb.left_top.y - 2 }, right_bottom = { bb.right_bottom.x + 2, bb.right_bottom.y + 2 } }
local entities = s.find_entities_filtered({ area = area, name = items })
for _, e in pairs(entities) do
if e.name == "loader" or e.name == "fast-loader" or e.name == "express-loader" then
local loader_type = e.loader_type
else
if e.name ~= "loader" and e.name ~= "fast-loader" and e.name ~= "express-loader" then
local ppos = e.pickup_position
local dpos = e.drop_position
-- pulling an item from the market

View File

@ -34,12 +34,11 @@ end
local function mining_sound(player)
if game.tick % 15 ~= 0 then return end
local target = player.selected
if target ~= nil and target.valid then
local surface = target.surface
local position = target.position
local path = "entity-mining/" .. target.name
surface.play_sound({path = path, position = position, volume_modifier = 1, override_sound_type = "game-effect" })
end
if target == nil or not target.valid then return end
local surface = target.surface
local position = target.position
local path = "entity-mining/" .. target.name
surface.play_sound({path = path, position = position, volume_modifier = 1, override_sound_type = "game-effect" })
end
local function on_tick()

View File

@ -93,8 +93,6 @@ 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_whitelist_types = {
["simple-entity"] = true,
["resource"] = true,
@ -257,31 +255,26 @@ local function draw_town_spawn(player_name)
--end
end
local function is_valid_location(surface, entity)
local function is_valid_location(surface, position)
local ffatable = Table.get_table()
for _, vector in pairs(market_collide_vectors) do
local p = { x = entity.position.x + vector[1], y = 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 false
end
if not surface.can_place_entity({ name = "market", position = position }) then
surface.create_entity({
name = "flying-text",
position = position,
text = "Position is obstructed - no room for market!",
color = { r = 0.77, g = 0.0, b = 0.0 }
})
return false
end
for _, vector in pairs(town_wall_vectors) do
local p = { x = entity.position.x + vector[1], y = entity.position.y + vector[2] }
local tile = surface.get_tile(math_floor(p.x), math_floor(p.y))
local p = { x = math_floor(position.x + vector[1]), y = math_floor(position.y + vector[2]) }
local tile = surface.get_tile(p.x, p.y)
if tile.name == "out-of-map" then
surface.create_entity({
name = "flying-text",
position = entity.position,
position = position,
text = "Town would be off-map!",
color = { r = 0.77, g = 0.0, b = 0.0 }
})
@ -289,28 +282,27 @@ local function is_valid_location(surface, entity)
end
end
if ffatable.size_of_town_centers > 48 then
surface.create_entity({
name = "flying-text",
position = entity.position,
position = position,
text = "Too many town centers on the map!",
color = { r = 0.77, g = 0.0, b = 0.0 }
})
return false
end
if Building.near_town(entity.position, entity.surface, radius_between_towns) then
if Building.near_town(position, surface, radius_between_towns) then
surface.create_entity({
name = "flying-text",
position = entity.position,
position = position,
text = "Town location is too close to another town center!",
color = { r = 0.77, g = 0.0, b = 0.0 }
})
return false
end
local area = { { entity.position.x - town_radius, entity.position.y - town_radius }, { entity.position.x + town_radius, entity.position.y + town_radius } }
local area = { { position.x - town_radius, position.y - town_radius }, { position.x + town_radius, position.y + town_radius } }
local count = 0
for _, e in pairs(surface.find_entities_filtered({ area = area })) do
if e.force.name == "enemy" then
@ -321,11 +313,10 @@ local function is_valid_location(surface, entity)
if count > 1 then
surface.create_entity({
name = "flying-text",
position = entity.position,
text = "I got a bad feeling about this!",
position = position,
text = "I got a bad feeling about this! There are enemies nearby.",
color = { r = 0.77, g = 0.0, b = 0.0 }
})
return false
end
return true
@ -373,18 +364,17 @@ local function get_color()
end
local function found_town(event)
local ffatable = Table.get_table()
local entity = event.created_entity
if entity == nil or not entity.valid then return true end -- end checks, do nothing
if entity.name ~= "stone-furnace" then return false end -- continue building checks
if entity == nil or not entity.valid then return true end -- cancel, not a valid entity placed
if entity.name ~= "stone-furnace" then return false end -- cancel, player did not place a stone-furnace
local player = game.players[event.player_index]
if player.force ~= game.forces["player"] and player.force ~= game.forces["rogue"] then return false end -- return false means to continue checks
if player.force ~= game.forces.player and player.force ~= game.forces["rogue"] then return false end -- cancel, player is in a team already
local force_name = tostring(player.name)
if game.forces[force_name] then return end
if Team.has_key(player) == false then return false end -- no plane, continue building checks
if game.forces[force_name] then return end -- cancel, player is mayor of town
if Team.has_key(player) == false then return false end -- cancel, player has already placed a town
local surface = entity.surface
local ffatable = Table.get_table()
if ffatable.cooldowns_town_placement[player.index] then
if game.tick < ffatable.cooldowns_town_placement[player.index] then
@ -400,9 +390,11 @@ local function found_town(event)
end
end
if not is_valid_location(surface, entity) then
local position = entity.position
entity.destroy()
if not is_valid_location(surface, position) then
player.insert({ name = "stone-furnace", count = 1 })
entity.destroy()
return true
end
@ -410,7 +402,7 @@ local function found_town(event)
ffatable.town_centers[force_name] = {}
local town_center = ffatable.town_centers[force_name]
town_center.market = surface.create_entity({ name = "market", position = entity.position, force = force_name })
town_center.market = surface.create_entity({ name = "market", position = position, force = force_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.coin_balance = 0
@ -467,8 +459,6 @@ local function found_town(event)
ffatable.size_of_town_centers = ffatable.size_of_town_centers + 1
entity.destroy()
draw_town_spawn(force_name)
Team.add_player_to_town(player, town_center)