mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-03 13:12:11 +02:00
changes and new modules
This commit is contained in:
parent
17eec0b6b2
commit
1bd500b085
@ -1,85 +1,11 @@
|
||||
local Event = require 'utils.event'
|
||||
local Public = {}
|
||||
|
||||
local function player_ammo_starting_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.25,
|
||||
['cannon-shell'] = -0.75,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.5,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.33,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = 2,
|
||||
['railgun'] = 1,
|
||||
['rocket'] = -0.75,
|
||||
['shotgun-shell'] = -0.20
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function player_gun_speed_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.55,
|
||||
['cannon-shell'] = -0.75,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.5,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.33,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = 1,
|
||||
['railgun'] = 0,
|
||||
['rocket'] = -0.75,
|
||||
['shotgun-shell'] = -0.50
|
||||
}
|
||||
return data
|
||||
end
|
||||
local function player_ammo_research_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.5,
|
||||
['cannon-shell'] = -0.85,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.6,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.5,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = -0.5,
|
||||
['railgun'] = -0.5,
|
||||
['rocket'] = -0.5,
|
||||
['shotgun-shell'] = -0.20
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function player_turrets_research_modifiers()
|
||||
local data = {
|
||||
['gun-turret'] = -0.75,
|
||||
['laser-turret'] = -0.75,
|
||||
['flamethrower-turret'] = -0.75
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function enemy_ammo_starting_modifiers()
|
||||
function Public.init_enemy_weapon_damage()
|
||||
local data = {
|
||||
['artillery-shell'] = 0,
|
||||
['biological'] = 0,
|
||||
['bullet'] = 2,
|
||||
['biological'] = 0.1,
|
||||
['bullet'] = 4,
|
||||
['cannon-shell'] = 0,
|
||||
['capsule'] = 0,
|
||||
['combat-robot-beam'] = 0,
|
||||
@ -89,50 +15,15 @@ local function enemy_ammo_starting_modifiers()
|
||||
['grenade'] = 0,
|
||||
['landmine'] = 0,
|
||||
['laser-turret'] = 0,
|
||||
['melee'] = 0,
|
||||
['melee'] = 0.5,
|
||||
['railgun'] = 0,
|
||||
['rocket'] = 0,
|
||||
['shotgun-shell'] = 0
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function enemy_ammo_evolution_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = 1,
|
||||
['biological'] = 1,
|
||||
['bullet'] = 1,
|
||||
--['cannon-shell'] = 1,
|
||||
['capsule'] = 1,
|
||||
['combat-robot-beam'] = 1,
|
||||
['combat-robot-laser'] = 1,
|
||||
['electric'] = 1,
|
||||
['flamethrower'] = 1,
|
||||
--['grenade'] = 1,
|
||||
--['landmine'] = 1,
|
||||
['laser-turret'] = 1,
|
||||
['melee'] = 1
|
||||
--['railgun'] = 1,
|
||||
--['rocket'] = 1,
|
||||
--['shotgun-shell'] = 1
|
||||
}
|
||||
return data
|
||||
end
|
||||
local e, s, sd = game.forces.enemy, game.forces.scrap, game.forces.scrap_defense
|
||||
|
||||
local function init_player_weapon_damage(force)
|
||||
for k, v in pairs(player_ammo_starting_modifiers()) do
|
||||
force.set_ammo_damage_modifier(k, v)
|
||||
end
|
||||
|
||||
for k, v in pairs(player_gun_speed_modifiers()) do
|
||||
force.set_gun_speed_modifier(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.init_enemy_weapon_damage()
|
||||
local e, s, sd = game.forces['enemy'], game.forces['scrap'], game.forces['scrap_defense']
|
||||
|
||||
for k, v in pairs(enemy_ammo_starting_modifiers()) do
|
||||
for k, v in pairs(data) do
|
||||
e.set_ammo_damage_modifier(k, v)
|
||||
s.set_ammo_damage_modifier(k, v)
|
||||
sd.set_ammo_damage_modifier(k, v)
|
||||
@ -140,63 +31,43 @@ function Public.init_enemy_weapon_damage()
|
||||
end
|
||||
|
||||
local function enemy_weapon_damage()
|
||||
if game.tick < 100 then
|
||||
goto rtn
|
||||
end
|
||||
local e, s, sd = game.forces.enemy, game.forces.scrap, game.forces.scrap_defense
|
||||
|
||||
if not global.difficulty_vote_value then
|
||||
global.difficulty_vote_value = 1
|
||||
end
|
||||
local data = {
|
||||
['artillery-shell'] = 0.5,
|
||||
['biological'] = 0.5,
|
||||
['bullet'] = 0.5,
|
||||
['capsule'] = 0.5,
|
||||
['combat-robot-beam'] = 0.5,
|
||||
['combat-robot-laser'] = 0.5,
|
||||
['electric'] = 0.5,
|
||||
['flamethrower'] = 0.5,
|
||||
--['grenade'] = 0.5,
|
||||
--['landmine'] = 0.5,
|
||||
['laser-turret'] = 0.5,
|
||||
['melee'] = 0.5
|
||||
--['railgun'] = 0.5,
|
||||
--['rocket'] = 0.5,
|
||||
--['shotgun-shell'] = 0.5
|
||||
}
|
||||
|
||||
local ef = e.evolution_factor
|
||||
|
||||
for k, v in pairs(enemy_ammo_evolution_modifiers()) do
|
||||
local base = enemy_ammo_starting_modifiers()[k]
|
||||
|
||||
local new = base + v * ef * global.difficulty_vote_value
|
||||
for k, v in pairs(data) do
|
||||
local new = global.difficulty_vote_value * v
|
||||
if new > global.difficulty_vote_value then
|
||||
new = global.difficulty_vote_value / 2
|
||||
print('Ammo modifier is now: ' .. new)
|
||||
end
|
||||
e.set_ammo_damage_modifier(k, new)
|
||||
s.set_ammo_damage_modifier(k, new)
|
||||
sd.set_ammo_damage_modifier(k, new)
|
||||
end
|
||||
|
||||
::rtn::
|
||||
end
|
||||
|
||||
local function research_finished(event)
|
||||
local r = event.research
|
||||
local p_force = r.force
|
||||
|
||||
for _, e in ipairs(r.effects) do
|
||||
local t = e.type
|
||||
|
||||
if t == 'ammo-damage' then
|
||||
local category = e.ammo_category
|
||||
local factor = player_ammo_research_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_ammo_damage_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_ammo_damage_modifier(category, current_m + factor * m)
|
||||
end
|
||||
elseif t == 'turret-attack' then
|
||||
local category = e.turret_id
|
||||
local factor = player_turrets_research_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_turret_attack_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_turret_attack_modifier(category, current_m + factor * m)
|
||||
end
|
||||
elseif t == 'gun-speed' then
|
||||
local category = e.ammo_category
|
||||
local factor = player_gun_speed_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_gun_speed_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_gun_speed_modifier(category, current_m + factor * m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_nth_tick(18000, enemy_weapon_damage)
|
||||
--Event.add(defines.events.on_research_finished, research_finished)
|
||||
Event.on_nth_tick(30, enemy_weapon_damage)
|
||||
|
||||
return Public
|
||||
|
44
maps/scrapyard/commands.lua
Normal file
44
maps/scrapyard/commands.lua
Normal file
@ -0,0 +1,44 @@
|
||||
local Color = require 'utils.color_presets'
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
|
||||
commands.add_command(
|
||||
'rainbow_mode',
|
||||
'This will prevent new tiles from spawning when walking',
|
||||
function()
|
||||
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)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
if _DEBUG then
|
||||
commands.add_command(
|
||||
'reset_game',
|
||||
'Debug only, reset the game!',
|
||||
function()
|
||||
local reset_map = require 'maps.scrapyard.main'.reset_map
|
||||
|
||||
local player = game.player
|
||||
|
||||
if player then
|
||||
if player ~= nil then
|
||||
if not player.admin then
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
reset_map()
|
||||
end
|
||||
)
|
||||
end
|
115
maps/scrapyard/corpse_util.lua
Normal file
115
maps/scrapyard/corpse_util.lua
Normal file
@ -0,0 +1,115 @@
|
||||
-- unload the normal player list
|
||||
if package.loaded['modules.corpse_markers'] then
|
||||
package.unload = 'modules.corpse_markers'
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Task = require 'utils.task'
|
||||
local Game = require 'utils.game'
|
||||
local Token = require 'utils.token'
|
||||
|
||||
local player_corpses = {}
|
||||
|
||||
Global.register(
|
||||
player_corpses,
|
||||
function(tbl)
|
||||
player_corpses = tbl
|
||||
end
|
||||
)
|
||||
|
||||
local function player_died(event)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = player.position
|
||||
local entities =
|
||||
player.surface.find_entities_filtered {
|
||||
area = {{pos.x - 0.5, pos.y - 0.5}, {pos.x + 0.5, pos.y + 0.5}},
|
||||
name = 'character-corpse'
|
||||
}
|
||||
|
||||
local tick = game.tick
|
||||
local entity
|
||||
for _, e in ipairs(entities) do
|
||||
if e.character_corpse_player_index == event.player_index and e.character_corpse_tick_of_death == tick then
|
||||
entity = e
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not entity or not entity.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local text = player.name .. "'s corpse"
|
||||
local position = entity.position
|
||||
local tag =
|
||||
player.force.add_chart_tag(
|
||||
player.surface,
|
||||
{icon = {type = 'item', name = 'power-armor-mk2'}, position = position, text = text}
|
||||
)
|
||||
|
||||
if not tag then
|
||||
return
|
||||
end
|
||||
|
||||
player_corpses[player_index * 0x100000000 + tick] = tag
|
||||
end
|
||||
|
||||
local function remove_tag(player_index, tick)
|
||||
local index = player_index * 0x100000000 + tick
|
||||
|
||||
local tag = player_corpses[index]
|
||||
player_corpses[index] = nil
|
||||
|
||||
if not tag or not tag.valid then
|
||||
return
|
||||
end
|
||||
|
||||
tag.destroy()
|
||||
end
|
||||
|
||||
local function corpse_expired(event)
|
||||
local entity = event.corpse
|
||||
|
||||
if entity and entity.valid then
|
||||
remove_tag(entity.character_corpse_player_index, entity.character_corpse_tick_of_death)
|
||||
end
|
||||
end
|
||||
|
||||
local corpse_util_mined_entity =
|
||||
Token.register(
|
||||
function(data)
|
||||
if not data.entity.valid then
|
||||
remove_tag(data.player_index, data.tick)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
local function mined_entity(event)
|
||||
local entity = event.entity
|
||||
|
||||
if not entity or not entity.valid or entity.name ~= 'character-corpse' then
|
||||
return
|
||||
end
|
||||
-- The corpse may be mined but not removed (if player doesn't have inventory space)
|
||||
-- so we wait one tick to see if the corpse is gone.
|
||||
Task.set_timeout_in_ticks(
|
||||
1,
|
||||
corpse_util_mined_entity,
|
||||
{
|
||||
entity = entity,
|
||||
player_index = entity.character_corpse_player_index,
|
||||
tick = entity.character_corpse_tick_of_death
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_player_died, player_died)
|
||||
Event.add(defines.events.on_character_corpse_expired, corpse_expired)
|
||||
Event.add(defines.events.on_pre_player_mined_item, mined_entity)
|
470
maps/scrapyard/entities.lua
Normal file
470
maps/scrapyard/entities.lua
Normal file
@ -0,0 +1,470 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local Map_score = require 'comfy_panel.map_score'
|
||||
local BiterRolls = require 'modules.wave_defense.biter_rolls'
|
||||
local unearthing_worm = require 'functions.unearthing_worm'
|
||||
local unearthing_biters = require 'functions.unearthing_biters'
|
||||
local Loot = require 'maps.scrapyard.loot'
|
||||
local Pets = require 'modules.biter_pets'
|
||||
local tick_tack_trap = require 'functions.tick_tack_trap'
|
||||
local RPG = require 'maps.scrapyard.rpg'
|
||||
local Scrap = require 'maps.scrapyard.mining_scrap'
|
||||
|
||||
-- tables
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
|
||||
-- module
|
||||
local Public = {}
|
||||
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
|
||||
local grandmaster = '[color=blue]Grandmaster:[/color]'
|
||||
|
||||
local treasure_chest_messages = {
|
||||
"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!'
|
||||
}
|
||||
|
||||
local rare_treasure_chest_messages = {
|
||||
'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!"
|
||||
}
|
||||
|
||||
local disabled_entities = {'gun-turret', 'laser-turret', 'flamethrower-turret', 'land-mine'}
|
||||
|
||||
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 function set_objective_health(entity, final_damage_amount)
|
||||
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)
|
||||
end
|
||||
|
||||
local function is_protected(entity)
|
||||
local this = Scrap_table.get_table()
|
||||
if string.sub(entity.surface.name, 0, 9) ~= 'scrapyard' then
|
||||
return true
|
||||
end
|
||||
local protected = {this.locomotive, this.locomotive_cargo}
|
||||
for i = 1, #protected do
|
||||
if protected[i] == entity then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function protect_train(event)
|
||||
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
|
||||
end
|
||||
|
||||
local function hidden_biter(entity)
|
||||
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
|
||||
end
|
||||
|
||||
local function hidden_worm(entity)
|
||||
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})
|
||||
end
|
||||
|
||||
local function hidden_biter_pet(event)
|
||||
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)
|
||||
end
|
||||
|
||||
local function hidden_treasure(event)
|
||||
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')
|
||||
end
|
||||
|
||||
local function biters_chew_rocks_faster(event)
|
||||
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
|
||||
|
||||
event.entity.health = event.entity.health - event.final_damage_amount * 2.5
|
||||
end
|
||||
|
||||
local function give_coin(player)
|
||||
player.insert({name = 'coin', count = 1})
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
Scrap.on_player_mined_entity(event)
|
||||
|
||||
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
|
||||
this.mined_scrap = this.mined_scrap + 1
|
||||
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
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
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)
|
||||
end
|
||||
|
||||
local function on_player_repaired_entity(event)
|
||||
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 on_entity_died(event)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
if entity.type == 'unit' or entity.type == 'unit-spawner' then
|
||||
this.biters_killed = this.biters_killed + 1
|
||||
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
|
||||
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
|
||||
|
||||
local function on_robot_built_entity(event)
|
||||
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
|
||||
end
|
||||
|
||||
local function on_built_entity(event)
|
||||
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
|
||||
end
|
||||
|
||||
function Public.set_scores()
|
||||
local this = Scrap_table.get_table()
|
||||
local wagon = this.locomotive_cargo
|
||||
if not wagon then
|
||||
return
|
||||
end
|
||||
if not wagon.valid then
|
||||
return
|
||||
end
|
||||
local score = math_floor(wagon.position.y * -1)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if score > Map_score.get_score(player) then
|
||||
Map_score.set_score(player, score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Public.loco_died()
|
||||
local this = Scrap_table.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
local wave_defense_table = WD.get_table()
|
||||
Public.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)
|
||||
wave_defense_table.game_lost = true
|
||||
wave_defense_table.target = nil
|
||||
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
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
|
||||
return Public
|
@ -10,6 +10,25 @@ local Public = {}
|
||||
|
||||
local energy_upgrade = 50000000
|
||||
|
||||
local function validate_player(player)
|
||||
if not player then
|
||||
return false
|
||||
end
|
||||
if not player.valid then
|
||||
return false
|
||||
end
|
||||
if not player.character then
|
||||
return false
|
||||
end
|
||||
if not player.connected then
|
||||
return false
|
||||
end
|
||||
if not game.players[player.index] then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function rebuild_energy_overworld(data)
|
||||
local this = data.this
|
||||
local surface = data.surface
|
||||
@ -36,7 +55,7 @@ local function rebuild_energy_overworld(data)
|
||||
y = this.locomotive.position.y + 2
|
||||
},
|
||||
create_build_effect_smoke = false,
|
||||
force = game.forces.neutral
|
||||
force = game.forces.enemy
|
||||
}
|
||||
|
||||
this.ow_energy.destructible = false
|
||||
@ -111,6 +130,9 @@ local function property_boost(data)
|
||||
end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if not validate_player(player) then
|
||||
return
|
||||
end
|
||||
if Public.contains_positions(player.position, area) then
|
||||
local pos = player.position
|
||||
RPG.gain_xp(player, 0.2 * rpg[player.index].bonus)
|
||||
|
@ -506,7 +506,6 @@ local function gui_click(event)
|
||||
|
||||
this.players[player.index].reveal = this.players[player.index].reveal + duration_per_charge
|
||||
|
||||
this.players[player.index].reveal = duration_per_charge
|
||||
player.print(
|
||||
grandmaster ..
|
||||
' ' .. player.name .. ' a fine choice! You can now reveal terrain when going through the black mist!',
|
||||
|
@ -1,7 +1,9 @@
|
||||
if package.loaded['comfy_panel.player_list'] then
|
||||
package.unload = 'comfy_panel.player_list'
|
||||
end
|
||||
-- modules
|
||||
require 'maps.scrapyard.player_list'
|
||||
require 'maps.scrapyard.comfylatron'
|
||||
require 'maps.scrapyard.commands'
|
||||
require 'maps.scrapyard.corpse_util'
|
||||
|
||||
require 'on_tick_schedule'
|
||||
require 'modules.dynamic_landfill'
|
||||
require 'modules.difficulty_vote'
|
||||
@ -15,25 +17,18 @@ require 'modules.spawners_contain_biters'
|
||||
require 'modules.biters_yield_coins'
|
||||
require 'modules.biter_noms_you'
|
||||
require 'modules.wave_defense.main'
|
||||
require 'maps.scrapyard.comfylatron'
|
||||
require 'modules.admins_operate_biters'
|
||||
require 'modules.pistol_buffs'
|
||||
|
||||
local Map_score = require 'comfy_panel.map_score'
|
||||
local Explosives = require 'modules.explosives'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Entities = require 'maps.scrapyard.entities'
|
||||
local update_gui = require 'maps.scrapyard.gui'
|
||||
local ICW = require 'maps.scrapyard.icw.main'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Map = require 'modules.map_info'
|
||||
local RPG = require 'maps.scrapyard.rpg'
|
||||
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'
|
||||
local Loot = require 'maps.scrapyard.loot'
|
||||
local Pets = require 'modules.biter_pets'
|
||||
local tick_tack_trap = require 'functions.tick_tack_trap'
|
||||
local Terrain = require 'maps.scrapyard.terrain'
|
||||
local Event = require 'utils.event'
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
@ -51,7 +46,6 @@ local math_floor = math.floor
|
||||
Scrap_table.init({train_reveal = true, energy_shared = true})
|
||||
|
||||
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['wood'] = 4, ['rail'] = 16, ['raw-fish'] = 2}
|
||||
local disabled_entities = {'gun-turret', 'laser-turret', 'flamethrower-turret', 'land-mine'}
|
||||
local colors = {
|
||||
'green-refined-concrete',
|
||||
'red-refined-concrete',
|
||||
@ -65,71 +59,25 @@ local disabled_tiles = {
|
||||
['red-refined-concrete'] = true,
|
||||
['blue-refined-concrete'] = true
|
||||
}
|
||||
local treasure_chest_messages = {
|
||||
"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!'
|
||||
}
|
||||
|
||||
local rare_treasure_chest_messages = {
|
||||
'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!"
|
||||
}
|
||||
|
||||
local grandmaster = '[color=blue]Grandmaster:[/color]'
|
||||
|
||||
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 function set_scores()
|
||||
local this = Scrap_table.get_table()
|
||||
local wagon = this.locomotive_cargo
|
||||
if not wagon then
|
||||
return
|
||||
end
|
||||
if not wagon.valid then
|
||||
return
|
||||
end
|
||||
local score = math_floor(wagon.position.y * -1)
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if score > Map_score.get_score(player) then
|
||||
Map_score.set_score(player, score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function set_objective_health(entity, final_damage_amount)
|
||||
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)
|
||||
local function create_forces_and_disable_tech()
|
||||
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
|
||||
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
|
||||
game.forces.player.technologies['land-mine'].enabled = false
|
||||
end
|
||||
|
||||
local function set_difficulty()
|
||||
@ -161,7 +109,6 @@ function Public.reset_map()
|
||||
local get_score = Score.get_table()
|
||||
Poll.reset()
|
||||
ICW.reset()
|
||||
Balance.init_enemy_weapon_damage()
|
||||
game.reset_time_played()
|
||||
Scrap_table.reset_table()
|
||||
wave_defense_table.math = 8
|
||||
@ -199,14 +146,6 @@ function Public.reset_map()
|
||||
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
|
||||
game.forces.player.technologies['land-mine'].enabled = false
|
||||
game.forces.player.set_spawn_position({0, 21}, surface)
|
||||
|
||||
global.friendly_fire_history = {}
|
||||
@ -240,6 +179,26 @@ function Public.reset_map()
|
||||
Locomotive(surface, {x = -18, y = 25})
|
||||
render_train_hp()
|
||||
|
||||
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}
|
||||
|
||||
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()
|
||||
|
||||
if game.forces.scrap_defense then
|
||||
Balance.init_enemy_weapon_damage()
|
||||
else
|
||||
log('scrap_defense not found')
|
||||
end
|
||||
|
||||
set_difficulty()
|
||||
|
||||
rendering.draw_text {
|
||||
text = 'Welcome to Scrapyard!',
|
||||
surface = surface,
|
||||
@ -341,67 +300,6 @@ function Public.reset_map()
|
||||
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()
|
||||
end
|
||||
|
||||
local function is_protected(entity)
|
||||
local this = Scrap_table.get_table()
|
||||
if string.sub(entity.surface.name, 0, 9) ~= 'scrapyard' then
|
||||
return true
|
||||
end
|
||||
local protected = {this.locomotive, this.locomotive_cargo}
|
||||
for i = 1, #protected do
|
||||
if protected[i] == entity then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function protect_train(event)
|
||||
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
|
||||
end
|
||||
|
||||
local function change_tile(surface, pos, steps)
|
||||
@ -426,9 +324,7 @@ local function on_player_changed_position(event)
|
||||
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
|
||||
local tile = surface.get_tile(position).name
|
||||
local disabled = disabled_tiles[tile]
|
||||
@ -440,8 +336,6 @@ local function on_player_changed_position(event)
|
||||
this.players[player.index].steps = 0
|
||||
end
|
||||
this.players[player.index].steps = this.players[player.index].steps + 1
|
||||
--end
|
||||
--end
|
||||
end
|
||||
::continue::
|
||||
if not this.train_reveal or this.players[player.index].reveal - game.tick > 0 then
|
||||
@ -462,10 +356,6 @@ local function on_player_changed_position(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_left_game()
|
||||
set_difficulty()
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local this = Scrap_table.get_table()
|
||||
local surface = game.surfaces[this.active_surface_index]
|
||||
@ -506,174 +396,18 @@ local function on_player_joined_game(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function hidden_biter(entity)
|
||||
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
|
||||
local function on_player_left_game()
|
||||
set_difficulty()
|
||||
end
|
||||
|
||||
local function hidden_worm(entity)
|
||||
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})
|
||||
end
|
||||
|
||||
local function hidden_biter_pet(event)
|
||||
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)
|
||||
end
|
||||
|
||||
local function hidden_treasure(event)
|
||||
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')
|
||||
end
|
||||
|
||||
local function biters_chew_rocks_faster(event)
|
||||
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
|
||||
|
||||
event.entity.health = event.entity.health - event.final_damage_amount * 2.5
|
||||
end
|
||||
|
||||
local function give_coin(player)
|
||||
player.insert({name = 'coin', count = 1})
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
local function on_pre_player_left_game(event)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
local entity = event.entity
|
||||
local player = game.players[event.player_index]
|
||||
if not player.valid then
|
||||
return
|
||||
if player.controller_type == defines.controllers.editor then
|
||||
player.toggle_map_editor()
|
||||
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
|
||||
this.mined_scrap = this.mined_scrap + 1
|
||||
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
|
||||
end
|
||||
|
||||
local function on_entity_damaged(event)
|
||||
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)
|
||||
end
|
||||
|
||||
local function on_player_repaired_entity(event)
|
||||
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)
|
||||
if player.character then
|
||||
this.offline_players[#this.offline_players + 1] = {index = event.player_index, tick = game.tick}
|
||||
end
|
||||
end
|
||||
|
||||
@ -745,135 +479,6 @@ local function offline_players()
|
||||
end
|
||||
end
|
||||
|
||||
function Public.loco_died()
|
||||
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)
|
||||
wave_defense_table.game_lost = true
|
||||
wave_defense_table.target = nil
|
||||
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
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local this = Scrap_table.get_table()
|
||||
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
end
|
||||
if entity.type == 'unit' or entity.type == 'unit-spawner' then
|
||||
this.biters_killed = this.biters_killed + 1
|
||||
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
|
||||
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
|
||||
|
||||
local function on_built_entity(event)
|
||||
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
|
||||
end
|
||||
|
||||
local function on_research_finished(event)
|
||||
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
|
||||
@ -883,91 +488,6 @@ local function on_research_finished(event)
|
||||
event.research.force.manual_mining_speed_modifier = mining_speed_bonus
|
||||
end
|
||||
|
||||
local function on_robot_built_entity(event)
|
||||
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
|
||||
end
|
||||
|
||||
local on_init = function()
|
||||
global.custom_highscore.description = 'Depth reached: '
|
||||
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',
|
||||
'\n'
|
||||
}
|
||||
)
|
||||
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)
|
||||
end
|
||||
|
||||
local function darkness(data)
|
||||
local rnd = math.random
|
||||
local this = data.this
|
||||
@ -1033,17 +553,6 @@ local function transfer_pollution(data)
|
||||
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
|
||||
end
|
||||
|
||||
local tick_minute_functions = {
|
||||
[300 * 2 + 30 * 2] = scrap_randomness,
|
||||
[300 * 3 + 30 * 1] = darkness,
|
||||
@ -1062,7 +571,7 @@ local on_tick = function()
|
||||
surface = surface
|
||||
}
|
||||
if not this.locomotive.valid then
|
||||
Public.loco_died()
|
||||
Entities.loco_died()
|
||||
end
|
||||
if status == true then
|
||||
goto continue
|
||||
@ -1087,19 +596,12 @@ local on_tick = function()
|
||||
wave_defense_table.spawn_position = position
|
||||
end
|
||||
offline_players()
|
||||
set_scores()
|
||||
Entities.set_scores()
|
||||
end
|
||||
end
|
||||
if tick_minute_functions[key] then
|
||||
tick_minute_functions[key](data)
|
||||
end
|
||||
--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
|
||||
|
||||
if this.game_reset_tick then
|
||||
if this.game_reset_tick < game.tick then
|
||||
@ -1110,61 +612,65 @@ local on_tick = function()
|
||||
end
|
||||
end
|
||||
|
||||
commands.add_command(
|
||||
'rainbow_mode',
|
||||
'This will prevent new tiles from spawning when walking',
|
||||
function()
|
||||
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)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
local on_init = function()
|
||||
global.custom_highscore.description = 'Depth reached: '
|
||||
create_forces_and_disable_tech()
|
||||
|
||||
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
|
||||
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',
|
||||
'\n'
|
||||
}
|
||||
)
|
||||
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)
|
||||
end
|
||||
|
||||
Event.on_nth_tick(10, on_tick)
|
||||
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)
|
||||
Event.add(defines.events.on_player_left_game, on_player_left_game)
|
||||
Event.add(defines.events.on_player_repaired_entity, on_player_repaired_entity)
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_robot_built_entity, on_robot_built_entity)
|
||||
Event.add(defines.events.on_built_entity, on_built_entity)
|
||||
Event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
Event.add(defines.events.on_research_finished, on_research_finished)
|
||||
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
|
||||
|
||||
require 'maps.scrapyard.mineable_wreckage_yields_scrap'
|
||||
require 'maps.scrapyard.balance'
|
||||
|
||||
return Public
|
||||
|
@ -1,5 +1,7 @@
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local max_spill = 60
|
||||
local math_random = math.random
|
||||
local math_floor = math.floor
|
||||
@ -213,7 +215,7 @@ local function get_amount(data)
|
||||
if not r1 or not r2 then
|
||||
return
|
||||
end
|
||||
amount = math.random(r1, r2)
|
||||
amount = math_random(r1, r2)
|
||||
else
|
||||
amount = math_floor(amount * ore_yield_amounts()[entity.name] * m)
|
||||
end
|
||||
@ -242,10 +244,6 @@ local function scrap_randomness(data)
|
||||
|
||||
local position = {x = entity.position.x, y = entity.position.y}
|
||||
|
||||
entity.destroy()
|
||||
|
||||
--local scrap_amount = math_floor(amount * 0.85) + 1
|
||||
|
||||
if scrap_amount > max_spill then
|
||||
player.surface.spill_item_stack(position, {name = scrap, count = max_spill}, true)
|
||||
scrap_amount = scrap_amount - max_spill
|
||||
@ -274,7 +272,7 @@ local function scrap_randomness(data)
|
||||
create_particles(player.surface, 'shell-particle', position, 64, {x = player.position.x, y = player.position.y})
|
||||
end
|
||||
|
||||
local function on_player_mined_entity(event)
|
||||
function Public.on_player_mined_entity(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid then
|
||||
return
|
||||
@ -299,5 +297,4 @@ local function on_player_mined_entity(event)
|
||||
scrap_randomness(data)
|
||||
end
|
||||
|
||||
local Event = require 'utils.event'
|
||||
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
return Public
|
@ -1,17 +1,8 @@
|
||||
--[[
|
||||
Hello there!
|
||||
-- unload the normal player list
|
||||
if package.loaded['comfy_panel.player_list'] then
|
||||
package.unload = 'comfy_panel.player_list'
|
||||
end
|
||||
|
||||
This will add a player list with "ranks" to your server.
|
||||
Oh.. and you can also "poke" a player.
|
||||
pokemessages = 80% by redlabel
|
||||
|
||||
To install, add: require "player_list"
|
||||
to your scenario control.lua.
|
||||
|
||||
---MewMew---
|
||||
|
||||
Minor changes by ~~~Gerkiz~~~
|
||||
--]]
|
||||
local Event = require 'utils.event'
|
||||
local play_time = require 'utils.session_data'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
|
@ -10,6 +10,7 @@ local map_functions = require 'tools.map_functions'
|
||||
local Scrap_table = require 'maps.scrapyard.table'
|
||||
local shapes = require 'tools.shapes'
|
||||
local Loot = require 'maps.scrapyard.loot'
|
||||
local get_noise = require 'utils.get_noise'
|
||||
|
||||
local Public = {}
|
||||
|
||||
@ -99,73 +100,10 @@ local more_colors = {
|
||||
'blue-refined-concrete'
|
||||
}
|
||||
|
||||
local noises = {
|
||||
['no_rocks'] = {
|
||||
{modifier = 0.0044, weight = 1},
|
||||
{modifier = 0.01, weight = 0.22},
|
||||
{modifier = 0.05, weight = 0.05},
|
||||
{modifier = 0.1, weight = 0.04}
|
||||
},
|
||||
['no_rocks_2'] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
|
||||
['large_caves'] = {
|
||||
{modifier = 0.0044, weight = 1},
|
||||
{modifier = 0.01, weight = 0.22},
|
||||
{modifier = 0.05, weight = 0.05},
|
||||
{modifier = 0.1, weight = 0.04}
|
||||
},
|
||||
['small_caves'] = {
|
||||
{modifier = 0.008, weight = 1},
|
||||
{modifier = 0.03, weight = 0.15},
|
||||
{modifier = 0.25, weight = 0.05}
|
||||
},
|
||||
['small_caves_2'] = {
|
||||
{modifier = 0.009, weight = 1},
|
||||
{modifier = 0.05, weight = 0.25},
|
||||
{modifier = 0.25, weight = 0.05}
|
||||
},
|
||||
['cave_worms'] = {{modifier = 0.001, weight = 1}, {modifier = 0.1, weight = 0.06}},
|
||||
['cave_ponds'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
|
||||
['cave_rivers'] = {
|
||||
{modifier = 0.005, weight = 1},
|
||||
{modifier = 0.01, weight = 0.25},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_2'] = {
|
||||
{modifier = 0.003, weight = 1},
|
||||
{modifier = 0.01, weight = 0.21},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_3'] = {
|
||||
{modifier = 0.002, weight = 1},
|
||||
{modifier = 0.01, weight = 0.15},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_4'] = {
|
||||
{modifier = 0.001, weight = 1},
|
||||
{modifier = 0.01, weight = 0.11},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['scrapyard'] = {
|
||||
{modifier = 0.005, weight = 1},
|
||||
{modifier = 0.01, weight = 0.35},
|
||||
{modifier = 0.05, weight = 0.23},
|
||||
{modifier = 0.1, weight = 0.11}
|
||||
}
|
||||
}
|
||||
local function place_wagon(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
local function get_noise(name, pos, seed)
|
||||
local noise = 0
|
||||
local d = 0
|
||||
for _, n in pairs(noises[name]) do
|
||||
noise = noise + noise_v1(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
|
||||
d = d + n.weight
|
||||
seed = seed + 10000
|
||||
end
|
||||
noise = noise / d
|
||||
return noise
|
||||
end
|
||||
|
||||
local function place_wagon(surface, left_top)
|
||||
local position = {x = left_top.x + math_random(4, 12) * 2, y = left_top.y + math_random(4, 12) * 2}
|
||||
|
||||
local direction
|
||||
@ -185,7 +123,11 @@ local function place_wagon(surface, left_top)
|
||||
if tile.collides_with('resource-layer') then
|
||||
surface.set_tiles({{name = 'landfill', position = tile.position}}, true)
|
||||
end
|
||||
for _, e in pairs(surface.find_entities_filtered({position = tile.position, force = {'neutral', 'enemy'}})) do
|
||||
for _, e in pairs(
|
||||
surface.find_entities_filtered(
|
||||
{position = tile.position, force = {'neutral', 'enemy', 'scrap_defense', 'scrap'}}
|
||||
)
|
||||
) do
|
||||
e.destroy()
|
||||
end
|
||||
if tile.position.y % 2 == 0 and tile.position.x % 2 == 0 then
|
||||
@ -272,7 +214,11 @@ local function get_oil_amount(p)
|
||||
return (math_abs(p.y) * 200 + 10000) * math_random(75, 125) * 0.01
|
||||
end
|
||||
|
||||
local function wall(surface, left_top, seed)
|
||||
local function wall(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
local seed = data.seed
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
@ -293,7 +239,7 @@ local function wall(surface, left_top, seed)
|
||||
else
|
||||
surface.set_tiles({{name = 'dirt-7', position = p}})
|
||||
|
||||
if surface.can_place_entity({name = 'stone-wall', position = p, force = 'enemy'}) then
|
||||
if surface.can_place_entity({name = 'stone-wall', position = p, force = 'scrap_defense'}) then
|
||||
if math_random(1, 512) == 1 and y > 3 and y < 28 then
|
||||
if math_random(1, 2) == 1 then
|
||||
Loot.add(surface, p, 'wooden-chest')
|
||||
@ -305,13 +251,17 @@ local function wall(surface, left_top, seed)
|
||||
if y <= 15 then
|
||||
if math_random(1, y + 1) == 1 then
|
||||
local e =
|
||||
surface.create_entity({name = 'stone-wall', position = p, force = 'enemy'})
|
||||
surface.create_entity(
|
||||
{name = 'stone-wall', position = p, force = 'scrap_defense'}
|
||||
)
|
||||
e.minable = false
|
||||
end
|
||||
else
|
||||
if math_random(1, 32 - y) == 1 then
|
||||
local e =
|
||||
surface.create_entity({name = 'stone-wall', position = p, force = 'enemy'})
|
||||
surface.create_entity(
|
||||
{name = 'stone-wall', position = p, force = 'scrap_defense'}
|
||||
)
|
||||
e.minable = false
|
||||
end
|
||||
end
|
||||
@ -324,17 +274,17 @@ local function wall(surface, left_top, seed)
|
||||
end
|
||||
|
||||
if math_random(1, 16) == 1 then
|
||||
if surface.can_place_entity({name = 'small-worm-turret', position = p, force = 'enemy'}) then
|
||||
if surface.can_place_entity({name = 'small-worm-turret', position = p, force = 'scrap_defense'}) then
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
surface.create_entity(
|
||||
{name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
{name = Biters.wave_defense_roll_worm_name(), position = p, force = 'scrap_defense'}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
if math_random(1, 32) == 1 then
|
||||
if surface.can_place_entity({name = 'gun-turret', position = p, force = 'enemy'}) then
|
||||
local e = surface.create_entity({name = 'gun-turret', position = p, force = 'enemy'})
|
||||
if surface.can_place_entity({name = 'gun-turret', position = p, force = 'scrap_defense'}) then
|
||||
local e = surface.create_entity({name = 'gun-turret', position = p, force = 'scrap_defense'})
|
||||
if math_abs(p.y) < Public.level_depth * 2.5 then
|
||||
e.insert({name = 'piercing-rounds-magazine', count = math_random(64, 128)})
|
||||
else
|
||||
@ -347,7 +297,15 @@ local function wall(surface, left_top, seed)
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_9_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_9_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local maze_p = {x = math_floor(p.x - p.x % 10), y = math_floor(p.y - p.y % 10)}
|
||||
local maze_noise = get_noise('no_rocks_2', maze_p, seed)
|
||||
|
||||
@ -363,7 +321,11 @@ local function process_level_9_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 256) == 1 then
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
create_inner_content(surface, p, maze_noise)
|
||||
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -395,7 +357,15 @@ local function process_level_9_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_8_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_8_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local scrapyard = get_noise('scrapyard', p, seed)
|
||||
|
||||
--Chasms
|
||||
@ -414,7 +384,7 @@ local function process_level_8_position(surface, p, seed, tiles, entities, fishe
|
||||
|
||||
if scrapyard < -0.25 or scrapyard > 0.25 then
|
||||
if math_random(1, 256) == 1 then
|
||||
entities[#entities + 1] = {name = 'gun-turret', position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {name = 'gun-turret', position = p, force = 'scrap_defense'}
|
||||
end
|
||||
tiles[#tiles + 1] = {name = 'dirt-7', position = p}
|
||||
if scrapyard < -0.55 or scrapyard > 0.55 then
|
||||
@ -427,13 +397,17 @@ local function process_level_8_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 128) == 1 then
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
create_inner_content(surface, p, scrapyard)
|
||||
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 96) == 1 then
|
||||
entities[#entities + 1] = {
|
||||
name = scrap_entities[math_random(1, scrap_entities_index)],
|
||||
position = p,
|
||||
force = 'enemy'
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 5) > 1 then
|
||||
@ -442,7 +416,7 @@ local function process_level_8_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 256) == 1 then
|
||||
create_inner_content(surface, p, scrapyard)
|
||||
|
||||
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'scrap_defense'}
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -475,11 +449,19 @@ local function process_level_8_position(surface, p, seed, tiles, entities, fishe
|
||||
|
||||
tiles[#tiles + 1] = {name = 'stone-path', position = p}
|
||||
if math_random(1, 256) == 1 then
|
||||
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {name = 'land-mine', position = p, force = 'scrap_defense'}
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_7_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_7_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local cave_rivers_3 = get_noise('cave_rivers_3', p, seed)
|
||||
local cave_rivers_4 = get_noise('cave_rivers_4', p, seed + 50000)
|
||||
local no_rocks_2 = get_noise('no_rocks_2', p, seed)
|
||||
@ -575,7 +557,15 @@ local function process_level_7_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_6_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_6_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local large_caves = get_noise('large_caves', p, seed)
|
||||
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
|
||||
|
||||
@ -599,7 +589,11 @@ local function process_level_6_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 128) == 1 then
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
create_inner_content(surface, p, noise_cave_ponds)
|
||||
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -630,7 +624,15 @@ local function process_level_6_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_5_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_5_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local small_caves = get_noise('small_caves', p, seed)
|
||||
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
|
||||
|
||||
@ -654,7 +656,11 @@ local function process_level_5_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 128) == 1 then
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
create_inner_content(surface, p, noise_cave_ponds)
|
||||
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -685,7 +691,15 @@ local function process_level_5_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_4_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_4_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local noise_large_caves = get_noise('large_caves', p, seed)
|
||||
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
|
||||
local small_caves = get_noise('small_caves', p, seed)
|
||||
@ -713,7 +727,11 @@ local function process_level_4_position(surface, p, seed, tiles, entities, fishe
|
||||
if math_random(1, 384) == 1 then
|
||||
create_inner_content(surface, p, noise_cave_ponds)
|
||||
Biters.wave_defense_set_worm_raffle(math_abs(p.y) * worm_level_modifier)
|
||||
entities[#entities + 1] = {name = Biters.wave_defense_roll_worm_name(), position = p, force = 'enemy'}
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 1024) == 1 then
|
||||
treasure[#treasure + 1] = p
|
||||
@ -780,7 +798,15 @@ local function process_level_4_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_3_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_3_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local small_caves = get_noise('small_caves', p, seed + 50000)
|
||||
local small_caves_2 = get_noise('small_caves_2', p, seed + 70000)
|
||||
local noise_large_caves = get_noise('large_caves', p, seed + 60000)
|
||||
@ -869,7 +895,7 @@ local function process_level_3_position(surface, p, seed, tiles, entities, fishe
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'enemy'
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 512) == 1 then
|
||||
@ -908,7 +934,15 @@ local function process_level_3_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_2_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_2_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local small_caves = get_noise('small_caves', p, seed)
|
||||
local noise_large_caves = get_noise('large_caves', p, seed)
|
||||
|
||||
@ -981,7 +1015,7 @@ local function process_level_2_position(surface, p, seed, tiles, entities, fishe
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'enemy'
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 64) == 1 then
|
||||
@ -1017,7 +1051,15 @@ local function process_level_2_position(surface, p, seed, tiles, entities, fishe
|
||||
end
|
||||
end
|
||||
|
||||
local function process_level_1_position(surface, p, seed, tiles, entities, fishes, markets, treasure)
|
||||
local function process_level_1_position(data)
|
||||
local surface = data.surface
|
||||
local p = data.p
|
||||
local seed = data.seed
|
||||
local tiles = data.tiles
|
||||
local entities = data.entities
|
||||
local markets = data.markets
|
||||
local treasure = data.treasure
|
||||
|
||||
local small_caves = get_noise('small_caves', p, seed)
|
||||
|
||||
local noise_cave_ponds = get_noise('cave_ponds', p, seed)
|
||||
@ -1090,7 +1132,7 @@ local function process_level_1_position(surface, p, seed, tiles, entities, fishe
|
||||
entities[#entities + 1] = {
|
||||
name = Biters.wave_defense_roll_worm_name(),
|
||||
position = p,
|
||||
force = 'enemy'
|
||||
force = 'scrap_defense'
|
||||
}
|
||||
end
|
||||
if math_random(1, 1024) == 1 then
|
||||
@ -1148,42 +1190,41 @@ Public.levels = {
|
||||
|
||||
function Public.reveal_train(data)
|
||||
local position = data.position
|
||||
local seed = data.seed
|
||||
local surface = data.surface
|
||||
local circles = shapes.circles
|
||||
local uncover_radius = data.reveal
|
||||
local tiles = {}
|
||||
local fishes = {}
|
||||
local entities = {}
|
||||
local markets = {}
|
||||
local treasure = {}
|
||||
data.tiles = {}
|
||||
data.entities = {}
|
||||
data.markets = {}
|
||||
data.treasure = {}
|
||||
local level_index = math_floor((math_abs(position.y / Public.level_depth)) % 9) + 1
|
||||
local process_level = Public.levels[level_index]
|
||||
|
||||
for r = 1, uncover_radius, 1 do
|
||||
for _, v in pairs(circles[r]) do
|
||||
local pos = {x = position.x - 30 + math_random(1, 64) + v.x, y = position.y - 20 + v.y + math_random(1, 64)}
|
||||
data.p = pos
|
||||
local t_name
|
||||
if surface.get_tile(pos).valid then
|
||||
t_name = surface.get_tile(pos).name == 'out-of-map'
|
||||
end
|
||||
if t_name then
|
||||
process_level(surface, pos, seed, tiles, entities, fishes, markets, treasure)
|
||||
process_level(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #tiles > 0 then
|
||||
surface.set_tiles(tiles, true)
|
||||
if #data.tiles > 0 then
|
||||
surface.set_tiles(data.tiles, true)
|
||||
end
|
||||
for _, entity in pairs(entities) do
|
||||
for _, entity in pairs(data.entities) do
|
||||
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
|
||||
surface.create_entity(entity)
|
||||
else
|
||||
surface.create_entity(entity)
|
||||
end
|
||||
end
|
||||
if #markets > 0 then
|
||||
local pos = markets[math_random(1, #markets)]
|
||||
if #data.markets > 0 then
|
||||
local pos = data.markets[math_random(1, #data.markets)]
|
||||
if
|
||||
surface.count_entities_filtered {
|
||||
area = {{pos.x - 96, pos.y - 96}, {pos.x + 96, pos.y + 96}},
|
||||
@ -1195,13 +1236,10 @@ function Public.reveal_train(data)
|
||||
market.destructible = false
|
||||
end
|
||||
end
|
||||
for _, p in pairs(treasure) do
|
||||
for _, p in pairs(data.treasure) do
|
||||
local name = 'steel-chest'
|
||||
Loot.add(surface, p, name)
|
||||
end
|
||||
for _, fish in pairs(fishes) do
|
||||
surface.create_entity({name = 'fish', position = fish})
|
||||
end
|
||||
end
|
||||
|
||||
function Public.reveal(player)
|
||||
@ -1211,35 +1249,40 @@ function Public.reveal(player)
|
||||
local surface = player.surface
|
||||
local circles = shapes.circles
|
||||
local uncover_radius = 10
|
||||
local tiles = {}
|
||||
local fishes = {}
|
||||
local entities = {}
|
||||
local markets = {}
|
||||
local treasure = {}
|
||||
local data = {
|
||||
surface = surface,
|
||||
seed = seed,
|
||||
tiles = {},
|
||||
entities = {},
|
||||
markets = {},
|
||||
treasure = {}
|
||||
}
|
||||
|
||||
local level_index = math_floor((math_abs(position.y / Public.level_depth)) % 9) + 1
|
||||
local process_level = Public.levels[level_index]
|
||||
|
||||
for r = 1, uncover_radius, 1 do
|
||||
for _, v in pairs(circles[r]) do
|
||||
local pos = {x = position.x + v.x, y = position.y + v.y}
|
||||
data.p = pos
|
||||
local t_name = surface.get_tile(pos).name == 'out-of-map'
|
||||
if t_name then
|
||||
process_level(surface, pos, seed, tiles, entities, fishes, markets, treasure)
|
||||
process_level(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
if #tiles > 0 then
|
||||
surface.set_tiles(tiles, true)
|
||||
if #data.tiles > 0 then
|
||||
surface.set_tiles(data.tiles, true)
|
||||
end
|
||||
for _, entity in pairs(entities) do
|
||||
for _, entity in pairs(data.entities) do
|
||||
if surface.can_place_entity(entity) and entity == 'biter-spawner' or entity == 'spitter-spawner' then
|
||||
surface.create_entity(entity)
|
||||
else
|
||||
surface.create_entity(entity)
|
||||
end
|
||||
end
|
||||
if #markets > 0 then
|
||||
local pos = markets[math_random(1, #markets)]
|
||||
if #data.markets > 0 then
|
||||
local pos = data.markets[math_random(1, #data.markets)]
|
||||
if
|
||||
surface.count_entities_filtered {
|
||||
area = {{pos.x - 96, pos.y - 96}, {pos.x + 96, pos.y + 96}},
|
||||
@ -1251,20 +1294,20 @@ function Public.reveal(player)
|
||||
market.destructible = false
|
||||
end
|
||||
end
|
||||
for _, p in pairs(treasure) do
|
||||
for _, p in pairs(data.treasure) do
|
||||
local name = 'steel-chest'
|
||||
Loot.add(surface, p, name)
|
||||
end
|
||||
for _, fish in pairs(fishes) do
|
||||
surface.create_entity({name = 'fish', position = fish})
|
||||
end
|
||||
end
|
||||
|
||||
local function generate_spawn_area(surface, position_left_top)
|
||||
if position_left_top.y < -0 then
|
||||
local function generate_spawn_area(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
if left_top.y < -0 then
|
||||
return
|
||||
end
|
||||
if position_left_top.y > 10 then
|
||||
if left_top.y > 10 then
|
||||
return
|
||||
end
|
||||
local tiles = {}
|
||||
@ -1272,7 +1315,7 @@ local function generate_spawn_area(surface, position_left_top)
|
||||
|
||||
for r = 1, 12 do
|
||||
for k, v in pairs(circles[r]) do
|
||||
local pos = {x = position_left_top.x + v.x, y = position_left_top.y + 20 + v.y}
|
||||
local pos = {x = left_top.x + v.x, y = left_top.y + 20 + v.y}
|
||||
if pos.x > -15 and pos.x < 15 and pos.y < 40 then
|
||||
insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos})
|
||||
end
|
||||
@ -1294,9 +1337,6 @@ local function generate_spawn_area(surface, position_left_top)
|
||||
if pos.x > -180 and pos.x < 180 and pos.y < 40 then
|
||||
insert(tiles, {name = more_colors[math_random(1, #more_colors)], position = pos})
|
||||
end
|
||||
--if t_insert then
|
||||
-- insert(tiles, {name = t_insert, position = pos})
|
||||
--end
|
||||
end
|
||||
end
|
||||
surface.set_tiles(tiles, true)
|
||||
@ -1315,7 +1355,10 @@ local function is_out_of_map(p)
|
||||
return true
|
||||
end
|
||||
|
||||
local function border_chunk(surface, left_top)
|
||||
local function border_chunk(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 5, 31, 1 do
|
||||
local pos = {x = left_top.x + x, y = left_top.y + y}
|
||||
@ -1375,7 +1418,10 @@ local function border_chunk(surface, left_top)
|
||||
end
|
||||
end
|
||||
|
||||
local function replace_water(surface, left_top)
|
||||
local function replace_water(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
@ -1386,7 +1432,10 @@ local function replace_water(surface, left_top)
|
||||
end
|
||||
end
|
||||
|
||||
local function process(surface, left_top)
|
||||
local function process(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
local tiles = {}
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
@ -1405,9 +1454,10 @@ local function process(surface, left_top)
|
||||
surface.regenerate_decorative(decorative_names, {left_top})
|
||||
end
|
||||
|
||||
local function out_of_map_area(event)
|
||||
local surface = event.surface
|
||||
local left_top = event.area.left_top
|
||||
local function out_of_map_area(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
for x = -1, 32, 1 do
|
||||
for y = -1, 32, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
@ -1418,7 +1468,10 @@ local function out_of_map_area(event)
|
||||
end
|
||||
end
|
||||
|
||||
local function biter_chunk(surface, left_top)
|
||||
local function biter_chunk(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
|
||||
local tile_positions = {}
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
@ -1455,7 +1508,9 @@ local function biter_chunk(surface, left_top)
|
||||
end
|
||||
end
|
||||
|
||||
local function out_of_map(surface, left_top)
|
||||
local function out_of_map(data)
|
||||
local surface = data.surface
|
||||
local left_top = data.left_top
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
surface.set_tiles({{name = 'out-of-map', position = {x = left_top.x + x, y = left_top.y + y}}})
|
||||
@ -1471,36 +1526,30 @@ local function on_chunk_generated(event)
|
||||
local surface = event.surface
|
||||
local seed = surface.map_gen_settings.seed
|
||||
local position = this.locomotive.position
|
||||
local left_top = event.area.left_top
|
||||
|
||||
local data = {
|
||||
this = this,
|
||||
surface = surface,
|
||||
seed = seed,
|
||||
position = position,
|
||||
reveal = 23
|
||||
reveal = 23,
|
||||
left_top = left_top
|
||||
}
|
||||
|
||||
local left_top = event.area.left_top
|
||||
if left_top.x >= Public.level_depth * 0.5 then
|
||||
out_of_map(surface, left_top)
|
||||
out_of_map(data)
|
||||
return
|
||||
end
|
||||
if left_top.x < Public.level_depth * -0.5 then
|
||||
out_of_map(surface, left_top)
|
||||
out_of_map(data)
|
||||
return
|
||||
end
|
||||
if surface.name ~= event.surface.name then
|
||||
return
|
||||
end
|
||||
if this.rev_sp then
|
||||
goto continue
|
||||
end
|
||||
|
||||
if left_top.y > 32 then
|
||||
game.forces.player.chart(surface, {{left_top.x, left_top.y}, {left_top.x + 31, left_top.y + 31}})
|
||||
end
|
||||
|
||||
::continue::
|
||||
|
||||
if not this.train_reveal then
|
||||
if this.revealed_spawn > game.tick then
|
||||
Public.reveal_train(data)
|
||||
@ -1508,32 +1557,32 @@ local function on_chunk_generated(event)
|
||||
end
|
||||
|
||||
if left_top.y % Public.level_depth == 0 and left_top.y < 0 then
|
||||
this.left_top = event.area.left_top
|
||||
wall(surface, left_top, seed)
|
||||
this.left_top = data.left_top
|
||||
wall(data)
|
||||
return
|
||||
end
|
||||
|
||||
if left_top.y > 268 then
|
||||
out_of_map(surface, left_top)
|
||||
out_of_map(data)
|
||||
return
|
||||
end
|
||||
if left_top.y >= 0 then
|
||||
replace_water(surface, left_top)
|
||||
replace_water(data)
|
||||
end
|
||||
if left_top.y > 210 then
|
||||
biter_chunk(surface, left_top)
|
||||
biter_chunk(data)
|
||||
end
|
||||
if left_top.y >= 10 then
|
||||
border_chunk(surface, left_top)
|
||||
border_chunk(data)
|
||||
end
|
||||
if left_top.y < 0 then
|
||||
process(surface, left_top)
|
||||
process(data)
|
||||
if math_random(1, chance_for_wagon_spawn) == 1 then
|
||||
place_wagon(surface, left_top)
|
||||
place_wagon(data)
|
||||
end
|
||||
end
|
||||
out_of_map_area(event)
|
||||
generate_spawn_area(surface, left_top)
|
||||
out_of_map_area(data)
|
||||
generate_spawn_area(data)
|
||||
end
|
||||
|
||||
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
|
||||
|
193
modules/balance.lua
Normal file
193
modules/balance.lua
Normal file
@ -0,0 +1,193 @@
|
||||
local Event = require 'utils.event'
|
||||
|
||||
local function player_ammo_starting_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.25,
|
||||
['cannon-shell'] = -0.75,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.5,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.33,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = 2,
|
||||
['railgun'] = 1,
|
||||
['rocket'] = -0.75,
|
||||
['shotgun-shell'] = -0.20
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function player_gun_speed_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.55,
|
||||
['cannon-shell'] = -0.75,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.5,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.33,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = 1,
|
||||
['railgun'] = 0,
|
||||
['rocket'] = -0.75,
|
||||
['shotgun-shell'] = -0.50
|
||||
}
|
||||
return data
|
||||
end
|
||||
local function player_ammo_research_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = -0.75,
|
||||
['biological'] = -0.5,
|
||||
['bullet'] = -0.5,
|
||||
['cannon-shell'] = -0.85,
|
||||
['capsule'] = -0.5,
|
||||
['combat-robot-beam'] = -0.5,
|
||||
['combat-robot-laser'] = -0.5,
|
||||
['electric'] = -0.6,
|
||||
['flamethrower'] = -0.75,
|
||||
['grenade'] = -0.5,
|
||||
['landmine'] = -0.5,
|
||||
['laser-turret'] = -0.75,
|
||||
['melee'] = -0.5,
|
||||
['railgun'] = -0.5,
|
||||
['rocket'] = -0.5,
|
||||
['shotgun-shell'] = -0.20
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function player_turrets_research_modifiers()
|
||||
local data = {
|
||||
['gun-turret'] = -0.75,
|
||||
['laser-turret'] = -0.75,
|
||||
['flamethrower-turret'] = -0.75
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function enemy_ammo_starting_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = 3,
|
||||
['biological'] = 3,
|
||||
['bullet'] = 2,
|
||||
['cannon-shell'] = 0,
|
||||
['capsule'] = 0,
|
||||
['combat-robot-beam'] = 0,
|
||||
['combat-robot-laser'] = 0,
|
||||
['electric'] = 0,
|
||||
['flamethrower'] = 0,
|
||||
['grenade'] = 0,
|
||||
['landmine'] = 0,
|
||||
['laser-turret'] = 3,
|
||||
['melee'] = 1,
|
||||
['railgun'] = 0,
|
||||
['rocket'] = 0,
|
||||
['shotgun-shell'] = 0
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function enemy_ammo_evolution_modifiers()
|
||||
local data = {
|
||||
['artillery-shell'] = 1,
|
||||
['biological'] = 2,
|
||||
['bullet'] = 1,
|
||||
--['cannon-shell'] = 1,
|
||||
['capsule'] = 1,
|
||||
['combat-robot-beam'] = 1,
|
||||
['combat-robot-laser'] = 1,
|
||||
['electric'] = 1,
|
||||
['flamethrower'] = 2,
|
||||
--['grenade'] = 1,
|
||||
--['landmine'] = 1,
|
||||
['laser-turret'] = 2,
|
||||
['melee'] = 2
|
||||
--['railgun'] = 1,
|
||||
--['rocket'] = 1,
|
||||
--['shotgun-shell'] = 1
|
||||
}
|
||||
return data
|
||||
end
|
||||
|
||||
local function init_player_weapon_damage(force)
|
||||
for k, v in pairs(player_ammo_starting_modifiers()) do
|
||||
force.set_ammo_damage_modifier(k, v)
|
||||
end
|
||||
|
||||
for k, v in pairs(player_gun_speed_modifiers()) do
|
||||
force.set_gun_speed_modifier(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function init_enemy_weapon_damage()
|
||||
local e = game.forces['enemy']
|
||||
|
||||
for k, v in pairs(enemy_ammo_starting_modifiers()) do
|
||||
e.set_ammo_damage_modifier(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local function enemy_weapon_damage()
|
||||
local e = game.forces.enemy
|
||||
|
||||
local ef = e.evolution_factor
|
||||
|
||||
for k, v in pairs(enemy_ammo_evolution_modifiers()) do
|
||||
local base = enemy_ammo_starting_modifiers()[k]
|
||||
|
||||
local new = base + v * ef
|
||||
e.set_ammo_damage_modifier(k, new)
|
||||
end
|
||||
end
|
||||
|
||||
local function research_finished(event)
|
||||
local r = event.research
|
||||
local p_force = r.force
|
||||
|
||||
for _, e in ipairs(r.effects) do
|
||||
local t = e.type
|
||||
|
||||
if t == 'ammo-damage' then
|
||||
local category = e.ammo_category
|
||||
local factor = player_ammo_research_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_ammo_damage_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_ammo_damage_modifier(category, current_m + factor * m)
|
||||
end
|
||||
elseif t == 'turret-attack' then
|
||||
local category = e.turret_id
|
||||
local factor = player_turrets_research_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_turret_attack_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_turret_attack_modifier(category, current_m + factor * m)
|
||||
end
|
||||
elseif t == 'gun-speed' then
|
||||
local category = e.ammo_category
|
||||
local factor = player_gun_speed_modifiers()[category]
|
||||
|
||||
if factor then
|
||||
local current_m = p_force.get_gun_speed_modifier(category)
|
||||
local m = e.modifier
|
||||
p_force.set_gun_speed_modifier(category, current_m + factor * m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_init(init_player_weapon_damage)
|
||||
Event.on_init(init_enemy_weapon_damage)
|
||||
Event.on_nth_tick(18000, enemy_weapon_damage)
|
||||
Event.add(defines.events.on_research_finished, research_finished)
|
@ -1,133 +1,198 @@
|
||||
local math_random = math.random
|
||||
local nom_msg = {"munch", "munch", "yum"}
|
||||
local nom_msg = {'munch', 'munch', 'yum'}
|
||||
|
||||
local Public = {}
|
||||
|
||||
local function feed_floaty_text(unit)
|
||||
unit.surface.create_entity({name = "flying-text", position = unit.position, text = nom_msg[math_random(1, #nom_msg)], color = {math_random(50, 100), 0, 255}})
|
||||
unit.surface.create_entity(
|
||||
{
|
||||
name = 'flying-text',
|
||||
position = unit.position,
|
||||
text = nom_msg[math_random(1, #nom_msg)],
|
||||
color = {math_random(50, 100), 0, 255}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
local function floaty_hearts(entity, c)
|
||||
local position = {x = entity.position.x - 0.75, y = entity.position.y - 1}
|
||||
local b = 1.35
|
||||
for a = 1, c, 1 do
|
||||
local p = {(position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1), position.y + (b * -1 + math_random(0, b * 20) * 0.1)}
|
||||
entity.surface.create_entity({name = "flying-text", position = p, text = "♥", color = {math_random(150, 255), 0, 255}})
|
||||
end
|
||||
local position = {x = entity.position.x - 0.75, y = entity.position.y - 1}
|
||||
local b = 1.35
|
||||
for a = 1, c, 1 do
|
||||
local p = {
|
||||
(position.x + 0.4) + (b * -1 + math_random(0, b * 20) * 0.1),
|
||||
position.y + (b * -1 + math_random(0, b * 20) * 0.1)
|
||||
}
|
||||
entity.surface.create_entity(
|
||||
{name = 'flying-text', position = p, text = '♥', color = {math_random(150, 255), 0, 255}}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local function tame_unit_effects(player, entity)
|
||||
floaty_hearts(entity, 7)
|
||||
|
||||
rendering.draw_text{
|
||||
text = "~" .. player.name .. "'s pet~",
|
||||
surface = player.surface,
|
||||
target = entity,
|
||||
target_offset = {0, -2.6},
|
||||
color = {
|
||||
r = player.color.r * 0.6 + 0.25,
|
||||
g = player.color.g * 0.6 + 0.25,
|
||||
b = player.color.b * 0.6 + 0.25,
|
||||
a = 1
|
||||
},
|
||||
scale = 1.05,
|
||||
font = "default-large-semibold",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false
|
||||
}
|
||||
floaty_hearts(entity, 7)
|
||||
|
||||
rendering.draw_text {
|
||||
text = '~' .. player.name .. "'s pet~",
|
||||
surface = player.surface,
|
||||
target = entity,
|
||||
target_offset = {0, -2.6},
|
||||
color = {
|
||||
r = player.color.r * 0.6 + 0.25,
|
||||
g = player.color.g * 0.6 + 0.25,
|
||||
b = player.color.b * 0.6 + 0.25,
|
||||
a = 1
|
||||
},
|
||||
scale = 1.05,
|
||||
font = 'default-large-semibold',
|
||||
alignment = 'center',
|
||||
scale_with_zoom = false
|
||||
}
|
||||
end
|
||||
|
||||
local function find_unit(player, entity)
|
||||
local units = player.surface.find_entities_filtered({type = "unit", area = {{entity.position.x - 1, entity.position.y - 1},{entity.position.x + 1, entity.position.y + 1}}, limit = 1})
|
||||
return units[1]
|
||||
local units =
|
||||
player.surface.find_entities_filtered(
|
||||
{
|
||||
type = 'unit',
|
||||
area = {{entity.position.x - 1, entity.position.y - 1}, {entity.position.x + 1, entity.position.y + 1}},
|
||||
limit = 1
|
||||
}
|
||||
)
|
||||
return units[1]
|
||||
end
|
||||
|
||||
local function feed_pet(unit)
|
||||
if unit.prototype.max_health == unit.health then return end
|
||||
unit.health = unit.health + 8 + math.floor(unit.prototype.max_health * 0.05)
|
||||
feed_floaty_text(unit)
|
||||
floaty_hearts(unit, math_random(1,2))
|
||||
return true
|
||||
if unit.prototype.max_health == unit.health then
|
||||
return
|
||||
end
|
||||
unit.health = unit.health + 8 + math.floor(unit.prototype.max_health * 0.05)
|
||||
feed_floaty_text(unit)
|
||||
floaty_hearts(unit, math_random(1, 2))
|
||||
return true
|
||||
end
|
||||
|
||||
local function is_valid_player(player, unit)
|
||||
if not player.character then return end
|
||||
if not player.character.valid then return end
|
||||
if player.surface.index ~= unit.surface.index then return end
|
||||
return true
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
if not player.character.valid then
|
||||
return
|
||||
end
|
||||
if player.surface.index ~= unit.surface.index then
|
||||
return
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function Public.biter_pets_tame_unit(player, unit, forced)
|
||||
if global.biter_pets[player.index] then return false end
|
||||
if not forced then
|
||||
if math_random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then
|
||||
feed_floaty_text(unit)
|
||||
return true
|
||||
end
|
||||
end
|
||||
if unit.force.index == player.force.index then return false end
|
||||
unit.ai_settings.allow_destroy_when_commands_fail = false
|
||||
unit.ai_settings.allow_try_return_to_spawner = false
|
||||
unit.force = player.force
|
||||
unit.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
global.biter_pets[player.index] = {last_command = 0, entity = unit}
|
||||
tame_unit_effects(player, unit)
|
||||
return true
|
||||
if global.biter_pets[player.index] then
|
||||
return false
|
||||
end
|
||||
if not forced then
|
||||
if math_random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then
|
||||
feed_floaty_text(unit)
|
||||
return true
|
||||
end
|
||||
end
|
||||
if unit.force.index == player.force.index then
|
||||
return false
|
||||
end
|
||||
unit.ai_settings.allow_destroy_when_commands_fail = false
|
||||
unit.ai_settings.allow_try_return_to_spawner = false
|
||||
unit.force = player.force
|
||||
unit.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
global.biter_pets[player.index] = {last_command = 0, entity = unit}
|
||||
tame_unit_effects(player, unit)
|
||||
return true
|
||||
end
|
||||
|
||||
function Public.tame_unit_for_closest_player(unit)
|
||||
local valid_players = {}
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if is_valid_player(player, unit) then table.insert(valid_players, player) end
|
||||
end
|
||||
|
||||
local nearest_player = valid_players[1]
|
||||
if not nearest_player then return end
|
||||
local valid_players = {}
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if is_valid_player(player, unit) then
|
||||
table.insert(valid_players, player)
|
||||
end
|
||||
end
|
||||
|
||||
for i = 2, #valid_players, 1 do
|
||||
local player = valid_players[i + 1]
|
||||
if player.position.x ^ 2 + player.position.y ^ 2 < nearest_player.position.x ^ 2 + nearest_player.position.y ^ 2 then
|
||||
nearest_player = spawner
|
||||
end
|
||||
end
|
||||
|
||||
Public.biter_pets_tame_unit(nearest_player, unit, true)
|
||||
local nearest_player = valid_players[1]
|
||||
if not nearest_player then
|
||||
return
|
||||
end
|
||||
|
||||
for i = 2, #valid_players, 1 do
|
||||
local player = valid_players[i + 1]
|
||||
if player.position.x ^ 2 + player.position.y ^ 2 < nearest_player.position.x ^ 2 + nearest_player.position.y ^ 2 then
|
||||
nearest_player = spawner
|
||||
end
|
||||
end
|
||||
|
||||
Public.biter_pets_tame_unit(nearest_player, unit, true)
|
||||
end
|
||||
|
||||
local function command_unit(entity, player)
|
||||
local square_distance = (player.position.x - entity.position.x) ^ 2 + (player.position.y - entity.position.y) ^ 2
|
||||
|
||||
--Pet will follow, if the player is between a distance of 8 to 160 tiles away from it.
|
||||
if square_distance < 64 or square_distance > 25600 then
|
||||
entity.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
else
|
||||
entity.set_command({type = defines.command.go_to_location, destination_entity = player.character, radius = 4, distraction = defines.distraction.by_damage})
|
||||
end
|
||||
local square_distance = (player.position.x - entity.position.x) ^ 2 + (player.position.y - entity.position.y) ^ 2
|
||||
|
||||
--Pet will follow, if the player is between a distance of 8 to 160 tiles away from it.
|
||||
if square_distance < 64 or square_distance > 25600 then
|
||||
entity.set_command({type = defines.command.wander, distraction = defines.distraction.by_enemy})
|
||||
else
|
||||
entity.set_command(
|
||||
{
|
||||
type = defines.command.go_to_location,
|
||||
destination_entity = player.character,
|
||||
radius = 4,
|
||||
distraction = defines.distraction.by_damage
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_changed_position(event)
|
||||
if math_random(1, 100) ~= 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
if not global.biter_pets[player.index] then return end
|
||||
if not global.biter_pets[player.index].entity then global.biter_pets[player.index] = nil return end
|
||||
if not global.biter_pets[player.index].entity.valid then global.biter_pets[player.index] = nil return end
|
||||
if not player.character then return end
|
||||
if global.biter_pets[player.index].last_command + 600 > game.tick then return end
|
||||
global.biter_pets[player.index].last_command = game.tick
|
||||
command_unit(global.biter_pets[player.index].entity, player)
|
||||
if math_random(1, 100) ~= 1 then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
if not global.biter_pets[player.index] then
|
||||
return
|
||||
end
|
||||
if not global.biter_pets[player.index].entity then
|
||||
global.biter_pets[player.index] = nil
|
||||
return
|
||||
end
|
||||
if not global.biter_pets[player.index].entity.valid then
|
||||
global.biter_pets[player.index] = nil
|
||||
return
|
||||
end
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
if global.biter_pets[player.index].last_command + 600 > game.tick then
|
||||
return
|
||||
end
|
||||
global.biter_pets[player.index].last_command = game.tick
|
||||
command_unit(global.biter_pets[player.index].entity, player)
|
||||
end
|
||||
|
||||
local function on_player_dropped_item(event)
|
||||
local player = game.players[event.player_index]
|
||||
if event.entity.stack.name ~= "raw-fish" then return end
|
||||
local unit = find_unit(player, event.entity)
|
||||
if not unit then return end
|
||||
if Public.biter_pets_tame_unit(player, unit, false) then event.entity.destroy() return end
|
||||
if unit.force.index == player.force.index then feed_pet(unit) end
|
||||
local player = game.players[event.player_index]
|
||||
if event.entity.stack.name ~= 'raw-fish' then
|
||||
return
|
||||
end
|
||||
local unit = find_unit(player, event.entity)
|
||||
if not unit then
|
||||
return
|
||||
end
|
||||
if Public.biter_pets_tame_unit(player, unit, false) then
|
||||
event.entity.destroy()
|
||||
return
|
||||
end
|
||||
if unit.force.index == player.force.index then
|
||||
feed_pet(unit)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init(event)
|
||||
global.biter_pets = {}
|
||||
global.biter_pets = {}
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
@ -135,4 +200,4 @@ event.on_init(on_init)
|
||||
event.add(defines.events.on_player_dropped_item, on_player_dropped_item)
|
||||
event.add(defines.events.on_player_changed_position, on_player_changed_position)
|
||||
|
||||
return Public
|
||||
return Public
|
||||
|
@ -1,42 +1,99 @@
|
||||
local simplex_noise = require "utils.simplex_noise".d2
|
||||
local simplex_noise = require 'utils.simplex_noise'.d2
|
||||
|
||||
--add or use noise templates from here
|
||||
local noises = {
|
||||
["bb_biterland"] = {{modifier = 0.001, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.1, weight = 0.015}},
|
||||
["bb_ore"] = {{modifier = 0.0042, weight = 1}, {modifier = 0.031, weight = 0.08}, {modifier = 0.1, weight = 0.025}},
|
||||
["cave_ponds"] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
|
||||
["cave_rivers"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.25}, {modifier = 0.05, weight = 0.01}},
|
||||
["cave_rivers_2"] = {{modifier = 0.003, weight = 1}, {modifier = 0.01, weight = 0.21}, {modifier = 0.05, weight = 0.01}},
|
||||
["cave_rivers_3"] = {{modifier = 0.002, weight = 1}, {modifier = 0.01, weight = 0.15}, {modifier = 0.05, weight = 0.01}},
|
||||
["cave_rivers_4"] = {{modifier = 0.001, weight = 1}, {modifier = 0.01, weight = 0.11}, {modifier = 0.05, weight = 0.01}},
|
||||
["decoratives"] = {{modifier = 0.03, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}},
|
||||
["dungeons"] = {{modifier = 0.0025, weight = 1}, {modifier = 0.005, weight = 0.25}},
|
||||
["dungeon_sewer"] = {{modifier = 0.0005, weight = 1}, {modifier = 0.005, weight = 0.015}, {modifier = 0.025, weight = 0.0015}},
|
||||
["large_caves"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
|
||||
["n1"] = {{modifier = 0.0001, weight = 1}},
|
||||
["n2"] = {{modifier = 0.001, weight = 1}},
|
||||
["n3"] = {{modifier = 0.01, weight = 1}},
|
||||
["n4"] = {{modifier = 0.1, weight = 1}},
|
||||
["watery_world"] = {{modifier = 0.0007, weight = 1}, {modifier = 0.01, weight = 0.02}, {modifier = 0.1, weight = 0.005}},
|
||||
["no_rocks"] = {{modifier = 0.0033, weight = 1}, {modifier = 0.01, weight = 0.22}, {modifier = 0.05, weight = 0.05}, {modifier = 0.1, weight = 0.04}},
|
||||
["no_rocks_2"] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
|
||||
["oasis"] = {{modifier = 0.0015, weight = 1}, {modifier = 0.0025, weight = 0.5}, {modifier = 0.01, weight = 0.15}, {modifier = 0.1, weight = 0.017}},
|
||||
["scrapyard"] = {{modifier = 0.005, weight = 1}, {modifier = 0.01, weight = 0.35}, {modifier = 0.05, weight = 0.23}, {modifier = 0.1, weight = 0.11}},
|
||||
["small_caves"] = {{modifier = 0.008, weight = 1}, {modifier = 0.03, weight = 0.15}, {modifier = 0.25, weight = 0.05}},
|
||||
["small_caves_2"] = {{modifier = 0.009, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.25, weight = 0.05}},
|
||||
['bb_biterland'] = {
|
||||
{modifier = 0.001, weight = 1},
|
||||
{modifier = 0.01, weight = 0.35},
|
||||
{modifier = 0.1, weight = 0.015}
|
||||
},
|
||||
['bb_ore'] = {{modifier = 0.0042, weight = 1}, {modifier = 0.031, weight = 0.08}, {modifier = 0.1, weight = 0.025}},
|
||||
['cave_ponds'] = {{modifier = 0.01, weight = 1}, {modifier = 0.1, weight = 0.06}},
|
||||
['cave_worms'] = {{modifier = 0.001, weight = 1}, {modifier = 0.1, weight = 0.06}},
|
||||
['cave_rivers'] = {
|
||||
{modifier = 0.005, weight = 1},
|
||||
{modifier = 0.01, weight = 0.25},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_2'] = {
|
||||
{modifier = 0.003, weight = 1},
|
||||
{modifier = 0.01, weight = 0.21},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_3'] = {
|
||||
{modifier = 0.002, weight = 1},
|
||||
{modifier = 0.01, weight = 0.15},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['cave_rivers_4'] = {
|
||||
{modifier = 0.001, weight = 1},
|
||||
{modifier = 0.01, weight = 0.11},
|
||||
{modifier = 0.05, weight = 0.01}
|
||||
},
|
||||
['decoratives'] = {{modifier = 0.03, weight = 1}, {modifier = 0.05, weight = 0.25}, {modifier = 0.1, weight = 0.05}},
|
||||
['dungeons'] = {{modifier = 0.0025, weight = 1}, {modifier = 0.005, weight = 0.25}},
|
||||
['dungeon_sewer'] = {
|
||||
{modifier = 0.0005, weight = 1},
|
||||
{modifier = 0.005, weight = 0.015},
|
||||
{modifier = 0.025, weight = 0.0015}
|
||||
},
|
||||
['large_caves'] = {
|
||||
{modifier = 0.0033, weight = 1},
|
||||
{modifier = 0.01, weight = 0.22},
|
||||
{modifier = 0.05, weight = 0.05},
|
||||
{modifier = 0.1, weight = 0.04}
|
||||
},
|
||||
['n1'] = {{modifier = 0.0001, weight = 1}},
|
||||
['n2'] = {{modifier = 0.001, weight = 1}},
|
||||
['n3'] = {{modifier = 0.01, weight = 1}},
|
||||
['n4'] = {{modifier = 0.1, weight = 1}},
|
||||
['watery_world'] = {
|
||||
{modifier = 0.0007, weight = 1},
|
||||
{modifier = 0.01, weight = 0.02},
|
||||
{modifier = 0.1, weight = 0.005}
|
||||
},
|
||||
['no_rocks'] = {
|
||||
{modifier = 0.0033, weight = 1},
|
||||
{modifier = 0.01, weight = 0.22},
|
||||
{modifier = 0.05, weight = 0.05},
|
||||
{modifier = 0.1, weight = 0.04}
|
||||
},
|
||||
['no_rocks_2'] = {{modifier = 0.013, weight = 1}, {modifier = 0.1, weight = 0.1}},
|
||||
['oasis'] = {
|
||||
{modifier = 0.0015, weight = 1},
|
||||
{modifier = 0.0025, weight = 0.5},
|
||||
{modifier = 0.01, weight = 0.15},
|
||||
{modifier = 0.1, weight = 0.017}
|
||||
},
|
||||
['scrapyard'] = {
|
||||
{modifier = 0.005, weight = 1},
|
||||
{modifier = 0.01, weight = 0.35},
|
||||
{modifier = 0.05, weight = 0.23},
|
||||
{modifier = 0.1, weight = 0.11}
|
||||
},
|
||||
['small_caves'] = {
|
||||
{modifier = 0.008, weight = 1},
|
||||
{modifier = 0.03, weight = 0.15},
|
||||
{modifier = 0.25, weight = 0.05}
|
||||
},
|
||||
['small_caves_2'] = {
|
||||
{modifier = 0.009, weight = 1},
|
||||
{modifier = 0.05, weight = 0.25},
|
||||
{modifier = 0.25, weight = 0.05}
|
||||
}
|
||||
}
|
||||
|
||||
--returns a float number between -1 and 1
|
||||
local function get_noise(name, pos, seed)
|
||||
local noise = 0
|
||||
local d = 0
|
||||
for _, n in pairs(noises[name]) do
|
||||
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
|
||||
d = d + n.weight
|
||||
seed = seed + 10000
|
||||
end
|
||||
noise = noise / d
|
||||
return noise
|
||||
local noise = 0
|
||||
local d = 0
|
||||
for _, n in pairs(noises[name]) do
|
||||
noise = noise + simplex_noise(pos.x * n.modifier, pos.y * n.modifier, seed) * n.weight
|
||||
d = d + n.weight
|
||||
seed = seed + 10000
|
||||
end
|
||||
noise = noise / d
|
||||
return noise
|
||||
end
|
||||
|
||||
return get_noise
|
||||
return get_noise
|
||||
|
Loading…
x
Reference in New Issue
Block a user