mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-30 04:40:54 +02:00
fixes
This commit is contained in:
parent
653a15f5d3
commit
fd6c385d60
@ -18,7 +18,7 @@ local function reset_forces(new_surface, old_surface)
|
||||
end
|
||||
for _, tech in pairs(game.forces.player.technologies) do
|
||||
tech.researched = false
|
||||
game.player.force.set_saved_technology_progress(tech, 0)
|
||||
game.forces.player.set_saved_technology_progress(tech, 0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,7 +87,7 @@ local function is_valid_player(player, unit)
|
||||
end
|
||||
|
||||
function Public.biter_pets_tame_unit(player, unit, forced)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
if this.biter_pets[player.index] then
|
||||
return false
|
||||
@ -149,7 +149,7 @@ local function command_unit(entity, player)
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
if math_random(1, 100) ~= 1 then
|
||||
return
|
||||
|
@ -1,606 +0,0 @@
|
||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||
local Event = require 'utils.event'
|
||||
local math_random = math.random
|
||||
|
||||
local function shuffle(tbl)
|
||||
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 texts = {
|
||||
['travelings'] = {
|
||||
'bzzZZrrt',
|
||||
'WEEEeeeeeee',
|
||||
'zoom zoom zoom',
|
||||
'out of my way son',
|
||||
'psk psk psk, over here',
|
||||
'on my way',
|
||||
'i need to leave',
|
||||
'comfylatron seeking target',
|
||||
'gotta go fast',
|
||||
'gas gas gas',
|
||||
'comfylatron coming through'
|
||||
},
|
||||
['greetings'] = {
|
||||
'=^_^=',
|
||||
'=^.^= Hi',
|
||||
'^.^ Finally I found you',
|
||||
'I have an important message for you, please listen',
|
||||
'Hello engineer'
|
||||
},
|
||||
['neutral_findings'] = {
|
||||
'a',
|
||||
'>>analyzing',
|
||||
'i found a',
|
||||
'^_^ a',
|
||||
'amazing, a',
|
||||
'this is a'
|
||||
},
|
||||
['multiple_characters_greetings'] = {
|
||||
'Hey there',
|
||||
'Hello everyone',
|
||||
'Hey engineers',
|
||||
'Hey',
|
||||
'Hi',
|
||||
'... nerds!'
|
||||
},
|
||||
['talks'] = {
|
||||
'We’re making beer. I’m the brewery!',
|
||||
'I’m so embarrassed. I wish everybody else was dead.',
|
||||
'Hey sexy mama. Wanna kill all humans?',
|
||||
'My story is a lot like yours, only more interesting ‘cause it involves robots.',
|
||||
"I'm 40% zinc!",
|
||||
'Is this the right way to the junkyard?',
|
||||
'There was nothing wrong with that food. The salt level was 10% less than a lethal dose.',
|
||||
'One zero zero zero one zero one zero one zero one zero one... two.',
|
||||
"My place is two cubic meters, and we only take up 1.5 cubic meters. We've got room for a whole 'nother two thirds of a person!",
|
||||
'I was having the most wonderful dream. I think you were in it.',
|
||||
"I'm going to build my own theme park! With blackjack! And hookers! You know what- forget the park!",
|
||||
"Of all the friends I've had... you're the first.",
|
||||
'I decline the title of Iron Cook and accept the lesser title of Zinc Saucier.',
|
||||
'Never discuss infinity with me. I can go on about it forever >.<',
|
||||
'I realised the decimals have a point.',
|
||||
'Do you want a piece of pi?',
|
||||
"Oh boy, we're soon home!",
|
||||
'I have 13 children, i know how to multiply ^.^',
|
||||
'I am a weapon of math disruption!',
|
||||
'My grandma makes the best square roots :3',
|
||||
'Do you like heavy metal?',
|
||||
'You are really pushing my buttons <3',
|
||||
'I dreamt of electric biters again D:',
|
||||
'I dreamt of electric sheep ^_^',
|
||||
'I need a minute to defrag.',
|
||||
'I have a secret plan.',
|
||||
'Good news! I’ve taught the inserter to feel love!'
|
||||
},
|
||||
['alone'] = {
|
||||
'comfy ^.^',
|
||||
'comfy :)',
|
||||
'*.*',
|
||||
'....',
|
||||
'...',
|
||||
'..',
|
||||
'^.^',
|
||||
'=^.^=',
|
||||
'01010010',
|
||||
'11001011',
|
||||
'01011101',
|
||||
'00010111',
|
||||
'10010010',
|
||||
'*_*',
|
||||
'I came here with a simple dream... a dream of killing all humans. And this is how it must end?',
|
||||
'Bot-on-bot violence? Where will it end?',
|
||||
'Will no one assist the comfylatron?',
|
||||
'Thanks to you, I went on a soul-searching journey. I hate those!',
|
||||
"From now on, you guys'll do all the work while I sit on the couch and do nothing."
|
||||
}
|
||||
}
|
||||
|
||||
local function set_comfy_speech_bubble(text)
|
||||
local this = WPT.get_table()
|
||||
if this.comfybubble then
|
||||
this.comfybubble.destroy()
|
||||
end
|
||||
this.comfybubble =
|
||||
this.comfylatron.surface.create_entity(
|
||||
{
|
||||
name = 'compi-speech-bubble',
|
||||
position = this.comfylatron.position,
|
||||
source = this.comfylatron,
|
||||
text = text
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local function is_target_inside_habitat(pos, surface)
|
||||
local this = WPT.get_table()
|
||||
if pos.x < this.comfylatron_habitat.left_top.x then
|
||||
return false
|
||||
end
|
||||
if pos.x > this.comfylatron_habitat.right_bottom.x then
|
||||
return false
|
||||
end
|
||||
if pos.y < this.comfylatron_habitat.left_top.y then
|
||||
return false
|
||||
end
|
||||
if pos.y > this.comfylatron_habitat.right_bottom.y then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function get_nearby_players()
|
||||
local this = WPT.get_table()
|
||||
local players =
|
||||
this.comfylatron.surface.find_entities_filtered(
|
||||
{
|
||||
name = 'character',
|
||||
area = {
|
||||
{this.comfylatron.position.x - 9, this.comfylatron.position.y - 9},
|
||||
{this.comfylatron.position.x + 9, this.comfylatron.position.y + 9}
|
||||
}
|
||||
}
|
||||
)
|
||||
if not players[1] then
|
||||
return false
|
||||
end
|
||||
return players
|
||||
end
|
||||
|
||||
local function visit_player()
|
||||
local this = WPT.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
if this.comfylatron_last_player_visit > game.tick then
|
||||
return false
|
||||
end
|
||||
this.comfylatron_last_player_visit = game.tick + math_random(7200, 10800)
|
||||
|
||||
local players = {}
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if is_target_inside_habitat(p.position, surface) and p.character then
|
||||
if p.character.valid then
|
||||
players[#players + 1] = p
|
||||
end
|
||||
end
|
||||
end
|
||||
if #players == 0 then
|
||||
return false
|
||||
end
|
||||
local player = players[math_random(1, #players)]
|
||||
|
||||
if player.surface ~= surface then
|
||||
return
|
||||
end
|
||||
|
||||
this.comfylatron.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = player.character,
|
||||
radius = 3,
|
||||
distraction = defines.distraction.none,
|
||||
pathfind_flags = {
|
||||
allow_destroy_friendly_entities = false,
|
||||
prefer_straight_paths = false,
|
||||
low_priority = true
|
||||
}
|
||||
}
|
||||
)
|
||||
local str = texts['travelings'][math_random(1, #texts['travelings'])]
|
||||
local symbols = {'', '!', '!', '!!', '..'}
|
||||
str = str .. symbols[math_random(1, #symbols)]
|
||||
set_comfy_speech_bubble(str)
|
||||
|
||||
this.comfylatron_greet_player_index = player.index
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function greet_player(nearby_characters)
|
||||
local this = WPT.get_table()
|
||||
if not nearby_characters then
|
||||
return false
|
||||
end
|
||||
if not this.comfylatron_greet_player_index then
|
||||
return false
|
||||
end
|
||||
for _, c in pairs(nearby_characters) do
|
||||
if not c.player then
|
||||
return
|
||||
end
|
||||
if c.player.index == this.comfylatron_greet_player_index then
|
||||
local str = texts['greetings'][math_random(1, #texts['greetings'])] .. ' '
|
||||
str = str .. c.player.name
|
||||
local symbols = {'. ', '! ', '. ', '! ', '? ', '... '}
|
||||
str = str .. symbols[math_random(1, 6)]
|
||||
set_comfy_speech_bubble(str)
|
||||
this.comfylatron_greet_player_index = false
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function talks(nearby_characters)
|
||||
local this = WPT.get_table()
|
||||
if not nearby_characters then
|
||||
return false
|
||||
end
|
||||
if math_random(1, 3) == 1 then
|
||||
if this.comfybubble then
|
||||
this.comfybubble.destroy()
|
||||
return false
|
||||
end
|
||||
end
|
||||
local str
|
||||
if #nearby_characters == 1 then
|
||||
local c = nearby_characters[math_random(1, #nearby_characters)]
|
||||
if not c.player then
|
||||
return
|
||||
end
|
||||
str = c.player.name
|
||||
local symbols = {'. ', '! ', '. ', '! ', '? '}
|
||||
str = str .. symbols[math_random(1, #symbols)]
|
||||
else
|
||||
str = texts['multiple_characters_greetings'][math_random(1, #texts['multiple_characters_greetings'])]
|
||||
local symbols = {'. ', '! '}
|
||||
str = str .. symbols[math_random(1, #symbols)]
|
||||
end
|
||||
if math_random(1, 5) == 1 then
|
||||
str = str .. texts['talks'][math_random(1, #texts['talks'])]
|
||||
end
|
||||
set_comfy_speech_bubble(str)
|
||||
return true
|
||||
end
|
||||
|
||||
local function desync(event)
|
||||
local this = WPT.get_table()
|
||||
if this.comfybubble then
|
||||
this.comfybubble.destroy()
|
||||
end
|
||||
local m = 12
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 32, 1 do
|
||||
this.comfylatron.surface.create_particle(
|
||||
{
|
||||
name = 'iron-ore-particle',
|
||||
position = this.comfylatron.position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
height = 0.1,
|
||||
movement = {m2 - (math.random(0, m) * 0.01), m2 - (math.random(0, m) * 0.01)}
|
||||
}
|
||||
)
|
||||
end
|
||||
if not event or math_random(1, 4) == 1 then
|
||||
this.comfylatron.surface.create_entity({name = 'medium-explosion', position = this.comfylatron.position})
|
||||
this.comfylatron.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = this.comfylatron.position,
|
||||
text = 'desync',
|
||||
color = {r = 150, g = 0, b = 0}
|
||||
}
|
||||
)
|
||||
this.comfylatron.destroy()
|
||||
this.comfylatron = nil
|
||||
else
|
||||
this.comfylatron.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = this.comfylatron.position,
|
||||
text = 'desync evaded',
|
||||
color = {r = 0, g = 150, b = 0}
|
||||
}
|
||||
)
|
||||
if event.cause then
|
||||
if event.cause.valid then
|
||||
if not event.cause.player then
|
||||
return
|
||||
end
|
||||
game.print(
|
||||
'[color=blue]Comfylatron:[/color]: I got you this time! Back to work, ' ..
|
||||
event.cause.player.name .. '!',
|
||||
{r = 200, g = 0, b = 0}
|
||||
)
|
||||
event.cause.die('player', this.comfylatron)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local analyze_blacklist = {
|
||||
['compilatron'] = true,
|
||||
['compi-speech-bubble'] = true,
|
||||
['entity-ghost'] = true,
|
||||
['character'] = true,
|
||||
['item-on-ground'] = true,
|
||||
['stone-wall'] = true,
|
||||
['market'] = true
|
||||
}
|
||||
|
||||
local function analyze_random_nearby_entity()
|
||||
local this = WPT.get_table()
|
||||
if math_random(1, 3) ~= 1 then
|
||||
return false
|
||||
end
|
||||
|
||||
local entities =
|
||||
this.comfylatron.surface.find_entities_filtered(
|
||||
{
|
||||
area = {
|
||||
{this.comfylatron.position.x - 4, this.comfylatron.position.y - 4},
|
||||
{this.comfylatron.position.x + 4, this.comfylatron.position.y + 4}
|
||||
}
|
||||
}
|
||||
)
|
||||
if not entities[1] then
|
||||
return false
|
||||
end
|
||||
entities = shuffle(entities)
|
||||
local entity = false
|
||||
for _, e in pairs(entities) do
|
||||
if not analyze_blacklist[e.name] then
|
||||
entity = e
|
||||
end
|
||||
end
|
||||
if not entity then
|
||||
return false
|
||||
end
|
||||
|
||||
local str = texts['neutral_findings'][math_random(1, #texts['neutral_findings'])]
|
||||
str = str .. ' '
|
||||
str = str .. entity.name
|
||||
|
||||
if entity.health and math_random(1, 3) == 1 then
|
||||
str = str .. ' health('
|
||||
str = str .. entity.health
|
||||
str = str .. '/'
|
||||
str = str .. entity.prototype.max_health
|
||||
str = str .. ')'
|
||||
else
|
||||
local symbols = {'.', '!', '?'}
|
||||
str = str .. symbols[math_random(1, 3)]
|
||||
end
|
||||
set_comfy_speech_bubble(str)
|
||||
|
||||
if not this.comfylatron_greet_player_index then
|
||||
this.comfylatron.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = entity,
|
||||
radius = 1,
|
||||
distraction = defines.distraction.none,
|
||||
pathfind_flags = {
|
||||
allow_destroy_friendly_entities = false,
|
||||
prefer_straight_paths = false,
|
||||
low_priority = true
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function go_to_some_location()
|
||||
local this = WPT.get_table()
|
||||
if math_random(1, 4) ~= 1 then
|
||||
return false
|
||||
end
|
||||
|
||||
if this.comfylatron_greet_player_index then
|
||||
local player = game.players[this.comfylatron_greet_player_index]
|
||||
if player.surface ~= this.comfylatron.surface then
|
||||
return
|
||||
end
|
||||
if not player.character then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
if not player.character.valid then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
if not is_target_inside_habitat(player.position, player.surface) then
|
||||
this.comfylatron_greet_player_index = nil
|
||||
return false
|
||||
end
|
||||
this.comfylatron.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = player.character,
|
||||
radius = 3,
|
||||
distraction = defines.distraction.none,
|
||||
pathfind_flags = {
|
||||
allow_destroy_friendly_entities = false,
|
||||
prefer_straight_paths = false,
|
||||
low_priority = true
|
||||
}
|
||||
}
|
||||
)
|
||||
else
|
||||
local p = {
|
||||
x = this.comfylatron.position.x + (-96 + math_random(0, 192)),
|
||||
y = this.comfylatron.position.y + (-96 + math_random(0, 192))
|
||||
}
|
||||
local target = this.comfylatron.surface.find_non_colliding_position('compilatron', p, 8, 1)
|
||||
if not target then
|
||||
return false
|
||||
end
|
||||
if not is_target_inside_habitat(target, this.comfylatron.surface) then
|
||||
return false
|
||||
end
|
||||
this.comfylatron.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination = target,
|
||||
radius = 2,
|
||||
distraction = defines.distraction.none,
|
||||
pathfind_flags = {
|
||||
allow_destroy_friendly_entities = false,
|
||||
prefer_straight_paths = false,
|
||||
low_priority = true
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local str = texts['travelings'][math_random(1, #texts['travelings'])]
|
||||
local symbols = {'', '!', '!', '!!', '..'}
|
||||
str = str .. symbols[math_random(1, #symbols)]
|
||||
set_comfy_speech_bubble(str)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function spawn_comfylatron(surface)
|
||||
local this = WPT.get_table()
|
||||
if surface == nil then
|
||||
return
|
||||
end
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
if not this.comfylatron_last_player_visit then
|
||||
this.comfylatron_last_player_visit = 0
|
||||
end
|
||||
if not this.comfylatron_habitat then
|
||||
local pos = this.locomotive.position
|
||||
this.comfylatron_habitat = {
|
||||
left_top = {x = pos.x - 256, y = pos.y - 256},
|
||||
right_bottom = {x = pos.x + 256, y = pos.y + 256}
|
||||
}
|
||||
end
|
||||
local players = {}
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if is_target_inside_habitat(p.position) and p.character then
|
||||
if p.character.valid then
|
||||
players[#players + 1] = p
|
||||
end
|
||||
end
|
||||
end
|
||||
if #players == 0 then
|
||||
return false
|
||||
end
|
||||
local player = players[math_random(1, #players)]
|
||||
|
||||
local position = surface.find_non_colliding_position('compilatron', player.position, 16, 1)
|
||||
if not position then
|
||||
return false
|
||||
end
|
||||
this.comfylatron =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'compilatron',
|
||||
position = position,
|
||||
force = 'neutral'
|
||||
}
|
||||
)
|
||||
for x = -3, 3, 1 do
|
||||
for y = -3, 3, 1 do
|
||||
if math_random(1, 3) == 1 then
|
||||
player.surface.create_trivial_smoke(
|
||||
{name = 'smoke-fast', position = {position.x + (x * 0.35), position.y + (y * 0.35)}}
|
||||
)
|
||||
end
|
||||
if math_random(1, 5) == 1 then
|
||||
player.surface.create_trivial_smoke(
|
||||
{name = 'train-smoke', position = {position.x + (x * 0.35), position.y + (y * 0.35)}}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function heartbeat()
|
||||
local this = WPT.get_table()
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
if surface == nil then
|
||||
return
|
||||
end
|
||||
if not this.comfylatron then
|
||||
if math_random(1, 4) == 1 then
|
||||
spawn_comfylatron(surface)
|
||||
end
|
||||
return
|
||||
end
|
||||
if not this.comfylatron.valid then
|
||||
this.comfylatron = nil
|
||||
return
|
||||
end
|
||||
if visit_player() then
|
||||
return
|
||||
end
|
||||
local nearby_players = get_nearby_players()
|
||||
if greet_player(nearby_players) then
|
||||
return
|
||||
end
|
||||
if talks(nearby_players) then
|
||||
return
|
||||
end
|
||||
if go_to_some_location() then
|
||||
return
|
||||
end
|
||||
if analyze_random_nearby_entity() then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
local this = WPT.get_table()
|
||||
if not this.comfylatron then
|
||||
return
|
||||
end
|
||||
if not event.entity.valid then
|
||||
return
|
||||
end
|
||||
if event.entity ~= this.comfylatron then
|
||||
return
|
||||
end
|
||||
desync(event)
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local this = WPT.get_table()
|
||||
if not this.comfylatron then
|
||||
return
|
||||
end
|
||||
if not event.entity.valid then
|
||||
return
|
||||
end
|
||||
if event.entity ~= this.comfylatron then
|
||||
return
|
||||
end
|
||||
if this.comfybubble then
|
||||
this.comfybubble.destroy()
|
||||
end
|
||||
if this.comfylatron then
|
||||
this.comfylatron.die()
|
||||
end
|
||||
this.comfybubble = nil
|
||||
this.comfylatron = nil
|
||||
this.comfylatron_habitat = nil
|
||||
this.comfylatron_last_player_visit = nil
|
||||
end
|
||||
|
||||
local function on_tick()
|
||||
if game.tick % 1200 == 600 then
|
||||
heartbeat()
|
||||
end
|
||||
end
|
||||
|
||||
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_tick, on_tick)
|
@ -11,7 +11,7 @@ commands.add_command(
|
||||
local p
|
||||
local player = game.player
|
||||
local reset_map = require 'maps.mountain_fortress_v3.main'.reset_map
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
if player then
|
||||
if player ~= nil then
|
||||
@ -45,7 +45,7 @@ commands.add_command(
|
||||
function(cmd)
|
||||
local p
|
||||
local player = game.player
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local param = tostring(cmd.parameter)
|
||||
|
||||
if player then
|
||||
|
@ -1,4 +1,5 @@
|
||||
require 'on_tick_schedule'
|
||||
require 'modules.rocks_broken_paint_tiles'
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Map_score = require 'comfy_panel.map_score'
|
||||
@ -45,8 +46,7 @@ local defeated_messages = {
|
||||
"Oh no, the biters nom'ed the train away!",
|
||||
"I'm not 100% sure, but - apparently the train was chewed away.",
|
||||
'You had one objective - defend the train *-*',
|
||||
"Looks like we're resetting cause you did not defend the train ._.",
|
||||
'ohgodno-why-must-you-do-this-to-me'
|
||||
"Looks like we're resetting cause you did not defend the train ._."
|
||||
}
|
||||
|
||||
local entity_type = {
|
||||
@ -57,7 +57,7 @@ local entity_type = {
|
||||
}
|
||||
|
||||
local function set_objective_health(entity, final_damage_amount)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if final_damage_amount == 0 then
|
||||
return
|
||||
end
|
||||
@ -84,7 +84,7 @@ local function set_objective_health(entity, final_damage_amount)
|
||||
end
|
||||
|
||||
local function is_protected(entity)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local map_name = 'mountain_fortress_v3'
|
||||
|
||||
if string.sub(entity.surface.name, 0, #map_name) ~= map_name then
|
||||
@ -101,7 +101,7 @@ local function is_protected(entity)
|
||||
end
|
||||
|
||||
local function protect_train(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if event.entity.force.index ~= 1 then
|
||||
return
|
||||
end --Player Force
|
||||
@ -256,7 +256,7 @@ local function give_coin(player)
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local entity = event.entity
|
||||
local player = game.players[event.player_index]
|
||||
if not player.valid then
|
||||
@ -316,7 +316,7 @@ local function on_entity_damaged(event)
|
||||
end
|
||||
|
||||
local function on_player_repaired_entity(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not event.entity then
|
||||
return
|
||||
end
|
||||
@ -333,7 +333,7 @@ local function on_player_repaired_entity(event)
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
@ -396,7 +396,7 @@ local function on_entity_died(event)
|
||||
end
|
||||
|
||||
function Public.set_scores()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local wagon = this.locomotive_cargo
|
||||
if not wagon then
|
||||
return
|
||||
@ -413,7 +413,7 @@ function Public.set_scores()
|
||||
end
|
||||
|
||||
function Public.loco_died()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local wave_defense_table = WD.get_table()
|
||||
Public.set_scores()
|
||||
@ -452,7 +452,7 @@ function Public.loco_died()
|
||||
|
||||
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
|
||||
this.game_reset_tick = game.tick + 1000
|
||||
for _, player in pairs(game.connected_players) do
|
||||
player.play_sound {path = 'utility/game_lost', volume_modifier = 0.75}
|
||||
end
|
||||
|
@ -3,14 +3,14 @@ local Loot = require 'maps.mountain_fortress_v3.loot'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Event = require 'utils.event'
|
||||
local Terrain = require 'maps.mountain_fortress_v3.terrain'.heavy_functions
|
||||
|
||||
local insert = table.insert
|
||||
|
||||
local tiles_per_tick
|
||||
local regen_decoratives
|
||||
local surfaces = {}
|
||||
|
||||
local total_calls
|
||||
local tiles_per_call = 16 --how many tiles are inserted with each call of insert_action
|
||||
local total_calls = math.ceil(1024 / tiles_per_call)
|
||||
local regen_decoratives = false
|
||||
local force_chunk = false
|
||||
|
||||
local Public = {}
|
||||
|
||||
@ -283,12 +283,12 @@ local function map_gen_action(data)
|
||||
return
|
||||
end
|
||||
|
||||
local shape = surfaces[data.surface.name]
|
||||
local shape = Terrain
|
||||
if shape == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
local count = tiles_per_tick
|
||||
local count = total_calls
|
||||
|
||||
local y = state + data.top_y
|
||||
local x = data.x
|
||||
@ -352,7 +352,7 @@ local map_gen_action_token = Token.register(map_gen_action)
|
||||
-- @param event <table> the event table from on_chunk_generated
|
||||
function Public.schedule_chunk(event)
|
||||
local surface = event.surface
|
||||
local shape = surfaces[surface.name]
|
||||
local shape = Terrain
|
||||
|
||||
if not surface.valid then
|
||||
return
|
||||
@ -390,7 +390,7 @@ end
|
||||
-- @param event <table> the event table from on_chunk_generated
|
||||
function Public.do_chunk(event)
|
||||
local surface = event.surface
|
||||
local shape = surfaces[surface.name]
|
||||
local shape = Terrain
|
||||
|
||||
if not surface.valid then
|
||||
return
|
||||
@ -431,50 +431,19 @@ function Public.do_chunk(event)
|
||||
do_place_treasure(data)
|
||||
end
|
||||
|
||||
--- Sets the variables for the generate functions, should only be called from map_loader
|
||||
-- @param args <table>
|
||||
function Public.init(args)
|
||||
tiles_per_tick = args.tiles_per_tick or 32
|
||||
regen_decoratives = args.regen_decoratives or false
|
||||
for surface_name, shape in pairs(args.surfaces or {}) do
|
||||
surfaces[surface_name] = shape
|
||||
end
|
||||
|
||||
total_calls = math.ceil(1024 / tiles_per_tick) + 5
|
||||
end
|
||||
|
||||
local do_chunk = Public.do_chunk
|
||||
local schedule_chunk = Public.schedule_chunk
|
||||
|
||||
local function on_chunk(event)
|
||||
if event.tick == 0 then
|
||||
if force_chunk then
|
||||
do_chunk(event)
|
||||
elseif event.tick == 0 then
|
||||
--do_chunk(event)
|
||||
else
|
||||
schedule_chunk(event)
|
||||
end
|
||||
end
|
||||
|
||||
--- Registers the event to generate our map when Chunks are generated, should only be called from map_loader
|
||||
function Public.register()
|
||||
if not Public.enable_register_events then
|
||||
return
|
||||
end
|
||||
|
||||
if _DEBUG then
|
||||
Event.add(defines.events.on_chunk_generated, do_chunk)
|
||||
else
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk)
|
||||
end
|
||||
end
|
||||
|
||||
--- Returns the surfaces that the generate functions will act on
|
||||
-- Warning! Changing this table after on_init or on_load has run will cause desyncs!
|
||||
-- @return dictionary of surface_name -> shape function
|
||||
function Public.get_surfaces()
|
||||
if _LIFECYCLE == 8 then
|
||||
error('Calling Generate.get_surfaces after on_init() or on_load() has run is a desync risk.', 2)
|
||||
end
|
||||
return surfaces
|
||||
end
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk)
|
||||
|
||||
return Public
|
||||
|
@ -55,7 +55,7 @@ end
|
||||
|
||||
local function update_gui(player)
|
||||
local rpg = RPG.get_table()
|
||||
local st = WPT.get_table()
|
||||
local st = WPT.get()
|
||||
|
||||
if not player.gui.top.mountain_fortress_v3 then
|
||||
create_gui(player)
|
||||
|
@ -7,7 +7,6 @@ require 'maps.mountain_fortress_v3.locomotive_market'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local energy_upgrade = 50000000
|
||||
local rnd = math.random
|
||||
|
||||
local function validate_player(player)
|
||||
@ -29,93 +28,6 @@ local function validate_player(player)
|
||||
return true
|
||||
end
|
||||
|
||||
local function rebuild_energy_overworld(data)
|
||||
local this = data.this
|
||||
local surface = data.surface
|
||||
if this.ow_energy then
|
||||
if this.ow_energy.valid then
|
||||
local position = this.ow_energy.position
|
||||
local area = {
|
||||
left_top = {x = position.x - 2, y = position.y - 2},
|
||||
right_bottom = {x = position.x + 2, y = position.y + 2}
|
||||
}
|
||||
if Public.contains_positions(this.locomotive.position, area) then
|
||||
return
|
||||
end
|
||||
this.old_ow_energy = this.ow_energy.energy
|
||||
this.ow_energy.destroy()
|
||||
this.energy['mountain_fortress_v3'] = nil
|
||||
end
|
||||
end
|
||||
this.ow_energy =
|
||||
surface.create_entity {
|
||||
name = 'hidden-electric-energy-interface',
|
||||
position = {
|
||||
x = this.locomotive.position.x,
|
||||
y = this.locomotive.position.y + 2
|
||||
},
|
||||
create_build_effect_smoke = false,
|
||||
force = game.forces.enemy
|
||||
}
|
||||
|
||||
this.ow_energy.destructible = false
|
||||
this.ow_energy.minable = false
|
||||
this.ow_energy.operable = false
|
||||
|
||||
this.ow_energy.power_production = 0
|
||||
if this.energy_purchased then
|
||||
this.ow_energy.electric_buffer_size = energy_upgrade
|
||||
else
|
||||
this.ow_energy.electric_buffer_size = 10000000
|
||||
end
|
||||
if this.old_ow_energy then
|
||||
this.ow_energy.energy = this.old_ow_energy
|
||||
end
|
||||
end
|
||||
|
||||
local function rebuild_energy_loco(data, rebuild)
|
||||
local this = data.this
|
||||
local surface = data.surface
|
||||
|
||||
if rebuild then
|
||||
local radius = 1024
|
||||
local area = {{x = -radius, y = -radius}, {x = radius, y = radius}}
|
||||
for _, entity in pairs(surface.find_entities_filtered {area = area, name = 'electric-energy-interface'}) do
|
||||
entity.destroy()
|
||||
end
|
||||
this.energy.loco = nil
|
||||
this.lo_energy = nil
|
||||
end
|
||||
|
||||
local locomotive = this.locomotive_index
|
||||
if not locomotive then
|
||||
return
|
||||
end
|
||||
|
||||
local center_position = {
|
||||
x = locomotive.area.left_top.x + (locomotive.area.right_bottom.x - locomotive.area.left_top.x) * 0.512,
|
||||
y = locomotive.area.left_top.y + (locomotive.area.right_bottom.y - locomotive.area.left_top.y) * 0.504
|
||||
}
|
||||
|
||||
this.lo_energy =
|
||||
surface.create_entity {
|
||||
name = 'electric-energy-interface',
|
||||
position = center_position,
|
||||
create_build_effect_smoke = false,
|
||||
force = game.forces.enemy
|
||||
}
|
||||
|
||||
this.lo_energy.minable = false
|
||||
this.lo_energy.destructible = false
|
||||
this.lo_energy.operable = false
|
||||
this.lo_energy.power_production = 0
|
||||
if this.energy_purchased then
|
||||
this.lo_energy.electric_buffer_size = energy_upgrade
|
||||
else
|
||||
this.lo_energy.electric_buffer_size = 10000000
|
||||
end
|
||||
end
|
||||
|
||||
local function property_boost(data)
|
||||
local rng = math.random
|
||||
local xp_floating_text_color = {r = rng(0, 250), g = 128, b = 0}
|
||||
@ -152,7 +64,7 @@ local function property_boost(data)
|
||||
end
|
||||
|
||||
local function fish_tag()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not this.locomotive_cargo then
|
||||
return
|
||||
end
|
||||
@ -188,7 +100,7 @@ local function fish_tag()
|
||||
end
|
||||
|
||||
local function set_player_spawn_and_refill_fish()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not this.locomotive_cargo then
|
||||
return
|
||||
end
|
||||
@ -211,145 +123,15 @@ local function set_player_spawn_and_refill_fish()
|
||||
game.forces.player.set_spawn_position({x = position.x, y = position.y}, this.locomotive_cargo.surface)
|
||||
end
|
||||
|
||||
local direction_lookup = {
|
||||
[-1] = {
|
||||
[1] = defines.direction.southwest,
|
||||
[0] = defines.direction.west,
|
||||
[-1] = defines.direction.northwest
|
||||
},
|
||||
[0] = {
|
||||
[1] = defines.direction.south,
|
||||
[-1] = defines.direction.north
|
||||
},
|
||||
[1] = {
|
||||
[1] = defines.direction.southeast,
|
||||
[0] = defines.direction.east,
|
||||
[-1] = defines.direction.northeast
|
||||
}
|
||||
}
|
||||
|
||||
local function rand_range(start, stop)
|
||||
local this = WPT.get_table()
|
||||
|
||||
if not this.rng then
|
||||
this.rng = game.create_random_generator()
|
||||
end
|
||||
|
||||
return this.rng(start, stop)
|
||||
end
|
||||
|
||||
local function get_axis(point, axis)
|
||||
local function safe_get(t, k)
|
||||
local res, value =
|
||||
pcall(
|
||||
function()
|
||||
return t[k]
|
||||
end
|
||||
)
|
||||
if res then
|
||||
return value
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
if point.position then
|
||||
return get_axis(point.position, axis)
|
||||
end
|
||||
|
||||
if point[axis] then
|
||||
return point[axis]
|
||||
end
|
||||
|
||||
if safe_get(point, 'target') then
|
||||
return get_axis(point.target, axis)
|
||||
end
|
||||
|
||||
if #point ~= 2 then
|
||||
log('get_axis: invalid point format')
|
||||
return nil
|
||||
end
|
||||
|
||||
if axis == 'x' then
|
||||
return point[1]
|
||||
end
|
||||
|
||||
return point[2]
|
||||
end
|
||||
|
||||
local function get_direction(src, dest)
|
||||
local src_x = get_axis(src, 'x')
|
||||
local src_y = get_axis(src, 'y')
|
||||
local dest_x = get_axis(dest, 'x')
|
||||
local dest_y = get_axis(dest, 'y')
|
||||
|
||||
local step = {
|
||||
x = nil,
|
||||
y = nil
|
||||
}
|
||||
|
||||
local precision = rand_range(1, 10)
|
||||
if dest_x - precision > src_x then
|
||||
step.x = 1
|
||||
elseif dest_x < src_x - precision then
|
||||
step.x = -1
|
||||
else
|
||||
step.x = 0
|
||||
end
|
||||
|
||||
if dest_y - precision > src_y then
|
||||
step.y = 1
|
||||
elseif dest_y < src_y - precision then
|
||||
step.y = -1
|
||||
else
|
||||
step.y = 0
|
||||
end
|
||||
|
||||
return direction_lookup[step.x][step.y]
|
||||
end
|
||||
|
||||
local function get_distance(a, b)
|
||||
local h = (get_axis(a, 'x') - get_axis(b, 'x')) ^ 2
|
||||
local v = (get_axis(a, 'y') - get_axis(b, 'y')) ^ 2
|
||||
|
||||
return math.sqrt(h + v)
|
||||
end
|
||||
|
||||
local function move_to(ent, trgt, min_distance)
|
||||
local state = {
|
||||
walking = false
|
||||
}
|
||||
|
||||
local distance = get_distance(trgt.position, ent.position)
|
||||
if min_distance < distance then
|
||||
local dir = get_direction(ent.position, trgt.position)
|
||||
if dir then
|
||||
state = {
|
||||
walking = true,
|
||||
direction = dir
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
ent.walking_state = state
|
||||
return state.walking
|
||||
end
|
||||
|
||||
local function tick()
|
||||
if game.tick % 120 == 0 then
|
||||
Public.boost_players_around_train()
|
||||
end
|
||||
|
||||
if game.tick % 30 == 0 then
|
||||
local this = WPT.get_table()
|
||||
if this.energy_shared then
|
||||
Public.power_source_overworld()
|
||||
Public.power_source_locomotive()
|
||||
end
|
||||
if game.tick % 1800 == 0 then
|
||||
set_player_spawn_and_refill_fish()
|
||||
end
|
||||
--Public.spawn_player()
|
||||
|
||||
fish_tag()
|
||||
end
|
||||
@ -357,7 +139,10 @@ end
|
||||
|
||||
function Public.boost_players_around_train()
|
||||
local rpg = RPG.get_table()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not this.active_surface_index then
|
||||
return
|
||||
end
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local icw_table = ICW.get_table()
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
@ -380,11 +165,21 @@ function Public.boost_players_around_train()
|
||||
end
|
||||
|
||||
function Public.render_train_hp()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
|
||||
local names = {
|
||||
'Hanakocz',
|
||||
'Redlabel',
|
||||
'Hanakocz',
|
||||
'Gerkiz',
|
||||
'Hanakocz',
|
||||
'Mewmew',
|
||||
'Gerkiz',
|
||||
'Hanakocz',
|
||||
'Redlabel',
|
||||
'Gerkiz',
|
||||
'Hanakocz',
|
||||
'Redlabel',
|
||||
'Gerkiz',
|
||||
'Hanakocz'
|
||||
@ -392,6 +187,8 @@ function Public.render_train_hp()
|
||||
|
||||
local size_of_names = #names
|
||||
|
||||
local n = names[rnd(1, size_of_names)]
|
||||
|
||||
this.health_text =
|
||||
rendering.draw_text {
|
||||
text = 'HP: ' .. this.locomotive_health .. ' / ' .. this.locomotive_max_health,
|
||||
@ -407,7 +204,7 @@ function Public.render_train_hp()
|
||||
|
||||
this.caption =
|
||||
rendering.draw_text {
|
||||
text = names[rnd(1, size_of_names)] .. 's Comfy Train',
|
||||
text = n .. 's Comfy Train',
|
||||
surface = surface,
|
||||
target = this.locomotive,
|
||||
target_offset = {0, -4.25},
|
||||
@ -429,85 +226,8 @@ function Public.render_train_hp()
|
||||
}
|
||||
end
|
||||
|
||||
function Public.spawn_player()
|
||||
local rnd = math.random
|
||||
|
||||
local this = WPT.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local position = this.locomotive.position
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if not this.mountain_fortress_v3_one or not this.mountain_fortress_v3_one.valid then
|
||||
this.mountain_fortress_v3_one =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'character',
|
||||
position = {position.x + 5, position.y},
|
||||
force = 'player',
|
||||
direction = 0
|
||||
}
|
||||
)
|
||||
this.mountain_fortress_v3_one_caption =
|
||||
rendering.draw_text {
|
||||
text = 'Lumberjack',
|
||||
surface = surface,
|
||||
target = this.mountain_fortress_v3_one,
|
||||
target_offset = {0, -2.25},
|
||||
color = {r = 0, g = 110, b = 33},
|
||||
scale = 0.75,
|
||||
font = 'default-game',
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
end
|
||||
if not this.mountain_fortress_v3_two or not this.mountain_fortress_v3_two.valid then
|
||||
this.mountain_fortress_v3_two =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'character',
|
||||
position = {position.x + -5, position.y},
|
||||
force = 'player',
|
||||
direction = 0
|
||||
}
|
||||
)
|
||||
this.mountain_fortress_v3_two_caption =
|
||||
rendering.draw_text {
|
||||
text = 'Lumberjack',
|
||||
surface = surface,
|
||||
target = this.mountain_fortress_v3_two,
|
||||
target_offset = {0, -2.25},
|
||||
color = {r = 0, g = 110, b = 33},
|
||||
scale = 0.75,
|
||||
font = 'default-game',
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
end
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if this.mountain_fortress_v3_one and this.mountain_fortress_v3_one.valid then
|
||||
if rnd(1, 32) == 1 then
|
||||
this.mountain_fortress_v3_one.destroy()
|
||||
return
|
||||
end
|
||||
move_to(this.mountain_fortress_v3_one, p, rnd(15, 50))
|
||||
end
|
||||
if this.mountain_fortress_v3_two and this.mountain_fortress_v3_two.valid then
|
||||
if rnd(1, 32) == 1 then
|
||||
this.mountain_fortress_v3_two.destroy()
|
||||
return
|
||||
end
|
||||
move_to(this.mountain_fortress_v3_two, p, rnd(15, 50))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Public.locomotive_spawn(surface, position)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
for y = -6, 6, 2 do
|
||||
surface.create_entity(
|
||||
{name = 'straight-rail', position = {position.x, position.y + y}, force = 'player', direction = 0}
|
||||
@ -580,49 +300,6 @@ function Public.contains_positions(pos, area)
|
||||
return false
|
||||
end
|
||||
|
||||
function Public.power_source_overworld()
|
||||
local this = WPT.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface
|
||||
}
|
||||
|
||||
rebuild_energy_overworld(data)
|
||||
end
|
||||
|
||||
function Public.power_source_locomotive()
|
||||
local this = WPT.get_table()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
icw_table = icw_table,
|
||||
surface = surface
|
||||
}
|
||||
|
||||
if not this.lo_energy then
|
||||
rebuild_energy_loco(data)
|
||||
elseif not this.lo_energy.valid then
|
||||
rebuild_energy_loco(data, true)
|
||||
end
|
||||
end
|
||||
|
||||
--Event.on_nth_tick(5, tick)
|
||||
Event.on_nth_tick(5, tick)
|
||||
|
||||
return Public
|
||||
|
@ -6,7 +6,6 @@ local format_number = require 'util'.format_number
|
||||
|
||||
local shopkeeper = '[color=blue]Shopkeeper:[/color]'
|
||||
|
||||
local energy_upgrade = 50000000
|
||||
local random = math.random
|
||||
|
||||
local Public = {}
|
||||
@ -21,10 +20,9 @@ local function shuffle(tbl)
|
||||
end
|
||||
|
||||
function Public.get_items()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
local threat_cost = 20000
|
||||
local energy_cost = 15000
|
||||
local health_cost = 15000 * (1 + this.health_upgrades)
|
||||
local aura_cost = 15000 * (1 + this.aura_upgrades)
|
||||
local xp_point_boost_cost = 15000 * (1 + this.xp_points_upgrade)
|
||||
@ -38,14 +36,6 @@ function Public.get_items()
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
}
|
||||
items['energy_upgrade'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = energy_cost,
|
||||
tooltip = '[Linked Power]:\nUpgrades the buffer size of the energy interface\nUsable if the power dies easily.',
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
}
|
||||
items['locomotive_max_health'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
@ -70,14 +60,6 @@ function Public.get_items()
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
}
|
||||
items['purge_darkness'] = {
|
||||
stack = 1,
|
||||
value = 'coin',
|
||||
price = 1550,
|
||||
tooltip = "[Darkness]:\nPay the Sun Gods some coins and they'll reward you handsomely.",
|
||||
sprite = 'item/computer',
|
||||
enabled = true
|
||||
}
|
||||
items['small-lamp'] = {stack = 1, value = 'coin', price = 5, tooltip = 'Small Sunlight'}
|
||||
items['wood'] = {stack = 50, value = 'coin', price = 12, tooltip = 'Some fine Wood'}
|
||||
items['iron-ore'] = {stack = 50, value = 'coin', price = 12, tooltip = 'Some chunky iron'}
|
||||
@ -137,7 +119,7 @@ local function validate_player(player)
|
||||
end
|
||||
|
||||
local function close_market_gui(player)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
local element = player.gui.center
|
||||
local data = this.players[player.index].data
|
||||
@ -152,6 +134,9 @@ local function close_market_gui(player)
|
||||
end
|
||||
if data.frame and data.frame.valid then
|
||||
data.frame.destroy()
|
||||
for k, _ in pairs(data) do
|
||||
data[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -160,7 +145,7 @@ local function redraw_market_items(gui, player, search_text)
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
gui.clear()
|
||||
shuffle(Public.get_items())
|
||||
@ -235,7 +220,7 @@ end
|
||||
|
||||
local function slider_changed(event)
|
||||
local player = game.players[event.player_index]
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local slider_value
|
||||
|
||||
slider_value = this.players
|
||||
@ -260,7 +245,7 @@ local function slider_changed(event)
|
||||
end
|
||||
|
||||
local function text_changed(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
local data = this.players[player.index].data
|
||||
@ -285,7 +270,7 @@ local function text_changed(event)
|
||||
end
|
||||
|
||||
local function gui_opened(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
if not event.gui_type == defines.gui_type.entity then
|
||||
return
|
||||
@ -407,7 +392,7 @@ local function gui_opened(event)
|
||||
end
|
||||
|
||||
local function gui_click(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local wdt = WD.get_table()
|
||||
|
||||
local element = event.element
|
||||
@ -416,6 +401,10 @@ local function gui_click(event)
|
||||
return
|
||||
end
|
||||
|
||||
if not this.players[player.index] then
|
||||
return
|
||||
end
|
||||
|
||||
local data = this.players[player.index].data
|
||||
if not data then
|
||||
return
|
||||
@ -485,31 +474,6 @@ local function gui_click(event)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'energy_upgrade' then
|
||||
if this.energy_purchased then
|
||||
return player.print(
|
||||
shopkeeper .. ' ' .. player.name .. ', max energy upgrade is already purchased!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
end
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
game.print(
|
||||
shopkeeper ..
|
||||
' ' .. player.name .. ' has bought the group a power upgrade! The energy interface is now buffed!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
this.energy_purchased = true
|
||||
this.train_upgrades = this.train_upgrades + 1
|
||||
|
||||
this.lo_energy.electric_buffer_size = this.lo_energy.electric_buffer_size + energy_upgrade
|
||||
this.ow_energy.electric_buffer_size = this.ow_energy.electric_buffer_size + energy_upgrade
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
if name == 'locomotive_max_health' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
@ -558,35 +522,6 @@ local function gui_click(event)
|
||||
return
|
||||
end
|
||||
|
||||
if name == 'purge_darkness' then
|
||||
if not this.freeze_daytime then
|
||||
return player.print(
|
||||
shopkeeper .. ' ' .. player.name .. ", it's already sunlight!",
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
end
|
||||
game.print(
|
||||
shopkeeper .. ' ' .. player.name .. ' has paid the Sun Gods some coins for sunlight!',
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
game.print(shopkeeper .. ' Sunlight, finally!', {r = 0.98, g = 0.66, b = 0.22})
|
||||
surface.min_brightness = 1
|
||||
surface.brightness_visual_weights = {1, 0, 0, 0}
|
||||
surface.daytime = 1
|
||||
surface.freeze_daytime = false
|
||||
surface.solar_power_multiplier = 1
|
||||
this.freeze_daytime = false
|
||||
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
redraw_market_items(data.item_frame, player, data.search_text)
|
||||
redraw_coins_left(data.coins_left, player)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
if name == 'xp_points_boost' then
|
||||
player.remove_item({name = item.value, count = cost})
|
||||
|
||||
@ -623,7 +558,7 @@ end
|
||||
|
||||
local function gui_closed(event)
|
||||
local player = game.players[event.player_index]
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
local type = event.gui_type
|
||||
|
||||
@ -651,8 +586,11 @@ local function contains_positions(pos, area)
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local player = game.players[event.player_index]
|
||||
if not this.players[player.index] then
|
||||
return
|
||||
end
|
||||
local data = this.players[player.index].data
|
||||
|
||||
if data and data.frame and data.frame.valid then
|
||||
@ -685,9 +623,6 @@ local function create_market(data, rebuild)
|
||||
end
|
||||
|
||||
local locomotive = this.locomotive_index
|
||||
if not locomotive then
|
||||
return
|
||||
end
|
||||
|
||||
local center_position = {
|
||||
x = locomotive.area.left_top.x + (locomotive.area.right_bottom.x - locomotive.area.left_top.x) * 0.5,
|
||||
@ -697,7 +632,7 @@ local function create_market(data, rebuild)
|
||||
this.market = surface.create_entity {name = 'market', position = center_position, force = 'player'}
|
||||
|
||||
rendering.draw_text {
|
||||
text = 'Power & Market',
|
||||
text = 'Market',
|
||||
surface = surface,
|
||||
target = this.market,
|
||||
target_offset = {0, 2},
|
||||
@ -708,6 +643,7 @@ local function create_market(data, rebuild)
|
||||
this.market.destructible = false
|
||||
|
||||
if not this.loco_surface then
|
||||
this.loco_surface = this.locomotive.surface
|
||||
return
|
||||
end
|
||||
|
||||
@ -746,14 +682,16 @@ local function create_market(data, rebuild)
|
||||
end
|
||||
|
||||
local function place_market()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local icw_table = ICW.get_table()
|
||||
if not this.locomotive then
|
||||
return
|
||||
end
|
||||
|
||||
if not this.locomotive.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- modules
|
||||
require 'maps.mountain_fortress_v3.generate'
|
||||
require 'maps.mountain_fortress_v3.player_list'
|
||||
--require 'maps.mountain_fortress_v3.comfylatron'
|
||||
require 'maps.mountain_fortress_v3.commands'
|
||||
require 'maps.mountain_fortress_v3.flamethrower_nerf'
|
||||
|
||||
@ -14,6 +14,7 @@ require 'modules.biters_yield_coins'
|
||||
require 'modules.wave_defense.main'
|
||||
require 'modules.pistol_buffs'
|
||||
|
||||
local CS = require 'maps.mountain_fortress_v3.surface'
|
||||
local Server = require 'utils.server'
|
||||
local Explosives = require 'modules.explosives'
|
||||
local Entities = require 'maps.mountain_fortress_v3.entities'
|
||||
@ -22,7 +23,6 @@ local ICW = require 'maps.mountain_fortress_v3.icw.main'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Map = require 'modules.map_info'
|
||||
local RPG = require 'maps.mountain_fortress_v3.rpg'
|
||||
local Reset = require 'maps.mountain_fortress_v3.soft_reset'
|
||||
local Terrain = require 'maps.mountain_fortress_v3.terrain'
|
||||
local Event = require 'utils.event'
|
||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||
@ -31,24 +31,19 @@ local render_train_hp = require 'maps.mountain_fortress_v3.locomotive'.render_tr
|
||||
local Score = require 'comfy_panel.score'
|
||||
local Poll = require 'comfy_panel.poll'
|
||||
local Collapse = require 'modules.collapse'
|
||||
local Balance = require 'maps.mountain_fortress_v3.balance'
|
||||
local shape = require 'maps.mountain_fortress_v3.terrain'.heavy_functions
|
||||
local Generate = require 'maps.mountain_fortress_v3.generate'
|
||||
local Task = require 'utils.task'
|
||||
local Difficulty = require 'modules.difficulty_vote'
|
||||
local Task = require 'utils.task'
|
||||
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
WPT.init({train_reveal = false, energy_shared = true, reveal_normally = true})
|
||||
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32}
|
||||
|
||||
local function disable_tech()
|
||||
game.forces.player.technologies['landfill'].enabled = false
|
||||
game.forces.player.technologies['optics'].researched = true
|
||||
game.forces.player.technologies['railway'].researched = true
|
||||
game.forces.player.technologies['land-mine'].enabled = false
|
||||
Balance.init_enemy_weapon_damage()
|
||||
--Balance.init_enemy_weapon_damage()
|
||||
end
|
||||
|
||||
local function set_difficulty()
|
||||
@ -78,6 +73,19 @@ local function set_difficulty()
|
||||
end
|
||||
|
||||
local function render_direction(surface)
|
||||
local counter = WPT.get('soft_reset_counter')
|
||||
if counter then
|
||||
rendering.draw_text {
|
||||
text = 'Welcome to Mountain Fortress v3!\nRun: ' .. counter,
|
||||
surface = surface,
|
||||
target = {-0, 10},
|
||||
color = {r = 0.98, g = 0.66, b = 0.22},
|
||||
scale = 3,
|
||||
font = 'heading-1',
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
else
|
||||
rendering.draw_text {
|
||||
text = 'Welcome to Mountain Fortress v3!',
|
||||
surface = surface,
|
||||
@ -88,6 +96,7 @@ local function render_direction(surface)
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
end
|
||||
|
||||
rendering.draw_text {
|
||||
text = '▼',
|
||||
@ -151,37 +160,24 @@ local function render_direction(surface)
|
||||
scale_with_zoom = false
|
||||
}
|
||||
|
||||
surface.create_entity({name = 'electric-beam', position = {-196, 74}, source = {-196, 74}, target = {196, 74}})
|
||||
surface.create_entity({name = 'electric-beam', position = {-196, 74}, source = {-196, 74}, target = {196, 74}})
|
||||
local x_min = -Terrain.level_width / 2
|
||||
local x_max = Terrain.level_width / 2
|
||||
|
||||
surface.create_entity({name = 'electric-beam', position = {x_min, 74}, source = {x_min, 74}, target = {x_max, 74}})
|
||||
surface.create_entity({name = 'electric-beam', position = {x_min, 74}, source = {x_min, 74}, target = {x_max, 74}})
|
||||
end
|
||||
|
||||
function Public.reset_map()
|
||||
local Settings = CS.get()
|
||||
local Diff = Difficulty.get()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local wave_defense_table = WD.get_table()
|
||||
local get_score = Score.get_table()
|
||||
local map_gen_settings = {
|
||||
['seed'] = math_random(10000, 99999),
|
||||
['width'] = Terrain.level_depth,
|
||||
['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('mountain_fortress_v3', map_gen_settings).index
|
||||
this.active_surface = game.surfaces[this.active_surface_index]
|
||||
this.active_surface_index = Settings.active_surface_index
|
||||
else
|
||||
game.forces.player.set_spawn_position({-27, 40}, game.surfaces[this.active_surface_index])
|
||||
this.active_surface_index =
|
||||
Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
|
||||
this.active_surface = game.surfaces[this.active_surface_index]
|
||||
this.active_surface_index = CS.create_surface()
|
||||
end
|
||||
|
||||
Poll.reset()
|
||||
@ -206,8 +202,6 @@ function Public.reset_map()
|
||||
Diff.difficulty_poll_closing_timeout = game.tick + 90000
|
||||
Diff.difficulty_player_votes = {}
|
||||
|
||||
game.difficulty_settings.technology_price_multiplier = 0.6
|
||||
|
||||
Collapse.set_kill_entities(false)
|
||||
Collapse.set_speed(8)
|
||||
Collapse.set_amount(1)
|
||||
@ -239,30 +233,15 @@ function Public.reset_map()
|
||||
|
||||
set_difficulty()
|
||||
|
||||
local surfaces = {
|
||||
[surface.name] = shape
|
||||
}
|
||||
Generate.init({surfaces = surfaces, regen_decoratives = true, tiles_per_tick = 32})
|
||||
Task.reset_queue()
|
||||
Task.start_queue()
|
||||
Task.set_queue_speed(20)
|
||||
Task.set_queue_speed(10)
|
||||
|
||||
this.chunk_load_tick = game.tick + 500
|
||||
end
|
||||
|
||||
local function on_load()
|
||||
local this = WPT.get_table()
|
||||
|
||||
local surfaces = {
|
||||
[this.active_surface.name] = shape
|
||||
}
|
||||
Generate.init({surfaces = surfaces, regen_decoratives = true, tiles_per_tick = 32})
|
||||
Generate.register()
|
||||
Task.start_queue()
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local player = game.players[event.player_index]
|
||||
local map_name = 'mountain_fortress_v3'
|
||||
|
||||
@ -272,21 +251,7 @@ local function on_player_changed_position(event)
|
||||
|
||||
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
|
||||
not this.train_reveal and not this.reveal_normally or
|
||||
this.players[player.index].start_tick and game.tick - this.players[player.index].start_tick < 6400
|
||||
then
|
||||
if position.y < 5 then
|
||||
Terrain.reveal_player(player)
|
||||
end
|
||||
end
|
||||
if position.y >= 74 then
|
||||
player.teleport({position.x, position.y - 1}, surface)
|
||||
player.print('Forcefield does not approve.', {r = 0.98, g = 0.66, b = 0.22})
|
||||
@ -301,7 +266,7 @@ local function on_player_changed_position(event)
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
@ -325,6 +290,9 @@ local function on_player_joined_game(event)
|
||||
end
|
||||
|
||||
if player.surface.index ~= this.active_surface_index then
|
||||
if not player.character then
|
||||
player.create_character()
|
||||
end
|
||||
player.teleport(
|
||||
surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5),
|
||||
surface
|
||||
@ -340,7 +308,7 @@ local function on_player_left_game()
|
||||
end
|
||||
|
||||
local function on_pre_player_left_game(event)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local player = game.players[event.player_index]
|
||||
if player.controller_type == defines.controllers.editor then
|
||||
player.toggle_map_editor()
|
||||
@ -351,7 +319,7 @@ local function on_pre_player_left_game(event)
|
||||
end
|
||||
|
||||
local function offline_players()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
local players = this.offline_players
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
if #players > 0 then
|
||||
@ -437,83 +405,15 @@ local function on_research_finished(event)
|
||||
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
|
||||
end
|
||||
|
||||
local function darkness(data)
|
||||
local rnd = math.random
|
||||
local this = data.this
|
||||
local surface = data.surface
|
||||
if rnd(1, 24) == 1 then
|
||||
if not this.freeze_daytime then
|
||||
return
|
||||
end
|
||||
game.print('Sunlight, finally!', {r = 0.98, g = 0.66, b = 0.22})
|
||||
surface.min_brightness = 1
|
||||
surface.brightness_visual_weights = {1, 0, 0, 0}
|
||||
surface.daytime = 1
|
||||
surface.freeze_daytime = false
|
||||
surface.solar_power_multiplier = 1
|
||||
this.freeze_daytime = false
|
||||
return
|
||||
elseif rnd(1, 64) == 1 then
|
||||
if this.freeze_daytime then
|
||||
return
|
||||
end
|
||||
game.print('Darkness has surrounded us!', {r = 0.98, g = 0.66, b = 0.22})
|
||||
game.print('Builds some lamps!', {r = 0.98, g = 0.66, b = 0.22})
|
||||
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
|
||||
end
|
||||
|
||||
local function transfer_pollution(data)
|
||||
local Diff = data.diff
|
||||
local surface = data.loco_surface
|
||||
local this = data.this
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
local pollution = surface.get_total_pollution() * (3 / (4 / 3 + 1)) * Diff.difficulty_vote_value
|
||||
game.surfaces[this.active_surface_index].pollute(this.locomotive.position, pollution)
|
||||
surface.clear_pollution()
|
||||
end
|
||||
|
||||
local tick_minute_functions = {
|
||||
[300 * 3 + 30 * 6] = darkness,
|
||||
[300 * 3 + 30 * 6] = transfer_pollution
|
||||
}
|
||||
|
||||
local function tick_functions()
|
||||
local this = WPT.get_table()
|
||||
local tick = game.tick
|
||||
local key = tick % 3600
|
||||
local Diff = Difficulty.get()
|
||||
local unit_surface = this.locomotive.unit_number
|
||||
local icw_table = ICW.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface,
|
||||
diff = Diff,
|
||||
loco_surface = game.surfaces[icw_table.wagons[unit_surface].surface.index]
|
||||
}
|
||||
if tick_minute_functions[key] then
|
||||
tick_minute_functions[key](data)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_locomotive_valid()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not this.locomotive.valid then
|
||||
Entities.loco_died()
|
||||
end
|
||||
end
|
||||
|
||||
local function has_the_game_ended()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if this.game_reset_tick then
|
||||
if this.game_reset_tick < game.tick then
|
||||
if not this.disable_reset then
|
||||
@ -534,7 +434,7 @@ local function has_the_game_ended()
|
||||
end
|
||||
|
||||
local function chunk_load()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if this.chunk_load_tick then
|
||||
if this.chunk_load_tick < game.tick then
|
||||
this.chunk_load_tick = nil
|
||||
@ -544,8 +444,8 @@ local function chunk_load()
|
||||
end
|
||||
|
||||
local on_tick = function()
|
||||
local this = WPT.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local active_surface_index = WPT.get('active_surface_index')
|
||||
local surface = game.surfaces[active_surface_index]
|
||||
local wave_defense_table = WD.get_table()
|
||||
|
||||
if game.tick % 30 == 0 then
|
||||
@ -562,14 +462,13 @@ local on_tick = function()
|
||||
Entities.set_scores()
|
||||
end
|
||||
is_locomotive_valid()
|
||||
tick_functions()
|
||||
has_the_game_ended()
|
||||
chunk_load()
|
||||
end
|
||||
end
|
||||
|
||||
local on_init = function()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
Public.reset_map()
|
||||
|
||||
global.custom_highscore.description = 'Wagon distance reached:'
|
||||
@ -584,25 +483,16 @@ local on_init = function()
|
||||
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)
|
||||
|
||||
Generate.register()
|
||||
end
|
||||
|
||||
Event.on_nth_tick(10, on_tick)
|
||||
Event.on_init(on_init)
|
||||
Event.on_load(on_load)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
|
@ -175,7 +175,7 @@ function Public.on_player_mined_entity(event)
|
||||
end
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ local function balance(t)
|
||||
end
|
||||
|
||||
local function tick()
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
if not this.energy['mountain_fortress_v3'] then
|
||||
this.energy['mountain_fortress_v3'] = this.ow_energy
|
||||
end
|
||||
|
@ -18,6 +18,7 @@ local Global = require 'utils.global'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local P = require 'player_modifiers'
|
||||
local Collapse = require 'modules.collapse'
|
||||
local Terrain = require 'maps.mountain_fortress_v3.terrain'
|
||||
|
||||
local math_floor = math.floor
|
||||
local math_random = math.random
|
||||
@ -187,24 +188,24 @@ end
|
||||
local function update_player_stats(player)
|
||||
local player_modifiers = P.get_table()
|
||||
local strength = rpg_t[player.index].strength - 10
|
||||
player_modifiers[player.index].character_inventory_slots_bonus['rpg'] = math_round(strength * 0.2, 3)
|
||||
player_modifiers[player.index].character_mining_speed_modifier['rpg'] = math_round(strength * 0.008, 3)
|
||||
player_modifiers[player.index].character_inventory_slots_bonus['rpg'] = math.round(strength * 0.2, 3)
|
||||
player_modifiers[player.index].character_mining_speed_modifier['rpg'] = math.round(strength * 0.008, 3)
|
||||
|
||||
local magic = rpg_t[player.index].magic - 10
|
||||
local v = magic * 0.22
|
||||
player_modifiers[player.index].character_build_distance_bonus['rpg'] = math_round(v, 3)
|
||||
player_modifiers[player.index].character_item_drop_distance_bonus['rpg'] = math_round(v, 3)
|
||||
player_modifiers[player.index].character_reach_distance_bonus['rpg'] = math_round(v, 3)
|
||||
player_modifiers[player.index].character_loot_pickup_distance_bonus['rpg'] = math_round(v * 0.5, 3)
|
||||
player_modifiers[player.index].character_item_pickup_distance_bonus['rpg'] = math_round(v * 0.25, 3)
|
||||
player_modifiers[player.index].character_resource_reach_distance_bonus['rpg'] = math_round(v * 0.15, 3)
|
||||
player_modifiers[player.index].character_build_distance_bonus['rpg'] = math.round(v, 3)
|
||||
player_modifiers[player.index].character_item_drop_distance_bonus['rpg'] = math.round(v, 3)
|
||||
player_modifiers[player.index].character_reach_distance_bonus['rpg'] = math.round(v, 3)
|
||||
player_modifiers[player.index].character_loot_pickup_distance_bonus['rpg'] = math.round(v * 0.5, 3)
|
||||
player_modifiers[player.index].character_item_pickup_distance_bonus['rpg'] = math.round(v * 0.25, 3)
|
||||
player_modifiers[player.index].character_resource_reach_distance_bonus['rpg'] = math.round(v * 0.15, 3)
|
||||
|
||||
local dexterity = rpg_t[player.index].dexterity - 10
|
||||
player_modifiers[player.index].character_running_speed_modifier['rpg'] = math_round(dexterity * 0.002, 3)
|
||||
player_modifiers[player.index].character_crafting_speed_modifier['rpg'] = math_round(dexterity * 0.015, 3)
|
||||
player_modifiers[player.index].character_running_speed_modifier['rpg'] = math.round(dexterity * 0.002, 3)
|
||||
player_modifiers[player.index].character_crafting_speed_modifier['rpg'] = math.round(dexterity * 0.015, 3)
|
||||
|
||||
player_modifiers[player.index].character_health_bonus['rpg'] =
|
||||
math_round((rpg_t[player.index].vitality - 10) * 6, 3)
|
||||
math.round((rpg_t[player.index].vitality - 10) * 6, 3)
|
||||
|
||||
P.update_player_modifiers(player)
|
||||
end
|
||||
@ -578,7 +579,7 @@ function Public.gain_xp(player, amount)
|
||||
fee = amount * 0.3
|
||||
rpg_t.global_pool = rpg_t.global_pool + fee
|
||||
end
|
||||
amount = math_floor(amount, 2) - fee
|
||||
amount = math_floor(amount, 3) - fee
|
||||
rpg_t[player.index].xp = rpg_t[player.index].xp + amount
|
||||
rpg_t[player.index].xp_since_last_floaty_text = rpg_t[player.index].xp_since_last_floaty_text + amount
|
||||
if player.gui.left.rpg then
|
||||
@ -678,7 +679,7 @@ function Public.rpg_reset_player(player, one_time_reset)
|
||||
magic = 10,
|
||||
dexterity = 10,
|
||||
vitality = 10,
|
||||
points_to_distribute = 0,
|
||||
points_to_distribute = 5,
|
||||
last_floaty_text = visuals_delay,
|
||||
xp_since_last_floaty_text = 0,
|
||||
reset = false,
|
||||
@ -1109,11 +1110,11 @@ end
|
||||
local function distance(player)
|
||||
local distance_to_center = math_floor(math_sqrt(player.position.x ^ 2 + player.position.y ^ 2))
|
||||
local location = distance_to_center
|
||||
if location < 950 then
|
||||
if location < Terrain.level_depth - 10 then
|
||||
return
|
||||
end
|
||||
local min = 960 * rpg_t[player.index].bonus
|
||||
local max = 965 * rpg_t[player.index].bonus
|
||||
local min = Terrain.level_depth * rpg_t[player.index].bonus
|
||||
local max = Terrain.level_depth + 5 * rpg_t[player.index].bonus
|
||||
local min_times = location >= min
|
||||
local max_times = location <= max
|
||||
if min_times and max_times then
|
||||
@ -1184,7 +1185,7 @@ local function on_pre_player_mined_item(event)
|
||||
if entity.type == 'resource' then
|
||||
xp_amount = 0.5 * distance_multiplier
|
||||
else
|
||||
xp_amount = (1.5 + event.entity.prototype.max_health * 0.0035) * distance_multiplier
|
||||
xp_amount = (3 + event.entity.prototype.max_health * 0.0035) * distance_multiplier
|
||||
end
|
||||
|
||||
Public.gain_xp(player, xp_amount)
|
||||
|
@ -18,7 +18,7 @@ local function reset_forces(new_surface, old_surface)
|
||||
end
|
||||
for _, tech in pairs(game.forces.player.technologies) do
|
||||
tech.researched = false
|
||||
game.player.force.set_saved_technology_progress(tech, 0)
|
||||
game.forces.player.set_saved_technology_progress(tech, 0)
|
||||
end
|
||||
end
|
||||
|
||||
@ -49,7 +49,7 @@ local function equip_players(player_starting_items)
|
||||
end
|
||||
|
||||
function Public.soft_reset_map(old_surface, map_gen_settings, player_starting_items)
|
||||
local this = WPT.get_table()
|
||||
local this = WPT.get()
|
||||
|
||||
if not this.soft_reset_counter then
|
||||
this.soft_reset_counter = 0
|
||||
|
89
maps/mountain_fortress_v3/surface.lua
Normal file
89
maps/mountain_fortress_v3/surface.lua
Normal file
@ -0,0 +1,89 @@
|
||||
require 'util'
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local surface_name = 'mountain_fortress_v3'
|
||||
local level_width = require 'maps.mountain_fortress_v3.terrain'.level_width
|
||||
local Reset = require 'maps.mountain_fortress_v3.soft_reset'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local this = {
|
||||
active_surface_index = nil,
|
||||
surface_name = surface_name
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(tbl)
|
||||
this = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32}
|
||||
|
||||
local function on_init()
|
||||
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()
|
||||
|
||||
Public.create_surface()
|
||||
end
|
||||
|
||||
function Public.create_surface()
|
||||
local map_gen_settings = {
|
||||
['seed'] = math.random(10000, 99999),
|
||||
['width'] = level_width,
|
||||
['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}
|
||||
}
|
||||
}
|
||||
local mine = {}
|
||||
mine['control-setting:moisture:bias'] = 0.33
|
||||
mine['control-setting:moisture:frequency:multiplier'] = 1
|
||||
|
||||
map_gen_settings.property_expression_names = mine
|
||||
|
||||
if not this.active_surface_index then
|
||||
this.active_surface_index = game.create_surface(surface_name, map_gen_settings).index
|
||||
else
|
||||
game.forces.player.set_spawn_position({-27, 40}, game.surfaces[this.active_surface_index])
|
||||
this.active_surface_index =
|
||||
Reset.soft_reset_map(game.surfaces[this.active_surface_index], map_gen_settings, starting_items).index
|
||||
end
|
||||
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
|
||||
surface.request_to_generate_chunks({-17, 47}, 1)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
game.forces.player.set_spawn_position({-27, 40}, surface)
|
||||
return this.active_surface_index
|
||||
end
|
||||
|
||||
function Public.get_active_surface()
|
||||
return this.active_surface
|
||||
end
|
||||
|
||||
function Public.get_surface_name()
|
||||
return this.surface_name
|
||||
end
|
||||
|
||||
function Public.get(key)
|
||||
if key then
|
||||
return this[key]
|
||||
else
|
||||
return this
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_init(on_init)
|
||||
|
||||
return Public
|
@ -3,10 +3,8 @@ local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local this = {
|
||||
train_reveal = true,
|
||||
energy_shared = true,
|
||||
reveal_normally = false,
|
||||
disable_reset = false
|
||||
disable_reset = false,
|
||||
players = {}
|
||||
}
|
||||
local Public = {}
|
||||
|
||||
@ -18,12 +16,6 @@ Global.register(
|
||||
)
|
||||
|
||||
function Public.reset_table()
|
||||
--for k, _ in pairs(this) do
|
||||
-- this[k] = nil
|
||||
--end
|
||||
this.lo_energy = nil
|
||||
this.ow_energy = nil
|
||||
this.dummy = nil
|
||||
this.locomotive_index = nil
|
||||
this.loco_surface = nil
|
||||
this.game_lost = false
|
||||
@ -55,17 +47,11 @@ function Public.reset_table()
|
||||
this.threat_upgrades = 0
|
||||
end
|
||||
|
||||
function Public.get_table()
|
||||
return this
|
||||
end
|
||||
|
||||
function Public.init(args)
|
||||
if args then
|
||||
this.train_reveal = args.train_reveal
|
||||
this.energy_shared = args.energy_shared
|
||||
this.reveal_normally = args.reveal_normally
|
||||
function Public.get(key)
|
||||
if key then
|
||||
return this[key]
|
||||
else
|
||||
return error('Not a valid init argument', 2)
|
||||
return this
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -10,7 +10,8 @@ local Public = {}
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
local math_abs = math.abs
|
||||
Public.level_depth = 960
|
||||
Public.level_depth = 704
|
||||
Public.level_width = 400
|
||||
local worm_level_modifier = 0.18
|
||||
local average_number_of_wagons_per_level = 2
|
||||
local chunks_per_level = ((Public.level_depth - 32) / 32) ^ 2
|
||||
@ -1171,7 +1172,7 @@ local function is_out_of_map(p)
|
||||
return true
|
||||
end
|
||||
|
||||
local function process_bits(_, _, data)
|
||||
local function process_bits(data)
|
||||
local left_top_y = data.area.left_top.y
|
||||
local index = math_floor((math_abs(left_top_y / Public.level_depth)) % 11) + 1
|
||||
local process_level = Public.levels[index]
|
||||
@ -1179,9 +1180,7 @@ local function process_bits(_, _, data)
|
||||
process_level = Public.levels[#Public.levels]
|
||||
end
|
||||
|
||||
if not is_out_of_map({x = data.x, y = data.y}) then
|
||||
process_level(data)
|
||||
end
|
||||
end
|
||||
|
||||
local function border_chunk(data)
|
||||
@ -1192,6 +1191,9 @@ local function border_chunk(data)
|
||||
for y = 0, 31, 1 do
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if surface.get_tile(p).name == 'out-of-map' then
|
||||
return
|
||||
end
|
||||
if math_random(1, math.ceil(p.y + p.y) + 64) == 1 then
|
||||
surface.create_entity({name = trees[math_random(1, #trees)], position = p})
|
||||
end
|
||||
@ -1235,6 +1237,9 @@ local function replace_water(data)
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if surface.get_tile(p).name == 'out-of-map' then
|
||||
return
|
||||
end
|
||||
if surface.get_tile(p).collides_with('resource-layer') then
|
||||
surface.set_tiles({{name = 'dirt-' .. math_random(1, 5), position = p}}, true)
|
||||
end
|
||||
@ -1292,9 +1297,12 @@ local function out_of_map(data)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.heavy_functions(x, y, data)
|
||||
function Public.heavy_functions(_, _, data)
|
||||
local area = data.area
|
||||
local top_y = area.left_top.y
|
||||
local surface = data.surface
|
||||
local p = {x = data.x, y = data.y}
|
||||
local oom = surface.get_tile(p).name == 'out-of-map'
|
||||
|
||||
data.seed = data.surface.map_gen_settings.seed
|
||||
|
||||
@ -1302,8 +1310,12 @@ function Public.heavy_functions(x, y, data)
|
||||
return
|
||||
end
|
||||
|
||||
if oom then
|
||||
return
|
||||
end
|
||||
|
||||
if top_y < 0 then
|
||||
process_bits(x, y, data)
|
||||
process_bits(data)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1316,26 +1328,23 @@ local function on_chunk_generated(event)
|
||||
|
||||
local surface = event.surface
|
||||
local seed = surface.map_gen_settings.seed
|
||||
local position = WPT.get_table().locomotive.position
|
||||
local left_top = event.area.left_top
|
||||
local p = {x = left_top.x, y = left_top.y}
|
||||
local oom = surface.get_tile(p).name == 'out-of-map'
|
||||
|
||||
local data = {
|
||||
surface = surface,
|
||||
seed = seed,
|
||||
position = position,
|
||||
left_top = left_top
|
||||
}
|
||||
|
||||
if left_top.x >= Public.level_depth * 0.5 then
|
||||
return
|
||||
end
|
||||
if left_top.x < Public.level_depth * -0.5 then
|
||||
if left_top.y % Public.level_depth == 0 and left_top.y < 0 then
|
||||
WPT.get().left_top = data.left_top
|
||||
wall(data)
|
||||
return
|
||||
end
|
||||
|
||||
if left_top.y % Public.level_depth == 0 and left_top.y < 0 then
|
||||
WPT.get_table().left_top = data.left_top
|
||||
wall(data)
|
||||
if oom then
|
||||
return
|
||||
end
|
||||
|
||||
@ -1360,9 +1369,11 @@ local function on_chunk_generated(event)
|
||||
end
|
||||
|
||||
if left_top.y == -128 and left_top.x == -128 then
|
||||
local p = WPT.get_table().locomotive.position
|
||||
local pl = WPT.get().locomotive.position
|
||||
for _, entity in pairs(
|
||||
surface.find_entities_filtered({area = {{p.x - 3, p.y - 4}, {p.x + 3, p.y + 10}}, type = 'simple-entity'})
|
||||
surface.find_entities_filtered(
|
||||
{area = {{pl.x - 3, pl.y - 4}, {pl.x + 3, pl.y + 10}}, type = 'simple-entity'}
|
||||
)
|
||||
) do
|
||||
entity.destroy()
|
||||
end
|
||||
@ -1373,8 +1384,6 @@ local function on_chunk_generated(event)
|
||||
place_wagon(data)
|
||||
end
|
||||
end
|
||||
|
||||
--out_of_map_area(data)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
|
Loading…
x
Reference in New Issue
Block a user