18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 01:17:23 +01:00
Files
jakubg1 d19411ce40 feat(lua): api.spawn_trainset() places trainsets from scenery scripts
A scenery Lua script can place trainsets while the simulation runs, with
spawn_trainset(definition) in eu07.events. The definition is written as in a
scenery file, from "trainset" to "endtrainset", e.g. as copied from the
scenario starter; it can hold more than one trainset.

- The trainsets are queued and placed at the start of the next simulation
  update, ahead of everything that goes through the vehicles. A Lua event with
  no delay runs at once, also from a track event fired while the vehicles are
  being updated, and a vehicle added then would change the list being
  iterated. A call made while the scenery loads waits until it's loaded.
- The whole definition is checked before anything is made: only trainset,
  reversed, assignment, vehicle nodes and endtrainset, each trainset on a track
  which exists, with vehicle names not in use and not repeated. Otherwise
  nothing is placed and the log says why.
- The statements go through the same code as in a scenery file, so "reversed"
  and "assignment" work as there. The trainset header is read without the
  overrides of the scenario starter, which go by the line of the scenario file
  (open_trainset, split off deserialize_trainset; loading is unchanged).
- The argument is checked with luaL_checkstring, a nil is a Lua error.

Based on PR #159, without its move of the smoke sources and lights into
TDynamicObject::Init (vehicles of road points would get their smoke twice) and
without the velocity parameter of insert_trainset.

Nothing changes for existing sceneries; no game data changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 02:24:35 +01:00
..