Merge branch 'improved_breakdowns' into improved_breakdowns-sx

This commit is contained in:
Jonathan G Rennison
2015-09-27 23:17:58 +01:00
3 changed files with 93 additions and 87 deletions

View File

@@ -1021,6 +1021,14 @@ static bool RoadVehAccelerationModelChanged(int32 p1)
} }
} }
} }
if (_settings_game.vehicle.roadveh_acceleration_model == AM_ORIGINAL || !_settings_game.vehicle.improved_breakdowns) {
RoadVehicle *rv;
FOR_ALL_ROADVEHICLES(rv) {
if (rv->IsFrontEngine()) {
rv->breakdown_chance = 128;
}
}
}
/* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */ /* These windows show acceleration values only when realistic acceleration is on. They must be redrawn after a setting change. */
SetWindowClassesDirty(WC_ENGINE_PREVIEW); SetWindowClassesDirty(WC_ENGINE_PREVIEW);

View File

@@ -484,8 +484,13 @@ void Train::UpdateAcceleration()
assert(weight != 0); assert(weight != 0);
this->acceleration = Clamp(power / weight * 4, 1, 255); this->acceleration = Clamp(power / weight * 4, 1, 255);
/* for non-realistic acceleration, breakdown chance is 128, corrected by the multiengine factor of 3/(n+2) */ if (_settings_game.vehicle.improved_breakdowns) {
this->breakdown_chance = min(128 * 3 / (this->tcache.cached_num_engines + 2), 5); if (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
this->breakdown_chance = max(128 * 3 / (this->tcache.cached_num_engines + 2), 5);
}
} else {
this->breakdown_chance = 128;
}
} }
/** /**

View File

@@ -116,16 +116,12 @@ void VehicleServiceInDepot(Vehicle *v)
v->reliability = e->reliability; v->reliability = e->reliability;
v->breakdown_ctr = 0; v->breakdown_ctr = 0;
v->vehstatus &= ~VS_AIRCRAFT_BROKEN; v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
/* Prevent vehicles from breaking down directly after exiting the depot. */
v->breakdown_chance /= 4;
SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated
do { do {
v->date_of_last_service = _date; v->date_of_last_service = _date;
v->breakdowns_since_last_service = 0; v->breakdowns_since_last_service = 0;
v->reliability = v->GetEngine()->reliability; v->reliability = v->GetEngine()->reliability;
/* Prevent vehicles from breaking down directly after exiting the depot. */
v->breakdown_chance /= 4;
v = v->Next(); v = v->Next();
} while (v != NULL && v->HasEngineType()); } while (v != NULL && v->HasEngineType());
} }
@@ -1193,8 +1189,7 @@ static const byte _breakdown_chances[4][4] = {
* @param v the vehicle in question. * @param v the vehicle in question.
* @param r the random number to use. (Note that bits 0..6 are already used) * @param r the random number to use. (Note that bits 0..6 are already used)
*/ */
void void DetermineBreakdownType(Vehicle *v, uint32 r) {
DetermineBreakdownType( Vehicle *v, uint32 r ) {
/* if 'improved breakdowns' is off, just do the classic breakdown */ /* if 'improved breakdowns' is off, just do the classic breakdown */
if (!_settings_game.vehicle.improved_breakdowns) { if (!_settings_game.vehicle.improved_breakdowns) {
v->breakdown_type = BREAKDOWN_CRITICAL; v->breakdown_type = BREAKDOWN_CRITICAL;
@@ -1341,7 +1336,6 @@ bool Vehicle::HandleBreakdown()
(this->current_order.GetDepotOrderType() & ODTFB_BREAKDOWN) && (this->current_order.GetDepotOrderType() & ODTFB_BREAKDOWN) &&
GetTargetAirportIfValid(Aircraft::From(this)) != NULL)) return false; GetTargetAirportIfValid(Aircraft::From(this)) != NULL)) return false;
FindBreakdownDestination(Aircraft::From(this)); FindBreakdownDestination(Aircraft::From(this));
} else if (this->type == VEH_TRAIN) { } else if (this->type == VEH_TRAIN) {
if (this->breakdown_type == BREAKDOWN_LOW_POWER || if (this->breakdown_type == BREAKDOWN_LOW_POWER ||
this->First()->cur_speed <= ((this->breakdown_type == BREAKDOWN_LOW_SPEED) ? this->breakdown_severity : 0)) { this->First()->cur_speed <= ((this->breakdown_type == BREAKDOWN_LOW_SPEED) ? this->breakdown_severity : 0)) {
@@ -1353,7 +1347,7 @@ bool Vehicle::HandleBreakdown()
(train_or_ship ? SND_10_TRAIN_BREAKDOWN : SND_0F_VEHICLE_BREAKDOWN) : (train_or_ship ? SND_10_TRAIN_BREAKDOWN : SND_0F_VEHICLE_BREAKDOWN) :
(train_or_ship ? SND_3A_COMEDY_BREAKDOWN_2 : SND_35_COMEDY_BREAKDOWN), this); (train_or_ship ? SND_3A_COMEDY_BREAKDOWN_2 : SND_35_COMEDY_BREAKDOWN), this);
} }
if (!(this->vehstatus & VS_HIDDEN)) { if (!(this->vehstatus & VS_HIDDEN) && !HasBit(EngInfo(this->engine_type)->misc_flags, EF_NO_BREAKDOWN_SMOKE) && this->breakdown_delay > 0) {
EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE); EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE);
if (u != NULL) u->animation_state = this->breakdown_delay * 2; if (u != NULL) u->animation_state = this->breakdown_delay * 2;
} }
@@ -1365,10 +1359,8 @@ bool Vehicle::HandleBreakdown()
if (rvi->max_speed > this->vcache.cached_max_speed) if (rvi->max_speed > this->vcache.cached_max_speed)
this->vcache.cached_max_speed = rvi->max_speed; this->vcache.cached_max_speed = rvi->max_speed;
} }
this->vcache.cached_max_speed = this->vcache.cached_max_speed = min(this->vcache.cached_max_speed -
min( (this->vcache.cached_max_speed >> 1) / Train::From(this->First())->tcache.cached_num_engines + 1, this->vcache.cached_max_speed);
this->vcache.cached_max_speed - (this->vcache.cached_max_speed >> 1) / Train::From(this->First())->tcache.cached_num_engines + 1,
this->vcache.cached_max_speed);
SetBit(Train::From(this)->flags, VRF_NEED_REPAIR); SetBit(Train::From(this)->flags, VRF_NEED_REPAIR);
Train::From(this->First())->ConsistChanged(CCF_TRACK); Train::From(this->First())->ConsistChanged(CCF_TRACK);
} }
@@ -1386,7 +1378,6 @@ bool Vehicle::HandleBreakdown()
break; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
this->First()->MarkDirty(); this->First()->MarkDirty();
SetWindowDirty(WC_VEHICLE_VIEW, this->index); SetWindowDirty(WC_VEHICLE_VIEW, this->index);
SetWindowDirty(WC_VEHICLE_DETAILS, this->index); SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
@@ -1396,8 +1387,10 @@ bool Vehicle::HandleBreakdown()
SetBit(Train::From(this)->flags, VRF_BREAKDOWN_BRAKING); SetBit(Train::From(this)->flags, VRF_BREAKDOWN_BRAKING);
return false; return false;
} }
if ( ( !( this->vehstatus & VS_HIDDEN ) ) && ( ( this->breakdown_type == BREAKDOWN_LOW_SPEED || this->breakdown_type == BREAKDOWN_LOW_POWER ) && ( this->tick_counter & 0x1F ) == 0 ) ) { if ((!(this->vehstatus & VS_HIDDEN)) && (this->breakdown_type == BREAKDOWN_LOW_SPEED || this->breakdown_type == BREAKDOWN_LOW_POWER)
CreateEffectVehicleRel( this, 0, 0, 2, EV_BREAKDOWN_SMOKE ); //some grey clouds to indicate a broken engine && !HasBit(EngInfo(this->engine_type)->misc_flags, EF_NO_BREAKDOWN_SMOKE)) {
EffectVehicle *u = CreateEffectVehicleRel(this, 0, 0, 2, EV_BREAKDOWN_SMOKE); //some grey clouds to indicate a broken engine
if (u != NULL) u->animation_state = 25;
} }
} else { } else {
switch (this->breakdown_type) { switch (this->breakdown_type) {
@@ -1405,7 +1398,7 @@ bool Vehicle::HandleBreakdown()
if (!PlayVehicleSound(this, VSE_BREAKDOWN)) { if (!PlayVehicleSound(this, VSE_BREAKDOWN)) {
SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ? SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, this); SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ? SND_0F_VEHICLE_BREAKDOWN : SND_35_COMEDY_BREAKDOWN, this);
} }
if (!(this->vehstatus & VS_HIDDEN)) { if (!(this->vehstatus & VS_HIDDEN) && !HasBit(EngInfo(this->engine_type)->misc_flags, EF_NO_BREAKDOWN_SMOKE) && this->breakdown_delay > 0) {
EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE); EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE);
if (u != NULL) u->animation_state = this->breakdown_delay * 2; if (u != NULL) u->animation_state = this->breakdown_delay * 2;
} }
@@ -1419,11 +1412,11 @@ bool Vehicle::HandleBreakdown()
break; break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
if ( ( !( this->vehstatus & VS_HIDDEN ) ) && ( if ((!(this->vehstatus & VS_HIDDEN)) &&
( this->breakdown_type == BREAKDOWN_LOW_SPEED || this->breakdown_type == BREAKDOWN_LOW_POWER ) && (this->breakdown_type == BREAKDOWN_LOW_SPEED || this->breakdown_type == BREAKDOWN_LOW_POWER)) {
( this->tick_counter & 0x1F ) == 0 ) ) {
/* Some gray clouds to indicate a broken RV */ /* Some gray clouds to indicate a broken RV */
CreateEffectVehicleRel( this, 0, 0, 2, EV_BREAKDOWN_SMOKE ); EffectVehicle *u = CreateEffectVehicleRel(this, 0, 0, 2, EV_BREAKDOWN_SMOKE);
if (u != NULL) u->animation_state = 25;
} }
this->First()->MarkDirty(); this->First()->MarkDirty();
SetWindowDirty(WC_VEHICLE_VIEW, this->index); SetWindowDirty(WC_VEHICLE_VIEW, this->index);