diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index 502d186ea4..071913ac8f 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -171,8 +171,7 @@ int GroundVehicle::GetAcceleration() AccelStatus mode = v->GetAccelerationStatus(); /* handle breakdown power reduction */ - //TODO - if( Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) { + if (Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) { /* We'd like to cache this, but changing cached_power has too many unwanted side-effects */ uint32 power_temp; this->CalculatePower(power_temp, max_te, true); @@ -198,7 +197,7 @@ int GroundVehicle::GetAcceleration() } /* If power is 0 because of a breakdown, we make the force 0 if accelerating */ - if ( Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER) && power == 0) { + if (Type == VEH_TRAIN && mode == AS_ACCEL && HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER) && power == 0) { force = 0; } @@ -214,7 +213,7 @@ int GroundVehicle::GetAcceleration() uint64 breakdown_factor = (uint64)abs(resistance) * (uint64)(this->cur_speed << 16); breakdown_factor /= (max(force, (int64)100) * this->gcache.cached_max_track_speed); breakdown_factor = min((64 << 16) + (breakdown_factor * 128), 255 << 16); - if ( Type == VEH_TRAIN && Train::From(this)->tcache.cached_num_engines > 1) { + if (Type == VEH_TRAIN && Train::From(this)->tcache.cached_num_engines > 1) { /* For multiengine trains, breakdown chance is multiplied by 3 / (num_engines + 2) */ breakdown_factor *= 3; breakdown_factor /= (Train::From(this)->tcache.cached_num_engines + 2); @@ -238,7 +237,7 @@ int GroundVehicle::GetAcceleration() accel = force < resistance ? min(-1, accel) : max(1, accel); if (this->type == VEH_TRAIN ) { if(_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL && - HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) { + HasBit(Train::From(this)->flags, VRF_BREAKDOWN_POWER)) { /* We need to apply the power reducation for non-realistic acceleration here */ uint32 power; CalculatePower(power, max_te, true); @@ -246,11 +245,10 @@ int GroundVehicle::GetAcceleration() accel -= this->acceleration >> 1; } - - if ( this->IsFrontEngine() && !(this->current_order_time & 0x1FF) && - !(this->current_order.IsType(OT_LOADING)) && - !(Train::From(this)->flags & (VRF_IS_BROKEN | (1 << VRF_TRAIN_STUCK))) && - this->cur_speed < 3 && accel < 5) { + if (this->IsFrontEngine() && !(this->current_order_time & 0x1FF) && + !(this->current_order.IsType(OT_LOADING)) && + !(Train::From(this)->flags & (VRF_IS_BROKEN | (1 << VRF_TRAIN_STUCK))) && + this->cur_speed < 3 && accel < 5) { SetBit(Train::From(this)->flags, VRF_TOO_HEAVY); } } diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index 00dcfca721..86f328fe1e 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -376,16 +376,17 @@ protected: if (this->breakdown_ctr == 1) { if (this->breakdown_type == BREAKDOWN_LOW_POWER) { - if((this->tick_counter & 0x7) == 0) { - if(this->cur_speed > (this->breakdown_severity * max_speed) >> 8) { + if ((this->tick_counter & 0x7) == 0) { + if (this->cur_speed > (this->breakdown_severity * max_speed) >> 8) { tempmax = this->cur_speed - (this->cur_speed / 10) - 1; } else { tempmax = (this->breakdown_severity * max_speed) >> 8; } } } - if(this->breakdown_type == BREAKDOWN_LOW_SPEED) + if (this->breakdown_type == BREAKDOWN_LOW_SPEED) { tempmax = min(max_speed, this->breakdown_severity); + } } if (this->cur_speed > max_speed) { diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index e7e2961bdd..9bd985c536 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -382,15 +382,15 @@ static bool ShipAccelerate(Vehicle *v) spd = min(v->cur_speed + 1, v->vcache.cached_max_speed); spd = min(spd, v->current_order.GetMaxSpeed() * 2); - if(v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_LOW_POWER && v->cur_speed > (v->breakdown_severity * ShipVehInfo(v->engine_type)->max_speed) >> 8) { - if((v->tick_counter & 0x7) == 0 && v->cur_speed > 0) { + if (v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_LOW_POWER && v->cur_speed > (v->breakdown_severity * ShipVehInfo(v->engine_type)->max_speed) >> 8) { + if ((v->tick_counter & 0x7) == 0 && v->cur_speed > 0) { spd = v->cur_speed - 1; } else { spd = v->cur_speed; } } - if(v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_LOW_SPEED) { + if (v->breakdown_ctr == 1 && v->breakdown_type == BREAKDOWN_LOW_SPEED) { spd = min(spd, v->breakdown_severity); } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 4c83477fd5..6cc941f562 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -4079,7 +4079,7 @@ void Train::OnNewDay() SetWindowClassesDirty(WC_TRAINS_LIST); } } - if(IsEngine() || IsMultiheaded()) { + if (IsEngine() || IsMultiheaded()) { CheckVehicleBreakdown(this); } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 398c61bdae..d357d2c9f9 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1430,7 +1430,7 @@ bool Vehicle::HandleBreakdown() if ((this->tick_counter & (this->type == VEH_TRAIN ? 3 : 1)) == 0) { if (--this->breakdown_delay == 0) { this->breakdown_ctr = 0; - if(this->type == VEH_TRAIN) { + if (this->type == VEH_TRAIN) { CheckBreakdownFlags(Train::From(this->First())); this->First()->MarkDirty(); SetWindowDirty(WC_VEHICLE_VIEW, this->First()->index);