1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-03 13:12:11 +02:00
This commit is contained in:
Piratux 2022-10-29 13:30:17 +03:00
commit 81905d9d7c
112 changed files with 4132 additions and 3629 deletions

View File

@ -402,6 +402,7 @@ stds.factorio_control = {
'server_save',
'set_game_state',
'reset_time_played',
'reset_game_state',
'show_message_dialog',
'table_to_json',
'encode_string',

View File

@ -78,7 +78,7 @@ require 'utils.freeplay'
--require 'modules.wave_defense.main'
--require 'modules.fjei.main'
--require 'modules.charging_station'
--require 'modules.nuclear_landmines'
--require 'modules.landmine_effects'
--require 'modules.crawl_into_pipes'
--require 'modules.no_acid_puddles'
--require 'modules.simple_tags'
@ -252,7 +252,6 @@ require 'utils.freeplay'
--require 'terrain_layouts.scrap_02'
--require 'terrain_layouts.watery_world'
--require 'terrain_layouts.tree_01'
--require 'terrain_layouts.scrap_towny_ffa'
---------------------------------------------------------------
--- this file exists only for the panel to sync and start from within the panel

View File

@ -75,7 +75,7 @@ local function spawn_biter(surface, position, evolution)
end
end
local function unearthing_biters(surface, position, amount)
local function unearthing_biters(surface, position, amount, relative_evolution)
if not surface then
return
end
@ -94,6 +94,10 @@ local function unearthing_biters(surface, position, amount)
local evolution = game.forces.enemy.evolution_factor
if relative_evolution then
evolution = relative_evolution
end
local ticks = amount * 40
ticks = ticks + 80
for t = 4, ticks, 4 do
@ -111,7 +115,7 @@ local function unearthing_biters(surface, position, amount)
if t % 40 == 36 then
traps[tick][#traps[tick] + 1] = {
callback = 'spawn_biter',
params = {surface, {x = position.x, y = position.y}, evolution}
params = {surface, {x = position.x, y = position.y}, evolution, relative_evolution}
}
end
end

View File

@ -126,7 +126,7 @@ local function spawn_worm(surface, position, evolution_index)
surface.create_entity({name = worm_name, position = position})
end
local function unearthing_worm(surface, position)
local function unearthing_worm(surface, position, relative_evolution)
if not surface then
return
end
@ -144,6 +144,10 @@ local function unearthing_worm(surface, position)
end
local evolution_index = math.ceil(game.forces.enemy.evolution_factor * 10)
if relative_evolution then
evolution_index = math.ceil(relative_evolution * 10)
end
if evolution_index < 1 then
evolution_index = 1
end

View File

@ -1,7 +1,7 @@
[mountain_fortress_v3]
map_info_main_caption=M O U N T A I N F O R T R E S S V3
map_info_sub_caption= ~~ diggy diggy choo choo ~~
map_info_text=[color=red]READ THIS!\nIf there are any code bugs or desyncs. Please report asap to @Gerkiz!\nIf there are any game breaking bugs then this map might be shutdown to hot-fix the issue.[/color]\n\nThe biters have caught the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn additon, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research will overhaul your mining equipment, increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause rocks to fall down the mountain, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nEnter the cargo wagon to reveal the wagon surface!\n\nRandom buildings that generate resources can be found throughout the world.\n\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nStaying inside the locomotive aura prevents biters from spawning when mining entities.\n\nRadars cannot be built near each other.\n\nRPG GUI is disabled inside the locomotive.\n\nDisconnecting wagons is disabled.\nYou can't cancel crafting when standing inside the locomotive aura.\n\nDon't try to run north with your Spidertron if the train is not near you.\nYou have been warned.\n\nMining drills have great mining-bonus which also is increased after each research, use them when you can!\n\nThe mystical chest in the locomotive offers some rewards.\nOne must feed the chest to receive such rewards.\n\nGood luck on your journey!
map_info_text=[color=red]READ THIS!\nIf there are any code bugs or desyncs. Please report asap to @Gerkiz!\nIf there are any game breaking bugs then this map might be shutdown to hot-fix the issue.[/color]\n\nThe biters have caught the scent of fish in the cargo wagon.\nGuide the choo into the mountain and protect it as long as possible!\nThis however will not be an easy task,\nsince their strength and numbers increase over time.\n\nIn addition, the southern grounds collapse over time.\n\nDelve deep for greater treasures, but also face increased dangers.\nMining productivity research will overhaul your mining equipment, increasing the size of your backpack.\n\nAs you dig, you will encounter impassable dark chasms or rivers.\nArtillery will try to shoot you down! Dig fast, dig north!\n\nSome explosives may cause rocks to fall down the mountain, filling the void, creating new ways.\nAll they need is a container and a well aimed shot.\n\nEnter the cargo wagon to reveal the wagon surface!\n\nRandom buildings that generate resources can be found throughout the world.\n\nPlacing steel-chests near cargo-wagons enables you to quickly move content.\n\nStaying inside the train aura prevents biters from spawning when mining entities.\n\nRadars cannot be built near each other.\n\nRPG GUI is disabled inside the train.\n\nDisconnecting wagons is disabled.\nYou can't cancel crafting when standing inside the train aura.\n\nDon't try to run north with your Spidertron if the train is not near you.\nYou have been warned.\n\nMining drills have great mining-bonus which also is increased after each research, use them when you can!\n\nThe mystical chest in the locomotive offers some rewards.\nOne must feed the chest to receive such rewards.\n\nGood luck on your journey!
[breached_wall]
collapse_start=[color=blue]Mapkeeper:[/color]\nWarning, Collapse has begun!
@ -11,8 +11,6 @@ first_to_reach=[color=blue]Mapkeeper:[/color]\n__1__ was the first to reach zone
artillery_warning=[color=blue]Mapkeeper:[/color]\nWarning, Artillery have been spotted north!
cheating_through=[color=blue]Mapkeeper:[/color] __1__ tried to cheat their way north with their spidertron!
hinder=[color=blue]Mapkeeper:[/color] You are too far away from the main locomotive. You cannot go beyond this point.
heavy_legs=[color=blue]Mapkeeper:[/color] Your legs feels all of a sudden very heavy.
[entity]
treasure_1=[color=blue]Mapkeeper:[/color] You notice an old crate within the rubble. It's filled with treasure!
@ -25,8 +23,8 @@ defeated_1=[color=blue]Mapkeeper:[/color]\nOh no, the biters nom'ed the train aw
defeated_2=[color=blue]Mapkeeper:[/color]\nApparently the train was chewed away.\nBetter luck next time.
defeated_3=[color=blue]Mapkeeper:[/color]\nYou had one objective - defend the train *-*\nBetter luck next time.
defeated_4=[color=blue]Mapkeeper:[/color]\nLooks like we're resetting cause you did not defend the train ._.\nBetter luck next time.
reset_game=*** Soft-reset is disabled! Server will restart from scenario to load new changes. ***
notify_restart=Soft-reset is disabled! Server will restart from scenario to load new changes.
reset_game=*** Soft-reset is disabled! Server will restart to load new changes. ***
notify_restart=Soft-reset is disabled! Server will restart to load new changes.
shutdown_game=*** Soft-reset is disabled! Server will shutdown. Most likely because of updates. ***
notify_shutdown=Soft-reset is disabled! Server will shutdown. Most likely because of updates.
train_taking_damage=[color=blue]Comfylatron:[/color]\nTrain is taking heavy damage.\nDeploying defense mechanisms.
@ -38,12 +36,12 @@ radar_limit=[color=blue]Mapkeeper:[/color] Another radar is found nearby!
[gui]
global_pool_tooltip=Dig, handcraft or run to increase the pool!
global_pool_amount=Amount of XP that is stored inside the global xp pool.\nRaw Value: __1__
amount_harvested=Amount of trees/rocks harvested.
amount_harvested=Amount of harvested trees and rocks.
biters_killed=Amount of biters killed.
land_mine_placed=Amount of land-mines that can be built.
chest_placed=Amount of chests that can be placed near train.\nLimit is per cargo-wagon.
flamethrowers_placed=Amount of flamethrower-turrets that can be built.
train_upgrades=Amount of train upgrades.
train_upgrade_contribution=Coins spent on upgrading train.
info_tooltip=Shows statistics!
hide_minimap=Hide locomotive minimap!
current_pickaxe_tier=The team currently has the __1__ pickaxe tier.\nBonus speed is: __2__%
@ -62,9 +60,9 @@ quantity_text=Quantity:
limit_reached=Max limit reached!
chests_full=You can't purchase more chests.
chest_bought_info=__1__ __2__ has bought the chest limit upgrade for __3__ coins.
health_bought_info=__1__ __2__ has bought the locomotive health modifier for __3__ coins.
aura_bought_info=__1__ __2__ has bought the locomotive xp aura modifier for __3__ coins.
xp_bought_info=__1__ __2__ has bought the XP points modifier for __3__ coins.
health_bought_info=__1__ __2__ has upgraded the train health for __3__ coins.
aura_bought_info=__1__ __2__ has upgraded the train aura radius for __3__ coins.
xp_bought_info=__1__ __2__ has upgraded the train aura XP modifier for __3__ coins.
mystical_bought_info=__1__ __2__ has rerolled the mystical chest for __3__ coins.
reroll_bought_info=__1__ __2__ has rerolled the market items for __3__ coins.
pickaxe_bought_info=__1__ __2__ has upgraded the teams pickaxe to tier __3__ for __4__ coins.
@ -73,7 +71,6 @@ car_health_upgrade_pool_bought_info=__1__ __2__ has bought the global car health
one_flamethrower_bought_info=__1__ __2__ has bought a flamethrower-turret slot for __3__ coins.
multiple_flamethrower_bought_info=__1__ __2__ has bought __3__ flamethrower-turret slot for __4__ coins.
landmine_bought_info=__1__ __2__ has bought a landmine slot for __3__ coins.
rpg_reset_bought_info=__1__ __2__ decided to recycle their RPG skills and start over for __3__ coins.
full_inventory=Your pockets are now filled to the brim. So you've only bought __1__ __2__(s).
change_returned=Shopkeeper has returned your change, for which you are infinitely grateful.
notify_full_inventory_1=Your inventory is full. Try to stash your loot somewhere first.
@ -81,8 +78,6 @@ notify_full_inventory_2=Your inventory is full. Join the warrior club today! Pum
new_items_at_market=New items have been unlocked at the locomotive market!
discharge_unlocked=Discharge defense has now been unlocked at the market!
artillery_unlocked=Artillery has now been unlocked at the market!
wd_paused=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Wave Defense has been paused for 5 minutes![/color]
wd_resumed=[color=yellow]Wave Defense has been resumed![/color]
mining_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Mining speed bonus has been applied for 15 minutes![/color]
mining_bonus_end=Mining speed bonus has ended!
movement_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Movement speed bonus has been applied for 15 minutes![/color]
@ -90,18 +85,17 @@ movement_bonus_end=Movement speed bonus has ended!
coin_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Coins has been distributed![/color]
xp_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]XP has been granted to Global pool![/color]
inventory_bonus=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Inventory slot upgrade has been applied![/color]
locomotive_health=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Locomotive health has been replenished![/color]
locomotive_health=__1__ unlocked the last missing piece for the mystical chest!\n[color=yellow]Train health has been replenished![/color]
[main_market]
chest=Upgrades the amount of chests that can be placed outside.\nCan be purchased multiple times. [__1__/__2__]
locomotive_max_health=Upgrades the train health.\nCan be purchased multiple times. [__1__/__2__]
locomotive_aura_radius=Upgrades the XP aura that is around the train. [__1__/__2__]\n[Limited to save UPS]
chest=Upgrades the amount of chests that can be placed outside. [__1__/__2__]
locomotive_max_health=Upgrades the train health. [__1__/__2__]
locomotive_aura_radius=Upgrades the train aura radius. [__1__/__2__]\n[Limited to save UPS]
global_car_health_modifier=Grants all cars/tanks/spidertrons a global health modifier.
xp_points_boost=Upgrades the amount of XP points you get inside the XP aura [__1__/♾]
xp_points_boost=Increases the amount of XP you get inside train aura [__1__/♾]
mystical_chest=Rerolls the mystical chest.
explosive_bullets=Upgrades ordinary SMG ammo to explosive bullets.
reroll_market_items=Will reroll the items in the market and shuffle prices.
purchase_pickaxe=Upgrade the teams Pickaxe to tier: __1__ [__2__/__3__]
sold_out=Sold out!
flamethrower_turret=Upgrades the amount of flamethrowers that can be placed. [__1__/♾]
@ -121,13 +115,14 @@ death_message_6=__1__ got obliterated!
death_message_7=__1__ tried to cheat their way north!
forcefield=Forcefield does not approve.
greeting=[color=blue]Comfylatron:[/color]\nGreetings, __1__!\nPlease read the map info.
death_mode_warning=[color=blue]Comfylatron:[/color]\nCAUTION! Walking outside of the locomotive aura will kill you!
aura_upgrade_warning=[color=blue]Comfylatron:[/color]\nThe locomotive aura range has been upgraded!
damage_mode_warning=[color=blue]Comfylatron:[/color]\nCAUTION! Walking outside of the locomotive aura will slowly kill you!
death_mode_warning=[color=blue]Comfylatron:[/color]\nCAUTION! Walking outside of the train aura will kill you!
aura_upgrade_warning=[color=blue]Comfylatron:[/color]\nThe train aura radius has been upgraded!
damage_mode_warning=[color=blue]Comfylatron:[/color]\nCAUTION! Walking outside of the train aura will slowly kill you!
cleaner=[color=blue]Cleaner:[/color]\n__1__ has left his goodies! Be quick and fetch them!
reset_in=Game will __1__ in __2__ seconds!
diff_set=Difficulty has been set! Game has been set to: [color=green]__1__[/color]
diff_tooltip=Wave Defense is based on amount of players.\nBonus XP on join: __1__.\nMining speed boost: __2__.\nRunning speed boost: __3__.\nCrafting speed boost: __4__.\nMaximum coin per harvest: __5__.\nFlame Turret limit: __6__.\nLandmine limit: __7__.\nLocomotive health: __8__.\nHidden Treasure has __9__ chance to spawn.\nGrace period: __10__ minutes\nSpidertrons unlocks at zone __11__.
diff_tooltip=Wave Defense is based on amount of players.\nBonus XP on join: __1__.\nMining speed boost: __2__.\nRunning speed boost: __3__.\nCrafting speed boost: __4__.\nMaximum coin per harvest: __5__.\nFlame Turret limit: __6__.\nLandmine limit: __7__.\nTrain health: __8__.\nHidden Treasure has __9__ chance to spawn.\nGrace period: __10__ minutes\nSpidertrons unlocks at zone __11__.
[functions]
researched_complete=__1__ has been researched!

View File

@ -40,7 +40,7 @@ biters_killed=Количество убитых кусак.
land_mine_placed=Количество мин, которые можно разместить.
chest_placed=Количество сундуков, которые можно разместить около поезда.\nПредел на каждый грузовой вагон.
flamethrowers_placed=Количество огненных турелей, которые можно построить.
train_upgrades=Количество улучшений поезда.
train_upgrade_contribution=Количество улучшений поезда.
info_tooltip=Показать статистику!
hide_minimap=Убрать миникарту локомотива!
current_pickaxe_tier=Уровень кирки у команды: __1__\nБонус скорости: __2__%
@ -70,7 +70,6 @@ car_health_upgrade_pool_bought_info=__1__ __2__ купил глобальное
one_flamethrower_bought_info=__1__ __2__ купил ячейку для огнемётной турели за __3__ монет.
multiple_flamethrower_bought_info=__1__ __2__ купил __3__ ячеек огнемётных турелей за __4__ монет.
landmine_bought_info=__1__ __2__ купил ячейку для мин за __3__ монет.
rpg_reset_bought_info=__1__ __2__ решил сбросить свои RPG умения и начать сначала за __3__ монет.
full_inventory=Ваши карманы заполнены до краёв. Итак, вы купили только __1__ __2__.
change_returned=Лавочник вернул вам сдачу, за что вы ему бесконечно благодарны.
notify_full_inventory_1=Ваш инвентарь полон. Попробуйте сначала сложить добычу где-нибудь.
@ -78,8 +77,6 @@ notify_full_inventory_2=Ваш инвентарь полон. Присоедин
new_items_at_market=На рынке локомотива открыты новые предметы!
discharge_unlocked=Электроразрядная защита теперь доступна на рынке!
artillery_unlocked=Артиллерия теперь доступна на рынке!
wd_paused=__1__ разблокировал последнюю недостающую часть для загадочного сундука!\n[color=yellow]Защита волн поставлена на паузу 5 минут![/color]
wd_resumed=[color=yellow]Защита волн возобновлена![/color]
mining_bonus=__1__ разблокировал последнюю недостающую часть для загадочного сундука!\n[color=yellow]Бонус добычи включён на 15 минут![/color]
movement_bonus=__1__ разблокировал последнюю недостающую часть для загадочного сундука!\n[color=yellow]Бонус к скорости передвижения включён на 15 минут![/color]
coin_bonus=__1__ разблокировал последнюю недостающую часть для загадочного сундука!\n[color=yellow]Всем раздали монет![/color]
@ -95,7 +92,6 @@ global_car_health_modifier=Даёт всем автомобилям/танкам
xp_points_boost=Увеличивает количество очков опыта, которые вы получаете внутри зоны опыта. [__1__]
mystical_chest=Обновляет содержимое загадочного сундука.
explosive_bullets=Улучшает боеприпасы обычных пистолетов-пулеметов до разрывных пуль.
reroll_market_items=Изменит предметы на рынке и перемешает цены.
purchase_pickaxe=Улучшит кирку команды до уровня: __1__ [__2__/58]
sold_out=Продано!
flamethrower_turret=Увеличивает количество размещаемых огнемётов. [__1__]

View File

@ -40,7 +40,7 @@ biters_killed=杀死虫子的数量.
land_mine_placed=制造的地雷数量.
chest_placed=可以放在火车附近箱子的数量.
flamethrowers_placed=火焰喷射器跟炮塔的数量.
train_upgrades=列车等级.
train_upgrade_contribution=列车等级.
info_tooltip=显示数值!
hide_minimap=隐藏火车迷你地图!
current_pickaxe_tier=团队当前 __1__ 斧头等级.\n奖励速度是: __2__%
@ -66,7 +66,6 @@ explosive_bullet_bought_info=__1__ __2__ 购买火焰弹升级 __3__ 硬币.
one_flamethrower_bought_info=__1__ __2__ 购买火焰喷射器-炮塔 __3__ 硬币.
multiple_flamethrower_bought_info=__1__ __2__ 购买 __3__ 火焰喷射器-炮塔 __4__ 硬币.
landmine_bought_info=__1__ __2__ 购买地雷 __3__ 硬币.
rpg_reset_bought_info=__1__ __2__ 重置玩家技能点 __3__ 硬币.
full_inventory=你的背包现在装满了。所以你只买了 __1__ __2__(s).
change_returned=店主已退回您的零钱,对此我们深表感谢.\n
notify_full_inventory_1=您的库存已满.试着先把你的战利品放在某个地方.
@ -80,7 +79,6 @@ locomotive_max_health=升级火车生命.\n可以多次购买
locomotive_aura_radius=升级火车周围的经验光环。
xp_points_boost=升级您在经验光环中获得的经验值
explosive_bullets=将普通的SMG弹药升级为爆炸子弹.
reroll_market_items=重置市场的商品并调整价格.
purchase_pickaxe=将团队镐升级到等级:__1__
sold_out=售罄!
flamethrower_turret=升级可以放置的火焰喷射器的数量.

View File

@ -255,8 +255,6 @@ local function treasure_chest(position, distance_to_center)
{{name = 'firearm-magazine', count = math_random(32, 128)}, weight = 5, evolution_min = 0, evolution_max = 0.3},
{{name = 'piercing-rounds-magazine', count = math_random(32, 128)}, weight = 5, evolution_min = 0.1, evolution_max = 0.8},
{{name = 'uranium-rounds-magazine', count = math_random(32, 128)}, weight = 5, evolution_min = 0.5, evolution_max = 1},
{{name = 'railgun', count = 1}, weight = 1, evolution_min = 0.2, evolution_max = 1},
{{name = 'railgun-dart', count = math_random(16, 32)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = 'defender-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.0, evolution_max = 0.7},
{{name = 'distractor-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.2, evolution_max = 1},
{{name = 'destroyer-capsule', count = math_random(8, 16)}, weight = 2, evolution_min = 0.3, evolution_max = 1},

View File

@ -1337,42 +1337,40 @@ function Public.reset_game()
end
Difficulty.reset_difficulty_poll({difficulty_poll_closing_timeout = wave_grace_period})
if game.is_multiplayer() then
local difficulties = {
[1] = {
name = 'Easy',
value = 0.75,
color = {r = 0.00, g = 0.25, b = 0.00},
print_color = {r = 0.00, g = 0.4, b = 0.00},
enabled = true
},
[2] = {
name = 'Normal',
value = 1,
color = {r = 0.00, g = 0.00, b = 0.25},
print_color = {r = 0.0, g = 0.0, b = 0.5}
},
[3] = {
name = 'Hard',
value = 1.5,
color = {r = 0.25, g = 0.00, b = 0.00},
print_color = {r = 0.4, g = 0.0, b = 0.00}
},
[4] = {
name = 'Nightmare',
value = 3,
color = {r = 0.35, g = 0.00, b = 0.00},
print_color = {r = 0.6, g = 0.0, b = 0.00}
},
[5] = {
name = 'Impossible',
value = 5,
color = {r = 0.45, g = 0.00, b = 0.00},
print_color = {r = 0.8, g = 0.0, b = 0.00}
}
local difficulties = {
[1] = {
name = 'Easy',
value = 0.75,
color = {r = 0.00, g = 0.25, b = 0.00},
print_color = {r = 0.00, g = 0.4, b = 0.00},
enabled = true
},
[2] = {
name = 'Normal',
value = 1,
color = {r = 0.00, g = 0.00, b = 0.25},
print_color = {r = 0.0, g = 0.0, b = 0.5}
},
[3] = {
name = 'Hard',
value = 1.5,
color = {r = 0.25, g = 0.00, b = 0.00},
print_color = {r = 0.4, g = 0.0, b = 0.00}
},
[4] = {
name = 'Nightmare',
value = 3,
color = {r = 0.35, g = 0.00, b = 0.00},
print_color = {r = 0.6, g = 0.0, b = 0.00}
},
[5] = {
name = 'Impossible',
value = 5,
color = {r = 0.45, g = 0.00, b = 0.00},
print_color = {r = 0.8, g = 0.0, b = 0.00}
}
Difficulty.set_difficulties(difficulties)
end
}
Difficulty.set_difficulties(difficulties)
local players = game.connected_players
for i = 1, #players do

View File

@ -1,9 +1,5 @@
local Event = require 'utils.event'
local Difficulty = require 'modules.difficulty_vote_by_amount'
local Public = {}
Public.events = {breached_wall = Event.generate_event_name('breached_wall')}
local Public = require 'maps.mountain_fortress_v3.table'
function Public.init_enemy_weapon_damage()
local data = {
@ -34,7 +30,7 @@ function Public.init_enemy_weapon_damage()
end
end
local function enemy_weapon_damage()
function Public.enemy_weapon_damage()
local e = game.forces.enemy
local data = {
@ -59,6 +55,4 @@ local function enemy_weapon_damage()
end
end
Event.add(Public.events.breached_wall, enemy_weapon_damage)
return Public

View File

@ -1,4 +1,5 @@
local Global = require 'utils.global'
local Public = require 'maps.mountain_fortress_v3.table'
local this = {
market_settings = {
@ -143,8 +144,6 @@ Global.register(
end
)
local Public = {}
local random = math.random
local floor = math.floor
@ -329,35 +328,4 @@ function Public.shuffle_prices()
end
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
function Public.set(key, value)
if key and (value or value == false) then
this[key] = value
return this[key]
elseif key then
return this[key]
else
return this
end
end
function Public.remove(key, sub_key)
if key and sub_key then
if this[key] and this[key][sub_key] then
this[key][sub_key] = nil
end
elseif key then
if this[key] then
this[key] = nil
end
end
end
return Public

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local insert = table.insert
@ -137,3 +138,5 @@ local function on_entity_died(event)
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

View File

@ -1,40 +1,37 @@
local Collapse = require 'modules.collapse'
local Balance = require 'maps.mountain_fortress_v3.balance'
local RPG = require 'modules.rpg.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local Alert = require 'utils.alert'
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Collapse = require 'modules.collapse'
local RPG = require 'modules.rpg.main'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Color = require 'utils.color_presets'
local BasicMarkets = require 'maps.mountain_fortress_v3.basic_markets'
local raise_event = script.raise_event
local floor = math.floor
local abs = math.abs
local random = math.random
local sub = string.sub
local sqrt = math.sqrt
local zone_settings = WPT.zone_settings
local zone_settings = Public.zone_settings
local clear_breach_text_and_render = function()
local beam1 = WPT.get('zone1_beam1')
local beam1 = Public.get('zone1_beam1')
if beam1 and beam1.valid then
beam1.destroy()
end
local beam2 = WPT.get('zone1_beam2')
local beam2 = Public.get('zone1_beam2')
if beam2 and beam2.valid then
beam2.destroy()
end
local zone1_text1 = WPT.get('zone1_text1')
local zone1_text1 = Public.get('zone1_text1')
if zone1_text1 then
rendering.set_text(zone1_text1, 'Collapse has started!')
end
local zone1_text2 = WPT.get('zone1_text2')
local zone1_text2 = Public.get('zone1_text2')
if zone1_text2 then
rendering.set_text(zone1_text2, 'Collapse has started!')
end
local zone1_text3 = WPT.get('zone1_text3')
local zone1_text3 = Public.get('zone1_text3')
if zone1_text3 then
rendering.set_text(zone1_text3, 'Collapse has started!')
end
@ -70,7 +67,7 @@ local first_player_to_zone =
local breached_wall = data.breached_wall
local message = ({'breached_wall.first_to_reach', player.name, breached_wall})
Alert.alert_all_players(10, message)
BasicMarkets.shuffle_prices()
Public.shuffle_prices()
end
)
@ -94,19 +91,19 @@ local spidertron_too_far =
local check_distance_between_player_and_locomotive = function(player)
local surface = player.surface
local position = player.position
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
local gap_between_locomotive = WPT.get('gap_between_locomotive')
local gap_between_locomotive = Public.get('gap_between_locomotive')
if not gap_between_locomotive.highest_pos then
gap_between_locomotive.highest_pos = locomotive.position
end
gap_between_locomotive.highest_pos = locomotive.position
gap_between_locomotive = WPT.get('gap_between_locomotive')
gap_between_locomotive = Public.get('gap_between_locomotive')
local c_y = position.y
local t_y = gap_between_locomotive.highest_pos.y
@ -127,7 +124,7 @@ end
local compare_player_pos = function(player)
local p = player.position
local index = player.index
local adjusted_zones = WPT.get('adjusted_zones')
local adjusted_zones = Public.get('adjusted_zones')
if not adjusted_zones.size then
return
end
@ -166,14 +163,14 @@ local compare_player_and_train = function(player, entity)
end
local position = player.position
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
local gap_between_zones = WPT.get('gap_between_zones')
local gap_between_zones = Public.get('gap_between_zones')
gap_between_zones.highest_pos = locomotive.position
gap_between_zones = WPT.get('gap_between_zones')
gap_between_zones = Public.get('gap_between_zones')
local c_y = position.y
local t_y = gap_between_zones.highest_pos.y
@ -207,13 +204,13 @@ local function distance(player)
local index = player.index
local bonus = RPG.get_value_from_player(index, 'bonus')
local rpg_extra = RPG.get('rpg_extra')
local breached_wall = WPT.get('breached_wall')
local bonus_xp_on_join = WPT.get('bonus_xp_on_join')
local enable_arties = WPT.get('enable_arties')
local breached_wall = Public.get('breached_wall')
local bonus_xp_on_join = Public.get('bonus_xp_on_join')
local enable_arties = Public.get('enable_arties')
local p = player.position
local validate_spider = WPT.get('validate_spider')
local validate_spider = Public.get('validate_spider')
if validate_spider[index] then
local e = validate_spider[index]
if not (e and e.valid) then
@ -236,16 +233,16 @@ local function distance(player)
local max_times = location >= max
if max_times then
if breach_max_times then
local placed_trains_in_zone = WPT.get('placed_trains_in_zone')
local biters = WPT.get('biters')
local placed_trains_in_zone = Public.get('placed_trains_in_zone')
local biters = Public.get('biters')
rpg_extra.breached_walls = rpg_extra.breached_walls + 1
rpg_extra.reward_new_players = bonus_xp_on_join * rpg_extra.breached_walls
WPT.set('breached_wall', breached_wall + 1)
Public.set('breached_wall', breached_wall + 1)
biters.amount = 0
placed_trains_in_zone.randomized = false
raise_event(Balance.events.breached_wall, {})
if WPT.get('breached_wall') == WPT.get('spidertron_unlocked_at_zone') then
local main_market_items = WPT.get('main_market_items')
Public.enemy_weapon_damage()
if Public.get('breached_wall') == Public.get('spidertron_unlocked_at_zone') then
local main_market_items = Public.get('main_market_items')
if not main_market_items['spidertron'] then
local rng = random(70000, 120000)
main_market_items['spidertron'] = {
@ -297,6 +294,9 @@ local function on_player_changed_position(event)
if not player or not player.valid then
return
end
if player.controller_type == defines.controllers.spectator then
return
end
local surface_name = player.surface.name
local map_name = 'mtn_v3'
@ -322,7 +322,7 @@ local function on_player_driving_changed_state(event)
if not (entity and entity.valid) then
return
end
local s = WPT.get('validate_spider')
local s = Public.get('validate_spider')
if entity.name == 'spidertron' then
if not s[player.index] then
s[player.index] = entity
@ -336,3 +336,5 @@ end
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
return Public

View File

@ -1,8 +1,8 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Global = require 'utils.global'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local WD = require 'modules.wave_defense.table'
local WPT = require 'maps.mountain_fortress_v3.table'
local this = {}
@ -13,7 +13,6 @@ Global.register(
end
)
local Public = {}
local round = math.round
local floor = math.floor
local random = math.random
@ -66,7 +65,7 @@ local function spawn_biters(data)
local position = data.position
local h = floor(abs(position.y))
local max_biters = WPT.get('biters')
local max_biters = Public.get('biters')
if max_biters.amount >= max_biters.limit then
return false
@ -116,7 +115,7 @@ end
local function spawn_worms(data)
local modified_unit_health = WD.get('modified_unit_health')
local modified_boss_unit_health = WD.get('modified_boss_unit_health')
local max_biters = WPT.get('biters')
local max_biters = Public.get('biters')
if max_biters.amount >= max_biters.limit then
return
@ -237,7 +236,7 @@ local function on_tick()
this[t] = nil
end
function Public.reset()
function Public.reset_buried_biters()
for k, _ in pairs(this) do
this[k] = nil
end

View File

@ -1,7 +1,7 @@
local Color = require 'utils.color_presets'
local Public = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Server = require 'utils.server'
local WPT = require 'maps.mountain_fortress_v3.table'
local Collapse = require 'modules.collapse'
local WD = require 'modules.wave_defense.table'
@ -23,8 +23,7 @@ commands.add_command(
end
end
local this = WPT.get()
local reset_map = require 'maps.mountain_fortress_v3.main'.reset_map
local this = Public.get()
local param = cmd.parameter
if param == 'restart' or param == 'shutdown' or param == 'reset' or param == 'restartnow' then
@ -87,7 +86,7 @@ commands.add_command(
else
game.print(mapkeeper .. ' server, has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
end
reset_map()
Public.reset_map()
p('[WARNING] Game has been reset!')
return
end
@ -135,7 +134,7 @@ commands.add_command(
return
end
local this = WPT.get()
local this = Public.get()
local tbl = WD.get()
if not this.disable_biters_are_you_sure then
@ -170,7 +169,7 @@ commands.add_command(
return
end
local this = WPT.get()
local this = Public.get()
if not this.orbital_strikes_are_you_sure then
this.orbital_strikes_are_you_sure = true
@ -240,3 +239,5 @@ if _DEBUG then
end
)
end
return Public

View File

@ -0,0 +1,32 @@
local Public = require 'maps.mountain_fortress_v3.table'
Public.balance = require 'maps.mountain_fortress_v3.balance'
Public.basic_markets = require 'maps.mountain_fortress_v3.basic_markets'
Public.biters_yield_coins = require 'maps.mountain_fortress_v3.biters_yield_coins'
Public.breached_wall = require 'maps.mountain_fortress_v3.breached_wall'
Public.buried_enemies = require 'maps.mountain_fortress_v3.buried_enemies'
Public.commands = require 'maps.mountain_fortress_v3.commands'
Public.entities = require 'maps.mountain_fortress_v3.entities'
Public.functions = require 'maps.mountain_fortress_v3.functions'
Public.terrain = require 'maps.mountain_fortress_v3.terrain'
Public.generate = require 'maps.mountain_fortress_v3.generate'
Public.get_perlin = require 'maps.mountain_fortress_v3.get_perlin'
Public.gui = require 'maps.mountain_fortress_v3.gui'
-- Public.highscore = require 'maps.mountain_fortress_v3.highscore'
Public.locomotive = require 'maps.mountain_fortress_v3.locomotive'
Public.loot = require 'maps.mountain_fortress_v3.loot'
Public.mining = require 'maps.mountain_fortress_v3.mining'
Public.mystical_chest = require 'maps.mountain_fortress_v3.mystical_chest'
Public.resource_generator = require 'maps.mountain_fortress_v3.resource_generator'
Public.rocks_yield_ore_veins = require 'maps.mountain_fortress_v3.rocks_yield_ore_veins'
Public.soft_reset = require 'maps.mountain_fortress_v3.soft_reset'
Public.surface = require 'maps.mountain_fortress_v3.surface'
Public.traps = require 'maps.mountain_fortress_v3.traps'
Public.defense_system = require 'maps.mountain_fortress_v3.locomotive.defense_system'
Public.friendly_pet = require 'maps.mountain_fortress_v3.locomotive.friendly_pet'
Public.linked_chests = require 'maps.mountain_fortress_v3.locomotive.linked_chests'
Public.market = require 'maps.mountain_fortress_v3.locomotive.market'
Public.permission_groups = require 'maps.mountain_fortress_v3.locomotive.permission_groups'
Public.spawn_locomotive = require 'maps.mountain_fortress_v3.locomotive.spawn_locomotive'
return Public

View File

@ -1,39 +1,26 @@
require 'modules.rocks_broken_paint_tiles'
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Server = require 'utils.server'
local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies'
local Loot = require 'maps.mountain_fortress_v3.loot'
local RPG = require 'modules.rpg.main'
local Callbacks = require 'maps.mountain_fortress_v3.functions'
local Mining = require 'maps.mountain_fortress_v3.mining'
local Traps = require 'maps.mountain_fortress_v3.traps'
local Locomotive = require 'maps.mountain_fortress_v3.locomotive'
local DefenseSystem = require 'maps.mountain_fortress_v3.locomotive.defense_system'
local Collapse = require 'modules.collapse'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Score = require 'utils.gui.score'
local Token = require 'utils.token'
-- local HS = require 'maps.mountain_fortress_v3.highscore'
local Discord = require 'utils.discord'
local Core = require 'utils.core'
local Diff = require 'modules.difficulty_vote_by_amount'
local format_number = require 'util'.format_number
local RPG_Progression = require 'utils.datastore.rpg_data'
-- tables
local WPT = require 'maps.mountain_fortress_v3.table'
local WD = require 'modules.wave_defense.table'
local zone_settings = WPT.zone_settings
-- module
local Public = {}
local zone_settings = Public.zone_settings
local random = math.random
local floor = math.floor
local abs = math.abs
local round = math.round
local raise_event = script.raise_event
-- Use these settings for live
local send_ping_to_channel = Discord.channel_names.mtn_channel
@ -98,20 +85,20 @@ local reset_game =
function(data)
local this = data.this
if this.soft_reset then
-- HS.set_scores()
-- Public.set_scores()
this.game_reset_tick = nil
raise_event(WPT.events.reset_map, {})
Public.reset_map()
return
end
if this.restart then
-- HS.set_scores()
-- Public.set_scores()
local message = ({'entity.reset_game'})
Server.to_discord_bold(message, true)
Server.start_scenario('Mountain_Fortress_v3')
return
end
if this.shutdown then
-- HS.set_scores()
-- Public.set_scores()
local message = ({'entity.shutdown_game'})
Server.to_discord_bold(message, true)
Server.stop_scenario()
@ -141,7 +128,7 @@ end
local function on_entity_removed(data)
local entity = data.entity
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
local built = {
['land-mine'] = upgrades.landmine.built,
@ -164,11 +151,11 @@ local function on_entity_removed(data)
end
local function check_health()
local locomotive_health = WPT.get('locomotive_health')
local locomotive_max_health = WPT.get('locomotive_max_health')
local carriages = WPT.get('carriages')
local locomotive_health = Public.get('locomotive_health')
local locomotive_max_health = Public.get('locomotive_max_health')
local carriages = Public.get('carriages')
if locomotive_health <= 0 then
WPT.set('locomotive_health', 0)
Public.set('locomotive_health', 0)
end
local m = locomotive_health / locomotive_max_health
if carriages then
@ -188,7 +175,7 @@ local function check_health()
end
local function check_health_final_damage(final_damage_amount)
local carriages = WPT.get('carriages')
local carriages = Public.get('carriages')
if carriages then
for i = 1, #carriages do
local entity = carriages[i]
@ -205,17 +192,17 @@ local function set_train_final_health(final_damage_amount, repair)
return
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not (locomotive and locomotive.valid) then
return
end
local locomotive_health = WPT.get('locomotive_health')
local locomotive_max_health = WPT.get('locomotive_max_health')
local locomotive_health = Public.get('locomotive_health')
local locomotive_max_health = Public.get('locomotive_max_health')
if not repair then
local poison_deployed = WPT.get('poison_deployed')
local robotics_deployed = WPT.get('robotics_deployed')
local poison_deployed = Public.get('poison_deployed')
local robotics_deployed = Public.get('robotics_deployed')
local lower_high = locomotive_max_health * 0.4
local higher_high = locomotive_max_health * 0.5
@ -224,12 +211,12 @@ local function set_train_final_health(final_damage_amount, repair)
if locomotive_health >= lower_high and locomotive_health <= higher_high then
if not poison_deployed then
local carriages = WPT.get('carriages')
local carriages = Public.get('carriages')
if carriages then
for i = 1, #carriages do
local entity = carriages[i]
DefenseSystem.enable_poison_defense(entity.position)
Public.enable_poison_defense(entity.position)
end
end
@ -238,16 +225,16 @@ local function set_train_final_health(final_damage_amount, repair)
}
local msg = ({'entity.train_taking_damage'})
Alert.alert_all_players_location(p, msg)
WPT.set().poison_deployed = true
Public.set().poison_deployed = true
end
elseif locomotive_health >= lower_low and locomotive_health <= higher_low then
if not robotics_deployed then
local carriages = WPT.get('carriages')
local carriages = Public.get('carriages')
if carriages then
for i = 1, #carriages do
local entity = carriages[i]
DefenseSystem.enable_robotic_defense(entity.position)
Public.enable_robotic_defense(entity.position)
end
end
local p = {
@ -255,17 +242,17 @@ local function set_train_final_health(final_damage_amount, repair)
}
local msg = ({'entity.train_taking_damage'})
Alert.alert_all_players_location(p, msg)
WPT.set().robotics_deployed = true
Public.set().robotics_deployed = true
end
elseif locomotive_health >= locomotive_max_health then
WPT.set().poison_deployed = false
Public.set().poison_deployed = false
end
end
if locomotive_health <= 0 or locomotive.health <= 5 then
locomotive.destructible = false
locomotive.health = 1
WPT.set('game_lost', true)
Public.set('game_lost', true)
Public.loco_died()
end
@ -274,15 +261,15 @@ local function set_train_final_health(final_damage_amount, repair)
return
end
WPT.set('locomotive_health', floor(locomotive_health - final_damage_amount))
Public.set('locomotive_health', floor(locomotive_health - final_damage_amount))
if locomotive_health > locomotive_max_health then
WPT.set('locomotive_health', locomotive_max_health)
Public.set('locomotive_health', locomotive_max_health)
end
locomotive_health = WPT.get('locomotive_health')
locomotive_health = Public.get('locomotive_health')
check_health()
local health_text = WPT.get('health_text')
local health_text = Public.get('health_text')
rendering.set_text(health_text, 'HP: ' .. round(locomotive_health) .. ' / ' .. round(locomotive_max_health))
end
@ -297,7 +284,7 @@ local function protect_entities(data)
return
end
local check_heavy_damage = WPT.get('check_heavy_damage')
local check_heavy_damage = Public.get('check_heavy_damage')
if check_heavy_damage then
if entity.type == 'simple-entity' and dmg >= 500 then
@ -321,7 +308,7 @@ local function protect_entities(data)
return false
end
local carriages_numbers = WPT.get('carriages_numbers')
local carriages_numbers = Public.get('carriages_numbers')
if is_protected(entity) then
if (cause and cause.valid) then
if cause.force.index == 2 then
@ -360,12 +347,12 @@ local function hidden_treasure(player, entity)
if magic >= 50 then
local msg = rare_treasure_chest_messages[random(1, #rare_treasure_chest_messages)]
Alert.alert_player(player, 5, msg)
Loot.add_rare(entity.surface, entity.position, 'wooden-chest', magic)
Public.add_loot_rare(entity.surface, entity.position, 'wooden-chest', magic)
return
end
local msg = treasure_chest_messages[random(1, #treasure_chest_messages)]
Alert.alert_player(player, 5, msg, nil, nil, 0.3)
Loot.add(entity.surface, entity.position, chests[random(1, size_chests)])
Public.add_loot(entity.surface, entity.position, chests[random(1, size_chests)])
end
local function biters_chew_rocks_faster(data)
@ -400,10 +387,10 @@ local function angry_tree(entity, cause, player)
return
end
if random(1, 6) == 1 then
BuriedEnemies.buried_biter(entity.surface, entity.position)
Public.buried_biter(entity.surface, entity.position)
end
if random(1, 8) == 1 then
BuriedEnemies.buried_worm(entity.surface, entity.position)
Public.buried_worm(entity.surface, entity.position)
end
if random(1, 32) ~= 1 then
return
@ -420,8 +407,8 @@ local function angry_tree(entity, cause, player)
if player then
local forest_zone = RPG.get_value_from_player(player.index, 'forest_zone')
if forest_zone and random(1, 32) == 1 then
local cbl = Callbacks.refill_turret_callback
local data = {callback_data = Callbacks.piercing_rounds_magazine_ammo}
local cbl = Public.refill_turret_callback
local data = {callback_data = Public.piercing_rounds_magazine_ammo}
local e =
entity.surface.create_entity(
{
@ -430,8 +417,8 @@ local function angry_tree(entity, cause, player)
force = 'enemy'
}
)
if e.can_insert(Callbacks.piercing_rounds_magazine_ammo) then
e.insert(Callbacks.piercing_rounds_magazine_ammo)
if e.can_insert(Public.piercing_rounds_magazine_ammo) then
e.insert(Public.piercing_rounds_magazine_ammo)
end
local callback = Token.get(cbl)
callback(e, data)
@ -453,8 +440,8 @@ local function angry_tree(entity, cause, player)
end
local function give_coin(player)
local coin_amount = WPT.get('coin_amount')
local coin_override = WPT.get('coin_override')
local coin_amount = Public.get('coin_amount')
local coin_override = Public.get('coin_override')
local forest_zone = RPG.get_value_from_player(player.index, 'forest_zone')
if forest_zone then
@ -504,12 +491,12 @@ local mining_events = {
},
{
function(entity)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
BuriedEnemies.buried_biter(entity.surface, entity.position)
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
end,
4096,
@ -517,12 +504,12 @@ local mining_events = {
},
{
function(entity)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
BuriedEnemies.buried_biter(entity.surface, entity.position)
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
end,
512,
@ -530,12 +517,12 @@ local mining_events = {
},
{
function(entity)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
BuriedEnemies.buried_worm(entity.surface, entity.position)
Public.buried_worm(entity.surface, entity.position)
entity.destroy()
end,
2048,
@ -543,12 +530,12 @@ local mining_events = {
},
{
function(entity)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
Traps(entity.surface, entity.position)
Public.tick_tack_trap(entity.surface, entity.position)
entity.destroy()
end,
2048,
@ -556,7 +543,7 @@ local mining_events = {
},
{
function(entity, index)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
@ -629,7 +616,7 @@ local mining_events = {
},
{
function(entity, index)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
@ -649,7 +636,7 @@ local mining_events = {
},
{
function(entity, index)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
@ -678,7 +665,7 @@ local mining_events = {
},
{
function(entity)
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
@ -744,11 +731,11 @@ local function on_player_mined_entity(event)
return
end
local mined_scrap = WPT.get('mined_scrap')
local mined_scrap = Public.get('mined_scrap')
if entity.type == 'simple-entity' or entity.type == 'simple-entity-with-owner' or entity.type == 'tree' then
WPT.set().mined_scrap = mined_scrap + 1
Mining.on_player_mined_entity(event)
Public.set().mined_scrap = mined_scrap + 1
Public.on_player_mined_entity(event)
if entity.type == 'tree' then
if random(1, 3) == 1 then
give_coin(player)
@ -912,7 +899,7 @@ local function on_entity_damaged(event)
local wave_number = WD.get_wave()
local boss_wave_warning = WD.get_alert_boss_wave()
local munch_time = WPT.get('munch_time')
local munch_time = Public.get('munch_time')
local data = {
cause = cause,
@ -945,7 +932,7 @@ local function on_player_repaired_entity(event)
return
end
local entity = event.entity
local carriages_numbers = WPT.get('carriages_numbers')
local carriages_numbers = Public.get('carriages_numbers')
if carriages_numbers[entity.unit_number] then
local player = game.get_player(event.player_index)
@ -998,20 +985,20 @@ local function on_entity_died(event)
return
end
local biters_killed = WPT.get('biters_killed')
local biters = WPT.get('biters')
local biters_killed = Public.get('biters_killed')
local biters = Public.get('biters')
if entity.type == 'unit' or entity.type == 'unit-spawner' then
WPT.set().biters_killed = biters_killed + 1
Public.set().biters_killed = biters_killed + 1
biters.amount = biters.amount - 1
if biters.amount <= 0 then
biters.amount = 0
end
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
return
end
if random(1, 512) == 1 then
Traps(entity.surface, entity.position)
Public.tick_tack_trap(entity.surface, entity.position)
return
end
end
@ -1033,7 +1020,7 @@ local function on_entity_died(event)
return
end
end
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
return
end
angry_tree(entity, cause, player)
@ -1041,22 +1028,22 @@ local function on_entity_died(event)
end
if entity.type == 'simple-entity' then
if Locomotive.is_around_train(entity) then
if Public.is_around_train(entity) then
entity.destroy()
return
end
if random(1, 32) == 1 then
BuriedEnemies.buried_biter(entity.surface, entity.position)
Public.buried_biter(entity.surface, entity.position)
entity.destroy()
return
end
if random(1, 64) == 1 then
BuriedEnemies.buried_worm(entity.surface, entity.position)
Public.buried_worm(entity.surface, entity.position)
entity.destroy()
return
end
if random(1, 512) == 1 then
Traps(entity.surface, entity.position)
Public.tick_tack_trap(entity.surface, entity.position)
return
end
entity.destroy()
@ -1159,7 +1146,7 @@ local function show_mvps(player)
miners_label_text.style.font = 'default-bold'
miners_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local sent_to_discord = WPT.get('sent_to_discord')
local sent_to_discord = Public.get('sent_to_discord')
if not sent_to_discord then
local message = {
@ -1199,12 +1186,12 @@ local function show_mvps(player)
end
local time_played = Core.format_time(game.ticks_played)
local total_players = #game.players
local pickaxe_upgrades = WPT.pickaxe_upgrades
local upgrades = WPT.get('upgrades')
local pickaxe_upgrades = Public.pickaxe_upgrades
local upgrades = Public.get('upgrades')
local pick_tier = pickaxe_upgrades[upgrades.pickaxe_tier]
local server_name_matches = Server.check_server_name('Mtn Fortress')
if WPT.get('prestige_system_enabled') then
if Public.get('prestige_system_enabled') then
RPG_Progression.save_all_players()
end
local date = Server.get_start_time()
@ -1263,12 +1250,14 @@ local function show_mvps(player)
}
}
if server_name_matches then
Server.to_discord_named_parsed_embed(send_ping_to_channel, text)
if wave >= 1000 then
Server.to_discord_named_parsed_embed(send_ping_to_channel, text)
end
else
Server.to_discord_embed_parsed(text)
end
WPT.set('sent_to_discord', true)
Public.set('sent_to_discord', true)
end
end
end
@ -1282,19 +1271,20 @@ function Public.unstuck_player(index)
end
player.teleport(position, surface)
end
function Public.loco_died(invalid_locomotive)
local game_lost = WPT.get('game_lost')
local game_lost = Public.get('game_lost')
if not game_lost then
return
end
local announced_message = WPT.get('announced_message')
local announced_message = Public.get('announced_message')
if announced_message then
return
end
local active_surface_index = WPT.get('active_surface_index')
local locomotive = WPT.get('locomotive')
local active_surface_index = Public.get('active_surface_index')
local locomotive = Public.get('locomotive')
local surface = game.surfaces[active_surface_index]
local wave_defense_table = WD.get_table()
if wave_defense_table.game_lost and not invalid_locomotive then
@ -1308,7 +1298,7 @@ function Public.loco_died(invalid_locomotive)
end
if not locomotive.valid then
local this = WPT.get()
local this = Public.get()
local data = {}
if this.locomotive and this.locomotive.valid then
@ -1349,7 +1339,7 @@ function Public.loco_died(invalid_locomotive)
return
end
local this = WPT.get()
local this = Public.get()
this.locomotive_health = 0
this.locomotive.color = {0.49, 0, 255, 1}
@ -1428,7 +1418,7 @@ local function on_built_entity(event)
return
end
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
local upg = upgrades
local surface = entity.surface
@ -1524,7 +1514,7 @@ local function on_robot_built_entity(event)
return
end
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
local upg = upgrades
local surface = entity.surface

View File

@ -1,12 +1,12 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Task = require 'utils.task'
local Color = require 'utils.color_presets'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local Event = require 'utils.event'
local Global = require 'utils.global'
local Alert = require 'utils.alert'
local WPT = require 'maps.mountain_fortress_v3.table'
local WD = require 'modules.wave_defense.table'
local RPG = require 'modules.rpg.main'
local Collapse = require 'modules.collapse'
@ -16,7 +16,9 @@ local math2d = require 'math2d'
local Misc = require 'utils.commands.misc'
local Core = require 'utils.core'
local Beams = require 'modules.render_beam'
local zone_settings = WPT.zone_settings
local BottomFrame = require 'utils.gui.bottom_frame'
local zone_settings = Public.zone_settings
local this = {
power_sources = {index = 1},
@ -69,8 +71,6 @@ Global.register(
end
)
local Public = {}
local random = math.random
local floor = math.floor
local round = math.round
@ -100,7 +100,7 @@ local artillery_target_entities = {
}
local function debug_str(msg)
local debug = WPT.get('debug')
local debug = Public.get('debug')
if not debug then
return
end
@ -296,7 +296,7 @@ local artillery_target_callback =
)
local function difficulty_and_adjust_prices()
local fixed_prices = WPT.get('marked_fixed_prices')
local fixed_prices = Public.get('marked_fixed_prices')
local difficulty_index = Difficulty.get('index')
for index, price in pairs(fixed_prices) do
@ -310,7 +310,7 @@ end
local function do_beams_away()
local wave_number = WD.get_wave()
local orbital_strikes = WPT.get('orbital_strikes')
local orbital_strikes = Public.get('orbital_strikes')
if not orbital_strikes.enabled then
return
end
@ -327,7 +327,7 @@ local function do_beams_away()
end
if wave_number % wave_nth == 0 then
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.get_surface(active_surface_index)
if not orbital_strikes[wave_number] then
@ -751,7 +751,7 @@ end
local function calc_players()
local players = game.connected_players
local check_afk_players = WPT.get('check_afk_players')
local check_afk_players = Public.get('check_afk_players')
if not check_afk_players then
return #players
end
@ -849,7 +849,7 @@ local boost_movement_speed_on_respawn =
)
function Public.set_difficulty()
local game_lost = WPT.get('game_lost')
local game_lost = Public.get('game_lost')
if game_lost then
return
end
@ -858,13 +858,13 @@ function Public.set_difficulty()
return
end
local wave_defense_table = WD.get_table()
local check_if_threat_below_zero = WPT.get('check_if_threat_below_zero')
local collapse_amount = WPT.get('collapse_amount')
local collapse_speed = WPT.get('collapse_speed')
local difficulty = WPT.get('difficulty')
local mining_bonus_till_wave = WPT.get('mining_bonus_till_wave')
local mining_bonus = WPT.get('mining_bonus')
local disable_mining_boost = WPT.get('disable_mining_boost')
local check_if_threat_below_zero = Public.get('check_if_threat_below_zero')
local collapse_amount = Public.get('collapse_amount')
local collapse_speed = Public.get('collapse_speed')
local difficulty = Public.get('difficulty')
local mining_bonus_till_wave = Public.get('mining_bonus_till_wave')
local mining_bonus = Public.get('mining_bonus')
local disable_mining_boost = Public.get('disable_mining_boost')
local wave_number = WD.get_wave()
local player_count = calc_players()
@ -971,17 +971,17 @@ function Public.set_difficulty()
mining_bonus = 0 -- back to 0% with more than 11 players
end
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + mining_bonus
WPT.set('mining_bonus', mining_bonus) -- Setting mining_bonus globally so it remembers how much to reduce
Public.set('mining_bonus', mining_bonus) -- Setting mining_bonus globally so it remembers how much to reduce
else
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier - mining_bonus
WPT.set('disable_mining_boost', true)
Public.set('disable_mining_boost', true)
end
end
end
function Public.render_direction(surface)
local counter = WPT.get('soft_reset_counter')
local winter_mode = WPT.get('winter_mode')
local counter = Public.get('soft_reset_counter')
local winter_mode = Public.get('winter_mode')
local text = 'Welcome to Mountain Fortress v3!'
if winter_mode then
text = 'Welcome to Wintery Mountain Fortress v3!'
@ -1081,12 +1081,12 @@ function Public.render_direction(surface)
end
function Public.boost_difficulty()
local difficulty_set = WPT.get('difficulty_set')
local difficulty_set = Public.get('difficulty_set')
if difficulty_set then
return
end
local breached_wall = WPT.get('breached_wall')
local breached_wall = Public.get('breached_wall')
local difficulty = Difficulty.get()
if not difficulty then
@ -1102,51 +1102,51 @@ function Public.boost_difficulty()
local message = ({'main.diff_set', name})
local data = {
position = WPT.get('locomotive').position
position = Public.get('locomotive').position
}
Alert.alert_all_players_location(data, message)
local force = game.forces.player
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.get_surface(active_surface_index)
if index == 1 then
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 0.5
force.character_running_speed_modifier = 0.15
force.manual_crafting_speed_modifier = 0.15
WPT.set('coin_amount', 1)
WPT.set('upgrades').flame_turret.limit = 12
WPT.set('upgrades').landmine.limit = 50
WPT.set('locomotive_health', 10000)
WPT.set('locomotive_max_health', 10000)
WPT.set('bonus_xp_on_join', 500)
Public.set('coin_amount', 1)
Public.set('upgrades').flame_turret.limit = 12
Public.set('upgrades').landmine.limit = 50
Public.set('locomotive_health', 10000)
Public.set('locomotive_max_health', 10000)
Public.set('bonus_xp_on_join', 500)
WD.set('next_wave', game.tick + 3600 * 15)
WPT.set('spidertron_unlocked_at_zone', 10)
Public.set('spidertron_unlocked_at_zone', 10)
WD.set_normal_unit_current_health(1.0)
WD.set_unit_health_increment_per_wave(0.15)
WD.set_boss_unit_current_health(2)
WD.set_boss_health_increment_per_wave(1.5)
WD.set('death_mode', false)
WPT.set('difficulty_set', true)
Public.set('difficulty_set', true)
elseif index == 2 then
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 0.25
force.character_running_speed_modifier = 0.1
force.manual_crafting_speed_modifier = 0.1
WPT.set('coin_amount', 2)
WPT.set('upgrades').flame_turret.limit = 10
WPT.set('upgrades').landmine.limit = 50
WPT.set('locomotive_health', 7000)
WPT.set('locomotive_max_health', 7000)
WPT.set('bonus_xp_on_join', 300)
Public.set('coin_amount', 2)
Public.set('upgrades').flame_turret.limit = 10
Public.set('upgrades').landmine.limit = 50
Public.set('locomotive_health', 7000)
Public.set('locomotive_max_health', 7000)
Public.set('bonus_xp_on_join', 300)
WD.set('next_wave', game.tick + 3600 * 8)
WPT.set('spidertron_unlocked_at_zone', 8)
WD.set_normal_unit_current_health(1.6)
WD.set_unit_health_increment_per_wave(0.5)
Public.set('spidertron_unlocked_at_zone', 8)
WD.set_normal_unit_current_health(1.4)
WD.set_unit_health_increment_per_wave(0.3)
WD.set_boss_unit_current_health(3)
WD.set_boss_health_increment_per_wave(5)
WD.set_boss_health_increment_per_wave(3)
WD.set('death_mode', false)
WPT.set('difficulty_set', true)
Public.set('difficulty_set', true)
local damage_warning = ({'main.damage_mode_warning'})
Alert.alert_all_players_location(data, damage_warning)
Core.iter_players(
@ -1160,12 +1160,12 @@ function Public.boost_difficulty()
end
end
)
local upgrades = WPT.get('upgrades')
if WPT.get('circle') then
rendering.destroy(WPT.get('circle'))
local upgrades = Public.get('upgrades')
if Public.get('circle') then
rendering.destroy(Public.get('circle'))
end
local locomotive = WPT.get('locomotive')
WPT.set(
local locomotive = Public.get('locomotive')
Public.set(
'circle',
rendering.draw_circle {
surface = active_surface_index,
@ -1180,20 +1180,20 @@ function Public.boost_difficulty()
elseif index == 3 then
force.character_running_speed_modifier = 0
force.manual_crafting_speed_modifier = 0
WPT.set('coin_amount', 4)
WPT.set('upgrades').flame_turret.limit = 3
WPT.set('upgrades').landmine.limit = 10
WPT.set('locomotive_health', 5000)
WPT.set('locomotive_max_health', 5000)
WPT.set('bonus_xp_on_join', 50)
Public.set('coin_amount', 4)
Public.set('upgrades').flame_turret.limit = 3
Public.set('upgrades').landmine.limit = 10
Public.set('locomotive_health', 5000)
Public.set('locomotive_max_health', 5000)
Public.set('bonus_xp_on_join', 50)
WD.set('next_wave', game.tick + 3600 * 5)
WPT.set('spidertron_unlocked_at_zone', 6)
WD.set_normal_unit_current_health(2)
WD.set_unit_health_increment_per_wave(1)
Public.set('spidertron_unlocked_at_zone', 6)
WD.set_normal_unit_current_health(1.6)
WD.set_unit_health_increment_per_wave(0.5)
WD.set_boss_unit_current_health(4)
WD.set_boss_health_increment_per_wave(10)
WD.set_boss_health_increment_per_wave(6)
WD.set('death_mode', true)
WPT.set('difficulty_set', true)
Public.set('difficulty_set', true)
Core.iter_players(
function(player)
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5)
@ -1205,13 +1205,14 @@ function Public.boost_difficulty()
end
end
)
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
upgrades.locomotive_aura_radius = upgrades.locomotive_aura_radius + 20
if WPT.get('circle') then
rendering.destroy(WPT.get('circle'))
upgrades.aura_upgrades_max = upgrades.aura_upgrades_max - 4
if Public.get('circle') then
rendering.destroy(Public.get('circle'))
end
local locomotive = WPT.get('locomotive')
WPT.set(
local locomotive = Public.get('locomotive')
Public.set(
'circle',
rendering.draw_circle {
surface = active_surface_index,
@ -1232,7 +1233,7 @@ end
function Public.set_spawn_position()
local collapse_pos = Collapse.get_position()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
@ -1258,17 +1259,17 @@ function Public.set_spawn_position()
::retry::
local y_value_position = WPT.get('y_value_position')
local locomotive_positions = WPT.get('locomotive_pos')
local y_value_position = Public.get('y_value_position')
local locomotive_positions = Public.get('locomotive_pos')
local total_pos = #locomotive_positions.tbl
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if not (surface and surface.valid) then
return
end
local spawn_near_collapse = WPT.get('spawn_near_collapse')
local spawn_near_collapse = Public.get('spawn_near_collapse')
if spawn_near_collapse.active then
local collapse_position = surface.find_non_colliding_position('rocket-silo', collapse_pos, 64, 2)
@ -1343,8 +1344,8 @@ function Public.set_spawn_position()
end
function Public.on_player_joined_game(event)
local active_surface_index = WPT.get('active_surface_index')
local players = WPT.get('players')
local active_surface_index = Public.get('active_surface_index')
local players = Public.get('players')
local player = game.players[event.player_index]
local surface = game.surfaces[active_surface_index]
@ -1358,7 +1359,7 @@ function Public.on_player_joined_game(event)
end
local message = ({'main.greeting', player.name})
Alert.alert_player(player, 15, message)
if WPT.get('death_mode') then
if Public.get('death_mode') then
local death_message = ({'main.death_mode_warning'})
Alert.alert_player(player, 15, death_message)
end
@ -1388,7 +1389,7 @@ function Public.on_player_joined_game(event)
end
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
@ -1431,11 +1432,19 @@ function Public.on_player_respawned(event)
end
function Public.on_player_changed_position(event)
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
if not active_surface_index then
return
end
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
if player.controller_type == defines.controllers.spectator then
return
end
local map_name = 'mtn_v3'
if string.sub(player.surface.name, 0, #map_name) ~= map_name then
@ -1446,7 +1455,7 @@ function Public.on_player_changed_position(event)
local surface = game.surfaces[active_surface_index]
local p = {x = player.position.x, y = player.position.y}
local config_tile = WPT.get('void_or_tile')
local config_tile = Public.get('void_or_tile')
if config_tile == 'lab-dark-2' then
local get_tile = surface.get_tile(p)
if get_tile.valid and get_tile.name == 'lab-dark-2' then
@ -1528,7 +1537,7 @@ function Public.on_research_finished(event)
local technology_prototypes = game.technology_prototypes
if WPT.get('print_tech_to_discord') and force.name == 'player' then
if Public.get('print_tech_to_discord') and force.name == 'player' then
Server.to_discord_bold({'functions.researched_complete', technology_prototypes[research_name].localised_name}, true)
end
@ -1547,7 +1556,7 @@ function Public.on_research_finished(event)
if not force_name then
return
end
local flamethrower_damage = WPT.get('flamethrower_damage')
local flamethrower_damage = Public.get('flamethrower_damage')
flamethrower_damage[force_name] = -0.85
if research.name == 'military' then
game.forces[force_name].set_turret_attack_modifier('flamethrower-turret', flamethrower_damage[force_name])
@ -1561,6 +1570,89 @@ function Public.on_research_finished(event)
end
end
function Public.set_player_to_god(player)
if player.character and player.character.valid then
return false
end
if not player.character and player.controller_type ~= defines.controllers.spectator then
player.print('[color=blue][Spectate][/color] It seems that you are not in the realm of the living.', Color.warning)
return false
end
local spectate = Public.get('spectate')
if spectate[player.index] and spectate[player.index].delay and spectate[player.index].delay > game.tick then
local cooldown = floor((spectate[player.index].delay - game.tick) / 60) + 1 .. ' seconds!'
player.print('[color=blue][Spectate][/color] Retry again in ' .. cooldown, Color.warning)
return false
end
spectate[player.index] = nil
player.set_controller({type = defines.controllers.god})
player.create_character()
local active_surface_index = Public.get('active_surface_index')
local surface = game.get_surface(active_surface_index)
if not surface or not surface.valid then
return false
end
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5)
if pos then
player.teleport(pos, surface)
else
pos = game.forces.player.get_spawn_position(surface)
player.teleport(pos, surface)
end
Event.raise(
BottomFrame.events.bottom_quickbar_respawn_raise,
{
player_index = player.index
}
)
player.tag = ''
game.print('[color=blue][Spectate][/color] ' .. player.name .. ' is no longer spectating!')
Server.to_discord_bold(table.concat {'*** ', '[Spectate] ' .. player.name .. ' is no longer spectating!', ' ***'})
return true
end
function Public.set_player_to_spectator(player)
if player.in_combat then
player.print('[color=blue][Spectate][/color] You are in combat. Try again soon.', Color.warning)
return false
end
local spectate = Public.get('spectate')
if not spectate[player.index] then
spectate[player.index] = {
verify = false
}
player.print('[color=blue][Spectate][/color] Please click the spectate button again if you really want to this.', Color.warning)
return false
end
if player.character and player.character.valid then
player.character.die()
end
player.character = nil
player.spectator = true
player.tag = '[Spectator]'
player.set_controller({type = defines.controllers.spectator})
game.print('[color=blue][Spectate][/color] ' .. player.name .. ' is now spectating.')
Server.to_discord_bold(table.concat {'*** ', '[Spectate] ' .. player.name .. ' is now spectating.', ' ***'})
if spectate[player.index] and not spectate[player.index].delay then
spectate[player.index].verify = true
spectate[player.index].delay = game.tick + 18000
end
return true
end
Public.firearm_magazine_ammo = {name = 'firearm-magazine', count = 200}
Public.piercing_rounds_magazine_ammo = {name = 'piercing-rounds-magazine', count = 200}
Public.uranium_rounds_magazine_ammo = {name = 'uranium-rounds-magazine', count = 200}
@ -1568,7 +1660,7 @@ Public.light_oil_ammo = {name = 'light-oil', amount = 100}
Public.artillery_shell_ammo = {name = 'artillery-shell', count = 15}
Public.laser_turrent_power_source = {buffer_size = 2400000, power_production = 40000}
function Public.reset_table()
function Public.reset_func_table()
this.power_sources = {index = 1}
this.refill_turrets = {index = 1}
this.magic_crafters = {index = 1}

View File

@ -1,15 +1,10 @@
local Market = require 'maps.mountain_fortress_v3.basic_markets'
local WPT = require 'maps.mountain_fortress_v3.table'
local Loot = require 'maps.mountain_fortress_v3.loot'
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Event = require 'utils.event'
local Terrain = require 'maps.mountain_fortress_v3.terrain'
local WD = require 'modules.wave_defense.table'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local Public = {}
local random = math.random
local abs = math.abs
local ceil = math.ceil
@ -18,7 +13,8 @@ local queue_task = Task.queue_task
local tiles_per_call = 8
local total_calls = ceil(1024 / tiles_per_call)
local regen_decoratives = false
local generate_map = Terrain.heavy_functions
local generate_map = Public.heavy_functions
local winter_mode = false
local wintery_type = {
['simple-entity'] = true,
@ -211,7 +207,7 @@ local function do_place_treasure(data)
if random(1, 6) == 1 then
e.chest = 'iron-chest'
end
Loot.add(surface, e.position, e.chest)
Public.add_loot(surface, e.position, e.chest)
end
end
@ -231,7 +227,7 @@ local function do_place_markets(data)
limit = 1
} == 0
then
local market = Market.mountain_market(surface, pos, abs(pos.y) * 0.004)
local market = Public.mountain_market(surface, pos, abs(pos.y) * 0.004)
market.destructible = false
end
end
@ -618,11 +614,12 @@ local do_chunk = Public.do_chunk
local schedule_chunk = Public.schedule_chunk
local function on_chunk(event)
local force_chunk = WPT.get('force_chunk')
local stop_chunk = WPT.get('stop_chunk')
local force_chunk = Public.get('force_chunk')
local stop_chunk = Public.get('stop_chunk')
if stop_chunk then
return
end
if force_chunk then
do_chunk(event)
else

View File

@ -1,3 +1,4 @@
local Public = require 'maps.mountain_fortress_v3.table'
local simplex_noise = require 'utils.simplex_noise'.d2
--add or use noise templates from here
@ -125,7 +126,7 @@ local noises = {
}
--returns a float number between -1 and 1
local function get_noise(name, pos, seed)
function Public.get_noise(name, pos, seed)
local noise = 0
local d = 0
for i = 1, #noises[name] do
@ -138,4 +139,4 @@ local function get_noise(name, pos, seed)
return noise
end
return get_noise
return Public

View File

@ -1,6 +1,6 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local IC_Gui = require 'maps.mountain_fortress_v3.ic.gui'
local IC_Minimap = require 'maps.mountain_fortress_v3.ic.minimap'
local Difficulty = require 'modules.difficulty_vote_by_amount'
@ -9,10 +9,8 @@ local SpamProtection = require 'utils.spam_protection'
local format_number = require 'util'.format_number
local Public = {}
Public.events = {reset_map = Event.generate_event_name('reset_map')}
local main_button_name = Gui.uid_name()
local spectate_button_name = Gui.uid_name()
local main_frame_name = Gui.uid_name()
local floor = math.floor
@ -57,6 +55,22 @@ local function create_button(player)
b.style.maximal_height = 38
end
local function spectate_button(player)
if player.gui.top[spectate_button_name] then
return
end
local b =
player.gui.top.add {
type = 'sprite-button',
name = spectate_button_name,
sprite = 'utility/ghost_time_to_live_modifier_icon',
tooltip = 'Spectate!\nThis will kill your character.'
}
b.style.maximal_height = 38
end
local function create_main_frame(player)
local label
local line
@ -127,7 +141,7 @@ local function create_main_frame(player)
line.style.left_padding = 4
line.style.right_padding = 4
label = frame.add({type = 'label', caption = ' ', name = 'train_upgrades'})
label = frame.add({type = 'label', caption = ' ', name = 'train_upgrade_contribution'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.right_padding = 4
@ -142,6 +156,22 @@ local function create_main_frame(player)
label.style.right_padding = 4
end
local function hide_all_gui(player)
for _, child in pairs(player.gui.top.children) do
if child.name ~= spectate_button_name then
child.visible = false
end
end
end
local function show_all_gui(player)
for _, child in pairs(player.gui.top.children) do
if child.name ~= spectate_button_name then
child.visible = true
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if not player then
@ -151,6 +181,10 @@ local function on_player_joined_game(event)
if not player.gui.top[main_button_name] then
create_button(player)
end
if not player.gui.top[spectate_button_name] then
spectate_button(player)
end
end
local function on_gui_click(event)
@ -171,7 +205,7 @@ local function on_gui_click(event)
return
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not validate_entity(locomotive) then
return
end
@ -249,11 +283,12 @@ local function on_player_changed_surface(event)
local rpg_button = RPG.draw_main_frame_name
local rpg_frame = RPG.main_frame_name
local rpg_settings = RPG.settings_frame_name
local main = WPT.get('locomotive')
local icw_locomotive = WPT.get('icw_locomotive')
local main = Public.get('locomotive')
local icw_locomotive = Public.get('icw_locomotive')
local wagon_surface = icw_locomotive.surface
local info = player.gui.top[main_button_name]
local wd = player.gui.top['wave_defense']
local spectate = player.gui.top[spectate_button_name]
local rpg_b = player.gui.top[rpg_button]
local rpg_f = player.gui.screen[rpg_frame]
local rpg_s = player.gui.screen[rpg_settings]
@ -299,6 +334,9 @@ local function on_player_changed_surface(event)
if wd and not wd.visible then
wd.visible = true
end
if spectate and not spectate.visible then
spectate.visible = true
end
if charging and not charging.visible then
charging.visible = true
end
@ -311,6 +349,9 @@ local function on_player_changed_surface(event)
if wd then
wd.visible = false
end
if spectate then
spectate.visible = false
end
if rpg_b then
rpg_b.visible = false
end
@ -356,6 +397,7 @@ local function enable_guis(event)
local rpg_button = RPG.draw_main_frame_name
local info = player.gui.top[main_button_name]
local wd = player.gui.top['wave_defense']
local spectate = player.gui.top[spectate_button_name]
local rpg_b = player.gui.top[rpg_button]
local diff = player.gui.top[Difficulty.top_button_name]
local charging = player.gui.top['charging_station']
@ -382,6 +424,9 @@ local function enable_guis(event)
if wd and not wd.visible then
wd.visible = true
end
if spectate and not spectate.visible then
spectate.visible = true
end
if charging and not charging.visible then
charging.visible = true
end
@ -407,9 +452,9 @@ function Public.update_gui(player)
local gui = player.gui.top[main_frame_name]
local rpg_extra = RPG.get('rpg_extra')
local mined_scrap = WPT.get('mined_scrap')
local biters_killed = WPT.get('biters_killed')
local upgrades = WPT.get('upgrades')
local mined_scrap = Public.get('mined_scrap')
local biters_killed = Public.get('biters_killed')
local upgrades = Public.get('upgrades')
if rpg_extra.global_pool == 0 then
gui.global_pool.caption = 'XP: 0'
@ -422,9 +467,13 @@ function Public.update_gui(player)
gui.scrap_mined.caption = ' [img=entity.tree-01][img=entity.rock-huge]: ' .. format_number(mined_scrap, true)
gui.scrap_mined.tooltip = ({'gui.amount_harvested'})
local pickaxe_upgrades = WPT.pickaxe_upgrades
local pickaxe_upgrades = Public.pickaxe_upgrades
local pick_tier = pickaxe_upgrades[upgrades.pickaxe_tier]
local speed = math.round((player.force.manual_mining_speed_modifier + player.character_mining_speed_modifier + 1) * 100)
local train_upgrade_contribution = upgrades.train_upgrade_contribution
if upgrades.train_upgrade_contribution > 0 then
train_upgrade_contribution = upgrades.train_upgrade_contribution / 1000
end
gui.pickaxe_tier.caption = ' [img=item.dummy-steel-axe]: ' .. pick_tier .. ' (' .. upgrades.pickaxe_tier .. ')'
gui.pickaxe_tier.tooltip = ({'gui.current_pickaxe_tier', pick_tier, speed})
@ -438,8 +487,8 @@ function Public.update_gui(player)
gui.flame_turret.caption = ' [img=entity.flamethrower-turret]: ' .. format_number(upgrades.flame_turret.built, true) .. ' / ' .. format_number(upgrades.flame_turret.limit, true)
gui.flame_turret.tooltip = ({'gui.flamethrowers_placed'})
gui.train_upgrades.caption = ' [img=entity.locomotive]: ' .. format_number(upgrades.train_upgrades, true)
gui.train_upgrades.tooltip = ({'gui.train_upgrades'})
gui.train_upgrade_contribution.caption = ' [img=entity.locomotive]: ' .. train_upgrade_contribution .. 'k'
gui.train_upgrade_contribution.tooltip = ({'gui.train_upgrade_contribution'})
gui.chest_upgrades.caption = ' [img=entity.steel-chest]: ' .. format_number(upgrades.chests_outside_upgrades, true)
gui.chest_upgrades.tooltip = ({'gui.chest_placed'})
@ -450,4 +499,31 @@ Event.add(defines.events.on_player_changed_surface, on_player_changed_surface)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(Public.events.reset_map, enable_guis)
Gui.on_click(
spectate_button_name,
function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Mtn v3 Spectate Button')
if is_spamming then
return
end
local player = event.player
if not player or not player.valid then
return
end
if player.character and player.character.valid then
local success = Public.set_player_to_spectator(player)
if success then
hide_all_gui(player)
end
else
local success = Public.set_player_to_god(player)
if success then
show_all_gui(player)
end
end
end
)
return Public

View File

@ -1,10 +1,10 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Global = require 'utils.global'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Gui = require 'utils.gui'
local Score = require 'utils.gui.score'
local WPT = require 'maps.mountain_fortress_v3.table'
local WD = require 'modules.wave_defense.table'
local Core = require 'utils.core'
local SpamProtection = require 'utils.spam_protection'
@ -15,7 +15,6 @@ local score_key = 'mountain_fortress_v3_scores'
local set_data = Server.set_data
local try_get_data = Server.try_get_data
local Public = {}
local insert = table.insert
local random = math.random
local this = {
@ -291,7 +290,7 @@ end
local function write_additional_stats(key, difficulty)
local player = game.forces.player
local new_breached_zone = WPT.get('breached_wall')
local new_breached_zone = Public.get('breached_wall')
local new_wave_number = WD.get('wave_number')
local new_biters_killed = get_total_biter_killcount(player)
local new_rockets_launched = player.rockets_launched

View File

@ -10,7 +10,6 @@ local Event = require 'utils.event'
local Public = {}
local main_tile_name = 'black-refined-concrete'
local raise_event = script.raise_event
local round = math.round
local floor = math.floor
@ -140,7 +139,7 @@ local function get_entity_from_player_surface(cars, player)
end
local function get_owner_car_surface(cars, player, target)
for k, car in pairs(cars) do
for _, car in pairs(cars) do
if car.owner == player.index then
local surface_index = car.surface
local surface = game.surfaces[surface_index]
@ -173,7 +172,7 @@ end
local function get_player_entity(player)
local cars = IC.get('cars')
for k, car in pairs(cars) do
for _, car in pairs(cars) do
if car.owner == player.index and type(car.entity) == 'boolean' then
return car.name, true
elseif car.owner == player.index then
@ -187,7 +186,7 @@ local function get_owner_car_name(player)
local cars = IC.get('cars')
local saved_surfaces = IC.get('saved_surfaces')
local index = saved_surfaces[player.index]
for k, car in pairs(cars) do
for _, car in pairs(cars) do
if not index then
return false
end
@ -819,6 +818,10 @@ function Public.kill_car(entity)
local renders = IC.get('renders')
if not owner then
return
end
if renders[owner.index] then
rendering.destroy(renders[owner.index])
renders[owner.index] = nil
@ -892,6 +895,10 @@ function Public.kill_car_but_save_surface(entity)
end
end
if not owner then
return
end
local renders = IC.get('renders')
if renders[owner.index] then
@ -1246,7 +1253,7 @@ function Public.use_door_with_entity(player, door)
local surface_index = car.surface
local surface = game.surfaces[surface_index]
if validate_entity(car.entity) and car.owner == player.index then
raise_event(
Event.raise(
IC.events.used_car_door,
{
player = player,
@ -1277,7 +1284,7 @@ function Public.use_door_with_entity(player, door)
player_data.surface = surface.index
else
if validate_entity(car.entity) and car.owner == player.index then
raise_event(
Event.raise(
IC.events.used_car_door,
{
player = player,

View File

@ -31,7 +31,6 @@ local auto_upgrade_name = Gui.uid_name()
local kick_player_name = Gui.uid_name()
local destroy_surface_name = Gui.uid_name()
local raise_event = script.raise_event
local add_toolbar
local remove_toolbar
@ -869,7 +868,7 @@ Gui.on_click(
if player_list.players[name] then
player.print('[IC] ' .. name .. ' was removed from your vehicle.', Color.info)
decrement(player_list.players, name)
raise_event(
Event.raise(
ICT.events.on_player_kicked_from_surface,
{
player = player,

View File

@ -199,52 +199,6 @@ local function input_filtered(wagon_inventory, chest, chest_inventory, free_slot
end
end
local remove_lights_token =
Token.register(
function(data)
local id = data.id
if id then
rendering.destroy(id)
end
end
)
function Public.glimpse_of_lights()
local surface = WPT.get('loco_surface')
if not surface or not surface.valid then
return
end
local icw = ICW.get()
local hazardous_debris = icw.hazardous_debris
if not hazardous_debris then
return
end
local text = rendering.draw_text
local position = fallout_debris[random(1, size_of_debris)]
local p = {x = position[1], y = position[2]}
local get_tile = surface.get_tile(p)
if get_tile.valid and get_tile.name == 'out-of-map' then
local id =
text {
text = '',
surface = surface,
target = position,
color = {r = 1, g = 1, b = 0},
orientation = random(0, 100) * 0.01,
scale = 0.4,
font = 'heading-1',
alignment = 'center',
scale_with_zoom = false
}
Task.set_timeout_in_ticks(300, remove_lights_token, {id = id})
end
end
function Public.hazardous_debris()
local surface = WPT.get('loco_surface')
if not surface or not surface.valid then

View File

@ -96,7 +96,6 @@ local function on_tick()
if tick % 10 == 0 then
Functions.item_transfer()
Functions.hazardous_debris()
-- Functions.glimpse_of_lights()
end
if tick % 240 == 0 then
Functions.update_minimap()

View File

@ -12,7 +12,7 @@ local Public = {}
function Public.reset()
if this.surfaces then
for k, surface in pairs(this.surfaces) do
for _, surface in pairs(this.surfaces) do
if surface and surface.valid then
game.delete_surface(surface)
end

View File

@ -1,17 +1,12 @@
local Event = require 'utils.event'
local Market = require 'maps.mountain_fortress_v3.basic_markets'
local LocomotiveMarket = require 'maps.mountain_fortress_v3.locomotive.market'
local Public = require 'maps.mountain_fortress_v3.table'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local ICFunctions = require 'maps.mountain_fortress_v3.ic.functions'
local Session = require 'utils.datastore.session_data'
local Difficulty = require 'modules.difficulty_vote_by_amount'
local RPG = require 'modules.rpg.main'
local Gui = require 'utils.gui'
local Alert = require 'utils.alert'
local PermissionGroups = require 'maps.mountain_fortress_v3.locomotive.permission_groups'
local Public = {}
local rpg_main_frame = RPG.main_frame_name
local random = math.random
@ -40,8 +35,8 @@ local non_valid_vehicles = {
}
local function add_random_loot_to_main_market(rarity)
local main_market_items = WPT.get('main_market_items')
local items = Market.get_random_item(rarity, true, false)
local main_market_items = Public.get('main_market_items')
local items = Public.get_random_item(rarity, true, false)
if not items then
return false
end
@ -118,7 +113,7 @@ local function hurt_players_outside_of_aura()
if not Diff then
return
end
local difficulty_set = WPT.get('difficulty_set')
local difficulty_set = Public.get('difficulty_set')
if not difficulty_set then
return
end
@ -129,14 +124,14 @@ local function hurt_players_outside_of_aura()
death_mode = true
end
local loco_surface = WPT.get('loco_surface')
local loco_surface = Public.get('loco_surface')
if not (loco_surface and loco_surface.valid) then
return
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
local loco = locomotive.position
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
local players = game.connected_players
for i = 1, #players do
@ -207,12 +202,12 @@ end
local function give_passive_xp(data)
local xp_floating_text_color = {r = 188, g = 201, b = 63}
local visuals_delay = 1800
local loco_surface = WPT.get('loco_surface')
local loco_surface = Public.get('loco_surface')
if not (loco_surface and loco_surface.valid) then
return
end
local upgrades = WPT.get('upgrades')
local locomotive = WPT.get('locomotive')
local upgrades = Public.get('upgrades')
local locomotive = Public.get('locomotive')
local rpg = data.rpg
local loco = locomotive.position
@ -225,12 +220,12 @@ local function give_passive_xp(data)
if player.afk_time < 200 and not RPG.get_last_spell_cast(player) then
if inside or player.surface.index == loco_surface.index then
if player.surface.index == loco_surface.index then
PermissionGroups.add_player_to_permission_group(player, 'limited')
Public.add_player_to_permission_group(player, 'limited')
elseif ICFunctions.get_player_surface(player) then
PermissionGroups.add_player_to_permission_group(player, 'limited')
Public.add_player_to_permission_group(player, 'limited')
goto pre_exit
else
PermissionGroups.add_player_to_permission_group(player, 'near_locomotive')
Public.add_player_to_permission_group(player, 'near_locomotive')
end
local pos = player.position
@ -254,11 +249,11 @@ local function give_passive_xp(data)
end
end
else
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
if surface and surface.valid then
if player.surface.index == surface.index then
PermissionGroups.add_player_to_permission_group(player, 'main_surface')
Public.add_player_to_permission_group(player, 'main_surface')
end
end
end
@ -268,7 +263,7 @@ local function give_passive_xp(data)
end
local function fish_tag()
local locomotive_cargo = WPT.get('locomotive_cargo')
local locomotive_cargo = Public.get('locomotive_cargo')
if not (locomotive_cargo and locomotive_cargo.valid) then
return
end
@ -276,7 +271,7 @@ local function fish_tag()
return
end
local locomotive_tag = WPT.get('locomotive_tag')
local locomotive_tag = Public.get('locomotive_tag')
if locomotive_tag then
if locomotive_tag.valid then
@ -286,7 +281,7 @@ local function fish_tag()
locomotive_tag.destroy()
end
end
WPT.set(
Public.set(
'locomotive_tag',
locomotive_cargo.force.add_chart_tag(
locomotive_cargo.surface,
@ -300,7 +295,7 @@ local function fish_tag()
end
local function set_player_spawn()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end
@ -316,7 +311,7 @@ local function set_player_spawn()
end
local function refill_fish()
local locomotive_cargo = WPT.get('locomotive_cargo')
local locomotive_cargo = Public.get('locomotive_cargo')
if not locomotive_cargo then
return
end
@ -327,7 +322,7 @@ local function refill_fish()
end
local function set_carriages()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
@ -345,8 +340,8 @@ local function set_carriages()
end
end
WPT.set('carriages_numbers', t)
WPT.set('carriages', locomotive.train.carriages)
Public.set('carriages_numbers', t)
Public.set('carriages', locomotive.train.carriages)
end
local function get_driver_action(entity)
@ -388,17 +383,17 @@ local function get_driver_action(entity)
end
local function set_locomotive_health()
local locomotive_health = WPT.get('locomotive_health')
local locomotive_max_health = WPT.get('locomotive_max_health')
local locomotive = WPT.get('locomotive')
local locomotive_health = Public.get('locomotive_health')
local locomotive_max_health = Public.get('locomotive_max_health')
local locomotive = Public.get('locomotive')
local function check_health()
local m = locomotive_health / locomotive_max_health
if locomotive_health > locomotive_max_health then
WPT.set('locomotive_health', locomotive_max_health)
Public.set('locomotive_health', locomotive_max_health)
end
rendering.set_text(WPT.get('health_text'), 'HP: ' .. round(locomotive_health) .. ' / ' .. round(locomotive_max_health))
local carriages = WPT.get('carriages')
rendering.set_text(Public.get('health_text'), 'HP: ' .. round(locomotive_health) .. ' / ' .. round(locomotive_max_health))
local carriages = Public.get('carriages')
if carriages then
for i = 1, #carriages do
local entity = carriages[i]
@ -424,7 +419,7 @@ local function set_locomotive_health()
end
local function validate_index()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end
@ -433,12 +428,12 @@ local function validate_index()
end
local icw_table = ICW.get_table()
local icw_locomotive = WPT.get('icw_locomotive')
local icw_locomotive = Public.get('icw_locomotive')
local loco_surface = icw_locomotive.surface
local unit_surface = locomotive.unit_number
local locomotive_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
if loco_surface.valid then
WPT.set('loco_surface', locomotive_surface)
Public.set('loco_surface', locomotive_surface)
end
end
@ -459,21 +454,21 @@ local function on_research_finished(event)
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac', 0.1)
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
local market_announce = WPT.get('market_announce')
local market_announce = Public.get('market_announce')
if market_announce > game.tick then
return
end
local breached_wall = WPT.get('breached_wall')
local breached_wall = Public.get('breached_wall')
add_random_loot_to_main_market(breached_wall)
local message = ({'locomotive.new_items_at_market'})
Alert.alert_all_players(5, message, nil, 'achievement/tech-maniac', 0.1)
LocomotiveMarket.refresh_gui()
Public.refresh_gui()
end
local function on_player_changed_surface(event)
@ -482,7 +477,7 @@ local function on_player_changed_surface(event)
return
end
local active_surface = WPT.get('active_surface_index')
local active_surface = Public.get('active_surface_index')
local surface = game.surfaces[active_surface]
if not surface or not surface.valid then
return
@ -511,14 +506,14 @@ local function on_player_changed_surface(event)
end
end
local locomotive_surface = WPT.get('loco_surface')
local locomotive_surface = Public.get('loco_surface')
if locomotive_surface and locomotive_surface.valid and player.surface.index == locomotive_surface.index then
return PermissionGroups.add_player_to_permission_group(player, 'limited')
return Public.add_player_to_permission_group(player, 'limited')
elseif ICFunctions.get_player_surface(player) then
return PermissionGroups.add_player_to_permission_group(player, 'limited')
return Public.add_player_to_permission_group(player, 'limited')
elseif player.surface.index == surface.index then
return PermissionGroups.add_player_to_permission_group(player, 'main_surface')
return Public.add_player_to_permission_group(player, 'main_surface')
end
end
@ -537,7 +532,7 @@ local function on_player_driving_changed_state(event)
return
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
@ -553,11 +548,11 @@ end
function Public.boost_players_around_train()
local rpg = RPG.get('rpg_t')
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
if not active_surface_index then
return
end
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not (locomotive and locomotive.valid) then
return
end
@ -575,8 +570,8 @@ function Public.boost_players_around_train()
end
function Public.is_around_train(entity)
local locomotive = WPT.get('locomotive')
local active_surface_index = WPT.get('active_surface_index')
local locomotive = Public.get('locomotive')
local active_surface_index = Public.get('active_surface_index')
if not active_surface_index then
return false
@ -593,7 +588,7 @@ function Public.is_around_train(entity)
end
local surface = game.surfaces[active_surface_index]
local upgrades = WPT.get('upgrades')
local upgrades = Public.get('upgrades')
local data = {
locomotive = locomotive,
@ -607,15 +602,15 @@ function Public.is_around_train(entity)
end
function Public.render_train_hp()
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local locomotive_health = WPT.get('locomotive_health')
local locomotive_max_health = WPT.get('locomotive_max_health')
local locomotive = WPT.get('locomotive')
local upgrades = WPT.get('upgrades')
local locomotive_health = Public.get('locomotive_health')
local locomotive_max_health = Public.get('locomotive_max_health')
local locomotive = Public.get('locomotive')
local upgrades = Public.get('upgrades')
WPT.set(
Public.set(
'health_text',
rendering.draw_text {
text = 'HP: ' .. locomotive_health .. ' / ' .. locomotive_max_health,
@ -630,7 +625,7 @@ function Public.render_train_hp()
}
)
WPT.set(
Public.set(
'caption',
rendering.draw_text {
text = 'Comfy Choo Choo',
@ -645,7 +640,7 @@ function Public.render_train_hp()
}
)
WPT.set(
Public.set(
'circle',
rendering.draw_circle {
surface = surface,
@ -659,18 +654,18 @@ function Public.render_train_hp()
end
function Public.transfer_pollution()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local active_surface = game.surfaces[active_surface_index]
if not active_surface or not active_surface.valid then
return
end
local icw_locomotive = WPT.get('icw_locomotive')
local icw_locomotive = Public.get('icw_locomotive')
local surface = icw_locomotive.surface
if not surface or not surface.valid then
return

View File

@ -1,14 +1,12 @@
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local random = math.random
local rad = math.rad
local sin = math.sin
local cos = math.cos
local Public = {}
local function create_defense_system(position, name, target)
local active_surface_index = WPT.get('active_surface_index')
local active_surface_index = Public.get('active_surface_index')
local surface = game.surfaces[active_surface_index]
local random_angles = {
@ -78,7 +76,7 @@ local function create_defense_system(position, name, target)
end
function Public.enable_poison_defense(pos)
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end
@ -90,7 +88,7 @@ function Public.enable_poison_defense(pos)
end
function Public.enable_robotic_defense(pos)
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end

View File

@ -1,15 +1,13 @@
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local random = math.random
local Public = {}
local function shoo(event)
local icw_locomotive = WPT.get('icw_locomotive')
local icw_locomotive = Public.get('icw_locomotive')
local loco_surface = icw_locomotive.surface
if not loco_surface.valid then
if not loco_surface or not loco_surface.valid then
return
end
@ -21,7 +19,7 @@ local function shoo(event)
end
end
local locomotive_biter = WPT.get('locomotive_biter')
local locomotive_biter = Public.get('locomotive_biter')
local surface = player.surface
local message = event.message
message = string.lower(message)
@ -49,7 +47,7 @@ local function shoo(event)
}
surface.create_entity(explosion)
locomotive_biter.destroy()
WPT.set().locomotive_biter = nil
Public.set().locomotive_biter = nil
end
return
end
@ -57,7 +55,7 @@ local function shoo(event)
end
function Public.spawn_biter()
local this = WPT.get()
local this = Public.get()
local loco_surface = this.icw_locomotive.surface
if not loco_surface.valid then

View File

@ -1,8 +1,6 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = {}
local function contains_positions(area)
local function inside(pos)
@ -52,9 +50,9 @@ local function on_built_entity(event)
return
end
local outside_chests = WPT.get('outside_chests')
local chests_linked_to = WPT.get('chests_linked_to')
local upgrades = WPT.get('upgrades')
local outside_chests = Public.get('outside_chests')
local chests_linked_to = Public.get('chests_linked_to')
local upgrades = Public.get('upgrades')
local chest_created
local increased = false
@ -124,8 +122,8 @@ local function on_player_and_robot_mined_entity(event)
return
end
local outside_chests = WPT.get('outside_chests')
local chests_linked_to = WPT.get('chests_linked_to')
local outside_chests = Public.get('outside_chests')
local chests_linked_to = Public.get('chests_linked_to')
if outside_chests[entity.unit_number] then
for k, data in pairs(chests_linked_to) do
@ -144,8 +142,8 @@ local function on_player_and_robot_mined_entity(event)
end
local function divide_contents()
local outside_chests = WPT.get('outside_chests')
local chests_linked_to = WPT.get('chests_linked_to')
local outside_chests = Public.get('outside_chests')
local chests_linked_to = Public.get('chests_linked_to')
local target_chest
if not next(outside_chests) then

View File

@ -1,7 +1,6 @@
local Event = require 'utils.event'
local Generate = require 'maps.mountain_fortress_v3.generate'
local Public = require 'maps.mountain_fortress_v3.table'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local WD = require 'modules.wave_defense.table'
local Session = require 'utils.datastore.session_data'
local Difficulty = require 'modules.difficulty_vote_by_amount'
@ -11,12 +10,9 @@ local Server = require 'utils.server'
local Alert = require 'utils.alert'
local Math2D = require 'math2d'
local SpamProtection = require 'utils.spam_protection'
local MysticalChest = require 'maps.mountain_fortress_v3.mystical_chest'
local FriendlyPet = require 'maps.mountain_fortress_v3.locomotive.friendly_pet'
local format_number = require 'util'.format_number
local Public = {}
local concat = table.concat
local main_frame_name = Gui.uid_name()
@ -45,11 +41,11 @@ local function add_space(frame)
end
local function get_items()
local market_limits = WPT.get('market_limits')
local main_market_items = WPT.get('main_market_items')
local flame_turret = WPT.get('upgrades').flame_turret.bought
local upgrades = WPT.get('upgrades')
local fixed_prices = WPT.get('marked_fixed_prices')
local market_limits = Public.get('market_limits')
local main_market_items = Public.get('main_market_items')
local flame_turret = Public.get('upgrades').flame_turret.bought
local upgrades = Public.get('upgrades')
local fixed_prices = Public.get('marked_fixed_prices')
local chests_outside_cost = round(fixed_prices.chests_outside_cost * (1 + upgrades.chests_outside_upgrades))
local health_cost = round(fixed_prices.health_cost * (1 + upgrades.health_upgrades))
@ -62,7 +58,7 @@ local function get_items()
local land_mine_cost = round(fixed_prices.land_mine_cost * (1 + upgrades.landmine.bought))
local car_health_upgrade_pool = fixed_prices.car_health_upgrade_pool_cost
local pickaxe_upgrades = WPT.pickaxe_upgrades
local pickaxe_upgrades = Public.pickaxe_upgrades
local offer = pickaxe_upgrades[upgrades.pickaxe_tier]
@ -96,7 +92,7 @@ local function get_items()
value = 'coin',
price = chests_outside_cost,
tooltip = ({'locomotive.limit_reached'}),
sprite = 'achievement/so-long-and-thanks-for-all-the-fish',
sprite = 'entity.steel-chest',
enabled = false,
upgrade = true,
static = true
@ -107,7 +103,7 @@ local function get_items()
value = 'coin',
price = chests_outside_cost,
tooltip = ({'main_market.chest', upgrades.chests_outside_upgrades, market_limits.chests_outside_limit}),
sprite = 'achievement/so-long-and-thanks-for-all-the-fish',
sprite = 'entity.steel-chest',
enabled = true,
upgrade = true,
static = true
@ -154,7 +150,7 @@ local function get_items()
stack = 1,
value = 'coin',
price = aura_cost,
tooltip = ({'main_market.locomotive_aura_radius', upgrades.locomotive_aura_radius, market_limits.aura_limit}),
tooltip = ({'main_market.locomotive_aura_radius', upgrades.aura_upgrades, upgrades.aura_upgrades_max}),
sprite = 'achievement/tech-maniac',
enabled = true,
upgrade = true,
@ -493,7 +489,7 @@ local function validate_player(player)
end
local function close_market_gui(player)
local players = WPT.get('players')
local players = Public.get('players')
local element = player.gui.screen
local data = players[player.index].data
@ -512,7 +508,7 @@ local function redraw_market_items(gui, player, search_text)
if not validate_player(player) then
return
end
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -630,7 +626,7 @@ local function redraw_market_items(gui, player, search_text)
enabled = data.enabled
}
)
if WPT.get('trusted_only_car_tanks') then
if Public.get('trusted_only_car_tanks') then
local trustedPlayer = Session.get_trusted_player(player)
if not trustedPlayer then
if item == 'tank' then
@ -683,7 +679,7 @@ end
local function slider_changed(event)
local player = game.players[event.player_index]
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -726,7 +722,7 @@ local function text_changed(event)
return
end
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -771,7 +767,7 @@ local function text_changed(event)
end
local function gui_opened(event)
local market = WPT.get('market')
local market = Public.get('market')
if not event.gui_type == defines.gui_type.entity then
return
@ -795,7 +791,7 @@ local function gui_opened(event)
local inventory = player.get_main_inventory()
local player_item_count = inventory.get_item_count('coin')
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -889,7 +885,7 @@ local function gui_opened(event)
end
local function gui_click(event)
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -941,13 +937,13 @@ local function gui_click(event)
local cost = (item.price * slider_value)
local item_count = item.stack * slider_value
local this = WPT.get()
local this = Public.get()
if name == 'upgrade_pickaxe' then
player.remove_item({name = item.value, count = item.price})
this.upgrades.pickaxe_tier = this.upgrades.pickaxe_tier + item.stack
local pickaxe_upgrades = WPT.pickaxe_upgrades
local pickaxe_upgrades = Public.pickaxe_upgrades
local offer = pickaxe_upgrades[this.upgrades.pickaxe_tier]
local message = ({
@ -967,6 +963,7 @@ local function gui_click(event)
local force = game.forces.player
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + this.pickaxe_speed_per_purchase
this.upgrades.train_upgrade_contribution = this.upgrades.train_upgrade_contribution + item.price
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
@ -985,10 +982,11 @@ local function gui_click(event)
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought the chest limit upgrade for ' .. format_number(item.price, true) .. ' coins.'
player.name .. ' has upgraded the chest limit for ' .. format_number(item.price, true) .. ' coins.'
}
)
this.upgrades.chests_outside_upgrades = this.upgrades.chests_outside_upgrades + item.stack
this.upgrades.train_upgrade_contribution = this.upgrades.train_upgrade_contribution + item.price
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
@ -1002,7 +1000,7 @@ local function gui_click(event)
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought the locomotive health modifier for ' .. format_number(item.price, true) .. ' coins.'
player.name .. ' has upgraded the train health for ' .. format_number(item.price, true) .. ' coins.'
}
)
@ -1034,7 +1032,7 @@ local function gui_click(event)
end
end
this.upgrades.train_upgrades = this.upgrades.train_upgrades + item.stack
this.upgrades.train_upgrade_contribution = this.upgrades.train_upgrade_contribution + item.price
this.upgrades.health_upgrades = this.upgrades.health_upgrades + item.stack
rendering.set_text(this.health_text, 'HP: ' .. round(this.locomotive_health) .. ' / ' .. round(this.locomotive_max_health))
@ -1056,12 +1054,12 @@ local function gui_click(event)
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought the locomotive xp aura modifier for ' .. format_number(item.price, true) .. ' coins.'
player.name .. ' has upgraded the train aura radius for ' .. format_number(item.price, true) .. ' coins.'
}
)
this.upgrades.locomotive_aura_radius = this.upgrades.locomotive_aura_radius + 5
this.upgrades.aura_upgrades = this.upgrades.aura_upgrades + item.stack
this.upgrades.train_upgrades = this.upgrades.train_upgrades + item.stack
this.upgrades.train_upgrade_contribution = this.upgrades.train_upgrade_contribution + item.price
if this.circle then
rendering.destroy(this.circle)
@ -1096,12 +1094,12 @@ local function gui_click(event)
Alert.alert_all_players(5, message)
Server.to_discord_bold(
table.concat {
player.name .. ' has bought the XP points modifier for ' .. format_number(item.price) .. ' coins.'
player.name .. ' has upgraded the train aura XP modifier for ' .. format_number(item.price) .. ' coins.'
}
)
this.upgrades.xp_points = this.upgrades.xp_points + 0.5
this.upgrades.xp_points_upgrade = this.upgrades.xp_points_upgrade + item.stack
this.upgrades.train_upgrades = this.upgrades.train_upgrades + item.stack
this.upgrades.train_upgrade_contribution = this.upgrades.train_upgrade_contribution + item.price
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
@ -1120,7 +1118,7 @@ local function gui_click(event)
}
)
MysticalChest.init_price_check(this.locomotive, this.mystical_chest)
Public.init_price_check(this.locomotive, this.mystical_chest)
redraw_market_items(data.item_frame, player, data.search_text)
redraw_coins_left(data.coins_left, player)
@ -1272,7 +1270,7 @@ end
local function gui_closed(event)
local player = game.players[event.player_index]
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -1289,7 +1287,7 @@ local function gui_closed(event)
end
local function on_player_changed_position(event)
local players = WPT.get('players')
local players = Public.get('players')
if not players then
return
end
@ -1299,7 +1297,7 @@ local function on_player_changed_position(event)
end
local data = players[player.index].data
local market = WPT.get('market')
local market = Public.get('market')
if not (market and market.valid) then
return
@ -1323,7 +1321,7 @@ end
local function create_market(data, rebuild)
local surface = data.surface
local this = WPT.get()
local this = Public.get()
if not this.locomotive then
return
@ -1396,7 +1394,7 @@ local function create_market(data, rebuild)
this.mystical_chest.entity.minable = false
this.mystical_chest.entity.destructible = false
if not this.mystical_chest.price then
MysticalChest.add_mystical_chest()
Public.add_mystical_chest()
end
rendering.draw_text {
text = 'Mystical chest',
@ -1409,7 +1407,7 @@ local function create_market(data, rebuild)
}
end
Generate.wintery(this.market, 5.5)
Public.wintery(this.market, 5.5)
rendering.draw_text {
text = 'Market',
@ -1423,7 +1421,7 @@ local function create_market(data, rebuild)
this.market.destructible = false
FriendlyPet.spawn_biter()
Public.spawn_biter()
for x = center_position.x - 5, center_position.x + 5, 1 do
for y = center_position.y - 5, center_position.y + 5, 1 do
@ -1444,7 +1442,7 @@ local function create_market(data, rebuild)
end
local function place_market()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end
@ -1456,7 +1454,7 @@ local function place_market()
local icw_table = ICW.get_table()
local unit_surface = locomotive.unit_number
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
local market = WPT.get('market')
local market = Public.get('market')
local data = {
surface = surface
@ -1486,7 +1484,7 @@ function Public.refresh_gui()
local gui = player.gui
local screen = gui.screen
local player_data = WPT.get('players')
local player_data = Public.get('players')
if not players then
return
end

View File

@ -1,4 +1,4 @@
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local Session = require 'utils.datastore.session_data'
local Jailed = require 'utils.datastore.jail_data'
@ -6,17 +6,23 @@ local Antigrief = require 'utils.antigrief'
local required_playtime = 5184000 -- 24 hours
local Public = {}
function Public.add_player_to_permission_group(player, group, forced)
local jailed = Jailed.get_jailed_table()
local enable_permission_group_disconnect = WPT.get('disconnect_wagon')
local enable_permission_group_disconnect = Public.get('disconnect_wagon')
local session = Session.get_session_table()
local AG = Antigrief.get()
local allow_decon = WPT.get('allow_decon')
local allow_decon_main_surface = WPT.get('allow_decon_main_surface')
if not AG then
return
end
local allow_decon = Public.get('allow_decon')
local allow_decon_main_surface = Public.get('allow_decon_main_surface')
local default_group = game.permissions.get_group('Default')
if not default_group then
return
end
default_group.set_allows_action(defines.input_action.activate_cut, false)
if allow_decon_main_surface then
default_group.set_allows_action(defines.input_action.deconstruct, true)
@ -26,6 +32,9 @@ function Public.add_player_to_permission_group(player, group, forced)
if not game.permissions.get_group('limited') then
local limited_group = game.permissions.create_group('limited')
if not limited_group then
return
end
limited_group.set_allows_action(defines.input_action.cancel_craft, false)
limited_group.set_allows_action(defines.input_action.drop_item, false)
if allow_decon then
@ -38,6 +47,9 @@ function Public.add_player_to_permission_group(player, group, forced)
if not game.permissions.get_group('near_locomotive') then
local near_locomotive_group = game.permissions.create_group('near_locomotive')
if not near_locomotive_group then
return
end
near_locomotive_group.set_allows_action(defines.input_action.cancel_craft, false)
near_locomotive_group.set_allows_action(defines.input_action.drop_item, false)
if allow_decon_main_surface then
@ -50,6 +62,9 @@ function Public.add_player_to_permission_group(player, group, forced)
if not game.permissions.get_group('main_surface') then
local main_surface_group = game.permissions.create_group('main_surface')
if not main_surface_group then
return
end
if allow_decon_main_surface then
main_surface_group.set_allows_action(defines.input_action.deconstruct, true)
else
@ -60,6 +75,9 @@ function Public.add_player_to_permission_group(player, group, forced)
if not game.permissions.get_group('not_trusted') then
local not_trusted = game.permissions.create_group('not_trusted')
if not not_trusted then
return
end
not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
not_trusted.set_allows_action(defines.input_action.edit_permission_group, false)
not_trusted.set_allows_action(defines.input_action.import_permissions_string, false)
@ -149,18 +167,33 @@ function Public.add_player_to_permission_group(player, group, forced)
if playtime < required_playtime then
local not_trusted = game.permissions.get_group('not_trusted')
if not not_trusted then
return
end
if not player.admin then
not_trusted.add_player(player)
end
else
if group == 'limited' then
local limited_group = game.permissions.get_group('limited')
if not limited_group then
return
end
limited_group.add_player(player)
elseif group == 'main_surface' then
local main_surface_group = game.permissions.get_group('main_surface')
if not main_surface_group then
return
end
main_surface_group.add_player(player)
elseif group == 'near_locomotive' then
local near_locomotive_group = game.permissions.get_group('near_locomotive')
if not near_locomotive_group then
return
end
near_locomotive_group.add_player(player)
elseif group == 'default' then
default_group.add_player(player)

View File

@ -1,12 +1,9 @@
local Generate = require 'maps.mountain_fortress_v3.generate'
local Public = require 'maps.mountain_fortress_v3.table'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WPT = require 'maps.mountain_fortress_v3.table'
local Task = require 'utils.task'
local Token = require 'utils.token'
local MapFunctions = require 'tools.map_functions'
local Public = {}
local random = math.random
local function initial_cargo_boxes()
@ -113,7 +110,7 @@ local set_loco_tiles =
)
function Public.locomotive_spawn(surface, position)
local this = WPT.get()
local this = Public.get()
for y = -6, 6, 2 do
surface.create_entity({name = 'straight-rail', position = {position.x, position.y + y}, force = 'player', direction = 0})
end
@ -123,7 +120,7 @@ function Public.locomotive_spawn(surface, position)
this.locomotive_cargo = surface.create_entity({name = 'cargo-wagon', position = {position.x, position.y + 3}, force = 'player'})
this.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = 'raw-fish', count = 8})
local winter_mode_locomotive = Generate.wintery(this.locomotive, 5.5)
local winter_mode_locomotive = Public.wintery(this.locomotive, 5.5)
if not winter_mode_locomotive then
rendering.draw_light(
{
@ -141,7 +138,7 @@ function Public.locomotive_spawn(surface, position)
)
end
local winter_mode_cargo = Generate.wintery(this.locomotive_cargo, 5.5)
local winter_mode_cargo = Public.wintery(this.locomotive_cargo, 5.5)
if not winter_mode_cargo then
rendering.draw_light(
@ -165,7 +162,7 @@ function Public.locomotive_spawn(surface, position)
position = position
}
Task.set_timeout_in_ticks(100, set_loco_tiles, data)
Task.set_timeout_in_ticks(150, set_loco_tiles, data)
for y = -1, 0, 0.05 do
local scale = random(50, 100) * 0.01
@ -190,6 +187,10 @@ function Public.locomotive_spawn(surface, position)
this.locomotive_cargo.operable = true
local locomotive = ICW.register_wagon(this.locomotive)
if not locomotive then
return
end
ICW.register_wagon(this.locomotive_cargo)
this.icw_locomotive = locomotive

View File

@ -1,6 +1,5 @@
local LootRaffle = require 'functions.loot_raffle'
local Public = {}
local Public = require 'maps.mountain_fortress_v3.table'
local random = math.random
local abs = math.abs
local floor = math.floor
@ -27,7 +26,7 @@ function Public.get_distance(position)
return difficulty
end
function Public.add(surface, position, chest)
function Public.add_loot(surface, position, chest)
local budget = 48 + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01
@ -79,7 +78,7 @@ function Public.add(surface, position, chest)
end
end
function Public.add_rare(surface, position, chest, magic)
function Public.add_loot_rare(surface, position, chest, magic)
local budget = magic * 48 + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01

View File

@ -5,30 +5,20 @@ Mountain Fortress v3 is maintained by Gerkiz and hosted by Comfy.
Want to host it? Ask Gerkiz#0001 at discord!
]]
local Functions = require 'maps.mountain_fortress_v3.functions'
local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies'
-- local HS = require 'maps.mountain_fortress_v3.highscore'
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.core'
local Discord = require 'utils.discord'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
local Autostash = require 'modules.autostash'
local Group = require 'utils.gui.group'
local PL = require 'utils.gui.player_list'
local CS = require 'maps.mountain_fortress_v3.surface'
local Server = require 'utils.server'
local Explosives = require 'modules.explosives'
local Balance = require 'maps.mountain_fortress_v3.balance'
local Entities = require 'maps.mountain_fortress_v3.entities'
local Gui_mf = require 'maps.mountain_fortress_v3.gui'
local ICW = require 'maps.mountain_fortress_v3.icw.main'
local WD = require 'modules.wave_defense.table'
local Map = require 'modules.map_info'
local RPG = require 'modules.rpg.main'
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
local Locomotive = require 'maps.mountain_fortress_v3.locomotive'
local SpawnLocomotive = require 'maps.mountain_fortress_v3.locomotive.spawn_locomotive'
local Score = require 'utils.gui.score'
local Poll = require 'utils.gui.poll'
local Collapse = require 'modules.collapse'
@ -45,19 +35,10 @@ local JailData = require 'utils.datastore.jail_data'
local RPG_Progression = require 'utils.datastore.rpg_data'
local OfflinePlayers = require 'modules.clear_vacant_players'
require 'maps.mountain_fortress_v3.locomotive.market'
require 'maps.mountain_fortress_v3.locomotive.linked_chests'
require 'maps.mountain_fortress_v3.rocks_yield_ore_veins'
require 'maps.mountain_fortress_v3.generate'
require 'maps.mountain_fortress_v3.commands'
require 'maps.mountain_fortress_v3.breached_wall'
require 'maps.mountain_fortress_v3.ic.main'
require 'maps.mountain_fortress_v3.biters_yield_coins'
require 'modules.shotgun_buff'
require 'modules.no_deconstruction_of_neutral_entities'
require 'modules.spawners_contain_biters'
require 'maps.mountain_fortress_v3.ic.main'
require 'modules.wave_defense.main'
require 'modules.charging_station'
@ -69,9 +50,6 @@ local role_to_mention = Discord.role_mentions.mtn_fortress
-- local send_ping_to_channel = Discord.channel_names.bot_quarters
-- local role_to_mention = Discord.role_mentions.test_role
local Public = {}
local raise_event = script.raise_event
local floor = math.floor
local remove = table.remove
RPG.disable_cooldowns_on_spells()
@ -142,30 +120,31 @@ local announce_new_map =
)
function Public.reset_map()
local this = WPT.get()
local this = Public.get()
local wave_defense_table = WD.get_table()
Misc.set('creative_are_you_sure', false)
Misc.set('creative_enabled', false)
this.active_surface_index = CS.create_surface()
-- this.soft_reset_counter = CS.get_reset_counter()
this.active_surface_index = Public.create_surface()
-- this.soft_reset_counter = Public.get_reset_counter()
Autostash.insert_into_furnace(true)
Autostash.insert_into_wagon(true)
Autostash.bottom_button(true)
BottomFrame.reset()
BottomFrame.activate_custom_buttons(true)
BuriedEnemies.reset()
Public.reset_buried_biters()
Poll.reset()
ICW.reset()
IC.reset()
IC.allowed_surface(game.surfaces[this.active_surface_index].name)
Functions.reset_table()
Public.reset_func_table()
game.reset_time_played()
WPT.reset_table()
Public.reset_main_table()
OfflinePlayers.set_active_surface_index(this.active_surface_index)
OfflinePlayers.set_offline_players_enabled(true)
OfflinePlayers.clear_offline_players()
-- OfflinePlayers.set_offline_players_surface_removal(true)
RPG.rpg_reset_all_players()
@ -184,14 +163,14 @@ function Public.reset_map()
RPG_Progression.toggle_module(false)
RPG_Progression.set_dataset('mtn_v3_rpg_prestige')
if WPT.get('prestige_system_enabled') then
if Public.get('prestige_system_enabled') then
RPG_Progression.restore_xp_on_reset()
end
Group.reset_groups()
Group.alphanumeric_only(false)
Functions.disable_tech()
Public.disable_tech()
init_protectors_force()
init_bonus_drill_force()
@ -218,7 +197,7 @@ function Public.reset_map()
BiterHealthBooster.enable_boss_loot(false)
BiterHealthBooster.enable_randomize_stun_and_slowdown_sticker(true)
Balance.init_enemy_weapon_damage()
Public.init_enemy_weapon_damage()
AntiGrief.whitelist_types('tree', true)
AntiGrief.enable_capsule_warning(false)
@ -244,7 +223,7 @@ function Public.reset_map()
player.gui.left['mvps'].destroy()
end
ICMinimap.kill_minimap(player)
raise_event(Gui_mf.events.reset_map, {player_index = player.index})
Event.raise(Public.events.reset_map, {player_index = player.index})
end
Difficulty.reset_difficulty_poll({closing_timeout = game.tick + 36000})
@ -264,9 +243,9 @@ function Public.reset_map()
this.locomotive_health = 10000
this.locomotive_max_health = 10000
SpawnLocomotive.locomotive_spawn(surface, {x = -18, y = 25})
Locomotive.render_train_hp()
Functions.render_direction(surface)
Public.locomotive_spawn(surface, {x = -18, y = 25})
Public.render_train_hp()
Public.render_direction(surface)
WD.reset_wave_defense()
wave_defense_table.surface_index = this.active_surface_index
@ -283,8 +262,8 @@ function Public.reset_map()
WD.increase_damage_per_wave(true)
WD.increase_health_per_wave(true)
Functions.set_difficulty()
Functions.disable_creative()
Public.set_difficulty()
Public.disable_creative()
if not surface.is_chunk_generated({-20, 22}) then
surface.request_to_generate_chunks({-20, 22}, 0.1)
@ -295,9 +274,9 @@ function Public.reset_map()
Task.set_queue_speed(16)
-- HS.get_scores()
-- Public.get_scores()
this.chunk_load_tick = game.tick + 200
this.chunk_load_tick = game.tick + 400
this.force_chunk = true
this.market_announce = game.tick + 1200
this.game_lost = false
@ -306,10 +285,10 @@ function Public.reset_map()
end
local is_locomotive_valid = function()
local locomotive = WPT.get('locomotive')
if not locomotive.valid then
WPT.set('game_lost', true)
Entities.loco_died(true)
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
Public.set('game_lost', true)
Public.loco_died(true)
end
end
@ -325,13 +304,13 @@ local is_player_valid = function()
end
local has_the_game_ended = function()
local game_reset_tick = WPT.get('game_reset_tick')
local game_reset_tick = Public.get('game_reset_tick')
if game_reset_tick then
if game_reset_tick < 0 then
return
end
local this = WPT.get()
local this = Public.get()
this.game_reset_tick = this.game_reset_tick - 30
if this.game_reset_tick % 1800 == 0 then
@ -352,14 +331,14 @@ local has_the_game_ended = function()
if this.soft_reset and this.game_reset_tick == 0 then
this.game_reset_tick = nil
-- HS.set_scores(diff_name)
-- Public.set_scores(diff_name)
Public.reset_map()
return
end
if this.restart and this.game_reset_tick == 0 then
if not this.announced_message then
-- HS.set_scores(diff_name)
-- Public.set_scores(diff_name)
game.print(({'entity.notify_restart'}), {r = 0.22, g = 0.88, b = 0.22})
local message = 'Soft-reset is disabled! Server will restart from scenario to load new changes.'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
@ -370,7 +349,7 @@ local has_the_game_ended = function()
end
if this.shutdown and this.game_reset_tick == 0 then
if not this.announced_message then
-- HS.set_scores(diff_name)
-- Public.set_scores(diff_name)
game.print(({'entity.notify_shutdown'}), {r = 0.22, g = 0.88, b = 0.22})
local message = 'Soft-reset is disabled! Server will shutdown. Most likely because of updates.'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
@ -384,12 +363,12 @@ local has_the_game_ended = function()
end
local chunk_load = function()
local chunk_load_tick = WPT.get('chunk_load_tick')
local chunk_load_tick = Public.get('chunk_load_tick')
local tick = game.tick
if chunk_load_tick then
if chunk_load_tick < tick then
WPT.set('force_chunk', false)
WPT.remove('chunk_load_tick')
Public.set('force_chunk', false)
Public.remove('chunk_load_tick')
Task.set_queue_speed(8)
end
end
@ -408,12 +387,12 @@ local collapse_message =
)
local lock_locomotive_positions = function()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive or not locomotive.valid then
return
end
local locomotive_positions = WPT.get('locomotive_pos')
local locomotive_positions = Public.get('locomotive_pos')
local success = is_position_near_tbl(locomotive.position, locomotive_positions.tbl)
local p = locomotive.position
if not success then
@ -428,7 +407,7 @@ end
local compare_collapse_and_train = function()
local collapse_pos = Collapse.get_position()
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not (locomotive and locomotive.valid) then
return
end
@ -436,10 +415,10 @@ local compare_collapse_and_train = function()
local c_y = collapse_pos.y
local t_y = locomotive.position.y
local gap_between_zones = WPT.get('gap_between_zones')
local gap_between_zones = Public.get('gap_between_zones')
if c_y - t_y <= gap_between_zones.gap then
Functions.set_difficulty()
Public.set_difficulty()
else
Collapse.set_speed(1)
Collapse.set_amount(4)
@ -447,7 +426,7 @@ local compare_collapse_and_train = function()
end
local collapse_after_wave_200 = function()
local collapse_grace = WPT.get('collapse_grace')
local collapse_grace = Public.get('collapse_grace')
if not collapse_grace then
return
end
@ -467,8 +446,14 @@ local collapse_after_wave_200 = function()
end
end
local handle_changes = function()
Public.set('restart', true)
Public.set('soft_reset', false)
print('Received new changes from backend.')
end
local on_tick = function()
local update_gui = Gui_mf.update_gui
local update_gui = Public.update_gui
local tick = game.tick
local players = game.connected_players
@ -486,14 +471,14 @@ local on_tick = function()
if tick % 250 == 0 then
compare_collapse_and_train()
Functions.set_spawn_position()
Functions.boost_difficulty()
Public.set_spawn_position()
Public.boost_difficulty()
end
if tick % 1000 == 0 then
collapse_after_wave_200()
Functions.set_difficulty()
Functions.is_creativity_mode_on()
Public.set_difficulty()
Public.is_creativity_mode_on()
end
end
@ -532,8 +517,9 @@ local on_init = function()
Explosives.set_whitelist_entity('tank')
end
Event.add(Server.events.on_changes_detected, handle_changes)
Event.on_nth_tick(10, on_tick)
Event.on_init(on_init)
Event.add(WPT.events.reset_map, Public.reset_map)
return Public

View File

@ -1,11 +1,9 @@
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
local Event = require 'utils.event'
local Ai = require 'modules.ai'
require 'modules.check_fullness'
local Public = {events = {on_entity_mined = Event.generate_event_name('on_entity_mined')}}
local random = math.random
local floor = math.floor
local sqrt = math.sqrt
@ -219,7 +217,7 @@ local size_of_scrap_raffle = #scrap_raffle
local function get_amount(data)
local entity = data.entity
local mining_utils = WPT.get('mining_utils')
local mining_utils = Public.get('mining_utils')
local t_modifier = mining_utils.type_modifier
local rocks_yield_ore_distance_modifier = mining_utils.rocks_yield_ore_distance_modifier
local rocks_yield_ore_base_amount = mining_utils.rocks_yield_ore_base_amount
@ -286,7 +284,7 @@ end
local function randomness(data)
local entity = data.entity
local player = data.player
local spill_items_to_surface = WPT.get('spill_items_to_surface')
local spill_items_to_surface = Public.get('spill_items_to_surface')
local harvest
local harvest_amount
@ -351,7 +349,7 @@ end
local function randomness_scrap(data)
local entity = data.entity
local player = data.player
local spill_items_to_surface = WPT.get('spill_items_to_surface')
local spill_items_to_surface = Public.get('spill_items_to_surface')
local harvest = scrap_raffle[random(1, size_of_scrap_raffle)]
local amount_bonus = game.forces.player.mining_drill_productivity_bonus * 2

View File

@ -1,11 +1,10 @@
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local RPG = require 'modules.rpg.main'
local Alert = require 'utils.alert'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Public = {}
local shuffle = table.shuffle_table
local random = math.random
@ -267,7 +266,7 @@ end
local restore_mining_speed_token =
Token.register(
function()
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.mining then
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier - 0.5
@ -281,7 +280,7 @@ local restore_mining_speed_token =
local restore_movement_speed_token =
Token.register(
function()
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.movement then
force.character_running_speed_modifier = force.character_running_speed_modifier - 0.2
@ -333,7 +332,7 @@ local mc_random_rewards = {
color = {r = 0.00, g = 0.25, b = 0.00},
tooltip = 'Selecting this will grant the team a bonus movement speed for 15 minutes!',
func = (function(player)
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.movement then
return false, '[Rewards] Movement bonus is already applied. Please choose another reward.'
@ -355,7 +354,7 @@ local mc_random_rewards = {
color = {r = 0.00, g = 0.00, b = 0.25},
tooltip = 'Selecting this will grant the team a bonus mining speed for 15 minutes!',
func = (function(player)
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
local force = game.forces.player
if mc_rewards.temp_boosts.mining then
return false, '[Rewards] Mining bonus is already applied. Please choose another reward.'
@ -376,8 +375,8 @@ local mc_random_rewards = {
color = {r = 0.00, g = 0.00, b = 0.25},
tooltip = 'Selecting this will heal the main locomotive to full health!',
func = (function(player)
local locomotive_max_health = WPT.get('locomotive_max_health')
WPT.set('locomotive_health', locomotive_max_health)
local locomotive_max_health = Public.get('locomotive_max_health')
Public.set('locomotive_health', locomotive_max_health)
local message = ({'locomotive.locomotive_health', player.name})
Alert.alert_all_players(15, message, nil, 'achievement/tech-maniac')
return true
@ -397,7 +396,7 @@ local function mystical_chest_reward(player)
frame = frame.add {type = 'frame', name = 'reward_system_1', direction = 'vertical', style = 'inside_shallow_frame'}
frame.style.padding = 4
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
mc_rewards.current = {}
for i = 1, 3 do
@ -437,7 +436,7 @@ local function container_opened(event)
return
end
local mystical_chest = WPT.get('mystical_chest')
local mystical_chest = Public.get('mystical_chest')
if not mystical_chest then
return
end
@ -480,7 +479,7 @@ local function on_gui_click(event)
end
local i = tonumber(element.name)
local mc_rewards = WPT.get('mc_rewards')
local mc_rewards = Public.get('mc_rewards')
local current = mc_rewards.current
local player = game.get_player(element.player_index)
@ -566,7 +565,7 @@ function Public.roll(budget, max_slots, blacklist)
end
function Public.add_mystical_chest(player)
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if not locomotive then
return
end
@ -574,7 +573,7 @@ function Public.add_mystical_chest(player)
return
end
local mystical_chest = WPT.get('mystical_chest')
local mystical_chest = Public.get('mystical_chest')
if not (mystical_chest.entity and mystical_chest.entity.valid) then
return
end

View File

@ -1,3 +1,4 @@
local Public = require 'maps.mountain_fortress_v3.table'
local Functions = require 'maps.mountain_fortress_v3.functions'
local random = math.random
@ -604,7 +605,7 @@ if testing then
}
end
local function spawn_random_buildings(entities, p, depth)
function Public.spawn_random_buildings(entities, p, depth)
local randomizer = random(1, #buildings)
local low = random(1, 2)
local medium = random(2, 3)
@ -650,4 +651,4 @@ local function spawn_random_buildings(entities, p, depth)
end
end
return spawn_random_buildings
return Public

View File

@ -1,4 +1,5 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Global = require 'utils.global'
local random = math.random
@ -181,3 +182,5 @@ end
Event.on_init(on_init)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
return Public

View File

@ -1,11 +1,21 @@
local Server = require 'utils.server'
local Session = require 'utils.datastore.session_data'
local Modifers = require 'utils.player_modifiers'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
local Public = {}
local function show_all_gui(player)
for _, child in pairs(player.gui.top.children) do
child.visible = true
end
end
local function clear_spec_tag(player)
if player.tag == '[Spectator]' then
player.tag = ''
end
end
local function reset_forces(new_surface, old_surface)
for _, f in pairs(game.forces) do
@ -52,6 +62,8 @@ local function equip_players(player_starting_items, data)
for item, amount in pairs(player_starting_items) do
player.insert({name = item, count = amount})
end
show_all_gui(player)
clear_spec_tag(player)
else
data.players[player.index] = nil
Session.clear_player(player)
@ -61,7 +73,7 @@ local function equip_players(player_starting_items, data)
end
function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items)
local this = WPT.get()
local this = Public.get()
if not this.soft_reset_counter then
this.soft_reset_counter = 0
@ -72,7 +84,7 @@ function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_it
this.soft_reset_counter = this.soft_reset_counter + 1
local new_surface = game.create_surface(this.original_surface_name .. '_' .. tostring(this.soft_reset_counter), map_gen_settings)
new_surface.request_to_generate_chunks({0, 0}, 0.5)
new_surface.request_to_generate_chunks({0, 0}, 0.1)
new_surface.force_generate_chunk_requests()
reset_forces(new_surface, old_surface)

View File

@ -1,10 +1,7 @@
local Global = require 'utils.global'
local surface_name = 'mtn_v3'
local WPT = require 'maps.mountain_fortress_v3.table'
local Reset = require 'maps.mountain_fortress_v3.soft_reset'
local zone_settings = WPT.zone_settings
local Public = {}
local Public = require 'maps.mountain_fortress_v3.table'
local zone_settings = Public.zone_settings
local this = {
active_surface_index = nil,
@ -59,10 +56,10 @@ function Public.create_surface()
if not this.active_surface_index then
this.active_surface_index = game.create_surface(surface_name, map_gen_settings).index
else
this.active_surface_index = Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
this.active_surface_index = Public.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
end
-- this.soft_reset_counter = Reset.get_reset_counter()
-- this.soft_reset_counter = Public.get_reset_counter()
if not this.cleared_nauvis then
local mgs = game.surfaces['nauvis'].map_gen_settings
@ -91,12 +88,4 @@ function Public.get_reset_counter()
return this.soft_reset_counter
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
return Public

View File

@ -8,7 +8,10 @@ local this = {
}
local Public = {}
Public.events = {reset_map = Event.generate_event_name('reset_map')}
Public.events = {
reset_map = Event.generate_event_name('reset_map'),
on_entity_mined = Event.generate_event_name('on_entity_mined')
}
Global.register(
this,
@ -84,7 +87,7 @@ Public.pickaxe_upgrades = {
'Luminite'
}
function Public.reset_table()
function Public.reset_main_table()
-- @start
-- these 3 are in case of stop/start/reloading the instance.
this.soft_reset = true
@ -146,8 +149,9 @@ function Public.reset_table()
explosive_bullets_purchased = false,
xp_points_upgrade = 0,
aura_upgrades = 0,
aura_upgrades_max = 12, -- = (aura_limit - locomotive_aura_radius) / 5
locomotive_aura_radius = 40,
train_upgrades = 0,
train_upgrade_contribution = 0,
xp_points = 0,
health_upgrades = 0,
pickaxe_tier = 1,
@ -173,6 +177,7 @@ function Public.reset_table()
this.bonus_xp_on_join = 250
this.main_market_items = {}
this.spill_items_to_surface = false
this.spectate = {}
this.outside_chests = {}
this.chests_linked_to = {}
this.placed_trains_in_zone = {
@ -288,6 +293,6 @@ function Public.remove(key, sub_key)
end
end
Event.on_init(Public.reset_table)
Event.on_init(Public.reset_main_table)
return Public

View File

@ -1,17 +1,13 @@
local Event = require 'utils.event'
local Public = require 'maps.mountain_fortress_v3.table'
local Biters = require 'modules.wave_defense.biter_rolls'
local Functions = require 'maps.mountain_fortress_v3.functions'
local Generate_resources = require 'maps.mountain_fortress_v3.resource_generator'
local WPT = require 'maps.mountain_fortress_v3.table'
local get_perlin = require 'maps.mountain_fortress_v3.get_perlin'
local Public = {}
local random = math.random
local abs = math.abs
local floor = math.floor
local ceil = math.ceil
local zone_settings = WPT.zone_settings
local zone_settings = Public.zone_settings
local worm_level_modifier = 0.19
local start_ground_tiles = {
@ -97,12 +93,12 @@ local trees = {
}
local callback = {
[1] = {callback = Functions.refill_turret_callback, data = Functions.firearm_magazine_ammo},
[2] = {callback = Functions.refill_turret_callback, data = Functions.piercing_rounds_magazine_ammo},
[3] = {callback = Functions.refill_turret_callback, data = Functions.uranium_rounds_magazine_ammo},
[4] = {callback = Functions.refill_turret_callback, data = Functions.uranium_rounds_magazine_ammo},
[5] = {callback = Functions.refill_liquid_turret_callback, data = Functions.light_oil_ammo},
[6] = {callback = Functions.refill_artillery_turret_callback, data = Functions.artillery_shell_ammo}
[1] = {callback = Public.refill_turret_callback, data = Public.firearm_magazine_ammo},
[2] = {callback = Public.refill_turret_callback, data = Public.piercing_rounds_magazine_ammo},
[3] = {callback = Public.refill_turret_callback, data = Public.uranium_rounds_magazine_ammo},
[4] = {callback = Public.refill_turret_callback, data = Public.uranium_rounds_magazine_ammo},
[5] = {callback = Public.refill_liquid_turret_callback, data = Public.light_oil_ammo},
[6] = {callback = Public.refill_artillery_turret_callback, data = Public.artillery_shell_ammo}
}
local turret_list = {
@ -162,11 +158,11 @@ local function is_position_near(area, table_to_check)
end
local function place_wagon(data, adjusted_zones)
local placed_trains_in_zone = WPT.get('placed_trains_in_zone')
local placed_trains_in_zone = Public.get('placed_trains_in_zone')
if not placed_trains_in_zone.randomized then
placed_trains_in_zone.limit = random(1, 2)
placed_trains_in_zone.randomized = true
placed_trains_in_zone = WPT.get('placed_trains_in_zone')
placed_trains_in_zone = Public.get('placed_trains_in_zone')
end
if not data.new_zone then
@ -205,11 +201,11 @@ local function place_wagon(data, adjusted_zones)
local top_y = data.top_y
local position = {x = data.x, y = top_y + random(4, 12) * 2}
local wagon_mineable = {
callback = Functions.disable_minable_and_ICW_callback
callback = Public.disable_minable_and_ICW_callback
}
local rail_mineable = {
callback = Functions.disable_destructible_callback
callback = Public.disable_destructible_callback
}
local radius = 300
@ -282,15 +278,15 @@ local function wall(p, data)
local entities = data.entities
local surface = data.surface
local treasure = data.treasure
local stone_wall = {callback = Functions.disable_minable_callback}
local enable_arties = WPT.get('enable_arties')
local alert_zone_1 = WPT.get('alert_zone_1')
local stone_wall = {callback = Public.disable_minable_callback}
local enable_arties = Public.get('enable_arties')
local alert_zone_1 = Public.get('alert_zone_1')
local seed = data.seed
local y = data.yv
local small_caves = get_perlin('small_caves', p, seed + 204000)
local cave_ponds = get_perlin('cave_rivers', p, seed + 120400)
local small_caves = Public.get_noise('small_caves', p, seed + 204000)
local cave_ponds = Public.get_noise('cave_rivers', p, seed + 120400)
if y > 9 + cave_ponds * 6 and y < 23 + small_caves * 6 then
if small_caves > 0.02 or cave_ponds > 0.02 then
if small_caves > 0.005 then
@ -353,10 +349,10 @@ local function wall(p, data)
if not alert_zone_1 and data.y >= -zone_settings.zone_depth then
local x_min = -zone_settings.zone_width / 2
local x_max = zone_settings.zone_width / 2
WPT.set('zone1_beam1', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}))
WPT.set('zone1_beam2', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}))
WPT.set('alert_zone_1', true)
WPT.set(
Public.set('zone1_beam1', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}))
Public.set('zone1_beam2', surface.create_entity({name = 'electric-beam', position = {x_min, p.y}, source = {x_min, p.y}, target = {x_max, p.y}}))
Public.set('alert_zone_1', true)
Public.set(
'zone1_text1',
rendering.draw_text {
text = 'Breaching the far side wall will start collapse.',
@ -369,7 +365,7 @@ local function wall(p, data)
scale_with_zoom = false
}
)
WPT.set(
Public.set(
'zone1_text2',
rendering.draw_text {
text = 'Breaching the far side wall will start collapse',
@ -382,7 +378,7 @@ local function wall(p, data)
scale_with_zoom = false
}
)
WPT.set(
Public.set(
'zone1_text3',
rendering.draw_text {
text = 'Breaching the far side wall will start collapse',
@ -475,15 +471,16 @@ local function zone_14(x, y, data, _, adjusted_zones)
local entities = data.entities
local buildings = data.buildings
local treasure = data.treasure
data.forest_zone = true
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 40000)
local small_caves = Public.get_noise('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 40000)
--Resource Spots
if smol_areas < -0.71 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -556,14 +553,14 @@ local function zone_13(x, y, data, _, adjusted_zones)
local buildings = data.buildings
local treasure = data.treasure
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 70000)
local small_caves = Public.get_noise('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 70000)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -637,14 +634,14 @@ local function zone_12(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local noise_1 = get_perlin('small_caves', p, seed)
local noise_2 = get_perlin('no_rocks_2', p, seed + 20000)
local smol_areas = get_perlin('smol_areas', p, seed + 60000)
local noise_1 = Public.get_noise('small_caves', p, seed)
local noise_2 = Public.get_noise('no_rocks_2', p, seed + 20000)
local smol_areas = Public.get_noise('smol_areas', p, seed + 60000)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -723,9 +720,9 @@ local function zone_11(x, y, data, _, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local noise_1 = get_perlin('small_caves', p, seed)
local noise_2 = get_perlin('no_rocks_2', p, seed + 10000)
local smol_areas = get_perlin('smol_areas', p, seed + 50000)
local noise_1 = Public.get_noise('small_caves', p, seed)
local noise_2 = Public.get_noise('no_rocks_2', p, seed + 10000)
local smol_areas = Public.get_noise('smol_areas', p, seed + 50000)
if noise_1 > 0.7 then
tiles[#tiles + 1] = {name = 'water', position = p}
@ -738,7 +735,7 @@ local function zone_11(x, y, data, _, adjusted_zones)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -782,7 +779,7 @@ local function zone_11(x, y, data, _, adjusted_zones)
return
end
local noise_forest_location = get_perlin('forest_location', p, seed)
local noise_forest_location = Public.get_noise('forest_location', p, seed)
if noise_forest_location > 0.095 then
if noise_forest_location > 0.6 then
if random(1, 100) > 42 then
@ -819,8 +816,8 @@ local function zone_10(x, y, data, _, adjusted_zones)
local treasure = data.treasure
data.forest_zone = true
local scrapyard = get_perlin('scrapyard', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 45000)
local scrapyard = Public.get_noise('scrapyard', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 45000)
if scrapyard < -0.70 or scrapyard > 0.70 then
tiles[#tiles + 1] = {name = 'grass-3', position = p}
@ -837,7 +834,7 @@ local function zone_10(x, y, data, _, adjusted_zones)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -874,7 +871,7 @@ local function zone_10(x, y, data, _, adjusted_zones)
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
return
end
local noise_forest_location = get_perlin('forest_location', p, seed)
local noise_forest_location = Public.get_noise('forest_location', p, seed)
if scrapyard > -0.15 and scrapyard < 0.15 then
if noise_forest_location > 0.095 then
if random(1, 256) == 1 then
@ -935,12 +932,12 @@ local function zone_9(x, y, data, _, adjusted_zones)
local treasure = data.treasure
local maze_p = {x = floor(p.x - p.x % 10), y = floor(p.y - p.y % 10)}
local maze_noise = get_perlin('no_rocks_2', maze_p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 40000)
local maze_noise = Public.get_noise('no_rocks_2', maze_p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 40000)
if maze_noise > -0.35 and maze_noise < 0.35 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
local no_rocks_2 = get_perlin('no_rocks_2', p, seed)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed)
if random(1, 2) == 1 and no_rocks_2 > -0.5 then
entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p}
end
@ -979,7 +976,7 @@ local function zone_9(x, y, data, _, adjusted_zones)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -1007,12 +1004,12 @@ local function zone_scrap_2(x, y, data, void_or_lab, adjusted_zones)
local treasure = data.treasure
data.scrap_zone = true
local scrapyard_modified = get_perlin('scrapyard_modified', p, seed)
local cave_rivers = get_perlin('cave_rivers', p, seed + 65030)
local scrapyard_modified = Public.get_noise('scrapyard_modified', p, seed)
local cave_rivers = Public.get_noise('cave_rivers', p, seed + 65030)
--Chasms
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local small_caves = Public.get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = void_or_lab, position = p}
@ -1086,7 +1083,7 @@ local function zone_scrap_2(x, y, data, void_or_lab, adjusted_zones)
return
end
local cave_ponds = get_perlin('cave_ponds', p, seed)
local cave_ponds = Public.get_noise('cave_ponds', p, seed)
if cave_ponds < -0.6 and scrapyard_modified > -0.2 and scrapyard_modified < 0.2 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 128) == 1 then
@ -1098,11 +1095,11 @@ local function zone_scrap_2(x, y, data, void_or_lab, adjusted_zones)
--Resource Spots
if cave_rivers < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
local large_caves = get_perlin('large_caves', p, seed)
local large_caves = Public.get_noise('large_caves', p, seed)
if scrapyard_modified > -0.15 and scrapyard_modified < 0.15 then
if floor(large_caves * 10) % 4 < 3 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
@ -1136,12 +1133,12 @@ local function zone_scrap_1(x, y, data, void_or_lab, adjusted_zones)
local treasure = data.treasure
data.scrap_zone = true
local scrapyard = get_perlin('scrapyard', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 35000)
local scrapyard = Public.get_noise('scrapyard', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 35000)
--Chasms
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local small_caves = Public.get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
if small_caves > 0.35 then
tiles[#tiles + 1] = {name = void_or_lab, position = p}
@ -1215,7 +1212,7 @@ local function zone_scrap_1(x, y, data, void_or_lab, adjusted_zones)
return
end
local cave_ponds = get_perlin('cave_ponds', p, seed)
local cave_ponds = Public.get_noise('cave_ponds', p, seed)
if cave_ponds < -0.6 and scrapyard > -0.2 and scrapyard < 0.2 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 128) == 1 then
@ -1227,11 +1224,11 @@ local function zone_scrap_1(x, y, data, void_or_lab, adjusted_zones)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
local large_caves = get_perlin('large_caves', p, seed)
local large_caves = Public.get_noise('large_caves', p, seed)
if scrapyard > -0.15 and scrapyard < 0.15 then
if floor(large_caves * 10) % 4 < 3 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
@ -1264,10 +1261,10 @@ local function zone_7(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local cave_rivers_3 = get_perlin('cave_rivers_3', p, seed)
local cave_rivers_4 = get_perlin('cave_rivers_4', p, seed + 50000)
local no_rocks_2 = get_perlin('no_rocks_2', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 30000)
local cave_rivers_3 = Public.get_noise('cave_rivers_3', p, seed)
local cave_rivers_4 = Public.get_noise('cave_rivers_4', p, seed + 50000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 30000)
if cave_rivers_3 > -0.025 and cave_rivers_3 < 0.025 and no_rocks_2 > -0.6 then
tiles[#tiles + 1] = {name = 'water', position = p}
@ -1285,7 +1282,7 @@ local function zone_7(x, y, data, void_or_lab, adjusted_zones)
return
end
local noise_ores = get_perlin('no_rocks_2', p, seed + 25000)
local noise_ores = Public.get_noise('no_rocks_2', p, seed + 25000)
if cave_rivers_3 > -0.20 and cave_rivers_3 < 0.20 then
tiles[#tiles + 1] = {name = 'grass-' .. floor(cave_rivers_3 * 32) % 3 + 1, position = p}
@ -1341,8 +1338,8 @@ local function zone_7(x, y, data, void_or_lab, adjusted_zones)
end
--Chasms
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local small_caves = Public.get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.25 and noise_cave_ponds > -0.25 then
if small_caves > 0.55 then
tiles[#tiles + 1] = {name = void_or_lab, position = p}
@ -1359,7 +1356,7 @@ local function zone_7(x, y, data, void_or_lab, adjusted_zones)
--Resource Spots
if smol_areas < -0.72 then
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
end
@ -1382,13 +1379,13 @@ local function zone_forest_2(x, y, data, void_or_lab, adjusted_zones)
local treasure = data.treasure
data.forest_zone = true
local large_caves = get_perlin('large_caves', p, seed)
local cave_rivers = get_perlin('cave_rivers', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 25000)
local large_caves = Public.get_noise('large_caves', p, seed)
local cave_rivers = Public.get_noise('cave_rivers', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 25000)
--Chasms
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local small_caves = Public.get_noise('small_caves', p, seed)
if noise_cave_ponds < 0.45 and noise_cave_ponds > -0.45 then
if small_caves > 0.45 then
tiles[#tiles + 1] = {name = void_or_lab, position = p}
@ -1413,7 +1410,7 @@ local function zone_forest_2(x, y, data, void_or_lab, adjusted_zones)
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -1427,7 +1424,7 @@ local function zone_forest_2(x, y, data, void_or_lab, adjusted_zones)
return
end
local noise_forest_location = get_perlin('forest_location', p, seed)
local noise_forest_location = Public.get_noise('forest_location', p, seed)
if cave_rivers > -0.1 and cave_rivers < 0.1 then
local success = place_wagon(data, adjusted_zones)
if success then
@ -1516,9 +1513,9 @@ local function zone_5(x, y, data, void_or_lab, adjusted_zones)
local buildings = data.buildings
local treasure = data.treasure
local small_caves = get_perlin('small_caves', p, seed)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 20000)
local small_caves = Public.get_noise('small_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 20000)
if small_caves > -0.24 and small_caves < 0.24 then
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
@ -1555,7 +1552,7 @@ local function zone_5(x, y, data, void_or_lab, adjusted_zones)
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -1609,10 +1606,10 @@ local function zone_4(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local noise_large_caves = get_perlin('large_caves', p, seed)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local small_caves = get_perlin('dungeons', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 15000)
local noise_large_caves = Public.get_noise('large_caves', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local small_caves = Public.get_noise('dungeons', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 15000)
if abs(noise_large_caves) > 0.7 then
tiles[#tiles + 1] = {name = 'water', position = p}
@ -1691,7 +1688,7 @@ local function zone_4(x, y, data, void_or_lab, adjusted_zones)
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -1708,7 +1705,7 @@ local function zone_4(x, y, data, void_or_lab, adjusted_zones)
if noise_large_caves > -0.2 and noise_large_caves < 0.2 then
--Main Rock Terrain
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
tiles[#tiles + 1] = {name = 'dirt-' .. floor(no_rocks_2 * 8) % 2 + 5, position = p}
if random(1, 512) == 1 then
@ -1740,18 +1737,18 @@ local function zone_3(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_perlin('dungeons', p, seed + 50000)
local small_caves_2 = get_perlin('small_caves_2', p, seed + 70000)
local noise_large_caves = get_perlin('large_caves', p, seed + 60000)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local cave_miner = get_perlin('cave_miner_01', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 60000)
local small_caves = Public.get_noise('dungeons', p, seed + 50000)
local small_caves_2 = Public.get_noise('small_caves_2', p, seed + 70000)
local noise_large_caves = Public.get_noise('large_caves', p, seed + 60000)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local cave_miner = Public.get_noise('cave_miner_01', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 60000)
--Resource Spots
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -1808,7 +1805,7 @@ local function zone_3(x, y, data, void_or_lab, adjusted_zones)
end
--Rivers
local cave_rivers = get_perlin('cave_rivers', p, seed + 100000)
local cave_rivers = Public.get_noise('cave_rivers', p, seed + 100000)
if cave_rivers < 0.024 and cave_rivers > -0.024 then
if noise_cave_ponds > 0.2 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -1818,7 +1815,7 @@ local function zone_3(x, y, data, void_or_lab, adjusted_zones)
return
end
end
local cave_rivers_2 = get_perlin('cave_rivers_2', p, seed)
local cave_rivers_2 = Public.get_noise('cave_rivers_2', p, seed)
if cave_rivers_2 < 0.024 and cave_rivers_2 > -0.024 then
if noise_cave_ponds < 0.4 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -1834,7 +1831,7 @@ local function zone_3(x, y, data, void_or_lab, adjusted_zones)
return
end
local no_rocks = get_perlin('no_rocks', p, seed + 25000)
local no_rocks = Public.get_noise('no_rocks', p, seed + 25000)
--Worm oil Zones
if no_rocks < 0.20 and no_rocks > -0.20 then
if small_caves > 0.35 then
@ -1866,7 +1863,7 @@ local function zone_3(x, y, data, void_or_lab, adjusted_zones)
end
--Main Rock Terrain
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
local success = place_wagon(data, adjusted_zones)
if success then
@ -1906,15 +1903,15 @@ local function zone_2(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_perlin('dungeons', p, seed)
local noise_large_caves = get_perlin('large_caves', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 15000)
local small_caves = Public.get_noise('dungeons', p, seed)
local noise_large_caves = Public.get_noise('large_caves', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 15000)
--Resource Spots
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -1929,7 +1926,7 @@ local function zone_2(x, y, data, void_or_lab, adjusted_zones)
end
if noise_large_caves > -0.75 and noise_large_caves < 0.75 then
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
--Chasms
if noise_cave_ponds < 0.15 and noise_cave_ponds > -0.15 then
@ -1954,7 +1951,7 @@ local function zone_2(x, y, data, void_or_lab, adjusted_zones)
end
--Rivers
local cave_rivers = get_perlin('cave_rivers', p, seed + 100000)
local cave_rivers = Public.get_noise('cave_rivers', p, seed + 100000)
if cave_rivers < 0.037 and cave_rivers > -0.037 then
if noise_cave_ponds < 0.1 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -1982,7 +1979,7 @@ local function zone_2(x, y, data, void_or_lab, adjusted_zones)
return
end
local no_rocks = get_perlin('no_rocks', p, seed + 25000)
local no_rocks = Public.get_noise('no_rocks', p, seed + 25000)
--Worm oil Zones
if no_rocks < 0.20 and no_rocks > -0.20 then
if small_caves > 0.30 then
@ -2014,7 +2011,7 @@ local function zone_2(x, y, data, void_or_lab, adjusted_zones)
end
--Main Rock Terrain
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.80 or no_rocks_2 < -0.80 then
local success = place_wagon(data, adjusted_zones)
if success then
@ -2051,15 +2048,15 @@ local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones)
local treasure = data.treasure
data.forest_zone = true
local small_caves = get_perlin('dungeons', p, seed + 33322)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed + 33333)
local small_caves = Public.get_noise('dungeons', p, seed + 33322)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed + 33333)
--Resource Spots
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -2105,7 +2102,7 @@ local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones)
end
--Rivers
local cave_rivers = get_perlin('cave_rivers', p, seed + 200000)
local cave_rivers = Public.get_noise('cave_rivers', p, seed + 200000)
if cave_rivers < 0.041 and cave_rivers > -0.042 then
if noise_cave_ponds > 0 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -2127,7 +2124,7 @@ local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones)
return
end
local no_rocks = get_perlin('no_rocks', p, seed + 30000)
local no_rocks = Public.get_noise('no_rocks', p, seed + 30000)
--Worm oil Zones
if p.y < -64 + noise_cave_ponds * 10 then
if no_rocks < 0.11 and no_rocks > -0.11 then
@ -2158,7 +2155,7 @@ local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones)
end
--Main Rock Terrain
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 5000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 5000)
if no_rocks_2 > 0.64 or no_rocks_2 < -0.64 then
local success = place_wagon(data, adjusted_zones)
if success then
@ -2179,7 +2176,7 @@ local function zone_forest_1(x, y, data, void_or_lab, adjusted_zones)
treasure[#treasure + 1] = {position = p, chest = 'iron-chest'}
end
tiles[#tiles + 1] = {name = 'landfill', position = p}
local noise_forest_location = get_perlin('forest_location', p, seed)
local noise_forest_location = Public.get_noise('forest_location', p, seed)
if noise_forest_location > 0.095 then
if random(1, 256) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -2234,14 +2231,14 @@ local function zone_1(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_perlin('dungeons', p, seed)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed)
local smol_areas = get_perlin('smol_areas', p, seed)
local small_caves = Public.get_noise('dungeons', p, seed)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed)
local smol_areas = Public.get_noise('smol_areas', p, seed)
if smol_areas < 0.055 and smol_areas > -0.025 then
tiles[#tiles + 1] = {name = 'deepwater-green', position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 32) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -2287,7 +2284,7 @@ local function zone_1(x, y, data, void_or_lab, adjusted_zones)
end
--Rivers
local cave_rivers = get_perlin('cave_rivers', p, seed + 300000)
local cave_rivers = Public.get_noise('cave_rivers', p, seed + 300000)
if cave_rivers < 0.042 and cave_rivers > -0.042 then
if noise_cave_ponds > 0 then
tiles[#tiles + 1] = {name = 'water-shallow', position = p}
@ -2309,7 +2306,7 @@ local function zone_1(x, y, data, void_or_lab, adjusted_zones)
return
end
local no_rocks = get_perlin('no_rocks', p, seed + 50000)
local no_rocks = Public.get_noise('no_rocks', p, seed + 50000)
--Worm oil Zones
if p.y < -64 + noise_cave_ponds * 10 then
if no_rocks < 0.12 and no_rocks > -0.12 then
@ -2340,7 +2337,7 @@ local function zone_1(x, y, data, void_or_lab, adjusted_zones)
end
--Main Rock Terrain
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 75000)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 75000)
if no_rocks_2 > 0.66 or no_rocks_2 < -0.66 then
local success = place_wagon(data, adjusted_zones)
if success then
@ -2360,7 +2357,7 @@ local function zone_1(x, y, data, void_or_lab, adjusted_zones)
if random(1, 2048) == 1 then
treasure[#treasure + 1] = {position = p, chest = 'iron-chest'}
end
local random_tiles = get_perlin('forest_location', p, seed)
local random_tiles = Public.get_noise('forest_location', p, seed)
if random_tiles > 0.095 then
if random_tiles > 0.6 then
if random(1, 100) > 42 then
@ -2398,17 +2395,17 @@ local function starting_zone(x, y, data, void_or_lab, adjusted_zones)
local markets = data.markets
local treasure = data.treasure
local small_caves = get_perlin('dungeons', p, seed + 34883)
local noise_cave_ponds = get_perlin('cave_ponds', p, seed + 28939)
local smol_areas = get_perlin('smol_areas', p, seed + 3992)
local no_rocks_2 = get_perlin('no_rocks_2', p, seed + 1922)
local cave_rivers = get_perlin('cave_rivers', p, seed)
local no_rocks = get_perlin('no_rocks', p, seed)
local small_caves = Public.get_noise('dungeons', p, seed + 34883)
local noise_cave_ponds = Public.get_noise('cave_ponds', p, seed + 28939)
local smol_areas = Public.get_noise('smol_areas', p, seed + 3992)
local no_rocks_2 = Public.get_noise('no_rocks_2', p, seed + 1922)
local cave_rivers = Public.get_noise('cave_rivers', p, seed)
local no_rocks = Public.get_noise('no_rocks', p, seed)
if smol_areas < 0.055 and smol_areas > -0.025 then
entities[#entities + 1] = {name = rock_raffle[random(1, size_of_rock_raffle)], position = p}
if random(1, 32) == 1 then
Generate_resources(buildings, p, zone_settings.zone_depth)
Public.spawn_random_buildings(buildings, p, zone_settings.zone_depth)
end
if random(1, 128) == 1 then
Biters.wave_defense_set_worm_raffle(abs(p.y) * worm_level_modifier)
@ -2624,7 +2621,7 @@ local function process_bits(p, data, adjusted_zones)
adjusted_zones.scrap[index] = true
end
local void_or_tile = WPT.get('void_or_tile')
local void_or_tile = Public.get('void_or_tile')
local x = p.x
local y = p.y
@ -2643,7 +2640,7 @@ local function border_chunk(p, data)
entities[#entities + 1] = {name = trees[random(1, #trees)], position = pos}
end
local noise = get_perlin('dungeons', pos, data.seed)
local noise = Public.get_noise('dungeons', pos, data.seed)
local index = floor(noise * 32) % 4 + 1
tiles[#tiles + 1] = {name = start_ground_tiles[index], position = pos}
@ -2679,10 +2676,10 @@ local function biter_chunk(p, data)
tile_positions[#tile_positions + 1] = p
local disable_spawners = {
callback = Functions.deactivate_callback
callback = Public.deactivate_callback
}
local disable_worms = {
callback = Functions.active_not_destructible_callback
callback = Public.active_not_destructible_callback
}
if random(1, 128) == 1 then
@ -2721,7 +2718,7 @@ function Public.heavy_functions(data)
local p = data.position
local get_tile = surface.get_tile(p)
local adjusted_zones = WPT.get('adjusted_zones')
local adjusted_zones = Public.get('adjusted_zones')
init_terrain(adjusted_zones)
local map_name = 'mtn_v3'
@ -2739,7 +2736,7 @@ function Public.heavy_functions(data)
end
if top_y % zone_settings.zone_depth == 0 and top_y < 0 then
WPT.set('left_top', data.left_top)
Public.set('left_top', data.left_top)
return wall(p, data)
end
@ -2779,7 +2776,7 @@ Event.add(
return
end
local winter_mode = WPT.get('winter_mode')
local winter_mode = Public.get('winter_mode')
if winter_mode then
rendering.draw_sprite(
{
@ -2795,7 +2792,7 @@ Event.add(
end
if left_top.y == -128 and left_top.x == -128 then
local locomotive = WPT.get('locomotive')
local locomotive = Public.get('locomotive')
if locomotive and locomotive.valid then
local position = locomotive.position
for _, entity in pairs(surface.find_entities_filtered({area = {{position.x - 5, position.y - 6}, {position.x + 5, position.y + 10}}, type = 'simple-entity'})) do

View File

@ -1,5 +1,5 @@
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = require 'maps.mountain_fortress_v3.table'
local random = math.random
@ -85,7 +85,7 @@ local function create_kaboom(surface, position, name)
)
end
local function tick_tack_trap(surface, position)
function Public.tick_tack_trap(surface, position)
if not surface then
return
end
@ -101,7 +101,7 @@ local function tick_tack_trap(surface, position)
if not position.y then
return
end
local traps = WPT.get('traps')
local traps = Public.get('traps')
local tick_tack_count = random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not traps[game.tick + t] then
@ -130,7 +130,7 @@ local function tick_tack_trap(surface, position)
end
local function on_tick()
local traps = WPT.get('traps')
local traps = Public.get('traps')
if not traps[game.tick] then
return
end
@ -148,4 +148,4 @@ end
Event.add(defines.events.on_tick, on_tick)
return tick_tack_trap
return Public

View File

@ -1,3 +1,7 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local Public = {}
local math_random = math.random
local math_floor = math.floor
@ -8,9 +12,6 @@ local table_insert = table.insert
local table_remove = table.remove
local table_shuffle = table.shuffle_table
local Global = require 'utils.global'
local BiterHealthBooster = require 'modules.biter_health_booster_v2'
local tick_schedule = {}
Global.register(
tick_schedule,
@ -19,8 +20,8 @@ Global.register(
end
)
local Table = require 'modules.scrap_towny_ffa.table'
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local function get_commmands(target, group)
local commands = {}
@ -67,8 +68,8 @@ local function get_commmands(target, group)
end
local function roll_market()
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
if town_centers == nil or table_size(town_centers) == 0 then
return
end
@ -116,23 +117,23 @@ local function is_swarm_valid(swarm)
end
function Public.validate_swarms()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for k, swarm in pairs(ffatable.swarms) do
for k, swarm in pairs(this.swarms) do
if not is_swarm_valid(swarm) then
table_remove(ffatable.swarms, k)
table_remove(this.swarms, k)
end
end
end
function Public.unit_groups_start_moving()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for _, swarm in pairs(ffatable.swarms) do
for _, swarm in pairs(this.swarms) do
if swarm.group then
if swarm.group.valid then
swarm.group.start_moving()
@ -156,8 +157,8 @@ function Public.swarm(town_center, radius)
if town_center == nil then
return
end
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
local r = radius or 32
@ -170,8 +171,8 @@ function Public.swarm(town_center, radius)
return
end
-- skip if we have to many swarms already
local count = table_size(ffatable.swarms)
local towns = table_size(ffatable.town_centers)
local count = table_size(this.swarms)
local towns = table_size(this.town_centers)
if count > 3 * towns then
return
end
@ -255,7 +256,7 @@ function Public.swarm(town_center, radius)
commands = get_commmands(market, unit_group)
}
)
table_insert(ffatable.swarms, {group = unit_group, timeout = game.tick + 36000})
table_insert(this.swarms, {group = unit_group, timeout = game.tick + 36000})
end
local function on_unit_group_finished_gathering(event)
@ -265,8 +266,8 @@ local function on_unit_group_finished_gathering(event)
local target = entities[1]
if target ~= nil then
local force = target.force
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
local town_center = town_centers[force.name]
-- cancel if relatively new town
if new_town(town_center) then
@ -297,13 +298,10 @@ local function on_tick()
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.swarms = {}
BiterHealthBooster.acid_nova(true)
BiterHealthBooster.check_on_entity_died(true)
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_unit_group_finished_gathering, on_unit_group_finished_gathering)

View File

@ -0,0 +1,363 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Public = {}
local math_floor = math.floor
local table_insert = table.insert
local table_size = table.size
local town_zoning_entity_types = {'wall', 'gate', 'electric-pole', 'ammo-turret', 'electric-turret', 'fluid-turret'}
-- these should be allowed to place inside any base by anyone as neutral
local neutral_whitelist = {
['burner-inserter'] = true,
['car'] = true,
['coin'] = true,
['express-loader'] = true,
['fast-inserter'] = true,
['fast-loader'] = true,
['filter-inserter'] = true,
['inserter'] = true,
['iron-chest'] = true,
['loader'] = true,
['long-handed-inserter'] = true,
['raw-fish'] = true,
['stack-filter-inserter'] = true,
['stack-inserter'] = true,
['steel-chest'] = true,
['tank'] = 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
}
local function refund_item(event, item_name)
if item_name == 'blueprint' then
return
end
local player = game.get_player(event.player_index)
local robot = event.robot
if player and player.valid then
player.insert({name = item_name, count = 1})
return
end
-- return item to robot, but don't replace ghost (otherwise might loop)
if robot and robot.valid then
local inventory = robot.get_inventory(defines.inventory.robot_cargo)
inventory.insert({name = item_name, count = 1})
return
end
end
local function error_floaty(surface, position, msg)
surface.create_entity(
{
name = 'flying-text',
position = position,
text = msg,
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
end
function Public.in_range(pos1, pos2, radius)
if pos1 == nil then
return false
end
if pos2 == nil then
return false
end
if radius < 1 then
return true
end
local dx = pos1.x - pos2.x
local dy = pos1.y - pos2.y
if dx ^ 2 + dy ^ 2 < radius ^ 2 then
return true
end
return false
end
function Public.in_area(position, area_center, area_radius)
if position == nil then
return false
end
if area_center == nil then
return false
end
if area_radius < 1 then
return true
end
if position.x >= area_center.x - area_radius and position.x <= area_center.x + area_radius then
if position.y >= area_center.y - area_radius and position.y <= area_center.y + area_radius then
return true
end
end
return false
end
-- is the position near another town?
function Public.near_another_town(force_name, position, surface, radius)
-- check for nearby town centers
if force_name == nil then
return false
end
local this = ScenarioTable.get_table()
local forces = {}
-- check for nearby town centers
local fail = false
if table_size(this.town_centers) > 0 then
for _, town_center in pairs(this.town_centers) do
if town_center ~= nil then
local market = town_center.market
if market ~= nil and market.valid then
local market_force = market.force
if market_force ~= nil then
if market_force.name ~= nil then
if force_name ~= market_force.name then
table_insert(forces, market_force.name)
if Public.in_range(position, market.position, radius) == true then
fail = true
break
end
end
end
end
end
end
end
if fail == true then
return true
end
end
-- check for nearby town entities
if table.size(forces) > 0 then
if
surface.count_entities_filtered(
{
position = position,
radius = radius,
force = forces,
type = town_zoning_entity_types,
limit = 1
}
) > 0
then
return true
end
end
return false
end
function Public.in_restricted_zone(surface, position)
if surface.name ~= 'nauvis' then
return false
end
local chunk_position = {}
chunk_position.x = math_floor(position.x / 32)
chunk_position.y = math_floor(position.y / 32)
if chunk_position.x <= -33 or chunk_position.x >= 32 or chunk_position.y <= -33 or chunk_position.y >= 32 then
return true
end
return false
end
local function prevent_entity_in_restricted_zone(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 error = false
if Public.in_restricted_zone(surface, position) then
error = true
entity.destroy()
local item = event.item
if name ~= 'entity-ghost' and name ~= 'tile-ghost' and item ~= nil then
refund_item(event, item.name)
end
end
if error == true then
if player_index ~= nil then
local player = game.get_player(player_index)
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, 'Can not build in restricted zone!')
end
end
local function prevent_landfill_in_restricted_zone(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 fail = false
local position
for _, t in pairs(event.tiles) do
local old_tile = t.old_tile
position = t.position
if Public.in_restricted_zone(surface, position) then
fail = true
surface.set_tiles({{name = old_tile.name, position = position}}, true)
end
end
if fail == true then
if player_index ~= nil then
local player = game.get_player(player_index)
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, 'Can not build in restricted zone!')
end
return fail
end
local function process_built_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
local force_name
if player_index ~= nil then
local player = game.get_player(player_index)
force = player.force
force_name = force.name
else
local robot = event.robot
force = robot.force
force_name = force.name
end
if Public.near_another_town(force_name, position, surface, 32) == true then
if neutral_whitelist[name] then
entity.force = game.forces['neutral']
else
entity.destroy()
if player_index ~= nil then
local player = game.get_player(player_index)
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, "Can't build near town!")
if name ~= 'entity-ghost' then
refund_item(event, event.stack.name)
end
return
end
end
if force_name == 'player' or force_name == 'rogue' then
entity.force = game.forces['neutral']
end
end
local function prevent_tiles_near_towns(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 force_name
if player_index ~= nil then
local player = game.get_player(player_index)
if player ~= nil then
local force = player.force
if force ~= nil then
force_name = force.name
end
end
else
local robot = event.robot
if robot ~= nil then
local force = robot.force
if force ~= nil then
force_name = force.name
end
end
end
local fail = false
local position
for _, t in pairs(event.tiles) do
local old_tile = t.old_tile
position = t.position
if Public.near_another_town(force_name, position, surface, 32) == true then
fail = true
surface.set_tiles({{name = old_tile.name, position = position}}, true)
end
end
if fail == true then
if player_index ~= nil then
local player = game.get_player(player_index)
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
end
error_floaty(surface, position, "Can't build near town!")
end
return fail
end
-- called when a player places an item, or a ghost
local function on_built_entity(event)
if prevent_entity_in_restricted_zone(event) then
return
end
if process_built_entities(event) then
return
end
end
local function on_robot_built_entity(event)
if prevent_entity_in_restricted_zone(event) then
return
end
if process_built_entities(event) then
return
end
end
-- called when a player places landfill
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
end
local function on_robot_built_tile(event)
if prevent_landfill_in_restricted_zone(event) then
return
end
if prevent_tiles_near_towns(event) then
return
end
end
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)
return Public

View File

@ -1,10 +1,10 @@
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Color = require 'utils.color_presets'
local Public = {}
local table_shuffle = table.shuffle_table
local Table = require 'modules.scrap_towny_ffa.table'
local Color = require 'utils.color_presets'
local colors = {}
colors[1] = {name = 'Almond', rgb = {239, 222, 205}}
colors[2] = {name = 'Antique Brass', rgb = {205, 149, 117}}
@ -151,8 +151,8 @@ local function is_color_used(color, town_centers)
end
function Public.get_random_color()
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
local rgb
local color = {}
local name
@ -187,8 +187,8 @@ local function random_color(cmd)
player.print('You are not member of a town!', Color.fail)
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
local crayon = Public.get_random_color()

View File

@ -0,0 +1,82 @@
local Event = require 'utils.event'
local Public = {}
local player_ammo_damage_starting_modifiers = {
['bullet'] = 0,
['cannon-shell'] = -0.5,
['capsule'] = 0,
['beam'] = -0.5,
['laser'] = -0.5,
['electric'] = -0.5,
['flamethrower'] = 0,
['grenade'] = -0.5,
['landmine'] = -0.75,
['shotgun-shell'] = 0
}
local player_ammo_damage_modifiers = {
['bullet'] = 0,
['cannon-shell'] = -0.5,
['capsule'] = 0,
['beam'] = -0.5,
['laser'] = -0.5,
['electric'] = -0.5,
['flamethrower'] = 0,
['grenade'] = -0.5,
['landmine'] = -0.5,
['shotgun-shell'] = 0
}
local player_gun_speed_modifiers = {
['bullet'] = 0,
['cannon-shell'] = -0.5,
['capsule'] = -0.5,
['beam'] = -0.5,
['laser'] = 0,
['electric'] = -0.5,
['flamethrower'] = 0,
['grenade'] = -0.5,
['landmine'] = 0,
['shotgun-shell'] = 0
}
function Public.init_player_weapon_damage(force)
for k, v in pairs(player_ammo_damage_starting_modifiers) do
force.set_ammo_damage_modifier(k, v)
end
for k, v in pairs(player_gun_speed_modifiers) do
force.set_gun_speed_modifier(k, v)
end
force.set_turret_attack_modifier('laser-turret', 3)
end
-- After a research is finished and the game applied the modifier, we reduce modifiers to achieve the reduction
local function research_finished(event)
local r = event.research
local p_force = r.force
for _, e in ipairs(r.effects) do
local t = e.type
if t == 'ammo-damage' then
local category = e.ammo_category
local factor = player_ammo_damage_modifiers[category]
if factor then
local current_m = p_force.get_ammo_damage_modifier(category)
p_force.set_ammo_damage_modifier(category, current_m + factor * e.modifier)
end
elseif t == 'gun-speed' then
local category = e.ammo_category
local factor = player_gun_speed_modifiers[category]
if factor then
local current_m = p_force.get_gun_speed_modifier(category)
p_force.set_gun_speed_modifier(category, current_m + factor * e.modifier)
end
end
end
end
Event.add(defines.events.on_research_finished, research_finished)
return Public

View File

@ -1,9 +1,10 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Public = {}
local math_floor = math.floor
local math_log10 = math.log10
local Table = require 'modules.scrap_towny_ffa.table'
local biters = {
[1] = 'small-biter',
[2] = 'medium-biter',
@ -358,7 +359,7 @@ local function get_unit_size(evolution)
if (evolution >= 0.90 and evolution < 1) then
local r = math.random()
if r < 0.5 then
return 3
return 3
end
return 4
end
@ -381,20 +382,26 @@ local function calculate_relative_evolution(evolution_factor, distance_factor)
-- distance factor will be from 0.0 to 1.0 but drop off dramatically towards zero
local log_distance_factor = math_log10(distance_factor * 10 + 1)
local evo = log_distance_factor * evolution_factor
if evo < 0.0 then evo = 0.0 end
if evo > 1.0 then evo = 1.0 end
if evo < 0.0 then
evo = 0.0
end
if evo > 1.0 then
evo = 1.0
end
return evo
end
local function get_relative_biter_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -416,14 +423,16 @@ local function get_relative_biter_evolution(position)
end
local function get_relative_spitter_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -445,14 +454,16 @@ local function get_relative_spitter_evolution(position)
end
local function get_relative_worm_evolution(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local relative_evolution = 0.0
local max_d2 = max_evolution_distance * max_evolution_distance
-- for all of the teams
local teams = ffatable.town_centers
local teams = this.town_centers
for _, town_center in pairs(teams) do
local market = town_center.market
if market == nil or not market.valid then return relative_evolution end
if market == nil or not market.valid then
return relative_evolution
end
-- calculate the distance squared
local d2 = distance_squared(position, market.position)
if d2 < max_d2 then
@ -473,6 +484,17 @@ local function get_relative_worm_evolution(position)
return relative_evolution
end
function Public.get_highest_evolution()
local this = ScenarioTable.get_table()
local max_evo = 0
for _, town_center in pairs(this.town_centers) do
if town_center.evolution.worms > max_evo then
max_evo = town_center.evolution.worms
end
end
return max_evo
end
function Public.get_evolution(position)
return get_relative_biter_evolution(position)
end
@ -636,8 +658,8 @@ local function update_evolution(force_name, technology)
if technology == nil then
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force_name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force_name]
-- town_center is a reference to a global table
if not town_center then
return
@ -694,7 +716,6 @@ local function on_biter_base_built(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_research_finished, on_research_finished)
Event.add(defines.events.on_entity_spawned, on_entity_spawned)
Event.add(defines.events.on_biter_base_built, on_biter_base_built)

View File

@ -1,11 +1,13 @@
--This will add a new game mechanic so that containers with explosives actually go boom when they get damaged.
--Made by MewMew
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local math_min = math.min
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
--local damage_per_explosive = 100
local damage_per_explosive = 50
local empty_tile_damage_decay = 100
@ -1676,18 +1678,18 @@ local circle_coordinates = {
}
local function process_explosion_tile(pos, explosion_index, current_radius)
local ffatable = Table.get_table()
local surface = game.surfaces[ffatable.explosion_schedule[explosion_index].surface]
local this = ScenarioTable.get_table()
local surface = game.surfaces[this.explosion_schedule[explosion_index].surface]
local target_entities = surface.find_entities_filtered({area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.499, pos.y + 0.499}}})
local explosion_animation = 'explosion'
local tile = surface.get_tile(pos)
if tile.name == 'out-of-map' then
if ffatable.explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
if this.explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
explosion_animation = 'big-explosion'
surface.set_tiles({{name = 'dirt-5', position = pos}}, true)
end
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
else
local decay_explosion = true
for _, entity in pairs(target_entities) do
@ -1696,35 +1698,35 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
end
if decay_explosion then
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
end
end
for _, entity in pairs(target_entities) do
if entity.valid then
if entity.health then
if entity.health < ffatable.explosion_schedule[explosion_index].damage_remaining then
if entity.health < this.explosion_schedule[explosion_index].damage_remaining then
explosion_animation = 'big-explosion'
if entity.health > 500 then
explosion_animation = 'big-artillery-explosion'
end
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - entity.health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - entity.health
if entity.name ~= 'character' then
entity.damage(2097152, 'player', 'explosion')
else
entity.die('player')
end
else
entity.damage(ffatable.explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
entity.damage(this.explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
if entity.valid then
ffatable.explosion_schedule[explosion_index].damage_remaining = ffatable.explosion_schedule[explosion_index].damage_remaining - entity.health
this.explosion_schedule[explosion_index].damage_remaining = this.explosion_schedule[explosion_index].damage_remaining - entity.health
end
end
end
end
end
if ffatable.explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if this.explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if math_random(1, 2) == 1 then
explosion_animation = 'big-explosion'
else
@ -1735,7 +1737,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
surface.create_entity({name = explosion_animation, position = pos})
Pollution.explosion(pos, surface, explosion_animation)
if ffatable.explosion_schedule[explosion_index].damage_remaining <= 0 then
if this.explosion_schedule[explosion_index].damage_remaining <= 0 then
return false
end
@ -1752,7 +1754,7 @@ local function volatility(inventory)
end
local function create_explosion_schedule(entity)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local inventory = defines.inventory.chest
if entity.type == 'car' then
inventory = defines.inventory.car_trunk
@ -1764,22 +1766,22 @@ local function create_explosion_schedule(entity)
end
local center_position = entity.position
if not ffatable.explosion_schedule then
ffatable.explosion_schedule = {}
if not this.explosion_schedule then
this.explosion_schedule = {}
end
ffatable.explosion_schedule[#ffatable.explosion_schedule + 1] = {}
ffatable.explosion_schedule[#ffatable.explosion_schedule].surface = entity.surface.name
ffatable.explosion_schedule[#ffatable.explosion_schedule].damage_remaining = damage_per_explosive * explosives_amount
this.explosion_schedule[#this.explosion_schedule + 1] = {}
this.explosion_schedule[#this.explosion_schedule].surface = entity.surface.name
this.explosion_schedule[#this.explosion_schedule].damage_remaining = damage_per_explosive * explosives_amount
for current_radius = 1, 23, 1 do
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius] = {}
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
this.explosion_schedule[#this.explosion_schedule][current_radius] = {}
this.explosion_schedule[#this.explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
local circle_coords = circle_coordinates[current_radius]
for index, tile_position in pairs(circle_coords) do
local pos = {x = center_position.x + tile_position.x, y = center_position.y + tile_position.y}
ffatable.explosion_schedule[#ffatable.explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
this.explosion_schedule[#this.explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
end
end
entity.die('player')
@ -1816,24 +1818,24 @@ local function on_entity_damaged(event)
end
local function on_tick(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local tick = event.tick
if ffatable.explosion_schedule then
if this.explosion_schedule then
local explosion_schedule_is_alive = false
for explosion_index = 1, #ffatable.explosion_schedule, 1 do
if #ffatable.explosion_schedule[explosion_index] > 0 then
for explosion_index = 1, #this.explosion_schedule, 1 do
if #this.explosion_schedule[explosion_index] > 0 then
explosion_schedule_is_alive = true
for radius = 1, #ffatable.explosion_schedule[explosion_index], 1 do
if ffatable.explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #ffatable.explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(ffatable.explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
for radius = 1, #this.explosion_schedule[explosion_index], 1 do
if this.explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #this.explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(this.explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
if not continue_explosion then
ffatable.explosion_schedule[explosion_index] = {}
this.explosion_schedule[explosion_index] = {}
break
end
end
if radius == #ffatable.explosion_schedule[explosion_index] then
ffatable.explosion_schedule[explosion_index] = {}
if radius == #this.explosion_schedule[explosion_index] then
this.explosion_schedule[explosion_index] = {}
end
break
end
@ -1841,17 +1843,10 @@ local function on_tick(event)
end
end
if not explosion_schedule_is_alive then
ffatable.explosion_schedule = nil
this.explosion_schedule = nil
end
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.explosion_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)

View File

@ -0,0 +1,48 @@
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Public = {}
local math_random = math.random
local math_floor = math.floor
function Public.reproduce()
local this = ScenarioTable.get_table()
for _, town_center in pairs(this.town_centers) do
if not town_center then
return
end
if not town_center.market or not town_center.market.valid then
return
end
local surface = town_center.market.surface
local position = town_center.market.position
local fishes = surface.find_entities_filtered({name = 'fish', position = position, radius = 27})
if #fishes == 0 then
return
end
if #fishes >= 100 then
return
end
-- pick a random fish
local t = math_random(1, #fishes)
local fish = fishes[t]
-- test against all other fishes
local guppy = false
for i, f in pairs(fishes) do
if i ~= t then
if math_floor(fish.position.x) == math_floor(f.position.x) and math_floor(fish.position.y) == math_floor(f.position.y) then
guppy = true
end
end
end
if guppy == true then
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
return Public

View File

@ -1,11 +1,13 @@
--This will add a new game mechanic so that containers with certain fluids explode when they get damaged or are destroyed.
--Made by MewMew
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local math_random = math.random
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
local empty_tile_damage_decay = 50
local out_of_map_tile_health = 1500
@ -35,18 +37,18 @@ local function shuffle(tbl)
end
local function process_explosion_tile(pos, explosion_index, current_radius)
local ffatable = Table.get_table()
local surface = game.surfaces[ffatable.fluid_explosion_schedule[explosion_index].surface]
local this = ScenarioTable.get_table()
local surface = game.surfaces[this.fluid_explosion_schedule[explosion_index].surface]
local target_entities = surface.find_entities_filtered({area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.499, pos.y + 0.499}}})
local explosion_animation = 'explosion'
local tile = surface.get_tile(pos)
if tile.name == 'out-of-map' then
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
if this.fluid_explosion_schedule[explosion_index].damage_remaining >= out_of_map_tile_health then
explosion_animation = 'big-explosion'
surface.set_tiles({{name = 'dirt-5', position = pos}}, true)
end
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - out_of_map_tile_health
else
local decay_explosion = true
for _, entity in pairs(target_entities) do
@ -55,33 +57,33 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
end
if decay_explosion then
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - empty_tile_damage_decay
end
end
for _, entity in pairs(target_entities) do
if entity.valid then
if entity.health then
if entity.health <= ffatable.fluid_explosion_schedule[explosion_index].damage_remaining then
if entity.health <= this.fluid_explosion_schedule[explosion_index].damage_remaining then
explosion_animation = 'big-explosion'
if entity.health > 500 then
explosion_animation = 'big-artillery-explosion'
end
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = ffatable.fluid_explosion_schedule[explosion_index].damage_remaining - entity.health
this.fluid_explosion_schedule[explosion_index].damage_remaining = this.fluid_explosion_schedule[explosion_index].damage_remaining - entity.health
if entity.name ~= 'character' then
entity.damage(2097152, 'player', 'explosion')
else
entity.die('player')
end
else
entity.damage(ffatable.fluid_explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
ffatable.fluid_explosion_schedule[explosion_index].damage_remaining = 0
entity.damage(this.fluid_explosion_schedule[explosion_index].damage_remaining, 'player', 'explosion')
this.fluid_explosion_schedule[explosion_index].damage_remaining = 0
end
end
end
end
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if this.fluid_explosion_schedule[explosion_index].damage_remaining > 5000 and current_radius < 2 then
if math_random(1, 2) == 1 then
explosion_animation = 'big-explosion'
else
@ -92,7 +94,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
surface.create_entity({name = explosion_animation, position = pos})
Pollution.explosion(pos, surface, explosion_animation)
if ffatable.fluid_explosion_schedule[explosion_index].damage_remaining <= 0 then
if this.fluid_explosion_schedule[explosion_index].damage_remaining <= 0 then
return false
end
@ -100,7 +102,7 @@ local function process_explosion_tile(pos, explosion_index, current_radius)
end
local function create_explosion_schedule(entity)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local explosives_amount = math_floor(entity.fluidbox[1].amount)
if explosives_amount < 1 then
@ -108,13 +110,13 @@ local function create_explosion_schedule(entity)
end
local center_position = entity.position
if not ffatable.fluid_explosion_schedule then
ffatable.fluid_explosion_schedule = {}
if not this.fluid_explosion_schedule then
this.fluid_explosion_schedule = {}
end
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule + 1] = {}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule].surface = entity.surface.name
this.fluid_explosion_schedule[#this.fluid_explosion_schedule + 1] = {}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule].surface = entity.surface.name
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule].damage_remaining = fluid_damages[entity.fluidbox[1].name] * explosives_amount
this.fluid_explosion_schedule[#this.fluid_explosion_schedule].damage_remaining = fluid_damages[entity.fluidbox[1].name] * explosives_amount
local circle_coordinates = {
[1] = {{x = 0, y = 0}},
@ -890,15 +892,15 @@ local function create_explosion_schedule(entity)
}
for current_radius = 1, 16, 1 do
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius] = {}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius] = {}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius].trigger_tick = game.tick + (current_radius * 8)
local circle_coords = circle_coordinates[current_radius]
circle_coords = shuffle(circle_coords)
for index, tile_position in pairs(circle_coords) do
local pos = {x = center_position.x + tile_position.x, y = center_position.y + tile_position.y}
ffatable.fluid_explosion_schedule[#ffatable.fluid_explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
this.fluid_explosion_schedule[#this.fluid_explosion_schedule][current_radius][index] = {x = pos.x, y = pos.y}
end
end
entity.die('player')
@ -932,24 +934,24 @@ local function on_entity_damaged(event)
end
local function on_tick(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local tick = event.tick
if ffatable.fluid_explosion_schedule then
if this.fluid_explosion_schedule then
local explosion_schedule_is_alive = false
for explosion_index = 1, #ffatable.fluid_explosion_schedule, 1 do
if #ffatable.fluid_explosion_schedule[explosion_index] > 0 then
for explosion_index = 1, #this.fluid_explosion_schedule, 1 do
if #this.fluid_explosion_schedule[explosion_index] > 0 then
explosion_schedule_is_alive = true
for radius = 1, #ffatable.fluid_explosion_schedule[explosion_index], 1 do
if ffatable.fluid_explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #ffatable.fluid_explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(ffatable.fluid_explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
for radius = 1, #this.fluid_explosion_schedule[explosion_index], 1 do
if this.fluid_explosion_schedule[explosion_index][radius].trigger_tick == tick then
for tile_index = 1, #this.fluid_explosion_schedule[explosion_index][radius], 1 do
local continue_explosion = process_explosion_tile(this.fluid_explosion_schedule[explosion_index][radius][tile_index], explosion_index, radius)
if not continue_explosion then
ffatable.fluid_explosion_schedule[explosion_index] = {}
this.fluid_explosion_schedule[explosion_index] = {}
break
end
end
if radius == #ffatable.fluid_explosion_schedule[explosion_index] then
ffatable.fluid_explosion_schedule[explosion_index] = {}
if radius == #this.fluid_explosion_schedule[explosion_index] then
this.fluid_explosion_schedule[explosion_index] = {}
end
break
end
@ -957,17 +959,10 @@ local function on_tick(event)
end
end
if not explosion_schedule_is_alive then
ffatable.fluid_explosion_schedule = nil
this.fluid_explosion_schedule = nil
end
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.fluid_explosion_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)

View File

@ -0,0 +1,134 @@
local Event = require 'utils.event'
local Public = {}
local info = [[This is the wasteland. Who will survive?
In this mode, players build towns and fight against other towns and the biters.
The Comfy gui has been disabled since it contains too many goodies.
Have fun and be comfy ^.^]]
local info_adv =
[[
# Changelog (21th October 2022):
- Fixed player spawn issue
- Fixed map random seed
- Made tank and car extremely rare to get via scrap
- Suicide command has been added. The poison pill will kill the character after 3 minutes
- Game will automatically reset whenever a town reaches 48h of survival time
- PvP Shield has been removed
- Combat balance overhaul (see "Bonuses" button top right to check modifiers)
- Town player limit fixes
- Improved base defenses and offline survivability
- Loads of bugfixes including freezes and desyncs
# 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 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 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 NEWNAME (chat command) to rename your town
# 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.
- 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
return
end
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
b.style.minimal_width = 80
b.style.top_padding = 1
b.style.left_padding = 1
b.style.right_padding = 1
b.style.bottom_padding = 1
end
function Public.show(player, info_type)
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
end
local frame = player.gui.center.add {type = 'frame', name = 'towny_map_intro_frame'}
frame = frame.add {type = 'frame', direction = 'vertical'}
local t = frame.add {type = 'table', column_count = 2}
local label = t.add {type = 'label', caption = 'COMFY Towny: Wasteland survival'}
label.style.font = 'heading-1'
label.style.font_color = {r = 0.85, g = 0.85, b = 0.85}
label.style.right_padding = 8
frame.add {type = 'line'}
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}
end
function Public.close(event)
if not event.element then
return
end
if not event.element.valid then
return
end
local parent = event.element.parent
for _ = 1, 4, 1 do
if not parent then
return
end
if parent.name == 'towny_map_intro_frame' then
parent.destroy()
return
end
parent = parent.parent
end
end
function Public.toggle(event)
if not event.element then
return
end
if not event.element.valid then
return
end
if event.element.name == 'towny_map_intro_button' then
local player = game.players[event.player_index]
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
else
Public.show(player, 'adv')
end
end
end
local function on_gui_click(event)
Public.close(event)
Public.toggle(event)
end
Event.add(defines.events.on_gui_click, on_gui_click)
return Public

View File

@ -0,0 +1,22 @@
local Public = {}
local function initialize_limbo()
if game.surfaces['limbo'] then
-- clear the surface
game.surfaces['limbo'].clear(false)
else
game.create_surface('limbo')
end
local surface = game.surfaces['limbo']
surface.generate_with_lab_tiles = true
surface.peaceful_mode = true
surface.always_day = true
surface.freeze_daytime = true
surface.clear(true)
end
function Public.initialize()
initialize_limbo()
end
return Public

View File

@ -1,10 +1,13 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Public = {}
local Table = require 'modules.scrap_towny_ffa.table'
function Public.reset()
local ffatable = Table.get_table()
if ffatable.testing_mode then return end
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for index = 1, table.size(game.forces), 1 do
local force = game.forces[index]
if force ~= nil then
@ -16,7 +19,9 @@ end
local function add_force(id, force_name)
local forces = rendering.get_forces(id)
for _, force in ipairs(forces) do
if force.name == force_name or force == force_name then return end
if force.name == force_name or force == force_name then
return
end
end
forces[#forces + 1] = force_name
rendering.set_forces(id, forces)
@ -40,8 +45,12 @@ local function on_chunk_charted(event)
local markets = surface.find_entities_filtered({area = area, name = 'market'})
for _, market in pairs(markets) do
local force_name = market.force.name
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force_name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force_name]
if not town_center then
return
end
-- town caption
local town_caption = town_center.town_caption
update_forces(town_caption)
@ -53,7 +62,6 @@ local function on_chunk_charted(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_chunk_charted, on_chunk_charted)
return Public

View File

@ -1,197 +1,228 @@
require 'modules.custom_death_messages'
require 'modules.flashlight_toggle_button'
require 'modules.global_chat_toggle'
require 'modules.worms_create_oil_patches'
require 'modules.biters_yield_coins'
require 'modules.scrap_towny_ffa.mining'
require 'modules.scrap_towny_ffa.on_tick_schedule'
require 'modules.scrap_towny_ffa.building'
require 'modules.scrap_towny_ffa.spaceship'
require 'modules.scrap_towny_ffa.town_center'
require 'modules.scrap_towny_ffa.market'
require 'modules.scrap_towny_ffa.slots'
require 'modules.scrap_towny_ffa.wreckage_yields_scrap'
require 'modules.scrap_towny_ffa.rocks_yield_ore_veins'
require 'modules.scrap_towny_ffa.spawners_contain_biters'
require 'modules.scrap_towny_ffa.explosives_are_explosive'
require 'modules.scrap_towny_ffa.fluids_are_explosive'
require 'modules.scrap_towny_ffa.trap'
require 'modules.scrap_towny_ffa.turrets_drop_ammo'
require 'modules.scrap_towny_ffa.combat_balance'
require 'maps.scrap_towny_ffa.reset'
require 'maps.scrap_towny_ffa.mining'
require 'maps.scrap_towny_ffa.building'
require 'maps.scrap_towny_ffa.spaceship'
require 'maps.scrap_towny_ffa.town_center'
require 'maps.scrap_towny_ffa.market'
require 'maps.scrap_towny_ffa.slots'
require 'maps.scrap_towny_ffa.wreckage_yields_scrap'
require 'maps.scrap_towny_ffa.rocks_yield_ore_veins'
require 'maps.scrap_towny_ffa.worms_create_oil_patches'
require 'maps.scrap_towny_ffa.spawners_contain_biters'
require 'maps.scrap_towny_ffa.explosives_are_explosive'
require 'maps.scrap_towny_ffa.fluids_are_explosive'
require 'maps.scrap_towny_ffa.trap'
require 'maps.scrap_towny_ffa.turrets_drop_ammo'
require 'maps.scrap_towny_ffa.vehicles'
require 'maps.scrap_towny_ffa.suicide'
local Event = require 'utils.event'
local Alert = require 'utils.alert'
local Autostash = require 'modules.autostash'
local MapDefaults = require 'maps.scrap_towny_ffa.map_defaults'
local BottomFrame = require 'utils.gui.bottom_frame'
local Table = require 'modules.scrap_towny_ffa.table'
local Nauvis = require 'modules.scrap_towny_ffa.nauvis'
local Biters = require 'modules.scrap_towny_ffa.biters'
local Pollution = require 'modules.scrap_towny_ffa.pollution'
local Fish = require 'modules.scrap_towny_ffa.fish_reproduction'
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 ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Nauvis = require 'maps.scrap_towny_ffa.nauvis'
local Biters = require 'maps.scrap_towny_ffa.biters'
local Pollution = require 'maps.scrap_towny_ffa.pollution'
local Fish = require 'maps.scrap_towny_ffa.fish_reproduction'
local Team = require 'maps.scrap_towny_ffa.team'
local Radar = require 'maps.scrap_towny_ffa.limited_radar'
local Limbo = require 'maps.scrap_towny_ffa.limbo'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local mod_gui = require('mod-gui')
local Gui = require 'utils.gui'
local Color = require 'utils.color_presets'
local Server = require 'utils.server'
local Where = require 'utils.commands.where'
local Inventory = require 'modules.show_inventory'
-- for testing purposes only!!!
local testing_mode = false
-- how long in ticks between spawn and death will be considered spawn kill (10 seconds)
local max_ticks_between_spawns = 60 * 10
-- how many players must login before teams are teams_enabled
local min_players_for_enabling_towns = 0
local function load_buffs(player)
if player.force.name ~= 'player' and player.force.name ~= 'rogue' then
return
local function spairs(t)
local keys = {}
for k in pairs(t) do
keys[#keys + 1] = k
end
local ffatable = Table.get_table()
local player_index = player.index
if player.character == nil then
return
end
if ffatable.buffs[player_index] == nil then
ffatable.buffs[player_index] = {}
end
if ffatable.buffs[player_index].character_inventory_slots_bonus ~= nil then
player.character.character_inventory_slots_bonus = ffatable.buffs[player_index].character_inventory_slots_bonus
end
if ffatable.buffs[player_index].character_mining_speed_modifier ~= nil then
player.character.character_mining_speed_modifier = ffatable.buffs[player_index].character_mining_speed_modifier
end
if ffatable.buffs[player_index].character_crafting_speed_modifier ~= nil then
player.character.character_crafting_speed_modifier = ffatable.buffs[player_index].character_crafting_speed_modifier
table.sort(
keys,
function(a, b)
return t[b] < t[a]
end
)
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
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,
['show-electric-network'] = false,
['show-turret-range'] = false,
['show-pollution'] = false,
['show-train-station-names'] = false,
['show-player-names'] = false,
['show-networkless-logistic-members'] = false,
['show-non-standard-map-info'] = false
}
player.show_on_map = false
--player.game_view_settings.show_side_menu = false
Info.toggle_button(player)
Team.set_player_color(player)
if player.force ~= game.forces.player then
local function init_score_board(player)
local this = ScenarioTable.get_table()
local saved_frame = this.score_gui_frame[player.index]
if saved_frame and saved_frame.valid then
return
end
if player.online_time == 0 then
Info.show(player)
if testing_mode then
ffatable.towns_enabled = true
else
ffatable.players = ffatable.players + 1
if ffatable.players >= min_players_for_enabling_towns then
ffatable.towns_enabled = true
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
this.score_gui_frame[player.index] = frame
end
local function update_score()
local this = ScenarioTable.get_table()
if this.winner then
if not this.game_won then
this.game_won = true
this.game_reset_tick = 5400
Alert.alert_all_players(900, 'Winner winner chicken dinner!\n[color=red]' .. this.winner.name .. '[/color] has won the game!', Color.white, 'restart_required', 1.0)
for _, player in pairs(game.connected_players) do
player.play_sound {path = 'utility/game_won', volume_modifier = 0.75}
end
local winner = this.winner
local message = {
title = 'Game over',
description = 'Town statistics is below',
color = 'success',
field1 = {
text1 = 'Town won:',
text2 = winner.name,
inline = 'false'
},
field2 = {
text1 = 'Town researched:',
text2 = winner.name .. ' with a score of ' .. winner.research_counter .. ' techs!',
inline = 'false'
},
field3 = {
text1 = 'Town upgrades:',
text2 = winner.name .. ' upgraded their town with:\nCrafting speed:' .. winner.upgrades.crafting_speed .. '\nMining speed:' .. winner.upgrades.mining_speed,
inline = 'false'
},
field4 = {
text1 = 'Town health:',
text2 = winner.name .. ' had a health of ' .. winner.health .. ' left!',
inline = 'false'
},
field5 = {
text1 = 'Town coins:',
text2 = winner.name .. ' had ' .. winner.coin_balance .. ' coins stashed!',
inline = 'false'
}
}
Server.to_discord_embed_parsed(message)
end
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'}
end
-- first time spawn point
local spawn_point = Spawn.get_new_spawn_point(player, surface)
ffatable.strikes[player.name] = 0
Spawn.clear_spawn_point(spawn_point, surface)
-- reset cooldown
ffatable.cooldowns_town_placement[player.index] = 0
ffatable.last_respawn[player.name] = 0
player.teleport(spawn_point, surface)
return
end
load_buffs(player)
if not ffatable.requests[player.index] or ffatable.requests[player.index] ~= 'kill-character' then
return
end
if player.character then
if player.character.valid then
player.character.die()
for _, player in pairs(game.connected_players) do
local frame = this.score_gui_frame[player.index]
if not (frame and frame.valid) then
init_score_board(player)
end
end
ffatable.requests[player.index] = nil
end
if frame and frame.valid then
frame.clear()
local function on_player_respawned(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
local surface = player.surface
Team.give_player_items(player)
if player.force == game.forces['rogue'] then
Team.set_player_to_outlander(player)
end
if player.force == game.forces['player'] then
Team.give_key(player.index)
end
local inner_frame = frame.add {type = 'frame', style = 'inside_shallow_frame', direction = 'vertical'}
-- get_spawn_point will always return a valid spawn
local spawn_point = Spawn.get_spawn_point(player, surface)
local subheader = inner_frame.add {type = 'frame', style = 'subheader_frame'}
subheader.style.horizontally_stretchable = true
subheader.style.vertical_align = 'center'
-- reset cooldown
ffatable.last_respawn[player.name] = game.tick
player.teleport(spawn_point, surface)
load_buffs(player)
end
subheader.add {type = 'label', style = 'subheader_label', caption = {'', 'Survive 2 days (48h) to win!'}}
local function on_player_died(event)
local ffatable = Table.get_table()
local player = game.players[event.player_index]
if ffatable.strikes[player.name] == nil then
ffatable.strikes[player.name] = 0
end
if not next(subheader.children) then
subheader.destroy()
end
local ticks_elapsed = game.tick - ffatable.last_respawn[player.name]
if ticks_elapsed < max_ticks_between_spawns then
ffatable.strikes[player.name] = ffatable.strikes[player.name] + 1
else
ffatable.strikes[player.name] = 0
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 (players online/total)', '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(this.town_centers) do
if town_center ~= nil then
local age = game.tick - town_center.creation_tick
town_ages[town_center] = age
end
end
local rank = 1
for town_center, age in spairs(town_ages) do
local position = information_table.add {type = 'label', caption = '#' .. rank}
if town_center == this.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 .. ' (' .. #town_center.market.force.connected_players .. '/' .. #town_center.market.force.players .. ')'
}
label.style.font = 'default-semibold'
label.style.font_color = town_center.color
local age_hours = age / 60 / 3600
local total_age = string.format('%.1f', age_hours)
information_table.add {type = 'label', caption = total_age .. 'h'}
rank = rank + 1
if tonumber(total_age) >= this.required_time_to_win then
this.winner = {
name = town_center.town_name,
research_counter = town_center.research_counter,
upgrades = town_center.upgrades,
health = town_center.health,
coin_balance = town_center.coin_balance
}
end
end
-- Outlander section
information_table.add {type = 'label', caption = '-'}
local outlander_on = #game.forces['player'].connected_players + #game.forces['rogue'].connected_players
local outlander_total = #game.forces['player'].players + #game.forces['rogue'].players
local label =
information_table.add {
type = 'label',
caption = 'Outlanders' .. ' (' .. outlander_on .. '/' .. outlander_total .. ')'
}
label.style.font_color = {170, 170, 170}
information_table.add {type = 'label', caption = '-'}
end
end
end
local function on_init()
Autostash.insert_into_furnace(true)
Autostash.insert_to_neutral_chests(true)
Autostash.insert_into_wagon(true)
Autostash.bottom_button(true)
BottomFrame.reset()
BottomFrame.activate_custom_buttons(true)
Where.module_disabled(true)
Inventory.module_disabled(true)
--log("on_init")
game.enemy_has_vision_on_land_mines = false
game.draw_resource_selection = true
game.disable_tutorial_triggers()
local ffatable = Table.get_table()
ffatable.last_respawn = {}
ffatable.last_death = {}
ffatable.strikes = {}
ffatable.testing_mode = testing_mode
ffatable.spawn_point = {}
ffatable.buffs = {}
ffatable.players = 0
ffatable.towns_enabled = true
MapDefaults.initialize()
Limbo.initialize()
Nauvis.initialize()
Team.initialize()
end
@ -220,10 +251,63 @@ local function on_nth_tick(event)
tick_actions[seconds]()
end
local Event = require 'utils.event'
local function handle_changes()
ScenarioTable.set('restart', true)
ScenarioTable.set('soft_reset', false)
print('Received new changes from backend.')
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
Event.on_init(on_init)
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)
Event.add(Server.events.on_changes_detected, handle_changes)
--Disable the comfy main gui since we got too many goodies there.
Event.add(
defines.events.on_gui_click,
function(event)
local element = event.element
if not element or not element.valid then
return
end
local fish_button = Gui.top_main_gui_button
local main_frame_name = Gui.main_frame_name
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
if element.name == fish_button then
if not player.admin then
if player.gui.left[main_frame_name] and player.gui.left[main_frame_name].valid then
player.gui.left[main_frame_name].destroy()
end
return player.print('Comfy panel is disabled in this scenario.', Color.fail)
end
end
end
)
require 'maps.scrap_towny_ffa.scrap_towny_ffa_layout'

View File

@ -0,0 +1,71 @@
local Public = {}
function Public.initialize()
-- difficulty settings
game.difficulty_settings.recipe_difficulty = defines.difficulty_settings.recipe_difficulty.normal
game.difficulty_settings.technology_difficulty = defines.difficulty_settings.technology_difficulty.normal
game.difficulty_settings.technology_price_multiplier = 0.50
game.difficulty_settings.research_queue_from_the_start = 'always'
-- pollution settings
game.map_settings.pollution.enabled = true
game.map_settings.pollution.diffusion_ratio = 0.02 -- amount that is diffused to neighboring chunk each second
game.map_settings.pollution.min_to_diffuse = 15 -- minimum number of pollution units on the chunk to start diffusing
game.map_settings.pollution.ageing = 1 -- percent of pollution eaten by a chunk's tiles per second
game.map_settings.pollution.expected_max_per_chunk = 150 -- anything greater than this number of pollution units is visualized similarly
game.map_settings.pollution.min_to_show_per_chunk = 50
game.map_settings.pollution.min_pollution_to_damage_trees = 60
game.map_settings.pollution.pollution_with_max_forest_damage = 150
game.map_settings.pollution.pollution_per_tree_damage = 50
game.map_settings.pollution.pollution_restored_per_tree_damage = 10
game.map_settings.pollution.max_pollution_to_restore_trees = 20
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1
-- enemy evolution settings
game.map_settings.enemy_evolution.enabled = true
game.map_settings.enemy_evolution.time_factor = 0.0 -- percent increase in the evolution factor per second
game.map_settings.enemy_evolution.destroy_factor = 0.0 -- percent increase in the evolution factor for each spawner destroyed
game.map_settings.enemy_evolution.pollution_factor = 0.0 -- percent increase in the evolution factor for each pollution unit
-- enemy expansion settings
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_distance = 7 -- maximum distance in chunks from the nearest base (4 = 128 tiles)
game.map_settings.enemy_expansion.friendly_base_influence_radius = 4 -- consider other nests within radius number of chunks (2 = 64 tiles)
game.map_settings.enemy_expansion.other_base_coefficient = 2.0 -- multiply by coefficient for friendly bases
game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 -- multiply by coefficient for friendly bases (^distance)
game.map_settings.enemy_expansion.enemy_building_influence_radius = 4 -- consider player buildings within radius number of chunks
game.map_settings.enemy_expansion.building_coefficient = 1.0 -- multiply by coefficient for player buildings
game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.5 -- multiply by coefficient for player buildings (^distance)
game.map_settings.enemy_expansion.max_colliding_tiles_coefficient = 0.9 -- percent of unbuildable tiles to not be considered a candidate
game.map_settings.enemy_expansion.settler_group_min_size = 4 -- min size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.settler_group_max_size = 12 -- max size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.min_expansion_cooldown = 1200 -- minimum time before next expansion
game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 -- maximum time before next expansion
-- unit group settings
game.map_settings.unit_group.min_group_gathering_time = 400
game.map_settings.unit_group.max_group_gathering_time = 2400
game.map_settings.unit_group.max_wait_time_for_late_members = 3600
game.map_settings.unit_group.max_group_radius = 30.0
game.map_settings.unit_group.min_group_radius = 5.0
game.map_settings.unit_group.max_member_speedup_when_behind = 1.4
game.map_settings.unit_group.max_member_slowdown_when_ahead = 0.6
game.map_settings.unit_group.max_group_slowdown_factor = 0.3
game.map_settings.unit_group.max_group_member_fallback_factor = 3
game.map_settings.unit_group.member_disown_distance = 10
game.map_settings.unit_group.tick_tolerance_when_member_arrives = 60
game.map_settings.unit_group.max_gathering_unit_groups = 30
game.map_settings.unit_group.max_unit_group_size = 200
---- steering settings
--game.map_settings.steering.default.radius = 1.2
--game.map_settings.steering.default.separation_force = 0.005
--game.map_settings.steering.default.separation_factor = 1.2
--game.map_settings.steering.default.force_unit_fuzzy_goto_behavior = false
--game.map_settings.steering.moving.radius = 3
--game.map_settings.steering.moving.separation_force = 0.01
--game.map_settings.steering.moving.separation_factor = 3
--game.map_settings.steering.moving.force_unit_fuzzy_goto_behavior = false
end
return Public

View File

@ -1,14 +1,15 @@
local table_insert = table.insert
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Town_center = require 'maps.scrap_towny_ffa.town_center'
local Table = require 'modules.scrap_towny_ffa.table'
local Town_center = require 'modules.scrap_towny_ffa.town_center'
local table_insert = table.insert
local upgrade_functions = {
-- Upgrade Town Center Health
[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
@ -22,7 +23,7 @@ local upgrade_functions = {
local market = town_center.market
local force = market.force
local surface = market.surface
if force.character_inventory_slots_bonus + 5 > 100 then
if force.character_inventory_slots_bonus + 5 > 50 then
return false
end
force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + 5
@ -78,12 +79,12 @@ local upgrade_functions = {
end,
-- Set Spawn Point
[7] = function(town_center, player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local market = town_center.market
local force = market.force
local surface = market.surface
local spawn_point = force.get_spawn_position(surface)
ffatable.spawn_point[player.name] = spawn_point
this.spawn_point[player.index] = spawn_point
surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1})
return false
end
@ -105,18 +106,18 @@ 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!'}
end
if force.character_inventory_slots_bonus + 5 <= 100 then
if force.character_inventory_slots_bonus + 5 <= 50 then
special_offers[2] = {{{'coin', (force.character_inventory_slots_bonus / 5 + 1) * 50}}, 'Upgrade Backpack +5 Slot'}
else
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% (Drills, Pumps, Scrap)'}
else
special_offers[3] = {{}, 'Maximum Productivity upgrades reached!'}
end
@ -131,36 +132,39 @@ 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', (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 = 15}})
table_insert(market_items, {price = {{'wood', 1}}, offer = {type = 'give-item', item = 'coin', count = 3}})
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}})
table_insert(market_items, {price = {{'empty-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = 1}})
table_insert(market_items, {price = {{'car', 1}}, offer = {type = 'give-item', item = 'coin', count = 10}})
table_insert(market_items, {price = {{'tank', 1}}, offer = {type = 'give-item', item = 'coin', count = 50}})
for _, item in pairs(market_items) do
market.add_market_item(item)
@ -168,7 +172,7 @@ local function set_offers(town_center)
end
local function refresh_offers(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.entity or event.market
if not market then
@ -180,7 +184,7 @@ local function refresh_offers(event)
if market.name ~= 'market' then
return
end
local town_center = ffatable.town_centers[market.force.name]
local town_center = this.town_centers[market.force.name]
if not town_center then
return
end
@ -191,19 +195,19 @@ local function refresh_offers(event)
if player.opened ~= nil then
player.opened = nil
player.surface.create_entity(
{
name = 'flying-text',
position = {market.position.x - 1.75, market.position.y},
text = 'Sorry, we are closed.',
color = {r = 1, g = 0.68, b = 0.26}
}
{
name = 'flying-text',
position = {market.position.x - 1.75, market.position.y},
text = 'Sorry, we are closed.',
color = {r = 1, g = 0.68, b = 0.26}
}
)
end
end
end
local function offer_purchased(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
@ -211,7 +215,7 @@ local function offer_purchased(event)
if not upgrade_functions[offer_index] then
return
end
local town_center = ffatable.town_centers[market.force.name]
local town_center = this.town_centers[market.force.name]
if not town_center then
return
end
@ -271,26 +275,34 @@ local function is_loader(entity)
end
local function is_filtered_inserter(entity)
return entity.name == 'filter-inserter' or entity.name == "stack-filter-inserter"
return entity.name == 'filter-inserter' or entity.name == 'stack-filter-inserter'
end
local function max_stack_size(entity)
if is_loader(entity) then return 1 end
if (entity.name == "stack-inserter" or entity.name == "stack-filter-inserter") then
if is_loader(entity) then
return 1
end
if (entity.name == 'stack-inserter' or entity.name == 'stack-filter-inserter') then
local override = entity.inserter_stack_size_override
if override > 0 then return override end
if override > 0 then
return override
end
local capacity = entity.force.stack_inserter_capacity_bonus
return 1 + capacity
else
local override = entity.inserter_stack_size_override
if override > 0 then return override end
if override > 0 then
return override
end
local bonus = entity.force.inserter_stack_size_bonus
return 1 + bonus
end
end
local function get_connected_entities(market)
if not market.valid then return {} end
if not market.valid then
return {}
end
local items = {
'burner-inserter',
'inserter',
@ -304,7 +316,7 @@ local function get_connected_entities(market)
'express-loader'
}
local items2 = {
'long-handed-inserter',
'long-handed-inserter'
}
local bb = market.bounding_box
local s = market.surface
@ -312,7 +324,7 @@ local function get_connected_entities(market)
local entities = s.find_entities_filtered({area = area, name = items})
local area2 = {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 entities2 = s.find_entities_filtered({area = area2, name = items2})
for k,v in pairs(entities2) do
for k, v in pairs(entities2) do
entities[k] = v
end
return entities
@ -334,19 +346,19 @@ end
local function get_loader_market_position(entity)
-- gets the position of the market relative to the loader
local position = {x=entity.position.x, y=entity.position.y}
local position = {x = entity.position.x, y = entity.position.y}
local orientation = entity.orientation
local type = entity.loader_type
if (orientation == 0.0 and type == "input") or (orientation == 0.5 and type == "output") then
if (orientation == 0.0 and type == 'input') or (orientation == 0.5 and type == 'output') then
position.y = position.y - 1.5
end
if (orientation == 0.25 and type == "input") or (orientation == 0.75 and type == "output") then
if (orientation == 0.25 and type == 'input') or (orientation == 0.75 and type == 'output') then
position.x = position.x + 1.5
end
if (orientation == 0.5 and type == "input") or (orientation == 0.0 and type == "output") then
if (orientation == 0.5 and type == 'input') or (orientation == 0.0 and type == 'output') then
position.y = position.y + 1.5
end
if (orientation == 0.75 and type == "input") or (orientation == 0.25 and type == "output") then
if (orientation == 0.75 and type == 'input') or (orientation == 0.25 and type == 'output') then
position.x = position.x - 1.5
end
return position
@ -404,7 +416,7 @@ local function trade_coin_for_items(town_center, market, trade)
town_center.output_buffer[item] = 0
end
while town_center.coin_balance - price >= 0 do
if town_center.output_buffer[item] == 0 then
if town_center.output_buffer[item] == 0 then
town_center.coin_balance = town_center.coin_balance - price
town_center.output_buffer[item] = town_center.output_buffer[item] + count
else
@ -418,7 +430,9 @@ local function handle_loader_output(town_center, market, entity, index)
local line = entity.get_transport_line(index)
-- get loader filters
local filter = get_loader_filter(entity, index)
if filter == nil then return end
if filter == nil then
return
end
if filter == 'coin' then
-- output for coins
while town_center.coin_balance > 0 and line.can_insert_at_back() do
@ -450,12 +464,16 @@ end
local function handle_inserter_output(town_center, market, entity)
-- get inserter filter
local filter = get_inserter_filter(entity)
if filter == nil then return end
if filter == nil then
return
end
local amount = max_stack_size(entity)
local stack = {name = 'coin', count = amount}
if filter == 'coin' then
-- output coins
if amount > town_center.coin_balance then amount = town_center.coin_balance end
if amount > town_center.coin_balance then
amount = town_center.coin_balance
end
stack.count = amount
if town_center.coin_balance > 0 then
town_center.coin_balance = town_center.coin_balance - amount
@ -621,26 +639,26 @@ local function get_entity_mode(market, entity)
if inside(ppos, bb) then
return 'output'
end
return "none"
return 'none'
end
end
local function handle_connected_entity(town_center, market, entity)
local mode = get_entity_mode(market, entity)
if mode == "input" then
if mode == 'input' then
handle_market_input(town_center, market, entity)
end
if mode == "output" then
if mode == 'output' then
handle_market_output(town_center, market, entity)
end
end
local function on_tick(_)
local ffatable = Table.get_table()
if not ffatable.town_centers then
local this = ScenarioTable.get_table()
if not this.town_centers then
return
end
for _, town_center in pairs(ffatable.town_centers) do
for _, town_center in pairs(this.town_centers) do
-- get connected entities on markets
local market = town_center.market
local entities = get_connected_entities(market)
@ -653,7 +671,6 @@ local function on_tick(_)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)

View File

@ -1,4 +1,5 @@
local Table = require 'modules.scrap_towny_ffa.table'
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local crash_site = {
-- simple entity with owner
@ -43,19 +44,20 @@ 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()
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
for index, player in pairs(game.players) do
if player.character ~= nil then
local mining = player.mining_state.mining
if ffatable.mining[index] ~= mining then
ffatable.mining[index] = mining
if this.mining[index] ~= mining then
this.mining[index] = mining
-- state change
if mining == true then
--log(player.name .. " started mining")
@ -67,14 +69,14 @@ local function on_tick()
if is_crash_site(target) then
-- mining crash site
mining_sound(player)
ffatable.mining_target[index] = target
this.mining_target[index] = target
end
end
else
--log(player.name .. " stopped mining")
local target = ffatable.mining_target[index]
local target = this.mining_target[index]
if target ~= nil then
ffatable.mining_target[index] = nil
this.mining_target[index] = nil
end
end
else
@ -94,13 +96,4 @@ local function on_tick()
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.mining = {}
ffatable.mining_entity = {}
ffatable.mining_target = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)

View File

@ -0,0 +1,216 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local math_random = math.random
local table_shuffle = table.shuffle_table
local Public = {}
--local Server = require 'utils.server'
local map_width = 2560
local map_height = 2560
function Public.nuke(position)
local surface = game.surfaces['nauvis']
surface.create_entity({name = 'atomic-rocket', position = position, target = position, speed = 0.5})
end
function Public.armageddon()
local targets = {}
local offset = 1
local this = ScenarioTable.get_table()
for _, town_center in pairs(this.town_centers) do
local market = town_center.market
if market and market.valid then
for _ = 1, 5 do
local px = market.position.x + math_random(1, 256) - 128
local py = market.position.y + math_random(1, 256) - 128
targets[offset] = {x = px, y = py}
offset = offset + 1
end
targets[offset] = {x = market.position.x, y = market.position.y}
offset = offset + 1
end
end
for _, spaceship in pairs(this.spaceships) do
local market = spaceship.market
if market and market.valid then
for _ = 1, 5 do
local px = market.position.x + math_random(1, 256) - 128
local py = market.position.y + math_random(1, 256) - 128
targets[offset] = {x = px, y = py}
offset = offset + 1
end
targets[offset] = {x = market.position.x, y = market.position.y}
offset = offset + 1
end
end
table_shuffle(targets)
for i, pos in pairs(targets) do
local position = pos
local future = game.tick + i * 60
-- schedule to run this method again with a higher radius on next tick
if not this.nuke_tick_schedule[future] then
this.nuke_tick_schedule[future] = {}
end
this.nuke_tick_schedule[future][#this.nuke_tick_schedule[future] + 1] = {
callback = 'nuke',
params = {position}
}
end
end
function Public.initialize()
if game.surfaces['nauvis'] then
-- clear the surface
game.surfaces['nauvis'].clear(false)
end
local surface = game.surfaces['nauvis']
-- this overrides what is in the map_gen_settings.json file
local mgs = surface.map_gen_settings
mgs.default_enable_all_autoplace_controls = true -- don't mess with this!
mgs.autoplace_controls = {
coal = {frequency = 2, size = 0.1, richness = 0.2},
stone = {frequency = 2, size = 0.1, richness = 0.2},
['copper-ore'] = {frequency = 5, size = 0.1, richness = 0.1},
['iron-ore'] = {frequency = 5, size = 0.1, richness = 0.1},
['uranium-ore'] = {frequency = 0, size = 0.1, richness = 0.2},
['crude-oil'] = {frequency = 5, size = 0.05, richness = 0.5},
trees = {frequency = 2, size = 1, richness = 1},
['enemy-base'] = {frequency = 2, size = 2, richness = 1}
}
mgs.autoplace_settings = {
entity = {
settings = {
['rock-huge'] = {frequency = 2, size = 1, richness = 1},
['rock-big'] = {frequency = 2, size = 1, richness = 1},
['sand-rock-big'] = {frequency = 2, size = 1, richness = 1}
}
},
decorative = {
settings = {
['rock-tiny'] = {frequency = 10, size = 'normal', richness = 'normal'},
['rock-small'] = {frequency = 5, size = 'normal', richness = 'normal'},
['rock-medium'] = {frequency = 2, size = 'normal', richness = 'normal'},
['sand-rock-small'] = {frequency = 10, size = 'normal', richness = 'normal'},
['sand-rock-medium'] = {frequency = 5, size = 'normal', richness = 'normal'}
}
}
}
mgs.cliff_settings = {
name = 'cliff',
cliff_elevation_0 = 5,
cliff_elevation_interval = 10,
richness = 0.4
}
-- water = 0 means no water allowed
-- water = 1 means elevation is not reduced when calculating water tiles (elevation < 0)
-- water = 2 means elevation is reduced by 10 when calculating water tiles (elevation < 0)
-- or rather, the water table is 10 above the normal elevation
mgs.water = 0.5
mgs.peaceful_mode = false
mgs.starting_area = 'none'
mgs.terrain_segmentation = 8
-- terrain size is 64 x 64 chunks, water size is 80 x 80
mgs.width = map_width
mgs.height = map_height
--mgs.starting_points = {
-- {x = 0, y = 0}
--}
-- here we put the named noise expressions for the specific noise-layer if we want to override them
mgs.property_expression_names = {
-- here we are overriding the moisture noise-layer with a fixed value of 0 to keep moisture consistently dry across the map
-- it allows to free up the moisture noise expression
-- low moisture
--moisture = 0,
-- here we are overriding the aux noise-layer with a fixed value to keep aux consistent across the map
-- it allows to free up the aux noise expression
-- aux should be not sand, nor red sand
--aux = 0.5,
-- here we are overriding the temperature noise-layer with a fixed value to keep temperature consistent across the map
-- it allows to free up the temperature noise expression
-- temperature should be 20C or 68F
--temperature = 20,
-- here we are overriding the cliffiness noise-layer with a fixed value of 0 to disable cliffs
-- it allows to free up the cliffiness noise expression (which may or may not be useful)
-- disable cliffs
--cliffiness = 0,
-- we can disable starting lakes two ways, one by setting starting-lake-noise-amplitude = 0
-- or by making the elevation a very large number
-- make sure starting lake amplitude is 0 to disable starting lakes
['starting-lake-noise-amplitude'] = 0,
-- allow enemies to get up close on spawn
['starting-area'] = 0,
-- this accepts a string representing a named noise expression
-- or number to determine the elevation based on x, y and distance from starting points
-- we can not add a named noise expression at this point, we can only reference existing ones
-- if we have any custom noise expressions defined from a mod, we will be able to use them here
-- setting it to a fixed number would mean a flat map
-- elevation < 0 means there is water unless the water table has been changed
--elevation = -1,
--elevation = 0,
--elevation-persistence = 0,
-- testing
--["control-setting:moisture:bias"] = 0.5,
--["control-setting:moisture:frequency:multiplier"] = 0,
--["control-setting:aux:bias"] = 0.5,
--["control-setting:aux:frequency:multiplier"] = 1,
--["control-setting:temperature:bias"] = 0.01,
--["control-setting:temperature:frequency:multiplier"] = 100,
--["tile:water:probability"] = -1000,
--["tile:deep-water:probability"] = -1000,
-- a constant intensity means base distribution will be consistent with regard to distance
['enemy-base-intensity'] = 1,
-- adjust this value to set how many nests spawn per tile
['enemy-base-frequency'] = 0.4,
-- this will make and average base radius around 12 tiles
['enemy-base-radius'] = 12
}
mgs.seed = math_random(10000, 999999)
surface.map_gen_settings = mgs
surface.peaceful_mode = false
surface.always_day = false
surface.freeze_daytime = false
surface.clear(true)
surface.regenerate_entity({'rock-huge', 'rock-big', 'sand-rock-big'})
surface.regenerate_decorative()
-- this will force generate the entire map
--Server.to_discord_embed('ScrapTownyFFA Map Regeneration in Progress')
--surface.request_to_generate_chunks({x=0,y=0},64)
--surface.force_generate_chunk_requests()
--Server.to_discord_embed('Regeneration Complete')
end
local function on_tick()
local this = ScenarioTable.get_table()
if not this.nuke_tick_schedule[game.tick] then
return
end
for _, token in pairs(this.nuke_tick_schedule[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'nuke' then
Public.nuke(params[1])
end
end
this.nuke_tick_schedule[game.tick] = nil
end
function Public.clear_nuke_schedule()
local this = ScenarioTable.get_table()
this.nuke_tick_schedule = {}
end
Event.add(defines.events.on_tick, on_tick)
return Public

View File

@ -0,0 +1,183 @@
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Team = require 'maps.scrap_towny_ffa.team'
local Event = require 'utils.event'
local Spawn = require 'maps.scrap_towny_ffa.spawn'
local Info = require 'maps.scrap_towny_ffa.info'
local Public = {}
-- how long in ticks between spawn and death will be considered spawn kill (10 seconds)
local max_ticks_between_spawns = 60 * 10
-- how many players must login before teams are teams_enabled
local min_players_for_enabling_towns = 0
function Public.settings(player)
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,
['show-electric-network'] = false,
['show-turret-range'] = false,
['show-pollution'] = false,
['show-train-station-names'] = false,
['show-player-names'] = false,
['show-networkless-logistic-members'] = false,
['show-non-standard-map-info'] = false
}
player.show_on_map = false
--player.game_view_settings.show_side_menu = false
end
function Public.initialize(player)
player.teleport({0, 0}, game.surfaces['limbo'])
Team.set_player_to_outlander(player)
Team.give_player_items(player)
Team.give_key(player.index)
local this = ScenarioTable.get()
if (this.testing_mode == true) then
player.cheat_mode = true
player.force.research_all_technologies()
player.insert {name = 'coin', count = '9900'}
end
end
function Public.spawn(player)
-- first time spawn point
local surface = game.surfaces['nauvis']
local spawn_point = Spawn.get_new_spawn_point(player, surface)
local this = ScenarioTable.get()
this.strikes[player.name] = 0
Spawn.clear_spawn_point(spawn_point, surface)
-- reset cooldown
this.cooldowns_town_placement[player.index] = 0
this.last_respawn[player.name] = 0
local position = surface.find_non_colliding_position('character', spawn_point, 50, 1)
if position then
player.teleport(position, surface)
else
player.teleport(spawn_point, surface)
end
end
function Public.load_buffs(player)
if player.force.name ~= 'player' and player.force.name ~= 'rogue' then
return
end
local this = ScenarioTable.get()
local player_index = player.index
if player.character == nil then
return
end
if this.buffs[player_index] == nil then
this.buffs[player_index] = {}
end
if this.buffs[player_index].character_inventory_slots_bonus ~= nil then
player.character.character_inventory_slots_bonus = this.buffs[player_index].character_inventory_slots_bonus
end
if this.buffs[player_index].character_mining_speed_modifier ~= nil then
player.character.character_mining_speed_modifier = this.buffs[player_index].character_mining_speed_modifier
end
if this.buffs[player_index].character_crafting_speed_modifier ~= nil then
player.character.character_crafting_speed_modifier = this.buffs[player_index].character_crafting_speed_modifier
end
end
function Public.requests(player)
local this = ScenarioTable.get()
if this.requests[player.index] and this.requests[player.index] == 'kill-character' then
if player.character and player.character.valid then
-- Clear inventories to avoid people easily getting back their stuff after a town dies offline
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.print('Your town has fallen since you last played. Good luck next time!', {r = 1, g = 0, b = 0})
player.character.die()
end
this.requests[player.index] = nil
end
end
function Public.increment()
local this = ScenarioTable.get()
local count = this.players + 1
this.players = count
if this.testing_mode then
this.towns_enabled = true
else
if this.players >= min_players_for_enabling_towns then
this.towns_enabled = true
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
Info.toggle_button(player)
Team.set_player_color(player)
if player.online_time == 0 then
Public.settings(player)
Public.increment()
Public.initialize(player)
Public.spawn(player)
Info.show(player)
end
Public.load_buffs(player)
Public.requests(player)
end
local function on_player_respawned(event)
local this = ScenarioTable.get()
local player = game.players[event.player_index]
local surface = player.surface
Team.give_player_items(player)
if player.force == game.forces['rogue'] then
Team.set_player_to_outlander(player)
end
if player.force == game.forces['player'] then
Team.give_key(player.index)
end
-- get_spawn_point will always return a valid spawn
local spawn_point = Spawn.get_spawn_point(player, surface)
-- reset cooldown
this.last_respawn[player.name] = game.tick
local position = surface.find_non_colliding_position('character', spawn_point, 50, 1)
if position then
player.teleport(position, surface)
else
player.teleport(spawn_point, surface)
end
Public.load_buffs(player)
end
local function on_player_died(event)
local this = ScenarioTable.get()
local player = game.players[event.player_index]
if this.strikes[player.name] == nil then
this.strikes[player.name] = 0
end
local ticks_elapsed = game.tick - this.last_respawn[player.name]
if ticks_elapsed < max_ticks_between_spawns then
this.strikes[player.name] = this.strikes[player.name] + 1
else
this.strikes[player.name] = 0
end
end
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)
return Public

View File

@ -1,9 +1,10 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local Public = {}
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local pollution_index = {
['small-biter'] = {min = 0.1, max = 0.1},
['medium-biter'] = {min = 0.1, max = 0.2},
@ -46,11 +47,11 @@ local pollution_index = {
}
function Public.market_scent()
local ffatable = Table.get_table()
if ffatable.testing_mode then
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
local town_centers = ffatable.town_centers
local town_centers = this.town_centers
if town_centers == nil then
return
end
@ -109,7 +110,6 @@ local function on_entity_died(event)
entity.surface.pollute(entity.position, amount)
end
local Event = require 'utils.event'
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -0,0 +1,258 @@
local Event = require 'utils.event'
local Server = require 'utils.server'
local Alert = require 'utils.alert'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Nauvis = require 'maps.scrap_towny_ffa.nauvis'
local Team = require 'maps.scrap_towny_ffa.team'
local Player = require 'maps.scrap_towny_ffa.player'
local Color = require 'utils.color_presets'
local table_insert = table.insert
-- game duration in ticks
-- 7d * 24h * 60m * 60s * 60t
-- local game_duration = 36288000
local game_duration = 36288000
local armageddon_duration = 3600
local warning_duration = 600
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
local function on_rocket_launched(event)
local this = ScenarioTable.get()
local rocket = event.rocket
local tick = event.tick
local force_index = rocket.force.index
table_insert(this.rocket_launches, {force_index = force_index, tick = tick})
end
local function get_victorious_force()
local this = ScenarioTable.get_table()
if this.rocket_launches then
for _, launch in pairs(this.rocket_launches) do
local force = game.forces[launch.force_index]
if force.valid then
return force.name
end
end
end
return nil
end
local function warning()
Alert.alert_all_players(5, 'The world is ending!', Color.white, 'warning-white', 1.0)
end
local function armageddon()
if not get_victorious_force() then
Nauvis.armageddon()
end
end
local function do_soft_reset()
local this = ScenarioTable.get_table()
for _, player in pairs(game.players) do
local frame = this.score_gui_frame[player.index]
if frame and frame.valid then
frame.destroy()
end
end
this.game_reset_tick = nil
this.game_won = false
ScenarioTable.reset_table()
local surface = game.surfaces['nauvis']
if get_victorious_force() then
surface.play_sound({path = 'utility/game_won', volume_modifier = 1})
else
surface.play_sound({path = 'utility/game_lost', volume_modifier = 1})
end
game.reset_time_played()
game.reset_game_state()
for _, player in pairs(game.players) do
player.teleport({0, 0}, game.surfaces['limbo'])
end
Nauvis.initialize()
Team.initialize()
if game.forces['rogue'] == nil then
log('rogue force is missing!')
end
for _, player in pairs(game.players) do
Player.increment()
Player.initialize(player)
Team.set_player_color(player)
Player.spawn(player)
Player.load_buffs(player)
Player.requests(player)
end
Alert.alert_all_players(5, 'The world has been reset!', Color.white, 'restart_required', 1.0)
game.print('The world has been reset!', {r = 0.22, g = 0.88, b = 0.22})
Server.to_discord_embed('*** The world has been reset! ***')
end
local function has_the_game_ended()
local game_reset_tick = ScenarioTable.get('game_reset_tick')
if game_reset_tick then
if game_reset_tick < 0 then
return
end
local this = ScenarioTable.get_table()
this.game_reset_tick = this.game_reset_tick - 30
if this.game_reset_tick % 1800 == 0 then
if this.game_reset_tick > 0 then
local cause_msg
if this.restart then
cause_msg = 'restart'
elseif this.shutdown then
cause_msg = 'shutdown'
elseif this.soft_reset then
cause_msg = 'soft-reset'
end
game.print(({'main.reset_in', cause_msg, this.game_reset_tick / 60}), {r = 0.22, g = 0.88, b = 0.22})
end
if this.soft_reset and this.game_reset_tick == 0 then
do_soft_reset()
return
end
if this.restart and this.game_reset_tick == 0 then
if not this.announced_message then
game.print(({'entity.notify_restart'}), {r = 0.22, g = 0.88, b = 0.22})
local message = 'Soft-reset is disabled! Server will restart from scenario to load new changes.'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.start_scenario('Towny')
this.announced_message = true
return
end
end
if this.shutdown and this.game_reset_tick == 0 then
if not this.announced_message then
game.print(({'entity.notify_shutdown'}), {r = 0.22, g = 0.88, b = 0.22})
local message = 'Soft-reset is disabled! Server will shutdown. Most likely because of updates.'
Server.to_discord_bold(table.concat {'*** ', message, ' ***'})
Server.stop_scenario()
this.announced_message = true
return
end
end
end
end
end
local function on_tick()
local tick = game.tick
if tick > 0 then
if tick % 40 == 0 then
local game_won = ScenarioTable.get('game_won')
if game_won then
has_the_game_ended()
end
end
if (tick + armageddon_duration + warning_duration) % game_duration == 0 then
warning()
end
if (tick + armageddon_duration) % game_duration == 0 then
armageddon()
end
if (tick + 1) % game_duration == 0 then
Nauvis.clear_nuke_schedule()
Team.reset_all_forces()
end
if tick % game_duration == 0 then
has_the_game_ended()
end
end
end
commands.add_command(
'scenario',
'Usable only for admins - controls the scenario!',
function(cmd)
local p
local player = game.player
if not player or not player.valid then
p = log
else
p = player.print
if not player.admin then
return
end
end
local this = ScenarioTable.get_table()
local param = cmd.parameter
if param == 'restart' or param == 'shutdown' or param == 'reset' or param == 'restartscenario' then
goto continue
else
p('[ERROR] Arguments are:\nrestart\nshutdown\nreset\nrestartscenario')
return
end
::continue::
if not this.reset_are_you_sure then
this.reset_are_you_sure = true
p('[WARNING] This command will disable the soft-reset feature, run this command again if you really want to do this!')
return
end
if param == 'restart' then
if this.restart then
this.reset_are_you_sure = nil
this.restart = false
this.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
this.reset_are_you_sure = nil
this.restart = true
this.soft_reset = false
if this.shutdown then
this.shutdown = false
end
p('[WARNING] Soft-reset is disabled! Server will restart from scenario to load new changes.')
return
end
elseif param == 'restartscenario' then
this.reset_are_you_sure = nil
Server.start_scenario('Towny')
return
elseif param == 'shutdown' then
if this.shutdown then
this.reset_are_you_sure = nil
this.shutdown = false
this.soft_reset = true
p('[SUCCESS] Soft-reset is enabled.')
return
else
this.reset_are_you_sure = nil
this.shutdown = true
this.soft_reset = false
if this.restart then
this.restart = false
end
p('[WARNING] Soft-reset is disabled! Server will shutdown. Most likely because of updates.')
return
end
elseif param == 'reset' then
this.reset_are_you_sure = nil
if player and player.valid then
game.print(mapkeeper .. ' ' .. player.name .. ', has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
else
game.print(mapkeeper .. ' server, has reset the game!', {r = 0.98, g = 0.66, b = 0.22})
end
do_soft_reset()
p('[WARNING] Game has been reset!')
return
end
end
)
Event.on_nth_tick(10, on_tick)
Event.add(defines.events.on_rocket_launched, on_rocket_launched)

View File

@ -1,9 +1,11 @@
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local math_random = math.random
local math_floor = math.floor
local table_insert = table.insert
local table_shuffle = table.shuffle_table
local Table = require 'modules.scrap_towny_ffa.table'
local valid_entities = {
['rock-big'] = true,
@ -12,11 +14,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()
@ -31,24 +33,22 @@ local function get_chances()
end
local function set_raffle()
local ffatable = Table.get_table()
ffatable.rocks_yield_ore_veins.raffle = {}
local this = ScenarioTable.get_table()
this.rocks_yield_ore_veins.raffle = {}
for _, t in pairs(get_chances()) do
for _ = 1, t[2], 1 do
table_insert(ffatable.rocks_yield_ore_veins.raffle, t[1])
table_insert(this.rocks_yield_ore_veins.raffle, t[1])
end
end
ffatable.rocks_yield_ore_veins.mixed_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'}
this.rocks_yield_ore_veins.mixed_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'}
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(20, 200)
end
local function draw_chain(surface, count, ore, ore_entities, ore_positions)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local vectors = {{0, -0.75}, {-0.75, 0}, {0.75, 0}, {0, 0.75}}
local r = math_random(1, #ore_entities)
local position = {x = ore_entities[r].ore.position.x, y = ore_entities[r].ore.position.y}
@ -63,7 +63,7 @@ local function draw_chain(surface, count, ore, ore_entities, ore_positions)
local name = ore
if ore == 'mixed' then
name = ffatable.rocks_yield_ore_veins.mixed_ores[math_random(1, #ffatable.rocks_yield_ore_veins.mixed_ores)]
name = this.rocks_yield_ore_veins.mixed_ores[math_random(1, #this.rocks_yield_ore_veins.mixed_ores)]
end
if surface.can_place_entity({name = name, position = p, force = 'neutral'}) then
if math_random(1, 2) == 1 then
@ -97,10 +97,10 @@ local function draw_chain(surface, count, ore, ore_entities, ore_positions)
end
local function ore_vein(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = event.entity.surface
local size = size_raffle[math_random(1, #size_raffle)]
local ore = ffatable.rocks_yield_ore_veins.raffle[math_random(1, #ffatable.rocks_yield_ore_veins.raffle)]
local ore = this.rocks_yield_ore_veins.raffle[math_random(1, #this.rocks_yield_ore_veins.raffle)]
local icon
if game.entity_prototypes[ore] then
icon = '[img=entity/' .. ore .. ']'
@ -143,7 +143,7 @@ local function ore_vein(event)
ore_entities = {
{
ore = {
name = ffatable.rocks_yield_ore_veins.mixed_ores[math_random(1, #ffatable.rocks_yield_ore_veins.mixed_ores)],
name = this.rocks_yield_ore_veins.mixed_ores[math_random(1, #this.rocks_yield_ore_veins.mixed_ores)],
position = {x = position.x, y = position.y}
},
amount = get_amount()
@ -180,7 +180,7 @@ local function ore_vein(event)
end
local function on_player_mined_entity(event)
local rocks_yield_ore_veins = Table.get('rocks_yield_ore_veins')
local rocks_yield_ore_veins = ScenarioTable.get('rocks_yield_ore_veins')
if not rocks_yield_ore_veins then
return
end
@ -195,21 +195,20 @@ local function on_player_mined_entity(event)
if not valid_entities[event.entity.name] then
return
end
if math_random(1, rocks_yield_ore_veins.chance) ~= 1 then
if math_random(1, rocks_yield_ore_veins.chance) ~= 1 and not ScenarioTable.get('testing_mode') then
return
end
ore_vein(event)
end
local function on_init()
local ffatable = Table.get_table()
ffatable.rocks_yield_ore_veins = {}
ffatable.rocks_yield_ore_veins.raffle = {}
ffatable.rocks_yield_ore_veins.mixed_ores = {}
ffatable.rocks_yield_ore_veins.chance = 10
local this = ScenarioTable.get_table()
this.rocks_yield_ore_veins = {}
this.rocks_yield_ore_veins.raffle = {}
this.rocks_yield_ore_veins.mixed_ores = {}
this.rocks_yield_ore_veins.chance = 10
set_raffle()
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -0,0 +1,34 @@
local Public = {}
local scrapable = {
-- simple entity
['small-ship-wreck'] = true,
['medium-ship-wreck'] = true,
-- simple entity with owner
['crash-site-spaceship-wreck-small-1'] = true,
['crash-site-spaceship-wreck-small-2'] = true,
['crash-site-spaceship-wreck-small-3'] = true,
['crash-site-spaceship-wreck-small-4'] = true,
['crash-site-spaceship-wreck-small-5'] = true,
['crash-site-spaceship-wreck-small-6'] = true,
['big-ship-wreck-1'] = true,
['big-ship-wreck-2'] = true,
['big-ship-wreck-3'] = true,
['crash-site-chest-1'] = true,
['crash-site-chest-2'] = true,
['crash-site-spaceship-wreck-medium-1'] = true,
['crash-site-spaceship-wreck-medium-2'] = true,
['crash-site-spaceship-wreck-medium-3'] = true,
['crash-site-spaceship-wreck-big-1'] = true,
['crash-site-spaceship-wreck-big-2'] = true,
['crash-site-spaceship'] = true
}
function Public.is_scrap(entity)
if not entity.valid then
return false
end
return scrapable[entity.name] or false
end
return Public

View File

@ -1,27 +1,14 @@
local Event = require 'utils.event'
local get_noise = require 'utils.get_noise'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local table_insert = table.insert
local math_random = math.random
local math_floor = math.floor
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
@ -71,66 +58,60 @@ local scrap_containers_index = table.size(scrap_containers)
-- loot chances and amounts for scrap containers
local container_loot_chance = {
{name = 'advanced-circuit', chance = 5},
{name = 'artillery-shell', chance = 1},
{name = 'cannon-shell', chance = 2},
{name = 'cliff-explosives', chance = 5},
{name = 'advanced-circuit', chance = 15},
--{name = "artillery-shell", chance = 1},
{name = 'battery', chance = 15},
{name = 'cannon-shell', chance = 4},
--{name = "cluster-grenade", chance = 2},
{name = 'coin', chance = 1},
{name = 'construction-robot', chance = 1},
{name = 'copper-cable', chance = 250},
{name = 'copper-plate', chance = 500},
{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 = 'electric-engine-unit', chance = 2},
{name = 'electronic-circuit', chance = 200},
{name = 'electronic-circuit', chance = 150},
{name = 'empty-barrel', chance = 10},
{name = 'engine-unit', chance = 7},
{name = 'engine-unit', chance = 5},
{name = 'explosive-cannon-shell', chance = 2},
--{name = "explosive-rocket", chance = 3},
{name = 'explosive-uranium-cannon-shell', chance = 1},
--{name = "explosive-uranium-cannon-shell", chance = 1},
{name = 'explosives', chance = 5},
{name = 'green-wire', chance = 10},
{name = 'grenade', chance = 10},
{name = 'heat-pipe', chance = 1},
{name = 'heavy-oil-barrel', chance = 15},
{name = 'heavy-oil-barrel', chance = 20},
{name = 'iron-gear-wheel', chance = 500},
{name = 'iron-plate', chance = 750},
{name = 'iron-plate', chance = 500},
{name = 'iron-stick', chance = 50},
{name = 'land-mine', chance = 3},
{name = 'light-oil-barrel', chance = 15},
{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 = 'petroleum-gas-barrel', chance = 15},
{name = 'petroleum-gas-barrel', chance = 30},
{name = 'pipe', chance = 100},
{name = 'pipe-to-ground', chance = 10},
{name = 'plastic-bar', chance = 5},
{name = 'processing-unit', chance = 2},
{name = 'red-wire', chance = 10},
--{name = "rocket", chance = 3}, {name = "battery", chance = 20},
{name = 'rocket-control-unit', chance = 1},
{name = 'rocket-fuel', chance = 3},
--{name = "rocket", chance = 3},
--{name = "rocket-control-unit", chance = 1},
--{name = "rocket-fuel", chance = 3},
{name = 'solid-fuel', chance = 100},
{name = 'steel-plate', chance = 150},
{name = 'sulfuric-acid-barrel', chance = 15},
{name = 'uranium-cannon-shell', chance = 1},
--{name = "uranium-cannon-shell", chance = 1},
{name = 'uranium-fuel-cell', chance = 1},
{name = 'used-up-uranium-fuel-cell', chance = 1},
--{name = "used-up-uranium-fuel-cell", chance = 1},
{name = 'water-barrel', chance = 10}
}
local container_loot_amounts = {
['advanced-circuit'] = 2,
['artillery-shell'] = 0.3,
['advanced-circuit'] = 6,
--["artillery-shell"] = 0.3,
['battery'] = 2,
['cannon-shell'] = 2,
['cliff-explosives'] = 2,
['cannon-shell'] = 4,
--["cluster-grenade"] = 0.3,
['coin'] = 2,
['construction-robot'] = 0.3,
['copper-cable'] = 24,
['copper-plate'] = 16,
@ -144,16 +125,16 @@ local container_loot_amounts = {
['engine-unit'] = 2,
['explosive-cannon-shell'] = 2,
--["explosive-rocket"] = 2,
['explosive-uranium-cannon-shell'] = 2,
--["explosive-uranium-cannon-shell"] = 2,
['explosives'] = 4,
['green-wire'] = 8,
['grenade'] = 2,
['grenade'] = 6,
['heat-pipe'] = 1,
['heavy-oil-barrel'] = 3,
['iron-gear-wheel'] = 8,
['iron-plate'] = 16,
['iron-stick'] = 16,
['land-mine'] = 1,
['land-mine'] = 6,
['light-oil-barrel'] = 3,
['logistic-robot'] = 0.3,
['low-density-structure'] = 0.3,
@ -163,17 +144,17 @@ local container_loot_amounts = {
['pipe'] = 8,
['pipe-to-ground'] = 1,
['plastic-bar'] = 4,
['processing-unit'] = 1,
['processing-unit'] = 2,
['red-wire'] = 8,
--["rocket"] = 2,
['rocket-control-unit'] = 0.3,
['rocket-fuel'] = 0.3,
--["rocket-control-unit"] = 0.3,
--["rocket-fuel"] = 0.3,
['solid-fuel'] = 4,
['steel-plate'] = 4,
['sulfuric-acid-barrel'] = 3,
['uranium-cannon-shell'] = 2,
--["uranium-cannon-shell"] = 2,
['uranium-fuel-cell'] = 0.3,
['used-up-uranium-fuel-cell'] = 1,
--["used-up-uranium-fuel-cell"] = 1,
['water-barrel'] = 3
}
@ -187,9 +168,9 @@ end
local size_of_scrap_raffle = #scrap_raffle
local function place_scrap(surface, position)
local ffatable = Table.get_table()
if ffatable.spaceships == nil then
ffatable.spaceships = {}
local this = ScenarioTable.get_table()
if this.spaceships == nil then
this.spaceships = {}
end
-- place turrets
if math_random(1, 700) == 1 then
@ -202,24 +183,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)]
@ -325,9 +288,7 @@ local function on_chunk_generated(event)
for x = 0, 31, 1 do
for y = 0, 31, 1 do
position = {x = left_top_x + x, y = left_top_y + y}
if not surface.get_tile(position).collides_with('water-tile') then
surface.set_tiles({{name = 'water-shallow', position = position}}, true)
end
surface.set_tiles({{name = 'water-shallow', position = position}}, true)
end
end
return
@ -363,7 +324,7 @@ local function on_chunk_generated(event)
end
end
move_away_biteys(surface, event.area)
--ffatable.chunk_generated[key] = true
--this.chunk_generated[key] = true
end
local function on_chunk_charted(event)
@ -377,11 +338,10 @@ local function on_chunk_charted(event)
end
-- local on_init = function ()
-- local ffatable = Table.get_table()
-- ffatable.chunk_generated = {}
-- local this = ScenarioTable.get_table()
-- this.chunk_generated = {}
-- end
local Event = require 'utils.event'
-- Event.on_init(on_init)
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
Event.add(defines.events.on_chunk_charted, on_chunk_charted)

View File

@ -1,8 +1,9 @@
local Table = require 'modules.scrap_towny_ffa.table'
local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
-- called whenever a player places an item
local function on_built_entity(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local entity = event.created_entity
if not entity.valid then
return
@ -12,7 +13,7 @@ local function on_built_entity(event)
end
local player = game.players[event.player_index]
local force = player.force
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
local surface = entity.surface
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
surface.create_entity(
@ -44,10 +45,10 @@ local function on_built_entity(event)
return
end
local key = script.register_on_entity_destroyed(entity)
if (ffatable.laser_turrets == nil) then
ffatable.laser_turrets = {}
if (this.laser_turrets == nil) then
this.laser_turrets = {}
end
ffatable.laser_turrets[key] = force.index
this.laser_turrets[key] = force.index
locations = locations + 1
town_center.upgrades.laser_turret.locations = locations
surface.create_entity(
@ -62,7 +63,7 @@ end
-- called whenever a robot places an item
local function on_robot_built_entity(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local entity = event.created_entity
if not entity.valid then
return
@ -72,7 +73,7 @@ local function on_robot_built_entity(event)
end
local robot = event.robot
local force = robot.force
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
local surface = entity.surface
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
surface.create_entity(
@ -103,10 +104,10 @@ local function on_robot_built_entity(event)
return
end
local key = script.register_on_entity_destroyed(entity)
if (ffatable.laser_turrets == nil) then
ffatable.laser_turrets = {}
if (this.laser_turrets == nil) then
this.laser_turrets = {}
end
ffatable.laser_turrets[key] = force.index
this.laser_turrets[key] = force.index
locations = locations + 1
town_center.upgrades.laser_turret.locations = locations
surface.create_entity(
@ -122,15 +123,15 @@ end
-- called whenever a laser-turret is removed from the map
local function on_entity_destroyed(event)
local key = event.registration_number
local ffatable = Table.get_table()
if (ffatable.laser_turrets == nil) then
local this = ScenarioTable.get_table()
if (this.laser_turrets == nil) then
return
end
if (ffatable.laser_turrets[key] ~= nil) then
local index = ffatable.laser_turrets[key]
if (this.laser_turrets[key] ~= nil) then
local index = this.laser_turrets[key]
local force = game.forces[index]
if force ~= nil then
local town_center = ffatable.town_centers[force.name]
local town_center = this.town_centers[force.name]
if town_center ~= nil then
if force.index == game.forces['player'].index or force.index == game.forces['rogue'].index or town_center == nil then
return
@ -146,7 +147,6 @@ local function on_entity_destroyed(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
Event.add(defines.events.on_entity_destroyed, on_entity_destroyed)

View File

@ -1,70 +1,75 @@
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Event = require 'utils.event'
local table_insert = table.insert
local Table = require 'modules.scrap_towny_ffa.table'
local function position_tostring(position)
return '[x=' .. position.x .. ',y=' .. position.y .. ']'
end
local upgrade_functions = {
-- Upgrade Backpack
[1] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_inventory_slots_bonus + 5 > 100 then
return false
end
player.character.character_inventory_slots_bonus = player.character.character_inventory_slots_bonus + 5
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_inventory_slots_bonus then
ffatable.buffs[player.index].character_inventory_slots_bonus = 0
if not this.buffs[player.index].character_inventory_slots_bonus then
this.buffs[player.index].character_inventory_slots_bonus = 0
end
ffatable.buffs[player.index].character_inventory_slots_bonus = player.character.character_inventory_slots_bonus
this.buffs[player.index].character_inventory_slots_bonus = player.character.character_inventory_slots_bonus
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Upgrade Pickaxe Speed
[2] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_mining_speed_modifier + 0.1 > 1 then
return false
end
player.character.character_mining_speed_modifier = player.character.character_mining_speed_modifier + 0.1
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_mining_speed_modifier then
ffatable.buffs[player.index].character_mining_speed_modifier = 0
if not this.buffs[player.index].character_mining_speed_modifier then
this.buffs[player.index].character_mining_speed_modifier = 0
end
ffatable.buffs[player.index].character_mining_speed_modifier = player.character.character_mining_speed_modifier
this.buffs[player.index].character_mining_speed_modifier = player.character.character_mining_speed_modifier
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Upgrade Crafting Speed
[3] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
if player.character.character_crafting_speed_modifier + 0.1 > 1 then
return false
end
player.character.character_crafting_speed_modifier = player.character.character_crafting_speed_modifier + 0.1
if not ffatable.buffs[player.index] then
ffatable.buffs[player.index] = {}
if not this.buffs[player.index] then
this.buffs[player.index] = {}
end
if not ffatable.buffs[player.index].character_crafting_speed_modifier then
ffatable.buffs[player.index].character_crafting_speed_modifier = 0
if not this.buffs[player.index].character_crafting_speed_modifier then
this.buffs[player.index].character_crafting_speed_modifier = 0
end
ffatable.buffs[player.index].character_crafting_speed_modifier = player.character.character_crafting_speed_modifier
this.buffs[player.index].character_crafting_speed_modifier = player.character.character_crafting_speed_modifier
surface.play_sound({path = 'utility/achievement_unlocked', position = player.position, volume_modifier = 1})
return true
end,
-- Set Spawn Point
[4] = function(player)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local surface = player.surface
local position = player.position
position = surface.find_non_colliding_position('character', position, 0, 0.25)
if position ~= nil and player ~= nil then
ffatable.spawn_point[player.name] = {x = position.x, y = position.y}
this.spawn_point[player.index] = {x = position.x, y = position.y}
surface.play_sound({path = 'utility/scenario_message', position = player.position, volume_modifier = 1})
else
surface.create_entity(
@ -168,7 +173,7 @@ local function refresh_offers(event)
return
end
local player = game.players[event.player_index]
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local market = event.entity or event.market
if not market then
return
@ -179,8 +184,9 @@ local function refresh_offers(event)
if market.name ~= 'crash-site-spaceship-market' then
return
end
local position = market.position
local spaceship = ffatable.spaceships[position.x][position.y]
local key = position_tostring(market.position)
local spaceship = this.spaceships[key]
if not spaceship then
return
end
@ -189,7 +195,7 @@ local function refresh_offers(event)
end
local function offer_purchased(event)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
local market = event.market
local offer_index = event.offer_index
@ -197,7 +203,8 @@ local function offer_purchased(event)
if not upgrade_functions[offer_index] then
return
end
local spaceship = ffatable.spaceships[market.position.x][market.position.y]
local key = position_tostring(market.position)
local spaceship = this.spaceships[key]
if not spaceship then
return
end
@ -242,10 +249,11 @@ local function on_market_item_purchased(event)
end
local function kill_spaceship(entity)
local ffatable = Table.get_table()
local spaceship = ffatable.spaceships[entity.position.x][entity.position.y]
local this = ScenarioTable.get_table()
local key = position_tostring(entity.position)
local spaceship = this.spaceships[key]
if spaceship ~= nil then
ffatable.spaceships[entity.position.x][entity.position.y] = nil
this.spaceships[key] = nil
end
end
@ -256,13 +264,6 @@ local function on_entity_died(event)
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.spaceships = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_gui_opened, on_gui_opened)
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -1,3 +1,7 @@
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Enemy = require 'maps.scrap_towny_ffa.enemy'
local Building = require 'maps.scrap_towny_ffa.building'
local Public = {}
local table_size = table.size
@ -8,10 +12,6 @@ local math_sin = math.sin
local math_cos = math.cos
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
local Enemy = require 'modules.scrap_towny_ffa.enemy'
local Building = require 'modules.scrap_towny_ffa.building'
-- don't spawn if town is within this range
local spawn_point_town_buffer = 256
-- clear enemies within this distance from spawn
@ -55,9 +55,13 @@ end
-- is the position already used
local function in_use(position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
local result = false
for _, v in pairs(ffatable.spawn_point) do
if position.x == 0 and position.y == 0 then
return true
end
for _, v in pairs(this.spawn_point) do
if v == position then
result = true
end
@ -66,6 +70,26 @@ local function in_use(position)
return result
end
local function is_position_near(area)
local status = false
local function inside(pos)
local lt = area.left_top
local rb = area.right_bottom
return pos.x >= lt.x and pos.y >= lt.y and pos.x <= rb.x and pos.y <= rb.y
end
local players = game.connected_players
for i = 1, #players do
local player = players[i]
if inside(player.position) then
status = true
end
end
return status
end
-- is the position empty
local function is_empty(position, surface)
local chunk_position = {}
@ -94,8 +118,8 @@ local function is_empty(position, surface)
end
-- finds a valid spawn point that is not near a town and not in a polluted area
local function find_valid_spawn_point(force_name, surface)
local ffatable = Table.get_table()
local function find_valid_spawn_point(player, force_name, surface)
local this = ScenarioTable.get_table()
-- check center of map first if valid
local position = {x = 0, y = 0}
@ -103,7 +127,7 @@ local function find_valid_spawn_point(force_name, surface)
force_load(position, surface, 1)
-- is the point near any buildings
if in_use(position) == false then
if not in_use(position) then
if Building.near_another_town(force_name, position, surface, spawn_point_town_buffer) == false then
-- force load the position
if is_empty(position, surface) == true then
@ -112,15 +136,29 @@ local function find_valid_spawn_point(force_name, surface)
end
end
end
-- is the point near any other players
local r = 55
local area = {
left_top = {x = player.position.x - r, y = player.position.y - r},
right_bottom = {x = player.position.x + r, y = player.position.y + r}
}
if not is_position_near(area) then
if is_empty(position, surface) == true then
return position
end
end
-- otherwise find a nearby town
local keyset = {}
for town_name, _ in pairs(ffatable.town_centers) do
for town_name, _ in pairs(this.town_centers) do
table_insert(keyset, town_name)
end
local count = table_size(keyset)
if count > 0 then
local town_name = keyset[math_random(1, count)]
local town_center = ffatable.town_centers[town_name]
local town_center = this.town_centers[town_name]
if town_center ~= nil then
position = town_center.market.position
end
@ -161,28 +199,28 @@ local function find_valid_spawn_point(force_name, surface)
end
function Public.get_new_spawn_point(player, surface)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
-- get a new spawn point
local position = {0, 0}
if player ~= nil then
local force = player.force
if force ~= nil then
local force_name = force.name
position = find_valid_spawn_point(force_name, surface)
position = find_valid_spawn_point(player, force_name, surface)
end
end
-- should never be invalid or blocked
ffatable.spawn_point[player.name] = position
this.spawn_point[player.index] = position
--log("player " .. player.name .. " assigned new spawn point at {" .. position.x .. "," .. position.y .. "}")
return position
end
-- gets a new or existing spawn point for the player
function Public.get_spawn_point(player, surface)
local ffatable = Table.get_table()
local position = ffatable.spawn_point[player.name]
local this = ScenarioTable.get_table()
local position = this.spawn_point[player.index]
-- if there is a spawn point and less than three strikes
if position ~= nil and ffatable.strikes[player.name] < 3 then
if position ~= nil and this.strikes[player.name] < 3 then
-- check that the spawn point is not blocked
if surface.can_place_entity({name = 'character', position = position}) then
--log("player " .. player.name .. "using existing spawn point at {" .. position.x .. "," .. position.y .. "}")

View File

@ -1,7 +1,8 @@
-- spawners release biters on death -- by mewmew
local math_random = math.random
local Event = require 'utils.event'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local math_random = math.random
local biter_building_inhabitants = {
[1] = {{'small-biter', 8, 16}},
@ -20,7 +21,7 @@ local function on_entity_died(event)
if not event.entity.valid then
return
end
if event.entity.type ~= 'unit-spawner' then
if event.entity.name ~= 'biter-spawner' then
return
end
local e = math.ceil(Evolution.get_biter_evolution(event.entity) * 10)
@ -37,5 +38,4 @@ local function on_entity_died(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -0,0 +1,74 @@
local Event = require 'utils.event'
local Scheduler = require 'utils.scheduler'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local yellow = {r = 200, g = 200, b = 0}
-- Must be at least 1 minute
local minutes_to_die = 5
local one_minute = 60 * 60
local function on_player_died(event)
local this = ScenarioTable.get_table()
local player = game.players[event.player_index]
this.suicides[player.index] = nil
end
Event.add(defines.events.on_player_died, on_player_died)
local suicide_handler =
Scheduler.set(
function(data)
for i = 1, #data do
local this = ScenarioTable.get_table()
local player_index = data[i].player_index
local player = game.get_player(player_index)
if not player or not player.valid or not player.character then
return
end
if not this.suicides[player.index] then
-- the suicide was cancelled (the character died)
return
end
local minutes_remaining = this.suicides[player.index].minutes_remaining
if minutes_remaining <= 0 then
player.character.die()
this.suicides[player.index] = nil
else
if minutes_remaining == 1 then
player.print(minutes_remaining .. ' minute remaining until death.', yellow)
else
player.print(minutes_remaining .. ' minutes remaining until death.', yellow)
end
this.suicides[player.index].minutes_remaining = this.suicides[player.index].minutes_remaining - 1
Scheduler.timer(game.tick + one_minute, data[i].handler, {player_index = player.index, handler = data[i].handler})
end
end
end
)
commands.add_command(
'suicide',
'Kills the player',
function()
local this = ScenarioTable.get_table()
local player = game.player
if not player or not player.valid then
return
end
if this.suicides[player.index] then
player.print('You are already dying!', yellow)
return
end
this.suicides[player.index] = {minutes_remaining = minutes_to_die - 1}
Scheduler.timer(game.tick + one_minute, suicide_handler, {player_index = player.index, handler = suicide_handler})
player.print('You ate a poison pill. You will die in ' .. minutes_to_die .. ' minutes.', yellow)
end
)

View File

@ -0,0 +1,75 @@
local Public = {}
-- one table to rule them all!
local Global = require 'utils.global'
local Event = require 'utils.event'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
function Public.reset_table()
this.key = {}
this.rocket_launches = {}
this.requests = {}
this.town_centers = {}
this.cooldowns_town_placement = {}
this.last_respawn = {}
this.last_death = {}
this.strikes = {}
this.score_gui_frame = {}
this.testing_mode = false
this.spawn_point = {}
this.buffs = {}
this.players = 0
this.towns_enabled = true
this.nuke_tick_schedule = {}
this.swarms = {}
this.explosion_schedule = {}
this.fluid_explosion_schedule = {}
this.mining = {}
this.mining_entity = {}
this.mining_target = {}
this.spaceships = {}
this.suicides = {}
this.required_time_to_win = 48
this.announced_message = nil
this.soft_reset = true
this.winner = nil
end
function Public.get_table()
return this
end
function Public.get(key)
if key then
return this[key]
else
return this
end
end
function Public.set(key, value)
if key and (value or value == false) then
this[key] = value
return this[key]
elseif key then
return this[key]
else
return this
end
end
Event.on_init(
function()
Public.reset_table()
end
)
return Public

View File

@ -1,21 +1,23 @@
local Event = require 'utils.event'
local Server = require 'utils.server'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Team = require 'maps.scrap_towny_ffa.team'
local Building = require 'maps.scrap_towny_ffa.building'
local Colors = require 'maps.scrap_towny_ffa.colors'
local Enemy = require 'maps.scrap_towny_ffa.enemy'
local Color = require 'utils.color_presets'
local Public = {}
local math_random = math.random
local table_insert = table.insert
local math_floor = math.floor
local math_sqrt = math.sqrt
local table_shuffle = table.shuffle_table
local Server = require 'utils.server'
local Table = require 'modules.scrap_towny_ffa.table'
local Team = require 'modules.scrap_towny_ffa.team'
local Building = require 'modules.scrap_towny_ffa.building'
local Colors = require 'modules.scrap_towny_ffa.colors'
local Enemy = require 'modules.scrap_towny_ffa.enemy'
local Color = require 'utils.color_presets'
local table_size = table.size
local town_radius = 27
local radius_between_towns = 64
local ore_amount = 1000 * (200 / 168.5)
local radius_between_towns = 120
local ore_amount = 500 * (200 / 168.5)
local colors = {}
local c1 = 250
@ -120,33 +122,30 @@ 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)
local count = 0
local r = town_radius + 8
for _, e in pairs(
surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})
) do
for _, e in pairs(surface.find_entities_filtered({area = {{position.x - r, position.y - r}, {position.x + r, position.y + r}}, force = 'neutral', name = ore_name})) do
count = count + e.amount
end
return count
end
local function draw_town_spawn(player_name)
local ffatable = Table.get_table()
local market = ffatable.town_centers[player_name].market
local this = ScenarioTable.get_table()
local market = this.town_centers[player_name].market
local position = market.position
local surface = market.surface
@ -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})
@ -276,7 +275,7 @@ local function draw_town_spawn(player_name)
end
local function is_valid_location(force_name, surface, position)
local ffatable = Table.get_table()
local this = ScenarioTable.get_table()
if not surface.can_place_entity({name = 'market', position = position}) then
surface.create_entity(
{
@ -304,7 +303,7 @@ local function is_valid_location(force_name, surface, position)
end
end
if ffatable.number_of_towns > 48 then
if table_size(this.town_centers) > 48 then
surface.create_entity(
{
name = 'flying-text',
@ -332,8 +331,8 @@ local function is_valid_location(force_name, surface, position)
end
function Public.in_any_town(position)
local ffatable = Table.get_table()
local town_centers = ffatable.town_centers
local this = ScenarioTable.get_table()
local town_centers = this.town_centers
for _, town_center in pairs(town_centers) do
local market = town_center.market
if market ~= nil then
@ -346,14 +345,14 @@ function Public.in_any_town(position)
end
function Public.update_town_name(force)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
rendering.set_text(town_center.town_caption, town_center.town_name)
end
function Public.set_market_health(entity, final_damage_amount)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[entity.force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[entity.force.name]
town_center.health = math_floor(town_center.health - final_damage_amount)
if town_center.health > town_center.max_health then
town_center.health = town_center.max_health
@ -364,11 +363,28 @@ function Public.set_market_health(entity, final_damage_amount)
end
function Public.update_coin_balance(force)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
rendering.set_text(town_center.coins_text, 'Coins: ' .. town_center.coin_balance)
end
function Public.enemy_players_nearby(town_center, max_radius)
local own_force = town_center.market.force
local town_position = town_center.market.position
for _, player in pairs(game.connected_players) do
if player.surface == town_center.market.surface then
local distance = math_floor(math_sqrt((player.position.x - town_position.x) ^ 2 + (player.position.y - town_position.y) ^ 2))
if distance < max_radius then
if player.force ~= 'enemy' and (own_force ~= player.force and not own_force.get_friend(player.force)) then
return true
end
end
end
end
return false
end
local function found_town(event)
local entity = event.created_entity
-- is a valid entity placed?
@ -403,8 +419,8 @@ local function found_town(event)
entity.destroy()
-- are towns enabled?
local ffatable = Table.get_table()
if not ffatable.towns_enabled then
local this = ScenarioTable.get_table()
if not this.towns_enabled then
player.print('You must wait for more players to join!', {255, 255, 0})
player.insert({name = 'stone-furnace', count = 1})
return
@ -424,13 +440,13 @@ local function found_town(event)
end
-- is town placement on cooldown?
if ffatable.cooldowns_town_placement[player.index] then
if game.tick < ffatable.cooldowns_town_placement[player.index] then
if this.cooldowns_town_placement[player.index] then
if game.tick < this.cooldowns_town_placement[player.index] then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = 'Town founding is on cooldown for ' .. math.ceil((ffatable.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
text = 'Town founding is on cooldown for ' .. math.ceil((this.cooldowns_town_placement[player.index] - game.tick) / 3600) .. ' minutes.',
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
@ -445,20 +461,10 @@ 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] = {}
local town_center = ffatable.town_centers[force_name]
this.town_centers[force_name] = {}
local town_center = this.town_centers[force_name]
town_center.town_name = player.name .. "'s Town"
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)}
@ -475,7 +481,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 = 8
town_center.upgrades.laser_turret.locations = 0
town_center.evolution = {}
town_center.evolution.biters = 0
@ -487,7 +493,7 @@ local function found_town(event)
rendering.draw_text {
text = town_center.town_name,
surface = surface,
forces = {force_name},
forces = {force_name, game.forces.player, game.forces.rogue},
target = town_center.market,
target_offset = {0, -4.25},
color = town_center.color,
@ -501,7 +507,7 @@ local function found_town(event)
rendering.draw_text {
text = 'HP: ' .. town_center.health .. ' / ' .. town_center.max_health,
surface = surface,
forces = {force_name},
forces = {force_name, game.forces.player, game.forces.rogue},
target = town_center.market,
target_offset = {0, -3.25},
color = {200, 200, 200},
@ -525,9 +531,7 @@ local function found_town(event)
scale_with_zoom = false
}
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
@ -572,13 +576,6 @@ local function on_entity_damaged(event)
end
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.town_centers = {}
ffatable.number_of_towns = 0
ffatable.cooldowns_town_placement = {}
end
local function rename_town(cmd)
local player = game.players[cmd.player_index]
if not player or not player.valid then
@ -594,8 +591,8 @@ local function rename_town(cmd)
player.print('Must specify new town name!', Color.fail)
return
end
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force.name]
local old_name = town_center.town_name
town_center.town_name = name
Public.update_town_name(force)
@ -621,11 +618,8 @@ commands.add_command(
end
)
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_built_entity, on_built_entity)
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
--Event.add(defines.events.on_robot_repaired_entity, on_robot_repaired_entity)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
return Public

View File

@ -1,10 +1,12 @@
local Event = require 'utils.event'
local Evolution = require 'maps.scrap_towny_ffa.evolution'
local Town_center = require 'maps.scrap_towny_ffa.town_center'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local unearthing_worm = require 'functions.unearthing_worm'
local unearthing_biters = require 'functions.unearthing_biters'
local tick_tack_trap = require 'functions.tick_tack_trap'
local math_random = math.random
local Evolution = require 'modules.scrap_towny_ffa.evolution'
local Town_center = require 'modules.scrap_towny_ffa.town_center'
local Scrap = require 'modules.scrap_towny_ffa.scrap'
local unearthing_worm = require 'modules.scrap_towny_ffa.unearthing_worm'
local unearthing_biters = require 'modules.scrap_towny_ffa.unearthing_biters'
local tick_tack_trap = require 'modules.scrap_towny_ffa.tick_tack_trap'
local function trap(entity)
-- check if within 32 blocks of market
@ -28,5 +30,4 @@ local function on_player_mined_entity(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -1,3 +1,5 @@
local Event = require 'utils.event'
local math_random = math.random
local math_min = math.min
@ -12,5 +14,4 @@ local function on_entity_died(event)
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -0,0 +1,31 @@
local Event = require 'utils.event'
local Public = {}
local function on_player_driving_changed_state(event)
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
local vehicle = player.vehicle
if player.force.name ~= 'player' and player.force.name ~= 'rogue' then
return
end
if vehicle and vehicle.valid then
-- player entered a vehicle
if vehicle.name == 'locomotive' or vehicle.name == 'cargo-wagon' or vehicle.name == 'fluid-wagon' then
vehicle.force = 'neutral'
else
-- includes cars, tanks and artillery-wagons
vehicle.force = player.force.name
end
else
-- player exited a vehicle
vehicle = event.entity
vehicle.force = 'neutral'
end
end
Event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
return Public

View File

@ -0,0 +1,131 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local math_random = math.random
local this = {}
Global.register(
this,
function(t)
this = t
end
)
local death_animation_ticks = 120
local decay_ticks = 2
local worms = {
['small-worm-turret'] = {corpse = 'small-worm-corpse', patch_size = {min = 10000, max = 15000}},
['medium-worm-turret'] = {corpse = 'medium-worm-corpse', patch_size = {min = 15000, max = 30000}},
['big-worm-turret'] = {corpse = 'big-worm-corpse', patch_size = {min = 30000, max = 50000}},
['behemoth-worm-turret'] = {corpse = 'behemoth-worm-corpse', patch_size = {min = 50000, max = 80000}}
}
local function destroy_worm(name, position, surface)
local entity = surface.find_entity(name, position)
if entity ~= nil and entity.valid then
entity.destroy()
end
local corpse = worms[name].corpse
local remains = surface.find_entity(corpse, position)
if remains ~= nil and remains.valid then
-- show an animation
if math_random(1, 40) == 1 then
surface.create_entity({name = 'explosion', position = {x = position.x + (3 - (math_random(1, 60) * 0.1)), y = position.y + (3 - (math_random(1, 60) * 0.1))}})
end
if math_random(1, 32) == 1 then
surface.create_entity({name = 'blood-explosion-huge', position = position})
end
if math_random(1, 16) == 1 then
surface.create_entity({name = 'blood-explosion-big', position = position})
end
if math_random(1, 8) == 1 then
surface.create_entity({name = 'blood-explosion-small', position = position})
end
end
end
local function remove_corpse(name, position, surface)
local corpse = worms[name].corpse
local remains = surface.find_entity(corpse, position)
if remains ~= nil and remains.valid then
remains.destroy()
end
end
-- place an oil patch at the worm location
local function create_oil_patch(name, position, surface)
local min = worms[name].patch_size.min
local max = worms[name].patch_size.max
surface.create_entity({name = 'crude-oil', position = position, amount = math_random(min, max)})
end
-- worms create oil patches when killed
local function process_worm(entity)
local name = entity.name
local position = entity.position
local surface = entity.surface
local tick1 = game.tick + death_animation_ticks
if not this[tick1] then
this[tick1] = {}
end
this[tick1][#this[tick1] + 1] = {
callback = 'destroy_worm',
params = {name, position, surface}
}
local tick2 = game.tick + death_animation_ticks + decay_ticks
if not this[tick2] then
this[tick2] = {}
end
this[tick2][#this[tick2] + 1] = {
callback = 'remove_corpse',
params = {name, position, surface}
}
if math_random(1, 10) == 1 then
local tick3 = game.tick + death_animation_ticks + decay_ticks + 1
if not this[tick3] then
this[tick3] = {}
end
this[tick3][#this[tick3] + 1] = {
callback = 'create_oil_patch',
params = {name, position, surface}
}
end
end
local function on_entity_died(event)
local entity = event.entity
local test = {
['small-worm-turret'] = true,
['medium-worm-turret'] = true,
['big-worm-turret'] = true,
['behemoth-worm-turret'] = true
}
if test[entity.name] ~= nil then
process_worm(entity)
end
end
local function on_tick()
if not this[game.tick] then
return
end
for _, token in pairs(this[game.tick]) do
local callback = token.callback
local params = token.params
if callback == 'destroy_worm' then
destroy_worm(params[1], params[2], params[3])
end
if callback == 'remove_corpse' then
remove_corpse(params[1], params[2], params[3])
end
if callback == 'create_oil_patch' then
create_oil_patch(params[1], params[2], params[3])
end
end
this[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -0,0 +1,156 @@
local Event = require 'utils.event'
local Scrap = require 'maps.scrap_towny_ffa.scrap'
local insert = table.insert
local random = math.random
local entity_loot_chance = {
{name = 'advanced-circuit', chance = 150},
{name = 'battery', chance = 150},
{name = 'cannon-shell', chance = 50},
{name = 'copper-cable', chance = 5000},
{name = 'copper-plate', chance = 2500},
{name = 'crude-oil-barrel', chance = 500},
{name = 'defender-capsule', chance = 100},
{name = 'destroyer-capsule', chance = 20},
{name = 'distractor-capsule', chance = 40},
{name = 'electric-engine-unit', chance = 20},
{name = 'electronic-circuit', chance = 1500},
{name = 'empty-barrel', chance = 100},
{name = 'engine-unit', chance = 50},
{name = 'explosive-cannon-shell', chance = 50},
{name = 'explosives', chance = 50},
{name = 'grenade', chance = 100},
{name = 'heavy-oil-barrel', chance = 200},
{name = 'iron-gear-wheel', chance = 5000},
{name = 'iron-plate', chance = 5000},
{name = 'iron-stick', chance = 500},
{name = 'land-mine', chance = 30},
{name = 'light-oil-barrel', chance = 200},
{name = 'lubricant-barrel', chance = 200},
{name = 'nuclear-fuel', chance = 20},
{name = 'petroleum-gas-barrel', chance = 300},
{name = 'pipe', chance = 1000},
{name = 'pipe-to-ground', chance = 100},
{name = 'plastic-bar', chance = 50},
{name = 'processing-unit', chance = 20},
{name = 'rocket-fuel', chance = 50},
{name = 'solid-fuel', chance = 1000},
{name = 'steel-plate', chance = 1500},
{name = 'sulfuric-acid-barrel', chance = 150},
{name = 'uranium-fuel-cell', chance = 10},
{name = 'water-barrel', chance = 100},
{name = 'tank', chance = 1},
{name = 'car', chance = 5}
}
-- positive numbers can scale, 0 is disabled, and negative numbers are fixed absolute values
local entity_loot_amounts = {
['advanced-circuit'] = 6,
['battery'] = 2,
['cannon-shell'] = 2,
['copper-cable'] = 24,
['copper-plate'] = 16,
['crude-oil-barrel'] = 3,
['defender-capsule'] = 2,
['destroyer-capsule'] = 0.3,
['distractor-capsule'] = 0.3,
['electric-engine-unit'] = 2,
['electronic-circuit'] = 8,
['empty-barrel'] = 3,
['engine-unit'] = 2,
['explosive-cannon-shell'] = 1,
['explosives'] = 4,
['green-wire'] = 8,
['grenade'] = 6,
['heat-pipe'] = 1,
['heavy-oil-barrel'] = 3,
['iron-gear-wheel'] = 8,
['iron-plate'] = 16,
['iron-stick'] = 16,
['land-mine'] = 6,
['light-oil-barrel'] = 3,
['lubricant-barrel'] = 3,
['nuclear-fuel'] = 0.1,
['petroleum-gas-barrel'] = 3,
['pipe'] = 8,
['pipe-to-ground'] = 1,
['plastic-bar'] = 4,
['processing-unit'] = 2,
['red-wire'] = 8,
['rocket-fuel'] = 0.3,
['solid-fuel'] = 4,
['steel-plate'] = 4,
['sulfuric-acid-barrel'] = 3,
['uranium-fuel-cell'] = 0.3,
['water-barrel'] = 3,
['tank'] = -1,
['car'] = -1
}
local scrap_raffle = {}
for _, t in pairs(entity_loot_chance) do
for _ = 1, t.chance, 1 do
insert(scrap_raffle, t.name)
end
end
local size_of_scrap_raffle = #scrap_raffle
local function on_player_mined_entity(event)
local entity = event.entity
local buffer = event.buffer
if not entity.valid then
return
end
local position = entity.position
if not Scrap.is_scrap(entity) then
return
end
if entity.name == 'crash-site-chest-1' or entity.name == 'crash-site-chest-2' then
return
end
local player = game.get_player(event.player_index)
if not player or not player.valid then
return
end
local enemy = game.forces.enemy
-- scrap entities drop loot
buffer.clear()
local scrap = scrap_raffle[random(1, size_of_scrap_raffle)]
local scrap_amount_modifier = 3
local amount_bonus = scrap_amount_modifier * (enemy.evolution_factor * 2) + (player.force.mining_drill_productivity_bonus * 2)
local amount
if entity_loot_amounts[scrap] <= 0 then
amount = math.abs(entity_loot_amounts[scrap])
else
local m1 = 0.3 + (amount_bonus * 0.3)
local m2 = 1.7 + (amount_bonus * 1.7)
local r1 = math.ceil(entity_loot_amounts[scrap] * m1)
local r2 = math.ceil(entity_loot_amounts[scrap] * m2)
amount = random(r1, r2)
end
local inserted_count = player.insert({name = scrap, count = amount})
if inserted_count ~= amount then
local amount_to_spill = amount - inserted_count
entity.surface.spill_item_stack(position, {name = scrap, count = amount_to_spill}, true)
end
entity.surface.create_entity(
{
name = 'flying-text',
position = position,
text = '+' .. amount .. ' [img=item/' .. scrap .. ']',
color = {r = 0.98, g = 0.66, b = 0.22}
}
)
end
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)

View File

@ -44,8 +44,6 @@ local function treasure_chest(position, surface)
{{name = 'firearm-magazine', count = math_random(32, 128)}, weight = 10, evolution_min = 0, evolution_max = 0.3},
{{name = 'piercing-rounds-magazine', count = math_random(32, 128)}, weight = 10, evolution_min = 0.1, evolution_max = 0.8},
{{name = 'uranium-rounds-magazine', count = math_random(32, 128)}, weight = 10, evolution_min = 0.5, evolution_max = 1},
{{name = 'railgun', count = 1}, weight = 1, evolution_min = 0.2, evolution_max = 1},
{{name = 'railgun-dart', count = math_random(16, 32)}, weight = 3, evolution_min = 0.2, evolution_max = 0.7},
{{name = 'defender-capsule', count = math_random(8, 16)}, weight = 10, evolution_min = 0.0, evolution_max = 0.7},
{{name = 'distractor-capsule', count = math_random(8, 16)}, weight = 10, evolution_min = 0.2, evolution_max = 1},
{{name = 'destroyer-capsule', count = math_random(8, 16)}, weight = 10, evolution_min = 0.3, evolution_max = 1},

View File

@ -14,6 +14,7 @@ local auto_stash_button_name = Gui.uid_name()
local this = {
floating_text_y_offsets = {},
whitelist = {},
insert_to_neutral_chests = false,
insert_into_furnace = false,
insert_into_wagon = false,
bottom_button = false,
@ -167,22 +168,17 @@ local function get_nearby_chests(player, a, furnace, wagon)
inventory_type = defines.inventory.cargo_wagon
end
for _, e in pairs(player.surface.find_entities_filtered({type = container_type, area = area, force = player.force})) do
local forces = player.force
if this.insert_to_neutral_chests then
forces = {player.force, 'neutral'}
end
for _, e in pairs(player.surface.find_entities_filtered({type = container_type, area = area, force = forces})) do
if ((player.position.x - e.position.x) ^ 2 + (player.position.y - e.position.y) ^ 2) <= r_square then
i = i + 1
containers[i] = e
end
end
if #containers <= 0 then
if is_mod_loaded('Krastorio2') then
for _, e in pairs(player.surface.find_entities_filtered({type = 'assembling-machine', area = area, force = player.force})) do
if ((player.position.x - e.position.x) ^ 2 + (player.position.y - e.position.y) ^ 2) <= r_square then
i = i + 1
containers[i] = e
end
end
end
end
sort_entities_by_distance(player.position, containers)
for _, entity in pairs(containers) do
@ -626,10 +622,10 @@ local function do_whitelist()
this.whitelist = {}
for k, _ in pairs(resources) do
if resources[k] and resources[k].type == 'resource' and resources[k].mineable_properties then
if resources[k].mineable_properties.products[1] then
if resources[k].mineable_properties.products and resources[k].mineable_properties.products[1] then
local r = resources[k].mineable_properties.products[1].name
this.whitelist[r] = true
elseif resources[k].mineable_properties.products[2] then
elseif resources[k].mineable_properties.products and resources[k].mineable_properties.products[2] then
local r = resources[k].mineable_properties.products[2].name
this.whitelist[r] = true
end
@ -665,27 +661,19 @@ Gui.on_click(
)
function Public.insert_into_furnace(value)
if value then
this.insert_into_furnace = value
else
this.insert_into_furnace = false
end
this.insert_into_furnace = value or false
end
function Public.insert_into_wagon(value)
if value then
this.insert_into_wagon = value
else
this.insert_into_wagon = false
end
this.insert_into_wagon = value or false
end
function Public.bottom_button(value)
if value then
this.bottom_button = value
else
this.bottom_button = false
end
this.bottom_button = value or false
end
function Public.insert_to_neutral_chests(value)
this.insert_to_neutral_chests = value or false
end
function Public.set_dungeons_initial_level(value)

View File

@ -21,6 +21,7 @@ Global.register(
)
local Public = {events = {remove_surface = Event.generate_event_name('remove_surface')}}
local remove = table.remove
function Public.remove_offline_players()
if not this.settings.offline_players_enabled then
@ -35,6 +36,9 @@ function Public.remove_offline_players()
return error('An active surface index must be set', 2)
end
local surface = game.get_surface(this.settings.active_surface_index)
if not surface or not surface.valid then
return
end
local player_inv = {}
local items = {}
if #this.offline_players > 0 then
@ -43,7 +47,7 @@ function Public.remove_offline_players()
local target = game.get_player(this.offline_players[i].index)
if target and target.valid then
if target.connected then
this.offline_players[i] = nil
remove(this.offline_players, i)
else
if this.offline_players[i].tick < tick then
local name = this.offline_players[i].name
@ -57,7 +61,7 @@ function Public.remove_offline_players()
end
if target.get_item_count() == 0 then -- if the player has zero items, don't do anything
this.offline_players[i] = nil
remove(this.offline_players, i)
goto final
end
@ -70,7 +74,16 @@ function Public.remove_offline_players()
force = 'neutral'
}
)
if not e or not e.valid then
break
end
local inv = e.get_inventory(defines.inventory.character_main)
if not inv then
break
end
---@diagnostic disable-next-line: assign-type-mismatch
e.character_inventory_slots_bonus = #player_inv[1]
for ii = 1, 5, 1 do
if player_inv[ii].valid then
@ -104,7 +117,8 @@ function Public.remove_offline_players()
player_inv[ii].clear()
end
end
this.offline_players[i] = nil
remove(this.offline_players, i)
break
end
::final::
@ -133,6 +147,11 @@ function Public.set_active_surface_index(value)
this.settings.active_surface_index = value or nil
end
--- Clears the offline table
function Public.clear_offline_players()
this.offline_players = {}
end
local remove_offline_players = Public.remove_offline_players
Event.on_nth_tick(200, remove_offline_players)
@ -146,7 +165,7 @@ Event.add(
local player = game.get_player(event.player_index)
local ticker = game.tick
if player.online_time >= this.settings.required_online_time then
if player and player.online_time >= this.settings.required_online_time then
if player.character then
this.offline_players[#this.offline_players + 1] = {
index = event.player_index,

View File

@ -59,7 +59,7 @@ local function on_player_died(event)
if cause.type == 'car' then
local driver = cause.get_driver()
if driver.player then
if driver and driver.player then
game.print(player.name .. tag .. ' was killed by ' .. driver.player.name .. ' ' .. player.tag .. '.', message_color)
return
end

View File

@ -0,0 +1,102 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Public = {}
--by hanakocz
--module to alternate what happens when landmine gets detonated
--nuke module: there is 1 in nuke_chance chance that the landmine was hidden nuclear device
--vehicle module: landmine causes affected vehicles to lose part of speed
--vehicle_slowdown should be <0, 1>, where 1 is no effect and 0 is full loss of speed
--can also add bonus damage to hit vehicles, as landmines should be counterplay to tanks,
-- while just buffing their damage causes players being oneshot and that's not fun.
local this = {
nuke_landmines = false,
nuke_chance = 512,
vehicle_effects = true,
bonus_damage_to_vehicles = 100,
vehicle_slowdown = 0.4
}
Global.register(
this,
function(tbl)
this = tbl
end
)
local function detonate_nuke(entity)
local surface = entity.surface
surface.create_entity({name = 'atomic-rocket', position = entity.position, force = entity.force, speed = 1, max_range = 800, target = entity, source = entity})
end
local function hit_car(car, hitting_force)
if not car or not car.valid then return end
car.speed = car.speed * this.vehicle_slowdown
if this.bonus_damage_to_vehicles > 0 then
--cars do have no resistance to explosions and 450 hp
--tanks do have 15/70% resistance to explosions and 2000 hp, so get (damage - 15) * (1 - 0.70) actual damage
car.damage(this.bonus_damage_to_vehicles, hitting_force or 'enemy', 'explosion')
end
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then
return
end
if entity.type == 'land-mine' and entity.armed then
if this.vehicle_effects then
local surface = entity.surface
local cars = surface.find_entities_filtered{type = 'car', position = entity.position, radius = 6}
for _, car in pairs(cars) do
if car.force.is_enemy(entity.force) then
hit_car(car, entity.force)
end
end
end
if this.nuke_landmines then
if math.random(1, this.nuke_chance) == 1 then
detonate_nuke(entity)
end
end
end
end
--- Forces a value of nuke_landmines
---@param boolean
function Public.enable_nuke_landmines(boolean)
this.nuke_landmines = boolean or false
return this.nuke_landmines
end
--- Forces a value of vehicle_effects
---@param boolean
function Public.enable_vehicle_effects(boolean)
this.vehicle_effects = boolean or false
return this.vehicle_effects
end
--- Forces a number for bonus_damage_to_vehicles
---@param number
function Public.set_bonus_damage_to_vehicles(number)
if number and type(number) == 'number' then
this.bonus_damage_to_vehicles = number or 0
end
return this.bonus_damage_to_vehicles
end
--- Forces a number for vehicle_slowdown
---@param number
function Public.set_vehicle_slowdown(number)
if number and type(number) == 'number' then
this.vehicle_slowdown = number or 1
end
return this.vehicle_slowdown
end
Event.add(defines.events.on_entity_died, on_entity_died)
return Public

View File

@ -144,9 +144,11 @@ local function fish_in_space_gui(player)
progress = 1
end
local progressbar = frame.add({type = 'progressbar', value = progress})
progressbar.style.minimal_width = 100
progressbar.style.maximal_width = 100
progressbar.style.top_padding = 10
progressbar.style = 'achievement_progressbar'
progressbar.style.minimal_width = 96
progressbar.style.maximal_width = 96
progressbar.style.padding = -1
progressbar.style.top_padding = 1
label = frame.add({type = 'label', caption = global.fish_in_space .. '/' .. tostring(global.catplanet_goals[i + 1].goal)})
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}

View File

@ -1,27 +0,0 @@
local math_random = math.random
local function detonate_nuke(entity)
local surface = entity.surface
surface.create_entity({name = 'atomic-rocket', position = entity.position, force = entity.force, speed = 1, max_range = 800, target = entity, source = entity})
end
local function on_entity_died(event)
local entity = event.entity
if not entity.valid then
return
end
if entity.name == 'land-mine' then
if math_random(1, global.nuclear_landmines.chance) == 1 then
detonate_nuke(entity)
end
end
end
local function on_init()
global.nuclear_landmines = {}
global.nuclear_landmines.chance = 512
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_entity_died, on_entity_died)

View File

@ -45,10 +45,11 @@ local remove = table.remove
local speed = 0.06
--- Draws a new render.
---@return integer
---@return table
function Public:new_render()
local surface = game.get_surface(self.surface_id)
self.render_id = rendering.draw_sprite {target = self.position, sprite = self.sprite, surface = surface}
return self
end
--- Sets a new target for a given render.

View File

@ -90,7 +90,7 @@ local function on_gui_click(event)
elseif event.button == defines.mouse_button_type.right then
local left = rpg_t.points_left / 2
if left > 2 then
for _ = 1, left, 1 do
for _ = 2, left, 1 do -- for _ = 1 results in uneven distribution
if rpg_t.points_left <= 0 then
Public.toggle(player, true)
return

View File

@ -1,593 +0,0 @@
local Public = {}
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 blacklist_entity_types = {
['car'] = true,
['character'] = true,
['combat-robot'] = true,
['construction-robot'] = true,
['logistic-robot'] = true,
['entity-ghost'] = true,
['character-corpse'] = true,
['corpse'] = true
}
-- these should be allowed to place inside any base by outlanders as neutral
local neutral_whitelist = {
['burner-inserter'] = true,
['car'] = true,
['coin'] = true,
['express-loader'] = true,
['fast-inserter'] = true,
['fast-loader'] = true,
['filter-inserter'] = true,
['inserter'] = true,
['iron-chest'] = true,
['loader'] = true,
['long-handed-inserter'] = true,
['raw-fish'] = true,
['stack-filter-inserter'] = true,
['stack-inserter'] = true,
['steel-chest'] = true,
['tank'] = true,
['wooden-chest'] = true
}
-- these should be allowed to place outside any base by town players
local team_whitelist = {
['burner-inserter'] = true,
['car'] = true,
['cargo-wagon'] = true,
['coin'] = true,
['curved-rail'] = true,
['electric-pole'] = true,
['express-loader'] = true,
['fast-inserter'] = true,
['fast-loader'] = true,
['filter-inserter'] = true,
['inserter'] = true,
['fluid-wagon'] = true,
['iron-chest'] = true,
['loader'] = true,
['long-handed-inserter'] = true,
['locomotive'] = true,
['rail'] = true,
['rail-chain-signal'] = true,
['rail-signal'] = true,
['raw-fish'] = true,
['stack-filter-inserter'] = true,
['stack-inserter'] = true,
['steel-chest'] = true,
['straight-rail'] = true,
['tank'] = true,
['train-stop'] = true,
['wooden-chest'] = true
}
-- these need to be prototypes
local team_entities = {
['accumulator'] = true,
['ammo-turret'] = true,
['arithmetic-combinator'] = true,
['artillery-turret'] = true,
['assembling-machine'] = true,
['beacon'] = true,
['boiler'] = true,
['burner-generator'] = true,
['constant-combinator'] = true,
['container'] = true,
['decider-combinator'] = true,
['electric-energy-interface'] = true,
['electric-pole'] = true,
['electric-turret'] = true,
['fluid-turret'] = true,
['furnace'] = true,
['gate'] = true,
['generator'] = true,
['heat-interface'] = true,
['heat-pipe'] = true,
['infinity-container'] = true,
['infinity-pipe'] = true,
['inserter'] = true,
['lab'] = true,
['lamp'] = true,
['land-mine'] = true,
['linked-belt'] = true,
['linked-container'] = true,
['loader'] = true,
['loader-1x1'] = true,
['logistic-container'] = true,
['market'] = true,
['mining-drill'] = true,
['offshore-pump'] = true,
['pipe'] = true,
['pipe-to-ground'] = true,
['player-port'] = true,
['power-switch'] = true,
['programmable-speaker'] = true,
['pump'] = true,
['radar'] = true,
['reactor'] = true,
['roboport'] = true,
['rocket-silo'] = true,
['solar-panel'] = true,
['splitter'] = true,
['storage-tank'] = true,
['transport-belt'] = true,
['underground-belt'] = true,
['wall'] = true
}
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}}
local count = 0
for _, e in pairs(surface.find_entities_filtered({area = area, force = force.name})) do
if team_entities[e.type] then
count = count + 1
if count > 1 then
return false
end -- are there more than one team entities in the area?
end
end
return true
end
local function refund_item(event, item_name)
if item_name == 'blueprint' then
return
end
if event.player_index ~= nil then
game.players[event.player_index].insert({name = item_name, count = 1})
return
end
-- return item to robot, but don't replace ghost (otherwise might loop)
if event.robot ~= nil then
local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
inventory.insert({name = item_name, count = 1})
return
end
end
local function error_floaty(surface, position, msg)
surface.create_entity(
{
name = 'flying-text',
position = position,
text = msg,
color = {r = 0.77, g = 0.0, b = 0.0}
}
)
end
function Public.in_range(pos1, pos2, radius)
if pos1 == nil then
return false
end
if pos2 == nil then
return false
end
if radius < 1 then
return true
end
local dx = pos1.x - pos2.x
local dy = pos1.y - pos2.y
if dx ^ 2 + dy ^ 2 < radius ^ 2 then
return true
end
return false
end
function Public.in_area(position, area_center, area_radius)
if position == nil then
return false
end
if area_center == nil then
return false
end
if area_radius < 1 then
return true
end
if position.x >= area_center.x - area_radius and position.x <= area_center.x + area_radius then
if position.y >= area_center.y - area_radius and position.y <= area_center.y + area_radius then
return true
end
end
return false
end
-- is the position near another town?
function Public.near_another_town(force_name, position, surface, radius)
-- check for nearby town centers
if force_name == nil then
return false
end
local ffatable = Table.get_table()
local forces = {}
-- check for nearby town centers
local fail = false
if table_size(ffatable.town_centers) > 0 then
for _, town_center in pairs(ffatable.town_centers) do
if town_center ~= nil then
local market = town_center.market
if market ~= nil and market.valid then
local market_force = market.force
if market_force ~= nil then
if market_force.name ~= nil then
table_insert(forces, market_force.name)
if force_name ~= market_force.name then
if Public.in_range(position, market.position, radius) == true then
fail = true
break
end
end
end
end
end
end
end
if fail == true then
return true
end
end
-- check for nearby town entities
if table.size(forces) > 0 then
local entities = surface.find_entities_filtered({position = position, radius = radius, force = forces})
for _, e in pairs(entities) do
if e.valid and e.force ~= nil then
local entity_force_name = e.force.name
--if force_name ~= force.name and force_name ~= 'enemy' and force_name ~= 'neutral' and force_name ~= 'player' and force_name ~= 'rogue' then
if entity_force_name ~= nil then
if entity_force_name ~= force_name then
if blacklist_entity_types[e.type] ~= true then
fail = true
break
end
end
end
end
end
if fail == true then
return true
end
end
return false
end
local function in_own_town(force, position)
local ffatable = Table.get_table()
local town_center = ffatable.town_centers[force.name]
if town_center ~= nil then
local market = town_center.market
if market ~= nil then
local 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
end
return false
end
function Public.in_restricted_zone(surface, position)
if surface.name ~= 'nauvis' then
return false
end
local chunk_position = {}
chunk_position.x = math_floor(position.x / 32)
chunk_position.y = math_floor(position.y / 32)
if chunk_position.x <= -33 or chunk_position.x >= 32 or chunk_position.y <= -33 or chunk_position.y >= 32 then
return true
end
return false
end
local function prevent_entity_in_restricted_zone(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 error = false
if Public.in_restricted_zone(surface, position) then
error = true
entity.destroy()
local item = event.item
if name ~= 'entity-ghost' and name ~= 'tile-ghost' and item ~= nil then
refund_item(event, item.name)
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, 'Can not build in restricted zone!')
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
if tile == nil or not tile.valid then
return
end
local surface = game.surfaces[event.surface_index]
local fail = false
local position
for _, t in pairs(event.tiles) do
local old_tile = t.old_tile
position = t.position
if Public.in_restricted_zone(surface, position) then
fail = true
surface.set_tiles({{name = old_tile.name, position = position}}, true)
refund_item(event, tile.name)
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, 'Can not build in restricted zone!')
end
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
if entity == nil or not entity.valid then
return
end
local name = entity.name
local surface = entity.surface
local position = entity.position
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
else
local robot = event.robot
if robot ~= nil then
local force = robot.force
if force ~= nil then
force_name = force.name
end
end
end
if Public.near_another_town(force_name, position, surface, 32) == true then
if neutral_whitelist[name] then
entity.force = game.forces['neutral']
else
entity.destroy()
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, "Can't build near town!")
if name ~= 'entity-ghost' then
refund_item(event, event.stack.name)
end
return
end
end
end
local function prevent_tiles_near_towns(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 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
else
local robot = event.robot
if robot ~= nil then
local force = robot.force
if force ~= nil then
force_name = force.name
end
end
end
local fail = false
local position
for _, t in pairs(event.tiles) do
local old_tile = t.old_tile
position = t.position
if Public.near_another_town(force_name, position, surface, 32) == true then
fail = true
surface.set_tiles({{name = old_tile.name, position = position}}, true)
refund_item(event, tile.name)
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, "Can't build near town!")
end
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'
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

@ -1,48 +0,0 @@
local string_sub = string.sub
local string_len = string.len
-- ammo damage modifiers are static values that increase with research
-- modifier is multiplied by base damage and then added to damage, so a negative value will reduce base damage and a positive value will increase damage
local balance_functions = {
['land-mine'] = function(force_name)
-- landmines normally have a modifier of 0, so have them start at 25% of normal
if force_name ~= nil then
game.forces[force_name].set_ammo_damage_modifier('landmine', -0.75)
end
end,
['military-2'] = function(force_name)
-- grenades normally have a modifier of 0, so have them start at 50% of normal
if force_name ~= nil then
game.forces[force_name].set_ammo_damage_modifier('grenade', -0.5)
end
end,
['military-4'] = function(force_name)
-- cluster-grenades normally have a modifier of 0, so have them start at 50% of normal
if force_name ~= nil then
game.forces[force_name].set_ammo_damage_modifier('grenade', -0.5)
end
end,
['stronger-explosives'] = function(force_name)
-- landmines should never increase in damage with stronger explosives
if force_name ~= nil then
game.forces[force_name].set_ammo_damage_modifier('landmine', -0.75)
-- allow grenades to increase by 10%
game.forces[force_name].set_ammo_damage_modifier('grenade', game.forces[force_name].get_ammo_damage_modifier('grenade') + 0.1)
end
end
}
local function on_research_finished(event)
local research_name = event.research.name
local force_name = event.research.force.name
for b = 1, string_len(research_name), 1 do
local key = string_sub(research_name, 0, b)
if balance_functions[key] then
balance_functions[key](force_name)
return
end
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_research_finished, on_research_finished)

View File

@ -1,75 +0,0 @@
local Public = {}
local math_random = math.random
local math_floor = math.floor
local Table = require 'modules.scrap_towny_ffa.table'
function Public.reproduce()
local ffatable = Table.get_table()
for _, town_center in pairs(ffatable.town_centers) do
local surface = town_center.market.surface
local position = town_center.market.position
local fishes = surface.find_entities_filtered({name = 'fish', position = position, radius = 27})
if #fishes == 0 then
return
end
if #fishes >= 128 then
return
end
-- pick a random fish
local t = math_random(1, #fishes)
local fish = fishes[t]
-- test against all other fishes
local guppy = false
for i, f in pairs(fishes) do
if i ~= t then
if math_floor(fish.position.x) == math_floor(f.position.x) and math_floor(fish.position.y) == math_floor(f.position.y) then
guppy = true
end
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})
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

@ -1,140 +0,0 @@
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".
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.
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.
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.
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'})
b.style.font_color = {r = 0.5, g = 0.3, b = 0.99}
b.style.font = 'heading-1'
b.style.minimal_height = 38
b.style.minimal_width = 80
b.style.top_padding = 1
b.style.left_padding = 1
b.style.right_padding = 1
b.style.bottom_padding = 1
end
function Public.show(player)
local ffatable = Table.get_table()
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
end
local frame = player.gui.center.add {type = 'frame', name = 'towny_map_intro_frame'}
frame = frame.add {type = 'frame', direction = 'vertical'}
local t = frame.add {type = 'table', column_count = 2}
local label = t.add {type = 'label', caption = 'Active Factions:'}
label.style.font = 'heading-1'
label.style.font_color = {r = 0.85, g = 0.85, b = 0.85}
label.style.right_padding = 8
t = t.add {type = 'table', column_count = 4}
local label2 = t.add {type = 'label', caption = 'Outlander' .. ':' .. #game.forces.player.connected_players .. ' '}
label2.style.font_color = {170, 170, 170}
label2.style.font = 'heading-3'
label2.style.minimal_width = 80
for _, town_center in pairs(ffatable.town_centers) do
local force = town_center.market.force
local label3 = t.add {type = 'label', caption = force.name .. ':' .. #force.connected_players .. ' '}
label3.style.font = 'heading-3'
label3.style.minimal_width = 80
label3.style.font_color = town_center.color
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}
l2.style.single_line = false
l2.style.font = 'heading-2'
l2.style.font_color = {r = 0.8, g = 0.7, b = 0.99}
end
function Public.close(event)
if not event.element then
return
end
if not event.element.valid then
return
end
local parent = event.element.parent
for _ = 1, 4, 1 do
if not parent then
return
end
if parent.name == 'towny_map_intro_frame' then
parent.destroy()
return
end
parent = parent.parent
end
end
function Public.toggle(event)
if not event.element then
return
end
if not event.element.valid then
return
end
if event.element.name == 'towny_map_intro_button' then
local player = game.players[event.player_index]
if player.gui.center['towny_map_intro_frame'] then
player.gui.center['towny_map_intro_frame'].destroy()
else
Public.show(player)
end
end
end
local function on_gui_click(event)
Public.close(event)
Public.toggle(event)
end
local Event = require 'utils.event'
Event.add(defines.events.on_gui_click, on_gui_click)
return Public

View File

@ -1,215 +0,0 @@
local Public = {}
--local Server = require 'utils.server'
local function create_limbo()
game.create_surface('limbo')
end
local function initialize_nauvis()
local surface = game.surfaces['nauvis']
-- this overrides what is in the map_gen_settings.json file
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'},
['uranium-ore'] = {frequency = 'none', size = 1, richness = 'normal'},
['crude-oil'] = {frequency = 'very-low', size = 'very-small', richness = 'normal'},
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'}
}
},
decorative = {
settings = {
['rock-tiny'] = {frequency = 10, size = 'normal', richness = 'normal'},
['rock-small'] = {frequency = 5, size = 'normal', richness = 'normal'},
['rock-medium'] = {frequency = 2, size = 'normal', richness = 'normal'},
['sand-rock-small'] = {frequency = 10, size = 'normal', richness = 'normal'},
['sand-rock-medium'] = {frequency = 5, size = 'normal', richness = 'normal'}
}
}
}
mgs.cliff_settings = {
name = 'cliff',
cliff_elevation_0 = 5,
cliff_elevation_interval = 10,
richness = 0.4
}
-- water = 0 means no water allowed
-- water = 1 means elevation is not reduced when calculating water tiles (elevation < 0)
-- water = 2 means elevation is reduced by 10 when calculating water tiles (elevation < 0)
-- or rather, the water table is 10 above the normal elevation
mgs.water = 0.5
mgs.peaceful_mode = false
mgs.starting_area = 'none'
mgs.terrain_segmentation = 8
-- terrain size is 64 x 64 chunks, water size is 80 x 80
mgs.width = 2560
mgs.height = 2560
--mgs.starting_points = {
-- {x = 0, y = 0}
--}
mgs.research_queue_from_the_start = 'always'
-- here we put the named noise expressions for the specific noise-layer if we want to override them
mgs.property_expression_names = {
-- here we are overriding the moisture noise-layer with a fixed value of 0 to keep moisture consistently dry across the map
-- it allows to free up the moisture noise expression
-- low moisture
--moisture = 0,
-- here we are overriding the aux noise-layer with a fixed value to keep aux consistent across the map
-- it allows to free up the aux noise expression
-- aux should be not sand, nor red sand
--aux = 0.5,
-- here we are overriding the temperature noise-layer with a fixed value to keep temperature consistent across the map
-- it allows to free up the temperature noise expression
-- temperature should be 20C or 68F
--temperature = 20,
-- here we are overriding the cliffiness noise-layer with a fixed value of 0 to disable cliffs
-- it allows to free up the cliffiness noise expression (which may or may not be useful)
-- disable cliffs
--cliffiness = 0,
-- we can disable starting lakes two ways, one by setting starting-lake-noise-amplitude = 0
-- or by making the elevation a very large number
-- make sure starting lake amplitude is 0 to disable starting lakes
['starting-lake-noise-amplitude'] = 0,
-- allow enemies to get up close on spawn
['starting-area'] = 0,
-- this accepts a string representing a named noise expression
-- or number to determine the elevation based on x, y and distance from starting points
-- we can not add a named noise expression at this point, we can only reference existing ones
-- if we have any custom noise expressions defined from a mod, we will be able to use them here
-- setting it to a fixed number would mean a flat map
-- elevation < 0 means there is water unless the water table has been changed
--elevation = -1,
--elevation = 0,
--elevation-persistence = 0,
-- testing
--["control-setting:moisture:bias"] = 0.5,
--["control-setting:moisture:frequency:multiplier"] = 0,
--["control-setting:aux:bias"] = 0.5,
--["control-setting:aux:frequency:multiplier"] = 1,
--["control-setting:temperature:bias"] = 0.01,
--["control-setting:temperature:frequency:multiplier"] = 100,
--["tile:water:probability"] = -1000,
--["tile:deep-water:probability"] = -1000,
-- a constant intensity means base distribution will be consistent with regard to distance
['enemy-base-intensity'] = 1,
-- adjust this value to set how many nests spawn per tile
['enemy-base-frequency'] = 0.4,
-- this will make and average base radius around 12 tiles
['enemy-base-radius'] = 12
}
mgs.seed = game.surfaces[1].map_gen_settings.seed
surface.map_gen_settings = mgs
surface.peaceful_mode = false
surface.always_day = false
surface.freeze_daytime = false
surface.clear(true)
surface.regenerate_entity({'rock-huge', 'rock-big', 'sand-rock-big'})
surface.regenerate_decorative()
-- this will force generate the entire map
--Server.to_discord_embed('ScrapTownyFFA Map Regeneration in Progress')
--surface.request_to_generate_chunks({x=0,y=0},64)
--surface.force_generate_chunk_requests()
--Server.to_discord_embed('Regeneration Complete')
end
local function initialize_limbo()
local surface = game.surfaces['limbo']
surface.generate_with_lab_tiles = true
surface.peaceful_mode = true
surface.always_day = true
surface.freeze_daytime = true
surface.clear(true)
end
function Public.initialize()
-- difficulty settings
game.difficulty_settings.recipe_difficulty = defines.difficulty_settings.recipe_difficulty.normal
game.difficulty_settings.technology_difficulty = defines.difficulty_settings.technology_difficulty.normal
game.difficulty_settings.technology_price_multiplier = 0.50
-- pollution settings
game.map_settings.pollution.enabled = true
game.map_settings.pollution.diffusion_ratio = 0.02 -- amount that is diffused to neighboring chunk each second
game.map_settings.pollution.min_to_diffuse = 15 -- minimum number of pollution units on the chunk to start diffusing
game.map_settings.pollution.ageing = 1 -- percent of pollution eaten by a chunk's tiles per second
game.map_settings.pollution.expected_max_per_chunk = 150 -- anything greater than this number of pollution units is visualized similarly
game.map_settings.pollution.min_to_show_per_chunk = 50
game.map_settings.pollution.min_pollution_to_damage_trees = 60
game.map_settings.pollution.pollution_with_max_forest_damage = 150
game.map_settings.pollution.pollution_per_tree_damage = 50
game.map_settings.pollution.pollution_restored_per_tree_damage = 10
game.map_settings.pollution.max_pollution_to_restore_trees = 20
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 1
-- enemy evolution settings
game.map_settings.enemy_evolution.enabled = true
game.map_settings.enemy_evolution.time_factor = 0.0 -- percent increase in the evolution factor per second
game.map_settings.enemy_evolution.destroy_factor = 0.0 -- percent increase in the evolution factor for each spawner destroyed
game.map_settings.enemy_evolution.pollution_factor = 0.0 -- percent increase in the evolution factor for each pollution unit
-- enemy expansion settings
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_distance = 7 -- maximum distance in chunks from the nearest base (4 = 128 tiles)
game.map_settings.enemy_expansion.friendly_base_influence_radius = 4 -- consider other nests within radius number of chunks (2 = 64 tiles)
game.map_settings.enemy_expansion.other_base_coefficient = 2.0 -- multiply by coefficient for friendly bases
game.map_settings.enemy_expansion.neighbouring_base_chunk_coefficient = 0.4 -- multiply by coefficient for friendly bases (^distance)
game.map_settings.enemy_expansion.enemy_building_influence_radius = 4 -- consider player buildings within radius number of chunks
game.map_settings.enemy_expansion.building_coefficient = 1.0 -- multiply by coefficient for player buildings
game.map_settings.enemy_expansion.neighbouring_chunk_coefficient = 0.5 -- multiply by coefficient for player buildings (^distance)
game.map_settings.enemy_expansion.max_colliding_tiles_coefficient = 0.9 -- percent of unbuildable tiles to not be considered a candidate
game.map_settings.enemy_expansion.settler_group_min_size = 4 -- min size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.settler_group_max_size = 12 -- max size of group for building a base (multiplied by evo factor, so need evo > 0)
game.map_settings.enemy_expansion.min_expansion_cooldown = 1200 -- minimum time before next expansion
game.map_settings.enemy_expansion.max_expansion_cooldown = 3600 -- maximum time before next expansion
-- unit group settings
game.map_settings.unit_group.min_group_gathering_time = 400
game.map_settings.unit_group.max_group_gathering_time = 2400
game.map_settings.unit_group.max_wait_time_for_late_members = 3600
game.map_settings.unit_group.max_group_radius = 30.0
game.map_settings.unit_group.min_group_radius = 5.0
game.map_settings.unit_group.max_member_speedup_when_behind = 1.4
game.map_settings.unit_group.max_member_slowdown_when_ahead = 0.6
game.map_settings.unit_group.max_group_slowdown_factor = 0.3
game.map_settings.unit_group.max_group_member_fallback_factor = 3
game.map_settings.unit_group.member_disown_distance = 10
game.map_settings.unit_group.tick_tolerance_when_member_arrives = 60
game.map_settings.unit_group.max_gathering_unit_groups = 30
game.map_settings.unit_group.max_unit_group_size = 200
---- steering settings
--game.map_settings.steering.default.radius = 1.2
--game.map_settings.steering.default.separation_force = 0.005
--game.map_settings.steering.default.separation_factor = 1.2
--game.map_settings.steering.default.force_unit_fuzzy_goto_behavior = false
--game.map_settings.steering.moving.radius = 3
--game.map_settings.steering.moving.separation_force = 0.01
--game.map_settings.steering.moving.separation_factor = 3
--game.map_settings.steering.moving.force_unit_fuzzy_goto_behavior = false
create_limbo()
initialize_limbo()
initialize_nauvis()
end
return Public

View File

@ -1,21 +0,0 @@
local Table = require 'modules.scrap_towny_ffa.table'
local function on_tick()
local ffatable = Table.get_table()
if not ffatable.on_tick_schedule[game.tick] then
return
end
for _, schedule in pairs(ffatable.on_tick_schedule[game.tick]) do
schedule.func(unpack(schedule.args))
end
ffatable.on_tick_schedule[game.tick] = nil
end
local on_init = function()
local ffatable = Table.get_table()
ffatable.on_tick_schedule = {}
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.add(defines.events.on_tick, on_tick)

View File

@ -1,40 +0,0 @@
local Public = {}
local scrapable = {
-- simple entity
'small-ship-wreck',
'medium-ship-wreck',
-- simple entity with owner
'crash-site-spaceship-wreck-small-1',
'crash-site-spaceship-wreck-small-2',
'crash-site-spaceship-wreck-small-3',
'crash-site-spaceship-wreck-small-4',
'crash-site-spaceship-wreck-small-5',
'crash-site-spaceship-wreck-small-6',
'big-ship-wreck-1',
'big-ship-wreck-2',
'big-ship-wreck-3',
'crash-site-chest-1',
'crash-site-chest-2',
'crash-site-spaceship-wreck-medium-1',
'crash-site-spaceship-wreck-medium-2',
'crash-site-spaceship-wreck-medium-3',
'crash-site-spaceship-wreck-big-1',
'crash-site-spaceship-wreck-big-2',
'crash-site-spaceship'
}
function Public.is_scrap(entity)
if not entity.valid then
return false
end
local f = false
for i = 1, #scrapable, 1 do
if entity.name == scrapable[i] then
f = true
end
end
return f
end
return Public

View File

@ -1,49 +0,0 @@
local Public = {}
-- one table to rule them all!
local Global = require 'utils.global'
local ffatable = {}
Global.register(
ffatable,
function(tbl)
ffatable = tbl
end
)
function Public.reset_table()
for k, _ in pairs(ffatable) do
ffatable[k] = nil
end
end
function Public.get_table()
return ffatable
end
function Public.get(key)
if key then
return ffatable[key]
else
return ffatable
end
end
function Public.set(key, value)
if key and (value or value == false) then
ffatable[key] = value
return ffatable[key]
elseif key then
return ffatable[key]
else
return ffatable
end
end
local on_init = function()
Public.reset_table()
end
local Event = require 'utils.event'
Event.on_init(on_init)
return Public

View File

@ -1,112 +0,0 @@
-- timer traps -- by mewmew
local table_insert = table.insert
local math_random = math.random
local Table = require 'modules.scrap_towny_ffa.table'
local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*'}
local kaboom_weights = {
{name = 'grenade', chance = 7},
{name = 'cluster-grenade', chance = 1},
{name = 'destroyer-capsule', chance = 1},
{name = 'defender-capsule', chance = 4},
{name = 'distractor-capsule', chance = 3},
{name = 'poison-capsule', chance = 2},
{name = 'explosive-uranium-cannon-projectile', chance = 3},
{name = 'explosive-cannon-projectile', chance = 5}
}
local kabooms = {}
for _, t in pairs(kaboom_weights) do
for _ = 1, t.chance, 1 do
table_insert(kabooms, t.name)
end
end
local function create_flying_text(surface, position, text)
surface.create_entity(
{
name = 'flying-text',
position = position,
text = text,
color = {r = 0.75, g = 0.75, b = 0.75}
}
)
if text == '...' then
return
end
surface.play_sound({path = 'utility/armor_insert', position = position, volume_modifier = 0.75})
end
local function create_kaboom(surface, position, name)
local target = position
local speed = 0.5
if name == 'defender-capsule' or name == 'destroyer-capsule' or name == 'distractor-capsule' then
surface.create_entity(
{
name = 'flying-text',
position = position,
text = '(((Sentries Engaging Target)))',
color = {r = 0.8, g = 0.0, b = 0.0}
}
)
local nearest_player_unit = surface.find_nearest_enemy({position = position, max_distance = 128, force = 'enemy'})
if nearest_player_unit then
target = nearest_player_unit.position
end
speed = 0.001
end
surface.create_entity(
{
name = name,
position = position,
force = 'enemy',
target = target,
speed = speed
}
)
end
local function tick_tack_trap(surface, position)
local ffatable = Table.get_table()
if not surface then
return
end
if not position then
return
end
if not position.x then
return
end
if not position.y then
return
end
local tick_tack_count = math_random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not ffatable.on_tick_schedule[game.tick + t] then
ffatable.on_tick_schedule[game.tick + t] = {}
end
if t < tick_tack_count * 60 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, tick_tacks[math_random(1, #tick_tacks)]}
}
else
if math_random(1, 10) == 1 then
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_flying_text,
args = {surface, {x = position.x, y = position.y}, '...'}
}
else
ffatable.on_tick_schedule[game.tick + t][#ffatable.on_tick_schedule[game.tick + t] + 1] = {
func = create_kaboom,
args = {surface, {x = position.x, y = position.y}, kabooms[math_random(1, #kabooms)]}
}
end
end
end
end
return tick_tack_trap

Some files were not shown because too many files have changed in this diff Show More