2020-04-24 21:07:41 +02:00
|
|
|
local Chrono_table = require 'maps.chronosphere.table'
|
2020-05-18 22:21:11 +02:00
|
|
|
local Balance = require 'maps.chronosphere.balance'
|
2020-02-14 22:06:52 +02:00
|
|
|
local Public = {}
|
2020-04-14 09:51:09 +02:00
|
|
|
local Upgrades = require "maps.chronosphere.upgrade_list"
|
2020-02-14 22:06:52 +02:00
|
|
|
local math_floor = math.floor
|
|
|
|
local math_random = math.random
|
2020-03-05 16:56:59 +02:00
|
|
|
local function math_sgn(x)
|
|
|
|
return (x<0 and -1) or 1
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
|
2020-02-21 07:25:19 +02:00
|
|
|
function Public.locomotive_spawn(surface, position, wagons)
|
2020-04-27 00:15:58 +02:00
|
|
|
surface.request_to_generate_chunks(position, 0.5)
|
2020-04-26 15:43:59 +02:00
|
|
|
surface.force_generate_chunk_requests()
|
2020-04-24 21:07:41 +02:00
|
|
|
local objective = Chrono_table.get_table()
|
2020-05-18 22:21:11 +02:00
|
|
|
if objective.planet[1].type.id == 17 then --fish market
|
2020-02-21 23:58:14 +02:00
|
|
|
position.x = position.x - 960
|
|
|
|
position.y = position.y - 64
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
for y = -10, 18, 2 do
|
2020-02-17 01:46:22 +02:00
|
|
|
local rail = {name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0}
|
2020-02-14 22:06:52 +02:00
|
|
|
surface.create_entity({name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0})
|
|
|
|
end
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -6}, force = "player"})
|
|
|
|
objective.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100})
|
2020-03-05 16:56:59 +02:00
|
|
|
for i = 1, 3, 1 do
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.locomotive_cargo[i] = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + math_floor((i - 1) * 6.5)}, force = "player"})
|
|
|
|
local inv = objective.locomotive_cargo[i].get_inventory(defines.inventory.cargo_wagon)
|
2020-03-14 13:01:17 +02:00
|
|
|
if wagons[i].bar > 0 then inv.set_bar(wagons[i].bar) end
|
|
|
|
for ii = 1, 40, 1 do
|
|
|
|
inv.set_filter(ii, wagons[i].filters[ii])
|
|
|
|
if wagons[i].inventory[ii] then
|
|
|
|
inv.insert(wagons[i].inventory[ii])
|
|
|
|
end
|
2020-03-05 16:56:59 +02:00
|
|
|
end
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.locomotive_cargo[i].minable = false
|
2020-02-21 07:25:19 +02:00
|
|
|
end
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.locomotive_cargo[1].operable = false
|
|
|
|
objective.locomotive.color = {0, 255, 0}
|
|
|
|
objective.locomotive.minable = false
|
2020-02-14 22:06:52 +02:00
|
|
|
|
2020-04-24 21:07:41 +02:00
|
|
|
--if not objective.comfychests then objective.comfychests = {} end
|
2020-05-18 22:21:11 +02:00
|
|
|
--if not objective.accumulators then objective.accumulators = {} end
|
2020-02-14 22:06:52 +02:00
|
|
|
for i = 1, 24, 1 do
|
|
|
|
local yi = 0
|
|
|
|
local xi = 5
|
|
|
|
if i > 20 then
|
|
|
|
yi = 6 - 12
|
|
|
|
xi = 5
|
|
|
|
elseif i > 16 then
|
|
|
|
yi = 6 - 15
|
|
|
|
xi = 5
|
|
|
|
elseif i > 12 then
|
|
|
|
xi = 5
|
|
|
|
yi = 6 - 18
|
|
|
|
elseif i > 8 then
|
|
|
|
yi = 6
|
|
|
|
xi = 0
|
|
|
|
elseif i > 4 then
|
|
|
|
yi = 3
|
|
|
|
xi = 0
|
|
|
|
else
|
|
|
|
yi = 0
|
|
|
|
xi = 0
|
|
|
|
end
|
|
|
|
|
2020-05-19 17:08:10 +02:00
|
|
|
local comfychest = surface.create_entity({name = "blue-chest", position = {position.x - 2 + xi, position.y - 2 + yi + i}, force = "player"})
|
2020-02-14 22:06:52 +02:00
|
|
|
comfychest.minable = false
|
|
|
|
--comfychest.destructible = false
|
2020-04-24 21:07:41 +02:00
|
|
|
if not objective.comfychests[i] then
|
|
|
|
table.insert(objective.comfychests, comfychest)
|
2020-02-14 22:06:52 +02:00
|
|
|
else
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.comfychests[i] = comfychest
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rendering.draw_light({
|
|
|
|
sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0,
|
2020-04-24 21:07:41 +02:00
|
|
|
oriented = true, color = {255,255,255}, target = objective.locomotive,
|
2020-02-14 22:06:52 +02:00
|
|
|
surface = surface, visible = true, only_in_alt_mode = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
rendering.draw_light({
|
|
|
|
sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0,
|
2020-04-24 21:07:41 +02:00
|
|
|
oriented = true, color = {255,255,255}, target = objective.locomotive_cargo[3],
|
2020-02-14 22:06:52 +02:00
|
|
|
surface = surface, visible = true, only_in_alt_mode = false,
|
|
|
|
})
|
|
|
|
|
2020-03-05 16:56:59 +02:00
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Public.fish_tag()
|
2020-04-24 21:07:41 +02:00
|
|
|
local objective = Chrono_table.get_table()
|
|
|
|
if not objective.locomotive_cargo[1] then return end
|
|
|
|
local cargo = objective.locomotive_cargo[1]
|
2020-03-05 16:56:59 +02:00
|
|
|
if not cargo.valid then return end
|
|
|
|
if not cargo.surface then return end
|
|
|
|
if not cargo.surface.valid then return end
|
2020-04-24 21:07:41 +02:00
|
|
|
if objective.locomotive_tag then
|
|
|
|
if objective.locomotive_tag.valid then
|
|
|
|
if objective.locomotive_tag.position.x == cargo.position.x and objective.locomotive_tag.position.y == cargo.position.y then return end
|
|
|
|
objective.locomotive_tag.destroy()
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
end
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.locomotive_tag = cargo.force.add_chart_tag(
|
2020-03-05 16:56:59 +02:00
|
|
|
cargo.surface,
|
2020-02-14 22:06:52 +02:00
|
|
|
{icon = {type = 'item', name = 'raw-fish'},
|
2020-03-05 16:56:59 +02:00
|
|
|
position = cargo.position,
|
2020-02-14 22:06:52 +02:00
|
|
|
text = " "
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-03-05 16:56:59 +02:00
|
|
|
function Public.create_wagon_room()
|
2020-04-24 21:07:41 +02:00
|
|
|
local objective = Chrono_table.get_table()
|
2020-02-14 22:06:52 +02:00
|
|
|
local width = 64
|
|
|
|
local height = 384
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.comfychests2 = {}
|
2020-05-18 22:21:11 +02:00
|
|
|
objective.accumulators = {}
|
2020-02-14 22:06:52 +02:00
|
|
|
local map_gen_settings = {
|
|
|
|
["width"] = width,
|
2020-02-17 01:46:22 +02:00
|
|
|
["height"] = height + 128,
|
2020-02-14 22:06:52 +02:00
|
|
|
["water"] = 0,
|
|
|
|
["starting_area"] = 1,
|
|
|
|
["cliff_settings"] = {cliff_elevation_interval = 0, cliff_elevation_0 = 0},
|
|
|
|
["default_enable_all_autoplace_controls"] = true,
|
|
|
|
["autoplace_settings"] = {
|
|
|
|
["entity"] = {treat_missing_as_default = false},
|
|
|
|
["tile"] = {treat_missing_as_default = true},
|
|
|
|
["decorative"] = {treat_missing_as_default = false},
|
|
|
|
},
|
|
|
|
}
|
2020-03-05 16:56:59 +02:00
|
|
|
if not game.surfaces["cargo_wagon"] then game.create_surface("cargo_wagon", map_gen_settings) end
|
|
|
|
local surface = game.surfaces["cargo_wagon"]
|
2020-02-14 22:06:52 +02:00
|
|
|
surface.freeze_daytime = true
|
|
|
|
surface.daytime = 0.1
|
|
|
|
surface.request_to_generate_chunks({0,0}, 12)
|
|
|
|
surface.force_generate_chunk_requests()
|
2020-02-17 18:37:22 +02:00
|
|
|
local carfpos = {
|
|
|
|
[1]={x=-33,y=-127},[2]={x=-33,y=-128},[3]={x=-33,y=-129},[4]={x=-33,y=-130},[5]={x=32,y=-127},[6]={x=32,y=-128},[7]={x=32,y=-129},[8]={x=32,y=-130},
|
|
|
|
[9]={x=-33,y=-2},[10]={x=-33,y=-1},[11]={x=-33,y=0},[12]={x=-33,y=1},[13]={x=32,y=-2},[14]={x=32,y=-1},[15]={x=32,y=0},[16]={x=32,y=1},
|
|
|
|
[17]={x=-33,y=126},[18]={x=-33,y=127},[19]={x=-33,y=128},[20]={x=-33,y=129},[21]={x=32,y=126},[22]={x=32,y=127},[23]={x=32,y=128},[24]={x=32,y=129}
|
|
|
|
}
|
|
|
|
for i = 1, 24, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {carfpos[i].x,carfpos[i].y}}})
|
|
|
|
end
|
2020-02-21 00:19:00 +02:00
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
for x = width * -0.5, width * 0.5 - 1, 1 do
|
2020-02-17 01:46:22 +02:00
|
|
|
for y = height * 0.5, height * 0.7, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * -0.7, height * -0.5, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
for y = height * -0.5 + 3, height * 0.5 - 4, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * -0.16 - 5, height * -0.16 + 0, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * 0.16 - 0, height * 0.16 + 5, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * -0.5, height * -0.5 + 2, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * 0.5 - 3, height * 0.5, 1 do
|
|
|
|
surface.set_tiles({{name = "out-of-map", position = {x,y}}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for x = width * -0.2 + 1, width * 0.2 - 1, 1 do
|
|
|
|
for y = height * -0.16 - 5, height * -0.16 + 0, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
end
|
|
|
|
for y = height * 0.16 -0, height * 0.16 + 5, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
end
|
|
|
|
--for y = height * -0.5 -5, height * -0.5 + 3, 1 do
|
|
|
|
-- surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
--end
|
|
|
|
end
|
|
|
|
|
|
|
|
for x = width * -0.5 + 5, width * 0.5 - 6, 1 do
|
|
|
|
for y = height * -0.7 + 18, height * -0.5 - 5, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-21 00:19:00 +02:00
|
|
|
for x = width * -0.5 - 6, width * -0.5 + 3, 1 do -- combinators
|
|
|
|
for y = -251, -241, 1 do
|
|
|
|
surface.set_tiles({{name = "tutorial-grid", position = {x,y}}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
for x = width * -0.4 + 6, width * 0.4 - 6, 1 do
|
|
|
|
for y = height * -0.5 + 7, height * -0.5 + 10, 1 do
|
|
|
|
local p = {x,y}
|
|
|
|
surface.set_tiles({{name = "water", position = p}})
|
2020-05-18 22:21:11 +02:00
|
|
|
if math_random(1, 3) == 1 and (x ~= width * -0.4 + 6) and (y ~= height * -0.5 + 7) then surface.create_entity({name = "fish", position = p}) end
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-21 00:19:00 +02:00
|
|
|
local combinators = {}
|
|
|
|
for x = width * -0.5 - 6, width * -0.5 + 3, 1 do
|
|
|
|
for y = -250, -244, 2 do
|
|
|
|
combinators[#combinators + 1] = {name = "arithmetic-combinator", position = {x, y}, force = "player", create_build_effect_smoke = false}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local combimade = {}
|
|
|
|
for i = 1, #combinators, 1 do
|
|
|
|
combimade[i] = surface.create_entity(combinators[i])
|
|
|
|
combimade[i].minable = false
|
|
|
|
combimade[i].destructible = false
|
|
|
|
combimade[i].operable = false
|
|
|
|
|
|
|
|
if i > 1 then
|
|
|
|
combimade[i].connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[i - 1], source_circuit_id = 2, target_circuit_id = 1})
|
|
|
|
local rule = combimade[i].get_or_create_control_behavior()
|
|
|
|
rule.parameters = {parameters = {first_signal = {type = "virtual", name = "signal-A"}, second_constant = 0, operation = "+", output_signal = {type = "virtual", name = "signal-A"}}}
|
|
|
|
else
|
|
|
|
local rule2 = combimade[i].get_or_create_control_behavior()
|
|
|
|
rule2.parameters = {parameters = {first_signal = {type = "virtual", name = "signal-A"}, second_constant = 0, operation = "+", output_signal = {type = "virtual", name = "signal-B"}}}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local checker = surface.create_entity({name = "decider-combinator", position = {x = width * -0.5 - 6, y = -242}, force = "player", create_build_effect_smoke = false })
|
|
|
|
local rules3 = checker.get_or_create_control_behavior()
|
|
|
|
rules3.parameters = {parameters = {first_signal = {type = "virtual", name = "signal-A"}, second_signal = {type = "virtual", name = "signal-B"}, comparator = ">",
|
|
|
|
output_signal = {type = "virtual", name = "signal-C"}, copy_count_from_input = false }}
|
|
|
|
local combipower = surface.create_entity({name = "substation", position = {x = width * -0.5 - 4, y = -242}, force="player", create_build_effect_smoke = false})
|
|
|
|
combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 1})
|
|
|
|
combipower.connect_neighbour({wire = defines.wire_type.green, target_entity = combimade[#combimade], target_circuit_id = 1})
|
|
|
|
combimade[1].connect_neighbour({wire = defines.wire_type.green, target_entity = checker, source_circuit_id = 2, target_circuit_id = 1})
|
|
|
|
local speaker = surface.create_entity({name = "programmable-speaker", position = {x = width * -0.5 - 6, y = -241}, force = "player", create_build_effect_smoke = false,
|
2020-02-24 01:39:58 +02:00
|
|
|
parameters = {playback_volume = 0.6, playback_globally = true, allow_polyphony = false},
|
2020-02-21 00:19:00 +02:00
|
|
|
alert_parameters = {show_alert = true, show_on_map = true, icon_signal_id = {type = "item", name = "accumulator"}, alert_message = "Train Is Charging!" }})
|
|
|
|
speaker.connect_neighbour({wire = defines.wire_type.green, target_entity = checker, target_circuit_id = 2})
|
|
|
|
local rules4 = speaker.get_or_create_control_behavior()
|
|
|
|
rules4.circuit_condition = {condition = {first_signal = {type = "virtual", name = "signal-C"}, second_constant = 0, comparator = ">"}}
|
2020-03-05 16:56:59 +02:00
|
|
|
rules4.circuit_parameters = {signal_value_is_pitch = false, instrument_id = 8, note_id = 5}
|
2020-02-21 00:19:00 +02:00
|
|
|
local solar1 = surface.create_entity({name = "solar-panel", position = {x = width * -0.5 - 2, y = -242}, force="player", create_build_effect_smoke = false})
|
|
|
|
local solar2 = surface.create_entity({name = "solar-panel", position = {x = width * -0.5 + 1, y = -242}, force="player", create_build_effect_smoke = false})
|
|
|
|
solar1.destructible = false
|
|
|
|
solar1.minable = false
|
|
|
|
solar2.destructible = false
|
|
|
|
solar2.minable = false
|
|
|
|
combipower.destructible = false
|
|
|
|
combipower.minable = false
|
2020-02-21 07:25:19 +02:00
|
|
|
combipower.operable = false
|
2020-02-21 00:19:00 +02:00
|
|
|
speaker.destructible = false
|
|
|
|
speaker.minable = false
|
2020-02-21 07:25:19 +02:00
|
|
|
speaker.operable = false
|
|
|
|
checker.destructible = false
|
|
|
|
checker.minable = false
|
|
|
|
checker.operable = false
|
|
|
|
|
2020-02-21 00:19:00 +02:00
|
|
|
|
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
for _, x in pairs({-1, 0}) do
|
|
|
|
for i = 1, 12, 1 do
|
|
|
|
local step = math_floor((i-1)/4)
|
2020-03-05 16:56:59 +02:00
|
|
|
local y = -131 + i + step * 128 - step * 4
|
2020-05-19 17:08:10 +02:00
|
|
|
local e = surface.create_entity({name = "red-chest", position = {x,y}, force = "player", create_build_effect_smoke = false})
|
2020-02-14 22:06:52 +02:00
|
|
|
e.destructible = false
|
|
|
|
e.minable = false
|
2020-04-24 21:07:41 +02:00
|
|
|
table.insert(objective.comfychests2, e)
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
for i = 1, 9, 1 do
|
|
|
|
local y = -0.7 * height + 18 + 9 + 18 * ( math_floor((i - 1) / 3))
|
|
|
|
local x = -0.5 * width + 5 + 9 + 18 * ( i%3 )
|
|
|
|
local substation = surface.create_entity({name = "substation", position = {x,y}, force="player", create_build_effect_smoke = false})
|
2020-02-21 00:19:00 +02:00
|
|
|
if i == 3 then
|
|
|
|
substation.disconnect_neighbour(combipower)
|
|
|
|
substation.connect_neighbour({wire = defines.wire_type.green, target_entity = combipower})
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
substation.minable = false
|
|
|
|
substation.destructible = false
|
|
|
|
for j = 1, 4, 1 do
|
|
|
|
local xx = x - 2 * j
|
|
|
|
local acumulator = surface.create_entity({name = "accumulator", position = {xx,y}, force="player", create_build_effect_smoke = false})
|
2020-02-21 00:19:00 +02:00
|
|
|
if i == 3 and j == 1 then
|
|
|
|
acumulator.connect_neighbour({wire = defines.wire_type.green, target_entity = substation})
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
acumulator.minable = false
|
|
|
|
acumulator.destructible = false
|
2020-05-18 22:21:11 +02:00
|
|
|
table.insert(objective.accumulators, acumulator)
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
for k = 1, 4, 1 do
|
|
|
|
local xx = x + 2 * k
|
|
|
|
local acumulator = surface.create_entity({name = "accumulator", position = {xx,y}, force="player", create_build_effect_smoke = false})
|
|
|
|
acumulator.minable = false
|
|
|
|
acumulator.destructible = false
|
2020-05-18 22:21:11 +02:00
|
|
|
table.insert(objective.accumulators, acumulator)
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local powerpole = surface.create_entity({name = "big-electric-pole", position = {0, height * -0.5 }, force="player", create_build_effect_smoke = false})
|
|
|
|
powerpole.minable = false
|
|
|
|
powerpole.destructible = false
|
|
|
|
|
2020-04-14 16:24:32 +02:00
|
|
|
local market = surface.create_entity({name = "market", position = {-29, height * -0.5 + 4}, force="neutral", create_build_effect_smoke = false})
|
2020-02-14 22:06:52 +02:00
|
|
|
market.minable = false
|
|
|
|
market.destructible = false
|
2020-05-19 17:08:10 +02:00
|
|
|
local repairchest = surface.create_entity({name = "blue-chest", position = {-24, height * -0.5 + 3}, force = "player"})
|
2020-04-14 09:51:09 +02:00
|
|
|
repairchest.minable = false
|
|
|
|
repairchest.destructible = false
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.upgradechest[0] = repairchest
|
2020-04-14 09:51:09 +02:00
|
|
|
rendering.draw_text{
|
2020-05-18 22:21:11 +02:00
|
|
|
text = "Repair Chest",
|
2020-04-14 09:51:09 +02:00
|
|
|
surface = surface,
|
|
|
|
target = repairchest,
|
|
|
|
target_offset = {0, -2.5},
|
2020-04-24 21:07:41 +02:00
|
|
|
color = objective.locomotive.color,
|
2020-04-14 09:51:09 +02:00
|
|
|
scale = 1.00,
|
|
|
|
font = "default-game",
|
|
|
|
alignment = "center",
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
|
|
|
local upgrades = Upgrades.upgrades()
|
|
|
|
for i = 1, #upgrades, 1 do
|
2020-05-19 17:08:10 +02:00
|
|
|
local e = surface.create_entity({name = "blue-chest", position = {-21 + i, height * -0.5 + 3}, force = "player"})
|
2020-04-14 09:51:09 +02:00
|
|
|
e.minable = false
|
|
|
|
e.destructible = false
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.upgradechest[i] = e
|
2020-04-14 09:51:09 +02:00
|
|
|
rendering.draw_sprite{
|
|
|
|
sprite = upgrades[i].sprite,
|
|
|
|
surface = surface,
|
|
|
|
target = e,
|
|
|
|
target_offset = {0, -1.3},
|
|
|
|
font = "default-game",
|
|
|
|
visible = true
|
|
|
|
}
|
|
|
|
end
|
2020-02-21 00:19:00 +02:00
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
local market1_text = rendering.draw_text{
|
2020-05-18 22:21:11 +02:00
|
|
|
text = "Market",
|
2020-02-14 22:06:52 +02:00
|
|
|
surface = surface,
|
|
|
|
target = market,
|
|
|
|
target_offset = {0, -3.5},
|
2020-04-24 21:07:41 +02:00
|
|
|
color = objective.locomotive.color,
|
2020-02-14 22:06:52 +02:00
|
|
|
scale = 1.00,
|
|
|
|
font = "default-game",
|
|
|
|
alignment = "center",
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
2020-02-17 01:46:22 +02:00
|
|
|
local upgrade_text = rendering.draw_text{
|
2020-02-14 22:06:52 +02:00
|
|
|
text = "Upgrades",
|
|
|
|
surface = surface,
|
2020-04-24 21:07:41 +02:00
|
|
|
target = objective.upgradechest[8],
|
2020-02-14 22:06:52 +02:00
|
|
|
target_offset = {0, -3.5},
|
2020-04-24 21:07:41 +02:00
|
|
|
color = objective.locomotive.color,
|
2020-02-14 22:06:52 +02:00
|
|
|
scale = 1.00,
|
|
|
|
font = "default-game",
|
|
|
|
alignment = "center",
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
2020-02-17 01:46:22 +02:00
|
|
|
local upgrade_sub_text = rendering.draw_text{
|
2020-05-18 22:21:11 +02:00
|
|
|
text = "Click [Upgrades] at top of screen",
|
2020-02-17 01:46:22 +02:00
|
|
|
surface = surface,
|
2020-04-24 21:07:41 +02:00
|
|
|
target = objective.upgradechest[8],
|
2020-02-17 01:46:22 +02:00
|
|
|
target_offset = {0, -2.5},
|
2020-04-24 21:07:41 +02:00
|
|
|
color = objective.locomotive.color,
|
2020-02-17 01:46:22 +02:00
|
|
|
scale = 0.80,
|
|
|
|
font = "default-game",
|
|
|
|
alignment = "center",
|
|
|
|
scale_with_zoom = false
|
|
|
|
}
|
2020-02-21 00:19:00 +02:00
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
|
2020-05-18 22:21:11 +02:00
|
|
|
for _, offer in pairs(Balance.market_offers()) do market.add_market_item(offer) end
|
2020-02-14 22:06:52 +02:00
|
|
|
|
|
|
|
--generate cars--
|
2020-03-05 16:56:59 +02:00
|
|
|
local car_pos = {
|
|
|
|
{x = width * -0.5 - 1.4, y = -128},
|
|
|
|
{x = width * -0.5 - 1.4, y = 0},
|
|
|
|
{x = width * -0.5 - 1.4, y = 128},
|
|
|
|
{x = width * 0.5 + 1.4, y = -128},
|
|
|
|
{x = width * 0.5 + 1.4, y = 0},
|
|
|
|
{x = width * 0.5 + 1.4, y = 128}
|
|
|
|
}
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.car_exits = {}
|
2020-03-05 16:56:59 +02:00
|
|
|
for i = 1, 6, 1 do
|
|
|
|
local e = surface.create_entity({name = "car", position = car_pos[i], force = "player", create_build_effect_smoke = false})
|
2020-02-14 22:06:52 +02:00
|
|
|
e.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 16})
|
|
|
|
e.destructible = false
|
|
|
|
e.minable = false
|
|
|
|
e.operable = false
|
2020-04-24 21:07:41 +02:00
|
|
|
objective.car_exits[i] = e
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--generate chests inside south wagon--
|
|
|
|
local positions = {}
|
|
|
|
for x = width * -0.5 + 2, width * 0.5 - 1, 1 do
|
|
|
|
if x == -1 then x = x - 1 end
|
|
|
|
if x == 0 then x = x + 1 end
|
|
|
|
for y = 68, height * 0.5 - 4, 1 do
|
|
|
|
positions[#positions + 1] = {x = x, y = y}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.shuffle_table(positions)
|
|
|
|
|
2020-05-18 22:21:11 +02:00
|
|
|
local cargo_boxes = Balance.initial_cargo_boxes()
|
2020-02-14 22:06:52 +02:00
|
|
|
|
|
|
|
local i = 1
|
|
|
|
for _ = 1, 16, 1 do
|
|
|
|
if not positions[i] then break end
|
|
|
|
local e = surface.create_entity({name = "wooden-chest", position = positions[i], force="player", create_build_effect_smoke = false})
|
|
|
|
local inventory = e.get_inventory(defines.inventory.chest)
|
|
|
|
inventory.insert({name = "raw-fish", count = math_random(2, 5)})
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
for _ = 1, 24, 1 do
|
|
|
|
if not positions[i] then break end
|
|
|
|
local e = surface.create_entity({name = "wooden-chest", position = positions[i], force="player", create_build_effect_smoke = false})
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
for loot_i = 1, #cargo_boxes, 1 do
|
2020-05-18 22:21:11 +02:00
|
|
|
if not positions[i] then
|
|
|
|
log("ran out of cargo box positions")
|
|
|
|
break
|
|
|
|
end
|
2020-02-14 22:06:52 +02:00
|
|
|
local e = surface.create_entity({name = "wooden-chest", position = positions[i], force="player", create_build_effect_smoke = false})
|
|
|
|
local inventory = e.get_inventory(defines.inventory.chest)
|
|
|
|
inventory.insert(cargo_boxes[loot_i])
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Public.set_player_spawn_and_refill_fish()
|
2020-04-24 21:07:41 +02:00
|
|
|
local objective = Chrono_table.get_table()
|
|
|
|
if not objective.locomotive_cargo[1] then return end
|
|
|
|
local cargo = objective.locomotive_cargo[1]
|
2020-03-05 16:56:59 +02:00
|
|
|
if not cargo.valid then return end
|
2020-05-18 22:21:11 +02:00
|
|
|
cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 1})
|
2020-03-05 16:56:59 +02:00
|
|
|
local position = cargo.surface.find_non_colliding_position("stone-furnace", cargo.position, 16, 2)
|
2020-02-14 22:06:52 +02:00
|
|
|
if not position then return end
|
2020-03-05 16:56:59 +02:00
|
|
|
game.forces.player.set_spawn_position({x = position.x, y = position.y}, cargo.surface)
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
|
2020-05-18 22:21:11 +02:00
|
|
|
function Public.award_coins(_count)
|
|
|
|
if not (_count >= 1) then return end
|
|
|
|
local objective = Chrono_table.get_table()
|
|
|
|
if not objective.locomotive_cargo[1] then return end
|
|
|
|
local cargo = objective.locomotive_cargo[1]
|
|
|
|
if not cargo.valid then return end
|
|
|
|
cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "coin", count = math_floor(_count)})
|
|
|
|
end
|
|
|
|
|
2020-02-14 22:06:52 +02:00
|
|
|
function Public.enter_cargo_wagon(player, vehicle)
|
2020-04-24 21:07:41 +02:00
|
|
|
local objective = Chrono_table.get_table()
|
2020-02-19 16:15:16 +02:00
|
|
|
if not vehicle then log("no vehicle") return end
|
|
|
|
if not vehicle.valid then log("vehicle invalid") return end
|
2020-03-05 16:56:59 +02:00
|
|
|
if not game.surfaces["cargo_wagon"] then Public.create_wagon_room() end
|
|
|
|
local wagon_surface = game.surfaces["cargo_wagon"]
|
|
|
|
for i = 1, 3, 1 do
|
2020-04-24 21:07:41 +02:00
|
|
|
if not objective.locomotive_cargo[i] then log("no cargo") return end
|
|
|
|
if not objective.locomotive_cargo[i].valid then log("cargo invalid") return end
|
|
|
|
if vehicle == objective.locomotive_cargo[i] then
|
2020-03-05 16:56:59 +02:00
|
|
|
local x_vector = vehicle.position.x - player.position.x
|
|
|
|
local position
|
|
|
|
if x_vector > 0 then
|
|
|
|
position = {wagon_surface.map_gen_settings.width * -0.5, -128 + 128 * (i - 1)}
|
|
|
|
else
|
|
|
|
position = {wagon_surface.map_gen_settings.width * 0.5, -128 + 128 * (i - 1)}
|
|
|
|
end
|
|
|
|
player.teleport(wagon_surface.find_non_colliding_position("character", position, 128, 0.5), wagon_surface)
|
|
|
|
break
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if player.surface.name == "cargo_wagon" and vehicle.type == "car" then
|
2020-04-24 21:07:41 +02:00
|
|
|
if objective.flame_boots then
|
|
|
|
objective.flame_boots[player.index] = {fuel = 1, steps = {}}
|
2020-02-23 19:33:37 +02:00
|
|
|
end
|
2020-03-05 16:56:59 +02:00
|
|
|
local used_exit = 0
|
|
|
|
for i = 1, 6, 1 do
|
2020-04-24 21:07:41 +02:00
|
|
|
if vehicle == objective.car_exits[i] then
|
2020-03-05 16:56:59 +02:00
|
|
|
used_exit = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2020-04-24 21:07:41 +02:00
|
|
|
local surface = objective.locomotive_cargo[1].surface
|
|
|
|
local position = {x = objective.locomotive_cargo[((used_exit - 1) % 3) + 1].position.x + math_sgn(used_exit - 3.5) * 2, y = objective.locomotive_cargo[((used_exit - 1) % 3) + 1].position.y}
|
2020-02-18 03:43:22 +02:00
|
|
|
local position2 = surface.find_non_colliding_position("character", position, 128, 0.5)
|
|
|
|
if not position2 then return end
|
|
|
|
player.teleport(position2, surface)
|
2020-02-14 22:06:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return Public
|