2019-10-28 17:38:36 +01:00
|
|
|
local Public = {}
|
|
|
|
|
|
|
|
function Public.locomotive_spawn(surface, position)
|
2019-10-06 18:16:32 +02:00
|
|
|
for y = -6, 6, 2 do
|
|
|
|
surface.create_entity({name = "straight-rail", position = {position.x, position.y + y}, force = "player", direction = 0})
|
|
|
|
end
|
|
|
|
global.locomotive = surface.create_entity({name = "locomotive", position = {position.x, position.y + -3}, force = "player"})
|
2019-10-07 07:19:41 +02:00
|
|
|
global.locomotive.get_inventory(defines.inventory.fuel).insert({name = "wood", count = 100})
|
2019-10-06 18:16:32 +02:00
|
|
|
|
|
|
|
global.locomotive_cargo = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + 3}, force = "player"})
|
2019-10-10 07:24:49 +02:00
|
|
|
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 8})
|
2019-10-06 18:16:32 +02:00
|
|
|
|
2019-10-18 07:01:14 +02:00
|
|
|
rendering.draw_light({
|
|
|
|
sprite = "utility/light_medium", scale = 5.5, intensity = 1, minimum_darkness = 0,
|
|
|
|
oriented = true, color = {255,255,255}, target = global.locomotive,
|
|
|
|
surface = surface, visible = true, only_in_alt_mode = false,
|
|
|
|
})
|
|
|
|
|
2019-10-06 18:16:32 +02:00
|
|
|
global.locomotive.color = {0, 255, 0}
|
|
|
|
global.locomotive.minable = false
|
|
|
|
global.locomotive_cargo.minable = false
|
|
|
|
global.locomotive_cargo.operable = false
|
|
|
|
end
|
|
|
|
|
2019-10-22 08:29:30 +02:00
|
|
|
--[[
|
2019-10-10 21:33:54 +02:00
|
|
|
local function fish_tag()
|
|
|
|
if not global.locomotive_cargo then return end
|
|
|
|
if not global.locomotive_cargo.valid then return end
|
2019-10-17 00:06:18 +02:00
|
|
|
if not global.locomotive_cargo.surface then return end
|
|
|
|
if not global.locomotive_cargo.surface.valid then return end
|
2019-10-10 21:33:54 +02:00
|
|
|
if global.locomotive_tag then
|
|
|
|
if global.locomotive_tag.valid then
|
|
|
|
if global.locomotive_tag.position.x == global.locomotive_cargo.position.x and global.locomotive_tag.position.y == global.locomotive_cargo.position.y then return end
|
|
|
|
global.locomotive_tag.destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
global.locomotive_tag = global.locomotive_cargo.force.add_chart_tag(
|
|
|
|
global.locomotive_cargo.surface,
|
|
|
|
{icon = {type = 'item', name = 'raw-fish'},
|
|
|
|
position = global.locomotive_cargo.position,
|
|
|
|
text = " "
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-10-06 18:16:32 +02:00
|
|
|
local function accelerate()
|
2019-10-11 21:52:32 +02:00
|
|
|
if not global.locomotive then return end
|
|
|
|
if not global.locomotive.valid then return end
|
2019-10-13 15:46:46 +02:00
|
|
|
if global.locomotive.get_driver() then return end
|
|
|
|
global.locomotive_driver = global.locomotive.surface.create_entity({name = "character", position = global.locomotive.position, force = "player"})
|
|
|
|
global.locomotive_driver.driving = true
|
|
|
|
global.locomotive_driver.riding_state = {acceleration = defines.riding.acceleration.accelerating, direction = defines.riding.direction.straight}
|
2019-10-06 18:16:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function remove_acceleration()
|
2019-10-11 21:52:32 +02:00
|
|
|
if not global.locomotive then return end
|
|
|
|
if not global.locomotive.valid then return end
|
2019-10-13 15:46:46 +02:00
|
|
|
if global.locomotive_driver then global.locomotive_driver.destroy() end
|
|
|
|
global.locomotive_driver = nil
|
2019-10-07 22:40:05 +02:00
|
|
|
end
|
|
|
|
|
2019-10-18 07:01:14 +02:00
|
|
|
local function set_daytime()
|
|
|
|
if not global.locomotive_cargo then return end
|
|
|
|
if not global.locomotive_cargo.valid then return end
|
|
|
|
local p = global.locomotive_cargo.position.y
|
|
|
|
local t = math.abs(global.locomotive_cargo.position.y) * 0.02
|
|
|
|
if t > 0.5 then t = 0.5 end
|
|
|
|
global.locomotive_cargo.surface.daytime = t
|
|
|
|
game.print(t)
|
|
|
|
end
|
2019-10-22 08:29:30 +02:00
|
|
|
]]
|
|
|
|
|
|
|
|
local function set_player_spawn_and_refill_fish()
|
|
|
|
if not global.locomotive_cargo then return end
|
|
|
|
if not global.locomotive_cargo.valid then return end
|
|
|
|
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 4})
|
|
|
|
local position = global.locomotive_cargo.surface.find_non_colliding_position("stone-furnace", global.locomotive_cargo.position, 16, 2)
|
|
|
|
if not position then return end
|
|
|
|
game.forces.player.set_spawn_position({x = position.x, y = position.y}, global.locomotive_cargo.surface)
|
|
|
|
end
|
2019-10-18 07:01:14 +02:00
|
|
|
|
2019-10-06 18:16:32 +02:00
|
|
|
local function tick()
|
2019-10-28 17:38:36 +01:00
|
|
|
local Reset = require "maps.mountain_fortress_v2.main".reset_map
|
2019-10-13 15:46:46 +02:00
|
|
|
if game.tick % 30 == 0 then
|
2019-10-09 03:25:00 +02:00
|
|
|
if game.tick % 1800 == 0 then
|
|
|
|
set_player_spawn_and_refill_fish()
|
2019-10-12 22:54:00 +02:00
|
|
|
end
|
|
|
|
if global.game_reset_tick then
|
|
|
|
if global.game_reset_tick < game.tick then
|
|
|
|
global.game_reset_tick = nil
|
2019-10-28 17:38:36 +01:00
|
|
|
Reset()
|
2019-10-10 19:33:32 +02:00
|
|
|
end
|
2019-10-22 08:29:30 +02:00
|
|
|
return
|
2019-10-07 22:40:05 +02:00
|
|
|
end
|
2019-10-22 08:29:30 +02:00
|
|
|
--fish_tag()
|
|
|
|
--set_daytime()
|
|
|
|
--accelerate()
|
2019-10-06 18:16:32 +02:00
|
|
|
else
|
2019-10-22 08:29:30 +02:00
|
|
|
--remove_acceleration()
|
2019-10-06 18:16:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local event = require 'utils.event'
|
2019-10-28 17:38:36 +01:00
|
|
|
event.on_nth_tick(5, tick)
|
|
|
|
|
|
|
|
return Public
|