Skip to content

Commit

Permalink
Initial code. Does not work properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoxyNixie committed Feb 21, 2018
0 parents commit 5a4ba1a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
82 changes: 82 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
-- If only you could rotate locomotives that where connected this mod would be so much easier.

local movingstate = {
[defines.train_state.on_the_path] = true,
[defines.train_state.path_lost] = true,
[defines.train_state.no_schedule] = false,
[defines.train_state.no_path] = false,
[defines.train_state.arrive_signal] = true,
[defines.train_state.wait_signal] = false,
[defines.train_state.arrive_station] = true,
[defines.train_state.wait_station] = false,
[defines.train_state.manual_control_stop] = false,
[defines.train_state.manual_control] = false,
}

local function rotate(loco)
loco.disconnect_rolling_stock(defines.rail_direction.back)
loco.disconnect_rolling_stock(defines.rail_direction.front)
local ret = loco.rotate()
loco.connect_rolling_stock(defines.rail_direction.back)
loco.connect_rolling_stock(defines.rail_direction.front)
return ret
end

script.on_init(function()
global.movingstate = global.movingstate or {}
global.lastmode = global.lastmode or {}
end)

script.on_event(defines.events.on_train_created, function (event)
global.movingstate = global.movingstate or {}
global.lastmode = global.lastmode or {}
if event.old_train_id_1 then -- We can ignore the second one since the first old id is the one that gets its stuff copied.
-- Train changed
global.movingstate[event.train.id] = global.movingstate[event.old_train_id_1]
global.movingstate[event.old_train_id_1] = nil
global.lastmode[event.train.id] = global.lastmode[event.old_train_id_1]
global.lastmode[event.old_train_id_1] = nil
--@todo: current schedule id too?
else
-- Train created
global.movingstate[event.train.id] = false
global.lastmode[event.train.id] = true
end
end)

script.on_event(defines.events.on_train_changed_state, function(event)
local train = event.train
if train.state == defines.train_state.manual_control or train.state == defines.train_state.manual_control_stop then
return
end
if event.old_state == defines.train_state.manual_control or event.old_state == defines.train_state.manual_control_stop then
return
end
if movingstate[train.state] ~= global.movingstate[train.id] then
global.movingstate[train.id] = movingstate[train.state]
global.lastmode[train.id] = train.manual_mode
if movingstate[train.state] then
for _, loco in pairs(train.locomotives.back_movers) do
global[loco.unit_number] = rotate(loco)
train = loco.train
end
train.manual_mode = global.lastmode[train.id]
else
for _, loco in pairs(train.locomotives.back_movers) do
if global[loco.unit_number] then
rotate(loco)
global[loco.unit_number] = nil
train = loco.train
end
end
for _, loco in pairs(train.locomotives.front_movers) do
if global[loco.unit_number] then
rotate(loco)
global[loco.unit_number] = nil
train = loco.train
end
end
train.manual_mode = global.lastmode[train.id]
end
end
end)
11 changes: 11 additions & 0 deletions info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Noxys_Multidirectional_Trains",
"version": "0.0.1",
"factorio_version": "0.16",
"title": "Noxys Multidirectional Trains",
"author": "Noxy",
"contact": "donotcontactme@example.com",
"homepage": "https://mods.factorio.com/",
"description": "Sneakily rotate locomotives that are being pulled backwards so that they actually help with acceleration instead of just being dead weight.",
"dependencies": ["base >= 0.16.0"]
}

0 comments on commit 5a4ba1a

Please sign in to comment.