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

minor ai logic fixes

This commit is contained in:
tmj-fstate
2019-06-16 00:40:04 +02:00
parent a8511c89b3
commit 49e34fa3d8

View File

@@ -3546,29 +3546,56 @@ void TController::SetTimeControllers()
//5.1. Digital controller in DMUs with hydro //5.1. Digital controller in DMUs with hydro
if ((mvControlling->EngineType == TEngineType::DieselEngine) && (mvControlling->EIMCtrlType == 3)) if ((mvControlling->EngineType == TEngineType::DieselEngine) && (mvControlling->EIMCtrlType == 3))
{ {
if( mvControlling->Vel > 10 ) {
DizelPercentage_Speed = DizelPercentage; DizelPercentage_Speed = DizelPercentage;
double Factor = 10 * (mvControlling->Vmax) / (mvControlling->Vmax + 3*mvControlling->Vel); auto const Factor{ 10 * ( mvControlling->Vmax ) / ( mvControlling->Vmax + 3 * mvControlling->Vel ) };
double DesiredPercentage = (VelDesired > mvControlling->Vel ? (VelDesired - mvControlling->Vel) / Factor : 0); auto DesiredPercentage{ clamp(
DesiredPercentage = clamp(DesiredPercentage, 0.0, 1.0); ( VelDesired > mvControlling->Vel ?
if (VelDesired < 0.5 * mvControlling->Vmax && VelDesired - mvControlling->Vel < 10) ( VelDesired - mvControlling->Vel ) / Factor :
DesiredPercentage = std::min(DesiredPercentage, 0.75); 0 ),
int DizelActualPercentage = 100.4 * mvControlling->eimic_real; 0.0, 1.0 ) };
int PosInc = mvControlling->MainCtrlPosNo; if( ( VelDesired < 0.5 * mvControlling->Vmax )
int PosDec = 0; && ( VelDesired - mvControlling->Vel < 10 ) ) {
for(int i=PosInc;i>=0;i--) DesiredPercentage = std::min( DesiredPercentage, 0.75 );
if ((mvControlling->UniCtrlList[i].SetCtrlVal <= 0) && (mvControlling->UniCtrlList[i].SpeedDown > 0.01)) }
{ DizelPercentage_Speed = std::round( DesiredPercentage * DizelPercentage );
if( VelDesired < std::min( mvControlling->hydro_TC_LockupSpeed, mvControlling->Vmax / 5 ) ) {
DizelPercentage = std::min( DizelPercentage_Speed, 1 );
}
}
else {
// HACK: workaround for the default mode breaking at low speeds
DizelPercentage = DizelPercentage_Speed = ( AccDesired > 0.0 ? 100 : 0 );
}
auto const DizelActualPercentage { 100.4 * mvControlling->eimic_real };
auto const PosInc { mvControlling->MainCtrlPosNo };
auto PosDec { 0 };
for( int i = PosInc; i >= 0; --i ) {
if( ( mvControlling->UniCtrlList[ i ].SetCtrlVal <= 0 )
&& ( mvControlling->UniCtrlList[ i ].SpeedDown > 0.01 ) ) {
PosDec = i; PosDec = i;
break; break;
} }
DizelPercentage_Speed = round(double(DizelPercentage*DesiredPercentage)); }
if (VelDesired < std::min(mvControlling->hydro_TC_LockupSpeed,mvControlling->Vmax / 5)) DizelPercentage = std::min(DizelPercentage_Speed, 1);
if (abs(DizelPercentage_Speed - DizelActualPercentage)>(DizelPercentage>1?3:0)) if( std::abs( DizelPercentage_Speed - DizelActualPercentage ) > ( DizelPercentage > 1 ? 3 : 0 ) ) {
{
if (((DizelPercentage_Speed == 0 && DizelActualPercentage > 10) || (DizelActualPercentage - DizelPercentage_Speed > 50)) && PosDec > 0) PosDec -= 1; //pozycję wczesniej powinno byc szybkie zejscie, jeśli trzeba if( ( PosDec > 0 )
int DesiredPos = (DizelPercentage_Speed > DizelActualPercentage ? PosInc : PosDec); && ( ( DizelActualPercentage - DizelPercentage_Speed > 50 )
while (mvControlling->MainCtrlPos > DesiredPos) mvControlling->DecMainCtrl(1); || ( ( DizelPercentage_Speed == 0 )
while (mvControlling->MainCtrlPos < DesiredPos) mvControlling->IncMainCtrl(1); && ( DizelActualPercentage > 10 ) ) ) ) {
//pozycję wczesniej powinno byc szybkie zejscie, jeśli trzeba
PosDec -= 1;
}
auto const DesiredPos { (
DizelPercentage_Speed > DizelActualPercentage ?
PosInc :
PosDec ) };
while( mvControlling->MainCtrlPos > DesiredPos ) { mvControlling->DecMainCtrl( 1 ); }
while( mvControlling->MainCtrlPos < DesiredPos ) { mvControlling->IncMainCtrl( 1 ); }
} }
} }
else else
@@ -5158,6 +5185,7 @@ TController::UpdateSituation(double dt) {
// za radą yB ustawiamy pozycję 3 kranu (ruszanie kranem w innych miejscach // za radą yB ustawiamy pozycję 3 kranu (ruszanie kranem w innych miejscach
// powino zostać wyłączone) // powino zostać wyłączone)
// WriteLog("Zahamowanie składu"); // WriteLog("Zahamowanie składu");
AccDesired = std::min( AccDesired, -0.9 ); // HACK: make sure the ai doesn't try to release the brakes to accelerate
if( mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ) { if( mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic ) {
mvOccupied->BrakeLevelSet( mvOccupied->Handle->GetPos( bh_EPB ) ); mvOccupied->BrakeLevelSet( mvOccupied->Handle->GetPos( bh_EPB ) );
} }