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

changes to mtn and wave_defense

This commit is contained in:
Gerkiz 2020-08-09 20:22:33 +02:00
parent 33c6b82f40
commit 3613c37c1c
19 changed files with 1143 additions and 571 deletions

View File

@ -76,7 +76,7 @@ require 'modules.autostash'
--require 'maps.fish_defender_v2.main'
--require 'maps.fish_defender.main'
--require 'maps.biter_battles_v2.main'
--require 'maps.mountain_fortress_v3.main'
require 'maps.mountain_fortress_v3.main'
--require 'maps.mountain_fortress_v2.main'
--require 'maps.lumberjack.main'
--require 'maps.dungeons.main'

View File

@ -1,6 +1,8 @@
local Public = {}
local market = {}
local random = math.random
local floor = math.floor
market.weapons = {
['pistol'] = {value = 10, rarity = 1},
@ -153,13 +155,13 @@ end
local function get_resource_market_sells()
local sells = {
{price = {{'coin', math.random(5, 10)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
{price = {{'coin', math.random(5, 10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
{price = {{'coin', math.random(5, 10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
{price = {{'coin', math.random(5, 10)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
{price = {{'coin', math.random(5, 10)}}, offer = {type = 'give-item', item = 'coal', count = 50}},
{price = {{'coin', math.random(8, 16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}},
{price = {{'coin', math.random(2, 4)}}, offer = {type = 'give-item', item = 'crude-oil-barrel', count = 1}}
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'wood', count = 50}},
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'iron-ore', count = 50}},
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'copper-ore', count = 50}},
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'stone', count = 50}},
{price = {{'coin', random(5, 10)}}, offer = {type = 'give-item', item = 'coal', count = 50}},
{price = {{'coin', random(8, 16)}}, offer = {type = 'give-item', item = 'uranium-ore', count = 50}},
{price = {{'coin', random(2, 4)}}, offer = {type = 'give-item', item = 'crude-oil-barrel', count = 1}}
}
table.shuffle_table(sells)
return sells
@ -167,18 +169,18 @@ end
local function get_resource_market_buys()
local buys = {
{price = {{'wood', math.random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'iron-ore', math.random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'copper-ore', math.random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'stone', math.random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'coal', math.random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'uranium-ore', math.random(8, 10)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'water-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(1, 2)}},
{price = {{'lubricant-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(3, 6)}},
{price = {{'sulfuric-acid-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(4, 8)}},
{price = {{'light-oil-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(2, 4)}},
{price = {{'heavy-oil-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(2, 4)}},
{price = {{'petroleum-gas-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = math.random(3, 5)}}
{price = {{'wood', random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'iron-ore', random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'copper-ore', random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'stone', random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'coal', random(10, 12)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'uranium-ore', random(8, 10)}}, offer = {type = 'give-item', item = 'coin'}},
{price = {{'water-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(1, 2)}},
{price = {{'lubricant-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(3, 6)}},
{price = {{'sulfuric-acid-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(4, 8)}},
{price = {{'light-oil-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(2, 4)}},
{price = {{'heavy-oil-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(2, 4)}},
{price = {{'petroleum-gas-barrel', 1}}, offer = {type = 'give-item', item = 'coin', count = random(3, 5)}}
}
table.shuffle_table(buys)
return buys
@ -196,7 +198,7 @@ local function get_market_item_list(market_types, rarity)
for k, item in pairs(market[market_type]) do
--if item.rarity <= rarity and item.rarity + 7 >= rarity then
if item.rarity <= rarity then
local price = math.random(math.floor(item.value * 0.75), math.floor(item.value * 1.25))
local price = random(floor(item.value * 0.75), floor(item.value * 1.25))
if price < 1 then
price = 1
end
@ -239,7 +241,7 @@ function Public.get_random_item(rarity, sell, buy)
['car'] = true
}
for i = 1, math.random(5, 10), 1 do
for i = 1, random(5, 10), 1 do
local item = items[i]
if not item then
break
@ -251,14 +253,14 @@ function Public.get_random_item(rarity, sell, buy)
if sell then
local sells = get_resource_market_sells()
for i = 1, math.random(1, 3), 1 do
for i = 1, random(1, 3), 1 do
items_return[#items_return + 1] = sells[i]
end
end
if buy then
local buys = get_resource_market_buys()
for i = 1, math.random(1, 3), 1 do
for i = 1, random(1, 3), 1 do
items_return[#items_return + 1] = buys[i]
end
end
@ -286,7 +288,7 @@ function Public.mountain_market(surface, position, rarity, buy)
['land-mine'] = true
}
for i = 1, math.random(5, 10), 1 do
for i = 1, random(5, 10), 1 do
local item = items[i]
if not item then
break
@ -297,13 +299,13 @@ function Public.mountain_market(surface, position, rarity, buy)
end
local sells = get_resource_market_sells()
for i = 1, math.random(1, 3), 1 do
for i = 1, random(1, 3), 1 do
mrk.add_market_item(sells[i])
end
if buy then
local buys = get_resource_market_buys()
for i = 1, math.random(1, 3), 1 do
for i = 1, random(1, 3), 1 do
mrk.add_market_item(buys[i])
end
end

View File

@ -3,14 +3,16 @@ local WPT = require 'maps.mountain_fortress_v3.table'
local nom_msg = {'munch', 'munch', 'yum'}
local Public = {}
local random = math.random
local floor = math.floor
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}
text = nom_msg[random(1, #nom_msg)],
color = {random(50, 100), 0, 255}
}
)
end
@ -20,11 +22,11 @@ local function floaty_hearts(entity, c)
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)
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
entity.surface.create_entity(
{name = 'flying-text', position = p, text = '', color = {math.random(150, 255), 0, 255}}
{name = 'flying-text', position = p, text = '', color = {random(150, 255), 0, 255}}
)
end
end
@ -66,9 +68,9 @@ 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)
unit.health = unit.health + 8 + floor(unit.prototype.max_health * 0.05)
feed_floaty_text(unit)
floaty_hearts(unit, math.random(1, 2))
floaty_hearts(unit, random(1, 2))
return true
end
@ -93,7 +95,7 @@ function Public.biter_pets_tame_unit(player, unit, forced)
end
if not forced then
if math.random(1, math.floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then
if random(1, floor(unit.prototype.max_health * 0.01) + 1) ~= 1 then
feed_floaty_text(unit)
return true
end
@ -150,7 +152,7 @@ end
local function on_player_changed_position(event)
local this = WPT.get()
if math.random(1, 100) ~= 1 then
if random(1, 100) ~= 1 then
return
end
local player = game.players[event.player_index]

View File

@ -22,6 +22,11 @@ local WD = require 'modules.wave_defense.table'
-- module
local Public = {}
local random = math.random
local floor = math.floor
local abs = math.abs
local sqrt = math.sqrt
local round = math.round
--local raise_event = script.raise_event
@ -64,7 +69,8 @@ local protect_types = {
['artillery-wagon'] = true,
['fluid-wagon'] = true,
['locomotive'] = true,
['reactor'] = true
['reactor'] = true,
['car'] = true
}
local function set_objective_health(final_damage_amount)
@ -101,7 +107,7 @@ local function set_objective_health(final_damage_amount)
return
end
this.locomotive_health = math.floor(this.locomotive_health - final_damage_amount)
this.locomotive_health = floor(this.locomotive_health - final_damage_amount)
if this.locomotive_health > this.locomotive_max_health then
this.locomotive_health = this.locomotive_max_health
end
@ -152,9 +158,9 @@ end
local function hidden_biter(entity)
local surface = entity.surface
local h = math.floor(math.abs(entity.position.y))
local h = floor(abs(entity.position.y))
local m = 1 / Terrain.level_depth
local count = math.floor(math.random(0, h + Terrain.level_depth) * m) + 1
local count = floor(random(0, h + Terrain.level_depth) * m) + 1
local position = surface.find_non_colliding_position('small-biter', entity.position, 16, 0.5)
if not position then
position = entity.position
@ -164,30 +170,30 @@ local function hidden_biter(entity)
for _ = 1, count, 1 do
local unit
if math.random(1, 3) == 1 then
if random(1, 3) == 1 then
unit = surface.create_entity({name = BiterRolls.wave_defense_roll_spitter_name(), position = position})
else
unit = surface.create_entity({name = BiterRolls.wave_defense_roll_biter_name(), position = position})
end
if math.random(1, 64) == 1 then
if random(1, 64) == 1 then
BiterHealthBooster.add_boss_unit(unit, m * h * 5 + 1, 0.38)
end
end
end
local function hidden_worm(entity)
BiterRolls.wave_defense_set_worm_raffle(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.20)
BiterRolls.wave_defense_set_worm_raffle(sqrt(entity.position.x ^ 2 + entity.position.y ^ 2) * 0.20)
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
if 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)
BiterRolls.wave_defense_set_unit_raffle(sqrt(event.entity.position.x ^ 2 + event.entity.position.y ^ 2) * 0.25)
local unit
if math.random(1, 3) == 1 then
if random(1, 3) == 1 then
unit =
event.entity.surface.create_entity(
{name = BiterRolls.wave_defense_roll_spitter_name(), position = event.entity.position}
@ -207,26 +213,30 @@ local function hidden_treasure(event)
local magic = rpg[player.index].magicka
local name = Difficulty.get('name')
if name == 'Easy' then
if math.random(1, 220) ~= 1 then
if random(1, 220) ~= 1 then
return
end
elseif name == 'Normal' then
if math.random(1, 320) ~= 1 then
if random(1, 320) ~= 1 then
return
end
elseif name == 'Hard' then
if math.random(1, 420) ~= 1 then
if random(1, 420) ~= 1 then
return
end
elseif name == 'Insane' then
if random(1, 520) ~= 1 then
return
end
end
if magic > 50 then
local msg = rare_treasure_chest_messages[math.random(1, #rare_treasure_chest_messages)]
local msg = rare_treasure_chest_messages[random(1, #rare_treasure_chest_messages)]
Alert.alert_player(player, 5, msg)
Loot.add_rare(event.entity.surface, event.entity.position, 'wooden-chest', magic)
return
end
local msg = treasure_chest_messages[math.random(1, #treasure_chest_messages)]
local msg = treasure_chest_messages[random(1, #treasure_chest_messages)]
Alert.alert_player(player, 5, msg)
Loot.add(event.entity.surface, event.entity.position, 'wooden-chest')
end
@ -254,16 +264,16 @@ local function angry_tree(entity, cause)
return
end
if math.abs(entity.position.y) < Terrain.level_depth then
if abs(entity.position.y) < Terrain.level_depth then
return
end
if math.random(1, 4) == 1 then
if random(1, 4) == 1 then
hidden_biter(entity)
end
if math.random(1, 8) == 1 then
if random(1, 8) == 1 then
hidden_worm(entity)
end
if math.random(1, 16) ~= 1 then
if random(1, 16) ~= 1 then
return
end
local position = false
@ -273,12 +283,12 @@ local function angry_tree(entity, cause)
end
end
if not position then
position = {entity.position.x + (-20 + math.random(0, 40)), entity.position.y + (-20 + math.random(0, 40))}
position = {entity.position.x + (-20 + random(0, 40)), entity.position.y + (-20 + random(0, 40))}
end
entity.surface.create_entity(
{
name = projectiles[math.random(1, 5)],
name = projectiles[random(1, 5)],
position = entity.position,
force = 'neutral',
source = entity.position,
@ -352,17 +362,17 @@ local function on_player_mined_entity(event)
return
end
if math.random(1, 32) == 1 then
if random(1, 32) == 1 then
hidden_biter(event.entity)
entity.destroy()
return
end
if math.random(1, 512) == 1 then
if random(1, 512) == 1 then
hidden_worm(event.entity)
entity.destroy()
return
end
if math.random(1, 512) == 1 then
if random(1, 512) == 1 then
Traps(entity.surface, entity.position)
return
end
@ -411,14 +421,14 @@ end
local function get_damage(event)
local entity = event.entity
local damage = event.original_damage_amount + event.original_damage_amount * math.random(1, 100)
local damage = event.original_damage_amount + event.original_damage_amount * random(1, 100)
if entity.prototype.resistances then
if entity.prototype.resistances.physical then
damage = damage - entity.prototype.resistances.physical.decrease
damage = damage - damage * entity.prototype.resistances.physical.percent
end
end
damage = math.round(damage, 3)
damage = round(damage, 3)
if damage < 1 then
damage = 1
end
@ -438,25 +448,25 @@ local function kaboom(entity, target, damage)
{
name = 'flying-text',
position = {entity.position.x + base_vector[1] * 0.5, entity.position.y + base_vector[2] * 0.5},
text = msg[math.random(1, #msg)],
text = msg[random(1, #msg)],
color = {255, 0, 0}
}
)
if math.abs(vector[1]) > math.abs(vector[2]) then
local d = math.abs(vector[1])
if math.abs(vector[1]) > 0 then
if abs(vector[1]) > abs(vector[2]) then
local d = abs(vector[1])
if abs(vector[1]) > 0 then
vector[1] = vector[1] / d
end
if math.abs(vector[2]) > 0 then
if abs(vector[2]) > 0 then
vector[2] = vector[2] / d
end
else
local d = math.abs(vector[2])
if math.abs(vector[2]) > 0 then
local d = abs(vector[2])
if abs(vector[2]) > 0 then
vector[2] = vector[2] / d
end
if math.abs(vector[1]) > 0 and d > 0 then
if abs(vector[1]) > 0 and d > 0 then
vector[1] = vector[1] / d
end
end
@ -515,7 +525,7 @@ local function boss_puncher(event)
return
end
if math.random(1, 10) == 1 then
if random(1, 10) == 1 then
kaboom(cause, entity, get_damage(event))
end
end
@ -539,7 +549,7 @@ local function on_entity_damaged(event)
if munch_time then
if boss_wave_warning or wave_number >= 1500 then
if math.random(0, 512) == 1 then
if random(0, 512) == 1 then
boss_puncher(event)
end
end
@ -632,11 +642,17 @@ local function on_entity_died(event)
if entity.type == 'unit' or entity_type == 'unit-spawner' then
this.biters_killed = this.biters_killed + 1
end
if math.random(1, 64) == 1 then
hidden_biter(event.entity)
if random(1, 32) == 1 then
hidden_biter(entity)
entity.destroy()
return
end
if math.random(1, 512) == 1 then
if random(1, 368) == 1 then
hidden_worm(entity)
entity.destroy()
return
end
if random(1, 368) == 1 then
Traps(entity.surface, entity.position)
return
end
@ -667,7 +683,7 @@ function Public.set_scores()
if not loco.valid then
return
end
local score = math.floor(loco.position.y * -1)
local score = floor(loco.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)
@ -691,8 +707,10 @@ function Public.loco_died()
data.position = {x = 0, y = 0}
end
local msg = mapkeeper .. defeated_messages[math.random(1, #defeated_messages)] .. '\nBetter luck next time.'
Alert.alert_all_players_location(data, msg)
this.survival_time = game.tick - this.last_reset
local msg = mapkeeper .. defeated_messages[random(1, #defeated_messages)] .. '\nBetter luck next time.'
Alert.alert_all_players_location(data, msg, nil, 6000)
Reset_map()
return
end
@ -711,12 +729,12 @@ function Public.loco_died()
if this.soft_reset then
msg =
mapkeeper ..
defeated_messages[math.random(1, #defeated_messages)] ..
defeated_messages[random(1, #defeated_messages)] ..
'\nBetter luck next time.\nGame will soft-reset shortly.'
else
msg =
mapkeeper ..
defeated_messages[math.random(1, #defeated_messages)] ..
defeated_messages[random(1, #defeated_messages)] ..
'\nBetter luck next time.\nGame will not soft-reset. Soft-reset is disabled.'
end
local pos = {

View File

@ -20,10 +20,11 @@ Global.register(
)
local Public = {}
local random = math.random
local floor = math.floor
local sqrt = math.sqrt
local magic_crafters_per_tick = 3
local magic_fluid_crafters_per_tick = 8
local floor = math.floor
local artillery_target_entities = {
'character',
@ -270,7 +271,7 @@ local function do_artillery_turrets_targets()
local position = turret.position
for i = 1, count do
local entity = entities[math.random(#entities)]
local entity = entities[random(#entities)]
if entity and entity.valid then
local data = {position = position, entity = entity}
Task.set_timeout_in_ticks(i * 60, artillery_target_callback, data)
@ -487,7 +488,7 @@ Public.magic_item_crafting_callback =
local p = entity.position
local x, y = p.x, p.y
local distance = math.sqrt(x * x + y * y)
local distance = sqrt(x * x + y * y)
local output = callback_data.output
if #output == 0 then
@ -519,7 +520,7 @@ Public.magic_item_crafting_callback_weighted =
local p = entity.position
local i = math.random() * weights.total
local i = random() * weights.total
local index = table.binary_search(weights, i)
if (index < 0) then
@ -543,7 +544,7 @@ Public.magic_item_crafting_callback_weighted =
end
local x, y = p.x, p.y
local distance = math.sqrt(x * x + y * y)
local distance = sqrt(x * x + y * y)
local output = stack.output
if #output == 0 then
@ -584,7 +585,7 @@ function Public.do_random_loot(entity, weights, loot)
entity.operable = false
--entity.destructible = false
local i = math.random() * weights.total
local i = random() * weights.total
local index = table.binary_search(weights, i)
if (index < 0) then
@ -601,7 +602,7 @@ function Public.do_random_loot(entity, weights, loot)
if df then
local p = entity.position
local x, y = p.x, p.y
local d = math.sqrt(x * x + y * y)
local d = sqrt(x * x + y * y)
count = stack.count + d * df
else

View File

@ -5,14 +5,17 @@ local Token = require 'utils.token'
local Event = require 'utils.event'
local Terrain = require 'maps.mountain_fortress_v3.terrain'.heavy_functions
local Public = {}
local random = math.random
local abs = math.abs
local ceil = math.ceil
local queue_task = Task.queue_task
local tiles_per_call = 8
local total_calls = math.ceil(1024 / tiles_per_call)
local total_calls = ceil(1024 / tiles_per_call)
local regen_decoratives = false
local force_chunk = false
local Public = {}
-- Set to false by modules that want to control the on_chunk_generated event themselves.
Public.enable_register_events = true
@ -174,7 +177,7 @@ local function do_place_treasure(data)
pcall(
function()
for _, e in ipairs(data.treasure) do
if math.random(1, 6) == 1 then
if random(1, 6) == 1 then
e.chest = 'iron-chest'
end
Loot.add(surface, e.position, e.chest)
@ -193,7 +196,7 @@ local function do_place_markets(data)
pcall(
function()
local pos = markets[math.random(1, #markets)]
local pos = markets[random(1, #markets)]
if
surface.count_entities_filtered {
area = {{pos.x - 96, pos.y - 96}, {pos.x + 96, pos.y + 96}},
@ -201,7 +204,7 @@ local function do_place_markets(data)
limit = 1
} == 0
then
local market = Market.mountain_market(surface, pos, math.abs(pos.y) * 0.004)
local market = Market.mountain_market(surface, pos, abs(pos.y) * 0.004)
market.destructible = false
end
end

View File

@ -7,6 +7,7 @@ local format_number = require 'util'.format_number
local Public = {}
local main_button_name = Gui.uid_name()
local main_frame_name = Gui.uid_name()
local floor = math.floor
local function validate_player(player)
if not player then
@ -307,9 +308,9 @@ function Public.update_gui(player)
gui.global_pool.caption = 'XP: 0'
gui.global_pool.tooltip = 'Dig, handcraft or run to increase the pool!'
elseif rpg_extra.global_pool >= 0 then
gui.global_pool.caption = 'XP: ' .. format_number(math.floor(rpg_extra.global_pool), true)
gui.global_pool.caption = 'XP: ' .. format_number(floor(rpg_extra.global_pool), true)
gui.global_pool.tooltip =
'Amount of XP that is stored inside the global xp pool.\nRaw Value: ' .. math.floor(rpg_extra.global_pool)
'Amount of XP that is stored inside the global xp pool.\nRaw Value: ' .. floor(rpg_extra.global_pool)
end
gui.scrap_mined.caption = ' [img=entity.tree-01][img=entity.rock-huge]: ' .. format_number(this.mined_scrap, true)

View File

@ -1,5 +1,7 @@
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
local Task = require 'utils.task'
local Token = require 'utils.token'
local Public = {}
@ -21,10 +23,44 @@ local function upperCase(str)
return (str:gsub('^%l', string.upper))
end
local function has_no_entity(t, entity)
for k, car in pairs(t) do
local unit_number = entity.unit_number
if car.name ~= entity.name then
local function kill_doors(ic, car)
if not validate_entity(car.entity) then
return
end
for k, e in pairs(car.doors) do
ic.doors[e.unit_number] = nil
e.destroy()
car.doors[k] = nil
end
end
local function get_owner_car_object(cars, player)
for k, car in pairs(cars) do
if car.owner == player.index then
return k
end
end
return false
end
local function get_owner_car_name(ic, player)
local cars = ic.cars
local saved_surfaces = ic.saved_surfaces
local index = saved_surfaces[player.index]
for k, car in pairs(cars) do
if not index then
return false
end
if car.owner == player.index then
return car.name
end
end
return false
end
local function get_saved_entity(cars, entity, index)
for k, car in pairs(cars) do
if index and index.name ~= entity.name then
local msg =
'The built entity is not the same as the saved one. ' ..
upperCase(car.name) .. ' is not equal to ' .. upperCase(entity.name) .. '.'
@ -49,6 +85,80 @@ local function replace_doors(t, saved, entity)
end
end
local function replace_surface(surfaces, entity, index)
if not validate_entity(entity) then
return
end
for k, surface in pairs(surfaces) do
local unit_number = entity.unit_number
if tostring(index.saved_entity) == surface.name then
if validate_entity(surface) then
surface.name = unit_number
surfaces[unit_number] = surface
surfaces[k] = nil
end
end
end
end
local function replace_surface_entity(cars, entity, index)
if not validate_entity(entity) then
return
end
for _, car in pairs(cars) do
local unit_number = entity.unit_number
if index and index.saved_entity == car.saved_entity then
if validate_entity(car.surface) then
car.surface.name = unit_number
end
end
end
end
local function remove_logistics(car)
local chests = car.transfer_entities
for k, chest in pairs(chests) do
car.transfer_entities[k] = nil
chest.destroy()
end
end
local function set_new_area(ic, car)
local new_area = ic.car_areas
local name = car.name
local apply_area = new_area[name]
car.area = apply_area
end
local function upgrade_surface(ic, player, entity)
local ce = entity
local saved_surfaces = ic.saved_surfaces
local cars = ic.cars
local door = ic.doors
local surfaces = ic.surfaces
local index = saved_surfaces[player.index]
if not index then
return
end
if saved_surfaces[player.index] then
local c = get_owner_car_object(cars, player)
local car = ic.cars[c]
car.name = 'tank'
set_new_area(ic, car)
remove_logistics(car)
replace_entity(cars, ce, index)
replace_doors(door, ce, index)
replace_surface(surfaces, ce, index)
replace_surface_entity(cars, ce, index)
kill_doors(ic, car)
Public.create_car_room(ic, car)
saved_surfaces[player.index] = nil
return true
end
return false
end
local function save_surface(ic, entity, player)
local car = ic.cars[entity.unit_number]
@ -242,6 +352,15 @@ local function get_player_data(ic, player)
return ic.players[player.index]
end
local remove_car =
Token.register(
function(data)
local player = data.player
local car = data.car
player.remove_item({name = car.name, count = 9999})
end
)
function Public.save_car(ic, event)
local entity = event.entity
if not validate_entity(entity) then
@ -270,8 +389,32 @@ function Public.save_car(ic, event)
if car.owner == player.index then
save_surface(ic, entity, player)
else
save_surface(ic, entity, game.players[car.owner])
Utils.action_warning('{Car}', player.name .. ' has looted ' .. game.players[car.owner].name .. '´s car.')
local p = game.players[car.owner]
if not p then
return
end
log_err(ic, 'Owner of this vehicle is: ' .. p.name)
save_surface(ic, entity, p)
Utils.action_warning('{Car}', player.name .. ' has looted ' .. p.name .. '´s car.')
player.print('This car was not yours to keep.', Color.warning)
player.remove_item({name = car.name, count = 9999})
local params = {
player = player,
car = car
}
Task.set_timeout_in_ticks(10, remove_car, params)
if ic.restore_on_theft then
local e =
player.surface.create_entity(
{name = car.name, position = position, force = player.force, create_build_effect_smoke = false}
)
e.health = health
restore_surface(ic, p, e)
else
p.insert({name = car.name, count = 1, health = health})
p.print('Your car was stolen from you - the gods foresaw this and granted you a new one.', Color.info)
end
end
end
@ -280,17 +423,6 @@ function Public.kill_car(ic, entity)
return
end
local function kill_doors(car)
if not validate_entity(car.entity) then
return
end
for k, e in pairs(car.doors) do
ic.doors[e.unit_number] = nil
e.destroy()
car.doors[k] = nil
end
end
local entity_type = ic.entity_type
if not entity_type[entity.name] then
@ -299,7 +431,7 @@ function Public.kill_car(ic, entity)
local car = ic.cars[entity.unit_number]
local surface = car.surface
kick_players_out_of_vehicles(car)
kill_doors(car)
kill_doors(ic, car)
kick_player_from_surface(car)
for _, tile in pairs(surface.find_tiles_filtered({area = car.area})) do
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
@ -341,7 +473,9 @@ end
function Public.create_car_room(ic, car)
local surface = car.surface
local area = car.area
local car_areas = ic.car_areas
local entity_name = car.name
local area = car_areas[entity_name]
local main_tile_name = 'black-refined-concrete'
@ -360,19 +494,10 @@ function Public.create_car_room(ic, car)
local fishes = {}
if car.name == 'car' then
for x = -3, 2, 1 do
for y = 2, 3, 1 do
tiles[#tiles + 1] = {name = 'water', position = {x, y}}
fishes[#fishes + 1] = {name = 'fish', position = {x, y}}
end
end
else
for x = -4, 3, 1 do
for y = 2, 4, 1 do
tiles[#tiles + 1] = {name = 'water', position = {x, y}}
fishes[#fishes + 1] = {name = 'fish', position = {x, y}}
end
for x = area.left_top.x, area.right_bottom.x - 1, 1 do
for y = -0, 1, 1 do
tiles[#tiles + 1] = {name = 'water', position = {x, y}}
fishes[#fishes + 1] = {name = 'fish', position = {x, y}}
end
end
@ -383,18 +508,14 @@ function Public.create_car_room(ic, car)
construct_doors(ic, car)
local entity_name = car.name
local car_areas = ic.car_areas
local c = car_areas[entity_name]
local lx, ly, rx, ry
if car.name == 'car' then
lx, ly, rx, ry = 4, 1, 5, 1
else
lx, ly, rx, ry = 4, 1, 5, 1
end
local position1 = {c.left_top.x + lx, c.left_top.y + ly}
local position2 = {c.right_bottom.x - rx, c.left_top.y + ry}
local position1 = {area.left_top.x + lx, area.left_top.y + ly}
local position2 = {area.right_bottom.x - rx, area.left_top.y + ry}
local e1 =
surface.create_entity(
@ -447,16 +568,18 @@ function Public.create_car(ic, event)
return
end
if saved_surfaces[player.index] then
local index = saved_surfaces[player.index]
local success, msg = has_no_entity(cars, created_entity)
if not success then
player.print(msg, Color.warning)
created_entity.destroy()
return
end
replace_doors(door, index, created_entity)
saved_surfaces[player.index] = nil
if string.sub(ce.surface.name, 0, #map_name) ~= map_name then
return player.print('Multi-surface is not supported at the moment.', Color.warning)
end
if get_owner_car_name(ic, player) == 'car' and ce.name == 'tank' then
upgrade_surface(ic, player, ce)
player.print('Your car-surface has been upgraded!', Color.success)
return
end
local saved_surface = restore_surface(ic, player, ce)
if saved_surface then
return
end
@ -482,13 +605,35 @@ function Public.create_car(ic, event)
local car = ic.cars[created_entity.unit_number]
car.surface = Public.create_room_surface(ic, created_entity.unit_number)
Public.create_car_room(ic, ic.cars[created_entity.unit_number])
car.surface = Public.create_room_surface(ic, un)
Public.create_car_room(ic, car)
Public.request_reconstruction(ic)
return car
end
function Public.remove_invalid_cars(ic)
for k, car in pairs(ic.cars) do
if type(car.entity) == 'boolean' then
return
end
if not validate_entity(car.entity) then
ic.cars[k] = nil
for key, value in pairs(ic.doors) do
if k == value then
ic.doors[key] = nil
end
end
end
end
for k, surface in pairs(ic.surfaces) do
if not ic.cars[tonumber(surface.name)] then
game.delete_surface(surface)
ic.surfaces[k] = nil
end
end
end
function Public.teleport_players_around(ic)
for _, player in pairs(game.connected_players) do
if not validate_player(player) then
@ -522,6 +667,9 @@ function Public.teleport_players_around(ic)
end
if car.entity.surface.name ~= player.surface.name then
if validate_entity(car.entity) and car.owner == player.index then
car.entity.minable = true
end
local surface = car.entity.surface
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
local position = {car.entity.position.x + x_vector, car.entity.position.y}
@ -598,48 +746,9 @@ function Public.use_door_with_entity(ic, player, door)
player_data.fallback_surface = car.entity.surface.index
player_data.fallback_position = {car.entity.position.x, car.entity.position.y}
if car.entity.surface.name ~= player.surface.name then
local surface = car.entity.surface
local x_vector = (door.position.x / math.abs(door.position.x)) * 2
local position = {car.entity.position.x + x_vector, car.entity.position.y}
local surface_position = surface.find_non_colliding_position('character', position, 128, 0.5)
if not position then
return
end
if not surface_position then
surface.request_to_generate_chunks({-20, 22}, 1)
if player.character and player.character.valid and player.character.driving then
if car.surface == player.surface then
player.character.driving = false
end
end
return
end
if car.entity.type == 'car' then
player.teleport(surface_position, surface)
player_data.state = 2
player.driving = true
else
player.teleport(surface_position, surface)
end
player_data.surface = surface.index
else
local surface = car.surface
local area = car.area
local x_vector = door.position.x - player.position.x
local position
if x_vector > 0 then
position = {area.left_top.x + 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
else
position = {area.right_bottom.x - 0.5, area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5)}
end
local p = surface.find_non_colliding_position('character', position, 128, 0.5)
if p then
player.teleport(p, surface)
else
player.teleport(position, surface)
end
player_data.surface = surface.index
local surface = car.surface
if validate_entity(car.entity) and car.owner == player.index then
car.entity.minable = false
end
end
@ -661,12 +770,13 @@ end
function Public.item_transfer(ic)
for _, car in pairs(ic.cars) do
if not validate_entity(car.entity) then
return
end
if car.transfer_entities then
for k, e in pairs(car.transfer_entities) do
transfer_functions[e.name](car, e)
if validate_entity(car.entity) then
if car.transfer_entities then
for k, e in pairs(car.transfer_entities) do
if validate_entity(e) then
transfer_functions[e.name](car, e)
end
end
end
end
end

View File

@ -75,8 +75,8 @@ local function on_tick()
Functions.item_transfer(ic)
end
if not ic.rebuild_tick then
return
if tick % 600 == 0 then
Functions.remove_invalid_cars(ic)
end
if ic.rebuild_tick ~= tick then
@ -98,5 +98,13 @@ 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_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
--[[ Event.add(
defines.events.on_player_joined_game,
function(e)
local p = game.get_player(e.player_index)
p.insert({name = 'car', count = 5})
p.insert({name = 'tank', count = 5})
end
)
]]
return Public

View File

@ -19,6 +19,12 @@ local Public = {}
local concat = table.concat
local main_frame_name = Gui.uid_name()
local rpg_main_frame = RPG_Settings.main_frame_name
local random = math.random
local floor = math.floor
local rad = math.rad
local sin = math.sin
local cos = math.cos
local ceil = math.ceil
local shopkeeper = '[color=blue]Shopkeeper:[/color]\n'
@ -172,7 +178,7 @@ local function property_boost(data)
local f = player.gui.left[rpg_main_frame]
local d = Gui.get_data(f)
if d.exp_gui and d.exp_gui.valid then
d.exp_gui.caption = math.floor(rpg[player.index].xp)
d.exp_gui.caption = floor(rpg[player.index].xp)
end
end
else
@ -258,7 +264,7 @@ local function refill_fish()
if not locomotive_cargo.valid then
return
end
locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = 'raw-fish', count = math.random(2, 5)})
locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = 'raw-fish', count = random(2, 5)})
end
local function set_locomotive_health()
@ -302,10 +308,10 @@ local function create_poison_cloud(position)
local surface = game.surfaces[active_surface_index]
local random_angles = {
math.rad(math.random(359)),
math.rad(math.random(359)),
math.rad(math.random(359)),
math.rad(math.random(359))
rad(random(359)),
rad(random(359)),
rad(random(359)),
rad(random(359))
}
surface.create_entity({name = 'poison-cloud', position = {x = position.x, y = position.y}})
@ -313,8 +319,8 @@ local function create_poison_cloud(position)
{
name = 'poison-cloud',
position = {
x = position.x + 12 * math.cos(random_angles[1]),
y = position.y + 12 * math.sin(random_angles[1])
x = position.x + 12 * cos(random_angles[1]),
y = position.y + 12 * sin(random_angles[1])
}
}
)
@ -322,8 +328,8 @@ local function create_poison_cloud(position)
{
name = 'poison-cloud',
position = {
x = position.x + 12 * math.cos(random_angles[2]),
y = position.y + 12 * math.sin(random_angles[2])
x = position.x + 12 * cos(random_angles[2]),
y = position.y + 12 * sin(random_angles[2])
}
}
)
@ -331,8 +337,8 @@ local function create_poison_cloud(position)
{
name = 'poison-cloud',
position = {
x = position.x + 12 * math.cos(random_angles[3]),
y = position.y + 12 * math.sin(random_angles[3])
x = position.x + 12 * cos(random_angles[3]),
y = position.y + 12 * sin(random_angles[3])
}
}
)
@ -340,8 +346,8 @@ local function create_poison_cloud(position)
{
name = 'poison-cloud',
position = {
x = position.x + 12 * math.cos(random_angles[4]),
y = position.y + 12 * math.sin(random_angles[4])
x = position.x + 12 * cos(random_angles[4]),
y = position.y + 12 * sin(random_angles[4])
}
}
)
@ -436,7 +442,7 @@ local function redraw_market_items(gui, player, search_text)
}
)
local slider_value = math.ceil(players[player.index].data.slider.slider_value)
local slider_value = ceil(players[player.index].data.slider.slider_value)
local items_table = gui.add({type = 'table', column_count = 6})
for item, data in pairs(Public.get_items()) do
@ -528,7 +534,7 @@ local function slider_changed(event)
if not slider_value then
return
end
slider_value = math.ceil(slider_value)
slider_value = ceil(slider_value)
this.players[player.index].data.text_input.text = slider_value
redraw_market_items(this.players[player.index].data.item_frame, player, this.players[player.index].data.search_text)
end
@ -743,7 +749,7 @@ local function gui_click(event)
local inventory = player.get_main_inventory()
local player_item_count = inventory.get_item_count(item.value)
local slider_value = math.ceil(data.slider.slider_value)
local slider_value = ceil(data.slider.slider_value)
local cost = (item.price * slider_value)
local item_count = item.stack * slider_value
@ -1026,7 +1032,7 @@ local function spawn_biter()
}
this.locomotive_biter =
loco_surface.create_entity(
{name = biters[math.random(1, 4)], position = position, force = 'player', create_build_effect_smoke = false}
{name = biters[random(1, 4)], position = position, force = 'player', create_build_effect_smoke = false}
)
this.locomotive_biter.ai_settings.allow_destroy_when_commands_fail = false
this.locomotive_biter.ai_settings.allow_try_return_to_spawner = false
@ -1108,9 +1114,9 @@ local function create_market(data, rebuild)
for x = center_position.x - 5, center_position.x + 5, 1 do
for y = center_position.y - 5, center_position.y + 5, 1 do
if math.random(1, 2) == 1 then
if random(1, 2) == 1 then
loco_surface.spill_item_stack(
{x + math.random(0, 9) * 0.1, y + math.random(0, 9) * 0.1},
{x + random(0, 9) * 0.1, y + random(0, 9) * 0.1},
{name = 'raw-fish', count = 1},
false
)
@ -1120,9 +1126,9 @@ local function create_market(data, rebuild)
end
for x = center_position.x - 3, center_position.x + 3, 1 do
for y = center_position.y - 3, center_position.y + 3, 1 do
if math.random(1, 2) == 1 then
if random(1, 2) == 1 then
loco_surface.spill_item_stack(
{x + math.random(0, 9) * 0.1, y + math.random(0, 9) * 0.1},
{x + random(0, 9) * 0.1, y + random(0, 9) * 0.1},
{name = 'raw-fish', count = 1},
false
)
@ -1340,7 +1346,7 @@ local function add_random_loot_to_main_market(rarity)
end
for k, v in pairs(items) do
local price = v.price[1][2] + math.random(1, 15) * rarity
local price = v.price[1][2] + random(1, 15) * rarity
local value = v.price[1][1]
local stack = 1
ticker = ticker + 1
@ -1609,17 +1615,17 @@ function Public.locomotive_spawn(surface, position)
)
for y = -1, 0, 0.05 do
local scale = math.random(50, 100) * 0.01
local scale = random(50, 100) * 0.01
rendering.draw_sprite(
{
sprite = 'item/raw-fish',
orientation = math.random(0, 100) * 0.01,
orientation = random(0, 100) * 0.01,
x_scale = scale,
y_scale = scale,
tint = {math.random(60, 255), math.random(60, 255), math.random(60, 255)},
tint = {random(60, 255), random(60, 255), random(60, 255)},
render_layer = 'selection-box',
target = this.locomotive_cargo,
target_offset = {-0.7 + math.random(0, 140) * 0.01, y},
target_offset = {-0.7 + random(0, 140) * 0.01, y},
surface = surface
}
)
@ -1901,9 +1907,9 @@ function Public.enable_poison_defense()
end
local pos = locomotive.position
create_poison_cloud({x = pos.x, y = pos.y})
if math.random(1, 3) == 1 then
local random_angles = {math.rad(math.random(359))}
create_poison_cloud({x = pos.x + 24 * math.cos(random_angles[1]), y = pos.y + -24 * math.sin(random_angles[1])})
if random(1, 3) == 1 then
local random_angles = {rad(random(359))}
create_poison_cloud({x = pos.x + 24 * cos(random_angles[1]), y = pos.y + -24 * sin(random_angles[1])})
end
end

View File

@ -1,6 +1,9 @@
local LootRaffle = require 'functions.loot_raffle'
local Public = {}
local random = math.random
local abs = math.abs
local floor = math.floor
local blacklist = {
['atomic-bomb'] = true,
@ -11,19 +14,19 @@ local blacklist = {
}
function Public.add(surface, position, chest)
local budget = 48 + math.abs(position.y) * 1.75
budget = budget * math.random(25, 175) * 0.01
local budget = 48 + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01
if math.random(1, 128) == 1 then
if random(1, 128) == 1 then
budget = budget * 4
chest = 'crash-site-chest-' .. math.random(1, 2)
chest = 'crash-site-chest-' .. random(1, 2)
end
if math.random(1, 256) == 1 then
if random(1, 256) == 1 then
budget = budget * 4
chest = 'crash-site-chest-' .. math.random(1, 2)
chest = 'crash-site-chest-' .. random(1, 2)
end
budget = math.floor(budget) + 1
budget = floor(budget) + 1
local item_stacks = LootRaffle.roll(budget, 8, blacklist)
local container = surface.create_entity({name = chest, position = position, force = 'neutral'})
@ -33,8 +36,8 @@ function Public.add(surface, position, chest)
container.minable = false
for _ = 1, 3, 1 do
if math.random(1, 8) == 1 then
container.insert({name = 'explosives', count = math.random(25, 50)})
if random(1, 8) == 1 then
container.insert({name = 'explosives', count = random(25, 50)})
else
break
end
@ -42,19 +45,19 @@ function Public.add(surface, position, chest)
end
function Public.add_rare(surface, position, chest, magic)
local budget = magic * 48 + math.abs(position.y) * 1.75
budget = budget * math.random(25, 175) * 0.01
local budget = magic * 48 + abs(position.y) * 1.75
budget = budget * random(25, 175) * 0.01
if math.random(1, 128) == 1 then
if random(1, 128) == 1 then
budget = budget * 6
chest = 'crash-site-chest-' .. math.random(1, 2)
chest = 'crash-site-chest-' .. random(1, 2)
end
if math.random(1, 128) == 1 then
if random(1, 128) == 1 then
budget = budget * 6
chest = 'crash-site-chest-' .. math.random(1, 2)
chest = 'crash-site-chest-' .. random(1, 2)
end
budget = math.floor(budget) + 1
budget = floor(budget) + 1
local item_stacks = LootRaffle.roll(budget, 8, blacklist)
local container = surface.create_entity({name = chest, position = position, force = 'neutral'})
@ -64,8 +67,8 @@ function Public.add_rare(surface, position, chest, magic)
container.minable = false
for _ = 1, 3, 1 do
if math.random(1, 8) == 1 then
container.insert({name = 'explosives', count = math.random(25, 50)})
if random(1, 8) == 1 then
container.insert({name = 'explosives', count = random(25, 50)})
else
break
end

View File

@ -48,6 +48,8 @@ local AntiGrief = require 'antigrief'
--local HD = require 'modules.hidden_dimension.main'
local Public = {}
local floor = math.floor
local insert = table.insert
-- local raise_event = script.raise_event
local starting_items = {['pistol'] = 1, ['firearm-magazine'] = 16, ['rail'] = 16, ['wood'] = 16, ['explosives'] = 32}
@ -103,10 +105,10 @@ local set_difficulty = function()
-- threat gain / wave
wave_defense_table.threat_gain_multiplier = 1.2 + player_count * Diff.difficulty_vote_value * 0.1
local amount = player_count * 0.25 + 2
amount = math.floor(amount)
if amount > 8 then
amount = 8
local amount = player_count * 0.25 + 6
amount = floor(amount)
if amount > 10 then
amount = 10
end
local difficulty = Difficulty.get()
local name = difficulty.difficulties[difficulty.difficulty_vote_index].name
@ -378,6 +380,8 @@ function Public.reset_map()
WD.alert_boss_wave(true)
WD.clear_corpses(false)
WD.remove_entities(true)
WD.enable_threat_log(true)
WD.check_collapse_position(true)
set_difficulty()
@ -649,8 +653,6 @@ local has_the_game_ended = function()
cause_msg = 'soft-reset'
end
this.game_reset = true
this.game_has_ended = true
game.print(
'Game will ' .. cause_msg .. ' in ' .. this.game_reset_tick / 60 .. ' seconds!',
{r = 0.22, g = 0.88, b = 0.22}
@ -908,7 +910,7 @@ local on_init = function()
this.rocks_yield_ore_maximum_amount = 500
this.type_modifier = 1
this.rocks_yield_ore_base_amount = 50
this.rocks_yield_ore_base_amount = 100
this.rocks_yield_ore_distance_modifier = 0.025
local T = Map.Pop_info()

View File

@ -1,6 +1,9 @@
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = {}
local random = math.random
local floor = math.floor
local sqrt = math.sqrt
local max_spill = 60
@ -25,8 +28,8 @@ local particles = {
}
local function create_particles(surface, name, position, amount, cause_position)
local d1 = (-100 + math.random(0, 200)) * 0.0004
local d2 = (-100 + math.random(0, 200)) * 0.0004
local d1 = (-100 + random(0, 200)) * 0.0004
local d2 = (-100 + random(0, 200)) * 0.0004
if cause_position then
d1 = (cause_position.x - position.x) * 0.025
@ -34,7 +37,7 @@ local function create_particles(surface, name, position, amount, cause_position)
end
for i = 1, amount, 1 do
local m = math.random(4, 10)
local m = random(4, 10)
local m2 = m * 0.005
surface.create_particle(
@ -45,8 +48,8 @@ local function create_particles(surface, name, position, amount, cause_position)
vertical_speed = 0.130,
height = 0,
movement = {
(m2 - (math.random(0, m) * 0.01)) + d1,
(m2 - (math.random(0, m) * 0.01)) + d2
(m2 - (random(0, m) * 0.01)) + d1,
(m2 - (random(0, m) * 0.01)) + d2
}
}
)
@ -82,7 +85,7 @@ local size_of_ore_raffle = #harvest_raffle_ores
local function get_amount(data)
local entity = data.entity
local this = data.this
local distance_to_center = math.floor(math.sqrt(entity.position.x ^ 2 + entity.position.y ^ 2))
local distance_to_center = floor(sqrt(entity.position.x ^ 2 + entity.position.y ^ 2))
local type_modifier
local amount
local second_amount
@ -108,7 +111,7 @@ local function get_amount(data)
type_modifier = rock_yield[entity.name] or type_modifier
amount = base_amount + (distance_to_center * distance_modifier)
second_amount = math.floor((second_base_amount + (distance_to_center * distance_modifier)) / 3)
second_amount = floor((second_base_amount + (distance_to_center * distance_modifier)) / 3)
if amount > maximum_amount then
amount = maximum_amount
end
@ -116,9 +119,9 @@ local function get_amount(data)
second_amount = maximum_amount
end
local m = (70 + math.random(0, 60)) * 0.01
local m = (70 + random(0, 60)) * 0.01
amount = math.floor(amount * type_modifier * m * 0.7)
amount = floor(amount * type_modifier * m * 0.7)
return amount, second_amount
end
@ -128,11 +131,11 @@ function Public.entity_died_randomness(data)
local surface = data.surface
local harvest
harvest = harvest_raffle_ores[math.random(1, size_of_ore_raffle)]
harvest = harvest_raffle_ores[random(1, size_of_ore_raffle)]
local position = {x = entity.position.x, y = entity.position.y}
surface.spill_item_stack(position, {name = harvest, count = math.random(1, 5)}, true)
surface.spill_item_stack(position, {name = harvest, count = random(1, 5)}, true)
local particle = particles[harvest]
create_particles(surface, particle, position, 64, {x = entity.position.x, y = entity.position.y})
end
@ -161,14 +164,14 @@ local function randomness(data)
if fullness == 0 then
if player.character then
player.character.health = player.character.health - math.random(50, 100)
player.character.health = player.character.health - random(50, 100)
player.character.surface.create_entity({name = 'water-splash', position = player.position})
local messages = {
'Ouch.. That hurt! Better be careful now.',
'Just a fleshwound.',
'Better keep those hands to yourself or you might loose them.'
}
player.print(messages[math.random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0})
player.print(messages[random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0})
if player.character.health <= 0 then
player.character.die('enemy')
game.print(player.name .. ' should have emptied their pockets.', {r = 0.75, g = 0.0, b = 0.0})
@ -179,7 +182,7 @@ local function randomness(data)
::continue::
harvest = harvest_raffle_ores[math.random(1, size_of_ore_raffle)]
harvest = harvest_raffle_ores[random(1, size_of_ore_raffle)]
harvest_amount = get_amount(data)
local position = {x = entity.position.x, y = entity.position.y}

View File

@ -1,5 +1,8 @@
local Functions = require 'maps.mountain_fortress_v3.functions'
local random = math.random
local abs = math.abs
local types = {
'assembling-machine',
'furnace'
@ -494,46 +497,46 @@ local buildings = {
}
local function spawn_random_buildings(entities, p, depth)
local randomizer = math.random(1, #buildings)
local low = math.random(1, 2)
local medium = math.random(2, 3)
local randomizer = random(1, #buildings)
local low = random(1, 2)
local medium = random(2, 3)
local high = 3
if math.abs(p.y) < depth * 1.5 then
if math.random(1, 16) == 1 then
if abs(p.y) < depth * 1.5 then
if random(1, 16) == 1 then
return buildings[randomizer](entities, p, medium)
else
return buildings[randomizer](entities, p, low)
end
elseif math.abs(p.y) < depth * 2.5 then
if math.random(1, 8) == 1 then
elseif abs(p.y) < depth * 2.5 then
if random(1, 8) == 1 then
return buildings[randomizer](entities, p, medium)
else
return buildings[randomizer](entities, p, medium)
end
elseif math.abs(p.y) < depth * 3.5 then
if math.random(1, 4) == 1 then
elseif abs(p.y) < depth * 3.5 then
if random(1, 4) == 1 then
return buildings[randomizer](entities, p, high)
else
return buildings[randomizer](entities, p, medium)
end
elseif math.abs(p.y) < depth * 4.5 then
if math.random(1, 4) == 1 then
elseif abs(p.y) < depth * 4.5 then
if random(1, 4) == 1 then
return buildings[randomizer](entities, p, high)
else
return buildings[randomizer](entities, p, high)
end
elseif math.abs(p.y) < depth * 5.5 then
if math.random(1, 4) == 1 then
elseif abs(p.y) < depth * 5.5 then
if random(1, 4) == 1 then
return buildings[randomizer](entities, p, high)
elseif math.random(1, 2) == 1 then
elseif random(1, 2) == 1 then
return buildings[randomizer](entities, p, high)
elseif math.random(1, 8) == 1 then
elseif random(1, 8) == 1 then
return buildings[randomizer](entities, p, high)
end
end
if math.abs(p.y) > depth * 5.5 then
if math.random(1, 32) == 1 then
if abs(p.y) > depth * 5.5 then
if random(1, 32) == 1 then
return buildings[randomizer](entities, p, medium)
end
end

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
local Event = require 'utils.event'
local WPT = require 'maps.mountain_fortress_v3.table'
local random = math.random
local tick_tacks = {'*tick*', '*tick*', '*tack*', '*tak*', '*tik*', '*tok*', '( ͡° ͜ʖ ͡°)'}
local kaboom_weights = {
@ -88,7 +90,7 @@ local function tick_tack_trap(surface, position)
return
end
local traps = WPT.get('traps')
local tick_tack_count = math.random(5, 9)
local tick_tack_count = random(5, 9)
for t = 60, tick_tack_count * 60, 60 do
if not traps[game.tick + t] then
traps[game.tick + t] = {}
@ -97,10 +99,10 @@ local function tick_tack_trap(surface, position)
if t < tick_tack_count * 60 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, tick_tacks[math.random(1, #tick_tacks)]}
params = {surface, {x = position.x, y = position.y}, tick_tacks[random(1, #tick_tacks)]}
}
else
if math.random(1, 10) == 1 then
if random(1, 10) == 1 then
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_flying_text',
params = {surface, {x = position.x, y = position.y}, '( ͡° ͜ʖ ͡°)'}
@ -108,7 +110,7 @@ local function tick_tack_trap(surface, position)
else
traps[game.tick + t][#traps[game.tick + t] + 1] = {
callback = 'create_kaboom',
params = {surface, {x = position.x, y = position.y}, kabooms[math.random(1, #kabooms)]}
params = {surface, {x = position.x, y = position.y}, kabooms[random(1, #kabooms)]}
}
end
end

View File

@ -554,10 +554,7 @@ local function on_tick()
for _, player in pairs(game.connected_players) do update_gui(player) end
end
local function on_init()
local wave_defense_table = WD.get_table()
wave_defense_table.reset_wave_defense()
end
Event.on_nth_tick(30, on_tick)
event.on_nth_tick(30, on_tick)
return Public

View File

@ -220,9 +220,10 @@ end
---@param player LuaPlayer
---@param message string
---@param color string
function Public.alert_all_players_location(player, message, color)
function Public.alert_all_players_location(player, message, color, duration)
local length = duration or 15
Public.alert_all_players_template(
15,
length,
function(container)
local sprite =
container.add {

View File

@ -81,6 +81,17 @@ local noises = {
{modifier = 0.009, weight = 1},
{modifier = 0.05, weight = 0.25},
{modifier = 0.25, weight = 0.05}
},
['forest_location'] = {
{modifier = 0.006, weight = 1},
{modifier = 0.01, weight = 0.25},
{modifier = 0.05, weight = 0.15},
{modifier = 0.1, weight = 0.05}
},
['forest_density'] = {
{modifier = 0.01, weight = 1},
{modifier = 0.05, weight = 0.5},
{modifier = 0.1, weight = 0.025}
}
}