18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-28 23:13:23 +01:00
Files
maszyna/world/mtable.h
jerrrrycho aa84e41f09 feat: timetable service flags for the AI driver (eu07/maszyna#95)
A timetable can now tell the AI how the train is served, for trams,
underground trains and the like. The whole train gets them from a new
row of the first box of the header:

  [ Flagi AI | drzwi_centralne=tak,stopien=nie,kierownik=nie,proba_hamulca=nie ]

and a station changes them from there on with entries of its station
ware (the second line of the station, next to R2, ph, @):

  [       |     | po,kierownik=nie                 1  12.54  |        ]

- drzwi_centralne=tak: the driver opens all the doors from the cab,
  those of mixed control too (otherwise left to the passengers)
- stopien=tak/nie: the doorsteps switched on/off before the doors open
  (the AI didn't touch them before; new driver hints for it)
- kierownik=nie: no conductor, so no departure signal (direct or by
  radio) and no first door kept open for him before the departure
- proba_hamulca=nie: no running brake test

A flag left out keeps today's behaviour, so a timetable without flags
drives as before. Old builds skip the header row and keep the station
entries as station ware text (none starts with R or holds @, po, pt).

The reader moves out of TTrainParameters::LoadTTfile into
world/timetablereader.cpp (eu07_core) unchanged, so the tests can run it;
the flags come out of the station ware there. It now ends at the end of
the file with an error where the old one spun forever (a truncated file,
a missing number), and stops at 100 stations instead of writing past
the table.

Every .txt of the game's sceneries and of the SVN data reads the same
as with the old reader (compared field by field against a verbatim copy
of it); EU07_UNIT_TESTS_TIMETABLES=<scenery folder> reads them in the
unit tests and EU07_UNIT_TESTS_TIMETABLES_DUMP writes what was read.
2026-11-17 00:17:22 +01:00

115 lines
3.7 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include "utilities/Classes.h"
#include "audio/sound.h"
#include "world/timetablereader.h"
namespace Mtable
{
static char const *const hrsd = ".";
// Ra: pozycja zerowa rozkładu chyba nie ma sensu
// Ra: numeracja przystanków jest 1..StationCount
// a station of the timetable as the file gives it (TMTableEntry, world/timetablereader.h), with its name announcement
struct TMTableLine : TMTableEntry
{
sound_source name_sound{ sound_placement::engine };
};
using TMTable = TMTableLine[MaxTTableSize + 1];
// typedef TTrainParameters *PTrainParameters;
class TTrainParameters
{
public:
std::string TrainName;
std::string TrainCategory;
std::string TrainLabel;
double TTVmax;
std::string Relation1;
std::string Relation2; // nazwy stacji danego odcinka
double BrakeRatio;
std::string LocSeries; // seria (typ) pojazdu
double LocLoad;
TMTable TimeTable; // TimeTable[0].flags holds the service flags of the whole train
int StationCount; // ilość przystanków (0-techniczny)
int StationIndex; // numer najbliższego (aktualnego) przystanku
int StationStart; // numer pierwszej stacji pokazywanej na podglądzie rozkładu
std::string NextStationName;
double LastStationLatency;
int Direction; /*kierunek jazdy w/g kilometrazu*/
double CheckTrainLatency() const;
/*todo: str hh:mm to int i z powrotem*/
std::string ShowRelation() const;
double WatchMTable(double DistCounter) const;
std::string NextStop() const;
// wpis rozkladu Offset pozycji za StationIndex (Offset>=1); poza zakresem 1..StationCount
// zwraca techniczny wpis zerowy (TimeTable[0], StationName=="nowhere", Ah==-1)
TMTableLine const &TimeTableEntryAhead( int Offset ) const;
sound_source next_stop_sound() const;
sound_source last_stop_sound() const;
bool IsStop() const;
bool IsLastStop() const;
bool IsMaintenance() const;
bool IsTimeToGo(double hh, double mm) const;
// returns: difference between specified time and scheduled departure from current stop, in seconds
double seconds_until_departure( double const Hour, double const Minute ) const;
bool UpdateMTable(double hh, double mm, std::string_view NewName);
bool UpdateMTable( scenario_time const &Time, std::string const &NewName );
bool RewindTimeTable( std::string actualStationName );
explicit TTrainParameters( std::string const &NewTrainName = "none" );
void NewName(std::string_view NewTrainName);
void UpdateVelocity(int StationCount, double vActual);
bool LoadTTfile(std::string const &scnpath, int iPlus, double vmax);
bool DirectionChange() const;
void StationIndexInc();
void serialize( dictionary_source *Output ) const;
// returns: radio channel associated with current station, or -1
int radio_channel() const;
// returns: sound file associated with current station, or -1
sound_source current_stop_sound() const;
// service flags (eu07/maszyna#95) which hold at the stop the train makes for or stands at
timetable::service_flags const &stop_flags() const;
// service flags which hold on the way, since the stop the train left last
timetable::service_flags const &run_flags() const;
private:
void load_sounds();
};
class TMTableTime
{
public:
int dd = 0;
int hh = 0;
int mm = 0;
double mr = 0.0;
void UpdateMTableTime(double deltaT);
TMTableTime(int InitH, int InitM ) :
hh( InitH ),
mm( InitM )
{}
TMTableTime() = default;
};
}
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Mtable;
#endif