18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 04:47:06 +01:00
Commit Graph

5 Commits

Author SHA1 Message Date
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
jakubg1 3a600334a7 Add an index parameter to lua::get_memcell_values()
We could have done away with it just because the memcell values are always the last parameter. However, this might not always be the case in the future. Also, it's better for consistency reasons.
2026-04-01 02:43:25 +02:00
jakubg1 686cab8184 Fix a segfault when calling api.dynobj_putvalues()
An undocumented change from the previous commit:
- When the Lua script is not able to find an object, the message is now printed to `errors.txt`, not just to `log.txt`.
2026-04-01 02:13:30 +02:00
jakubg1 ca8e4aae71 Refactor Lua bindings to not use FFI anymore
- Lua bindings are no longer using FFI in favor of the "classic" Lua C API.
  - This makes it work properly on native Linux builds.
- Changed the Lua API slightly:
  - Removed the `api.event_preparefunc()` function because it is no longer necessary. Instead, you can pass any function you want without preparing it first.
  - Added an `api.event_exists()` function. Takes a single `name` argument.
  - Any `api.find_*()` functions return `nil` instead of an userdata representing a null pointer when the requested object is not found.
2026-04-01 01:42:54 +02:00
copilot-swe-agent[bot] 0531086bb9 Reorganize source files into logical subdirectories
Co-authored-by: Hirek193 <23196899+Hirek193@users.noreply.github.com>
2026-03-14 19:01:57 +00:00