1
0
Fork 0

(svn r25500) [1.3] -Backport from trunk:

- Remove: SETX(Y) does not work at all with other than default fonts, so get rid of it (r25454)
- Fix: When addings bits to a (train) station, the train trying to stop there could overshoot the (new) stop location and not stop at all [FS#5553] (r25495)
- Fix: The face of the manager differed on clients when the company was started after the clients joined [FS#5610] (r25491, r25490)
release/1.3
rubidium 2013-06-28 19:29:08 +00:00
parent d271dd9566
commit 79c02e4ae4
15 changed files with 58 additions and 203 deletions

View File

@ -588,7 +588,7 @@ ERROR: IsEnd() is invalid as Begin() is never called
SetName(): false
GetLastErrorString(): ERR_NAME_IS_NOT_UNIQUE
GetName(): Regression
GetPresidentName(): P. Sharkey
GetPresidentName(): E. McAlpine
SetPresidentName(): true
GetPresidentName(): Regression AI
GetBankBalance(): 100000

View File

@ -39,7 +39,7 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
SetDParam(0, u->engine_type);
SetDParam(1, u->build_year);
SetDParam(2, u->value);
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
SetDParam(0, u->cargo_type);
SetDParam(1, u->cargo_cap);

View File

@ -910,7 +910,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
SetDParam(0, engine);
DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, SA_STRIP | (rtl ? SA_RIGHT : SA_LEFT));
DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, (rtl ? SA_RIGHT : SA_LEFT));
DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE);
if (show_count) {
SetDParam(0, num_engines);

View File

@ -550,7 +550,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY)
c->avail_railtypes = GetCompanyRailtypes(c->index);
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
c->inaugurated_year = _cur_year;
RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false); // create a random company manager face
RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); // create a random company manager face
SetDefaultCompanySettings(c->index);

View File

@ -201,12 +201,15 @@ static inline void ScaleAllCompanyManagerFaceBits(CompanyManagerFace &cmf)
* @param cmf the company manager's face to write the bits to
* @param ge the gender and ethnicity of the old company manager's face
* @param adv if it for the advanced company manager's face window
* @param interactive is the call from within the user interface?
*
* @pre scale 'ge' to a valid gender/ethnicity combination
*/
static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv)
static inline void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, bool interactive = true)
{
cmf = InteractiveRandom(); // random all company manager's face bits
/* This method is called from a command when not interactive and
* then we must use Random to get the same result on all clients. */
cmf = interactive ? InteractiveRandom() : Random(); // random all company manager's face bits
/* scale ge: 0 == GE_WM, 1 == GE_WF, 2 == GE_BM, 3 == GE_BF (and maybe in future: ...) */
ge = (GenderEthnicity)((uint)ge % GE_END);

View File

@ -369,11 +369,10 @@ static WChar *HandleBiDiAndArabicShapes(WChar *buffer)
* If the string is truncated, add three dots ('...') to show this.
* @param *str string that is checked and possibly truncated
* @param maxw maximum width in pixels of the string
* @param ignore_setxy whether to ignore SETX(Y) or not
* @param start_fontsize Fontsize to start the text with
* @return new width of (truncated) string
*/
static int TruncateString(char *str, int maxw, bool ignore_setxy, FontSize start_fontsize)
static int TruncateString(char *str, int maxw, FontSize start_fontsize)
{
int w = 0;
FontSize size = start_fontsize;
@ -396,13 +395,7 @@ static int TruncateString(char *str, int maxw, bool ignore_setxy, FontSize start
return ddd_w;
}
} else {
if (c == SCC_SETX) {
if (!ignore_setxy) w = *str;
str++;
} else if (c == SCC_SETXY) {
if (!ignore_setxy) w = *str;
str += 2;
} else if (c == SCC_TINYFONT) {
if (c == SCC_TINYFONT) {
size = FS_SMALL;
ddd = GetCharacterWidth(size, '.') * 3;
} else if (c == SCC_BIGFONT) {
@ -446,11 +439,6 @@ static int GetStringWidth(const WChar *str, FontSize start_fontsize)
width += GetCharacterWidth(size, c);
} else {
switch (c) {
case SCC_SETX:
case SCC_SETXY:
/* At this point there is no SCC_SETX(Y) anymore */
NOT_REACHED();
break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n':
@ -483,135 +471,54 @@ static int GetStringWidth(const WChar *str, FontSize start_fontsize)
*/
static int DrawString(int left, int right, int top, char *str, const char *last, DrawStringParams &params, StringAlignment align, bool underline = false, bool truncate = true)
{
/* We need the outer limits of both left/right */
int min_left = INT32_MAX;
int max_right = INT32_MIN;
int initial_left = left;
int initial_right = right;
int initial_top = top;
if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP, params.fontsize);
/*
* To support SETX and SETXY properly with RTL languages we have to
* calculate the offsets from the right. To do this we need to split
* the string and draw the parts separated by SETX(Y).
* So here we split
*/
static SmallVector<WChar *, 4> setx_offsets;
setx_offsets.Clear();
if (truncate) TruncateString(str, right - left + 1, params.fontsize);
WChar draw_buffer[DRAW_STRING_BUFFER];
WChar *p = draw_buffer;
*setx_offsets.Append() = p;
char *loc = str;
for (;;) {
WChar c;
/* We cannot use Utf8Consume as we need the location of the SETX(Y) */
size_t len = Utf8Decode(&c, loc);
const char *text = str;
for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
*p++ = c;
if (c == '\0') break;
if (p >= lastof(draw_buffer) - 3) {
/* Make sure we never overflow (even if copying SCC_SETX(Y)). */
*p = '\0';
break;
}
if (c != SCC_SETX && c != SCC_SETXY) {
loc += len;
continue;
}
if (align & SA_STRIP) {
/* We do not want to keep the SETX(Y)!. It was already copied, so
* remove it and undo the incrementing of the pointer! */
*p-- = '\0';
loc += len + (c == SCC_SETXY ? 2 : 1);
continue;
}
if ((align & SA_HOR_MASK) != SA_LEFT) {
DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
/* For left alignment and change the left so it will roughly be in the
* middle. This will never cause the string to be completely centered,
* but once SETX is used you cannot be sure the actual content of the
* string is centered, so it doesn't really matter. */
align = SA_LEFT | SA_FORCE;
initial_left = left = max(left, (left + right - (int)GetStringBoundingBox(str).width) / 2);
}
/* We add the begin of the string, but don't add it twice */
if (p != draw_buffer) {
*setx_offsets.Append() = p;
p[-1] = '\0';
*p++ = c;
}
/* Skip the SCC_SETX(Y) ... */
loc += len;
/* ... copy the x coordinate ... */
*p++ = *loc++;
/* ... and finally copy the y coordinate if it exists */
if (c == SCC_SETXY) *p++ = *loc++;
}
*p++ = '\0';
/* In case we have a RTL language we swap the alignment. */
if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && !(align & SA_STRIP) && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
for (WChar **iter = setx_offsets.Begin(); iter != setx_offsets.End(); iter++) {
WChar *to_draw = *iter;
int offset = 0;
WChar *to_draw = HandleBiDiAndArabicShapes(draw_buffer);
int w = GetStringWidth(to_draw, params.fontsize);
/* Skip the SETX(Y) and set the appropriate offsets. */
if (*to_draw == SCC_SETX || *to_draw == SCC_SETXY) {
to_draw++;
offset = *to_draw++;
if (*to_draw == SCC_SETXY) top = initial_top + *to_draw++;
}
/* right is the right most position to draw on. In this case we want to do
* calculations with the width of the string. In comparison right can be
* seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
* So most +1/-1 additions are to move from lengthof to 'indices'.
*/
switch (align & SA_HOR_MASK) {
case SA_LEFT:
/* right + 1 = left + w */
right = left + w - 1;
break;
to_draw = HandleBiDiAndArabicShapes(to_draw);
int w = GetStringWidth(to_draw, params.fontsize);
case SA_HOR_CENTER:
left = RoundDivSU(right + 1 + left - w, 2);
/* right + 1 = left + w */
right = left + w - 1;
break;
/* right is the right most position to draw on. In this case we want to do
* calculations with the width of the string. In comparison right can be
* seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
* So most +1/-1 additions are to move from lengthof to 'indices'.
*/
switch (align & SA_HOR_MASK) {
case SA_LEFT:
/* right + 1 = left + w */
left = initial_left + offset;
right = left + w - 1;
break;
case SA_RIGHT:
left = right + 1 - w;
break;
case SA_HOR_CENTER:
left = RoundDivSU(initial_right + 1 + initial_left - w, 2);
/* right + 1 = left + w */
right = left + w - 1;
break;
case SA_RIGHT:
left = initial_right + 1 - w - offset;
break;
default:
NOT_REACHED();
}
min_left = min(left, min_left);
max_right = max(right, max_right);
ReallyDoDrawString(to_draw, left, top, params, !truncate);
if (underline) {
GfxFillRect(left, top + FONT_HEIGHT_NORMAL, right, top + FONT_HEIGHT_NORMAL, _string_colourremap[1]);
}
default:
NOT_REACHED();
}
return (align & SA_HOR_MASK) == SA_RIGHT ? min_left : max_right;
ReallyDoDrawString(to_draw, left, top, params, !truncate);
if (underline) {
GfxFillRect(left, top + FONT_HEIGHT_NORMAL, right, top + FONT_HEIGHT_NORMAL, _string_colourremap[1]);
}
return (align & SA_HOR_MASK) == SA_RIGHT ? left : right;
}
/**
@ -743,8 +650,6 @@ uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize si
} else {
switch (c) {
case '\0': return num + (size << 16);
case SCC_SETX: str++; break;
case SCC_SETXY: str += 2; break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n': goto end_of_inner_loop;
@ -787,8 +692,6 @@ static int GetMultilineStringHeight(const char *src, int num, FontSize start_fon
switch (c) {
case 0: y += fh; if (--num < 0) return maxy; break;
case '\n': y += fh; break;
case SCC_SETX: src++; break;
case SCC_SETXY: src++; y = (int)*src++; break;
case SCC_TINYFONT: fh = GetCharacterHeight(FS_SMALL); break;
case SCC_BIGFONT: fh = GetCharacterHeight(FS_LARGE); break;
default: maxy = max<int>(maxy, y + fh); break;
@ -934,10 +837,6 @@ static int DrawStringMultiLine(int left, int right, int top, int bottom, char *s
WChar c = Utf8Consume(&src);
if (c == 0) {
break;
} else if (c == SCC_SETX) {
src++;
} else if (c == SCC_SETXY) {
src += 2;
} else if (skip_lines > 0) {
/* Skipped drawing, so do additional processing to update params. */
if (c >= SCC_BLUE && c <= SCC_BLACK) {
@ -1026,11 +925,6 @@ Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
br.width += GetCharacterWidth(size, c);
} else {
switch (c) {
case SCC_SETX: br.width = max((uint)*str++, br.width); break;
case SCC_SETXY:
br.width = max((uint)*str++, br.width);
br.height = max((uint)*str++, br.height);
break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n':
@ -1144,9 +1038,6 @@ skip_cont:;
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous colour
params.SetPreviousColour();
goto switch_colour;
} else if (c == SCC_SETX || c == SCC_SETXY) { // {SETX}/{SETXY}
/* The characters are handled before calling this. */
NOT_REACHED();
} else if (c == SCC_TINYFONT) { // {TINYFONT}
params.SetFontSize(FS_SMALL);
} else if (c == SCC_BIGFONT) { // {BIGFONT}

View File

@ -105,7 +105,6 @@ enum StringAlignment {
SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically.
SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
SA_STRIP = 1 << 5, ///< Strip the SETX/SETXY commands from the string
};
DECLARE_ENUM_AS_BIT_SET(StringAlignment)

View File

@ -432,8 +432,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline
switch (c) {
case 0x01:
if (str[0] == '\0') goto string_end;
d += Utf8Encode(d, SCC_SETX);
*d++ = *str++;
d += Utf8Encode(d, ' ');
str++;
break;
case 0x0A: break;
case 0x0D:
@ -447,9 +447,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline
case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break;
case 0x1F:
if (str[0] == '\0' || str[1] == '\0') goto string_end;
d += Utf8Encode(d, SCC_SETXY);
*d++ = *str++;
*d++ = *str++;
d += Utf8Encode(d, ' ');
str += 2;
break;
case 0x7B:
case 0x7C:

View File

@ -35,7 +35,7 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE);
if (v->HasArticulatedPart()) {
CargoArray max_cargo;

View File

@ -62,7 +62,7 @@ void DrawShipDetails(const Vehicle *v, int left, int right, int y)
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo_cap);

View File

@ -3119,7 +3119,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
* begin of the platform to the stop location is longer than the length
* of the platform. Station ahead 'includes' the current tile where the
* vehicle is on, so we need to subtract that. */
if (!IsInsideBS(stop + station_ahead, station_length, TILE_SIZE)) return VETSB_CONTINUE;
if (stop + station_ahead - (int)TILE_SIZE >= station_length) return VETSB_CONTINUE;
DiagDirection dir = DirToDiagDir(v->direction);
@ -3131,14 +3131,11 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
stop &= TILE_SIZE - 1;
if (x == stop) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
if (x < stop) {
uint16 spd;
if (x >= stop) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); // enter station
v->vehstatus |= VS_TRAIN_SLOWING;
spd = max(0, (stop - x) * 20 - 15);
if (spd < v->cur_speed) v->cur_speed = spd;
}
v->vehstatus |= VS_TRAIN_SLOWING;
uint16 spd = max(0, (stop - x) * 20 - 15);
if (spd < v->cur_speed) v->cur_speed = spd;
}
} else if (v->type == VEH_ROAD) {
RoadVehicle *rv = RoadVehicle::From(v);

View File

@ -248,16 +248,6 @@ void str_validate(char *str, const char *last, StringValidationSettings settings
/* Replace the undesirable character with a question mark */
str += len;
if ((settings & SVS_REPLACE_WITH_QUESTION_MARK) != 0) *dst++ = '?';
/* In case of these two special cases assume that they really
* mean SETX/SETXY and also "eat" the parameter. If this was
* not the case the string was broken to begin with and this
* would not break much more. */
if (c == SCC_SETX) {
str++;
} else if (c == SCC_SETXY) {
str += 2;
}
}
}

View File

@ -1003,21 +1003,6 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
break;
}
case SCC_SETX: // {SETX}
if (buff + Utf8CharLen(SCC_SETX) + 1 < last) {
buff += Utf8Encode(buff, SCC_SETX);
*buff++ = *str++;
}
break;
case SCC_SETXY: // {SETXY}
if (buff + Utf8CharLen(SCC_SETXY) + 2 < last) {
buff += Utf8Encode(buff, SCC_SETXY);
*buff++ = *str++;
*buff++ = *str++;
}
break;
case SCC_REVISION: // {REV}
buff = strecpy(buff, _openttd_revision, last);
break;
@ -2036,14 +2021,7 @@ bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
FontSize size = this->DefaultSize();
if (str != NULL) *str = text;
for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
if (c == SCC_SETX) {
/* SetX is, together with SetXY as special character that
* uses the next (two) characters as data points. We have
* to skip those, otherwise the UTF8 reading will go haywire. */
text++;
} else if (c == SCC_SETXY) {
text += 2;
} else if (c == SCC_TINYFONT) {
if (c == SCC_TINYFONT) {
size = FS_SMALL;
} else if (c == SCC_BIGFONT) {
size = FS_LARGE;

View File

@ -27,8 +27,6 @@ enum StringControlCode {
SCC_ENCODED = SCC_CONTROL_START,
/* Display control codes */
SCC_SETX,
SCC_SETXY,
SCC_TINYFONT, ///< Switch to small font
SCC_BIGFONT, ///< Switch to large font

View File

@ -215,12 +215,12 @@ static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
SetDParam(0, v->engine_type);
SetDParam(1, v->value);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
} else {
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
}
}