1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00

Merge pull request #308 from ComfyFactory/towny-changes

Merges towny changes from blubFisch
This commit is contained in:
Gerkiz 2022-09-22 20:22:33 +02:00 committed by GitHub
commit d03e49c538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 305 additions and 324 deletions

View File

@ -30,6 +30,8 @@ local Info = require 'modules.scrap_towny_ffa.info'
local Team = require 'modules.scrap_towny_ffa.team'
local Spawn = require 'modules.scrap_towny_ffa.spawn'
local Radar = require 'modules.scrap_towny_ffa.limited_radar'
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local mod_gui = require('mod-gui')
-- for testing purposes only!!!
local testing_mode = false
@ -62,13 +64,108 @@ local function load_buffs(player)
end
end
local function spairs(t, order)
local keys = {}
for k in pairs(t) do
keys[#keys + 1] = k
end
if order then
table.sort(
keys,
function(a, b)
return order(t, a, b)
end
)
else
table.sort(keys)
end
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
local function init_score_board(player)
local ffatable = Table.get_table()
local flow = mod_gui.get_frame_flow(player)
local frame = flow.add {type = 'frame', style = mod_gui.frame_style, caption = 'Town survival', direction = 'vertical'}
frame.style.vertically_stretchable = false
ffatable.score_gui_frame[player.index] = frame
end
local function update_score()
local ffatable = Table.get_table()
for _, player in pairs(game.connected_players) do
local frame = ffatable.score_gui_frame[player.index]
if not (frame and frame.valid) then
init_score_board(player)
end
frame.clear()
local inner_frame = frame.add {type = 'frame', style = 'inside_shallow_frame', direction = 'vertical'}
local subheader = inner_frame.add {type = 'frame', style = 'subheader_frame'}
subheader.style.horizontally_stretchable = true
subheader.style.vertical_align = 'center'
subheader.add {type = 'label', style = 'subheader_label', caption = {'', 'Survive 3 days (72h) to win!'}}
if not next(subheader.children) then
subheader.destroy()
end
local information_table = inner_frame.add {type = 'table', column_count = 3, style = 'bordered_table'}
information_table.style.margin = 4
information_table.style.column_alignments[3] = 'right'
for _, caption in pairs({'Rank', 'Town', 'Survival time'}) do
local label = information_table.add {type = 'label', caption = caption}
label.style.font = 'default-bold'
end
local town_ages = {}
for _, town_center in pairs(ffatable.town_centers) do
if town_center ~= nil then
local age = game.tick - town_center.creation_tick
town_ages[town_center] = age
log('XDB age ' .. town_center.town_name .. ': ' .. age)
end
end
local rank = 1
for town_center, age in spairs(
town_ages,
function(t, a, b)
return t[b] < t[a]
end
) do
log('XDB age sorted ' .. town_center.town_name .. ' ' .. age)
local position = information_table.add {type = 'label', caption = '#' .. rank}
if town_center == ffatable.town_centers[player.force.name] then
position.style.font = 'default-semibold'
position.style.font_color = {r = 1, g = 1}
end
local label = information_table.add {type = 'label', caption = town_center.town_name}
label.style.font = 'default-semibold'
label.style.font_color = town_center.color
local age_hours = age / 60 / 3600
information_table.add {type = 'label', caption = string.format('%.1f', age_hours) .. 'h'}
rank = rank + 1
end
end
end
local function on_player_joined_game(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
local surface = game.surfaces['nauvis']
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.map_view_settings = {
['show-logistic-network'] = false,
@ -80,9 +177,10 @@ local function on_player_joined_game(event)
['show-networkless-logistic-members'] = false,
['show-non-standard-map-info'] = false
}
player.show_on_map = false
--player.game_view_settings.show_side_menu = false
init_score_board(player)
Info.toggle_button(player)
Team.set_player_color(player)
if player.force ~= game.forces.player then
@ -103,14 +201,13 @@ local function on_player_joined_game(event)
player.teleport({0, 0}, game.surfaces['limbo'])
Team.set_player_to_outlander(player)
Team.give_player_items(player)
player.insert {name = 'coin', count = '100'}
player.insert {name = 'stone-furnace', count = '1'}
Team.give_key(player.index)
if (testing_mode == true) then
player.cheat_mode = true
player.force.research_all_technologies()
player.insert {name = 'coin', count = '9900'}
player.insert {name = 'coin', count = 9900}
end
-- first time spawn point
local spawn_point = Spawn.get_new_spawn_point(player, surface)
ffatable.strikes[player.name] = 0
@ -128,6 +225,19 @@ local function on_player_joined_game(event)
end
if player.character then
if player.character.valid then
local inventories = {
player.get_inventory(defines.inventory.character_main),
player.get_inventory(defines.inventory.character_guns),
player.get_inventory(defines.inventory.character_ammo),
player.get_inventory(defines.inventory.character_armor),
player.get_inventory(defines.inventory.character_vehicle),
player.get_inventory(defines.inventory.character_trash)
}
for _, i in pairs(inventories) do
i.clear()
end
player.character.die()
end
end
@ -186,6 +296,7 @@ local function on_init()
ffatable.last_respawn = {}
ffatable.last_death = {}
ffatable.strikes = {}
ffatable.score_gui_frame = {}
ffatable.testing_mode = testing_mode
ffatable.spawn_point = {}
ffatable.buffs = {}
@ -220,6 +331,28 @@ local function on_nth_tick(event)
tick_actions[seconds]()
end
local function ui_smell_evolution()
for _, player in pairs(game.connected_players) do
-- Only for non-townies
if player.force.index == game.forces.player.index or player.force.index == game.forces['rogue'].index then
local e = Evolution.get_evolution(player.position)
local extra
if e < 0.1 then
extra = 'A good place to found a town. Build a furnace to get started.'
else
extra = 'Not good to start a new town. Maybe somewhere else?'
end
player.create_local_flying_text(
{
position = {x = player.position.x, y = player.position.y},
text = 'You smell the evolution around here: ' .. string.format('%.0f', e * 100) .. '%. ' .. extra,
color = {r = 1, g = 1, b = 1}
}
)
end
end
end
local Event = require 'utils.event'
Event.on_init(on_init)
@ -227,3 +360,5 @@ Event.on_nth_tick(60, on_nth_tick) -- once every second
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_player_died, on_player_died)
Event.on_nth_tick(60 * 30, ui_smell_evolution)
Event.on_nth_tick(60, update_score)

View File

@ -4,11 +4,12 @@ local math_floor = math.floor
local table_insert = table.insert
local table_size = table.size
local Table = require 'modules.scrap_towny_ffa.table'
--[[
local town_radius = 27
local connection_radius = 7
local connection_radius = 15
]]
local blacklist_entity_types = {
['tank'] = true,
['car'] = true,
['character'] = true,
['combat-robot'] = true,
@ -36,10 +37,19 @@ local neutral_whitelist = {
['stack-inserter'] = true,
['steel-chest'] = true,
['tank'] = true,
['wooden-chest'] = true
['wooden-chest'] = true,
['transport-belt'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['underground-belt'] = true,
['fast-underground-belt'] = true,
['express-underground-belt'] = true,
['splitter'] = true,
['fast-splitter'] = true,
['express-splitter'] = true
}
-- these should be allowed to place outside any base by town players
--[[ -- these should be allowed to place outside any base by town players
local team_whitelist = {
['burner-inserter'] = true,
['car'] = true,
@ -67,9 +77,18 @@ local team_whitelist = {
['straight-rail'] = true,
['tank'] = true,
['train-stop'] = true,
['wooden-chest'] = true
}
['wooden-chest'] = true,
['transport-belt'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['underground-belt'] = true,
['fast-underground-belt'] = true,
['express-underground-belt'] = true,
['splitter'] = true,
['fast-splitter'] = true,
['express-splitter'] = true
} ]]
--[[
-- these need to be prototypes
local team_entities = {
['accumulator'] = true,
@ -122,8 +141,8 @@ local team_entities = {
['transport-belt'] = true,
['underground-belt'] = true,
['wall'] = true
}
} ]]
--[[
local function isolated(surface, force, position)
local position_x = position.x
local position_y = position.y
@ -141,7 +160,7 @@ local function isolated(surface, force, position)
return true
end
]]
local function refund_item(event, item_name)
if item_name == 'blueprint' then
return
@ -250,6 +269,7 @@ function Public.near_another_town(force_name, position, surface, radius)
if entity_force_name ~= nil then
if entity_force_name ~= force_name then
if blacklist_entity_types[e.type] ~= true then
log('XDB prevent_entity, e.type:' .. e.type)
fail = true
break
end
@ -263,7 +283,7 @@ function Public.near_another_town(force_name, position, surface, radius)
end
return false
end
--[[
local function in_own_town(force, position)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
@ -279,8 +299,7 @@ local function in_own_town(force, position)
end
end
return false
end
end ]]
function Public.in_restricted_zone(surface, position)
if surface.name ~= 'nauvis' then
return false
@ -321,40 +340,6 @@ local function prevent_entity_in_restricted_zone(event)
end
end
local function prevent_unconnected_town_entities(event)
local player_index = event.player_index or nil
local entity = event.created_entity
if entity == nil or not entity.valid then
return
end
local name = entity.name
local surface = entity.surface
local position = entity.position
local force = entity.force
if force.index == game.forces.player.index or force.index == game.forces['rogue'].index then
-- no town restrictions if outlander or rogue
return
end
local error = false
if name ~= 'entity-ghost' then
if not in_own_town(force, position) and isolated(surface, force, position) and not team_whitelist[name] then
error = true
entity.destroy()
local item = event.item
if item ~= nil then
refund_item(event, item.name)
end
end
end
if error == true then
if player_index ~= nil then
local player = game.players[player_index]
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, 'Building is not connected to your town!')
end
end
local function prevent_landfill_in_restricted_zone(event)
local player_index = event.player_index or nil
local tile = event.tile
@ -383,45 +368,6 @@ local function prevent_landfill_in_restricted_zone(event)
return fail
end
local function prevent_unconnected_town_tiles(event)
local player_index = event.player_index or nil
local tile = event.tile
if tile == nil or not tile.valid then
return
end
local surface = game.surfaces[event.surface_index]
local tiles = event.tiles
local force
if player_index ~= nil then
force = game.players[player_index].force
else
force = event.robot.force
end
local fail = false
local position
for _, t in pairs(tiles) do
local old_tile = t.old_tile
position = t.position
if tile.name ~= 'tile-ghost' then
if not in_own_town(force, position) and isolated(surface, force, position) then
fail = true
surface.set_tiles({{name = old_tile.name, position = position}}, true)
if tile.name == 'stone-path' then
tile.name = 'stone-brick'
end
refund_item(event, tile.name)
end
end
end
if fail == true then
if player_index ~= nil then
local player = game.players[player_index]
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, 'Tile is not connected to town!')
end
end
local function prevent_entities_near_towns(event)
local player_index = event.player_index or nil
local entity = event.created_entity
@ -513,74 +459,42 @@ local function prevent_tiles_near_towns(event)
return fail
end
local function prevent_neutral_deconstruct(event)
local player = game.players[event.player_index] or nil
local entity = event.entity
if entity.to_be_deconstructed() and entity.force.name == 'neutral' then
for _, f in pairs(game.forces) do
if entity.is_registered_for_deconstruction(f) then
entity.cancel_deconstruction(f, player)
end
end
end
end
-- called when a player places an item, or a ghost
local function on_built_entity(event)
local player = game.players[event.player_index]
if prevent_entity_in_restricted_zone(event) then
return
end
if prevent_entities_near_towns(event) then
return
end
if player.force.index ~= game.forces['player'].index and player.force.index ~= game.forces['rogue'].index then
prevent_unconnected_town_entities(event)
end
end
local function on_robot_built_entity(event)
local robot = event.robot
if prevent_entity_in_restricted_zone(event) then
return
end
if prevent_entities_near_towns(event) then
return
end
if robot.force.index ~= game.forces['player'].index and robot.force.index ~= game.forces['rogue'].index then
prevent_unconnected_town_entities(event)
end
end
-- called when a player places landfill
local function on_player_built_tile(event)
local player = game.players[event.player_index]
if prevent_landfill_in_restricted_zone(event) then
return
end
if prevent_tiles_near_towns(event) then
return
end
if player.force.index ~= game.forces['player'].index and player.force.index ~= game.forces['rogue'].index then
prevent_unconnected_town_tiles(event)
end
end
local function on_robot_built_tile(event)
local robot = event.robot
if prevent_landfill_in_restricted_zone(event) then
return
end
if prevent_tiles_near_towns(event) then
return
end
if robot.force.index ~= game.forces['player'].index and robot.force.index ~= game.forces['rogue'].index then
prevent_unconnected_town_tiles(event)
end
end
local function on_marked_for_deconstruction(event)
prevent_neutral_deconstruct(event)
end
local Event = require 'utils.event'
@ -588,6 +502,5 @@ Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_player_built_tile, on_player_built_tile)
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_robot_built_tile, on_robot_built_tile)
Event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
return Public

View File

@ -13,7 +13,7 @@ function Public.reproduce()
if #fishes == 0 then
return
end
if #fishes >= 128 then
if #fishes >= 100 then
return
end
-- pick a random fish
@ -29,47 +29,12 @@ function Public.reproduce()
end
end
if guppy == true then
--log("fish spawn {" .. fish.position.x .. "," .. fish.position.y .. "}")
surface.create_entity({name = 'water-splash', position = fish.position})
surface.create_entity({name = 'fish', position = fish.position})
for i=1, math_random(1, 5) do
surface.create_entity({name = 'water-splash', position = fish.position})
surface.create_entity({name = 'fish', position = fish.position})
end
end
end
end
local function on_player_used_capsule(event)
if event.item.name ~= 'raw-fish' then
return
end
local player = game.players[event.player_index]
local surface = player.surface
local position = event.position
local tile = player.surface.get_tile(position.x, position.y)
-- return back some of the health if not healthy
if player.character.health < 250 then
player.surface.play_sound({path = 'utility/armor_insert', position = player.position, volume_modifier = 1})
return
end
-- if using fish on water
if tile.name == 'water'
or tile.name == 'water-green'
or tile.name == 'water-mud'
or tile.name == 'water-shallow'
or tile.name == 'deepwater'
or tile.name == 'deepwater-green'
then
-- get the count of fish in the water nearby and test if can be repopulated
surface.create_entity({name = 'water-splash', position = position})
surface.create_entity({name = 'fish', position = position})
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return
end
-- otherwise return the fish and make no sound
player.insert({name = 'raw-fish', count = 1})
end
local Event = require 'utils.event'
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
return Public

View File

@ -2,18 +2,38 @@ local Public = {}
local Table = require 'modules.scrap_towny_ffa.table'
local info =
[[You are an "outlander" stuck on this god-forsaken planet with a bunch of other desolate fools. You can choose to join
an existing town if accepted, or go at it alone, building your own outpost or living as an "outlander".
local info = [[You wake up on this god-forsaken planet with a bunch of other desolate fools. Who will survive?
The local inhabitants are indifferent to you at first, so long as you don't build or pollute, but become increasingly aggressive
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.
You better found a town and start producing and defending yourself!
To create a new town 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. Each town costs 100 coins.
TIP: It's best to find a spot far from existing towns and pollution, as enemies will become aggressive once you form a town.
Have fun and be comfy ^.^
]]
local info_adv =
[[
# Goal of the game
Survive as long as you can. Raid other towns. Defend your town.
# Advanced tips and tricks
It's best to found new towns far from existing towns, as enemies will become aggressive with town's research.
Are you out of ore patches? Make sure you researched steel processing,
then hand mine a few big rocks to find ore patches under them!
The town market is the heart of your town. If it is destroyed, you lose everything.
So protect it well, repair it whenever possible, and if you can afford, increase its health by purchasing upgrades.
It's possible to automate trading with the town center! How cool is that?!! Try it out.
When building your town, note that you may only build nearby existing structures such as your town market and walls and
any other structure you have placed. Beware that biters and spitters become more aggressive towards towns that are
advanced in research. Their evolution will scale around technology progress in any nearby towns and pollution levels.
# Alliances
Once a town is formed, members may invite other players and teams using a coin. To invite another player, drop a coin
on that player (with the Z key). To accept an invite, offer a coin in return to the member. To leave a town, simply drop coal
@ -21,25 +41,13 @@ on the market. As a member of a town, your respawn point will change to that of
To form any alliance with another town, drop a coin on a member or their market. If they agree they can reciprocate with a
coin offering.
The town market is the heart of your town. If it is destroyed, your town is destroyed and you will lose all research. So
protect it well, repair it whenever possible, and if you can afford, increase its health by purchasing upgrades. If your
town falls, members will be disbanded, and all buildings will become neutral and lootable.
When building your town, note that you may only build nearby existing structures such as your town market and walls and
any other structure you have placed. Beware that biters and spitters become more aggressive towards towns that are
advanced in research. Their evolution will scale around technology progress in any nearby towns and pollution levels.
This is a FFA ("Free-For-All") world. Short of bullying and derogatory remarks, anything goes. Griefing is encouraged,
so best to setup proper defenses for your town or outpost to fend off enemies when you are there and away.
Have fun and be comfy ^.^]]
]]
function Public.toggle_button(player)
if player.gui.top['towny_map_intro_button'] then
return
end
local b = player.gui.top.add({type = 'sprite-button', caption = 'Towny', name = 'towny_map_intro_button', tooltip = 'Show Info'})
local b = player.gui.top.add({type = 'sprite-button', caption = 'Info', name = 'towny_map_intro_button', tooltip = 'Show Info'})
b.style.font_color = {r = 0.5, g = 0.3, b = 0.99}
b.style.font = 'heading-1'
b.style.minimal_height = 38
@ -50,7 +58,7 @@ function Public.toggle_button(player)
b.style.bottom_padding = 1
end
function Public.show(player)
function Public.show(player, info_type)
local ffatable = Table.get_table()
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
@ -81,12 +89,11 @@ function Public.show(player)
end
frame.add {type = 'line'}
local l = frame.add {type = 'label', caption = 'Instructions:'}
l.style.font = 'heading-1'
l.style.font_color = {r = 0.85, g = 0.85, b = 0.85}
local l2 = frame.add {type = 'label', caption = info}
local cap = info
if info_type == 'adv' then
cap = info_adv
end
local l2 = frame.add {type = 'label', caption = cap}
l2.style.single_line = false
l2.style.font = 'heading-2'
l2.style.font_color = {r = 0.8, g = 0.7, b = 0.99}
@ -124,7 +131,7 @@ function Public.toggle(event)
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
else
Public.show(player)
Public.show(player, 'adv')
end
end
end

View File

@ -8,7 +8,7 @@ local upgrade_functions = {
[1] = function(town_center, player)
local market = town_center.market
local surface = market.surface
if town_center.max_health > 500000 then
if town_center.max_health > 50000 then
return false
end
town_center.health = town_center.health + town_center.max_health
@ -105,7 +105,7 @@ local function set_offers(town_center)
-- special offers
local special_offers = {}
if town_center.max_health < 500000 then
if town_center.max_health < 50000 then
special_offers[1] = {{{'coin', town_center.max_health * 0.1}}, 'Upgrade Town Center Health'}
else
special_offers[1] = {{}, 'Maximum Health upgrades reached!'}
@ -116,7 +116,7 @@ local function set_offers(town_center)
special_offers[2] = {{}, 'Maximum Backpack upgrades reached!'}
end
if town_center.upgrades.mining_prod + 1 <= 10 then
special_offers[3] = {{{'coin', (town_center.upgrades.mining_prod + 1) * 400}}, 'Upgrade Mining Productivity +10%'}
special_offers[3] = {{{'coin', (town_center.upgrades.mining_prod + 1) * 1000}}, 'Upgrade Mining Productivity +10%'}
else
special_offers[3] = {{}, 'Maximum Productivity upgrades reached!'}
end
@ -131,32 +131,33 @@ local function set_offers(town_center)
special_offers[5] = {{}, 'Maximum Crafting Speed upgrades reached!'}
end
local laser_turret = 'Laser Turret Slot [#' .. tostring(town_center.upgrades.laser_turret.slots + 1) .. ']'
special_offers[6] = {{{'coin', 1000 + (town_center.upgrades.laser_turret.slots * 50)}}, laser_turret}
special_offers[6] = {{{'coin', 2000 + (town_center.upgrades.laser_turret.slots * 200)}}, laser_turret}
local spawn_point = 'Set Spawn Point'
special_offers[7] = {{}, spawn_point}
for _, v in pairs(special_offers) do
table_insert(market_items, {price = v[1], offer = {type = 'nothing', effect_description = v[2]}})
end
-- coin purchases
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'raw-fish', count = 1}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'wood', count = 6}})
-- item purchases
table_insert(market_items, {price = {{'coin', 25}}, offer = {type = 'give-item', item = 'raw-fish', count = 1}})
table_insert(market_items, {price = {{'coin', 6}}, offer = {type = 'give-item', item = 'wood', count = 1}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'iron-ore', count = 6}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'copper-ore', count = 6}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'stone', count = 6}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'coal', count = 6}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'uranium-ore', count = 4}})
table_insert(market_items, {price = {{'coin', 1}}, offer = {type = 'give-item', item = 'uranium-ore', count = 2}})
table_insert(market_items, {price = {{'coin', 1000}}, offer = {type = 'give-item', item = 'laser-turret', count = 1}})
table_insert(market_items, {price = {{'coin', 300}}, offer = {type = 'give-item', item = 'loader', count = 1}})
table_insert(market_items, {price = {{'coin', 600}}, offer = {type = 'give-item', item = 'fast-loader', count = 1}})
table_insert(market_items, {price = {{'coin', 900}}, offer = {type = 'give-item', item = 'express-loader', count = 1}})
-- scrap selling
table_insert(market_items, {price = {{'raw-fish', 1}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'wood', 7}}, offer = {type = 'give-item', item = 'coin', count = 1}})
-- item selling
table_insert(market_items, {price = {{'raw-fish', 1}}, offer = {type = 'give-item', item = 'coin', count = 20}})
table_insert(market_items, {price = {{'wood', 1}}, offer = {type = 'give-item', item = 'coin', count = 5}})
table_insert(market_items, {price = {{'iron-ore', 7}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'copper-ore', 7}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'stone', 7}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'coal', 7}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'uranium-ore', 5}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'uranium-ore', 3}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'copper-cable', 12}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'iron-gear-wheel', 3}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'iron-stick', 12}}, offer = {type = 'give-item', item = 'coin', count = 1}})

View File

@ -43,10 +43,11 @@ local function mining_sound(player)
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'})
-- local surface = target.surface
-- local position = target.position
-- local path = 'entity-mining/' .. target.name
-- TODO: find the right sound
--surface.play_sound({path = path, position = position, volume_modifier = 1, override_sound_type = 'game-effect'})
end
local function on_tick()

View File

@ -13,21 +13,21 @@ local function initialize_nauvis()
local mgs = surface.map_gen_settings
mgs.default_enable_all_autoplace_controls = true -- don't mess with this!
mgs.autoplace_controls = {
coal = {frequency = 'none', size = 1, richness = 'normal'},
stone = {frequency = 'none', size = 1, richness = 'normal'},
['copper-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['iron-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
coal = {frequency = 2, size = 0.1, richness = 'very-low'},
stone = {frequency = 2, size = 0.1, richness = 'very-low'},
['copper-ore'] = {frequency = 7, size = 0.1, richness = 'very-low'},
['iron-ore'] = {frequency = 7, size = 0.1, richness = 'very-low'},
['uranium-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['crude-oil'] = {frequency = 'very-low', size = 'very-small', richness = 'normal'},
['crude-oil'] = {frequency = 2, size = 0.05, richness = 'very-low'},
trees = {frequency = 2, size = 'normal', richness = 'normal'},
['enemy-base'] = {frequency = 'very-high', size = 2, richness = 'normal'}
}
mgs.autoplace_settings = {
entity = {
settings = {
['rock-huge'] = {frequency = 2, size = 12, richness = 'very-high'},
['rock-big'] = {frequency = 3, size = 12, richness = 'very-high'},
['sand-rock-big'] = {frequency = 3, size = 12, richness = 1, 'very-high'}
['rock-huge'] = {frequency = 2, size = 3, richness = 'very-high'},
['rock-big'] = {frequency = 2, size = 3, richness = 'very-high'},
['sand-rock-big'] = {frequency = 2, size = 3, richness = 1, 'very-high'}
}
},
decorative = {

View File

@ -12,11 +12,11 @@ local valid_entities = {
}
local size_raffle = {
{'giant', 1024, 2048},
{'huge', 512, 1024},
{'big', 256, 510},
{'small', 126, 256},
{'tiny', 64, 128}
{'giant', 500, 1000},
{'huge', 300, 500},
{'big', 150, 300},
{'small', 80, 150},
{'tiny', 50, 80}
}
local function get_chances()
@ -42,9 +42,7 @@ local function set_raffle()
end
local function get_amount()
local base = 256 + 2 ^ 8
local max = 2 ^ 12
return math_random(math_random(256, base), math_random(base, max))
return math_random(100, 1000)
end
local function draw_chain(surface, count, ore, ore_entities, ore_positions)

View File

@ -41,6 +41,35 @@ local destroy_robot_types = {
['logistic-robot'] = true
}
-- hand craftable
local player_force_disabled_recipes = {
'lab',
'automation-science-pack',
'steel-furnace',
'electric-furnace',
'stone-wall',
'stone-brick',
'radar'
}
local player_force_enabled_recipes = {
'submachine-gun',
'assembling-machine-1',
'small-lamp',
'shotgun',
'shotgun-shell',
'underground-belt',
'splitter',
'steel-plate',
'car',
'tank',
'engine-unit',
'constant-combinator',
'green-wire',
'red-wire',
'arithmetic-combinator',
'decider-combinator'
}
local function min_slots(slots)
local min = 0
for i = 1, 3, 1 do
@ -192,6 +221,7 @@ end
function Public.give_player_items(player)
player.clear_items_inside()
player.insert({name = 'raw-fish', count = 3})
player.insert({name = 'stone-furnace', count = 1})
end
function Public.set_player_to_outlander(player)
@ -399,10 +429,7 @@ local function declare_war(player, item)
requesting_force.set_friend(target_force, false)
target_force.set_friend(requesting_force, false)
game.print(
'>> ' .. player.name .. ' has dropped the coal! Town ' .. target_force.name .. ' and ' .. requesting_force.name .. ' are now at war!',
{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 function delete_chart_tag_for_all_forces(market)
@ -547,7 +574,8 @@ local function disable_deconstruct(permission_group)
end
end
local function enable_artillery(force, permission_group)
-- not in use
--[[ local function enable_artillery(force, permission_group)
permission_group.set_allows_action(defines.input_action.use_artillery_remote, true)
force.technologies['artillery'].enabled = true
force.technologies['artillery-shell-range-1'].enabled = true
@ -556,8 +584,7 @@ local function enable_artillery(force, permission_group)
force.recipes['artillery-wagon'].enabled = false
force.recipes['artillery-targeting-remote'].enabled = false
force.recipes['artillery-shell'].enabled = false
end
end ]]
local function disable_artillery(force, permission_group)
permission_group.set_allows_action(defines.input_action.use_artillery_remote, false)
force.technologies['artillery'].enabled = false
@ -622,7 +649,7 @@ function Public.add_new_force(force_name)
reset_permissions(permission_group)
enable_blueprints(permission_group)
enable_deconstruct(permission_group)
enable_artillery(force, permission_group)
disable_artillery(force, permission_group)
disable_spidertron(force, permission_group)
disable_rockets(force)
disable_nukes(force)
@ -637,6 +664,11 @@ function Public.add_new_force(force_name)
-- balance initial combat
force.set_ammo_damage_modifier('landmine', -0.75)
force.set_ammo_damage_modifier('grenade', -0.5)
--Give townys same tech as outlanders
local recipes = force.recipes
for _, recipe_name in pairs(player_force_enabled_recipes) do
recipes[recipe_name].enabled = true
end
if (ffatable.testing_mode == true) then
local e_force = game.forces['enemy']
e_force.set_friend(force, true) -- team force should not be attacked by turrets
@ -701,9 +733,7 @@ local function kill_force(force_name, cause)
end
end
local r = 27
for _, e in pairs(
surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', type = 'resource'})
) do
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', type = 'resource'})) do
if e.name ~= 'crude-oil' then
e.destroy()
end
@ -759,35 +789,6 @@ local function kill_force(force_name, cause)
end
end
-- hand craftable
local player_force_disabled_recipes = {
'lab',
'automation-science-pack',
'steel-furnace',
'electric-furnace',
'stone-wall',
'stone-brick',
'radar'
}
local player_force_enabled_recipes = {
'submachine-gun',
'assembling-machine-1',
'small-lamp',
'shotgun',
'shotgun-shell',
'underground-belt',
'splitter',
'steel-plate',
'car',
'tank',
'engine-unit',
'constant-combinator',
'green-wire',
'red-wire',
'arithmetic-combinator',
'decider-combinator'
}
local function setup_neutral_force()
local force = game.forces['neutral']
force.technologies['military'].researched = true
@ -930,6 +931,7 @@ local function on_entity_damaged(event)
local player = cause.player
if player ~= nil and force.index == game.forces['player'].index then
-- set the force of the player to rogue until they die or create a town
player.print('You have broken the peace with the biters. They will seek revenge!')
set_player_to_rogue(player)
end
end

View File

@ -15,7 +15,7 @@ local Color = require 'utils.color_presets'
local town_radius = 27
local radius_between_towns = 64
local ore_amount = 1000 * (200 / 168.5)
local ore_amount = 500 * (200 / 168.5)
local colors = {}
local c1 = 250
@ -120,17 +120,16 @@ end
--}
local starter_supplies = {
{name = 'raw-fish', count = 3},
{name = 'grenade', count = 3},
{name = 'stone', count = 32},
{name = 'raw-fish', count = 20},
{name = 'grenade', count = 5},
{name = 'stone', count = 100},
{name = 'land-mine', count = 4},
{name = 'iron-gear-wheel', count = 16},
{name = 'iron-plate', count = 32},
{name = 'copper-plate', count = 16},
{name = 'iron-plate', count = 200},
{name = 'shotgun', count = 1},
{name = 'shotgun-shell', count = 8},
{name = 'firearm-magazine', count = 16},
{name = 'gun-turret', count = 2}
{name = 'firearm-magazine', count = 20},
{name = 'gun-turret', count = 4}
}
local function count_nearby_ore(surface, position, ore_name)
@ -188,7 +187,7 @@ local function draw_town_spawn(player_name)
table_shuffle(ores)
for i = 1, 4, 1 do
if count_nearby_ore(surface, position, ores[i]) < 200000 then
if count_nearby_ore(surface, position, ores[i]) < 100000 then
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, 64, 1)
@ -244,7 +243,7 @@ local function draw_town_spawn(player_name)
local x = position.x + vector[1] + 0.5
local y = position.y + vector[2] + 0.5
local p = {x = x, y = y}
if math_random(1, 5) == 1 then
if math_random(1, 3) == 1 then
if surface.can_place_entity({name = 'fish', position = p}) then
surface.create_entity({name = 'water-splash', position = p})
surface.create_entity({name = 'fish', position = p})
@ -445,16 +444,6 @@ local function found_town(event)
return
end
-- does player have 100 coins?
local inventory = character.get_main_inventory()
if inventory == nil or inventory.get_item_count('coin') < 100 then
player.print('Towns cost 100 coins!', {255, 255, 0})
player.insert({name = 'stone-furnace', count = 1})
return
else
inventory.remove({name = 'coin', count = 100})
end
local force = Team.add_new_force(force_name)
ffatable.town_centers[force_name] = {}
@ -475,7 +464,7 @@ local function found_town(event)
town_center.upgrades.mining_speed = 0
town_center.upgrades.crafting_speed = 0
town_center.upgrades.laser_turret = {}
town_center.upgrades.laser_turret.slots = 0
town_center.upgrades.laser_turret.slots = 4
town_center.upgrades.laser_turret.locations = 0
town_center.evolution = {}
town_center.evolution.biters = 0
@ -527,7 +516,7 @@ local function found_town(event)
ffatable.number_of_towns = ffatable.number_of_towns + 1
Enemy.clear_enemies(position, surface, town_radius * 2)
Enemy.clear_enemies(position, surface, town_radius * 5)
draw_town_spawn(force_name)
-- set the spawn point

View File

@ -6,22 +6,8 @@ local math_abs = math.abs
local get_noise = require 'utils.get_noise'
local Table = require 'modules.scrap_towny_ffa.table'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
require 'modules.no_deconstruction_of_neutral_entities'
local scrap_entities = {
-- simple entity
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'small-ship-wreck'}, -- these are not mineable normally
{name = 'medium-ship-wreck'}, -- these are not mineable normally
{name = 'medium-ship-wreck'}, -- these are not mineable normally
{name = 'medium-ship-wreck'}, -- these are not mineable normally
{name = 'medium-ship-wreck'}, -- these are not mineable normally
-- simple entity with owner
{name = 'crash-site-spaceship-wreck-small-1'}, -- these do not have mining animation
{name = 'crash-site-spaceship-wreck-small-1'}, -- these do not have mining animation
@ -202,24 +188,6 @@ local function place_scrap(surface, position)
end
end
-- place market spaceship
if math_random(1, 4096) == 1 then
local spaceship = {}
if surface.can_place_entity({name = 'crash-site-spaceship-market', position = position, force = 'neutral'}) then
spaceship.market = surface.create_entity({name = 'crash-site-spaceship-market', position = position, force = 'neutral'})
spaceship.market.minable = false
spaceship.max_health = 300
spaceship.health = spaceship.max_health
if spaceship.market and spaceship.market.valid then
if ffatable.spaceships[position.x] == nil then
ffatable.spaceships[position.x] = {}
end
ffatable.spaceships[position.x][position.y] = spaceship
end
end
return
end
-- place scrap containers with loot
if math_random(1, 128) == 1 then
local scrap = scrap_containers[math_random(1, scrap_containers_index)]

View File

@ -0,0 +1,2 @@
require 'maps.scrap_towny_ffa.main'
return require 'terrain_layouts.scrap_towny_ffa'