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
track = track->Connected(int(sd), sd);
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
{ // 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
// dopiero tutaj jest ustalany kierunek segmentu na skrzyżowaniu
sSpeedTable[iLast].iFlags |=
((pTrack->CrossSegment(
(fLastDir < 0 ?
tLast->iPrevDirection :
tLast->iNextDirection),
iRouteWanted) & 0xf) << 28); // ostatnie 4 bity pola flag
( ( pTrack->CrossSegment(
(fLastDir < 0 ?
tLast->iPrevDirection :
tLast->iNextDirection),
/*
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
if (sSpeedTable[iLast].iFlags < 0) {
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) {
fLastDir = -fLastDir;
}
/*
if (AIControllFlag) {
// dla AI na razie losujemy kierunek na kolejnym skrzyżowaniu
iRouteWanted = 1 + Random(3);
}
*/
}
}
else if ( ( pTrack->fRadius != 0.0 ) // odległość na łuku lepiej aproksymować cięciwami
@@ -5616,31 +5631,30 @@ int TController::CrossRoute(TTrack *tr)
}
return 0; // nic nie znaleziono?
};
/*
void TController::RouteSwitch(int d)
{ // ustawienie kierunku jazdy z kabiny
d &= 3;
if( d ) {
if( iRouteWanted != d ) { // nowy kierunek
iRouteWanted = d; // zapamiętanie
if( mvOccupied->CategoryFlag & 2 ) {
// jeśli samochód
for( std::size_t i = 0; i < sSpeedTable.size(); ++i ) {
// szukanie pierwszego skrzyżowania i resetowanie kierunku na nim
if( true == TestFlag( sSpeedTable[ i ].iFlags, spEnabled | spTrack ) ) {
// jeśli pozycja istotna (1) oraz odcinek (2)
if( false == TestFlag( sSpeedTable[ i ].iFlags, spElapsed ) ) {
// odcinek nie może być miniętym
if( sSpeedTable[ i ].trTrack->eType == tt_Cross ) // jeśli skrzyżowanie
{
while( sSpeedTable.size() >= i ) {
// NOTE: we're ignoring semaphor flags and not resetting them like we do for train route trimming
// but what if there's street lights?
// TODO: investigate
sSpeedTable.pop_back();
}
iLast = sSpeedTable.size();
if( ( d != 0 )
&& ( iRouteWanted != d ) ) { // nowy kierunek
iRouteWanted = d; // zapamiętanie
if( mvOccupied->CategoryFlag & 2 ) {
// jeśli samochód
for( std::size_t i = 0; i < sSpeedTable.size(); ++i ) {
// szukanie pierwszego skrzyżowania i resetowanie kierunku na nim
if( true == TestFlag( sSpeedTable[ i ].iFlags, spEnabled | spTrack ) ) {
// jeśli pozycja istotna (1) oraz odcinek (2)
if( false == TestFlag( sSpeedTable[ i ].iFlags, spElapsed ) ) {
// odcinek nie może być miniętym
if( sSpeedTable[ i ].trTrack->eType == tt_Cross ) // jeśli skrzyżowanie
{
while( sSpeedTable.size() >= i ) {
// NOTE: we're ignoring semaphor flags and not resetting them like we do for train route trimming
// but what if there's street lights?
// TODO: investigate
sSpeedTable.pop_back();
}
iLast = sSpeedTable.size();
}
}
}
@@ -5648,6 +5662,7 @@ void TController::RouteSwitch(int d)
}
}
};
*/
std::string TController::OwnerName() const
{
return ( pVehicle ? pVehicle->MoverParameters->Name : "none" );

View File

@@ -230,8 +230,9 @@ private:
TAction GetAction() {
return eAction; }
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:
TDynamicObject *pVehicle = nullptr; // pojazd w którym siedzi sterujący
TDynamicObject *pVehicles[2]; // skrajne pojazdy w składzie (niekoniecznie bezpośrednio sterowane)
@@ -401,7 +402,9 @@ private:
void DirectionInitial();
std::string TableText(std::size_t const Index);
int CrossRoute(TTrack *tr);
/*
void RouteSwitch(int d);
*/
std::string OwnerName() const;
TMoverParameters const *Controlling() const {
return mvControlling; }

View File

@@ -2343,18 +2343,18 @@ int TTrack::CrossSegment(int from, int into)
switch (into)
{
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;
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];
break;
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];
break;
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];
break;
}

View File

@@ -209,6 +209,15 @@ public:
SwitchExtension ?
SwitchExtension->CurrentIndex :
-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);
bool AssignEvents(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 ) {
ggCabLightDimButton.PutValue( 1.0 );
}
if( true == InstrumentLightActive ) {
ggInstrumentLightButton.PutValue( 1.0 );
}
ggInstrumentLightButton.PutValue( (
InstrumentLightActive ?
1.0 :
0.0 ) );
// doors
// NOTE: we're relying on the cab models to have switches reversed for the rear cab(?)
ggDoorLeftButton.PutValue( mvOccupied->DoorLeftOpened ? 1.0 : 0.0 );

View File

@@ -363,6 +363,12 @@ mouse_input::default_bindings() {
{ "pantselectedoff_sw:", {
user_command::none,
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:", {
user_command::heatingtoggle,
user_command::none } },

View File

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

View File

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