1
0
Fork 0

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

- Feature: [NewGRF] Add 2 bits of pseudo-random data for rail types, based on tile location (r19235)
- Fix: Writing (console) output to a file failed on Windows if the date would not be logged [FS#3639] (r19252)
- Fix: [NewGRF] Some GRF error messages did not free the previous error messages, creating a memory leak (r19251)
- Fix: With RTL languages clicking a horizontal scrollbar that could not scroll could cause a crash [FS#3643] (r19250)
- Fix: Start and end tiles were swapped in CMD_REMOVE_LONG_ROAD causing too much road to be removed [FS#3642] (r19249)
- Fix: DOS 'port' did not compile anymore (r19248)
- Fix: The -M command line option did not work (r19233)
release/1.0
rubidium 2010-02-25 21:18:38 +00:00
parent bfa5e7fef5
commit 7ed9361ad9
11 changed files with 60 additions and 57 deletions

View File

@ -549,7 +549,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 1 : 2) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
}
/* static */ bool AIRoad::RemoveRoadFull(TileIndex start, TileIndex end)
@ -559,7 +559,7 @@ static bool NeighbourHasReachableRoad(::RoadTypes rts, TileIndex start_tile, Dia
EnforcePrecondition(false, ::TileX(start) == ::TileX(end) || ::TileY(start) == ::TileY(end));
EnforcePrecondition(false, IsRoadTypeAvailable(GetCurrentRoadType()));
return AIObject::DoCommand(end, start, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
return AIObject::DoCommand(start, end, (::TileY(start) != ::TileY(end) ? 4 : 0) | (start < end ? 2 : 1) | (AIObject::GetRoadType() << 3), CMD_REMOVE_LONG_ROAD);
}
/* static */ bool AIRoad::RemoveRoadDepot(TileIndex tile)

View File

@ -50,7 +50,7 @@ static void IConsoleWriteToLogFile(const char *string)
if (_iconsole_output_file != NULL) {
/* if there is an console output file ... also print it there */
const char *header = GetLogPrefix();
if (fwrite(header, strlen(header), 1, _iconsole_output_file) != 1 ||
if ((strlen(header) != 0 && fwrite(header, strlen(header), 1, _iconsole_output_file) != 1) ||
fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 ||
fwrite("\n", 1, 1, _iconsole_output_file) != 1) {
fclose(_iconsole_output_file);

View File

@ -22,7 +22,7 @@
#include <Path.h>
#include <storage/FindDirectory.h>
#else
#ifdef OPENBSD
#if defined(OPENBSD) || defined(DOS)
#include <unistd.h>
#endif
#include <pwd.h>

View File

@ -2668,8 +2668,8 @@ static bool HandleChangeInfoResult(const char *caller, ChangeInfoResult cir, uin
/* No debug message for an invalid ID, as it has already been output */
_skip_sprites = -1;
_cur_grfconfig->status = GCS_DISABLED;
_cur_grfconfig->error = CallocT<GRFError>(1);
_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
delete _cur_grfconfig->error;
_cur_grfconfig->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL);
_cur_grfconfig->error->message = (cir == CIR_INVALID_ID) ? STR_NEWGRF_ERROR_INVALID_ID : STR_NEWGRF_ERROR_UNKNOWN_PROPERTY;
return true;
}
@ -4198,16 +4198,10 @@ static void CfgApply(ByteReader *buf)
*/
static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
{
if (c->error != NULL) {
free(c->error->custom_message);
free(c->error->data);
free(c->error);
}
delete c->error;
c->status = GCS_DISABLED;
c->error = CallocT<GRFError>(1);
c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC);
c->error->data = strdup(_cur_grfconfig->name);
c->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
c->error->message = STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC;
ClearTemporaryNewGRFData(GetFileByGRFID(c->grfid));
}
@ -4416,9 +4410,8 @@ static void GRFInfo(ByteReader *buf)
if (_cur_stage < GLS_RESERVE && _cur_grfconfig->status != GCS_UNKNOWN) {
_cur_grfconfig->status = GCS_DISABLED;
_cur_grfconfig->error = CallocT<GRFError>(1);
_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
_cur_grfconfig->error->message = STR_NEWGRF_ERROR_MULTIPLE_ACTION_8;
delete _cur_grfconfig->error;
_cur_grfconfig->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_MULTIPLE_ACTION_8);
_skip_sprites = -1;
return;
@ -4556,9 +4549,7 @@ static void GRFLoadError(ByteReader *buf)
return;
}
GRFError *error = CallocT<GRFError>(1);
error->severity = sevstr[severity];
GRFError *error = new GRFError(sevstr[severity]);
if (message_id == 0xFF) {
/* This is a custom error message. */
@ -5426,17 +5417,12 @@ static void TranslateGRFStrings(ByteReader *buf)
if (c->status == GCS_INITIALISED) {
/* If the file is not active but will be activated later, give an error
* and disable this file. */
GRFError *error = CallocT<GRFError>(1);
delete _cur_grfconfig->error;
_cur_grfconfig->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_LOAD_AFTER);
char tmp[256];
GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp));
error->data = strdup(tmp);
error->message = STR_NEWGRF_ERROR_LOAD_AFTER;
error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error);
_cur_grfconfig->error = error;
_cur_grfconfig->error->data = strdup(tmp);
_cur_grfconfig->status = GCS_DISABLED;
ClearTemporaryNewGRFData(_cur_grffile);
@ -5714,9 +5700,7 @@ static void ResetNewGRFErrors()
{
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
if (!HasBit(c->flags, GCF_COPY) && c->error != NULL) {
free(c->error->custom_message);
free(c->error->data);
free(c->error);
delete c->error;
c->error = NULL;
}
}
@ -6189,9 +6173,8 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
_skip_sprites = -1;
_cur_grfconfig->status = GCS_DISABLED;
_cur_grfconfig->error = CallocT<GRFError>(1);
_cur_grfconfig->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
_cur_grfconfig->error->message = STR_NEWGRF_ERROR_READ_BOUNDS;
delete _cur_grfconfig->error;
_cur_grfconfig->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_READ_BOUNDS);
}
}
@ -6221,9 +6204,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
if (file_index > LAST_GRF_SLOT) {
DEBUG(grf, 0, "'%s' is not loaded as the maximum number of GRFs has been reached", filename);
config->status = GCS_DISABLED;
config->error = CallocT<GRFError>(1);
config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
config->error->message = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
config->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED);
return;
}
@ -6269,9 +6250,8 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
if (_skip_sprites == 0) {
grfmsg(0, "LoadNewGRFFile: Unexpected sprite, disabling");
config->status = GCS_DISABLED;
config->error = CallocT<GRFError>(1);
config->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
config->error->message = STR_NEWGRF_ERROR_UNEXPECTED_SPRITE;
delete config->error;
config->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_UNEXPECTED_SPRITE);
break;
}

View File

@ -26,6 +26,17 @@ GRFConfig *_grfconfig;
GRFConfig *_grfconfig_newgame;
GRFConfig *_grfconfig_static;
GRFError::GRFError(StringID severity, StringID message) :
message(message),
severity(severity)
{
}
GRFError::~GRFError()
{
free(this->custom_message);
free(this->data);
}
/**
* Update the palettes of the graphics from the config file.
@ -101,12 +112,7 @@ void ClearGRFConfig(GRFConfig **config)
free((*config)->filename);
free((*config)->name);
free((*config)->info);
if ((*config)->error != NULL) {
free((*config)->error->custom_message);
free((*config)->error->data);
free((*config)->error);
}
delete (*config)->error;
}
free(*config);
*config = NULL;
@ -139,8 +145,9 @@ GRFConfig *DuplicateGRFConfig(const GRFConfig *c)
if (c->name != NULL) config->name = strdup(c->name);
if (c->info != NULL) config->info = strdup(c->info);
if (c->error != NULL) {
config->error = MallocT<GRFError>(1);
memcpy(config->error, c->error, sizeof(GRFError));
config->error = new GRFError(c->error->severity, c->error->message);
config->error->num_params = c->error->num_params;
memcpy(config->error->param_value, c->error->param_value, sizeof(config->error->param_value));
if (c->error->data != NULL) config->error->data = strdup(c->error->data);
if (c->error->custom_message != NULL) config->error->custom_message = strdup(c->error->custom_message);
}

View File

@ -13,6 +13,7 @@
#define NEWGRF_CONFIG_H
#include "strings_type.h"
#include "core/alloc_type.hpp"
/** GRF config bit flags */
enum GCF_Flags {
@ -55,7 +56,10 @@ struct GRFIdentifier {
};
/** Information about why GRF had problems during initialisation */
struct GRFError {
struct GRFError : ZeroedMemoryAllocator {
GRFError(StringID severity, StringID message = 0);
~GRFError();
char *custom_message; ///< Custom message (if present)
char *data; ///< Additional data for message and custom_message
StringID message; ///< Default message

View File

@ -14,10 +14,13 @@
#include "newgrf_commons.h"
#include "newgrf_railtype.h"
#include "newgrf_spritegroup.h"
#include "core/bitmath_func.hpp"
static uint32 RailTypeGetRandomBits(const ResolverObject *object)
{
return 0;
TileIndex tile = object->u.routes.tile;
uint tmp = CountBits(tile + (TileX(tile) + TileY(tile)) * TILE_SIZE);
return GB(tmp, 0, 2);
}
static uint32 RailTypeGetTriggers(const ResolverObject *object)

View File

@ -446,7 +446,7 @@ int ttd_main(int argc, char *argv[])
* a letter means: it accepts that param (e.g.: -h)
* a ':' behind it means: it need a param (e.g.: -m<driver>)
* a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */
optformat = "m:s:v:b:hD::n::ei::I:S:t:d::r:g::G:c:xl:p:P:"
optformat = "m:s:v:b:hD::n::ei::I:S:M:t:d::r:g::G:c:xl:p:P:"
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
"f"
#endif

View File

@ -779,9 +779,9 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
}
/** Remove a long piece of road.
* @param end_tile end tile of drag
* @param start_tile start tile of drag
* @param flags operation to perform
* @param p1 start tile of drag
* @param p1 end tile of drag
* @param p2 various bitstuffed elements
* - p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
* - p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
@ -790,13 +790,13 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRemoveLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
CommandCost cost(EXPENSES_CONSTRUCTION);
if (p1 >= MapSize()) return CMD_ERROR;
TileIndex start_tile = p1;
TileIndex end_tile = p1;
RoadType rt = (RoadType)GB(p2, 3, 2);
if (!IsValidRoadType(rt)) return CMD_ERROR;
@ -829,7 +829,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1
if (flags & DC_EXEC) {
money -= ret.GetCost();
if (money < 0) {
_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
_additional_cash_required = DoCommand(start_tile, end_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
return cost;
}
RemoveRoad(tile, flags, bits, rt, true, false);

View File

@ -225,6 +225,15 @@
#endif /* defined(_MSC_VER) */
#if defined(DOS)
/* The DOS port does not have all signals/signal functions. */
#define strsignal(sig) ""
/* Use 'no floating point' for bus errors; SIGBUS does not
* exist for does, SIGNOFP not for other platforms. So it's
* fairly safe the interchange those. */
#define SIGBUS SIGNOFP
#endif
#if defined(WINCE)
#define strdup _strdup
#endif /* WINCE */

View File

@ -1757,7 +1757,7 @@ static bool HandleScrollbarScrolling()
/* Find the item we want to move to and make sure it's inside bounds. */
int pos = min(max(0, i + _scrollbar_start_pos) * sb->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos;
if (rtl) pos = max(0, sb->GetCount() - sb->GetCapacity() - pos);
if (pos != sb->GetPosition()) {
sb->SetPosition(pos);
w->SetDirty();