16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 20:59:19 +02:00

build 170916. mouse support for pantograph valve and compressor, minor tweak in ai route selection for cars

This commit is contained in:
tmj-fstate
2017-09-17 03:18:34 +02:00
parent bc1375e83c
commit 6e8fbf7362
8 changed files with 74 additions and 37 deletions

View File

@@ -73,7 +73,16 @@ double GetDistanceToEvent(TTrack const *track, TEvent const *event, double scan_
{ // przejście na inny tor { // przejście na inny tor
track = track->Connected(int(sd), sd); track = track->Connected(int(sd), sd);
start_dist += (1 == krok) ? 0 : back ? -segment->GetLength() : segment->GetLength(); start_dist += (1 == krok) ? 0 : back ? -segment->GetLength() : segment->GetLength();
return GetDistanceToEvent(track, event, sd, start_dist, ++iter, 1 == krok ? true : false); if( track->eType == tt_Cross ) {
// NOTE: tracing through crossroads currently poses risk of tracing through wrong segment
// as it's possible to be performerd before setting a route through the crossroads
// as a stop-gap measure we don't trace through crossroads which should be reasonable in most cases
// TODO: establish route before the scan, or a way for the function to know which route to pick
return start_dist;
}
else {
return GetDistanceToEvent( track, event, sd, start_dist, ++iter, 1 == krok ? true : false );
}
} }
else else
{ // obliczenie mojego toru { // obliczenie mojego toru
@@ -580,11 +589,15 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
// na skrzyżowaniach trzeba wybrać segment, po którym pojedzie pojazd // na skrzyżowaniach trzeba wybrać segment, po którym pojedzie pojazd
// dopiero tutaj jest ustalany kierunek segmentu na skrzyżowaniu // dopiero tutaj jest ustalany kierunek segmentu na skrzyżowaniu
sSpeedTable[iLast].iFlags |= sSpeedTable[iLast].iFlags |=
((pTrack->CrossSegment( ( ( pTrack->CrossSegment(
(fLastDir < 0 ? (fLastDir < 0 ?
tLast->iPrevDirection : tLast->iPrevDirection :
tLast->iNextDirection), tLast->iNextDirection),
iRouteWanted) & 0xf) << 28); // ostatnie 4 bity pola flag /*
iRouteWanted )
*/
1 + std::floor( Random( static_cast<double>(pTrack->RouteCount()) - 0.001 ) ) )
& 0xf ) << 28 ); // ostatnie 4 bity pola flag
sSpeedTable[iLast].iFlags &= ~spReverse; // usunięcie flagi kierunku, bo może być błędna sSpeedTable[iLast].iFlags &= ~spReverse; // usunięcie flagi kierunku, bo może być błędna
if (sSpeedTable[iLast].iFlags < 0) { if (sSpeedTable[iLast].iFlags < 0) {
sSpeedTable[iLast].iFlags |= spReverse; // ustawienie flagi kierunku na podstawie wybranego segmentu sSpeedTable[iLast].iFlags |= spReverse; // ustawienie flagi kierunku na podstawie wybranego segmentu
@@ -592,10 +605,12 @@ void TController::TableTraceRoute(double fDistance, TDynamicObject *pVehicle)
if (int(fLastDir) * sSpeedTable[iLast].iFlags < 0) { if (int(fLastDir) * sSpeedTable[iLast].iFlags < 0) {
fLastDir = -fLastDir; fLastDir = -fLastDir;
} }
/*
if (AIControllFlag) { if (AIControllFlag) {
// dla AI na razie losujemy kierunek na kolejnym skrzyżowaniu // dla AI na razie losujemy kierunek na kolejnym skrzyżowaniu
iRouteWanted = 1 + Random(3); iRouteWanted = 1 + Random(3);
} }
*/
} }
} }
else if ( ( pTrack->fRadius != 0.0 ) // odległość na łuku lepiej aproksymować cięciwami else if ( ( pTrack->fRadius != 0.0 ) // odległość na łuku lepiej aproksymować cięciwami
@@ -5616,12 +5631,12 @@ int TController::CrossRoute(TTrack *tr)
} }
return 0; // nic nie znaleziono? return 0; // nic nie znaleziono?
}; };
/*
void TController::RouteSwitch(int d) void TController::RouteSwitch(int d)
{ // ustawienie kierunku jazdy z kabiny { // ustawienie kierunku jazdy z kabiny
d &= 3; d &= 3;
if( d ) { if( ( d != 0 )
if( iRouteWanted != d ) { // nowy kierunek && ( iRouteWanted != d ) ) { // nowy kierunek
iRouteWanted = d; // zapamiętanie iRouteWanted = d; // zapamiętanie
if( mvOccupied->CategoryFlag & 2 ) { if( mvOccupied->CategoryFlag & 2 ) {
// jeśli samochód // jeśli samochód
@@ -5646,8 +5661,8 @@ void TController::RouteSwitch(int d)
} }
} }
} }
}
}; };
*/
std::string TController::OwnerName() const std::string TController::OwnerName() const
{ {
return ( pVehicle ? pVehicle->MoverParameters->Name : "none" ); return ( pVehicle ? pVehicle->MoverParameters->Name : "none" );

View File

@@ -230,8 +230,9 @@ private:
TAction GetAction() { TAction GetAction() {
return eAction; } return eAction; }
bool AIControllFlag = false; // rzeczywisty/wirtualny maszynista bool AIControllFlag = false; // rzeczywisty/wirtualny maszynista
int iRouteWanted = 3; // oczekiwany kierunek jazdy (0-stop,1-lewo,2-prawo,3-prosto) np. odpala /*
// migacz lub czeka na stan zwrotnicy int iRouteWanted = 3; // oczekiwany kierunek jazdy (0-stop,1-lewo,2-prawo,3-prosto) np. odpala migacz lub czeka na stan zwrotnicy
*/
private: private:
TDynamicObject *pVehicle = nullptr; // pojazd w którym siedzi sterujący TDynamicObject *pVehicle = nullptr; // pojazd w którym siedzi sterujący
TDynamicObject *pVehicles[2]; // skrajne pojazdy w składzie (niekoniecznie bezpośrednio sterowane) TDynamicObject *pVehicles[2]; // skrajne pojazdy w składzie (niekoniecznie bezpośrednio sterowane)
@@ -401,7 +402,9 @@ private:
void DirectionInitial(); void DirectionInitial();
std::string TableText(std::size_t const Index); std::string TableText(std::size_t const Index);
int CrossRoute(TTrack *tr); int CrossRoute(TTrack *tr);
/*
void RouteSwitch(int d); void RouteSwitch(int d);
*/
std::string OwnerName() const; std::string OwnerName() const;
TMoverParameters const *Controlling() const { TMoverParameters const *Controlling() const {
return mvControlling; } return mvControlling; }

View File

@@ -2343,18 +2343,18 @@ int TTrack::CrossSegment(int from, int into)
switch (into) switch (into)
{ {
case 0: // stop case 0: // stop
// WriteLog("Crossing from P"+AnsiString(from+1)+" into stop on "+pMyNode->asName); // WriteLog( "Stopping in P" + to_string( from + 1 ) + " on " + pMyNode->asName );
break; break;
case 1: // left case 1: // left
// WriteLog("Crossing from P"+AnsiString(from+1)+" to left on "+pMyNode->asName); // WriteLog( "Turning left from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
i = (SwitchExtension->iRoads == 4) ? iLewo4[from] : iLewo3[from]; i = (SwitchExtension->iRoads == 4) ? iLewo4[from] : iLewo3[from];
break; break;
case 2: // right case 2: // right
// WriteLog("Crossing from P"+AnsiString(from+1)+" to right on "+pMyNode->asName); // WriteLog( "Turning right from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
i = (SwitchExtension->iRoads == 4) ? iPrawo4[from] : iPrawo3[from]; i = (SwitchExtension->iRoads == 4) ? iPrawo4[from] : iPrawo3[from];
break; break;
case 3: // stright case 3: // stright
// WriteLog("Crossing from P"+AnsiString(from+1)+" to straight on "+pMyNode->asName); // WriteLog( "Going straight from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
i = (SwitchExtension->iRoads == 4) ? iProsto4[from] : iProsto3[from]; i = (SwitchExtension->iRoads == 4) ? iProsto4[from] : iProsto3[from];
break; break;
} }

View File

@@ -209,6 +209,15 @@ public:
SwitchExtension ? SwitchExtension ?
SwitchExtension->CurrentIndex : SwitchExtension->CurrentIndex :
-1); }; -1); };
// returns number of different routes possible to take from given point
// TODO: specify entry point, number of routes for switches can vary
inline
int
RouteCount() const {
return (
SwitchExtension != nullptr ?
SwitchExtension->iRoads - 1 :
1 ); }
void Load(cParser *parser, Math3D::vector3 pOrigin, std::string name); void Load(cParser *parser, Math3D::vector3 pOrigin, std::string name);
bool AssignEvents(TEvent *NewEvent0, TEvent *NewEvent1, TEvent *NewEvent2); bool AssignEvents(TEvent *NewEvent0, TEvent *NewEvent1, TEvent *NewEvent2);
bool AssignallEvents(TEvent *NewEvent0, TEvent *NewEvent1, TEvent *NewEvent2); bool AssignallEvents(TEvent *NewEvent0, TEvent *NewEvent1, TEvent *NewEvent2);

View File

@@ -6735,9 +6735,11 @@ void TTrain::set_cab_controls() {
if( true == bCabLightDim ) { if( true == bCabLightDim ) {
ggCabLightDimButton.PutValue( 1.0 ); ggCabLightDimButton.PutValue( 1.0 );
} }
if( true == InstrumentLightActive ) {
ggInstrumentLightButton.PutValue( 1.0 ); ggInstrumentLightButton.PutValue( (
} InstrumentLightActive ?
1.0 :
0.0 ) );
// doors // doors
// NOTE: we're relying on the cab models to have switches reversed for the rear cab(?) // NOTE: we're relying on the cab models to have switches reversed for the rear cab(?)
ggDoorLeftButton.PutValue( mvOccupied->DoorLeftOpened ? 1.0 : 0.0 ); ggDoorLeftButton.PutValue( mvOccupied->DoorLeftOpened ? 1.0 : 0.0 );

View File

@@ -363,6 +363,12 @@ mouse_input::default_bindings() {
{ "pantselectedoff_sw:", { { "pantselectedoff_sw:", {
user_command::none, user_command::none,
user_command::none } }, // TODO: lower selected pantograp(s) command user_command::none } }, // TODO: lower selected pantograp(s) command
{ "pantcompressor_sw:", {
user_command::pantographcompressoractivate,
user_command::none } },
{ "pantcompressorvalve_sw:", {
user_command::pantographcompressorvalvetoggle,
user_command::none } },
{ "trainheating_sw:", { { "trainheating_sw:", {
user_command::heatingtoggle, user_command::heatingtoggle,
user_command::none } }, user_command::none } },

View File

@@ -70,6 +70,8 @@ static std::unordered_map<std::string, std::string> m_cabcontrols = {
{ "pantalloff_sw:", "all pantographs" }, { "pantalloff_sw:", "all pantographs" },
{ "pantselected_sw:", "selected pantograph" }, { "pantselected_sw:", "selected pantograph" },
{ "pantselectedoff_sw:", "selected pantograph" }, { "pantselectedoff_sw:", "selected pantograph" },
{ "pantcompressor_sw:", "pantograph compressor" },
{ "pantcompressorvalve_sw:", "pantograph 3 way valve" },
{ "trainheating_sw:", "heating" }, { "trainheating_sw:", "heating" },
{ "signalling_sw:", "braking indicator" }, { "signalling_sw:", "braking indicator" },
{ "door_signalling_sw:", "door locking" }, { "door_signalling_sw:", "door locking" },

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 17 #define VERSION_MAJOR 17
#define VERSION_MINOR 914 #define VERSION_MINOR 916
#define VERSION_REVISION 0 #define VERSION_REVISION 0