Automatic train repair


If any locomotive or wagon is destroyed the train is stopped and a ghost is created. Including inventory filters, inventory limit and requests for fuel and equipment. As soon as the train is fully repaired it is set to automatic mode again.

Utilities
2 days ago
2.0
49
Trains Logistic network

Changelog

Version: 2.2.2
Date: 2026-07-27
  Changes:
    - Fuel type settings accept common typos (Solid-fuel, Solid Fuel) and resolve to the internal item ID; invalid names print a one-time warning with examples.
  Bugfixes:
    - Empty-train / repair-ghost fuel requests no longer silently fail on capitalized or spaced fuel names.
Version: 2.2.1
Date: 2026-07-24
  Bugfixes:
    - Newly placed trains no longer inherit schedules from unrelated open repair jobs or nearby history.
    - Repair completion and awaiting-restore only apply to trains linked to that job (proximity alone is not enough).
    - Brand-new placements (no old train ids) no longer merge nearby identity cache/jobs into the registry.
Version: 2.2.0
Date: 2026-07-24
  Features:
    - Live trains that completely run out of fuel can request more from construction bots (toggle, fuel type, and request percent — separate from repair-ghost fuel settings).
  Changes:
    - Reorganized map settings into Repair behavior, Repair ghost fuel, and Empty-train fuel groups.
  Bugfixes:
    - Empty-train fuel requests use item-request-proxy (insert_plan is only valid on ghosts/proxies, not live locomotives).
    - Skip incompatible fuel categories; reuse an existing proxy instead of recreating it every second.
Version: 2.1.0
Date: 2026-07-22
  Bugfixes:
    - Player schedule edits are stamped and preferred over older cached/frozen timetables, so a rebuilt train restores the schedule you last set — not a previous one.
Version: 2.0.18
Date: 2026-07-22
  Changes:
    - Removed temporary [ick-atr] schedule-debug logging (console, factorio-current.log, and script-output file).
Version: 2.0.17
Date: 2026-07-22
  Bugfixes:
    - Restore schedule/group as soon as the consist matches expected layout; only automatic mode waits for the refuel threshold (empty train GUI while awaiting fuel looked like a lost schedule).
    - Prefer joining a nearby open repair job and never shrink expected carriage counts, so mid-rebuild kills no longer spawn a second undersized job that never completes correctly.
Version: 2.0.16
Date: 2026-07-22
  Bugfixes:
    - Fixed crash on load: use helpers.write_file for debug log (game.write_file was removed in Factorio 2.0).
Version: 2.0.15
Date: 2026-07-22
  Bugfixes:
    - If the rebuilt consist already matches the expected layout, clear stale pending ghost regs and restore schedule — pending ghosts were blocking apply_train_identity forever after repeated destroys.
Version: 2.0.14
Date: 2026-07-22
  Changes:
    - Also write [ick-atr] debug lines to script-output/ick-atr-debug.log for easier sharing.
Version: 2.0.13
Date: 2026-07-22
  Changes:
    - Temporary verbose [ick-atr] schedule-debug logging to in-game console and factorio-current.log (toggle ICK_DEBUG in control.lua).
Version: 2.0.12
Date: 2026-07-22
  Bugfixes:
    - Prefer historical train records that still have a schedule; disregard blank snapshots when looking up identity after repeated destroys.
    - Empty on_train_schedule_changed during an active nearby repair no longer force-wipes inherited schedule or the identity cache (that was clearing timetables on split/rebuild).
    - Cache/job merge never replaces a scheduled entry with a weaker blank one; job complete recovers schedule from history if the job lost it.
Version: 2.0.11
Date: 2026-07-22
  Changes:
    - Documentation and packaging sync: README rewritten for current behavior; info.json version/description aligned for portal release.
Version: 2.0.10
Date: 2026-07-22
  Bugfixes:
    - Preserve schedule/group across repeated destroys and rebuilds: empty live snapshots no longer erase richer identity; open jobs and a nearby identity cache refill blanks; new unit numbers are rebound on job complete.
  Changes:
    - on_train_schedule_changed still accepts a cleared schedule (and clears the nearby cache) so intentional player edits are not resurrected.
Version: 2.0.9
Date: 2026-07-22
  Changes:
    - If the player fuels a repaired train to the threshold themselves, the repair job completes and can resume automatic without fighting their controls.
    - While awaiting refuel, re-check more often; also react to player fast-transfer into rolling stock.
    - Completing a job preserves automatic mode if the player already enabled it.
Version: 2.0.8
Date: 2026-07-22
  Changes:
    - Fuel request amount setting is now a percent of fuel inventory capacity (0–100, default 100); old 0 (= full) migrates to 100.
  Bugfixes:
    - While waiting only for the refuel threshold, do not force the train back to manual — player automatic/manual changes are respected.
Version: 2.0.7
Date: 2026-07-22
  Features:
    - Repair jobs can wait until the train is refueled before restoring schedule/automatic mode.
    - New map settings: "Require refueling before repair job completes" (default true) and "Minimum fuel fill percent" (default 100).
  Changes:
    - While waiting for fuel, jobs are re-checked periodically so bot/logistic delivery can finish the job.
Version: 2.0.6
Date: 2026-07-22
  Bugfixes:
    - Fixed crash on load: use game.train_manager.get_trains (LuaForce.get_trains was removed in Factorio 2.0).
Version: 2.0.5
Date: 2026-07-22
  Features:
    - Always keep a live registry of every train's schedule/group/layout in storage; on destroy, look that record up and restore it after rebuild.
  Changes:
    - Fuel amount 0 now requests a full fuel inventory (slot count × stack size), not a single stack.
  Bugfixes:
    - Do not discard repair-job schedules when pending clears before the consist matches.
    - Match rebuilt cars by proximity instead of exact float positions.
    - Freeze old train registry entries on split instead of deleting them mid-wipe.
Version: 2.0.4
Date: 2026-07-22
  Bugfixes:
    - Save schedule/group into mod storage on first death (before Factorio destroys LuaTrain) and re-apply after full rebuild via on_train_created.
    - Keep partial rebuilds forced to manual/stopped so a single replaced car cannot drive away.
    - Start repair jobs even when Factorio already flipped the train to manual on the killing blow, as long as a schedule or group existed.
Version: 2.0.3
Date: 2026-07-22
  Bugfixes:
    - Preserve schedule/group when a train is fully destroyed: later manual fragments still join the repair job, schedule is always snapshotted, and restore is deferred one tick after rebuild.
Version: 2.0.2
Date: 2026-07-22
  Changes:
    - Fuel request amount defaults to 0 = one full stack of each fuel type (still configurable with any positive count).
Version: 2.0.1
Date: 2026-07-22
  Features:
    - Multi-car repair jobs: automatic mode restores when all pending ghosts for an incident are built, in any order.
    - Saves and restores train group (or station schedule) when a repair job completes.
  Changes:
    - Map setting "Automatically enable automatic mode" now defaults to true.
Version: 2.0.0
Date: 2026-07-22
  Changes:
    - Ported to Factorio 2.0.
    - Replaced deprecated runtime APIs (storage, event.entity, prototypes.item, on_object_destroyed, insert_plan).
    - Item/equipment requests now preserve quality and use ghost insert_plan instead of writable item_requests.
    - Reuses an existing rolling-stock death ghost when present to avoid duplicate ghosts.
Version: 1.1.4
Date: 2021-12-07
  Bugfixes:
    - Fixed error because the mod tried to create a ghost even when the prototype had no items_to_place_this. Thanks to Kocou for the report.
Version: 1.1.3
Date: 2021-07-13
  Bugfixes:
    - Fixed error when fluid wagon was destroyed. Thanks to qwerty12butt for the report.
Version: 1.1.2
Date: 2021-05-17
  Features:
    - Added custom alert when rolling stock is destroyed. Thanks to PietersieliePC for the idea.
    - Added player setting to disable alerts.
    - Added smoke effect to simulate an emergency break. Thanks to Nosferatu for the idea.
  Changes:
    - Trains will no longer be set to automatic mode if they were destroyed by another train.
    - Map settings "automatically enable automatic mode" default is now false. There are too many unsolved issues with it.
  Bugfixes:
    - Fixed that locomotives sometimes didn't have the right orientation. Thanks to boskid.
Version: 1.1.1
Date: 2021-05-15
  Changes:
    - Added changelog.
    - Added thumbnail.
    - The mod can now be translated on Crowdin (https://crowdin.com/project/factorio-mods-localization).
Version: 1.1.0
Date: 2020-05-15
  Features:
    - Initial release
    - If any locomotive or wagon is destroyed the train is stopped and a ghost is created.
    - Including inventory filters, inventory limit and requests for fuel and equipment.
    - As soon as the train is fully repaired it is set to automatic mode again.
    - Map setting to disable item requests.
    - Map setting to specifiy which fuel shold be requested.
    - Map setting to disable automatically enabling automatic mode.