Mercurial > hg > openttd
changeset 8489:bcc7ea0c669d draft
(svn r12064) -Codechange : Give grf bridges their own ResetBridges function, and put bridge spec in table/bridge_land.h, where it should be.
author | belugas <belugas@openttd.org> |
---|---|
date | Tue, 05 Feb 2008 04:48:56 +0000 |
parents | 0b3e6ee2c852 |
children | 89b8bec56ac1 |
files | src/bridge.h src/newgrf.cpp src/table/bridge_land.h src/tunnelbridge_cmd.cpp |
diffstat | 4 files changed, 89 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bridge.h +++ b/src/bridge.h @@ -47,4 +47,6 @@ bool CheckBridge_Stuff(byte bridge_type, uint bridge_len); int CalcBridgeLenCostFactor(int x); +void ResetBridges(); + #endif /* BRIDGE_H */
--- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5091,15 +5091,8 @@ /* Copy/reset original engine info data */ SetupEngines(); - /* Copy/reset original bridge info data - * First, free sprite table data */ - for (uint i = 0; i < MAX_BRIDGES; i++) { - if (_bridge[i].sprite_table != NULL) { - for (uint j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]); - free(_bridge[i].sprite_table); - } - } - memcpy(&_bridge, &orig_bridge, sizeof(_bridge)); + /* Copy/reset original bridge info data */ + ResetBridges(); /* Reset refit/cargo class data */ memset(&cargo_allowed, 0, sizeof(cargo_allowed));
--- a/src/table/bridge_land.h +++ b/src/table/bridge_land.h @@ -707,3 +707,72 @@ _bridge_sprite_table_11, _bridge_sprite_table_12 }; + +/** Describes the data that defines each bridge in the game + * @param y year of availablity + * @param mnl minimum length + * @param mxl maximum length + * @param p price + * @param mxs maximum speed allowed + * @param spr sprite to use in purchase GUI + * @param plt palette for the sprite in purchase GUI + * @param dsc description of the bridge in purchase GUI + * @param nrl description of the rail bridge in query tool + * @param nrd description of the road bridge in query tool + */ +#define MB(y, mnl, mxl, p, mxs, spr, plt, dsc, nrl, nrd) \ + {y, mnl, mxl, p, mxs, spr, plt, dsc, nrl, nrd, NULL, 0} + +const Bridge _orig_bridge[] = { +/* + year of availablity + | minimum length + | | maximum length + | | | price + | | | | maximum speed + | | | | | sprite to use in GUI + | | | | | | palette in GUI + string with description name on rail name on road + | | | */ + MB( 0, 0, 16, 80, 32, 0xA24, PAL_NONE, + STR_5012_WOODEN, STR_501F_WOODEN_RAIL_BRIDGE, STR_5025_WOODEN_ROAD_BRIDGE), + + MB( 0, 0, 2, 112, 48, 0xA26, PALETTE_TO_STRUCT_RED, + STR_5013_CONCRETE, STR_5020_CONCRETE_RAIL_BRIDGE, STR_5026_CONCRETE_ROAD_BRIDGE), + + MB( 1930, 0, 5, 144, 64, 0xA25, PAL_NONE, + STR_500F_GIRDER_STEEL, STR_501C_STEEL_GIRDER_RAIL_BRIDGE, STR_5022_STEEL_GIRDER_ROAD_BRIDGE), + + MB( 0, 2, 10, 168, 80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, + STR_5011_SUSPENSION_CONCRETE, STR_501E_REINFORCED_CONCRETE_SUSPENSION, STR_5024_REINFORCED_CONCRETE_SUSPENSION), + + MB( 1930, 3, 16, 185, 96, 0xA22, PAL_NONE, + STR_500E_SUSPENSION_STEEL, STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE), + + MB( 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW, + STR_500E_SUSPENSION_STEEL, STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE), + + MB( 1930, 3, 7, 224, 160, 0xA23, PAL_NONE, + STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), + + MB( 1930, 3, 8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN, + STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), + + MB( 1930, 3, 9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED, + STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), + + MB( 1930, 0, 2, 240, 256, 0xA27, PAL_NONE, + STR_500F_GIRDER_STEEL, STR_501C_STEEL_GIRDER_RAIL_BRIDGE, STR_5022_STEEL_GIRDER_ROAD_BRIDGE), + + MB( 1995, 2, 16, 255, 320, 0xA28, PAL_NONE, + STR_5014_TUBULAR_STEEL, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE), + + MB( 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW, + STR_5014_TUBULAR_STEEL, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE), + + MB( 2010, 2, 32, 510, 608, 0xA28, PALETTE_TO_STRUCT_GREY, + STR_BRIDGE_TUBULAR_SILICON, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE) +}; + +#undef MB +
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -38,77 +38,24 @@ #include "table/strings.h" #include "table/bridge_land.h" - -/** Describes the data that defines each bridge in the game - * @param y year of availablity - * @param mnl minimum length - * @param mxl maximum length - * @param p price - * @param mxs maximum speed allowed - * @param spr sprite to use in purchase GUI - * @param plt palette for the sprite in purchase GUI - * @param dsc description of the bridge in purchase GUI - * @param nrl description of the rail bridge in query tool - * @param nrd description of the road bridge in query tool - */ -#define MB(y, mnl, mxl, p, mxs, spr, plt, dsc, nrl, nrd) \ - {y, mnl, mxl, p, mxs, spr, plt, dsc, nrl, nrd, NULL, 0} - -const Bridge orig_bridge[] = { -/* - year of availablity - | minimum length - | | maximum length - | | | price - | | | | maximum speed - | | | | | sprite to use in GUI - | | | | | | palette in GUI - string with description name on rail name on road - | | | */ - MB( 0, 0, 16, 80, 32, 0xA24, PAL_NONE, - STR_5012_WOODEN, STR_501F_WOODEN_RAIL_BRIDGE, STR_5025_WOODEN_ROAD_BRIDGE), - - MB( 0, 0, 2, 112, 48, 0xA26, PALETTE_TO_STRUCT_RED, - STR_5013_CONCRETE, STR_5020_CONCRETE_RAIL_BRIDGE, STR_5026_CONCRETE_ROAD_BRIDGE), - - MB( 1930, 0, 5, 144, 64, 0xA25, PAL_NONE, - STR_500F_GIRDER_STEEL, STR_501C_STEEL_GIRDER_RAIL_BRIDGE, STR_5022_STEEL_GIRDER_ROAD_BRIDGE), - - MB( 0, 2, 10, 168, 80, 0xA22, PALETTE_TO_STRUCT_CONCRETE, - STR_5011_SUSPENSION_CONCRETE, STR_501E_REINFORCED_CONCRETE_SUSPENSION, STR_5024_REINFORCED_CONCRETE_SUSPENSION), - - MB( 1930, 3, 16, 185, 96, 0xA22, PAL_NONE, - STR_500E_SUSPENSION_STEEL, STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE), - - MB( 1930, 3, 16, 192, 112, 0xA22, PALETTE_TO_STRUCT_YELLOW, - STR_500E_SUSPENSION_STEEL, STR_501B_STEEL_SUSPENSION_RAIL_BRIDGE, STR_5021_STEEL_SUSPENSION_ROAD_BRIDGE), - - MB( 1930, 3, 7, 224, 160, 0xA23, PAL_NONE, - STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), - - MB( 1930, 3, 8, 232, 208, 0xA23, PALETTE_TO_STRUCT_BROWN, - STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), - - MB( 1930, 3, 9, 248, 240, 0xA23, PALETTE_TO_STRUCT_RED, - STR_5010_CANTILEVER_STEEL, STR_501D_STEEL_CANTILEVER_RAIL_BRIDGE, STR_5023_STEEL_CANTILEVER_ROAD_BRIDGE), - - MB( 1930, 0, 2, 240, 256, 0xA27, PAL_NONE, - STR_500F_GIRDER_STEEL, STR_501C_STEEL_GIRDER_RAIL_BRIDGE, STR_5022_STEEL_GIRDER_ROAD_BRIDGE), - - MB( 1995, 2, 16, 255, 320, 0xA28, PAL_NONE, - STR_5014_TUBULAR_STEEL, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE), - - MB( 2005, 2, 32, 380, 512, 0xA28, PALETTE_TO_STRUCT_YELLOW, - STR_5014_TUBULAR_STEEL, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE), - - MB( 2010, 2, 32, 510, 608, 0xA28, PALETTE_TO_STRUCT_GREY, - STR_BRIDGE_TUBULAR_SILICON, STR_5027_TUBULAR_RAIL_BRIDGE, STR_5028_TUBULAR_ROAD_BRIDGE) -}; - -#undef MB - Bridge _bridge[MAX_BRIDGES]; +/** Reset the data been eventually changed by the grf loaded. */ +void ResetBridges() +{ + /* First, free sprite table data */ + for (uint i = 0; i < MAX_BRIDGES; i++) { + if (_bridge[i].sprite_table != NULL) { + for (uint j = 0; j < 7; j++) free(_bridge[i].sprite_table[j]); + free(_bridge[i].sprite_table); + } + } + + /* Then, wipe out current bidges */ + memset(&_bridge, 0, sizeof(_bridge)); + /* And finally, reinstall default data */ + memcpy(&_bridge, &_orig_bridge, sizeof(_orig_bridge)); +} /** calculate the price factor for building a long bridge. * basically the cost delta is 1,1, 1, 2,2, 3,3,3, 4,4,4,4, 5,5,5,5,5, 6,6,6,6,6,6, 7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8,