Improved breakdowns patch: fix various issues

* Whitespace/formatting
* Fix setting lang string
* Fix spelling of VRF_TO_HEAVY
This commit is contained in:
Jonathan G Rennison 2015-08-02 23:00:39 +01:00
parent 9f5164b403
commit 80d52eb20e
12 changed files with 86 additions and 72 deletions

View File

@ -1216,8 +1216,8 @@ static void HandleAircraftSmoke(Aircraft *v, bool mode)
if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
/* breakdown-related speed limits are lifted when we are on the ground */
if(v->state != FLYING && v->state != LANDING && v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED) {
/* Stop smoking when landed */
if (v->state != FLYING && v->state != LANDING && v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED) {
v->vehstatus &= ~VS_AIRCRAFT_BROKEN;
v->breakdown_ctr = 0;
return;

View File

@ -251,7 +251,7 @@ int GroundVehicle<T, Type>::GetAcceleration()
!(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_TO_HEAVY);
SetBit(Train::From(this)->flags, VRF_TOO_HEAVY);
}
}

View File

@ -1223,7 +1223,7 @@ STR_CONFIG_SETTING_STOP_LOCATION :New train order
STR_CONFIG_SETTING_STOP_LOCATION_HELPTEXT :Place where a train will stop at the platform by default. The 'near end' means close to the entry point, 'middle' means in the middle of the platform, and 'far end' means far away from the entry point. Note, that this setting only defines a default value for new orders. Individual orders can be set explicitly to either behaviour nevertheless
STR_CONFIG_SETTING_STOP_LOCATION_NEAR_END :near end
STR_CONFIG_SETTING_STOP_LOCATION_MIDDLE :middle
STR_CONFIG_SETTING_IMPROVED_BREAKDOWNS :{LTBLUE}Enable improved breakdowns: {ORANGE}{STRING}
STR_CONFIG_SETTING_IMPROVED_BREAKDOWNS :Enable improved breakdowns: {STRING2}
STR_CONFIG_SETTING_STOP_LOCATION_FAR_END :far end
STR_CONFIG_SETTING_AUTOSCROLL :Pan window when mouse is at the edge: {STRING2}
STR_CONFIG_SETTING_AUTOSCROLL_HELPTEXT :When enabled, viewports will start to scroll when the mouse is near the edge of the window
@ -3625,7 +3625,7 @@ STR_VEHICLE_STATUS_LEAVING :{LTBLUE}Leaving
STR_VEHICLE_STATUS_CRASHED :{RED}Crashed!
STR_VEHICLE_STATUS_BROKEN_DOWN :{RED}Broken down
STR_VEHICLE_STATUS_STOPPED :{RED}Stopped
STR_VEHICLE_STATUS_BROKEN_DOWN_VEL :{RED}Broken down - {STRING1}, {LTBLUE} {VELOCITY}
STR_VEHICLE_STATUS_BROKEN_DOWN_VEL :{RED}Broken down - {STRING1}, {LTBLUE} {VELOCITY}
STR_VEHICLE_STATUS_TRAIN_STOPPING_VEL :{RED}Stopping, {VELOCITY}
STR_VEHICLE_STATUS_TRAIN_NO_POWER :{RED}No power
STR_VEHICLE_STATUS_TRAIN_STUCK :{ORANGE}Waiting for free path
@ -3662,9 +3662,9 @@ STR_VEHICLE_DETAILS_AIRCRAFT_RENAME :{BLACK}Name air
STR_VEHICLE_INFO_AGE_RUNNING_COST_YR :{BLACK}Age: {LTBLUE}{STRING2}{BLACK} Running Cost: {LTBLUE}{CURRENCY_LONG}/yr
STR_RUNNING :{LTBLUE}Running
STR_NEED_REPAIR :{ORANGE}Train needs repair - max speed reduced to {VELOCITY}
STR_CURRENT_STATUS :{BLACK}Current status: {STRING2}
STR_RUNNING :{LTBLUE}Running
STR_NEED_REPAIR :{ORANGE}Train needs repair - max speed reduced to {VELOCITY}
STR_CURRENT_STATUS :{BLACK}Current status: {STRING2}
# The next two need to stay in this order
STR_VEHICLE_INFO_AGE :{COMMA} year{P "" s} ({COMMA})

View File

@ -163,8 +163,11 @@ protected: // These functions should not be called outside acceleration code.
if (!this->IsArticulatedPart()) {
/* Road vehicle weight is in units of 1/4 t. */
weight += GetVehicleProperty(this, PROP_ROADVEH_WEIGHT, RoadVehInfo(this->engine_type)->weight) / 4;
//DIRTY HACK
if ( !weight ) weight = 1; //at least 1 for realistic accelerate
/*
* TODO: DIRTY HACK: at least 1 for realistic accelerate
*/
if (weight == 0) weight = 1;
}
return weight;

View File

@ -671,8 +671,8 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
SLE_VAR(Vehicle, breakdown_delay, SLE_UINT8),
SLE_VAR(Vehicle, breakdowns_since_last_service, SLE_UINT8),
SLE_VAR(Vehicle, breakdown_chance, SLE_UINT8),
SLE_CONDVAR(Vehicle, breakdown_type, SLE_UINT8, SL_IB, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, breakdown_severity, SLE_UINT8, SL_IB, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, breakdown_type, SLE_UINT8, SL_IB, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, breakdown_severity, SLE_UINT8, SL_IB, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, build_year, SLE_FILE_U8 | SLE_VAR_I32, 0, 30),
SLE_CONDVAR(Vehicle, build_year, SLE_INT32, 31, SL_MAX_VERSION),

View File

@ -37,10 +37,10 @@ enum VehicleRailFlags {
VRF_BREAKDOWN_POWER = 11,///< used to mark a train in which the power of one (or more) of the engines is reduced because of a breakdown
VRF_BREAKDOWN_SPEED = 12,///< used to mark a train that has a reduced maximum speed because of a breakdown
VRF_BREAKDOWN_STOPPED = 13,///< used to mark a train that is stopped because of a breakdown
/* Bitmask of all flags that indicate a broken train (braking is not included) */
VRF_IS_BROKEN = (1 << VRF_BREAKDOWN_POWER) | (1 << VRF_BREAKDOWN_SPEED) | (1 << VRF_BREAKDOWN_STOPPED),
VRF_NEED_REPAIR = 14,///< used to mark a train that has a reduced maximum speed because of a critical breakdown
VRF_TO_HEAVY = 15,
VRF_TOO_HEAVY = 15,
VRF_IS_BROKEN = (1 << VRF_BREAKDOWN_POWER) | (1 << VRF_BREAKDOWN_SPEED) | (1 << VRF_BREAKDOWN_STOPPED), ///< Bitmask of all flags that indicate a broken train (braking is not included)
};
/** Modes for ignoring signals. */
@ -204,7 +204,7 @@ protected: // These functions should not be called outside acceleration code.
}
return speed;
}
/**
* Allows to know the power value that this vehicle will use.
* @return Power value from the engine in HP, or zero if the vehicle is not powered.

View File

@ -237,9 +237,9 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes)
if (speed != 0) max_speed = min(speed, max_speed);
}
if(u->IsEngine() || u-> IsMultiheaded()) {
if (u->IsEngine() || u-> IsMultiheaded()) {
this->tcache.cached_num_engines++;
}
}
}
uint16 new_cap = e_u->DetermineCapacity(u);
@ -467,7 +467,7 @@ int Train::GetCurrentMaxSpeed() const
}
max_speed = min(max_speed, this->current_order.GetMaxSpeed());
if ( HasBit(this->flags, VRF_BREAKDOWN_SPEED) ) {
if (HasBit(this->flags, VRF_BREAKDOWN_SPEED)) {
max_speed = min(max_speed, this->GetBreakdownSpeed());
}
@ -2870,7 +2870,7 @@ static bool HandlePossibleBreakdowns(Train *v)
for (Train *u = v; u != NULL; u = u->Next()) {
if (u->breakdown_ctr != 0 && (u->IsEngine() || u->IsMultiheaded())) {
if (u->breakdown_ctr <= 2) {
if ( u->HandleBreakdown() ) return true;
if (u->HandleBreakdown()) return true;
/* We check the order of v (the first vehicle) instead of u here! */
} else if (!v->current_order.IsType(OT_LOADING)) {
u->breakdown_ctr--;
@ -3755,7 +3755,7 @@ static bool TrainCheckIfLineEnds(Train *v, bool reverse)
{
/* First, handle broken down train */
if(HasBit(v->flags, VRF_BREAKDOWN_BRAKING)) {
if (HasBit(v->flags, VRF_BREAKDOWN_BRAKING)) {
v->vehstatus |= VS_TRAIN_SLOWING;
} else {
v->vehstatus &= ~VS_TRAIN_SLOWING;
@ -3811,7 +3811,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
}
/* train is broken down? */
if ( HandlePossibleBreakdowns(v) ) return true;
if (HandlePossibleBreakdowns(v)) return true;
if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
ReverseTrainDirection(v);

View File

@ -224,24 +224,25 @@ static void TrainDetailsInfoTab(const Train *v, int left, int right, int y, byte
SetDParam(0, v->engine_type);
SetDParam(1, v->value);
if ( show_speed && (speed = GetVehicleProperty(v, PROP_TRAIN_SPEED, rvi->max_speed))) {
if (show_speed && (speed = GetVehicleProperty(v, PROP_TRAIN_SPEED, rvi->max_speed))) {
SetDParam(2, speed); // StringID++
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE_AND_SPEED);
} else
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
} else {
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
}
} else {
switch ( line_number ) {
switch (line_number) {
case 0:
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
if ( show_speed && (speed = GetVehicleProperty(v, PROP_TRAIN_SPEED, rvi->max_speed))) {
if (show_speed && (speed = GetVehicleProperty(v, PROP_TRAIN_SPEED, rvi->max_speed))) {
SetDParam(3, speed); // StringID++
DrawString( left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE_AND_SPEED, TC_FROMSTRING, SA_LEFT);
} else
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE_AND_SPEED, TC_FROMSTRING, SA_LEFT);
} else {
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
}
break;
case 1:
@ -251,27 +252,31 @@ static void TrainDetailsInfoTab(const Train *v, int left, int right, int y, byte
break;
case 2:
if ( v->breakdown_ctr == 1 ) {
if ( _settings_game.vehicle.improved_breakdowns ) {
SetDParam( 0, STR_VEHICLE_STATUS_BROKEN_DOWN_VEL );
SetDParam( 1, STR_BREAKDOWN_TYPE_CRITICAL + v->breakdown_type );
if ( v->breakdown_type == BREAKDOWN_LOW_SPEED ) {
SetDParam( 2, min( v->First( )->GetCurrentMaxSpeed( ), v->breakdown_severity ) );
} else if ( v->breakdown_type == BREAKDOWN_LOW_POWER ) {
SetDParam( 2, v->breakdown_severity * 100 / 256 );
}
} else
if (v->breakdown_ctr == 1) {
if (_settings_game.vehicle.improved_breakdowns) {
SetDParam(0, STR_VEHICLE_STATUS_BROKEN_DOWN_VEL);
SetDParam(1, STR_BREAKDOWN_TYPE_CRITICAL + v->breakdown_type);
if (v->breakdown_type == BREAKDOWN_LOW_SPEED) {
SetDParam(2, min( v->First()->GetCurrentMaxSpeed(), v->breakdown_severity));
} else if (v->breakdown_type == BREAKDOWN_LOW_POWER) {
SetDParam(2, v->breakdown_severity * 100 / 256 );
}
} else {
SetDParam( 0, STR_VEHICLE_STATUS_BROKEN_DOWN );
}
} else {
if ( HasBit( v->flags, VRF_NEED_REPAIR ) ) {
SetDParam( 0, STR_NEED_REPAIR );
SetDParam( 1, v->vcache.cached_max_speed );
} else
SetDParam( 0, STR_RUNNING );
}
DrawString( left, right, y, STR_CURRENT_STATUS);
if (HasBit(v->flags, VRF_NEED_REPAIR)) {
SetDParam(0, STR_NEED_REPAIR);
SetDParam(1, v->vcache.cached_max_speed);
} else {
SetDParam(0, STR_RUNNING);
}
}
DrawString(left, right, y, STR_CURRENT_STATUS);
break;
default: NOT_REACHED();
default:
NOT_REACHED();
}
}
}
@ -483,8 +488,9 @@ void DrawTrainDetails(const Train *v, int left, int right, int y, int vscroll_po
if (det_tab != 1 || line_number >= (Train::From(v)->IsWagon() ? 0 : 2)) {
line_number = 0;
i++;
} else
} else {
line_number++;
}
vscroll_pos--;
}
}

View File

@ -917,13 +917,13 @@ void CallVehicleTicks()
default: break;
case VEH_TRAIN:
if (HasBit(Train::From(v)->flags, VRF_TO_HEAVY)) {
if (HasBit(Train::From(v)->flags, VRF_TOO_HEAVY)) {
_current_company = v->owner;
if (IsLocalCompany()) {
SetDParam(0, v->index);
SetDParam(1, STR_ERROR_TRAIN_TOO_HEAVY);
AddVehicleNewsItem(STR_ERROR_TRAIN_TOO_HEAVY, NT_ADVICE, v->index);
ClrBit(Train::From(v)->flags,VRF_TO_HEAVY);
ClrBit(Train::From(v)->flags, VRF_TOO_HEAVY);
}
_current_company = OWNER_NONE;
}

View File

@ -194,7 +194,7 @@ public:
Vehicle **hash_tile_current; ///< NOSAVE: Cache of the current hash chain.
byte breakdown_severity; ///< severity of the breakdown. Note that lower means more severe
byte breakdown_type; ///< Type of breakdown
byte breakdown_type; ///< Type of breakdown
SpriteID colourmap; ///< NOSAVE: cached colour mapping
/* Related to age and service time */

View File

@ -2610,28 +2610,29 @@ public:
StringID str;
if (v->vehstatus & VS_CRASHED) {
str = STR_VEHICLE_STATUS_CRASHED;
} else if ( v->breakdown_ctr == 1 || ( v->type == VEH_TRAIN && Train::From( v )->flags & VRF_IS_BROKEN ) ) {
if ( _settings_game.vehicle.improved_breakdowns ) {
} else if (v->breakdown_ctr == 1 || (v->type == VEH_TRAIN && Train::From(v)->flags & VRF_IS_BROKEN)) {
if (_settings_game.vehicle.improved_breakdowns) {
str = STR_VEHICLE_STATUS_BROKEN_DOWN_VEL;
SetDParam( 2, v->GetDisplaySpeed( ) );
} else
SetDParam(2, v->GetDisplaySpeed());
} else {
str = STR_VEHICLE_STATUS_BROKEN_DOWN;
}
if ( v->type == VEH_AIRCRAFT ) {
SetDParam( 0, _aircraft_breakdown_strings[v->breakdown_type] );
if ( v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED ) {
SetDParam( 1, v->breakdown_severity << 3 );
if (v->type == VEH_AIRCRAFT) {
SetDParam(0, _aircraft_breakdown_strings[v->breakdown_type]);
if (v->breakdown_type == BREAKDOWN_AIRCRAFT_SPEED) {
SetDParam(1, v->breakdown_severity << 3);
} else {
SetDParam( 1, v->current_order.GetDestination( ) );
SetDParam(1, v->current_order.GetDestination());
}
} else {
const Vehicle *w = ( v->type == VEH_TRAIN ) ? GetMostSeverelyBrokenEngine( Train::From( v ) ) : v;
SetDParam( 0, STR_BREAKDOWN_TYPE_CRITICAL + w->breakdown_type );
const Vehicle *w = (v->type == VEH_TRAIN) ? GetMostSeverelyBrokenEngine(Train::From(v)) : v;
SetDParam(0, STR_BREAKDOWN_TYPE_CRITICAL + w->breakdown_type);
if ( w->breakdown_type == BREAKDOWN_LOW_SPEED ) {
SetDParam( 1, min( w->First()->GetDisplayMaxSpeed( ), w->breakdown_severity >> ( v->type == VEH_TRAIN ? 0 : 1 ) ) );
} else if ( w->breakdown_type == BREAKDOWN_LOW_POWER ) {
SetDParam( 1, w->breakdown_severity * 100 / 256 );
if (w->breakdown_type == BREAKDOWN_LOW_SPEED) {
SetDParam(1, min( w->First()->GetDisplayMaxSpeed(), w->breakdown_severity >> ((v->type == VEH_TRAIN) ? 0 : 1)));
} else if (w->breakdown_type == BREAKDOWN_LOW_POWER) {
SetDParam(1, w->breakdown_severity * 100 / 256);
}
}
} else if (v->vehstatus & VS_STOPPED) {

View File

@ -77,13 +77,17 @@ static const uint MAX_LENGTH_VEHICLE_NAME_CHARS = 32; ///< The maximum length of
/** The length of a vehicle in tile units. */
static const uint VEHICLE_LENGTH = 8;
/* The different types of breakdowns */
/**
* The different types of breakdowns
*
* Aircraft have totally different breakdowns, so we use aliases to make things clearer
*/
enum BreakdownType {
BREAKDOWN_CRITICAL = 0, ///< Old style breakdown (black smoke)
BREAKDOWN_EM_STOP = 1, ///< Emergency stop
BREAKDOWN_LOW_SPEED = 2, ///< Lower max speed
BREAKDOWN_LOW_POWER = 3, ///< Power reduction
/* Aircraft have totally different breakdowns, so we use aliases to make things clearer */
BREAKDOWN_AIRCRAFT_SPEED = BREAKDOWN_CRITICAL, ///< Lower speed until the next airport
BREAKDOWN_AIRCRAFT_DEPOT = BREAKDOWN_EM_STOP, ///< We have to visit a depot at the next airport
BREAKDOWN_AIRCRAFT_EM_LANDING = BREAKDOWN_LOW_SPEED, ///< Emergency landing at the closest airport (with hangar!) we can find