(svn r19567) [1.0] -Backport from trunk:

- Feature: Give more detailed error message when trying to build a too long bridge (r19561)
- Fix: [NewGRF] Do not return a random colour for unowned industries in var 45; TTDPatch does not seem to set the colour data in that case either and it could lead to desyncs (r19566)
- Fix: Window::OnResize() was not always called while resizing a window causing incorrect windows [FS#3730] (r19563, r19558)
- Fix: Bridge build error message should not show the same message twice (r19560, r19559)
- Fix: Missed conversion to checking temporary data broke rail type setting upon changing traction type (r19557)
- Fix: Incorrect speed limit reported for rail depots with original acceleration model (r19556)
This commit is contained in:
rubidium 2010-04-05 21:34:47 +00:00
parent 8840831852
commit bb74ec40ea
8 changed files with 47 additions and 38 deletions

View File

@ -67,7 +67,7 @@ static inline const BridgeSpec *GetBridgeSpec(BridgeType i)
void DrawBridgeMiddle(const TileInfo *ti);
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags = DC_NONE);
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags = DC_NONE);
int CalcBridgeLenCostFactor(int x);
void ResetBridges();

View File

@ -375,7 +375,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
default: break; // water ways and air routes don't have bridge types
}
if (_ctrl_pressed && CheckBridge_Stuff(last_bridge_type, bridge_len)) {
if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
DoCommandP(end, start, type | last_bridge_type, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
return;
}
@ -396,7 +396,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
/* loop for all bridgetypes */
for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) {
if (CheckBridge_Stuff(brd_type, bridge_len)) {
if (CheckBridgeAvailability(brd_type, bridge_len).Succeeded()) {
/* bridge is accepted, add to list */
BuildBridgeData *item = bl->Append();
item->index = brd_type;

View File

@ -3518,6 +3518,7 @@ STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT :{WHITE}Bridge h
STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN :{WHITE}Bridge is too low for the terrain
STR_ERROR_START_AND_END_MUST_BE_IN :{WHITE}Start and end must be in line
STR_ERROR_ENDS_OF_BRIDGE_MUST_BOTH :{WHITE}... ends of bridge must both be on land
STR_ERROR_BRIDGE_TOO_LONG :{WHITE}... bridge too long
# Tunnel related errors
STR_ERROR_CAN_T_BUILD_TUNNEL_HERE :{WHITE}Can't build tunnel here...

View File

@ -656,8 +656,8 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
if (_cur_grffile->railtype_max == 0) {
/* Use traction type to select between normal and electrified
* rail only when no translation list is in place. */
if (rvi->railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
if (rvi->railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_RAIL_LABEL;
if (_gted[e->index].railtypelabel == RAILTYPE_RAIL_LABEL && engclass >= EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
if (_gted[e->index].railtypelabel == RAILTYPE_ELECTRIC_LABEL && engclass < EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_RAIL_LABEL;
}
rvi->engclass = engclass;

View File

@ -218,7 +218,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
/* Company info */
case 0x45: {
byte colours;
byte colours = 0;
bool is_ai = false;
const Company *c = Company::GetIfValid(industry->founder);
@ -227,8 +227,6 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
is_ai = c->is_ai;
colours = l->colour1 + l->colour2 * 16;
} else {
colours = GB(Random(), 0, 8);
}
return industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);

View File

@ -2598,10 +2598,12 @@ static void GetTileDesc_Track(TileIndex tile, TileDesc *td)
case RAIL_TILE_DEPOT:
td->str = STR_LAI_RAIL_DESCRIPTION_TRAIN_DEPOT;
if (td->rail_speed > 0) {
td->rail_speed = min(td->rail_speed, 61);
} else {
td->rail_speed = 61;
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) {
if (td->rail_speed > 0) {
td->rail_speed = min(td->rail_speed, 61);
} else {
td->rail_speed = 61;
}
}
break;

View File

@ -160,21 +160,29 @@ static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z)
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
}
bool CheckBridge_Stuff(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
/** Is a bridge of the specified type and length available?
* @param bridge_type Wanted type of bridge.
* @param bridge_len Wanted length of the bridge.
* @return A succeeded (the requested bridge is available) or failed (it cannot be built) command.
*/
CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags)
{
if (flags & DC_QUERY_COST) {
return bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U);
if (bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U)) return CommandCost();
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
}
if (bridge_type >= MAX_BRIDGES) return false;
if (bridge_type >= MAX_BRIDGES) return CMD_ERROR;
const BridgeSpec *b = GetBridgeSpec(bridge_type);
if (b->avail_year > _cur_year) return false;
if (b->avail_year > _cur_year) return CMD_ERROR;
uint max = b->max_length;
if (max >= 16 && _settings_game.construction.longbridges) max = 100;
return b->min_length <= bridge_len && bridge_len <= max;
if (b->min_length > bridge_len) return CMD_ERROR;
if (bridge_len <= max) return CommandCost();
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
}
/** Build a Bridge
@ -242,9 +250,10 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end);
if (transport_type != TRANSPORT_WATER) {
/* set and test bridge length, availability */
if (!CheckBridge_Stuff(bridge_type, bridge_len, flags)) return_cmd_error(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE);
CommandCost ret = CheckBridgeAvailability(bridge_type, bridge_len, flags);
if (ret.Failed()) return ret;
} else {
if (bridge_len > (_settings_game.construction.longbridges ? 100U : 16U)) return_cmd_error(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE);
if (bridge_len > (_settings_game.construction.longbridges ? 100U : 16U)) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
}
/* retrieve landscape height and ensure it's on land */

View File

@ -548,8 +548,7 @@ void Window::ReInit(int rx, int ry)
if (this->resize.step_height > 1) dy -= dy % (int)this->resize.step_height;
ResizeWindow(this, dx, dy);
this->OnResize();
this->SetDirty();
/* ResizeWindow() does this->SetDirty() already, no need to do it again here. */
}
/** Set the shaded state of the window to \a make_shaded.
@ -962,11 +961,12 @@ void Window::FindWindowPlacementAndResize(int def_width, int def_height)
if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
ResizeWindow(this, enlarge_x, enlarge_y);
/* ResizeWindow() calls this->OnResize(). */
} else {
/* Always call OnResize; that way the scrollbars and matrices get initialized. */
this->OnResize();
}
/* Always call OnResize; that way the scrollbars and matrices get initialized */
this->OnResize();
int nx = this->left;
int ny = this->top;
@ -1413,18 +1413,21 @@ static bool HandleMouseOver()
*/
void ResizeWindow(Window *w, int delta_x, int delta_y)
{
if (delta_x == 0 && delta_y == 0) return;
if (delta_x != 0 || delta_y != 0) {
w->SetDirty();
w->SetDirty();
uint new_xinc = max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
uint new_yinc = max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
uint new_xinc = max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
uint new_yinc = max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, _dynlang.text_dir == TD_RTL);
w->width = w->nested_root->current_x;
w->height = w->nested_root->current_y;
}
w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, _dynlang.text_dir == TD_RTL);
w->width = w->nested_root->current_x;
w->height = w->nested_root->current_y;
/* Always call OnResize to make sure everything is initialised correctly if it needs to be. */
w->OnResize();
w->SetDirty();
}
@ -1679,7 +1682,6 @@ static bool HandleWindowDragging()
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
ResizeWindow(w, x, y);
w->OnResize();
return false;
}
}
@ -2548,10 +2550,7 @@ void RelocateAllWindows(int neww, int newh)
* in a 'backup'-desc that the window should always be centred. */
switch (w->window_class) {
case WC_MAIN_TOOLBAR:
if (neww - w->width != 0) {
ResizeWindow(w, min(neww, 640) - w->width, 0);
w->OnResize();
}
if (neww - w->width != 0) ResizeWindow(w, min(neww, 640) - w->width, 0);
top = w->top;
left = PositionMainToolbar(w); // changes toolbar orientation