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

Merge pull request #191 from ComfyFactory/chronotrain_optimization_update

Chronotrain optimization update
This commit is contained in:
hanakocz 2021-12-17 18:45:49 +01:00 committed by GitHub
commit cb3821ab46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1285 additions and 775 deletions

View File

@ -101,23 +101,24 @@ local function tick_tack_trap(surface, position)
end
local tick_tack_count = math.random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
local tick = game.tick - (game.tick % 10) + t
if not traps[tick] then
traps[tick] = {}
end
if t < tick_tack_count * 60 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
traps[tick][#traps[tick] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, tick_tacks[math.random(1, #tick_tacks)]}
}
else
if math.random(1, 10) == 1 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
traps[tick][#traps[tick] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, '...'}
}
else
traps[game.tick + t][#traps[game.tick + t] + 1] = {
traps[tick][#traps[tick] + 1] = {
callback = 'create_kaboom',
params = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]}
}
@ -142,6 +143,6 @@ local function on_tick()
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
Event.on_nth_tick(10, on_tick)
return tick_tack_trap

View File

@ -94,21 +94,22 @@ local function unearthing_biters(surface, position, amount)
local evolution = game.forces.enemy.evolution_factor
local ticks = amount * 30
ticks = ticks + 90
for t = 1, ticks, 1 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
local ticks = amount * 40
ticks = ticks + 80
for t = 4, ticks, 4 do
local tick = game.tick - (game.tick % 4) + t
if not traps[tick] then
traps[tick] = {}
end
traps[game.tick + t][#traps[game.tick + t] + 1] = {
traps[tick][#traps[tick] + 1] = {
callback = 'create_particles',
params = {surface, {x = position.x, y = position.y}, 4}
}
if t > 90 then
if t % 30 == 29 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
if t % 40 == 36 then
traps[tick][#traps[tick] + 1] = {
callback = 'spawn_biter',
params = {surface, {x = position.x, y = position.y}, evolution}
}
@ -133,6 +134,6 @@ local function on_tick()
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
Event.on_nth_tick(4, on_tick)
return unearthing_biters

View File

@ -148,18 +148,19 @@ local function unearthing_worm(surface, position)
evolution_index = 1
end
for t = 1, 330, 1 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
for t = 4, 340, 4 do
local tick = game.tick - (game.tick % 4) + t
if not traps[tick] then
traps[tick] = {}
end
traps[game.tick + t][#traps[game.tick + t] + 1] = {
traps[tick][#traps[tick] + 1] = {
callback = 'create_particles',
params = {surface, {x = position.x, y = position.y}, math.ceil(t * 0.05)}
}
if t == 330 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
if t == 340 then
traps[tick][#traps[tick] + 1] = {
callback = 'spawn_worm',
params = {surface, {x = position.x, y = position.y}, evolution_index}
}
@ -183,6 +184,6 @@ local function on_tick()
traps[game.tick] = nil
end
Event.add(defines.events.on_tick, on_tick)
Event.on_nth_tick(4, on_tick)
return unearthing_worm

View File

@ -10,7 +10,7 @@ message_danger1=Comfylatron: We have a problem! We got disrupted in mid-jump, on
message_danger2=Comfylatron: Battery is unstable, we need to survive until it gets full without additional charging.
message_danger3=Robot voice: INTRUDER ALERT! Lifeforms detected!! Must eliminate!!
message_danger4=Robot voice: Nuclear missiles armed. Launch countdown enabled.
message_danger5=Comfylatron: Oh rip. I can deal with one incoming nuke if you help me load the anti-rocket system, but you will need to deal with the rest! Quick! Destroy the silos before they launch!
message_danger5=Comfylatron: Oh rip. We have the anti-rocket system, but ammo only for first use! It might buy us some time, at least. You need to deal with the threat! Quick! Destroy the silos before they launch!
message_rampup50=Comfylatron: Biters start to adapt to our presence, getting stronger every second...
message_overstay=Comfylatron: We took so long to get off that planet, our future destinations have evolved a little...
message_jump180=Comfylatron: Train is fully charged! Countdown sequence enabled. 180 seconds 'till jump!
@ -20,7 +20,7 @@ message_jump10=Comfylatron: Jump in __1__ seconds!
message_jump=Comfylatron: Wheeee! Time jump underway! This is Jump number __1__
message_poison_defense=Comfylatron: Triggering poison defense. Let's kill everything!
message_nuke=Warning: Nuclear missiles launched.
message_nuke_intercepted=Your Rocket shield successfully intercepted one of the incoming nukes.
message_nuke_intercepted=Your Rocket shield successfully intercepted enemy nuclear strike.
message_accident=Comfylatron: Offline player had an accident, and their corpse fell to the ground near the locomotive.
message_silo=Nuclear silo destroyed. You looted __1__ atomic bombs. Comfylatron seized them for your own safety.
message_game_won_restart=Comfylatron: WAIT whaat? Looks like we did not fixed the train properly and it teleported us back in time...sigh...so let's do this again, and now properly.
@ -45,6 +45,7 @@ message_comfylatron_desync=Comfylatron: I got you that time! Back to work, __1__
message_quest_research=Comfylatron: Oh MY GOD! Your research is soooo slow! Here, I made some adjustments for our labs, bring me some!
message_poison_mastery_unlock=Comfylatron: Why so dead of this thing called poison? Why you can't be like me, immune to it? Come on! Let's start some poison research!
spidertron_not_allowed=Spidertron can be used only on Final Map!
message_giftmas_spawned=Free Gifts appeared from thin air at [gps=__1__,__2__,__3__]! Looks like we were behaving nicely this year.
difficulty1=Suitable for singleplayer. Way less pollution, biters attack less, upgrades are cheaper, etc.
difficulty2=Small team of friends might pick this. Less pollution, less biter attacks, but not completely trivial.
@ -97,6 +98,7 @@ map_5_1=Hedge Maze
map_6_1=Riverlands
map_7_1=Fish Market
map_8_1=Methane Swamps
map_9_1=The Factory
ore_richness_very_rich=Very Rich
ore_richness_rich=Rich
@ -160,7 +162,7 @@ upgrade_computer4=Comfylatron's Final Quest
upgrade_computer4_message=Comfylatron: TIME SYNCHRONIZED... CALCULATING SPACETIME DESTINATION... Done! Power up the chrono engines once more and let me deliver the fish finally. This trip is getting long.
upgrade_computer4_tooltip=Progresses main quest.\nBy unlocking this, the next destination is Fish Market.\nBe sure to be ready, there's no way back! You will get spidertrons back, but use empty ones here!
upgrade_nukeshied=Rocket Shield Dome System
upgrade_nukeshield_message=Comfylatron: Rocket Shield system protection online, but it can deal with single target at once!
upgrade_nukeshield_message=Comfylatron: Rocket Shield system protection online, but it needs to be reloaded after each use!
upgrade_nukeshield_tooltip=Defense against incoming nuke.
upgrade_researchspeed=Better Laboratories
upgrade_researchspeed_message=Comfylatron: Finally we can catch up on the research!
@ -186,6 +188,12 @@ upgrade_nuclear_artillery_ammo_tooltip=One Nuke is used whenever Artillery shoot
upgrade_poison_mastery=Poison Mastery
upgrade_poison_mastery_message=Comfylatron: Now our poisons are more potent, while you silly humans actually learned how to use gas masks.
upgrade_poison_mastery_tooltip=+25% potency of poison capsules. Players take less damage from poison.
upgrade_giftmas=Giftmas Train Decoration
upgrade_giftmas_message=Comfylatron: Ho Ho Ho, maybe this Giftmas train decoration will lure in some Gifts!
upgrade_giftmas_tooltip=Adds seasonal train decoration, one gift drop per map per level can spawn randomly outside.
upgrade_radar=Radar Station
upgrade_radar_message=Comfylatron: I put some antennas on the train. Fancy sight!
upgrade_radar_tooltip=Grants full radar coverage inside train. Map outside is revealed when generated.
token_biters=Biter Killing Research Token
token_biters_add=+ __1__ Biter Killing Research Token
@ -209,6 +217,8 @@ gui_3=Charged in:
gui_3_1=Best Case:
gui_3_2=Nuclear missiles launched in:
gui_3_3=JUMP IN:
gui_3_4=WARMUP. Research [technology=logistic-science-pack] to start the timer.
gui_3_5=Initial timer until jump will be 15 minutes.
gui_4=Local Evolution:
gui_world_button=Area Info
gui_upgrades_button=Upgrades

View File

@ -9,9 +9,9 @@ message_danger1=Комфилатрон: У нас проблемы! Мы про
message_danger2=Комфилатрон: Аккумулятор нестабилен, нам нужно дожить до полного заряда без дополнительной зарядки.
message_danger3=Голос робота: УГРОЗА ВТОРЖЕНИЯ! Обнаружены жизненные формы!! Необходимо уничтожить!!
message_danger4=Голос робота: Ядерные ракеты в готовности. Обратный отсчет запущен.
message_danger5=Комфилатрон: О, чёрт. Я могу справиться с одной приближающейся ядерной ракетой, если вы поможете мне загрузить противоракетную систему, но вам нужно будет разобраться с остальными! Быстро! Уничтожьте шахты до запуска ракет!
message_danger5=Комфилатрон: О, чёрт. У нас есть зенитный ракетный комплекс, но боеприпасы только для первого использования! По крайней мере, это может выиграть нам время. Вам нужно бороться с угрозой! Быстро! Уничтожьте шахты перед запуском ракет!
message_rampup50=Комфилатрон: Кусаки начинают приспосабливаться к нашему присутствию, становясь сильнее с каждой секундой ...
message_overstay=Комфилатрон: Нам потребовалось так много времени, чтобы покинуть эту планету, наши будущие направления немного эволюционировали...
message_overstay=Комфилатрон: Нам потребовалось так много времени, чтобы покинуть эту планету, наши будущие направления немного эволюционировали...
message_jump180=Комфилатрон: Поезд полностью заряжен! Обратный отсчёт запущен. 180 секунд до прыжка!
message_jump60=Комфилатрон: Почти готово! Хватайте всё, что можете, мы отбываем через 60 секунд!
message_jump30=Комфилатрон: Вам лучше поторопиться! Осталось 30 секунд!!
@ -19,7 +19,7 @@ message_jump10=Комфилатрон: Прыжок через __1__ секун
message_jump=Комфилатрон: Ууиии! Прыжок во времени! Номер __1__.
message_poison_defense=Комфилатрон: Запуск ядовитой защиты. Давайте убьём всех!
message_nuke=Предупреждение: Запущена ядерная ракета.
message_nuke_intercepted=Ваш ракетный щит успешно перехватил одну из приближающихся ядерных боеголовок.
message_nuke_intercepted=Ваш противоракетный щит успешно перехватил приближающиеся ядерные боеголовки.
message_accident=Комфилатрон: Оффлайн игрок попал в аварию, и его труп упал на землю возле локомотива.
message_silo=Ядерный бункер разрушен. Вам удалось добыть __1__ атомных бомб. Комфилатрон изъял их для вашей же безопасности.
message_game_won_restart=Комфилатрон: Подождите, ЧТО? Похоже, мы не починили поезд как следует, и он телепортировал нас назад во времени ... вздох ... так что давайте сделаем это ещё раз, теперь как следует.
@ -44,6 +44,7 @@ message_comfylatron_desync=Комфилатрон: Попался! За рабо
message_quest_research=Комфилатрон: О, МОЙ БОГ! Ваше исследование идет так медленно! Вот, я внёс некоторые коррективы в наши лаборатории, принесите мне немного!
message_poison_mastery_unlock=Комфилатрон: Помер от штуки, называемой ядом? Почему ты не можешь быть таким, как я, невосприимчивым к этому? Давай! Начнём исследование ядов!
spidertron_not_allowed=Паукотрон можно использовать только на финальной карте!
message_giftmas_spawned=Free Gifts appeared from thin air at [gps=__1__,__2__,__3__]! Looks like we were behaving nicely this year.
difficulty1=Подходит для одиночной игры. Намного меньше загрязнения, кусаки меньше атакуют, обновления дешевле и т.д.
difficulty2=Это может выбрать небольшая группа друзей. Меньше загрязнения, меньше нападений кусак, но не совсем тривиально.
difficulty3=Легко. Меньше загрязнения, а значит, меньше атак, меньше трат монет. Лучше всего выбирать, если мало людей.\nЕсли вы играете в одиночной игре, щёлкните кнопку «Рыба» -> хронопоезд, чтобы включить больше сложностей.
@ -93,6 +94,7 @@ map_5_1=Лабиринт живой изгороди
map_6_1=Речные земли
map_7_1=Рыбный рынок
map_8_1=Метановые болота
map_9_1=Фабрика
ore_richness_very_rich=Очень богатые
ore_richness_rich=Богатые
ore_richness_normal=Обычный
@ -180,6 +182,12 @@ upgrade_nuclear_artillery_ammo_tooltip=Одна ядерная боеголов
upgrade_poison_mastery=Сильные яды
upgrade_poison_mastery_message=Комфилатрон: Теперь наши яды сильнее, а вы, глупые люди, научились пользоваться противогазами.
upgrade_poison_mastery_tooltip=+25% эффективности ядовитых капсул. Игроки получают меньше урона от яда.
upgrade_giftmas=благословение Деда Мороза
upgrade_giftmas_message=Комфилатрон: Я украсила поезд зимними украшениями, чтобы соблазнить подарками!
upgrade_giftmas_tooltip=Добавляет сезонное украшение поезда, один подарок на карту на уровне может появляться случайным образом снаружи.
upgrade_radar=РАДАР станция
upgrade_radar_message=Комфилатрон: Я поставил на поезд несколько антенн. Замечательное зрелище!
upgrade_radar_tooltip=Обеспечивает полное радиолокационное покрытие поезда. Карта снаружи открывается при создании.
token_biters=Жетон исследования убийства кусак
token_biters_add=+ __1__ жетонов исследования убийства кусачей
token_ammo=Жетон исследования боеприпасов
@ -201,6 +209,8 @@ gui_3=Заряжен в:
gui_3_1=Лучший вариант:
gui_3_2=Ядерные ракеты запущены в:
gui_3_3=Прыжок в:
gui_3_4=РАЗОГРЕВ. Изучите [technology=logistic-science-pack], чтобы запустить таймер.
gui_3_5=Начальный таймер до прыжка будет 15 минут.
gui_4=Местная эволюция:
gui_world_button=Информация о месте
gui_upgrades_button=Улучшения

View File

@ -9,6 +9,17 @@ local random = math.random
local floor = math.floor
local normal_area = {left_top = {-480, -480}, right_bottom = {480, 480}}
local normal_sector = { --clockwise from left top, sudoku sizes, no center
[1] = {left_top = {-480, -480}, right_bottom = {-160, -160}},
[2] = {left_top = {-160, -480}, right_bottom = {160, -160}},
[3] = {left_top = {160, -480}, right_bottom = {480, -160}},
[4] = {left_top = {160, -160}, right_bottom = {480, 160}},
[5] = {left_top = {160, 160}, right_bottom = {480, 480}},
[6] = {left_top = {-160, 160}, right_bottom = {160, 480}},
[7] = {left_top = {-480, 160}, right_bottom = {-160, 480}},
[8] = {left_top = {-480, -160}, right_bottom = {-160, 160}}
}
local central_sector = {left_top = {-160, -160}, right_bottom = {160, 160}}
local fish_area = {left_top = {-1100, -400}, right_bottom = {1100, 400}}
-----------commands-----------
@ -93,7 +104,7 @@ end
------------------------misc functions----------------------
local function generate_side_attack_target(surface, position)
local function search_area_for_targets(surface, area)
local targets = {
'character',
'pumpjack',
@ -109,9 +120,26 @@ local function generate_side_attack_target(surface, position)
'centrifuge',
'burner-inserter'
}
local entities = surface.find_entities_filtered {name = targets}
return surface.find_entities_filtered {name = targets, area = area}
end
local function generate_side_attack_target(surface, position, area)
local areas = {
[1] = {left_top = {position.x - 40, position.y - 40}, right_bottom = {position.x + 40, position.y + 40}},
[2] = area,
[3] = central_sector
}
local tries = 1
local entities
::retry::
entities = search_area_for_targets(surface, areas[tries]) or {}
if #entities < 1 then
return false
tries = tries + 1
if tries > #areas then
return false
else
goto retry
end
end
entities = Rand.shuffle(entities)
entities = Rand.shuffle_distance(entities, position)
@ -136,7 +164,7 @@ end
local function get_random_close_spawner(surface)
local objective = Chrono_table.get_table()
local area = normal_area
local area = normal_sector[random(1, 8)]
if objective.world.id == 7 then
area = fish_area
end
@ -151,7 +179,7 @@ local function get_random_close_spawner(surface)
for index, _ in pairs(spawners) do
weights[#weights + 1] = 1 + floor((#spawners - index) / 2)
end
return Rand.raffle(spawners, weights)
return Rand.raffle(spawners, weights), area
end
local function is_biter_inactive(biter)
@ -198,12 +226,13 @@ local function select_units_around_spawner(spawner, size)
if not biters[1] then
return nil
end
local max_size = Balance.max_new_attack_group_size(difficulty) * size
local valid_biters = {}
local unit_count = 0
for _, biter in pairs(biters) do
if unit_count >= floor(Balance.max_new_attack_group_size(difficulty) * size) then
if unit_count >= floor(max_size) then
break
end
if biter.force.name == 'enemy' and bitertable.active_biters[biter.unit_number] == nil then
@ -215,7 +244,7 @@ local function select_units_around_spawner(spawner, size)
--Manual spawning of additional units
local size_of_biter_raffle = #bitertable.biter_raffle
if size_of_biter_raffle > 0 then
for _ = 1, floor(Balance.max_new_attack_group_size(difficulty) * size - unit_count), 1 do
for _ = 1, floor(max_size - unit_count), 1 do
local biter_name = bitertable.biter_raffle[random(1, size_of_biter_raffle)]
local position = spawner.surface.find_non_colliding_position(biter_name, spawner.position, 50, 2)
if not position then
@ -292,7 +321,7 @@ local function create_attack_group(surface, size)
if get_active_biter_count() > 512 * Difficulty.get().difficulty_vote_value then
return nil
end
local spawner = get_random_close_spawner(surface)
local spawner, area = get_random_close_spawner(surface)
if not spawner then
return nil
end
@ -306,7 +335,7 @@ local function create_attack_group(surface, size)
unit_group.add_member(unit)
end
bitertable.unit_groups[unit_group.group_number] = unit_group
return unit_group
return unit_group, area
end
--------------------------command functions-------------------------------
@ -441,9 +470,9 @@ end
function Public.perform_rogue_attack()
local objective = Chrono_table.get_table()
local surface = game.surfaces[objective.active_surface_index]
local group = create_attack_group(surface, 0.15)
local group, area = create_attack_group(surface, 0.15)
if not group or not group.valid then return end
local target = generate_side_attack_target(surface, group.position)
local target = generate_side_attack_target(surface, group.position, area)
if not target or not target.valid then return end
attack_check(group, target, false)
--if _DEBUG then game.print(game.tick ..": sending rogue attack") end
@ -452,7 +481,7 @@ end
function Public.perform_main_attack()
local objective = Chrono_table.get_table()
local surface = game.surfaces[objective.active_surface_index]
local group = create_attack_group(surface, 1)
local group = (create_attack_group(surface, 1))
local target = generate_main_attack_target()
if not group or not group.valid or not target or not target.valid then
return
@ -485,6 +514,9 @@ function Public.Tick_actions(tick)
if objective.passivetimer < 60 then
return
end
if objective.world.id == 2 and objective.world.variant.id == 2 then
return --nuke map, has no biters
end
local tick_minute_functions = {
[100] = destroy_inactive_biters,
[200] = prepare_biters, -- setup for main_attack

View File

@ -4,6 +4,7 @@ local Score = require 'comfy_panel.score'
local Difficulty = require 'modules.difficulty_vote'
local Upgrades = require 'maps.chronosphere.upgrade_list'
local List = require 'maps.chronosphere.production_list'
local Rand = require 'maps.chronosphere.random'
local Public = {}
local Server = require 'utils.server'
@ -62,7 +63,7 @@ function Public.restart_settings()
local bitertable = Chrono_table.get_biter_table()
local production = Chrono_table.get_production_table()
Difficulty.reset_difficulty_poll()
Difficulty.set_poll_closing_timeout(game.tick + 35 * 60 * 60)
Difficulty.set_poll_closing_timeout(game.tick + 120 * 60 * 60)
objective.max_health = Balance.Chronotrain_max_HP
objective.health = Balance.Chronotrain_max_HP
objective.poisontimeout = 0
@ -74,6 +75,7 @@ function Public.restart_settings()
objective.overstaycount = 0
objective.jump_countdown_start_time = -1
objective.mainscore = 0
objective.warmup = true
bitertable.active_biters = {}
bitertable.unit_groups = {}
bitertable.biter_raffle = {}
@ -93,10 +95,14 @@ function Public.restart_settings()
objective.accumulators = {}
objective.comfychests = {}
objective.comfychests2 = {}
objective.comfychest_invs = {}
objective.comfychest_invs2 = {}
objective.locomotive_cargo = {}
objective.laser_battery = {}
objective.last_artillery_event = 0
objective.poison_mastery_unlocked = 0
objective.giftmas_lamps = {}
objective.giftmas_delivered = 0
for token, _ in pairs(objective.research_tokens) do
objective.research_tokens[token] = 0
end
@ -245,6 +251,7 @@ function Public.process_jump()
bitertable.biter_raffle = {}
bitertable.free_biters = 0
objective.chronocharges = 0
objective.giftmas_delivered = 0
objective.jump_countdown_start_time = -1
objective.dangertimer = 1200
game.print({'chronosphere.message_jump', objective.chronojumps}, {r = 0.98, g = 0.66, b = 0.22})
@ -343,6 +350,10 @@ function Public.post_jump()
elseif objective.world.id == 2 and objective.world.variant.id == 2 then
objective.chronocharges = objective.chronochargesneeded - 1500
objective.passive_chronocharge_rate = 1
if objective.chronojumps == 19 then
--first encounter gives one free rocket defense
objective.upgrades[17] = 1
end
end
for _, player in pairs(game.connected_players) do
playertable.flame_boots[player.index] = {fuel = 1, steps = {}}
@ -363,6 +374,8 @@ function Public.post_jump()
game.forces.player.technologies['power-armor-mk2'].enabled = true
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
script.raise_event(objective.events['update_world_gui'], {})
end
function Public.message_on_arrival()
@ -380,6 +393,22 @@ function Public.message_on_arrival()
end
end
local function create_chunk_list(surface)
local schedule = Chrono_table.get_schedule_table()
schedule.chunks_to_generate = {}
local chunks = {}
for x = -464, 464, 32 do
for y = -464, 464, 32 do
chunks[#chunks + 1] = {pos = {x, y}, generated = surface.is_chunk_generated({x, y}), distance = math.sqrt(x * x + y * y)}
end
end
for k, v in Rand.spairs(chunks, function(t, a, b) return t[b].distance > t[a].distance end) do
if v.generated == false then
schedule.chunks_to_generate[#schedule.chunks_to_generate + 1] = v
end
end
end
function Public.setup_world(surface)
local objective = Chrono_table.get_table()
local world = objective.world
@ -422,6 +451,8 @@ function Public.setup_world(surface)
surface.map_gen_settings = mgs
surface.request_to_generate_chunks({-960, -64}, 0.5)
surface.force_generate_chunk_requests()
else
create_chunk_list(surface)
end
end

View File

@ -4,6 +4,7 @@ local math_random = math.random
local Rand = require 'maps.chronosphere.random'
local Balance = require 'maps.chronosphere.balance'
local Difficulty = require 'modules.difficulty_vote'
local Public = {}
local texts = {
['approach_player'] = {
@ -754,7 +755,7 @@ local function heartbeat()
end
end
local function on_entity_damaged(event)
function Public.comfylatron_damaged(event)
local objective = Chrono_table.get_table()
if not objective.comfylatron then
return
@ -774,5 +775,6 @@ local function on_tick()
end
end
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
Event.add(defines.events.on_tick, on_tick)
Event.on_nth_tick(100, on_tick)
return Public

View File

@ -71,9 +71,6 @@ local function flying_text(surface, position, text, color)
end
function Public.biters_chew_rocks_faster(event)
if event.entity.force.index ~= 3 then
return
end --Neutral Force
if not event.cause then
return
end
@ -87,19 +84,21 @@ function Public.biters_chew_rocks_faster(event)
end
function Public.isprotected(entity)
local objective = Chrono_table.get_table()
if entity.surface.name == 'cargo_wagon' then
return true
end
local objective = Chrono_table.get_table()
local protected = {objective.locomotive, objective.locomotive_cargo[1], objective.locomotive_cargo[2], objective.locomotive_cargo[3]}
for i = 1, #objective.comfychests, 1 do
table.insert(protected, objective.comfychests[i])
end
for i = 1, #protected do
if protected[i] == entity then
return true
end
end
for _, chest in pairs(objective.comfychests) do
if chest == entity then
return true
end
end
return false
end
@ -123,18 +122,19 @@ end
function Public.lava_planet(event)
local playertable = Chrono_table.get_player_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not player.character then
return
end
if player.character.driving then
return
end
if player.surface.name == 'cargo_wagon' then
local surface = player.surface
if surface.name == 'cargo_wagon' then
return
end
local safe = {'stone-path', 'concrete', 'hazard-concrete-left', 'hazard-concrete-right', 'refined-concrete', 'refined-hazard-concrete-left', 'refined-hazard-concrete-right'}
local pavement = player.surface.get_tile(player.position.x, player.position.y)
local pavement = surface.get_tile(player.position.x, player.position.y)
for i = 1, 7, 1 do
if pavement.name == safe[i] then
return
@ -150,7 +150,7 @@ function Public.lava_planet(event)
steps[elements + 1] = {x = player.position.x, y = player.position.y}
if elements > 10 then
player.surface.create_entity({name = 'fire-flame', position = steps[elements - 1]})
surface.create_entity({name = 'fire-flame', position = steps[elements - 1]})
for i = 1, elements, 1 do
steps[i] = steps[i + 1]
end
@ -159,32 +159,27 @@ function Public.lava_planet(event)
end
function Public.shred_simple_entities(entity)
if game.forces['enemy'].evolution_factor < 0.25 then
if game.forces.enemy.evolution_factor < 0.25 then
return
end
local simple_entities =
entity.surface.find_entities_filtered(
{type = {'simple-entity', 'tree'}, area = {{entity.position.x - 3, entity.position.y - 3}, {entity.position.x + 3, entity.position.y + 3}}}
)
if #simple_entities == 0 then
return
end
for i = 1, #simple_entities, 1 do
if not simple_entities[i] then
break
end
if simple_entities[i].valid then
simple_entities[i].die('enemy', simple_entities[i])
for _, simple_entity in pairs(simple_entities) do
if simple_entity.valid then
simple_entity.destroy()
end
end
end
function Public.spawner_loot(surface, position)
local objective = Chrono_table.get_table()
if math_random(1, 18) == 1 then
local objective = Chrono_table.get_table()
local count = math_random(1, 1 + objective.chronojumps)
objective.research_tokens.weapons = objective.research_tokens.weapons + count
flying_text(surface, position, {'chronosphere.token_weapons_add', count}, {r = 0.8, g = 0.8, b = 0.8})
script.raise_event(objective.events['update_upgrades_gui'], {})
end
end
@ -195,11 +190,13 @@ function Public.research_loot(event)
bonus = 2
end
objective.research_tokens.tech = objective.research_tokens.tech + 5 * #event.research.research_unit_ingredients * bonus
script.raise_event(objective.events['update_upgrades_gui'], {})
end
function Public.tree_loot()
local objective = Chrono_table.get_table()
objective.research_tokens.ecology = objective.research_tokens.ecology + 1
script.raise_event(objective.events['update_upgrades_gui'], {})
end
function Public.choppy_loot(event)
@ -222,7 +219,7 @@ function Public.choppy_loot(event)
local second_item = 'wood'
local main_item = choppy_entity_yield[entity.name][math_random(1, #choppy_entity_yield[entity.name])]
local text = '+' .. amount .. ' [item=' .. main_item .. '] +' .. second_item_amount .. ' [item=' .. second_item .. ']'
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
flying_text(entity.surface, entity.position, text, {r = 0.8, g = 0.8, b = 0.8})
reward_ores(amount, main_item, entity.surface, player, player)
reward_ores(second_item_amount, second_item, entity.surface, player, player)
@ -230,7 +227,7 @@ function Public.choppy_loot(event)
end
function Public.rocky_loot(event)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local amount = math_ceil(get_ore_amount(false))
local rock_mining = {'iron-ore', 'iron-ore', 'iron-ore', 'iron-ore', 'copper-ore', 'copper-ore', 'copper-ore', 'stone', 'stone', 'coal', 'coal'}
local mined_loot = rock_mining[math_random(1, #rock_mining)]
@ -247,7 +244,7 @@ function Public.scrap_loot(event)
local scrap2 = scrap_table.second[math_random(1, #scrap_table.second)]
local amount = math_ceil(get_ore_amount(true) * scrap.amount)
local amount2 = math_ceil(get_ore_amount(true) * scrap2.amount)
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local text = '+' .. amount .. ' [item=' .. scrap.name .. '] + ' .. amount2 .. ' [item=' .. scrap2.name .. ']'
flying_text(player.surface, player.position, text, {r = 0.98, g = 0.66, b = 0.22})
reward_ores(amount, scrap.name, player.surface, player, player)
@ -388,10 +385,11 @@ local mining_researches = {
}
function Public.mining_buffs(event)
local force = game.forces.player
if event == nil then
-- initialization/reset call
game.forces.player.mining_drill_productivity_bonus = game.forces.player.mining_drill_productivity_bonus + 1
game.forces.player.manual_mining_speed_modifier = game.forces.player.manual_mining_speed_modifier + 1
force.mining_drill_productivity_bonus = force.mining_drill_productivity_bonus + 1
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + 1
return
end
@ -402,28 +400,37 @@ function Public.mining_buffs(event)
local tech = mining_researches[event.research.name]
if tech.bonus_productivity then
game.forces.player.mining_drill_productivity_bonus = game.forces.player.mining_drill_productivity_bonus + tech.bonus_productivity
force.mining_drill_productivity_bonus = force.mining_drill_productivity_bonus + tech.bonus_productivity
end
if tech.bonus_mining_speed then
game.forces.player.manual_mining_speed_modifier = game.forces.player.manual_mining_speed_modifier + tech.bonus_mining_speed
force.manual_mining_speed_modifier = force.manual_mining_speed_modifier + tech.bonus_mining_speed
end
if tech.bonus_inventory then
game.forces.player.character_inventory_slots_bonus = game.forces.player.character_inventory_slots_bonus + tech.bonus_inventory
force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + tech.bonus_inventory
end
end
function Public.jump_timers(event)
local objective = Chrono_table.get_table()
if event.research and event.research.name == 'logistic-science-pack' then
objective.warmup = false
objective.chronocharges = objective.chronochargesneeded / 2
end
end
function Public.on_technology_effects_reset(event)
local objective = Chrono_table.get_table()
if event.force.name == 'player' then
game.forces.player.character_inventory_slots_bonus = game.forces.player.character_inventory_slots_bonus + objective.invupgradetier * 10
game.forces.player.character_loot_pickup_distance_bonus = game.forces.player.character_loot_pickup_distance_bonus + objective.pickupupgradetier
local force = game.forces.player
force.character_inventory_slots_bonus = force.character_inventory_slots_bonus + objective.upgrades[5] * 10
force.character_loot_pickup_distance_bonus = force.character_loot_pickup_distance_bonus + objective.upgrades[4]
local fake_event = {}
Public.mining_buffs(nil)
for tech, bonuses in pairs(mining_researches) do
tech = game.forces.player.technologies[tech]
tech = force.technologies[tech]
if tech.researched == true or bonuses.infinite == true then
fake_event.research = tech
if bonuses.infinite and bonuses.infinite_level and tech.level > bonuses.infinite_level then

View File

@ -18,7 +18,7 @@ local function create_gui(player)
local label
local button
label = frame.add({type = 'label', caption = ' ', name = 'label'})
label = frame.add({type = 'label', caption = {'chronosphere.gui_1'}, name = 'label'})
label.style.font_color = {r = 0.88, g = 0.88, b = 0.88}
label.style.font = 'default-bold'
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
@ -29,7 +29,7 @@ local function create_gui(player)
label.style.right_padding = 4
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
label = frame.add({type = 'label', caption = ' ', name = 'charger'})
label = frame.add({type = 'label', caption = {'chronosphere.gui_2'}, name = 'charger'})
label.style.font = 'default-bold'
label.style.left_padding = 4
label.style.font_color = {r = 255, g = 200, b = 200} --255 200 200 --150 0 255
@ -74,12 +74,12 @@ local function create_gui(player)
-- line.style.left_padding = 4
-- line.style.right_padding = 8
button = frame.add({type = 'button', caption = ' ', name = 'world_button'})
button = frame.add({type = 'button', caption = {'chronosphere.gui_world_button'}, name = 'world_button'})
button.style.font = 'default-bold'
button.style.font_color = {r = 0.99, g = 0.99, b = 0.99}
button.style.minimal_width = 75
button = frame.add({type = 'button', caption = ' ', name = 'upgrades_button'})
button = frame.add({type = 'button', caption = {'chronosphere.gui_upgrades_button'}, name = 'upgrades_button'})
button.style.font = 'default-bold'
button.style.font_color = {r = 0.99, g = 0.99, b = 0.99}
button.style.minimal_width = 75
@ -300,18 +300,14 @@ function Public_gui.update_gui(player)
local objective = Chrono_table.get_table()
local difficulty = Difficulty.get().difficulty_vote_value
update_world_gui(player)
update_upgrades_gui(player)
if not player.gui.top.chronosphere then
create_gui(player)
end
local gui = player.gui.top.chronosphere
local guimode = objective.guimode
gui.label.caption = {'chronosphere.gui_1'}
gui.jump_number.caption = objective.chronojumps
gui.charger.caption = {'chronosphere.gui_2'}
if (objective.chronochargesneeded < 100000) then
gui.charger_value.caption = string.format('%.2f', objective.chronocharges / 1000) .. ' / ' .. math_floor(objective.chronochargesneeded) / 1000 .. ' GJ'
else
@ -321,43 +317,47 @@ function Public_gui.update_gui(player)
local interval = objective.chronochargesneeded
gui.progressbar.value = 1 - (objective.chronochargesneeded - objective.chronocharges) / interval
--[[
if (objective.chronochargesneeded<1000) then
gui.charger_value.caption = objective.chronocharges .. "/" .. objective.chronochargesneeded .. " MJ"
elseif (objective.chronochargesneeded<10000) then
gui.charger_value.caption = math_floor(objective.chronocharges/10)/100 .. " / " .. math_floor(objective.chronochargesneeded/10)/100 .. " GJ"
elseif (objective.chronochargesneeded<1000000) then
gui.charger_value.caption = math_floor(objective.chronocharges/100)/10 .. " / " .. math_floor(objective.chronochargesneeded/100)/10 .. " GJ"
elseif (objective.chronochargesneeded<10000000) then
gui.charger_value.caption = math_floor(objective.chronocharges/10000)/100 .. " / " .. math_floor(objective.chronochargesneeded/10000)/100 .. " TJ"
else
gui.charger_value.caption = math_floor(objective.chronocharges/100000)/10 .. " / " .. math_floor(objective.chronochargesneeded/100000)/10 .. " TJ"
end
]]
if objective.jump_countdown_start_time == -1 then
if objective.warmup then
if guimode ~= 'warmup' then
gui.timer.caption = {'chronosphere.gui_3_4'}
gui.timer_value.caption = ''
gui.timer.tooltip = {'chronosphere.gui_3_5'}
gui.timer_value.tooltip = ''
gui.timer2.caption = ''
gui.timer_value2.caption = ''
objective.guimode = 'warmup'
end
elseif objective.jump_countdown_start_time == -1 then
local powerobserved, storedbattery = 0, 0
local seconds_ETA = ETA_seconds_until_full(powerobserved, storedbattery)
gui.timer.caption = {'chronosphere.gui_3'}
gui.timer_value.caption = math_floor(seconds_ETA / 60) .. 'm' .. seconds_ETA % 60 .. 's'
gui.timer_value.style.font_color = {r = 0, g = 0.98, b = 0}
if objective.world.id == 2 and objective.world.variant.id == 2 and objective.passivetimer > 31 then
if guimode ~= 'nuclear' then
gui.timer.caption = {'chronosphere.gui_3'}
gui.timer_value.style.font_color = {r = 0, g = 0.98, b = 0}
gui.timer2.caption = {'chronosphere.gui_3_2'}
gui.timer2.style.font_color = {r = 0.98, g = 0, b = 0}
gui.timer_value2.style.font_color = {r = 0.98, g = 0, b = 0}
objective.guimode = 'nuclear'
end
local nukecase = objective.dangertimer
gui.timer2.caption = {'chronosphere.gui_3_2'}
gui.timer_value2.caption = math_floor(nukecase / 60) .. 'm' .. nukecase % 60 .. 's'
gui.timer2.style.font_color = {r = 0.98, g = 0, b = 0}
gui.timer_value2.style.font_color = {r = 0.98, g = 0, b = 0}
else
if objective.accumulators then
if guimode ~= 'accumulators' then
gui.timer.caption = {'chronosphere.gui_3'}
gui.timer_value.style.font_color = {r = 0, g = 0.98, b = 0}
gui.timer2.caption = {'chronosphere.gui_3_1'}
gui.timer2.style.font_color = {r = 0, g = 200, b = 0}
gui.timer_value2.style.font_color = {r = 0, g = 200, b = 0}
objective.guimode = 'accumulators'
end
local bestcase = math_floor(ETA_seconds_until_full(#objective.accumulators * 300000, storedbattery))
gui.timer2.caption = {'chronosphere.gui_3_1'}
gui.timer_value2.caption = math_floor(bestcase / 60) .. 'm' .. bestcase % 60 .. 's (drawing ' .. #objective.accumulators * 0.3 .. 'MW)'
gui.timer2.style.font_color = {r = 0, g = 200, b = 0}
gui.timer_value2.style.font_color = {r = 0, g = 200, b = 0}
end
end
--end
if objective.chronojumps >= Balance.jumps_until_overstay_is_on(difficulty) then
local time_until_overstay = (objective.chronochargesneeded * 0.75 / objective.passive_chronocharge_rate - objective.passivetimer)
local time_until_evo = (objective.chronochargesneeded * 0.5 / objective.passive_chronocharge_rate - objective.passivetimer)
@ -380,16 +380,16 @@ function Public_gui.update_gui(player)
gui.timer_value.tooltip = ''
end
else
gui.timer.caption = {'chronosphere.gui_3_3'}
gui.timer_value.caption = 180 - (objective.passivetimer - objective.jump_countdown_start_time) .. 's'
gui.timer.tooltip = ''
gui.timer_value.tooltip = ''
gui.timer2.caption = ''
gui.timer_value2.caption = ''
if guimode ~= 'countdown' then
gui.timer.caption = {'chronosphere.gui_3_3'}
gui.timer.tooltip = ''
gui.timer_value.tooltip = ''
gui.timer2.caption = ''
gui.timer_value2.caption = ''
objective.guimode = 'countdown'
end
end
gui.world_button.caption = {'chronosphere.gui_world_button'}
gui.upgrades_button.caption = {'chronosphere.gui_upgrades_button'}
end
local function upgrades_gui(player)
@ -578,4 +578,22 @@ function Public_gui.on_gui_click(event)
end
end
function Public_gui.update_all_player_gui()
for _, player in pairs(game.connected_players) do
Public_gui.update_gui(player)
end
end
function Public_gui.update_all_player_world_gui()
for _, player in pairs(game.connected_players) do
update_world_gui(player)
end
end
function Public_gui.update_all_player_upgrades_gui()
for _, player in pairs(game.connected_players) do
update_upgrades_gui(player)
end
end
return Public_gui

View File

@ -86,8 +86,10 @@ function Public.locomotive_spawn(surface, position, wagons)
comfychest.minable = false
if not objective.comfychests[i] then
table.insert(objective.comfychests, comfychest)
table.insert(objective.comfychest_invs, comfychest.get_inventory(defines.inventory.chest))
else
objective.comfychests[i] = comfychest
objective.comfychest_invs[i] = comfychest.get_inventory(defines.inventory.chest)
end
end
draw_light(objective.locomotive)

View File

@ -3,10 +3,11 @@
require 'modules.biter_noms_you'
require 'modules.biters_yield_coins'
require 'modules.no_deconstruction_of_neutral_entities'
require 'maps.chronosphere.comfylatron'
local Comfylatron = require 'maps.chronosphere.comfylatron'
local Ai = require 'maps.chronosphere.ai'
local Balance = require 'maps.chronosphere.balance'
local Difficulty = require 'modules.difficulty_vote'
local Event = require 'utils.event'
local Event_functions = require 'maps.chronosphere.event_functions'
local Factories = require 'maps.chronosphere.production'
local Gui = require 'maps.chronosphere.gui'
@ -125,6 +126,9 @@ local function drain_accumulators()
if objective.passivetimer < 10 then
return
end
if objective.warmup then
return
end
if not objective.chronocharges then
return
end
@ -165,7 +169,7 @@ local function do_tick()
local objective = Chrono_table.get_table()
local tick = game.tick
Ai.Tick_actions(tick)
if tick % 60 == 30 and objective.passivetimer < 64 then
if objective.passivetimer < 80 then
Tick_functions.request_chunks()
end
if tick % 30 == 20 then
@ -176,6 +180,9 @@ local function do_tick()
end
if tick % 60 == 0 then
objective.passivetimer = objective.passivetimer + 1
if objective.giftmas_enabled then
Tick_functions.giftmas_lights()
end
if objective.world.id ~= 7 then
Tick_functions.update_charges()
drain_accumulators()
@ -196,48 +203,59 @@ local function do_tick()
Tick_functions.train_pollution('countdown')
end
end
end
if tick % 120 == 0 then
Tick_functions.move_items()
Tick_functions.output_items()
end
if tick % 600 == 0 then
Tick_functions.ramp_evolution()
Factories.check_activity()
Upgrades.check_upgrades()
Tick_functions.transfer_pollution()
if objective.poisontimeout > 0 then
objective.poisontimeout = objective.poisontimeout - 1
end
if tick % 1800 == 0 then
Locomotive.set_player_spawn_and_refill_fish()
Event_functions.set_objective_health(Tick_functions.repair_train())
if objective.config.offline_loot then
Tick_functions.offline_players()
script.raise_event(objective.events['update_world_gui'], {})
if tick % 120 == 0 then
Tick_functions.move_items()
Tick_functions.output_items()
if tick % 360 == 0 then
Tick_functions.chart_wagons()
end
end
if tick % 1800 == 900 and objective.jump_countdown_start_time ~= -1 then
Ai.perform_main_attack()
end
if objective.game_reset_tick then
if objective.game_reset_tick < tick then
objective.game_reset_tick = nil
if objective.game_won then
Tick_functions.message_game_won()
if tick % 600 == 0 then
Tick_functions.ramp_evolution()
Factories.check_activity()
Upgrades.check_upgrades()
Tick_functions.transfer_pollution()
if objective.poisontimeout > 0 then
objective.poisontimeout = objective.poisontimeout - 1
end
reset_map()
if tick % 1800 == 0 then
Locomotive.set_player_spawn_and_refill_fish()
Event_functions.set_objective_health(Tick_functions.repair_train())
if objective.config.offline_loot then
Tick_functions.offline_players()
end
Tick_functions.giftmas_spawn()
end
if tick % 1800 == 900 and objective.jump_countdown_start_time ~= -1 then
Ai.perform_main_attack()
end
if objective.game_reset_tick then
if objective.game_reset_tick < tick then
objective.game_reset_tick = nil
if objective.game_won then
Tick_functions.message_game_won()
end
reset_map()
end
return
end
Locomotive.fish_tag()
end
return
end
Locomotive.fish_tag()
end
for _, player in pairs(game.connected_players) do
Minimap.toggle_button(player)
Gui.update_gui(player)
end
end
local function custom_event(name)
local objective = Chrono_table.get_table()
local id = script.generate_event_name()
objective.events[name] = id
return id
end
local function on_init()
local objective = Chrono_table.get_table()
local T = Map.Pop_info()
@ -259,6 +277,10 @@ local function on_init()
mgs.height = 16
game.surfaces['nauvis'].map_gen_settings = mgs
game.surfaces['nauvis'].clear()
Event.add(custom_event('update_gui'), Gui.update_all_player_gui)
Event.add(custom_event('update_world_gui'), Gui.update_all_player_world_gui)
Event.add(custom_event('update_upgrades_gui'), Gui.update_all_player_upgrades_gui)
Event.add(custom_event('comfylatron_damaged'), Comfylatron.comfylatron_damaged)
reset_map()
end
@ -269,7 +291,6 @@ local function on_player_driving_changed_state(event)
Minimap.minimap(player, true)
end
local Event = require 'utils.event'
Event.on_init(on_init)
Event.on_nth_tick(10, do_tick)
Event.add(defines.events.on_entity_damaged, On_Event.on_entity_damaged)
@ -286,6 +307,7 @@ Event.add(defines.events.on_technology_effects_reset, Event_functions.on_technol
Event.add(defines.events.on_gui_click, Gui.on_gui_click)
Event.add(defines.events.on_pre_player_died, On_Event.on_pre_player_died)
Event.add(defines.events.script_raised_revive, On_Event.script_raised_revive)
Event.add(defines.events.on_player_changed_surface, On_Event.on_player_changed_surface)
if _DEBUG then
local Session = require 'utils.datastore.session_data'

View File

@ -19,22 +19,22 @@ function Public.on_research_finished(event)
Event_functions.research_loot(event)
Event_functions.flamer_nerfs()
Event_functions.mining_buffs(event)
Event_functions.jump_timers(event)
end
function Public.on_player_mined_entity(event)
local objective = Chrono_table.get_table()
local entity = event.entity
if not entity.valid then
return
end
local objective = Chrono_table.get_table()
if entity.type == 'tree' then
Event_functions.tree_loot()
if objective.world.id == 4 then --choppy planet
Event_functions.trap(entity, false)
Event_functions.choppy_loot(event)
end
end
if entity.name == 'rock-huge' or entity.name == 'rock-big' or entity.name == 'sand-rock-big' then
elseif entity.name == 'rock-huge' or entity.name == 'rock-big' or entity.name == 'sand-rock-big' then
if objective.world.id == 3 then --rocky worlds
event.buffer.clear()
-- elseif objective.world.id == 5 then --maze worlds
@ -61,7 +61,7 @@ end
function Public.on_pre_player_left_game(event)
local playertable = Chrono_table.get_player_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if player.controller_type == defines.controllers.editor then
player.toggle_map_editor()
end
@ -73,7 +73,7 @@ end
function Public.on_player_joined_game(event)
local objective = Chrono_table.get_table()
local playertable = Chrono_table.get_player_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
if not playertable.flame_boots[event.player_index] then
playertable.flame_boots[event.player_index] = {}
end
@ -108,40 +108,55 @@ function Public.on_player_joined_game(event)
end
end
Minimap.update_surface(player)
Minimap.toggle_button(player)
end
function Public.on_player_changed_surface(event)
local player = game.get_player(event.player_index)
Minimap.toggle_button(player)
if not player.is_cursor_empty() then
if player.cursor_stack and player.cursor_stack.valid_for_read then
local blacklisted = {
['small-electric-pole'] = true,
['medium-electric-pole'] = true,
['big-electric-pole'] = true,
['substation'] = true
}
if blacklisted[player.cursor_stack.name] then
player.get_main_inventory().insert(player.cursor_stack)
player.cursor_stack.clear()
end
end
if player.cursor_ghost then
player.cursor_ghost = nil
end
end
end
function Public.on_entity_died(event)
local objective = Chrono_table.get_table()
if event.entity.type == 'tree' and objective.world.id == 4 then --choppy planet
local entity = event.entity
if entity.type == 'tree' and objective.world.id == 4 then --choppy planet
if event.cause then
if event.cause.valid then
if event.cause.force.name ~= 'enemy' then
Event_functions.trap(event.entity, false)
end
end
elseif event.damage_type == 'poison' then
Event_functions.trap(event.entity, false)
end
-- if not event.entity.valid then return end
-- for _, entity in pairs (event.entity.surface.find_entities_filtered({area = {{event.entity.position.x - 4, event.entity.position.y - 4},{event.entity.position.x + 4, event.entity.position.y + 4}}, name = "fire-flame-on-tree"})) do
-- if entity.valid then entity.destroy() end
-- end
--return
end
local entity = event.entity
if not entity.valid then
return
end
if entity.type == 'unit' and entity.force == 'enemy' then
objective.active_biters[entity.unit_number] = nil
end
if entity.type == 'rocket-silo' and entity.force.name == 'enemy' then
Event_functions.danger_silo(entity)
end
if entity.force.name == 'scrapyard' and entity.name == 'gun-turret' then
local fname = entity.force.name
if fname == 'scrapyard' and entity.name == 'gun-turret' then
if (objective.world.id == 2 and objective.world.variant.id == 2) or objective.world.id == 5 then --danger + hedge maze
Event_functions.trap(entity, true)
end
end
if entity.force.name == 'enemy' then
elseif fname == 'enemy' then
if entity.type == 'unit-spawner' then
Event_functions.spawner_loot(entity.surface, entity.position)
if objective.world.id == 8 then
@ -150,14 +165,22 @@ function Public.on_entity_died(event)
if event.cause and (event.cause.name == 'artillery-turret' or event.cause.name == 'artillery-wagon') then
Event_functions.nuclear_artillery(entity, event.cause)
end
else
elseif entity.type == 'unit' then
Event_functions.biter_loot(event)
local bitertable = Chrono_table.get_biter_table()
bitertable.active_biters[entity.unit_number] = nil
if objective.world.id == 8 then
Event_functions.swamp_loot(event)
end
elseif entity.type == 'rocket-silo' then
Event_functions.danger_silo(entity)
elseif entity.type == 'turret' then
Event_functions.biter_loot(event)
if objective.world.id == 8 then
Event_functions.swamp_loot(event)
end
end
end
if entity.force.index == 3 then
elseif fname == 'neutral' then
event.loot.clear()
if objective.world.id == 2 and objective.world.variant.id == 3 and entity.type == 'container' then --RUR robot spawns
Event_functions.trap(entity, true)
@ -174,9 +197,6 @@ end
local function protect_entity(event)
local objective = Chrono_table.get_table()
if event.entity.force.index ~= 1 then
return
end --Player Force
if Event_functions.isprotected(event.entity) then
if event.cause then
if event.cause == objective.comfylatron or event.entity == objective.comfylatron then
@ -192,6 +212,7 @@ local function protect_entity(event)
return
end
event.entity.health = event.entity.health + event.final_damage_amount
return
end
if event.entity.name == 'character' then
if objective.upgrades[25] > 0 and event.damage_type.name == 'poison' then
@ -201,19 +222,24 @@ local function protect_entity(event)
end
function Public.on_entity_damaged(event)
if not event.entity.valid then
return
end
protect_entity(event)
if not event.entity.valid then
return
end
if not event.entity.health then
return
end
Event_functions.biters_chew_rocks_faster(event)
if event.entity.force.name == 'enemy' then
local force = event.entity.force.name
if force == 'neutral' then
Event_functions.biters_chew_rocks_faster(event)
elseif force == 'enemy' then
Event_functions.biter_immunities(event)
elseif force == 'player' then
if event.entity.name == 'compilatron' then
local objective = Chrono_table.get_table()
script.raise_event(objective.events['comfylatron_damaged'], event)
return
end
protect_entity(event)
end
end
@ -237,11 +263,11 @@ function Public.on_built_entity(event)
end
function Public.on_pre_player_died(event)
local objective = Chrono_table.get_table()
local player = game.players[event.player_index]
local player = game.get_player(event.player_index)
local surface = player.surface
local poisons = surface.count_entities_filtered {position = player.position, radius = 10, name = 'poison-cloud'}
if poisons > 0 then
local objective = Chrono_table.get_table()
objective.poison_mastery_unlocked = objective.poison_mastery_unlocked + 1
if objective.poison_mastery_unlocked == 10 then
game.print({'chronosphere.message_poison_mastery_unlock'}, {r = 0.98, g = 0.66, b = 0.22})
@ -255,7 +281,12 @@ function Public.script_raised_revive(event)
if entity.force.name == "player" then return end
if entity.force.name == "scrapyard" then
if entity.name == "gun-turret" then
entity.insert({name = "uranium-rounds-magazine", count = 128})
local objective = Chrono_table.get_table()
if objective.chronojumps > 2 then
entity.insert({name = "uranium-rounds-magazine", count = 128})
else
entity.insert({name = "firearm-magazine", count = 12})
end
elseif entity.name == "artillery-turret" then
entity.insert({name = "artillery-shell", count = 30})
elseif entity.name == "accumulator" then

View File

@ -47,4 +47,27 @@ function Public.raffle(values, weights) --arguments of the form {[a] = A, [b] =
end
end
function Public.spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
return Public

View File

@ -65,6 +65,7 @@ function Public.reset_schedule_table()
schedulesphere[k] = nil
end
schedulesphere.lab_cells = {}
schedulesphere.chunks_to_generate = {}
end
function Public.reset_biter_table()
@ -86,6 +87,7 @@ function Public.reset_table()
chronosphere.chronojumps = 0
chronosphere.game_lost = true
chronosphere.game_won = false
chronosphere.warmup = true
chronosphere.max_health = 0
chronosphere.health = 0
chronosphere.poisontimeout = 0
@ -110,6 +112,8 @@ function Public.reset_table()
chronosphere.accumulators = {}
chronosphere.comfychests = {}
chronosphere.comfychests2 = {}
chronosphere.comfychest_invs = {}
chronosphere.comfychest_invs2 = {}
chronosphere.locomotive_cargo = {}
chronosphere.world = {}
chronosphere.research_tokens = {}
@ -121,6 +125,12 @@ function Public.reset_table()
chronosphere.laser_battery = 0
chronosphere.last_artillery_event = 0
chronosphere.poison_mastery_unlocked = 0
chronosphere.gen_speed = 2
chronosphere.events = {}
chronosphere.guimode = nil
chronosphere.giftmas_enabled = true
chronosphere.giftmas_lamps = {}
chronosphere.giftmas_delivered = 0
end
function Public.get_table()

View File

@ -1,6 +1,7 @@
local Chrono_table = require 'maps.chronosphere.table'
local Balance = require 'maps.chronosphere.balance'
local Difficulty = require 'modules.difficulty_vote'
local MFunctions = require 'maps.chronosphere.world_functions'
local Server = require 'utils.server'
local Public = {}
@ -51,6 +52,9 @@ end
function Public.train_pollution(source, interior_pollution)
local objective = Chrono_table.get_table()
local difficulty = Difficulty.get().difficulty_vote_value
if not objective.locomotive.valid then
return
end
local pos = objective.locomotive.position or {x = 0, y = 0}
local pollution = 0
local stat_target = 'locomotive'
@ -108,33 +112,33 @@ end
function Public.move_items()
local objective = Chrono_table.get_table()
if not objective.comfychests then
if not objective.comfychests or not objective.comfychest_invs then
return
end
if not objective.comfychests2 then
if not objective.comfychests2 or not objective.comfychest_invs2 then
return
end
if objective.game_lost == true then
return
end
local input = objective.comfychests
local output = objective.comfychests2
local input, input_inventory = objective.comfychests, objective.comfychest_invs
local output, output_inventory = objective.comfychests2, objective.comfychest_invs2
for i = 1, 24, 1 do
if not input[i].valid then
if not input[i].valid or not input_inventory[i].valid then
return
end
if not output[i].valid then
if not output[i].valid or not output_inventory[i].valid then
return
end
local input_inventory = input[i].get_inventory(defines.inventory.chest)
local output_inventory = output[i].get_inventory(defines.inventory.chest)
input_inventory.sort_and_merge()
output_inventory.sort_and_merge()
for ii = 1, #input_inventory, 1 do
if input_inventory[ii].valid_for_read then
local count = output_inventory.insert(input_inventory[ii])
input_inventory[ii].count = input_inventory[ii].count - count
input_inventory[i].sort_and_merge()
output_inventory[i].sort_and_merge()
for ii = 1, #input_inventory[i], 1 do
if input_inventory[i][ii].valid_for_read then
local count = output_inventory[i].insert(input_inventory[i][ii])
input_inventory[i][ii].count = input_inventory[i][ii].count - count
else
break
end
end
end
@ -142,10 +146,10 @@ end
local function transfer_signals(index, inventory)
local objective = Chrono_table.get_table()
local counts = inventory.get_contents()
if not objective.outcombinators then
return
end
local counts = inventory.get_contents()
local combi = objective.outcombinators[index].get_or_create_control_behavior()
local i = 1
for name, count in pairs(counts) do
@ -193,6 +197,8 @@ function Public.output_items()
if inv[ii].valid_for_read then
local count = wagon[math_ceil(i / 2)].insert(inv[ii])
inv[ii].count = inv[ii].count - count
else
break
end
end
if objective.upgrades[8] == 2 then
@ -261,28 +267,31 @@ local function launch_nukes()
local objective = Chrono_table.get_table()
local surface = game.surfaces[objective.active_surface_index]
if objective.dangers and #objective.dangers > 1 then
local max_range = 800
if objective.upgrades[17] == 1 then
objective.upgrades[17] = 0
max_range = 100
end
for i = 1, #objective.dangers, 1 do
if objective.dangers[i].destroyed == false then
if objective.upgrades[17] == 1 then
game.print({'chronosphere.message_nuke_intercepted'}, {r = 0, g = 0.98, b = 0})
objective.upgrades[17] = 0
else
local fake_shooter = surface.create_entity({name = 'character', position = objective.dangers[i].silo.position, force = 'enemy'})
surface.create_entity(
{
name = 'atomic-rocket',
position = objective.dangers[i].silo.position,
force = 'enemy',
speed = 1,
max_range = 800,
target = objective.locomotive,
source = fake_shooter
}
)
game.print({'chronosphere.message_nuke'}, {r = 0.98, g = 0, b = 0})
end
local fake_shooter = surface.create_entity({name = 'character', position = objective.dangers[i].silo.position, force = 'enemy'})
surface.create_entity(
{
name = 'atomic-rocket',
position = objective.dangers[i].silo.position,
force = 'enemy',
speed = 1,
max_range = max_range,
target = objective.locomotive,
source = fake_shooter
}
)
game.print({'chronosphere.message_nuke'}, {r = 0.98, g = 0, b = 0})
end
end
if max_range == 100 then
game.print({'chronosphere.message_nuke_intercepted'}, {r = 0, g = 0.98, b = 0})
end
end
end
@ -391,17 +400,29 @@ end
function Public.request_chunks()
local objective = Chrono_table.get_table()
local schedule = Chrono_table.get_schedule_table()
local surface = game.surfaces[objective.active_surface_index]
if objective.world.id == 7 then
surface.request_to_generate_chunks({-800, 0}, 1 + math_floor(objective.passivetimer / 5))
else
surface.request_to_generate_chunks({0, 0}, 1 + math_floor(objective.passivetimer / 5))
if table_size(schedule.chunks_to_generate) > 0 then
local amount = 0
for index, chunk in pairs(schedule.chunks_to_generate) do
surface.request_to_generate_chunks(chunk.pos, 0)
schedule.chunks_to_generate[index] = nil
amount = amount + 1
if amount >= objective.gen_speed then
break
end
end
end
end
--surface.force_generate_chunk_requests()
end
function Public.update_charges()
local objective = Chrono_table.get_table()
if objective.warmup then return end
if objective.chronocharges < objective.chronochargesneeded and objective.world.id ~= 7 then -- < 2000
objective.chronocharges = objective.chronocharges + objective.passive_chronocharge_rate
-- local chronotimer_ticks_between_increase = math_floor(objective.passive_chronocharge_rate / 10) * 10 --- 60 / (1800 / 2000)
@ -439,7 +460,7 @@ function Public.laser_defense()
{
name = 'flying-text',
position = objective.locomotive.position,
text = 'Low Power',
text = 'Laser: Low Power',
color = {r = 0.98, g = 0, b = 0}
}
)
@ -461,6 +482,58 @@ function Public.message_game_won()
Server.to_discord_embed({'chronosphere.message_game_won2', objective.mainscore}, true)
end
function Public.giftmas_lights()
local objective = Chrono_table.get_table()
local lights = objective.giftmas_lamps
local nr = #lights
if nr < 1 then return end
local colors = {
--[1] = {r = 255, g = 77, b = 55, a = 1}, --červená
[1] = {r = 255, g = 33, b = 11, a = 1}, --červená
[2] = {r = 86, g = 241, b = 59, a = 1}, --zelená
[3] = {r = 243, g = 189, b = 45, a = 1}, --žlutá
[4] = {r = 63, g = 49, b = 255, a = 1}, --modrá
}
for _ = 1, 5, 1 do
rendering.set_color(lights[math_random(1, nr)], colors[math_random(1, 4)])
end
end
function Public.giftmas_spawn()
local objective = Chrono_table.get_table()
if objective.upgrades[26] <= objective.giftmas_delivered or objective.world.id == 7 then
return
end
if objective.passivetimer + 60 * objective.upgrades[26] >= 400 * (1 + objective.giftmas_delivered) then
local random_pos = {x = math_random(-160, 160), y = math_random(-160, 160)}
local surface = game.surfaces[objective.active_surface_index]
local pos = surface.find_non_colliding_position('rocket-silo', random_pos, 64, 1)
if not pos then
return
end
local treasures = {
{pos.x, pos.y},
{pos.x - 2, pos.y - 2},
{pos.x - 2, pos.y + 2},
{pos.x + 2, pos.y - 2},
{pos.x + 2, pos.y + 2}
}
MFunctions.spawn_treasures(surface, treasures)
objective.giftmas_delivered = objective.giftmas_delivered + 1
game.print({'chronosphere.message_giftmas_spawned', pos.x, pos.y, surface.name}, {r = 0.98, g = 0.66, b = 0.22})
end
end
function Public.chart_wagons()
if not game.surfaces['cargo_wagon'] then
return
end
local objective = Chrono_table.get_table()
if objective.upgrades[27] == 1 then
game.forces.player.chart_all(game.surfaces['cargo_wagon'])
end
end
-- function Public.player_spit()
-- for _, player in pairs(game.connected_players) do
-- if not player.character or not player.character.valid then return end

File diff suppressed because it is too large Load Diff

View File

@ -240,6 +240,37 @@ local function upgrade_nuclear_artillery_add_ammo(amount)
objective.upgrades[24] = objective.upgrades[24] + amount
end
local function add_light(pos)
local light = rendering.draw_sprite{
sprite = 'tile/lab-white',
x_scale = 4,
y_scale = 4,
target = pos,
surface = game.surfaces['cargo_wagon'],
tint = {r = 86, g = 241, b = 59, a = 0.8},
render_layer = 'ground'
}
return light
end
local function upgrade_giftmas()
if not game.surfaces['cargo_wagon'] then
return
end
local objective = Chrono_table.get_table()
if objective.giftmas_enabled then
local positions = {x = {-34, 34}, y = {-190, -62, 66}}
local lamps = {}
for ii = 1, 3, 1 do
for i = 1, 30, 1 do --1 to 30 is size of wagon
lamps[#lamps + 1] = add_light({x = positions.x[1], y = positions.y[ii] + 4 * i})
lamps[#lamps + 1] = add_light({x = positions.x[2], y = positions.y[ii] + 4 * i})
end
end
objective.giftmas_lamps = lamps
end
end
local function process_upgrade(index)
local objective = Chrono_table.get_table()
if index == 1 then
@ -288,12 +319,17 @@ local function process_upgrade(index)
upgrade_nuclear_artillery_add_ammo(10)
elseif index == 24 then
upgrade_nuclear_artillery_add_ammo(9)
elseif index == 26 then
if objective.upgrades[26] == 1 then
upgrade_giftmas()
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
end
local function check_single_upgrade(index)
local function check_single_upgrade(index, coin_scaling)
local objective = Chrono_table.get_table()
local upgrades = Upgrades.upgrades()
local upgrade = Upgrades['upgrade' .. index](coin_scaling)
if objective.upgradechest[index] and objective.upgradechest[index].valid then
if index == 14 and (objective.upgrades[13] ~= 1 or objective.computermessage ~= 3) then
return
@ -303,13 +339,13 @@ local function check_single_upgrade(index)
return
end
local inv = objective.upgradechest[index].get_inventory(defines.inventory.chest)
if objective.upgrades[index] < upgrades[index].max_level and objective.chronojumps >= upgrades[index].jump_limit then
for _, item in pairs(upgrades[index].cost) do
if objective.upgrades[index] < upgrade.max_level and objective.chronojumps >= upgrade.jump_limit then
for _, item in pairs(upgrade.cost) do
if inv.get_item_count(item.name) < item.count then
return
end
end
for _, token in pairs(upgrades[index].virtual_cost) do
for _, token in pairs(upgrade.virtual_cost) do
if objective.research_tokens[token.type] < token.count then
return
end
@ -318,24 +354,25 @@ local function check_single_upgrade(index)
return
end
for _, item in pairs(upgrades[index].cost) do
for _, item in pairs(upgrade.cost) do
if item.count > 0 then
inv.remove({name = item.name, count = item.count})
end
end
for _, token in pairs(upgrades[index].virtual_cost) do
for _, token in pairs(upgrade.virtual_cost) do
objective.research_tokens[token.type] = objective.research_tokens[token.type] - token.count
end
objective.upgrades[index] = objective.upgrades[index] + 1
game.print(upgrades[index].message, {r = 0.98, g = 0.66, b = 0.22})
game.print(upgrade.message, {r = 0.98, g = 0.66, b = 0.22})
process_upgrade(index)
end
end
local function check_all_upgrades()
local upgrades = Upgrades.upgrades()
local coin_scaling = Upgrades.coin_scaling()
for i = 1, #upgrades, 1 do
check_single_upgrade(i)
check_single_upgrade(i, coin_scaling)
end
end
@ -374,6 +411,7 @@ function Public.trigger_poison()
surface.create_entity({name = 'poison-capsule', position = objective.comfychests[i].position, force = 'player', target = objective.comfychests[i], speed = 1})
end
end
script.raise_event(objective.events['update_upgrades_gui'], {})
end
return Public

View File

@ -213,8 +213,8 @@ function Public.determine_world(optional_choice)
end
table.insert(choices.weights, weight)
end
if Worlds[optional_choice] then
chosen_id = optional_choice
if Worlds[tonumber(optional_choice)] then
chosen_id = tonumber(optional_choice)
else
chosen_id = Rand.raffle(choices.types, choices.weights)
end
@ -260,6 +260,9 @@ local function process_chunk(surface, left_top)
if not surface.valid then
return
end
if objective.upgrades[27] == 1 then
game.forces.player.chart(surface, {{left_top.x + 16, left_top.y + 16}, {left_top.x + 16, left_top.y + 16}})
end
local world = objective.world
local level_depth = 960
if world.id == 7 then

View File

@ -8,7 +8,9 @@ local function process_tile(p, seed, entities)
local objective = Chrono_table.get_table()
local biters = objective.world.variant.biters
local noise1 = Functions.get_noise('forest_location', p, seed)
if noise1 > 0.095 then
local f_density = (math.min(Functions.distance(p.x, p.y) / 500, 1)) * 0.3
local handicap = math.max(0, 160 - objective.chronojumps * 20)
if noise1 > 0.095 + f_density then
if noise1 > 0.6 then
if random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-08-brown', position = p}
@ -19,13 +21,7 @@ local function process_tile(p, seed, entities)
end
end
return
else
if random(1, 152 - biters) == 1 and Functions.distance(p.x, p.y) > 200 then
entities[#entities + 1] = {name = Raffle.spawners[random(1, #Raffle.spawners)], position = p, spawn_decorations = true}
end
end
if noise1 < -0.095 then
elseif noise1 < -(0.095 + f_density) then
if noise1 < -0.6 then
if random(1, 100) > 42 then
entities[#entities + 1] = {name = 'tree-04', position = p}
@ -37,7 +33,7 @@ local function process_tile(p, seed, entities)
end
return
else
if random(1, 152 - biters) == 1 and Functions.distance(p.x, p.y) > 200 then
if random(1, 202 + handicap - biters) == 1 and Functions.distance(p.x, p.y) > 150 + handicap then
entities[#entities + 1] = {name = Raffle.spawners[random(1, #Raffle.spawners)], position = p, spawn_decorations = true}
end
end

View File

@ -196,6 +196,7 @@ function Public.create_wagon_room()
protect(e, true)
--e.link_id = 1000 + i + 12 * (k - 1)
table.insert(objective.comfychests2, e)
table.insert(objective.comfychest_invs2, e.get_inventory(defines.inventory.chest))
end
end