From 8ee1faca6c8b4dbb13962c132fd9544dfee42ffa Mon Sep 17 00:00:00 2001 From: belugas Date: Mon, 31 Dec 2007 04:38:11 +0000 Subject: (svn r11726) -Feature[newGRF]: Extend the Action 5, feature 0D usage. Patch by BigBB --- src/newgrf.cpp | 53 +++++++++++++++++++++++++++++++++++++++--------- src/newgrf.h | 6 ++---- src/table/files.h | 4 ++-- src/table/sprites.h | 17 +++++----------- src/table/station_land.h | 8 ++++---- src/water_cmd.cpp | 36 +++++++++----------------------- 6 files changed, 66 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 431f7464a..cacc67596 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -59,7 +59,6 @@ static int _skip_sprites; // XXX static uint _file_index; // XXX -SpriteID _coast_base; static GRFFile *_cur_grffile; GRFFile *_first_grffile; @@ -3355,12 +3354,47 @@ static void GraphicsNew(byte *buf, int len) /* case 0x0C: // Snowy temperate trees. Not yet used by OTTD. */ case 0x0D: // Coast graphics - if (num != 16) { - grfmsg(1, "GraphicsNew: Coast graphics sprite count must be 16, skipping"); - return; + switch (num) { + case 10: + if (!_cur_grffile->is_ottdfile) { + grfmsg(2, "GraphicsNew: feature is reserved only for OpenTTD, skipping"); + return; + } + + /* openttd(d/w).grf missing shore sprites and initialisation of SPR_SHORE_BASE */ + LoadNextSprite( SPR_SHORE_BASE + 0, _file_index, _nfo_line++); // SLOPE_STEEP_S + DupSprite( 4063, SPR_SHORE_BASE + 1 ); // SLOPE_W + DupSprite( 4064, SPR_SHORE_BASE + 2 ); // SLOPE_S + DupSprite( 4068, SPR_SHORE_BASE + 3 ); // SLOPE_SW + DupSprite( 4062, SPR_SHORE_BASE + 4 ); // SLOPE_E + LoadNextSprite( SPR_SHORE_BASE + 5, _file_index, _nfo_line++); // SLOPE_STEEP_W + DupSprite( 4066, SPR_SHORE_BASE + 6 ); // SLOPE_SE + LoadNextSprite( SPR_SHORE_BASE + 7, _file_index, _nfo_line++); // SLOPE_WSE + DupSprite( 4065, SPR_SHORE_BASE + 8 ); // SLOPE_N + DupSprite( 4069, SPR_SHORE_BASE + 9 ); // SLOPE_NW + LoadNextSprite( SPR_SHORE_BASE + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N + LoadNextSprite( SPR_SHORE_BASE + 11, _file_index, _nfo_line++); // SLOPE_NWS + DupSprite( 4067, SPR_SHORE_BASE + 12 ); // SLOPE_NE + LoadNextSprite( SPR_SHORE_BASE + 13, _file_index, _nfo_line++); // SLOPE_ENW + LoadNextSprite( SPR_SHORE_BASE + 14, _file_index, _nfo_line++); // SLOPE_SEN + LoadNextSprite( SPR_SHORE_BASE + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E + LoadNextSprite( SPR_SHORE_BASE + 16, _file_index, _nfo_line++); // SLOPE_EW + LoadNextSprite( SPR_SHORE_BASE + 17, _file_index, _nfo_line++); // SLOPE_NS + + grfmsg(2, "GraphicsNew: Loading all standard shore sprites"); + break; + + case 16: + case 18: + /* 'normal' newWater newGRF */ + replace = SPR_SHORE_BASE; + break; + + default: + /* no valid shore sprite count */ + grfmsg(1, "GraphicsNew: Shore graphics sprite count must be 10, 16 or 18, skipping"); + return; } - _coast_base = _cur_spriteid; - _loaded_newgrf_features.has_newwater = true; break; /* case 0x0E: // New Signals. Not yet used by OTTD. */ @@ -5083,8 +5117,6 @@ static void ResetNewGRFData() _loaded_newgrf_features.has_2CC = false; _loaded_newgrf_features.has_newhouses = false; _loaded_newgrf_features.has_newindustries = false; - _loaded_newgrf_features.has_newwater = false; - _coast_base = 0; InitializeSoundPool(); InitializeSpriteGroupPool(); @@ -5473,7 +5505,7 @@ static void DecodeSpecialSprite(uint num, GrfLoadingStage stage) } -void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage) +void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, bool ottd_grf) { const char *filename = config->filename; uint16 num; @@ -5492,6 +5524,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage) if (_cur_grffile == NULL) error("File '%s' lost in cache.\n", filename); if (stage == GLS_RESERVE && config->status != GCS_INITIALISED) return; if (stage == GLS_ACTIVATION && !HasBit(config->flags, GCF_RESERVED)) return; + _cur_grffile->is_ottdfile = ottd_grf; } if (file_index > LAST_GRF_SLOT) { @@ -5634,7 +5667,7 @@ void LoadNewGRF(uint load_index, uint file_index) if (!FioCheckFileExists(c->filename)) error("NewGRF file is missing '%s'", c->filename); if (stage == GLS_LABELSCAN) InitNewGRFFile(c, _cur_spriteid); - LoadNewGRFFile(c, slot++, stage); + LoadNewGRFFile(c, slot++, stage, true); if (stage == GLS_RESERVE) { SetBit(c->flags, GCF_RESERVED); } else if (stage == GLS_ACTIVATION) { diff --git a/src/newgrf.h b/src/newgrf.h index 283b35ec8..54b5c99c9 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -41,6 +41,7 @@ struct GRFLabel { struct GRFFile { char *filename; + bool is_ottdfile; uint32 grfid; uint16 sprite_offset; byte grf_version; @@ -84,19 +85,16 @@ struct GRFFile { extern GRFFile *_first_grffile; -extern SpriteID _coast_base; - struct GRFLoadedFeatures { bool has_2CC; ///< Set if any vehicle is loaded which uses 2cc (two company colours). bool has_newhouses; ///< Set if there are any newhouses loaded. bool has_newindustries; ///< Set if there are any newindustries loaded. - bool has_newwater; ///< Set it there are any newwater grf loaded }; /* Indicates which are the newgrf features currently loaded ingame */ extern GRFLoadedFeatures _loaded_newgrf_features; -void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage); +void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, bool ottd_grf = false); void LoadNewGRF(uint load_index, uint file_index); void ReloadNewGRFData(); // in openttd.cpp diff --git a/src/table/files.h b/src/table/files.h index 79ee01b0b..615029b6e 100644 --- a/src/table/files.h +++ b/src/table/files.h @@ -34,7 +34,7 @@ static FileList files_dos = { }, { "SAMPLE.CAT", {0x42, 0x2e, 0xa3, 0xdd, 0x07, 0x4d, 0x28, 0x59, 0xbb, 0x51, 0x63, 0x9a, 0x6e, 0x0e, 0x85, 0xda} }, { "CHARS.GRF", {0x5f, 0x2e, 0xbf, 0x05, 0xb6, 0x12, 0x65, 0x81, 0xd2, 0x10, 0xa9, 0x19, 0x62, 0x41, 0x70, 0x64} }, - { "OPENTTDD.GRF", {0x60, 0xfe, 0xc1, 0xc7, 0x66, 0xe7, 0x59, 0xff, 0x1b, 0x6c, 0xc4, 0x5f, 0xe6, 0x6b, 0x8c, 0x91} } + { "OPENTTDD.GRF", {0x9a, 0x26, 0xc9, 0xd1, 0xa2, 0x39, 0xb8, 0xaa, 0x57, 0xac, 0x0f, 0xf0, 0xe4, 0x4b, 0x37, 0xb2} } }; static FileList files_win = { @@ -48,5 +48,5 @@ static FileList files_win = { }, { "SAMPLE.CAT", {0x92, 0x12, 0xe8, 0x1e, 0x72, 0xba, 0xdd, 0x4b, 0xbe, 0x1e, 0xae, 0xae, 0x66, 0x45, 0x8e, 0x10} }, { "CHARS.GRF", {0x5f, 0x2e, 0xbf, 0x05, 0xb6, 0x12, 0x65, 0x81, 0xd2, 0x10, 0xa9, 0x19, 0x62, 0x41, 0x70, 0x64} }, - { "OPENTTDW.GRF", {0x85, 0xb7, 0xd0, 0xa6, 0xc3, 0x86, 0x44, 0x03, 0xa1, 0x25, 0xa5, 0xbb, 0x50, 0x75, 0xa0, 0xa1} } + { "OPENTTDW.GRF", {0xa1, 0x9c, 0xaa, 0xfc, 0x6b, 0xd2, 0x09, 0xc3, 0xd4, 0x84, 0x33, 0x43, 0x3f, 0xd1, 0xbd, 0xd5} } }; diff --git a/src/table/sprites.h b/src/table/sprites.h index 16fc900d7..e906383a8 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -141,7 +141,11 @@ enum Sprites { SPR_2CCMAP_BASE = SPR_ELRAIL_BASE + ELRAIL_SPRITE_COUNT, TWOCCMAP_SPRITE_COUNT = 256, - SPR_AIRPORTX_BASE = SPR_2CCMAP_BASE + TWOCCMAP_SPRITE_COUNT, // The sprites used for other airport angles + /* shore tiles - action 05-0D */ + SPR_SHORE_BASE = SPR_2CCMAP_BASE + TWOCCMAP_SPRITE_COUNT, + SPR_SHORE_SPRITE_COUNT = 18, + + SPR_AIRPORTX_BASE = SPR_SHORE_BASE + SPR_SHORE_SPRITE_COUNT, // The sprites used for other airport angles SPR_NEWAIRPORT_TARMAC = SPR_AIRPORTX_BASE, SPR_NSRUNWAY1 = SPR_AIRPORTX_BASE + 1, SPR_NSRUNWAY2 = SPR_AIRPORTX_BASE + 2, @@ -553,17 +557,6 @@ enum Sprites { SPR_FARMLAND_STATE_7 = 4259, SPR_FARMLAND_HAYPACKS = 4278, - /* Shores */ - SPR_NO_SHORE = 0, //used for tileh which have no shore - SPR_SHORE_TILEH_4 = 4062, // SLOPE_E - SPR_SHORE_TILEH_1 = 4063, // SLOPE_W - SPR_SHORE_TILEH_2 = 4064, // SLOPE_S - SPR_SHORE_TILEH_8 = 4065, // SLOPE_N - SPR_SHORE_TILEH_6 = 4066, // SLOPE_SE - SPR_SHORE_TILEH_12 = 4067, // SLOPE_NE - SPR_SHORE_TILEH_3 = 4068, // SLOPE_SW - SPR_SHORE_TILEH_9 = 4069, // SLOPE_NW - /* Water-related sprites */ SPR_SHIP_DEPOT_SE_FRONT = 4070, SPR_SHIP_DEPOT_SW_FRONT = 4071, diff --git a/src/table/station_land.h b/src/table/station_land.h index 6f955daf3..61700bf28 100644 --- a/src/table/station_land.h +++ b/src/table/station_land.h @@ -1168,10 +1168,10 @@ static const DrawTileSprites _station_display_datas_oilrig[] = { }; static const DrawTileSprites _station_display_datas_dock[] = { - { SPR_SHORE_TILEH_3, PAL_NONE, _station_display_datas_76 }, - { SPR_SHORE_TILEH_9, PAL_NONE, _station_display_datas_77 }, - { SPR_SHORE_TILEH_12, PAL_NONE, _station_display_datas_78 }, - { SPR_SHORE_TILEH_6, PAL_NONE, _station_display_datas_79 }, + { SPR_SHORE_BASE + SLOPE_SW, PAL_NONE, _station_display_datas_76 }, + { SPR_SHORE_BASE + SLOPE_NW, PAL_NONE, _station_display_datas_77 }, + { SPR_SHORE_BASE + SLOPE_NE, PAL_NONE, _station_display_datas_78 }, + { SPR_SHORE_BASE + SLOPE_SE, PAL_NONE, _station_display_datas_79 }, { SPR_FLAT_WATER_TILE, PAL_NONE, _station_display_datas_80 }, { SPR_FLAT_WATER_TILE, PAL_NONE, _station_display_datas_81 }, }; diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 78aa37cc4..86cd583ec 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -33,25 +33,6 @@ #include "vehicle_func.h" #include "sound_func.h" -/** Array for the shore sprites */ -static const SpriteID _water_shore_sprites[] = { - 0, - SPR_SHORE_TILEH_1, // SLOPE_W - SPR_SHORE_TILEH_2, // SLOPE_S - SPR_SHORE_TILEH_3, // SLOPE_SW - SPR_SHORE_TILEH_4, // SLOPE_E - 0, - SPR_SHORE_TILEH_6, // SLOPE_SE - 0, - SPR_SHORE_TILEH_8, // SLOPE_N - SPR_SHORE_TILEH_9, // SLOPE_NW - 0, - 0, - SPR_SHORE_TILEH_12, // SLOPE_NE - 0, - 0 -}; - static Vehicle *FindFloodableVehicleOnTile(TileIndex tile); static void FloodVehicle(Vehicle *v); @@ -513,15 +494,18 @@ static void DrawTile_Water(TileInfo *ti) DrawBridgeMiddle(ti); break; - case WATER_TILE_COAST: + case WATER_TILE_COAST: { + /* Converts the enum Slope into an offset based on SPR_SHORE_BASE. + * This allows to calculate the proper sprite to display for this Slope */ + static const byte tileh_to_shoresprite[32] = { + 0, 1, 2, 3, 4, 16, 6, 7, 8, 9, 17, 11, 12, 13, 14, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 10, 15, 0, + }; + assert(!IsSteepSlope(ti->tileh)); - if (_loaded_newgrf_features.has_newwater) { - DrawGroundSprite(_coast_base + ti->tileh, PAL_NONE); - } else { - DrawGroundSprite(_water_shore_sprites[ti->tileh], PAL_NONE); - } + DrawGroundSprite(SPR_SHORE_BASE + tileh_to_shoresprite[ti->tileh], PAL_NONE); DrawBridgeMiddle(ti); - break; + } break; case WATER_TILE_LOCK: { const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)]; -- cgit v1.2.3-54-g00ecf