18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 22:44:59 +01:00
Commit Graph

22 Commits

Author SHA1 Message Date
maj00r
5c8cc6d9a5 feat(ai): PointVelocity, a speed limit for the head of the train at a point beyond the cell (#304)
* feat(ai): PointVelocity, a speed limit for the head of the train at a point beyond the cell

A memory cell (or putvalues) with "PointVelocity v d" tells the train that the head has to be at v km/h
at the point d metres beyond the cell (v -1: no limit). The cell is read by the speed table scan like a
signal, live until the head passes it; what it says then is kept for the point, later changes of the
cell don't concern that train. The limit ends when the head passes the point, it doesn't hold the rest
of the train and doesn't extend or break a speed limit of the line, like W27 of length 0 moved d metres
on. The AI brakes so the head reaches the point at v; for a human driver it only shows as the next
speed limit of the driving aid, the security systems don't see it.

It is made for the warning disc of a level crossing (TOP, Osp1/Osp2), which has to give 20 km/h at the
crossing about 500 m beyond the disc, as the disc showed when the train passed it.

The cell with PointVelocity as its first command makes its getvalues scanned (passive) as SetVelocity
does; PutCommand ignores it when such an event runs. Old commands keep working as they did,
SetProximityVelocity included.

* fix(ai): a point limit isn't a signal, and a PointVelocity 0 can be released

From the review of the PointVelocity commit:
- a cell rewritten from SetVelocity or ShuntVelocity to PointVelocity drops the flags of a signal, so it
  can't count as a semaphor or report a signal passed at danger;
- PointVelocity 0 is read on after the head passes the cell, as a stop of a signal is, otherwise the
  train would stand short of the point for good;
- a point limit doesn't become eSignNext, so a W4 between the disc and the crossing keeps its release.

* fix(ai): a PointVelocity limit outlives a rebuilt speed table, and holds when shunting

The state of the cell, latched when the head passes it, is now kept by the
controller apart from the speed table, and the distance to the point is
measured by the movement of the consist in the world. Stopping, backing up
and going on between the cell and the point, coupling or a takeover no longer
lose the limit or read the cell anew, unless the head backs up past the cell,
when the cell is read again.

Near the point the desired speed is capped to the limit, so a train that
coasts within its tolerance (as a shunting one does) reaches the point at it.

* fix(ai): review of the latched point limits

- a point the head has passed already isn't latched, and a latched limit at
  or behind the head isn't applied (it asked for a full brake for a cycle);
- a latched limit is dropped once the head backs up behind its cell, so it
  can't follow the consist onto another track; the table reads the cell again;
- a cell latched already, found under the consist by a rebuilt table, is
  ignored whatever it shows now (a 0 for the next train no longer stops it);
- PointVelocity 0 stops at the usual distance, not from the approach;
- the heading follows the track under the measured vehicle, not the chord of
  the consist, which a long consist on a tight curve holds far off the track;
- vehicles coupled or uncoupled at the end towards the point move the head;
- a jump of the consist (moved elsewhere) drops the latched limits.

* fix(ai): a cab change and curves don't move the latched point limits

- the end of the consist towards the point is taken into the distance only
  when the consist changes (its end vehicles or its length), not when another
  vehicle is measured from (a cab change at a reversal) nor when a curve
  shortens its projection;
- the way of travel follows the direction of the driver's vehicle against
  its own couplers, not the chord of the consist, which on a balloon loop
  points against it.

* fix(ai): a coupling with a cab change in one order still moves the head of a latched point limit

The end of the consist measured from the previous vehicle is moved to the place of the new one, so a coupling or an uncoupling followed at once by a change of direction to the other cab (the shunting orders) is taken into the distance to the point.

---------

Co-authored-by: maj00r <maj00r@host>
2026-11-10 18:44:33 +01:00
68fdf1efdf Merge pull request #167 from pwarszawski/whois-station-ahead
whois: add lookahead mode for the timetable entry after the next stop
2026-11-07 20:28:22 +00:00
maj00r
978b99b7e5 feat(scenery): models laid along curves (sweep nodes), bent to follow the paths or repeated along them, loaded and saved with the scenery; trainsets put on a path while the simulation runs; trainset turned around by reversed after its header: the first vehicle stays at the offset and leads towards point 1, the rest stands behind it; launcher keeps reversed trainsets and can turn one around; memory cells saved with the new name of the path they name; events tell their targets and the events of a multiple event; renderer tells whether the cursor is over a surface; vehicle placed in the editor entered when the driving goes on 2026-10-06 22:19:32 +02:00
pwarszawski
247707ef94 Merge master into whois-station-ahead 2026-10-02 15:28:19 +02:00
7a469190ca Merge pull request #168 from pwarszawski/whois-owner-fallback
whois: fall back to the consist owner in the +0/+7 mode too
2026-09-05 21:08:29 +02:00
Piotr Warszawski
2dcae05c77 event names: drop redundant locale-dependent ToLower() at registration
make_event() lowercased the event name twice: cParser::getToken() already
folds ASCII via toLowerChar() (which intentionally leaves bytes >= 0x80
alone), then ToLower() ran std::tolower() over every byte on top of that.

With a non-"C" global locale, that second pass remaps cp1250 uppercase
accented letters (e.g. 0xAF -> 0xBF). Every lookup path - TTrack::AssignEvents(),
child-event resolution in multi_event, event-launcher name resolution -
normalizes only through the parser, so a registered name containing such a
letter can no longer be found: the track logs "can't find assigned event"
and the binding is silently dropped.

Removing the extra ToLower() makes the registration key match every lookup
site (ASCII-only folding, non-ASCII bytes compared verbatim), and matches
the direction toLowerChar()'s own comment already points at for UTF-8.
2026-09-05 19:10:58 +02:00
Piotr Warszawski
1ce576c0c6 whois: log the no-activator case instead of failing silently
A whois with no triggering vehicle previously just wrote nothing to
the target cell with no trace in the log, which is a real pain to
diagnose from the scenery side (this is exactly the kind of thing that
cost real debugging time on a station script recently).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 22:22:25 +02:00
Piotr Warszawski
7ead4f11b4 whois: guard against a null activator
whois_event::run_() dereferenced m_activator unconditionally in every
branch (this predates this PR). getvalues_event::run_() and
putvalues_event::run_() already guard the same way elsewhere in this
file; whois_event was missing it. Single early return covers every
branch, old and new.
2026-09-04 22:09:23 +02:00
Piotr Warszawski
93463a3850 whois: consolidate the two lookahead accessors into one
Per review: StationNameAhead()/StationIsStopAhead() duplicated the same
bounds check for no reason. Replaced with a single
TimeTableEntryAhead(Offset) returning the TMTableLine itself; the whois
branch reads .StationName/.Ah off it directly.
2026-09-04 21:24:01 +02:00
Piotr Warszawski
4f47233a89 whois: fall back to the consist owner in the +0/+7 mode too
The +8/+16/+24/+32/+40 (and the new +48) modes all pick the reporting
vehicle the same way: the activator's own Mechanik if it's the primary
driver, otherwise the consist's controlling vehicle (ctOwner) - so the
event still resolves correctly if a wagon happens to trigger it ahead
of its locomotive.

+0 (train name / stations left / stop flag) predates that pattern and
never got it: it required m_activator->Mechanik directly and silently
wrote nothing otherwise. A whois hook placed where the loco doesn't
necessarily lead (e.g. a train that reverses direction, or one being
propelled) can have a wagon trigger the event first and the memcell
stays empty, with no error - hard to diagnose from scenery side.

Same owner-selection, same guard semantics (still nothing written if
neither the activator nor its consist has a controller), only the
source of the vehicle it reads from is widened.
2026-09-04 21:01:33 +02:00
Piotr Warszawski
5705062cd2 whois: select the lookahead mode via +48 instead of a new bit
Per review: +48 (whois_name | whois_load, mode_alt clear) was an
unused combination of the existing mode bits - use that instead of
claiming a new bit 6. +56 (same, with mode_alt set) stays free for a
future mode. No new flags::* entry needed; mtable.h/.cpp unchanged.
2026-09-04 20:28:28 +02:00
Piotr Warszawski
4575f61cc8 whois: add lookahead mode for the timetable entry after the next stop
Dispatcher scripts that route trains at a station based on where they
go afterwards (e.g. a big terminal throat with several outbound
directions) have no way to read that: whois +40 only exposes the
current/next timetable entry (NextStop()/IsStop()), which while the
train is at that very station is that station itself.

Adds flags::whois_ahead (bit 6, previously unused) plus
TTrainParameters::StationNameAhead(Offset)/StationIsStopAhead(Offset),
returning the raw TimeTable[] entry Offset positions past StationIndex
(name and whether it's a booked stop, "none"/false past the end of the
timetable). The new whois branch calls both with Offset=1, mirroring
the existing +40 branch's UpdateValues()/WriteLog() shape.

Logic-verified with an isolated harness mirroring the touched types
(TTrainParameters/TController/TMemCell shapes and the exact function
bodies); not yet build-tested against the full engine locally - relying
on CI for that.
2026-09-04 15:52:38 +02:00
jerrrrycho
d85096f64d reformat: remove redundant parentheses 2026-06-30 21:19:46 +02:00
docentYT
81eadbef73 Do not use temp variable when it is not needed 2026-05-12 18:19:11 +02:00
docentYT
13c7317f6e Do not allow implicit cast for inline std::string to_string(bool Value) and change to_string to std::string for non boolean values 2026-05-03 15:49:29 +02:00
docentYT
d1f16411a1 Replace clamp with std::clamp 2026-05-01 22:14:29 +02:00
docentYT
ec1dfae953 Replace starts_with and ends_with with string class methods 2026-05-01 17:31:11 +02:00
jakubg1
5d5264a8f3 Prefix error messages
When a Lua code fails to execute and throws an error, the log line now starts from `lua: Runtime error: `.
2026-04-01 16:06:17 +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
jerrrrycho
9f43dca48b refactor: create paths namespace instead of global variables 2026-03-15 11:55:30 +01:00
copilot-swe-agent[bot]
7e49aa8740 Rewrite #includes to use explicit subdirectory paths
Co-authored-by: Hirek193 <23196899+Hirek193@users.noreply.github.com>
2026-03-14 19:16:48 +00: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