1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/mountain_fortress/locomotive.lua

41 lines
1.6 KiB
Lua
Raw Normal View History

2019-10-06 18:16:32 +02:00
function locomotive_spawn(surface, position)
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"})
global.locomotive.get_inventory(defines.inventory.fuel).insert({name = "coal", count = 50})
global.locomotive_cargo = surface.create_entity({name = "cargo-wagon", position = {position.x, position.y + 3}, force = "player"})
global.locomotive_cargo.get_inventory(defines.inventory.cargo_wagon).insert({name = "raw-fish", count = 4000})
global.locomotive.color = {0, 255, 0}
global.locomotive.minable = false
global.locomotive_cargo.minable = false
global.locomotive_cargo.operable = false
end
local function accelerate()
local driver = global.locomotive.get_driver()
if driver then return end
2019-10-07 01:46:26 +02:00
global.locomotive_driver = global.locomotive.surface.create_entity({name = "character", position = global.locomotive.position, force = "player"})
2019-10-06 18:16:32 +02:00
global.locomotive_driver.driving = true
global.locomotive_driver.riding_state = {acceleration = defines.riding.acceleration.accelerating, direction = defines.riding.direction.straight}
end
local function remove_acceleration()
if global.locomotive_driver then global.locomotive_driver.destroy() end
end
local function tick()
2019-10-07 01:46:26 +02:00
if not global.locomotive then return end
if not global.locomotive.valid then return end
2019-10-06 18:16:32 +02:00
if game.tick % 30 == 0 then
accelerate()
else
remove_acceleration()
end
end
local event = require 'utils.event'
event.on_nth_tick(5, tick)