mirror of https://github.com/OpenTTD/OpenTTD
(svn r8175) -Backport from trunk (r8030, r8070, r8071, r8074):
- crash when removing a town in the scenario editor and the query tool is open for a town's tile (r8030) - (FS#537) heightmap crashes when rescaling, or using 24bpp bitmaps (r8070, r8074) - (FS#536) inauguration date of companies from TTDP games was wrong (r8071)release/0.5
parent
06367834c6
commit
a4bab5f17f
11
heightmap.c
11
heightmap.c
|
@ -225,6 +225,9 @@ static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map)
|
||||||
BmpData data;
|
BmpData data;
|
||||||
BmpBuffer buffer;
|
BmpBuffer buffer;
|
||||||
|
|
||||||
|
// Init BmpData
|
||||||
|
memset(&data, 0, sizeof(data));
|
||||||
|
|
||||||
f = fopen(filename, "rb");
|
f = fopen(filename, "rb");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
ShowErrorMessage(STR_PNGMAP_ERR_FILE_NOT_FOUND, STR_BMPMAP_ERROR, 0, 0);
|
ShowErrorMessage(STR_PNGMAP_ERR_FILE_NOT_FOUND, STR_BMPMAP_ERROR, 0, 0);
|
||||||
|
@ -300,11 +303,11 @@ static void GrayscaleToMapHeights(uint img_width, uint img_height, byte *map)
|
||||||
if ((img_width * num_div) / img_height > ((width * num_div) / height)) {
|
if ((img_width * num_div) / img_height > ((width * num_div) / height)) {
|
||||||
/* Image is wider than map - center vertically */
|
/* Image is wider than map - center vertically */
|
||||||
img_scale = (width * num_div) / img_width;
|
img_scale = (width * num_div) / img_width;
|
||||||
row_pad = (height - ((img_height * img_scale) / num_div)) / 2;
|
row_pad = (1 + height - ((img_height * img_scale) / num_div)) / 2;
|
||||||
} else {
|
} else {
|
||||||
/* Image is taller than map - center horizontally */
|
/* Image is taller than map - center horizontally */
|
||||||
img_scale = (height * num_div) / img_height;
|
img_scale = (height * num_div) / img_height;
|
||||||
col_pad = (width - ((img_width * img_scale) / num_div)) / 2;
|
col_pad = (1 + width - ((img_width * img_scale) / num_div)) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Form the landscape */
|
/* Form the landscape */
|
||||||
|
@ -318,8 +321,8 @@ static void GrayscaleToMapHeights(uint img_width, uint img_height, byte *map)
|
||||||
|
|
||||||
/* Check if current tile is within the 1-pixel map edge or padding regions */
|
/* Check if current tile is within the 1-pixel map edge or padding regions */
|
||||||
if ((DistanceFromEdge(tile) <= 1) ||
|
if ((DistanceFromEdge(tile) <= 1) ||
|
||||||
(row < row_pad) || (row >= (img_height + row_pad)) ||
|
(row < row_pad) || (row >= (height - row_pad - 1)) ||
|
||||||
(col < col_pad) || (col >= (img_width + col_pad))) {
|
(col < col_pad) || (col >= (width - col_pad - 1))) {
|
||||||
SetTileHeight(tile, 0);
|
SetTileHeight(tile, 0);
|
||||||
} else {
|
} else {
|
||||||
/* Use nearest neighbor resizing to scale map data.
|
/* Use nearest neighbor resizing to scale map data.
|
||||||
|
|
169
misc_gui.c
169
misc_gui.c
|
@ -42,85 +42,25 @@ extern void SwitchMode(int new_mode);
|
||||||
static bool _fios_path_changed;
|
static bool _fios_path_changed;
|
||||||
static bool _savegame_sort_dirty;
|
static bool _savegame_sort_dirty;
|
||||||
|
|
||||||
typedef struct LandInfoData {
|
enum {
|
||||||
Town *town;
|
LAND_INFO_LINES = 7,
|
||||||
int32 costclear;
|
LAND_INFO_LINE_BUFF_SIZE = 512,
|
||||||
AcceptedCargo ac;
|
};
|
||||||
TileIndex tile;
|
|
||||||
TileDesc td;
|
static char _landinfo_data[LAND_INFO_LINES][LAND_INFO_LINE_BUFF_SIZE];
|
||||||
} LandInfoData;
|
|
||||||
|
|
||||||
static void LandInfoWndProc(Window *w, WindowEvent *e)
|
static void LandInfoWndProc(Window *w, WindowEvent *e)
|
||||||
{
|
{
|
||||||
if (e->event == WE_PAINT) {
|
if (e->event == WE_PAINT) {
|
||||||
const LandInfoData *lid;
|
|
||||||
StringID str;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
lid = WP(w,void_d).data;
|
DoDrawStringCentered(140, 16, _landinfo_data[0], 13);
|
||||||
|
DoDrawStringCentered(140, 27, _landinfo_data[1], 0);
|
||||||
SetDParam(0, lid->td.dparam[0]);
|
DoDrawStringCentered(140, 38, _landinfo_data[2], 0);
|
||||||
DrawStringCentered(140, 16, lid->td.str, 13);
|
DoDrawStringCentered(140, 49, _landinfo_data[3], 0);
|
||||||
|
DoDrawStringCentered(140, 60, _landinfo_data[4], 0);
|
||||||
SetDParam(0, STR_01A6_N_A);
|
if (_landinfo_data[5][0] != '\0') DrawStringMultiCenter(140, 76, BindCString(_landinfo_data[5]), 276);
|
||||||
if (lid->td.owner != OWNER_NONE && lid->td.owner != OWNER_WATER)
|
if (_landinfo_data[6][0] != '\0') DoDrawStringCentered(140, 71, _landinfo_data[6], 0);
|
||||||
GetNameOfOwner(lid->td.owner, lid->tile);
|
|
||||||
DrawStringCentered(140, 27, STR_01A7_OWNER, 0);
|
|
||||||
|
|
||||||
str = STR_01A4_COST_TO_CLEAR_N_A;
|
|
||||||
if (!CmdFailed(lid->costclear)) {
|
|
||||||
SetDParam(0, lid->costclear);
|
|
||||||
str = STR_01A5_COST_TO_CLEAR;
|
|
||||||
}
|
|
||||||
DrawStringCentered(140, 38, str, 0);
|
|
||||||
|
|
||||||
snprintf(_userstring, lengthof(_userstring), "0x%.4X", lid->tile);
|
|
||||||
SetDParam(0, TileX(lid->tile));
|
|
||||||
SetDParam(1, TileY(lid->tile));
|
|
||||||
SetDParam(2, STR_SPEC_USERSTRING);
|
|
||||||
DrawStringCentered(140, 49, STR_LANDINFO_COORDS, 0);
|
|
||||||
|
|
||||||
SetDParam(0, STR_01A9_NONE);
|
|
||||||
if (lid->town != NULL) {
|
|
||||||
SetDParam(0, STR_TOWN);
|
|
||||||
SetDParam(1, lid->town->index);
|
|
||||||
}
|
|
||||||
DrawStringCentered(140,60, STR_01A8_LOCAL_AUTHORITY, 0);
|
|
||||||
|
|
||||||
{
|
|
||||||
char buf[512];
|
|
||||||
char *p = GetString(buf, STR_01CE_CARGO_ACCEPTED, lastof(buf));
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_CARGO; ++i) {
|
|
||||||
if (lid->ac[i] > 0) {
|
|
||||||
// Add a comma between each item.
|
|
||||||
if (found) {
|
|
||||||
*p++ = ',';
|
|
||||||
*p++ = ' ';
|
|
||||||
}
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
// If the accepted value is less than 8, show it in 1/8:ths
|
|
||||||
if (lid->ac[i] < 8) {
|
|
||||||
SetDParam(0, lid->ac[i]);
|
|
||||||
SetDParam(1, _cargoc.names_s[i]);
|
|
||||||
p = GetString(p, STR_01D1_8, lastof(buf));
|
|
||||||
} else {
|
|
||||||
p = GetString(p, _cargoc.names_s[i], lastof(buf));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) DrawStringMultiCenter(140, 76, BindCString(buf), 276);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lid->td.build_date != 0) {
|
|
||||||
SetDParam(0,lid->td.build_date);
|
|
||||||
DrawStringCentered(140,71, STR_BUILD_DATE, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,31 +82,94 @@ static const WindowDesc _land_info_desc = {
|
||||||
static void Place_LandInfo(TileIndex tile)
|
static void Place_LandInfo(TileIndex tile)
|
||||||
{
|
{
|
||||||
Player *p;
|
Player *p;
|
||||||
static LandInfoData lid;
|
|
||||||
Window *w;
|
Window *w;
|
||||||
|
Town *t;
|
||||||
int64 old_money;
|
int64 old_money;
|
||||||
|
int64 costclear;
|
||||||
|
AcceptedCargo ac;
|
||||||
|
TileDesc td;
|
||||||
|
StringID str;
|
||||||
|
|
||||||
DeleteWindowById(WC_LAND_INFO, 0);
|
DeleteWindowById(WC_LAND_INFO, 0);
|
||||||
|
|
||||||
w = AllocateWindowDesc(&_land_info_desc);
|
w = AllocateWindowDesc(&_land_info_desc);
|
||||||
WP(w,void_d).data = &lid;
|
WP(w, void_d).data = &_landinfo_data;
|
||||||
|
|
||||||
lid.tile = tile;
|
|
||||||
lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
|
||||||
|
|
||||||
p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
|
p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : 0);
|
||||||
|
t = ClosestTownFromTile(tile, _patches.dist_local_authority);
|
||||||
|
|
||||||
old_money = p->money64;
|
old_money = p->money64;
|
||||||
p->money64 = p->player_money = 0x7fffffff;
|
p->money64 = p->player_money = 0x7fffffff;
|
||||||
lid.costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
|
costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
|
||||||
p->money64 = old_money;
|
p->money64 = old_money;
|
||||||
UpdatePlayerMoney32(p);
|
UpdatePlayerMoney32(p);
|
||||||
|
|
||||||
// Becuase build_date is not set yet in every TileDesc, we make sure it is empty
|
/* Because build_date is not set yet in every TileDesc, we make sure it is empty */
|
||||||
lid.td.build_date = 0;
|
td.build_date = 0;
|
||||||
|
GetAcceptedCargo(tile, ac);
|
||||||
|
GetTileDesc(tile, &td);
|
||||||
|
|
||||||
GetAcceptedCargo(tile, lid.ac);
|
SetDParam(0, td.dparam[0]);
|
||||||
GetTileDesc(tile, &lid.td);
|
GetString(_landinfo_data[0], td.str, lastof(_landinfo_data[0]));
|
||||||
|
|
||||||
|
SetDParam(0, STR_01A6_N_A);
|
||||||
|
if (td.owner != OWNER_NONE && td.owner != OWNER_WATER) GetNameOfOwner(td.owner, tile);
|
||||||
|
GetString(_landinfo_data[1], STR_01A7_OWNER, lastof(_landinfo_data[1]));
|
||||||
|
|
||||||
|
str = STR_01A4_COST_TO_CLEAR_N_A;
|
||||||
|
if (!CmdFailed(costclear)) {
|
||||||
|
SetDParam(0, costclear);
|
||||||
|
str = STR_01A5_COST_TO_CLEAR;
|
||||||
|
}
|
||||||
|
GetString(_landinfo_data[2], str, lastof(_landinfo_data[2]));
|
||||||
|
|
||||||
|
snprintf(_userstring, lengthof(_userstring), "0x%.4X", tile);
|
||||||
|
SetDParam(0, TileX(tile));
|
||||||
|
SetDParam(1, TileY(tile));
|
||||||
|
SetDParam(2, STR_SPEC_USERSTRING);
|
||||||
|
GetString(_landinfo_data[3], STR_LANDINFO_COORDS, lastof(_landinfo_data[3]));
|
||||||
|
|
||||||
|
SetDParam(0, STR_01A9_NONE);
|
||||||
|
if (t != NULL && IsValidTown(t)) {
|
||||||
|
SetDParam(0, STR_TOWN);
|
||||||
|
SetDParam(1, t->index);
|
||||||
|
}
|
||||||
|
GetString(_landinfo_data[4], STR_01A8_LOCAL_AUTHORITY, lastof(_landinfo_data[4]));
|
||||||
|
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *p = GetString(_landinfo_data[5], STR_01CE_CARGO_ACCEPTED, lastof(_landinfo_data[5]));
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (i = 0; i < NUM_CARGO; ++i) {
|
||||||
|
if (ac[i] > 0) {
|
||||||
|
/* Add a comma between each item. */
|
||||||
|
if (found) {
|
||||||
|
*p++ = ',';
|
||||||
|
*p++ = ' ';
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
|
||||||
|
/* If the accepted value is less than 8, show it in 1/8:ths */
|
||||||
|
if (ac[i] < 8) {
|
||||||
|
SetDParam(0, ac[i]);
|
||||||
|
SetDParam(1, _cargoc.names_s[i]);
|
||||||
|
p = GetString(p, STR_01D1_8, lastof(_landinfo_data[5]));
|
||||||
|
} else {
|
||||||
|
p = GetString(p, _cargoc.names_s[i], lastof(_landinfo_data[5]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) _landinfo_data[5][0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (td.build_date != 0) {
|
||||||
|
SetDParam(0, td.build_date);
|
||||||
|
GetString(_landinfo_data[6], STR_BUILD_DATE, lastof(_landinfo_data[6]));
|
||||||
|
} else {
|
||||||
|
_landinfo_data[6][0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
# define LANDINFOD_LEVEL 0
|
# define LANDINFOD_LEVEL 0
|
||||||
|
|
|
@ -723,7 +723,6 @@ static bool LoadOldIndustry(LoadgameState *ls, int num)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PlayerID _current_player_id;
|
static PlayerID _current_player_id;
|
||||||
static uint16 _old_inaugurated_year;
|
|
||||||
static int32 _old_yearly;
|
static int32 _old_yearly;
|
||||||
|
|
||||||
static const OldChunks player_yearly_chunk[] = {
|
static const OldChunks player_yearly_chunk[] = {
|
||||||
|
@ -938,7 +937,7 @@ static const OldChunks player_chunk[] = {
|
||||||
OCL_CHUNK( 3, OldPlayerYearly ),
|
OCL_CHUNK( 3, OldPlayerYearly ),
|
||||||
OCL_CHUNK( 1, OldPlayerEconomy ),
|
OCL_CHUNK( 1, OldPlayerEconomy ),
|
||||||
|
|
||||||
OCL_VAR ( OC_UINT16, 1, &_old_inaugurated_year ),
|
OCL_SVAR( OC_FILE_U16 | OC_VAR_I32, Player, inaugurated_year),
|
||||||
OCL_SVAR( OC_TILE, Player, last_build_coordinate ),
|
OCL_SVAR( OC_TILE, Player, last_build_coordinate ),
|
||||||
OCL_SVAR( OC_UINT8, Player, num_valid_stat_ent ),
|
OCL_SVAR( OC_UINT8, Player, num_valid_stat_ent ),
|
||||||
|
|
||||||
|
@ -989,7 +988,7 @@ static bool LoadOldPlayer(LoadgameState *ls, int num)
|
||||||
p->money64 = p->player_money = p->current_loan = 100000;
|
p->money64 = p->player_money = p->current_loan = 100000;
|
||||||
|
|
||||||
_player_colors[num] = p->player_color;
|
_player_colors[num] = p->player_color;
|
||||||
p->inaugurated_year = _old_inaugurated_year;
|
p->inaugurated_year -= ORIGINAL_BASE_YEAR;
|
||||||
if (p->location_of_house == 0xFFFF)
|
if (p->location_of_house == 0xFFFF)
|
||||||
p->location_of_house = 0;
|
p->location_of_house = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue