Skip to content

Commit

Permalink
Merge pull request ComfyFactory#336 from blubFisch/develop-blub
Browse files Browse the repository at this point in the history
Develop blub
  • Loading branch information
Gerkiz authored Oct 16, 2022
2 parents ff064a6 + d0dc8da commit d59a542
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 97 deletions.
23 changes: 10 additions & 13 deletions maps/scrap_towny_ffa/building.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local math_floor = math.floor
local table_insert = table.insert
local table_size = table.size
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local PvPShield = require 'maps.scrap_towny_ffa.pvp_shield'

local town_zoning_entity_types = { "wall", "gate", "electric-pole", "ammo-turret", "electric-turret", "fluid-turret"}

Expand Down Expand Up @@ -223,26 +224,19 @@ local function process_built_entities(event)
local name = entity.name
local surface = entity.surface
local position = entity.position
local force
local force_name
if player_index ~= nil then
local player = game.players[player_index]
if player ~= nil then
local force = player.force
if force ~= nil then
force_name = force.name
end
end
force = player.force
force_name = force.name
else
local robot = event.robot
if robot ~= nil then
local force = robot.force
if force ~= nil then
force_name = force.name
end
end
force = robot.force
force_name = force.name
end

if Public.near_another_town(force_name, position, surface, 32) == true then
if PvPShield.in_other_zones(surface, position, force) or Public.near_another_town(force_name, position, surface, 32) == true then
if neutral_whitelist[name] then
entity.force = game.forces['neutral']
else
Expand Down Expand Up @@ -335,6 +329,9 @@ local function on_player_built_tile(event)
if prevent_landfill_in_restricted_zone(event) then
return
end
if process_built_entities(event) then
return
end
if prevent_tiles_near_towns(event) then
return
end
Expand Down
51 changes: 20 additions & 31 deletions maps/scrap_towny_ffa/info.lua
Original file line number Diff line number Diff line change
@@ -1,64 +1,53 @@
local Public = {}

local info =
[[You wake up on this god-forsaken planet with a bunch of other desolate fools. Who will survive?
[[This is the wasteland. Who will survive?
You can either
- Found a new town or join an existing one
- Stay as an Outlander and fight towns side-by-side with the biters
- Stay as outlander and fight towns together with the biters
Click on the "Info" button for full intro/help.
Click on the "Info" button for full intro, help and changelog.
Have fun and be comfy ^.^
Have fun and be comfy ^.^]]

Changelog (10th-15th October 2022):
local info_adv =
[[
# Changelog (10th-16th October 2022):
- PvP shields now prevent building inside
- Combat balance overhaul
- Towns have an initial PvP protection shield, size and duration is scaled with the biggest town size
- Town player limit fixes
- Towns have an initial PvP protection shield - size and duration is scaled with the biggest town size
- Temporary PvP shield available in market for breaks / AFK
- Improved base defenses and offline survivability
- Loads of bugfixes including freezes and desyncs
]]
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.
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.
- How to get more ores? Make sure you researched steel processing,
then hand mine a few big rocks to find ore patches under them!
- How to get more oil? Kill worms - some of them will leave you a oil patch
- How to get more oil? Kill worms - some of them will leave you an oil patch
- 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.
So protect it well, repair it whenever possible, and increase its health by purchasing upgrades.
- It's possible to automate trading with the town center! How cool is that?!! Try it out.
Tip: use filter inserters with to get coins/iron/.. out of the market
- Fishes procreate near towns. The more fishes, the quicker they multiply. Automated fish farm, anyone?
- Use /rename-town (chat command) to rename your town
- PvP shields prevent players from entering and building inside, but they can still shoot inside!
- Your town has a AFK PvP shield that you can use to safely take a quick break
without other players killing your town. Deploy it from the market.
# Alliances
Once a town is formed, members may invite other players and teams using a coin. To invite another player, drop a coin
# Town members and 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
on the market. As a member of a town, your respawn point will change to that of the town.
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.
]]
on the market.
- 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.]]

function Public.toggle_button(player)
if player.gui.top['towny_map_intro_button'] then
Expand Down
18 changes: 15 additions & 3 deletions maps/scrap_towny_ffa/pvp_shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local function remove_drawn_borders(shield)
end
end

local function scale_size_and_box(shield)
local function scale_size_by_lifetime(shield)
local time_scale = math.min(1, (game.tick - shield.lifetime_start) / shield.time_to_full_size_ticks)
local scaled_size = time_scale * shield.max_size

Expand Down Expand Up @@ -63,7 +63,7 @@ function Public.add_shield(surface, force, center, max_size, lifetime_ticks, tim
string.format("%.0f", (Public.remaining_lifetime(shield)) / 60 / 60) .. ' minutes')
end

scale_size_and_box(shield)
scale_size_by_lifetime(shield)
this.pvp_shields[force.name] = shield
end

Expand All @@ -89,7 +89,7 @@ local function update_shield_lifetime()
if Public.remaining_lifetime(shield) > 0 then
if shield.size < shield.max_size then
remove_drawn_borders(shield)
scale_size_and_box(shield)
scale_size_by_lifetime(shield)
draw_borders(shield)

-- Push everyone out as we grow (even if they're just standing)
Expand All @@ -107,6 +107,18 @@ local function vector_norm(vector)
return math_sqrt(vector.x ^ 2 + vector.y ^ 2)
end

function Public.in_other_zones(surface, position, force)
local this = ScenarioTable.get_table()
for _, shield in pairs(this.pvp_shields) do
if not (shield.force == force or surface ~= shield.surface) then
if CommonFunctions.point_in_bounding_box(position, shield.box) then
return true
end
end
end
return false
end

function Public.push_enemies_out(player)
local this = ScenarioTable.get_table()
for _, shield in pairs(this.pvp_shields) do
Expand Down
53 changes: 24 additions & 29 deletions maps/scrap_towny_ffa/team.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ local all_force_enabled_recipes = {
'shotgun-shell',
}

local function min_slots(slots)
local min = 0
for i = 1, 3, 1 do
if slots[i] > min then
min = slots[i]
end
end
return min
end

local function update_member_limit(force)
if not force or not force.valid then
log('force nil or not valid!')
Expand All @@ -80,23 +70,25 @@ local function update_member_limit(force)
local this = ScenarioTable.get_table()
local town_centers = this.town_centers

local slots = {0, 0, 0}
for _, town_center in pairs(town_centers) do
local players = table_size(town_center.market.force.players)
-- get min value for all slots
local min = min_slots(slots)
-- if our value greater than min of all three replace that slot
if players > min then
for i = 1, 3, 1 do
if slots[i] == min then
slots[i] = players
break
end
-- Limit is increased by counting towns that are the limit
-- This will ensure no single town has many more players than another
local limit = 1
while true do
local towns_near_limit = 0
for _, town_center in pairs(town_centers) do
local players = table_size(town_center.market.force.players)
if players >= limit then
towns_near_limit = towns_near_limit + 1
end
end
if towns_near_limit >= 2 then
limit = limit + 1
else
break
end
end
-- get the min of all slots -- TODO: without the hard limit, the soft limit increases too much so it never applies
this.member_limit = math_min(min_slots(slots) + 1, 3)

this.member_limit = math_min(limit, 3)
end

local function can_force_accept_member(force)
Expand All @@ -108,7 +100,8 @@ local function can_force_accept_member(force)
update_member_limit(force)

if #force.players >= this.member_limit then
game.print('>> Town ' .. force.name .. ' has too many settlers! Current limit (' .. this.member_limit .. ')', {255, 255, 0})
game.print('>> Town ' .. force.name .. ' has too many settlers! Current limit: ' .. this.member_limit .. '.'
.. ' The limit will increase once other towns have more settlers.', {255, 255, 0})
return false
end
return true
Expand Down Expand Up @@ -239,7 +232,7 @@ function Public.add_player_to_town(player, town_center)
Public.set_player_color(player)

update_member_limit(force)
game.print('>> The new member limit for all towns is now ' .. this.member_limit, {255, 255, 0})
game.print('>> The member limit for all towns is now: ' .. this.member_limit, {255, 255, 0})
end

-- given to player upon respawn
Expand Down Expand Up @@ -277,7 +270,6 @@ local function set_player_to_rogue(player)
return
end

player.print("You have broken the peace with the biters. They will seek revenge!")
player.force = 'rogue'
local group = game.permissions.get_group('rogue')
if group == nil then
Expand All @@ -288,6 +280,7 @@ local function set_player_to_rogue(player)
log('Given object is not of LuaPlayer!')
return
end
player.print("You have broken the peace with the biters. They will seek revenge!")
group.add_player(player)
player.tag = '[Rogue]'
Map.disable_world_map(player)
Expand Down Expand Up @@ -460,7 +453,8 @@ local function declare_war(player, item)
if requesting_force.name == target_force.name then
if player.name ~= target.force.name then
Public.set_player_to_outlander(player)
game.print('>> ' .. player.name .. ' has abandoned ' .. target_force.name .. "'s Town!", {255, 255, 0})
local town_center = this.town_centers[target_force.name]
game.print('>> ' .. player.name .. ' has abandoned ' .. town_center.town_name, {255, 255, 0})
this.requests[player.index] = nil
end
if player.name == target.force.name then
Expand All @@ -475,7 +469,8 @@ local function declare_war(player, item)
return
end
Public.set_player_to_outlander(target_player)
game.print('>> ' .. player.name .. ' has banished ' .. target_player.name .. ' from their Town!', {255, 255, 0})
local town_center = this.town_centers[player.force.name]
game.print('>> ' .. player.name .. ' has banished ' .. target_player.name .. ' from ' .. town_center.town_name, {255, 255, 0})
this.requests[player.index] = nil
end
return
Expand Down
8 changes: 4 additions & 4 deletions maps/scrap_towny_ffa/town_center.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,18 @@ local function add_pvp_shield_scaled(position, force, surface)
local evo = Evolution.get_highest_evolution()

local min_size = 70
local max_size = 140
local max_size = 150
local min_duration = 0.5 * 60 * 60 * 60
local max_duration = 8 * 60 * 60 * 60
local lifetime_ticks = min_duration + evo * (max_duration - min_duration)
local size = math_min(min_size + 2 * evo * (max_size - min_size), max_size) -- Size grows quicker but is still capped
local lifetime_ticks = math_min(min_duration + 2 * evo * (max_duration - min_duration), max_duration)
local size = math_min(min_size + 2 * evo * (max_size - min_size), max_size)

PvPShield.add_shield(surface, force, position, size, lifetime_ticks, 60 * 60)
update_pvp_shields_display()
force.print("Based on the highest tech on map, your town deploys a PvP shield of "
.. string.format("%.0f", size) .. " tiles"
.. " for " .. string.format("%.0f", lifetime_ticks/60/60) .. " minutes."
.. " Enemy players will not be able to enter the shielded area.")
.. " Enemy players will not be able to enter and build in the shielded area.")
end

local function found_town(event)
Expand Down
28 changes: 11 additions & 17 deletions maps/scrap_towny_ffa/wreckage_yields_scrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ local entity_loot_chance = {
{name = 'advanced-circuit', chance = 15},
--{name = "artillery-shell", chance = 1},
{name = 'battery', chance = 15},
{name = 'cannon-shell', chance = 4},
{name = 'cannon-shell', chance = 5},
--{name = "cluster-grenade", chance = 2},
{name = 'construction-robot', chance = 1},
{name = 'copper-cable', chance = 250},
{name = 'copper-plate', chance = 250},
{name = 'crude-oil-barrel', chance = 30},
{name = 'defender-capsule', chance = 5},
{name = 'destroyer-capsule', chance = 1},
{name = 'distractor-capsule', chance = 2},
{name = 'crude-oil-barrel', chance = 50},
{name = 'defender-capsule', chance = 10},
{name = 'destroyer-capsule', chance = 2},
{name = 'distractor-capsule', chance = 4},
{name = 'electric-engine-unit', chance = 2},
{name = 'electronic-circuit', chance = 150},
{name = 'empty-barrel', chance = 10},
{name = 'engine-unit', chance = 5},
{name = 'explosive-cannon-shell', chance = 2},
{name = 'explosive-cannon-shell', chance = 5},
--{name = "explosive-rocket", chance = 3},
--{name = "explosive-uranium-cannon-shell", chance = 1},
{name = 'explosives', chance = 5},
Expand All @@ -33,10 +32,8 @@ local entity_loot_chance = {
{name = 'iron-stick', chance = 50},
{name = 'land-mine', chance = 3},
{name = 'light-oil-barrel', chance = 20},
{name = 'logistic-robot', chance = 1},
{name = 'low-density-structure', chance = 1},
{name = 'lubricant-barrel', chance = 20},
{name = "nuclear-fuel", chance = 1},
{name = "nuclear-fuel", chance = 5},
{name = 'petroleum-gas-barrel', chance = 30},
{name = 'pipe', chance = 100},
{name = 'pipe-to-ground', chance = 10},
Expand All @@ -52,18 +49,17 @@ local entity_loot_chance = {
{name = "uranium-fuel-cell", chance = 1},
--{name = "used-up-uranium-fuel-cell", chance = 1},
{name = 'water-barrel', chance = 10},
{name = 'tank', chance = 10},
{name = 'car', chance = 20}
{name = 'tank', chance = 2},
{name = 'car', chance = 30}
}

-- positive numbers can scale, 0 is disabled, and negative numbers are fixed absolute values
local entity_loot_amounts = {
['advanced-circuit'] = 6,
--["artillery-shell"] = 0.3,
['battery'] = 2,
['cannon-shell'] = 4,
['cannon-shell'] = 2,
--["cluster-grenade"] = 0.3,
['construction-robot'] = 0.3,
['copper-cable'] = 24,
['copper-plate'] = 16,
['crude-oil-barrel'] = 3,
Expand All @@ -74,7 +70,7 @@ local entity_loot_amounts = {
['electronic-circuit'] = 8,
['empty-barrel'] = 3,
['engine-unit'] = 2,
['explosive-cannon-shell'] = 2,
['explosive-cannon-shell'] = 1,
--["explosive-rocket"] = 2,
--["explosive-uranium-cannon-shell"] = 2,
['explosives'] = 4,
Expand All @@ -87,8 +83,6 @@ local entity_loot_amounts = {
['iron-stick'] = 16,
['land-mine'] = 6,
['light-oil-barrel'] = 3,
['logistic-robot'] = 0.3,
['low-density-structure'] = 0.3,
['lubricant-barrel'] = 3,
["nuclear-fuel"] = 0.1,
['petroleum-gas-barrel'] = 3,
Expand Down

0 comments on commit d59a542

Please sign in to comment.