2020-05-08 09:39:20 +02:00
|
|
|
if package.loaded['comfy_panel.player_list'] then
|
|
|
|
package.unload = 'comfy_panel.player_list'
|
|
|
|
end
|
|
|
|
require 'maps.scrapyard.player_list'
|
2020-05-06 14:59:23 +02:00
|
|
|
require 'on_tick_schedule'
|
|
|
|
require 'modules.dynamic_landfill'
|
|
|
|
require 'modules.difficulty_vote'
|
|
|
|
require 'modules.shotgun_buff'
|
2020-05-09 10:04:24 +02:00
|
|
|
require 'modules.burden'
|
2020-05-06 14:59:23 +02:00
|
|
|
require 'modules.rocks_heal_over_time'
|
|
|
|
require 'modules.no_deconstruction_of_neutral_entities'
|
2020-05-09 10:04:24 +02:00
|
|
|
require 'modules.flamethrower_nerf'
|
2020-05-06 14:59:23 +02:00
|
|
|
require 'modules.rocks_yield_ore_veins'
|
|
|
|
require 'modules.spawners_contain_biters'
|
|
|
|
require 'modules.biters_yield_coins'
|
|
|
|
require 'modules.biter_noms_you'
|
|
|
|
require 'modules.wave_defense.main'
|
|
|
|
require 'maps.scrapyard.comfylatron'
|
2020-05-08 09:39:20 +02:00
|
|
|
require 'modules.admins_operate_biters'
|
|
|
|
require 'modules.pistol_buffs'
|
2020-05-06 14:59:23 +02:00
|
|
|
|
|
|
|
local Map_score = require 'comfy_panel.map_score'
|
|
|
|
local Explosives = require 'modules.explosives'
|
2020-04-30 14:48:40 +02:00
|
|
|
local Color = require 'utils.color_presets'
|
2020-05-08 09:39:20 +02:00
|
|
|
local update_gui = require 'maps.scrapyard.gui'
|
2020-05-06 14:59:23 +02:00
|
|
|
local ICW = require 'maps.scrapyard.icw.main'
|
|
|
|
local WD = require 'modules.wave_defense.table'
|
2019-11-07 15:38:11 +01:00
|
|
|
local Map = require 'modules.map_info'
|
2020-04-28 21:55:19 +02:00
|
|
|
local RPG = require 'maps.scrapyard.rpg'
|
2020-05-06 14:59:23 +02:00
|
|
|
local Reset = require 'functions.soft_reset'
|
|
|
|
local BiterRolls = require 'modules.wave_defense.biter_rolls'
|
|
|
|
local unearthing_worm = require 'functions.unearthing_worm'
|
|
|
|
local unearthing_biters = require 'functions.unearthing_biters'
|
2019-11-07 15:38:11 +01:00
|
|
|
local Loot = require 'maps.scrapyard.loot'
|
2020-05-06 14:59:23 +02:00
|
|
|
local Pets = require 'modules.biter_pets'
|
|
|
|
local tick_tack_trap = require 'functions.tick_tack_trap'
|
2019-11-07 15:38:11 +01:00
|
|
|
local Terrain = require 'maps.scrapyard.terrain'
|
|
|
|
local Event = require 'utils.event'
|
2020-05-06 14:59:23 +02:00
|
|
|
local Scrap_table = require 'maps.scrapyard.table'
|
|
|
|
local Locomotive = require 'maps.scrapyard.locomotive'.locomotive_spawn
|
|
|
|
local render_train_hp = require 'maps.scrapyard.locomotive'.render_train_hp
|
|
|
|
local Score = require 'comfy_panel.score'
|
|
|
|
local Poll = require 'comfy_panel.poll'
|
2020-05-09 10:04:24 +02:00
|
|
|
local Collapse = require 'modules.collapse'
|
|
|
|
local Balance = require 'maps.scrapyard.balance'
|
2019-11-07 15:38:11 +01:00
|
|
|
|
|
|
|
local Public = {}
|
2020-04-27 00:19:06 +02:00
|
|
|
local math_random = math.random
|
|
|
|
local math_floor = math.floor
|
2020-05-01 01:02:56 +02:00
|
|
|
|
2020-05-09 10:04:24 +02:00
|
|
|
Scrap_table.init({train_reveal = true, energy_shared = true})
|
2019-11-07 15:38:11 +01:00
|
|
|
|
|
|
|
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
|
2020-05-06 14:59:23 +02:00
|
|
|
local disabled_entities = {'gun-turret', 'laser-turret', 'flamethrower-turret', 'land-mine'}
|
|
|
|
local colors = {
|
|
|
|
'green-refined-concrete',
|
|
|
|
'red-refined-concrete',
|
|
|
|
'blue-refined-concrete'
|
|
|
|
}
|
2020-05-09 10:04:24 +02:00
|
|
|
local disabled_tiles = {
|
|
|
|
['water-shallow'] = true,
|
|
|
|
['deepwater-green'] = true,
|
|
|
|
['out-of-map'] = true,
|
|
|
|
['green-refined-concrete'] = true,
|
|
|
|
['red-refined-concrete'] = true,
|
|
|
|
['blue-refined-concrete'] = true
|
|
|
|
}
|
2019-11-07 15:38:11 +01:00
|
|
|
local treasure_chest_messages = {
|
2020-05-06 14:59:23 +02:00
|
|
|
"You notice an old crate within the rubble. It's filled with treasure!",
|
|
|
|
"You find a chest underneath the broken rocks. It's filled with goodies!",
|
|
|
|
'We has found the precious!'
|
2019-11-07 15:38:11 +01:00
|
|
|
}
|
|
|
|
|
2020-05-01 01:02:56 +02:00
|
|
|
local rare_treasure_chest_messages = {
|
2020-05-06 14:59:23 +02:00
|
|
|
'Your magic improves. You have found a chest that is filled with rare treasures!',
|
|
|
|
"Oh wonderful magic. You found a chest underneath the broken rocks. It's filled with rare goodies!",
|
|
|
|
"You're a wizard Harry! We has found the rare precious!"
|
2020-05-01 01:02:56 +02:00
|
|
|
}
|
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
local grandmaster = '[color=blue]Grandmaster:[/color]'
|
2020-05-02 11:45:59 +02:00
|
|
|
|
2019-11-07 21:24:58 +01:00
|
|
|
local function shuffle(tbl)
|
2020-05-06 14:59:23 +02:00
|
|
|
local size = #tbl
|
|
|
|
for i = size, 1, -1 do
|
|
|
|
local rand = math_random(size)
|
|
|
|
tbl[i], tbl[rand] = tbl[rand], tbl[i]
|
|
|
|
end
|
|
|
|
return tbl
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_scores()
|
|
|
|
local this = Scrap_table.get_table()
|
2020-05-08 09:39:20 +02:00
|
|
|
local wagon = this.locomotive_cargo
|
|
|
|
if not wagon then
|
2020-05-06 14:59:23 +02:00
|
|
|
return
|
|
|
|
end
|
2020-05-08 09:39:20 +02:00
|
|
|
if not wagon.valid then
|
2020-05-06 14:59:23 +02:00
|
|
|
return
|
|
|
|
end
|
2020-05-08 09:39:20 +02:00
|
|
|
local score = math_floor(wagon.position.y * -1)
|
2020-05-06 14:59:23 +02:00
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
if score > Map_score.get_score(player) then
|
|
|
|
Map_score.set_score(player, score)
|
|
|
|
end
|
|
|
|
end
|
2019-11-07 21:24:58 +01:00
|
|
|
end
|
|
|
|
|
2020-04-28 21:55:19 +02:00
|
|
|
local function set_objective_health(entity, final_damage_amount)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
if final_damage_amount == 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
this.locomotive_health = math_floor(this.locomotive_health - final_damage_amount)
|
|
|
|
this.cargo_health = math_floor(this.cargo_health - final_damage_amount)
|
|
|
|
if this.locomotive_health > this.locomotive_max_health then
|
|
|
|
this.locomotive_health = this.locomotive_max_health
|
|
|
|
end
|
|
|
|
if this.cargo_health > this.cargo_max_health then
|
|
|
|
this.cargo_health = this.cargo_max_health
|
|
|
|
end
|
|
|
|
if this.locomotive_health <= 0 then
|
|
|
|
Public.loco_died()
|
|
|
|
end
|
|
|
|
local m
|
|
|
|
if entity == this.locomotive then
|
|
|
|
m = this.locomotive_health / this.locomotive_max_health
|
|
|
|
entity.health = 1000 * m
|
|
|
|
elseif entity == this.locomotive_cargo then
|
|
|
|
m = this.cargo_health / this.cargo_max_health
|
|
|
|
entity.health = 600 * m
|
|
|
|
end
|
|
|
|
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
2020-04-26 19:36:58 +02:00
|
|
|
end
|
|
|
|
|
2020-04-30 14:48:40 +02:00
|
|
|
local function set_difficulty()
|
2020-05-06 14:59:23 +02:00
|
|
|
local wave_defense_table = WD.get_table()
|
|
|
|
local player_count = #game.connected_players
|
2020-04-30 14:48:40 +02:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
wave_defense_table.max_active_biters = 1024
|
2020-04-30 14:48:40 +02:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
-- threat gain / wave
|
|
|
|
wave_defense_table.threat_gain_multiplier = 2 + player_count * 0.1
|
2020-05-01 01:02:56 +02:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
local amount = player_count * 0.25 + 2
|
|
|
|
amount = math.floor(amount)
|
|
|
|
if amount > 8 then
|
|
|
|
amount = 8
|
|
|
|
end
|
|
|
|
Collapse.set_amount(amount)
|
2020-04-30 14:48:40 +02:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
--20 Players for fastest wave_interval
|
|
|
|
wave_defense_table.wave_interval = 3600 - player_count * 90
|
2020-05-09 10:04:24 +02:00
|
|
|
if wave_defense_table.wave_interval < 2000 then
|
|
|
|
wave_defense_table.wave_interval = 2000
|
2020-05-06 14:59:23 +02:00
|
|
|
end
|
2020-04-30 14:48:40 +02:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
function Public.reset_map()
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local wave_defense_table = WD.get_table()
|
|
|
|
local get_score = Score.get_table()
|
|
|
|
Poll.reset()
|
|
|
|
ICW.reset()
|
2020-05-09 10:04:24 +02:00
|
|
|
Balance.init_enemy_weapon_damage()
|
2020-05-06 14:59:23 +02:00
|
|
|
game.reset_time_played()
|
|
|
|
Scrap_table.reset_table()
|
|
|
|
wave_defense_table.math = 8
|
2020-05-08 09:39:20 +02:00
|
|
|
if not this.train_reveal then
|
|
|
|
this.revealed_spawn = game.tick + 100
|
|
|
|
end
|
2020-05-06 14:59:23 +02:00
|
|
|
|
|
|
|
local map_gen_settings = {
|
|
|
|
['seed'] = math_random(1, 1000000),
|
|
|
|
['water'] = 0.001,
|
|
|
|
['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}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if not this.active_surface_index then
|
|
|
|
this.active_surface_index = game.create_surface('scrapyard', map_gen_settings).index
|
|
|
|
else
|
2020-05-08 09:39:20 +02:00
|
|
|
game.forces.player.set_spawn_position({0, 25}, game.surfaces[this.active_surface_index])
|
2020-05-06 14:59:23 +02:00
|
|
|
this.active_surface_index =
|
|
|
|
Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
|
2020-05-09 10:04:24 +02:00
|
|
|
this.active_surface = game.surfaces[this.active_surface_index]
|
2020-05-06 14:59:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
|
|
|
|
surface.request_to_generate_chunks({0, 0}, 0.5)
|
|
|
|
surface.force_generate_chunk_requests()
|
|
|
|
|
|
|
|
local p = surface.find_non_colliding_position('character-corpse', {2, 21}, 2, 2)
|
|
|
|
surface.create_entity({name = 'character-corpse', position = p})
|
|
|
|
|
|
|
|
game.forces.player.technologies['landfill'].enabled = false
|
|
|
|
game.forces.player.technologies['optics'].researched = true
|
|
|
|
game.forces.player.recipes['cargo-wagon'].enabled = false
|
|
|
|
game.forces.player.recipes['fluid-wagon'].enabled = false
|
|
|
|
game.forces.player.recipes['artillery-wagon'].enabled = false
|
|
|
|
game.forces.player.recipes['locomotive'].enabled = false
|
|
|
|
game.forces.player.recipes['pistol'].enabled = false
|
2020-05-08 09:39:20 +02:00
|
|
|
game.forces.player.technologies['land-mine'].enabled = false
|
2020-05-06 14:59:23 +02:00
|
|
|
game.forces.player.set_spawn_position({0, 21}, surface)
|
|
|
|
|
|
|
|
global.friendly_fire_history = {}
|
|
|
|
global.landfill_history = {}
|
|
|
|
global.mining_history = {}
|
|
|
|
get_score.score_table = {}
|
|
|
|
global.difficulty_poll_closing_timeout = game.tick + 90000
|
|
|
|
global.difficulty_player_votes = {}
|
|
|
|
|
|
|
|
game.difficulty_settings.technology_price_multiplier = 0.6
|
|
|
|
|
|
|
|
Collapse.set_kill_entities(false)
|
|
|
|
Collapse.set_speed(8)
|
|
|
|
Collapse.set_amount(1)
|
|
|
|
Collapse.set_max_line_size(Terrain.level_depth)
|
|
|
|
Collapse.set_surface(surface)
|
|
|
|
Collapse.set_position({0, 290})
|
|
|
|
Collapse.set_direction('north')
|
|
|
|
Collapse.start_now(false)
|
|
|
|
|
|
|
|
surface.ticks_per_day = surface.ticks_per_day * 2
|
2020-05-09 10:04:24 +02:00
|
|
|
surface.daytime = 1
|
2020-05-06 14:59:23 +02:00
|
|
|
surface.brightness_visual_weights = {1, 0, 0, 0}
|
2020-05-08 09:39:20 +02:00
|
|
|
surface.freeze_daytime = true
|
2020-05-06 14:59:23 +02:00
|
|
|
surface.solar_power_multiplier = 1
|
|
|
|
this.locomotive_health = 10000
|
|
|
|
this.locomotive_max_health = 10000
|
|
|
|
this.cargo_health = 10000
|
|
|
|
this.cargo_max_health = 10000
|
|
|
|
|
|
|
|
Locomotive(surface, {x = -18, y = 25})
|
|
|
|
render_train_hp()
|
|
|
|
|
|
|
|
rendering.draw_text {
|
|
|
|
text = 'Welcome to Scrapyard!',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 30},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 40},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 50},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 60},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 70},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 80},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 90},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 100},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = '▼',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 110},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
rendering.draw_text {
|
|
|
|
text = 'Biters will attack this area.',
|
|
|
|
surface = surface,
|
|
|
|
target = {-0, 120},
|
|
|
|
color = {r = 0.98, g = 0.66, b = 0.22},
|
|
|
|
scale = 3,
|
|
|
|
font = 'heading-1',
|
|
|
|
alignment = 'center',
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
|
|
|
|
WD.reset_wave_defense()
|
|
|
|
wave_defense_table.surface_index = this.active_surface_index
|
|
|
|
wave_defense_table.target = this.locomotive_cargo
|
|
|
|
wave_defense_table.nest_building_density = 32
|
|
|
|
wave_defense_table.game_lost = false
|
|
|
|
wave_defense_table.spawn_position = {x = 0, y = 220}
|
|
|
|
|
|
|
|
game.forces.player.set_friend('scrap', true)
|
|
|
|
game.forces.enemy.set_friend('scrap', true)
|
|
|
|
game.forces.scrap.set_friend('player', true)
|
|
|
|
game.forces.scrap.set_friend('enemy', true)
|
|
|
|
game.forces.scrap.share_chart = false
|
|
|
|
|
|
|
|
surface.create_entity({name = 'electric-beam', position = {-196, 190}, source = {-196, 190}, target = {196, 190}})
|
|
|
|
surface.create_entity({name = 'electric-beam', position = {-196, 190}, source = {-196, 190}, target = {196, 190}})
|
|
|
|
|
|
|
|
RPG.rpg_reset_all_players()
|
|
|
|
|
|
|
|
set_difficulty()
|
2019-11-07 21:24:58 +01:00
|
|
|
end
|
|
|
|
|
2020-04-30 11:44:57 +02:00
|
|
|
local function is_protected(entity)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
if string.sub(entity.surface.name, 0, 9) ~= 'scrapyard' then
|
|
|
|
return true
|
2020-04-27 20:04:37 +02:00
|
|
|
end
|
2020-05-06 14:59:23 +02:00
|
|
|
local protected = {this.locomotive, this.locomotive_cargo}
|
|
|
|
for i = 1, #protected do
|
|
|
|
if protected[i] == entity then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
2020-04-27 20:04:37 +02:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local function protect_train(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
if event.entity.force.index ~= 1 then
|
|
|
|
return
|
|
|
|
end --Player Force
|
|
|
|
if is_protected(event.entity) then
|
|
|
|
if event.entity == this.locomotive_cargo or event.entity == this.locomotive then
|
|
|
|
if event.cause then
|
|
|
|
if
|
|
|
|
event.cause.force.index == 2 or event.cause.force.name == 'scrap_defense' or
|
|
|
|
event.cause.force.name == 'scrap'
|
|
|
|
then
|
|
|
|
if this.locomotive_health <= 0 then
|
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
set_objective_health(event.entity, event.final_damage_amount)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
if not event.entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
event.entity.health = event.entity.health + event.final_damage_amount
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
2020-04-30 11:44:57 +02:00
|
|
|
local function change_tile(surface, pos, steps)
|
2020-05-09 10:04:24 +02:00
|
|
|
return surface.set_tiles {{name = colors[math_floor(steps * 0.5) % 3 + 1], position = {x = pos.x, y = pos.y}}}
|
2020-04-28 21:55:19 +02:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local function on_player_changed_position(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if string.sub(player.surface.name, 0, 9) ~= 'scrapyard' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local position = player.position
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
if position.x >= Terrain.level_depth * 0.5 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if position.x < Terrain.level_depth * -0.5 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if position.y < 5 then
|
|
|
|
if not this.players[player.index].tiles_enabled then
|
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
--for x = -1,1 do
|
|
|
|
--for y = -1,1 do
|
|
|
|
--local _pos = {position.x+x,position.y+y}
|
|
|
|
local steps = this.players[player.index].steps
|
2020-05-09 10:04:24 +02:00
|
|
|
local tile = surface.get_tile(position).name
|
|
|
|
local disabled = disabled_tiles[tile]
|
|
|
|
if disabled then
|
2020-05-06 14:59:23 +02:00
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
change_tile(surface, position, steps)
|
|
|
|
if this.players[player.index].steps > 5000 then
|
|
|
|
this.players[player.index].steps = 0
|
|
|
|
end
|
|
|
|
this.players[player.index].steps = this.players[player.index].steps + 1
|
|
|
|
--end
|
|
|
|
--end
|
|
|
|
end
|
|
|
|
::continue::
|
2020-05-09 10:04:24 +02:00
|
|
|
if not this.train_reveal or this.players[player.index].reveal - game.tick > 0 then
|
2020-05-08 09:39:20 +02:00
|
|
|
if position.y < 5 then
|
|
|
|
Terrain.reveal(player)
|
|
|
|
end
|
|
|
|
end
|
2020-05-06 14:59:23 +02:00
|
|
|
if position.y >= 190 then
|
|
|
|
player.teleport({position.x, position.y - 1}, surface)
|
|
|
|
player.print(grandmaster .. ' Forcefield does not approve.', {r = 0.98, g = 0.66, b = 0.22})
|
|
|
|
if player.character then
|
|
|
|
player.character.health = player.character.health - 5
|
|
|
|
player.character.surface.create_entity({name = 'water-splash', position = position})
|
|
|
|
if player.character.health <= 0 then
|
|
|
|
player.character.die('enemy')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
2020-04-30 11:44:57 +02:00
|
|
|
local function on_player_left_game()
|
2020-05-06 14:59:23 +02:00
|
|
|
set_difficulty()
|
2019-11-07 21:24:58 +01:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local function on_player_joined_game(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
|
|
|
|
set_difficulty(event)
|
|
|
|
|
|
|
|
if not this.players then
|
|
|
|
this.players = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if not this.players[player.index] then
|
|
|
|
this.players[player.index] = {
|
|
|
|
tiles_enabled = true,
|
|
|
|
steps = 0,
|
2020-05-09 10:04:24 +02:00
|
|
|
first_join = false,
|
|
|
|
reveal = 0,
|
|
|
|
data = {}
|
2020-05-06 14:59:23 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if not this.players[player.index].first_join then
|
|
|
|
player.print(grandmaster .. ' Greetings, newly joined ' .. player.name .. '!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
player.print(grandmaster .. ' Please read the map info.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
player.print(grandmaster .. ' Guide the choo through the black mist.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
player.print(grandmaster .. ' To disable rainbow mode, type in console: /rainbow_mode', Color.info)
|
|
|
|
this.players[player.index].first_join = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if player.surface.index ~= this.active_surface_index then
|
|
|
|
player.teleport(
|
|
|
|
surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5),
|
|
|
|
surface
|
|
|
|
)
|
|
|
|
for item, amount in pairs(starting_items) do
|
|
|
|
player.insert({name = item, count = amount})
|
|
|
|
end
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function hidden_biter(entity)
|
2020-05-06 14:59:23 +02:00
|
|
|
BiterRolls.wave_defense_set_unit_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25)
|
|
|
|
if math.random(1, 3) == 1 then
|
|
|
|
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = entity.position})
|
|
|
|
else
|
|
|
|
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = entity.position})
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function hidden_worm(entity)
|
2020-05-06 14:59:23 +02:00
|
|
|
BiterRolls.wave_defense_set_worm_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.25)
|
|
|
|
entity.surface.create_entity({name = BiterRolls.wave_defense_roll_worm_name(), position = entity.position})
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function hidden_biter_pet(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
if math.random(1, 2048) ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
BiterRolls.wave_defense_set_unit_raffle(math.sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.25)
|
|
|
|
local unit
|
|
|
|
if math.random(1, 3) == 1 then
|
|
|
|
unit =
|
|
|
|
event.entity.surface.create_entity(
|
|
|
|
{name = BiterRolls.wave_defense_roll_spitter_name(), position = event.entity.position}
|
|
|
|
)
|
|
|
|
else
|
|
|
|
unit =
|
|
|
|
event.entity.surface.create_entity(
|
|
|
|
{name = BiterRolls.wave_defense_roll_biter_name(), position = event.entity.position}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
Pets.biter_pets_tame_unit(game.players[event.player_index], unit, true)
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function hidden_treasure(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local rpg_t = RPG.get_table()
|
|
|
|
local magic = rpg_t[player.index].magic
|
|
|
|
if math.random(1, 320) ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if magic > 50 then
|
|
|
|
player.print(
|
|
|
|
rare_treasure_chest_messages[math.random(1, #rare_treasure_chest_messages)],
|
|
|
|
{r = 0.98, g = 0.66, b = 0.22}
|
|
|
|
)
|
|
|
|
Loot.add(event.entity.surface, event.entity.position, 'wooden-chest', magic)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
player.print(treasure_chest_messages[math.random(1, #treasure_chest_messages)], {r = 0.98, g = 0.66, b = 0.22})
|
|
|
|
Loot.add(event.entity.surface, event.entity.position, 'wooden-chest')
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
2019-11-07 21:24:58 +01:00
|
|
|
local function biters_chew_rocks_faster(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
if event.entity.force.index ~= 3 then
|
|
|
|
return
|
|
|
|
end --Neutral Force
|
|
|
|
if not event.cause then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not event.cause.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if event.cause.force.index ~= 2 then
|
|
|
|
return
|
|
|
|
end --Enemy Force
|
2019-11-07 21:24:58 +01:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
event.entity.health = event.entity.health - event.final_damage_amount * 2.5
|
2019-11-07 21:24:58 +01:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local function give_coin(player)
|
2020-05-06 14:59:23 +02:00
|
|
|
player.insert({name = 'coin', count = 1})
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_player_mined_entity(event)
|
2020-05-08 09:39:20 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
local entity = event.entity
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if not player.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if entity.type == 'unit' or entity.type == 'unit-spawner' then
|
|
|
|
if math_random(1, 160) == 1 then
|
|
|
|
tick_tack_trap(entity.surface, entity.position)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math.random(1, 32) == 1 then
|
|
|
|
hidden_biter(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if entity.name == 'mineable-wreckage' then
|
2020-05-08 09:39:20 +02:00
|
|
|
this.mined_scrap = this.mined_scrap + 1
|
2020-05-06 14:59:23 +02:00
|
|
|
give_coin(player)
|
|
|
|
|
|
|
|
if math.random(1, 32) == 1 then
|
|
|
|
hidden_biter(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math.random(1, 512) == 1 then
|
|
|
|
hidden_worm(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
hidden_biter_pet(event)
|
|
|
|
hidden_treasure(event)
|
|
|
|
if math_random(1, 160) == 1 then
|
|
|
|
tick_tack_trap(entity.surface, entity.position)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if entity.force.name ~= 'scrap' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local positions = {}
|
|
|
|
local r = math.ceil(entity.prototype.max_health / 32)
|
|
|
|
for x = r * -1, r, 1 do
|
|
|
|
for y = r * -1, r, 1 do
|
|
|
|
positions[#positions + 1] = {x = entity.position.x + x, y = entity.position.y + y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
positions = shuffle(positions)
|
|
|
|
for i = 1, math.ceil(entity.prototype.max_health / 32), 1 do
|
|
|
|
if not positions[i] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math_random(1, 3) ~= 1 then
|
|
|
|
unearthing_biters(entity.surface, positions[i], math_random(5, 10))
|
|
|
|
else
|
|
|
|
unearthing_worm(entity.surface, positions[i])
|
|
|
|
end
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_entity_damaged(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
if not event.entity then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not event.entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not event.entity.health then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
protect_train(event)
|
|
|
|
biters_chew_rocks_faster(event)
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
2020-04-28 21:55:19 +02:00
|
|
|
local function on_player_repaired_entity(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
if not event.entity then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not event.entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if not event.entity.health then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local entity = event.entity
|
|
|
|
if entity == this.locomotive_cargo or entity == this.locomotive then
|
|
|
|
set_objective_health(entity, -1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function offline_players()
|
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local players = this.offline_players
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
if #players > 0 then
|
|
|
|
local later = {}
|
|
|
|
for i = 1, #players, 1 do
|
|
|
|
if players[i] and game.players[players[i].index] and game.players[players[i].index].connected then
|
|
|
|
players[i] = nil
|
|
|
|
else
|
|
|
|
if players[i] and players[i].tick < game.tick - 54000 then
|
|
|
|
local player_inv = {}
|
|
|
|
local items = {}
|
|
|
|
player_inv[1] = game.players[players[i].index].get_inventory(defines.inventory.character_main)
|
|
|
|
player_inv[2] = game.players[players[i].index].get_inventory(defines.inventory.character_armor)
|
|
|
|
player_inv[3] = game.players[players[i].index].get_inventory(defines.inventory.character_guns)
|
|
|
|
player_inv[4] = game.players[players[i].index].get_inventory(defines.inventory.character_ammo)
|
|
|
|
player_inv[5] = game.players[players[i].index].get_inventory(defines.inventory.character_trash)
|
|
|
|
local e =
|
|
|
|
surface.create_entity(
|
|
|
|
{
|
|
|
|
name = 'character',
|
|
|
|
position = game.forces.player.get_spawn_position(surface),
|
|
|
|
force = 'neutral'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
local inv = e.get_inventory(defines.inventory.character_main)
|
|
|
|
for ii = 1, 5, 1 do
|
|
|
|
if player_inv[ii].valid then
|
|
|
|
for iii = 1, #player_inv[ii], 1 do
|
|
|
|
if player_inv[ii][iii].valid then
|
|
|
|
items[#items + 1] = player_inv[ii][iii]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #items > 0 then
|
|
|
|
for item = 1, #items, 1 do
|
|
|
|
if items[item].valid then
|
|
|
|
inv.insert(items[item])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
game.print({'chronosphere.message_accident'}, {r = 0.98, g = 0.66, b = 0.22})
|
|
|
|
e.die('neutral')
|
|
|
|
else
|
|
|
|
e.destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
for ii = 1, 5, 1 do
|
|
|
|
if player_inv[ii].valid then
|
|
|
|
player_inv[ii].clear()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
players[i] = nil
|
|
|
|
else
|
|
|
|
later[#later + 1] = players[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
players = {}
|
|
|
|
if #later > 0 then
|
|
|
|
for i = 1, #later, 1 do
|
|
|
|
players[#players + 1] = later[i]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-28 21:55:19 +02:00
|
|
|
end
|
|
|
|
|
2020-04-26 19:36:58 +02:00
|
|
|
function Public.loco_died()
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
local wave_defense_table = WD.get_table()
|
|
|
|
set_scores()
|
|
|
|
if not this.locomotive.valid then
|
|
|
|
wave_defense_table.game_lost = true
|
|
|
|
wave_defense_table.target = nil
|
|
|
|
game.print(grandmaster .. ' Oh noooeeeew, the void destroyed my train!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Better luck next time.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
Public.reset_map()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
this.locomotive_health = 0
|
|
|
|
this.locomotive.color = {0.49, 0, 255, 1}
|
|
|
|
rendering.set_text(this.health_text, 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health)
|
2020-05-01 01:02:56 +02:00
|
|
|
wave_defense_table.game_lost = true
|
|
|
|
wave_defense_table.target = nil
|
2020-05-06 14:59:23 +02:00
|
|
|
game.print(grandmaster .. ' Oh noooeeeew, they destroyed my train!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Better luck next time.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Game will soft-reset shortly.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
|
|
|
|
local fake_shooter =
|
|
|
|
surface.create_entity({name = 'character', position = this.locomotive.position, force = 'enemy'})
|
|
|
|
surface.create_entity(
|
|
|
|
{
|
|
|
|
name = 'atomic-rocket',
|
|
|
|
position = this.locomotive.position,
|
|
|
|
force = 'enemy',
|
|
|
|
speed = 1,
|
|
|
|
max_range = 800,
|
|
|
|
target = this.locomotive,
|
|
|
|
source = fake_shooter
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
surface.spill_item_stack(this.locomotive.position, {name = 'coin', count = 512}, false)
|
|
|
|
surface.spill_item_stack(this.locomotive_cargo.position, {name = 'coin', count = 512}, false)
|
|
|
|
this.game_reset_tick = game.tick + 1800
|
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
player.play_sound {path = 'utility/game_lost', volume_modifier = 0.75}
|
|
|
|
end
|
2020-04-26 19:36:58 +02:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local function on_entity_died(event)
|
2020-05-08 09:39:20 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
local entity = event.entity
|
|
|
|
if not entity.valid then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if entity.type == 'unit' or entity.type == 'unit-spawner' then
|
2020-05-08 09:39:20 +02:00
|
|
|
this.biters_killed = this.biters_killed + 1
|
2020-05-06 14:59:23 +02:00
|
|
|
if math_random(1, 160) == 1 then
|
|
|
|
tick_tack_trap(entity.surface, entity.position)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math.random(1, 32) == 1 then
|
|
|
|
hidden_biter(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2019-11-08 23:53:16 +01:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
if entity.name == 'mineable-wreckage' then
|
|
|
|
if math.random(1, 32) == 1 then
|
|
|
|
hidden_biter(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math.random(1, 512) == 1 then
|
|
|
|
hidden_worm(event.entity)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math_random(1, 160) == 1 then
|
|
|
|
tick_tack_trap(entity.surface, entity.position)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if entity.force.name ~= 'scrap' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local positions = {}
|
|
|
|
local r = math.ceil(entity.prototype.max_health / 32)
|
|
|
|
for x = r * -1, r, 1 do
|
|
|
|
for y = r * -1, r, 1 do
|
|
|
|
positions[#positions + 1] = {x = entity.position.x + x, y = entity.position.y + y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
positions = shuffle(positions)
|
|
|
|
for i = 1, math.ceil(entity.prototype.max_health / 32), 1 do
|
|
|
|
if not positions[i] then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if math_random(1, 3) ~= 1 then
|
|
|
|
unearthing_biters(entity.surface, positions[i], math_random(5, 10))
|
|
|
|
else
|
|
|
|
unearthing_worm(entity.surface, positions[i])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-08 23:53:16 +01:00
|
|
|
|
|
|
|
local function on_built_entity(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
if string.sub(event.created_entity.surface.name, 0, 9) ~= 'scrapyard' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
local y = event.created_entity.position.y
|
|
|
|
local ent = event.created_entity
|
|
|
|
if y >= 150 then
|
|
|
|
player.print(grandmaster .. ' I do not approve, ' .. ent.name .. ' was obliterated.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
ent.die()
|
|
|
|
return
|
|
|
|
else
|
|
|
|
for _, e in pairs(disabled_entities) do
|
|
|
|
if e == event.created_entity.name then
|
|
|
|
if y >= 0 then
|
|
|
|
ent.active = false
|
|
|
|
if event.player_index then
|
|
|
|
player.print(
|
|
|
|
grandmaster .. " Can't build here. I disabled your " .. ent.name .. '.',
|
|
|
|
{r = 1, g = 0.5, b = 0.1}
|
|
|
|
)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
end
|
|
|
|
|
2020-04-30 11:44:57 +02:00
|
|
|
local function on_research_finished(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
event.research.force.character_inventory_slots_bonus = game.forces.player.mining_drill_productivity_bonus * 50 -- +5 Slots / level
|
|
|
|
local mining_speed_bonus = game.forces.player.mining_drill_productivity_bonus * 5 -- +50% speed / level
|
|
|
|
if event.research.force.technologies['steel-axe'].researched then
|
|
|
|
mining_speed_bonus = mining_speed_bonus + 0.5
|
|
|
|
end -- +50% speed for steel-axe research
|
|
|
|
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
|
2020-04-30 11:44:57 +02:00
|
|
|
end
|
|
|
|
|
2019-11-08 23:53:16 +01:00
|
|
|
local function on_robot_built_entity(event)
|
2020-05-06 14:59:23 +02:00
|
|
|
if string.sub(event.created_entity.surface.name, 0, 9) ~= 'scrapyard' then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local y = event.created_entity.position.y
|
|
|
|
local ent = event.created_entity
|
|
|
|
if y >= 150 then
|
|
|
|
game.print(grandmaster .. ' I do not approve, ' .. ent.name .. ' was obliterated.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
ent.die()
|
|
|
|
return
|
|
|
|
else
|
|
|
|
for _, e in pairs(disabled_entities) do
|
|
|
|
if e == event.created_entity.name then
|
|
|
|
if y >= 0 then
|
|
|
|
ent.active = false
|
|
|
|
if event.player_index then
|
|
|
|
game.print(
|
|
|
|
grandmaster .. " Can't build here. I disabled your " .. ent.name .. '.',
|
|
|
|
{r = 1, g = 0.5, b = 0.1}
|
|
|
|
)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-11-08 23:53:16 +01:00
|
|
|
end
|
|
|
|
|
2019-11-07 15:38:11 +01:00
|
|
|
local on_init = function()
|
2020-05-08 09:39:20 +02:00
|
|
|
global.custom_highscore.description = 'Depth reached: '
|
2020-05-06 14:59:23 +02:00
|
|
|
game.create_force('scrap')
|
|
|
|
game.create_force('scrap_defense')
|
|
|
|
game.forces.player.set_friend('scrap', true)
|
|
|
|
game.forces.enemy.set_friend('scrap', true)
|
|
|
|
game.forces.scrap.set_friend('player', true)
|
|
|
|
game.forces.scrap.set_friend('enemy', true)
|
|
|
|
game.forces.scrap.share_chart = false
|
|
|
|
global.rocks_yield_ore_maximum_amount = 500
|
|
|
|
global.rocks_yield_ore_base_amount = 50
|
|
|
|
global.rocks_yield_ore_distance_modifier = 0.025
|
|
|
|
Public.reset_map()
|
|
|
|
local T = Map.Pop_info()
|
|
|
|
T.main_caption = 'R a i n b o w S c r a p y a r d'
|
|
|
|
T.sub_caption = ' ---defend the choo---'
|
|
|
|
T.text =
|
|
|
|
table.concat(
|
|
|
|
{
|
|
|
|
'The biters have catched the scent of fish in the cargo wagon.\n',
|
|
|
|
'Guide the choo through the black mist and protect it for as long as possible!\n',
|
|
|
|
'This will not be an easy task however,\n',
|
|
|
|
'since their strength and numbers increase over time.\n',
|
|
|
|
'\n',
|
|
|
|
'Delve deep for greater treasures, but also face increased dangers.\n',
|
|
|
|
'Mining productivity research, will overhaul your mining equipment,\n',
|
|
|
|
'reinforcing your pickaxe as well as increasing the size of your backpack.\n',
|
|
|
|
'\n',
|
|
|
|
'Scrap randomness seems to occur frequently, sometimes mining scrap\n',
|
|
|
|
'does not output scrap, weird...\n',
|
|
|
|
'\n',
|
|
|
|
"We've also noticed that solar eclipse occuring, \n",
|
|
|
|
'we have yet to solve this mystery\n',
|
|
|
|
'\n',
|
|
|
|
'Good luck, over and out!',
|
|
|
|
'\n',
|
|
|
|
'\n',
|
2020-05-09 10:04:24 +02:00
|
|
|
'\n'
|
2020-05-06 14:59:23 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
T.main_caption_color = {r = 150, g = 150, b = 0}
|
|
|
|
T.sub_caption_color = {r = 0, g = 150, b = 0}
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
Explosives.set_destructible_tile('out-of-map', 1500)
|
|
|
|
Explosives.set_destructible_tile('water', 1000)
|
|
|
|
Explosives.set_destructible_tile('water-green', 1000)
|
|
|
|
Explosives.set_destructible_tile('deepwater-green', 1000)
|
|
|
|
Explosives.set_destructible_tile('deepwater', 1000)
|
|
|
|
Explosives.set_destructible_tile('water-shallow', 1000)
|
2019-11-08 23:53:16 +01:00
|
|
|
end
|
2019-11-07 15:38:11 +01:00
|
|
|
|
2020-05-01 01:02:56 +02:00
|
|
|
local function darkness(data)
|
2020-05-06 14:59:23 +02:00
|
|
|
local rnd = math.random
|
|
|
|
local this = data.this
|
|
|
|
local surface = data.surface
|
2020-05-08 09:39:20 +02:00
|
|
|
if rnd(1, 32) == 1 then
|
|
|
|
if not this.freeze_daytime then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
game.print(grandmaster .. ' Sunlight, finally!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
surface.min_brightness = 1
|
|
|
|
surface.brightness_visual_weights = {1, 0, 0, 0}
|
2020-05-09 10:04:24 +02:00
|
|
|
surface.daytime = 1
|
2020-05-08 09:39:20 +02:00
|
|
|
surface.freeze_daytime = true
|
|
|
|
surface.solar_power_multiplier = 1
|
|
|
|
this.freeze_daytime = false
|
|
|
|
return
|
|
|
|
elseif rnd(1, 64) == 1 then
|
2020-05-06 14:59:23 +02:00
|
|
|
if this.freeze_daytime then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
game.print(grandmaster .. ' Darkness has surrounded us!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Builds some lamps!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
surface.min_brightness = 0
|
|
|
|
surface.brightness_visual_weights = {0.90, 0.90, 0.90}
|
|
|
|
surface.daytime = 0.42
|
|
|
|
surface.freeze_daytime = true
|
|
|
|
surface.solar_power_multiplier = 0
|
|
|
|
this.freeze_daytime = true
|
|
|
|
return
|
|
|
|
end
|
2020-04-30 11:44:57 +02:00
|
|
|
end
|
|
|
|
|
2020-05-01 01:02:56 +02:00
|
|
|
local function scrap_randomness(data)
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = data.this
|
|
|
|
local rnd = math.random
|
2020-05-08 09:39:20 +02:00
|
|
|
if rnd(1, 32) == 1 then
|
2020-05-06 14:59:23 +02:00
|
|
|
if this.scrap_enabled then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
this.scrap_enabled = true
|
|
|
|
game.print(grandmaster .. ' Scrap is back!', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Output from scrap is now randomized.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
return
|
2020-05-08 09:39:20 +02:00
|
|
|
elseif rnd(1, 64) == 1 then
|
|
|
|
if not this.scrap_enabled then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
this.scrap_enabled = false
|
|
|
|
game.print(grandmaster .. ' It seems that the scrap is temporarily gone.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
game.print(grandmaster .. ' Output from scrap is now only ores.', {r = 1, g = 0.5, b = 0.1})
|
|
|
|
return
|
2020-05-06 14:59:23 +02:00
|
|
|
end
|
2020-04-30 11:44:57 +02:00
|
|
|
end
|
|
|
|
|
2020-05-01 01:02:56 +02:00
|
|
|
local function transfer_pollution(data)
|
2020-05-06 14:59:23 +02:00
|
|
|
local surface = data.surface
|
|
|
|
local this = data.this
|
|
|
|
if not surface then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * global.difficulty_vote_value
|
|
|
|
game.surfaces[this.active_surface_index].pollute(this.locomotive.position, pollution)
|
|
|
|
surface.clear_pollution()
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_pre_player_left_game(event)
|
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local player = game.players[event.player_index]
|
|
|
|
if player.controller_type == defines.controllers.editor then
|
|
|
|
player.toggle_map_editor()
|
|
|
|
end
|
|
|
|
if player.character then
|
|
|
|
this.offline_players[#this.offline_players + 1] = {index = event.player_index, tick = game.tick}
|
|
|
|
end
|
2020-05-01 01:02:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local tick_minute_functions = {
|
2020-05-06 14:59:23 +02:00
|
|
|
[300 * 2 + 30 * 2] = scrap_randomness,
|
2020-05-08 09:39:20 +02:00
|
|
|
[300 * 3 + 30 * 1] = darkness,
|
|
|
|
[300 * 3 + 30 * 0] = transfer_pollution
|
2020-05-01 01:02:56 +02:00
|
|
|
}
|
|
|
|
|
2020-04-27 20:04:37 +02:00
|
|
|
local on_tick = function()
|
2020-05-06 14:59:23 +02:00
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
local surface = game.surfaces[this.active_surface_index]
|
|
|
|
local wave_defense_table = WD.get_table()
|
|
|
|
local tick = game.tick
|
|
|
|
local status = Collapse.start_now()
|
|
|
|
local key = tick % 3600
|
|
|
|
local data = {
|
|
|
|
this = this,
|
|
|
|
surface = surface
|
|
|
|
}
|
|
|
|
if not this.locomotive.valid then
|
|
|
|
Public.loco_died()
|
|
|
|
end
|
|
|
|
if status == true then
|
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
if
|
|
|
|
this.left_top.y % Terrain.level_depth == 0 and this.left_top.y < 0 and
|
|
|
|
this.left_top.y > Terrain.level_depth * -10
|
|
|
|
then
|
|
|
|
if not Collapse.start_now() then
|
|
|
|
Collapse.start_now(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::continue::
|
|
|
|
if game.tick % 30 == 0 then
|
2020-05-08 09:39:20 +02:00
|
|
|
for _, player in pairs(game.connected_players) do
|
|
|
|
update_gui(player)
|
|
|
|
end
|
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
if game.tick % 1800 == 0 then
|
|
|
|
local position = surface.find_non_colliding_position('stone-furnace', Collapse.get_position(), 128, 1)
|
|
|
|
if position then
|
|
|
|
wave_defense_table.spawn_position = position
|
|
|
|
end
|
|
|
|
offline_players()
|
|
|
|
set_scores()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if tick_minute_functions[key] then
|
|
|
|
tick_minute_functions[key](data)
|
|
|
|
end
|
2020-05-08 09:39:20 +02:00
|
|
|
--if this.randomness_tick then
|
|
|
|
-- if this.randomness_tick < game.tick then
|
|
|
|
-- this.randomness_tick = game.tick + 1800
|
|
|
|
-- scrap_randomness(this)
|
|
|
|
-- darkness(this)
|
|
|
|
-- end
|
|
|
|
--end
|
2020-05-06 14:59:23 +02:00
|
|
|
|
|
|
|
if this.game_reset_tick then
|
|
|
|
if this.game_reset_tick < game.tick then
|
|
|
|
this.game_reset_tick = nil
|
|
|
|
Public.reset_map()
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
2020-04-27 20:04:37 +02:00
|
|
|
end
|
|
|
|
|
2020-04-30 14:48:40 +02:00
|
|
|
commands.add_command(
|
|
|
|
'rainbow_mode',
|
|
|
|
'This will prevent new tiles from spawning when walking',
|
2020-05-01 01:02:56 +02:00
|
|
|
function()
|
2020-05-06 14:59:23 +02:00
|
|
|
local player = game.player
|
|
|
|
local this = Scrap_table.get_table()
|
|
|
|
if player and player.valid then
|
|
|
|
if this.players[player.index].tiles_enabled == false then
|
|
|
|
this.players[player.index].tiles_enabled = true
|
|
|
|
player.print('Rainbow mode: ON', Color.green)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if this.players[player.index].tiles_enabled == true then
|
|
|
|
this.players[player.index].tiles_enabled = false
|
|
|
|
player.print('Rainbow mode: OFF', Color.warning)
|
2020-04-30 11:44:57 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-06 14:59:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if _DEBUG then
|
|
|
|
commands.add_command(
|
|
|
|
'reset_game',
|
|
|
|
'Debug only, reset the game!',
|
|
|
|
function()
|
|
|
|
local player = game.player
|
|
|
|
|
|
|
|
if player then
|
|
|
|
if player ~= nil then
|
|
|
|
if not player.admin then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Public.reset_map()
|
|
|
|
end
|
|
|
|
)
|
2020-04-27 20:04:37 +02:00
|
|
|
end
|
|
|
|
|
2020-04-30 14:48:40 +02:00
|
|
|
Event.on_nth_tick(10, on_tick)
|
2019-11-07 15:38:11 +01:00
|
|
|
Event.on_init(on_init)
|
|
|
|
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
|
|
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
2019-11-07 21:24:58 +01:00
|
|
|
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
2020-04-28 21:55:19 +02:00
|
|
|
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
|
2019-11-07 15:38:11 +01:00
|
|
|
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
|
|
|
Event.add(defines.events.on_entity_died, on_entity_died)
|
2019-11-08 23:53:16 +01:00
|
|
|
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
|
|
|
Event.add(defines.events.on_built_entity, on_built_entity)
|
2019-11-07 15:38:11 +01:00
|
|
|
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
2020-04-30 11:44:57 +02:00
|
|
|
Event.add(defines.events.on_research_finished, on_research_finished)
|
2020-05-06 14:59:23 +02:00
|
|
|
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
|
2019-11-07 15:38:11 +01:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
require 'maps.scrapyard.mineable_wreckage_yields_scrap'
|
|
|
|
require 'maps.scrapyard.balance'
|
2020-04-28 21:55:19 +02:00
|
|
|
|
2020-05-06 14:59:23 +02:00
|
|
|
return Public
|