1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/chronosphere/main.lua

690 lines
25 KiB
Lua
Raw Normal View History

2020-02-14 22:06:52 +02:00
-- chronosphere --
require "functions.soft_reset"
require "functions.basic_markets"
require "modules.difficulty_vote"
2020-02-14 22:06:52 +02:00
require "modules.biters_yield_coins"
require "modules.no_deconstruction_of_neutral_entities"
--require "modules.no_solar"
require "modules.shotgun_buff"
require "modules.mineable_wreckage_yields_scrap"
require "maps.chronosphere.comfylatron"
2020-02-18 03:43:22 +02:00
require "maps.chronosphere.terrain"
2020-02-14 22:06:52 +02:00
require "on_tick_schedule"
require "modules.biter_noms_you"
2020-02-17 18:37:22 +02:00
local Server = require 'utils.server'
2020-02-14 22:06:52 +02:00
local Ai = require "maps.chronosphere.ai"
2020-02-18 03:43:22 +02:00
local Planets = require "maps.chronosphere.chronobubles"
local Ores =require "maps.chronosphere.ores"
2020-02-14 22:06:52 +02:00
local Reset = require "functions.soft_reset"
local Map = require "modules.map_info"
2020-02-18 03:43:22 +02:00
local Upgrades = require "maps.chronosphere.upgrades"
2020-02-24 01:39:58 +02:00
local Tick_functions = require "maps.chronosphere.tick_functions"
local Event_functions = require "maps.chronosphere.event_functions"
local Chrono = require "maps.chronosphere.chrono"
2020-02-14 22:06:52 +02:00
local Locomotive = require "maps.chronosphere.locomotive"
2020-02-24 01:39:58 +02:00
--local Modifier = require "player_modifiers"
2020-02-14 22:06:52 +02:00
local update_gui = require "maps.chronosphere.gui"
local math_random = math.random
local math_floor = math.floor
local math_sqrt = math.sqrt
--local chests = {}
2020-02-17 01:46:22 +02:00
--local acus = {}
2020-02-14 22:06:52 +02:00
global.objective = {}
2020-03-05 16:56:59 +02:00
global.objective.config = {}
2020-02-17 01:46:22 +02:00
global.flame_boots = {}
2020-02-18 03:43:22 +02:00
global.comfylatron = nil
global.lab_cells = {}
2020-02-14 22:06:52 +02:00
2020-02-18 03:43:22 +02:00
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 32, ['grenade'] = 4, ['raw-fish'] = 4, ['rail'] = 16, ['wood'] = 16}
2020-02-17 01:46:22 +02:00
local starting_cargo = {['firearm-magazine'] = 16, ['iron-plate'] = 16, ['wood'] = 16, ['burner-mining-drill'] = 8}
2020-02-14 22:06:52 +02:00
2020-02-18 03:43:22 +02:00
local function generate_overworld(surface, optplanet)
Planets.determine_planet(optplanet)
local planet = global.objective.planet
local message = "Planet info: " .. planet[1].name.name .. ", Ore richness: " .. planet[1].ore_richness.name .. ", Speed of day: " .. planet[1].day_speed.name
game.print(message, {r=0.98, g=0.66, b=0.22})
Server.to_discord_embed(message)
2020-02-21 07:25:19 +02:00
if planet[1].name.id == 12 then
2020-02-14 22:06:52 +02:00
game.print("Comfylatron: OwO what are those strange trees?!? They have ore fruits! WTF!", {r=0.98, g=0.66, b=0.22})
2020-02-21 07:25:19 +02:00
elseif planet[1].name.id == 14 then
game.print("Comfylatron: OOF this one is a bit hot. And have seen those biters? They BATHE in fire! Maybe try some bricks to protect from lava?", {r=0.98, g=0.66, b=0.22})
elseif planet[1].name.id == 17 then
2020-02-23 17:51:07 +02:00
game.print("Comfylatron: So here we are. Fish Market. When they ordered the fish, they said this location is perfectly safe. Looks like we will have to do it for them. I hope you have enough nukes. Also, that satellite gave us some space knowledge.", {r=0.98, g=0.66, b=0.22})
2020-02-14 22:06:52 +02:00
end
surface.min_brightness = 0
surface.brightness_visual_weights = {1, 1, 1}
global.objective.surface = surface
surface.daytime = planet[1].time
local timer = planet[1].day_speed.timer
if timer == 0 then
surface.freeze_daytime = true
timer = timer + 1
else
surface.freeze_daytime = false
end
surface.ticks_per_day = timer * 250
local moisture = planet[1].name.moisture
if moisture ~= 0 then
local mgs = surface.map_gen_settings
mgs.property_expression_names["control-setting:moisture:bias"] = moisture
surface.map_gen_settings = mgs
end
2020-02-21 07:25:19 +02:00
if planet[1].name.id == 8 then --water planet
2020-02-14 22:06:52 +02:00
local mgs = surface.map_gen_settings
2020-02-17 01:46:22 +02:00
mgs.water = 0.8
surface.map_gen_settings = mgs
end
2020-02-21 07:25:19 +02:00
if planet[1].name.id == 14 then --lava planet
2020-02-17 01:46:22 +02:00
local mgs = surface.map_gen_settings
mgs.water = 0
2020-02-14 22:06:52 +02:00
surface.map_gen_settings = mgs
end
2020-02-21 07:25:19 +02:00
if planet[1].name.id ~= 12 then --choppy planet
2020-02-14 22:06:52 +02:00
local mgs = surface.map_gen_settings
2020-02-17 01:46:22 +02:00
mgs.water = 0.2
2020-02-14 22:06:52 +02:00
surface.map_gen_settings = mgs
end
if planet[1].name.id == 17 then --fish market
local mgs = surface.map_gen_settings
mgs.width = 2176
surface.map_gen_settings = mgs
surface.request_to_generate_chunks({-960,-64}, 3)
--surface.request_to_generate_chunks({0,0}, 3)
surface.force_generate_chunk_requests()
else
surface.request_to_generate_chunks({0,0}, 3)
surface.force_generate_chunk_requests()
end
2020-02-14 22:06:52 +02:00
end
local function get_map_gen_settings()
2020-03-05 16:56:59 +02:00
local seed = math_random(1, 1000000)
2020-02-14 22:06:52 +02:00
local map_gen_settings = {
2020-03-05 16:56:59 +02:00
["seed"] = seed,
2020-02-18 03:43:22 +02:00
["width"] = 960,
["height"] = 960,
2020-02-14 22:06:52 +02:00
["water"] = 0.1,
["starting_area"] = 1,
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
["default_enable_all_autoplace_controls"] = true,
["autoplace_settings"] = {
["entity"] = {treat_missing_as_default = false},
["tile"] = {treat_missing_as_default = true},
["decorative"] = {treat_missing_as_default = true},
},
}
return map_gen_settings
end
local function render_train_hp()
local surface = game.surfaces[global.active_surface_index]
local objective = global.objective
objective.health_text = rendering.draw_text{
text = "HP: " .. objective.health .. " / " .. objective.max_health,
surface = surface,
target = global.locomotive,
target_offset = {0, -2.5},
color = global.locomotive.color,
scale = 1.40,
font = "default-game",
alignment = "center",
scale_with_zoom = false
}
objective.caption = rendering.draw_text{
text = "Comfylatron's ChronoTrain",
surface = surface,
target = global.locomotive,
target_offset = {0, -4.25},
color = global.locomotive.color,
scale = 1.80,
font = "default-game",
alignment = "center",
scale_with_zoom = false
}
end
2020-02-18 03:43:22 +02:00
local function reset_map()
2020-03-05 16:56:59 +02:00
for _,player in pairs(game.players) do
if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end
end
2020-02-14 22:06:52 +02:00
global.chunk_queue = {}
if game.surfaces["chronosphere"] then game.delete_surface(game.surfaces["chronosphere"]) end
if game.surfaces["cargo_wagon"] then game.delete_surface(game.surfaces["cargo_wagon"]) end
--chests = {}
local objective = global.objective
objective.computerupgrade = 0
objective.computerparts = 0
2020-02-25 15:49:30 +02:00
objective.computermessage = 0
2020-02-14 22:06:52 +02:00
local map_gen_settings = get_map_gen_settings()
2020-02-18 03:43:22 +02:00
Planets.determine_planet(nil)
local planet = global.objective.planet
2020-02-14 22:06:52 +02:00
if not global.active_surface_index then
global.active_surface_index = game.create_surface("chronosphere", map_gen_settings).index
else
game.forces.player.set_spawn_position({12, 10}, game.surfaces[global.active_surface_index])
global.active_surface_index = Reset.soft_reset_map(game.surfaces[global.active_surface_index], map_gen_settings, starting_items).index
end
local surface = game.surfaces[global.active_surface_index]
generate_overworld(surface, planet)
2020-02-14 22:06:52 +02:00
objective.max_health = 10000
objective.health = 10000
objective.hpupgradetier = 0
objective.acuupgradetier = 0
objective.filterupgradetier = 0
2020-02-17 01:46:22 +02:00
objective.pickupupgradetier = 0
objective.invupgradetier = 0
objective.toolsupgradetier = 0
objective.waterupgradetier = 0
objective.outupgradetier = 0
objective.boxupgradetier = 0
objective.poisondefense = 2
objective.poisontimeout = 0
2020-02-14 22:06:52 +02:00
objective.chronojumps = 0
objective.chronotimer = 0
objective.passivetimer = 0
objective.passivejumps = 0
2020-02-14 22:06:52 +02:00
objective.chrononeeds = 2000
objective.mainscore = 0
2020-02-14 22:06:52 +02:00
objective.active_biters = {}
objective.unit_groups = {}
objective.biter_raffle = {}
2020-03-05 16:56:59 +02:00
objective.dangertimer = 1200
objective.dangers = {}
objective.looted_nukes = 0
2020-02-17 01:46:22 +02:00
global.outchests = {}
global.upgradechest = {}
global.fishchest = {}
2020-02-23 17:51:07 +02:00
global.acumulators = {}
2020-03-05 16:56:59 +02:00
global.comfychests = {}
global.comfychests2 = {}
global.locomotive_cargo = {}
2020-02-24 01:39:58 +02:00
for _, player in pairs(game.connected_players) do
global.flame_boots[player.index] = {fuel = 1, steps = {}}
end
2020-02-23 17:51:07 +02:00
global.friendly_fire_history = {}
global.landfill_history = {}
global.mining_history = {}
global.score = {}
2020-02-17 01:46:22 +02:00
2020-02-14 22:06:52 +02:00
2020-02-17 18:37:22 +02:00
game.difficulty_settings.technology_price_multiplier = 0.6
2020-02-18 03:43:22 +02:00
game.map_settings.enemy_evolution.destroy_factor = 0.005
2020-02-14 22:06:52 +02:00
game.map_settings.enemy_evolution.pollution_factor = 0
2020-02-18 03:43:22 +02:00
game.map_settings.enemy_evolution.time_factor = 7e-05
2020-02-14 22:06:52 +02:00
game.map_settings.enemy_expansion.enabled = true
game.map_settings.enemy_expansion.max_expansion_cooldown = 3600
game.map_settings.enemy_expansion.min_expansion_cooldown = 3600
game.map_settings.enemy_expansion.settler_group_max_size = 8
game.map_settings.enemy_expansion.settler_group_min_size = 16
game.map_settings.pollution.enabled = true
game.map_settings.pollution.pollution_restored_per_tree_damage = 0.02
2020-02-17 18:37:22 +02:00
game.map_settings.pollution.min_pollution_to_damage_trees = 1
game.map_settings.pollution.max_pollution_to_restore_trees = 0
game.map_settings.pollution.pollution_with_max_forest_damage = 10
game.map_settings.pollution.pollution_per_tree_damage = 0.1
2020-02-18 03:43:22 +02:00
game.map_settings.pollution.ageing = 0.1
2020-02-17 18:37:22 +02:00
game.map_settings.pollution.diffusion_ratio = 0.1
game.map_settings.pollution.enemy_attack_pollution_consumption_modifier = 5
2020-03-05 16:56:59 +02:00
game.forces.enemy.evolution_factor = 0.0001
game.forces.scrapyard.set_friend('enemy', true)
game.forces.enemy.set_friend('scrapyard', true)
2020-02-14 22:06:52 +02:00
game.forces.player.technologies["land-mine"].enabled = false
game.forces.player.technologies["landfill"].enabled = false
2020-03-05 16:56:59 +02:00
game.forces.player.technologies["fusion-reactor-equipment"].enabled = false
game.forces.player.technologies["power-armor-mk2"].enabled = false
2020-02-14 22:06:52 +02:00
game.forces.player.technologies["railway"].researched = true
2020-03-05 16:56:59 +02:00
game.forces.player.recipes["pistol"].enabled = false
2020-02-14 22:06:52 +02:00
game.forces.player.set_spawn_position({12, 10}, surface)
2020-02-21 07:25:19 +02:00
local wagons = {}
2020-03-05 16:56:59 +02:00
wagons[1] = {inventory = {["raw-fish"] = 100}, bar = 0, filters = {}}
2020-02-21 07:25:19 +02:00
wagons[2] = {inventory = starting_cargo, bar = 0, filters = {}}
2020-03-05 16:56:59 +02:00
wagons[3] = {inventory = starting_cargo, bar = 0, filters = {}}
2020-02-21 07:25:19 +02:00
for i = 1, 40, 1 do
wagons[2].filters[i] = nil
2020-03-05 16:56:59 +02:00
wagons[3].filters[i] = nil
2020-02-21 07:25:19 +02:00
end
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, wagons)
2020-02-14 22:06:52 +02:00
render_train_hp()
2020-02-17 01:46:22 +02:00
game.reset_time_played()
2020-03-05 16:56:59 +02:00
Locomotive.create_wagon_room()
global.difficulty_poll_closing_timeout = game.tick + 54000
global.difficulty_player_votes = {}
if objective.game_won then
game.print("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.", {r=0.98, g=0.66, b=0.22})
end
2020-02-17 01:46:22 +02:00
objective.game_lost = false
objective.game_won = false
2020-02-14 22:06:52 +02:00
--set_difficulty()
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
2020-02-17 01:46:22 +02:00
global.flame_boots[event.player_index] = {fuel = 1}
if not global.flame_boots[event.player_index].steps then global.flame_boots[event.player_index].steps = {} end
2020-02-14 22:06:52 +02:00
local surface = game.surfaces[global.active_surface_index]
if player.online_time == 0 then
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 32, 0.5), surface)
for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount})
end
end
if player.surface.index ~= global.active_surface_index and player.surface.name ~= "cargo_wagon" then
player.character = nil
player.set_controller({type=defines.controllers.god})
player.create_character()
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 32, 0.5), surface)
for item, amount in pairs(starting_items) do
player.insert({name = item, count = amount})
end
end
local tile = surface.get_tile(player.position)
if tile.valid then
if tile.name == "out-of-map" then
player.teleport(surface.find_non_colliding_position("character", game.forces.player.get_spawn_position(surface), 32, 0.5), surface)
end
end
end
2020-03-05 16:56:59 +02:00
local function on_player_left_game(event)
local player = game.players[event.player_index]
end
local function on_pre_player_left_game(event)
local player = game.players[event.player_index]
if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end
if player.character then
global.objective.offline_players[#global.objective.offline_players + 1] = {index = event.player_index, tick = game.tick}
end
end
2020-02-24 01:39:58 +02:00
local function set_objective_health(final_damage_amount)
if final_damage_amount == 0 then return end
2020-02-14 22:06:52 +02:00
local objective = global.objective
2020-02-24 01:39:58 +02:00
objective.health = math_floor(objective.health - final_damage_amount)
if objective.health > objective.max_health then objective.health = objective.max_health end
2020-02-14 22:06:52 +02:00
2020-02-24 01:39:58 +02:00
if objective.health <= 0 then
2020-02-24 08:13:38 +02:00
Chrono.objective_died()
2020-02-14 22:06:52 +02:00
end
2020-02-24 01:39:58 +02:00
if objective.health < objective.max_health / 2 and final_damage_amount > 0 then
Upgrades.trigger_poison()
2020-02-17 01:46:22 +02:00
end
2020-02-24 01:39:58 +02:00
rendering.set_text(objective.health_text, "HP: " .. objective.health .. " / " .. objective.max_health)
2020-02-17 01:46:22 +02:00
end
2020-02-18 03:43:22 +02:00
local function chronojump(choice)
2020-02-14 22:06:52 +02:00
local objective = global.objective
2020-02-17 01:46:22 +02:00
if objective.game_lost then return end
2020-02-24 01:39:58 +02:00
Chrono.process_jump()
2020-02-14 22:06:52 +02:00
local oldsurface = game.surfaces[global.active_surface_index]
for _,player in pairs(game.players) do
if player.surface == oldsurface then
if player.controller_type == defines.controllers.editor then player.toggle_map_editor() end
2020-03-05 16:56:59 +02:00
local wagons = {global.locomotive_cargo[1], global.locomotive_cargo[2], global.locomotive_cargo[3]}
Locomotive.enter_cargo_wagon(player, wagons[math_random(1,3)])
2020-02-14 22:06:52 +02:00
end
end
local map_gen_settings = get_map_gen_settings()
global.lab_cells = {}
2020-02-14 22:06:52 +02:00
global.active_surface_index = game.create_surface("chronosphere" .. objective.chronojumps, map_gen_settings).index
local surface = game.surfaces[global.active_surface_index]
local planet = nil
if choice then
2020-02-18 03:43:22 +02:00
Planets.determine_planet(choice)
planet = global.objective.planet
2020-02-14 22:06:52 +02:00
end
generate_overworld(surface, planet)
2020-02-24 01:39:58 +02:00
2020-02-14 22:06:52 +02:00
game.forces.player.set_spawn_position({12, 10}, surface)
2020-02-24 01:39:58 +02:00
Locomotive.locomotive_spawn(surface, {x = 16, y = 10}, Chrono.get_wagons())
2020-02-14 22:06:52 +02:00
render_train_hp()
game.delete_surface(oldsurface)
2020-02-24 01:39:58 +02:00
Chrono.post_jump()
2020-02-25 15:49:30 +02:00
Event_functions.flamer_nerfs()
surface.pollute(global.locomotive.position, 150 * (4 / (objective.filterupgradetier / 2 + 1)) * (1 + global.objective.chronojumps))
2020-02-23 19:33:37 +02:00
end
2020-02-14 22:06:52 +02:00
local tick_minute_functions = {
[300 * 2] = Ai.destroy_inactive_biters,
[300 * 3 + 30 * 0] = Ai.pre_main_attack, -- setup for main_attack
[300 * 3 + 30 * 1] = Ai.perform_main_attack,
[300 * 3 + 30 * 2] = Ai.perform_main_attack,
2020-02-17 01:46:22 +02:00
[300 * 3 + 30 * 3] = Ai.perform_main_attack,
[300 * 3 + 30 * 4] = Ai.perform_main_attack,
[300 * 3 + 30 * 5] = Ai.perform_main_attack, -- call perform_main_attack 7 times on different ticks
2020-02-14 22:06:52 +02:00
[300 * 4] = Ai.send_near_biters_to_objective,
2020-02-25 15:49:30 +02:00
[300 * 5] = Ai.wake_up_sleepy_groups,
2020-02-25 16:47:10 +02:00
--[300] = Ai.rogue_group
2020-02-14 22:06:52 +02:00
}
local function tick()
2020-02-25 15:49:30 +02:00
local objective = global.objective
2020-02-14 22:06:52 +02:00
local tick = game.tick
2020-03-05 16:56:59 +02:00
if tick % 60 == 30 and objective.passivetimer < 64 then
2020-02-14 22:06:52 +02:00
local surface = game.surfaces[global.active_surface_index]
2020-02-25 15:49:30 +02:00
if objective.planet[1].name.id == 17 then
2020-03-05 16:56:59 +02:00
surface.request_to_generate_chunks({-800,0}, 3 + math_floor(objective.passivetimer / 5))
else
2020-03-05 16:56:59 +02:00
surface.request_to_generate_chunks({0,0}, 3 + math_floor(objective.passivetimer / 5))
end
2020-02-14 22:06:52 +02:00
--surface.force_generate_chunk_requests()
end
2020-02-25 15:49:30 +02:00
if tick % 10 == 0 and objective.planet[1].name.id == 18 then
2020-02-24 08:13:38 +02:00
Tick_functions.spawn_poison()
end
2020-02-14 22:06:52 +02:00
if tick % 30 == 0 then
if tick % 600 == 0 then
2020-02-24 01:39:58 +02:00
Tick_functions.charge_chronosphere()
Tick_functions.transfer_pollution()
2020-02-25 15:49:30 +02:00
if objective.poisontimeout > 0 then
objective.poisontimeout = objective.poisontimeout - 1
end
2020-02-14 22:06:52 +02:00
end
if tick % 1800 == 0 then
Locomotive.set_player_spawn_and_refill_fish()
2020-02-24 01:39:58 +02:00
set_objective_health(Tick_functions.repair_train())
2020-02-18 03:43:22 +02:00
Upgrades.check_upgrades()
2020-02-24 01:39:58 +02:00
Tick_functions.boost_evolution()
2020-03-05 16:56:59 +02:00
if objective.config.offline_loot then
Tick_functions.offline_players()
end
2020-02-14 22:06:52 +02:00
end
local key = tick % 3600
if tick_minute_functions[key] then tick_minute_functions[key]() end
2020-02-25 15:49:30 +02:00
if tick % 60 == 0 and objective.planet[1].name.id ~= 17 then
objective.chronotimer = objective.chronotimer + 1
objective.passivetimer = objective.passivetimer + 1
if objective.chronojumps > 0 then
game.surfaces[global.active_surface_index].pollute(global.locomotive.position, (0.5 * objective.chronojumps) * (4 / (objective.filterupgradetier / 2 + 1)) * global.difficulty_vote_value)
end
2020-03-05 16:56:59 +02:00
if objective.planet[1].name.id == 19 then
Tick_functions.dangertimer()
end
2020-02-24 01:39:58 +02:00
if Tick_functions.check_chronoprogress() then chronojump(nil) end
2020-02-14 22:06:52 +02:00
end
if tick % 120 == 0 then
2020-02-24 01:39:58 +02:00
Tick_functions.move_items()
Tick_functions.output_items()
2020-02-14 22:06:52 +02:00
end
if global.game_reset_tick then
if global.game_reset_tick < tick then
global.game_reset_tick = nil
2020-02-18 03:43:22 +02:00
reset_map()
2020-02-14 22:06:52 +02:00
end
return
end
Locomotive.fish_tag()
end
for _, player in pairs(game.connected_players) do update_gui(player) end
end
local function on_init()
local T = Map.Pop_info()
T.localised_category = "chronosphere"
T.main_caption_color = {r = 150, g = 150, b = 0}
T.sub_caption_color = {r = 0, g = 150, b = 0}
2020-02-17 01:46:22 +02:00
global.objective.game_lost = true
global.objective.game_won = false
2020-03-05 16:56:59 +02:00
global.objective.offline_players = {}
global.objective.config.offline_loot = true
global.objective.config.jumpfailure = true
2020-02-17 18:37:22 +02:00
game.create_force("scrapyard")
2020-03-05 16:56:59 +02:00
local mgs = game.surfaces["nauvis"].map_gen_settings
mgs.width = 16
mgs.height = 16
game.surfaces["nauvis"].map_gen_settings = mgs
game.surfaces["nauvis"].clear()
2020-02-18 03:43:22 +02:00
reset_map()
2020-02-24 01:39:58 +02:00
--if game.surfaces["nauvis"] then game.delete_surface(game.surfaces["nauvis"]) end
2020-02-14 22:06:52 +02:00
end
local function protect_entity(event)
if event.entity.force.index ~= 1 then return end --Player Force
2020-02-24 01:39:58 +02:00
if Event_functions.isprotected(event.entity) then
2020-02-14 22:06:52 +02:00
if event.cause then
2020-02-18 03:43:22 +02:00
if event.cause == global.comfylatron or event.entity == global.comfylatron then
return
end
2020-03-05 16:56:59 +02:00
if event.cause.force.index == 2 or event.cause.force.name == "scrapyard" then
2020-02-18 03:43:22 +02:00
set_objective_health(event.final_damage_amount)
2020-02-14 22:06:52 +02:00
end
2020-03-05 16:56:59 +02:00
elseif global.objective.planet[1].name.id == 19 then
set_objective_health(event.final_damage_amount)
2020-02-14 22:06:52 +02:00
end
if not event.entity.valid then return end
event.entity.health = event.entity.health + event.final_damage_amount
end
end
local function 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
2020-02-24 01:39:58 +02:00
Event_functions.biters_chew_rocks_faster(event)
2020-02-25 15:49:30 +02:00
if event.entity.force.name == "enemy" then
Event_functions.biter_immunities(event)
2020-02-24 08:13:38 +02:00
end
2020-02-14 22:06:52 +02:00
end
local function pre_player_mined_item(event)
local objective = global.objective
2020-02-21 07:25:19 +02:00
if objective.planet[1].name.id == 11 then --rocky planet
2020-02-14 22:06:52 +02:00
if event.entity.name == "rock-huge" or event.entity.name == "rock-big" or event.entity.name == "sand-rock-big" then
2020-02-24 01:39:58 +02:00
Event_functions.trap(event.entity, false)
2020-02-14 22:06:52 +02:00
event.entity.destroy()
2020-02-24 01:39:58 +02:00
Event_functions.rocky_loot(event)
2020-02-14 22:06:52 +02:00
end
end
end
local function on_player_mined_entity(event)
local entity = event.entity
if not entity.valid then return end
2020-02-21 07:25:19 +02:00
if entity.type == "tree" and global.objective.planet[1].name.id == 12 then --choppy planet
2020-02-24 01:39:58 +02:00
Event_functions.trap(entity, false)
Event_functions.choppy_loot(event)
2020-02-14 22:06:52 +02:00
end
if entity.name == "rock-huge" or entity.name == "rock-big" or entity.name == "sand-rock-big" then
if global.objective.planet[1].name.id ~= 11 and global.objective.planet[1].name.id ~= 16 then --rocky and maze planet
Ores.prospect_ores(entity, entity.surface, entity.position)
2020-02-14 22:06:52 +02:00
elseif
global.objective.planet[1].name.id == 11 then event.buffer.clear() -- rocky planet
2020-02-14 22:06:52 +02:00
end
end
end
local function on_entity_died(event)
2020-02-21 07:25:19 +02:00
if event.entity.type == "tree" and global.objective.planet[1].name.id == 12 then --choppy planet
2020-02-14 22:06:52 +02:00
if event.cause then
if event.cause.valid then
2020-02-24 01:39:58 +02:00
if event.cause.force.name ~= "enemy" then
Event_functions.trap(event.entity, false)
2020-02-14 22:06:52 +02:00
end
end
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
global.objective.active_biters[entity.unit_number] = nil
end
2020-03-05 16:56:59 +02:00
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
if global.objective.planet[1].name.id == 19 or global.objective.planet[1].name.id == 16 then --danger + hedge maze
Event_functions.trap(entity, true)
end
end
2020-03-05 16:56:59 +02:00
if entity.force.name == "enemy" then
if entity.type == "unit-spawner" then
Event_functions.spawner_loot(entity.surface, entity.position)
if global.objective.planet[1].name.id == 18 then
Ores.prospect_ores(entity, entity.surface, entity.position)
end
else
if global.objective.planet[1].name.id == 18 then
Event_functions.swamp_loot(event)
end
end
2020-02-24 08:13:38 +02:00
end
2020-02-14 22:06:52 +02:00
if entity.force.index == 3 then
if event.cause then
if event.cause.valid then
if event.cause.force.index == 2 then
2020-02-24 01:39:58 +02:00
Event_functions.shred_simple_entities(entity)
2020-02-14 22:06:52 +02:00
end
end
end
end
2020-02-24 01:39:58 +02:00
end
2020-02-14 22:06:52 +02:00
--on_player_mined_entity(event)
--if not event.entity.valid then return end
2020-02-24 01:39:58 +02:00
--end
2020-02-14 22:06:52 +02:00
2020-02-14 23:02:42 +02:00
local function on_research_finished(event)
2020-02-17 01:46:22 +02:00
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 100 + global.objective.invupgradetier * 5
2020-02-25 15:49:30 +02:00
Event_functions.flamer_nerfs()
2020-02-14 23:02:42 +02:00
if not event.research.force.technologies["steel-axe"].researched then return end
event.research.force.manual_mining_speed_modifier = 1 + game.forces.player.mining_drill_productivity_bonus * 4
end
2020-02-14 22:06:52 +02:00
local function on_player_driving_changed_state(event)
local player = game.players[event.player_index]
local vehicle = event.entity
Locomotive.enter_cargo_wagon(player, vehicle)
end
2020-02-17 01:46:22 +02:00
-- function deny_building(event)
-- local entity = event.created_entity
-- if not entity.valid then return end
-- local surface = event.created_entity.surface
--
-- if event.player_index then
-- game.players[event.player_index].insert({name = entity.name, count = 1})
-- else
-- local inventory = event.robot.get_inventory(defines.inventory.robot_cargo)
-- inventory.insert({name = entity.name, count = 1})
-- end
--
-- surface.create_entity({
-- name = "flying-text",
-- position = entity.position,
-- text = "Private Comfylatron's area!",
-- color = {r=0.98, g=0.66, b=0.22}
-- })
--
-- entity.destroy()
-- end
-- local function on_built_entity(event)
-- if event.surface.name == "cargo_wagon" and event.position.y < -190 then
-- deny_building(event)
-- end
-- end
--
-- local function on_robot_built_entity(event)
-- if event.surface.name == "cargo_wagon" and event.position.y < -190 then
-- deny_building(event)
-- end
-- Terrain.deny_construction_bots(event)
-- end
-- local function on_market_item_purchased(event)
-- Locomotive.offer_purchased(event)
-- end
local function on_player_changed_position(event)
2020-02-24 01:39:58 +02:00
if global.objective.planet[1].name.id == 14 then --lava planet
Event_functions.lava_planet(event)
2020-02-17 01:46:22 +02:00
end
2020-02-14 22:06:52 +02:00
end
local event = require 'utils.event'
event.on_init(on_init)
event.on_nth_tick(2, tick)
event.add(defines.events.on_entity_damaged, on_entity_damaged)
event.add(defines.events.on_entity_died, on_entity_died)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
2020-03-05 16:56:59 +02:00
event.add(defines.events.on_player_left_game, on_player_left_game)
event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
2020-02-14 22:06:52 +02:00
event.add(defines.events.on_pre_player_mined_item, pre_player_mined_item)
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
2020-02-14 23:02:42 +02:00
event.add(defines.events.on_research_finished, on_research_finished)
2020-02-17 01:46:22 +02:00
--event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
2020-02-14 22:06:52 +02:00
event.add(defines.events.on_player_driving_changed_state, on_player_driving_changed_state)
2020-02-17 01:46:22 +02:00
event.add(defines.events.on_player_changed_position, on_player_changed_position)
2020-02-14 22:06:52 +02:00
2020-02-18 03:43:22 +02:00
if _DEBUG then
local Session = require 'utils.session_data'
local Color = require 'utils.color_presets'
commands.add_command(
'chronojump',
'Weeeeee!',
function(cmd)
local player = game.player
local trusted = Session.get_trusted_table()
local param = tostring(cmd.parameter)
local p
if player then
if player ~= nil then
p = player.print
if not trusted[player.name] then
if not player.admin then
p("[ERROR] Only admins and trusted weebs are allowed to run this command!", Color.fail)
return
end
end
else
p = log
end
end
chronojump(param)
end)
end
2020-03-05 16:56:59 +02:00
--Time for the debug code. If any (not global.) globals are written to at this point, an error will be thrown.
--eg, x = 2 will throw an error because it's not global.x or local x
setmetatable(_G, {
__newindex = function(_, n, v)
log("Desync warning: attempt to write to undeclared var " .. n)
-- game.print("Attempt to write to undeclared var " .. n)
global[n] = v;
end,
__index = function(_, n)
return global[n];
end
})