diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 1b18f27e48..93f1309dc5 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -4,7 +4,7 @@ #include "../../openttd.h" #include "../../aircraft.h" #include "../../bridge_map.h" -#include "../../functions.h" +#include "../../tile_cmd.h" #include "../../landscape.h" #include "../../map.h" #include "../../rail_map.h" diff --git a/src/bridge.h b/src/bridge.h index 6565f983f3..bd85356d68 100644 --- a/src/bridge.h +++ b/src/bridge.h @@ -37,4 +37,8 @@ static inline const Bridge *GetBridge(uint i) void DrawBridgeMiddle(const TileInfo *ti); +bool CheckBridge_Stuff(byte bridge_type, uint bridge_len); +uint32 GetBridgeLength(TileIndex begin, TileIndex end); +int CalcBridgeLenCostFactor(int x); + #endif /* BRIDGE_H */ diff --git a/src/cargo_type.h b/src/cargo_type.h new file mode 100644 index 0000000000..ca2f4a239f --- /dev/null +++ b/src/cargo_type.h @@ -0,0 +1,58 @@ +/* $Id$ */ +/** @file openttd.h */ + +#ifndef CARGO_TYPE_H +#define CARGO_TYPE_H + +typedef byte CargoID; + +enum { + // Temperate + CT_PASSENGERS = 0, + CT_COAL = 1, + CT_MAIL = 2, + CT_OIL = 3, + CT_LIVESTOCK = 4, + CT_GOODS = 5, + CT_GRAIN = 6, + CT_WOOD = 7, + CT_IRON_ORE = 8, + CT_STEEL = 9, + CT_VALUABLES = 10, + + // Arctic + CT_WHEAT = 6, + CT_HILLY_UNUSED = 8, + CT_PAPER = 9, + CT_GOLD = 10, + CT_FOOD = 11, + + // Tropic + CT_RUBBER = 1, + CT_FRUIT = 4, + CT_MAIZE = 6, + CT_COPPER_ORE = 8, + CT_WATER = 9, + CT_DIAMONDS = 10, + + // Toyland + CT_SUGAR = 1, + CT_TOYS = 3, + CT_BATTERIES = 4, + CT_CANDY = 5, + CT_TOFFEE = 6, + CT_COLA = 7, + CT_COTTON_CANDY = 8, + CT_BUBBLES = 9, + CT_PLASTIC = 10, + CT_FIZZY_DRINKS = 11, + + NUM_CARGO = 32, + + CT_NO_REFIT = 0xFE, + CT_INVALID = 0xFF +}; + +typedef uint AcceptedCargo[NUM_CARGO]; + +#endif /* OPENTTD_H */ diff --git a/src/cargopacket.h b/src/cargopacket.h index 3fde1bacce..fe978667ad 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -5,6 +5,7 @@ #ifndef CARGOPACKET_H #define CARGOPACKET_H +#include "economy_type.h" #include typedef uint32 CargoPacketID; diff --git a/src/cargotype.h b/src/cargotype.h index 4c0702a6f9..56a974addd 100644 --- a/src/cargotype.h +++ b/src/cargotype.h @@ -5,6 +5,7 @@ #ifndef CARGOTYPE_H #define CARGOTYPE_H +#include "cargo_type.h" typedef uint32 CargoLabel; diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index 317b99a214..117cdd3857 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -22,6 +22,7 @@ #include "genworld.h" #include "industry.h" #include "water_map.h" +#include "tile_cmd.h" /* * In one terraforming command all four corners of a initial tile can be raised/lowered (though this is not available to the player). diff --git a/src/command_func.h b/src/command_func.h index 80e0695742..ccb9c2155c 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -76,6 +76,7 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma * used for user input data like names or chat messages. */ extern const char *_cmd_text; +extern Money _additional_cash_required; /** * Checks if a integer value belongs to a command. diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp index d033b702e2..2b14b4b897 100644 --- a/src/disaster_cmd.cpp +++ b/src/disaster_cmd.cpp @@ -18,14 +18,16 @@ #include "stdafx.h" #include "openttd.h" -#include "functions.h" +#include "gfx.h" #include "landscape.h" + #include "industry_map.h" #include "station_map.h" #include "table/strings.h" #include "map.h" #include "vehicle.h" #include "command_func.h" +#include "tile_cmd.h" #include "news.h" #include "station.h" #include "waypoint.h" diff --git a/src/dummy_land.cpp b/src/dummy_land.cpp index fcfd2618dc..fe605b90c9 100644 --- a/src/dummy_land.cpp +++ b/src/dummy_land.cpp @@ -5,10 +5,10 @@ #include "stdafx.h" #include "openttd.h" #include "table/strings.h" -#include "functions.h" -#include "viewport.h" +#include "tile_cmd.h" #include "command_func.h" #include "table/sprites.h" +#include "viewport.h" static void DrawTile_Dummy(TileInfo *ti) { diff --git a/src/economy.cpp b/src/economy.cpp index 7d0684611f..80d56c72eb 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -40,6 +40,7 @@ #include "player_face.h" #include "group.h" #include "strings_func.h" +#include "tile_cmd.h" /** * Multiply two integer values and shift the results to right. @@ -92,6 +93,9 @@ Economy _economy; Subsidy _subsidies[MAX_PLAYERS]; Prices _price; uint16 _price_frac[NUM_PRICES]; +Money _cargo_payment_rates[NUM_CARGO]; +uint16 _cargo_payment_rates_frac[NUM_CARGO]; +Money _additional_cash_required; Money CalculateCompanyValue(const Player* p) { diff --git a/src/economy_func.h b/src/economy_func.h index 4a2520696d..04d79ac8dc 100644 --- a/src/economy_func.h +++ b/src/economy_func.h @@ -6,6 +6,8 @@ #define ECONOMY_FUNC_H #include "economy_type.h" +#include "cargo_type.h" +#include "vehicle_type.h" struct Player; @@ -19,6 +21,8 @@ extern Subsidy _subsidies[MAX_PLAYERS]; /* Prices and also the fractional part. */ extern Prices _price; extern uint16 _price_frac[NUM_PRICES]; +extern Money _cargo_payment_rates[NUM_CARGO]; +extern uint16 _cargo_payment_rates_frac[NUM_CARGO]; int UpdateCompanyRatingAndValue(Player *p, bool update); Pair SetupSubsidyDecodeParam(const Subsidy *s, bool mode); diff --git a/src/economy_type.h b/src/economy_type.h index d93a709a89..197fd7e821 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -7,6 +7,7 @@ #include "core/overflowsafe_type.hpp" #include "core/enum_type.hpp" +#include "cargo_type.h" typedef OverflowSafeInt64 Money; diff --git a/src/engine.h b/src/engine.h index 9ac4cd5b96..6ee3d83767 100644 --- a/src/engine.h +++ b/src/engine.h @@ -7,8 +7,10 @@ #include "oldpool.h" #include "rail_type.h" +#include "cargo_type.h" +#include "vehicle_type.h" +#include "command_type.h" #include "sound.h" -#include "vehicle.h" enum RailVehicleTypes { RAILVEH_SINGLEHEAD, ///< indicates a "standalone" locomotive diff --git a/src/functions.h b/src/functions.h index e7ee6f26ff..c7b758132b 100644 --- a/src/functions.h +++ b/src/functions.h @@ -8,6 +8,7 @@ #include "gfx.h" #include "viewport.h" #include "core/random_func.hpp" +#include "command_type.h" void UpdateTownMaxPass(Town *t); @@ -38,11 +39,6 @@ void DeleteAnimatedTile(TileIndex tile); void AnimateAnimatedTiles(); void InitializeAnimatedTiles(); -/* tunnelbridge_cmd.cpp */ -bool CheckBridge_Stuff(byte bridge_type, uint bridge_len); -uint32 GetBridgeLength(TileIndex begin, TileIndex end); -int CalcBridgeLenCostFactor(int x); - /* misc_cmd.cpp */ void PlaceTreesRandomly(); diff --git a/src/gui.h b/src/gui.h index e492a593f3..db9e339a68 100644 --- a/src/gui.h +++ b/src/gui.h @@ -7,6 +7,7 @@ #include "string.h" #include "window_type.h" +#include "gfx.h" /* main_gui.cpp */ void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2); diff --git a/src/industry.h b/src/industry.h index e633a4c865..46f14defc0 100644 --- a/src/industry.h +++ b/src/industry.h @@ -6,8 +6,10 @@ #define INDUSTRY_H #include "oldpool.h" -#include "helpers.hpp" +#include "core/random_func.hpp" #include "newgrf_storage.h" +#include "cargo_type.h" +#include "economy_type.h" typedef uint16 IndustryGfx; typedef uint8 IndustryType; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 6ad18ad2b1..999537899a 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -39,6 +39,7 @@ #include "transparency.h" #include "water.h" #include "strings_func.h" +#include "tile_cmd.h" void ShowIndustryViewWindow(int industry); void BuildOilRig(TileIndex tile); @@ -1511,7 +1512,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); - MakeIndustry(cur_tile, i->index, it->gfx); + MakeIndustry(cur_tile, i->index, it->gfx, Random()); if (_generating_world) { SetIndustryConstructionCounter(cur_tile, 3); diff --git a/src/industry_map.h b/src/industry_map.h index e7e53e6a58..77cab89209 100644 --- a/src/industry_map.h +++ b/src/industry_map.h @@ -156,11 +156,12 @@ static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx) /** * Make the given tile an industry tile - * @param t the tile to make an industry tile - * @param index the industry this tile belongs to - * @param gfx the graphics to use for the tile + * @param t the tile to make an industry tile + * @param index the industry this tile belongs to + * @param gfx the graphics to use for the tile + * @param random the random value */ -static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx) +static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random) { SetTileType(t, MP_INDUSTRY); _m[t].m1 = 0; @@ -168,7 +169,7 @@ static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx) _m[t].m3 = 0; _m[t].m4 = 0; SetIndustryGfx(t, gfx); - _me[t].m7 = Random(); + _me[t].m7 = random; } /** diff --git a/src/landscape.cpp b/src/landscape.cpp index 1bff020a9e..0abef68eb7 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -21,6 +21,7 @@ #include "water_map.h" #include "tgp.h" #include "genworld.h" +#include "tile_cmd.h" extern const TileTypeProcs _tile_type_clear_procs, diff --git a/src/landscape.h b/src/landscape.h index 81b180d1a2..8324fc1293 100644 --- a/src/landscape.h +++ b/src/landscape.h @@ -5,6 +5,8 @@ #ifndef LANDSCAPE_H #define LANDSCAPE_H +#include "gfx.h" + enum { SNOW_LINE_MONTHS = 12, SNOW_LINE_DAYS = 32, @@ -47,13 +49,6 @@ void DrawFoundation(TileInfo *ti, Foundation f); void DoClearSquare(TileIndex tile); void RunTileLoop(); -uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode); -void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac); -void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player); -void AnimateTile(TileIndex tile); -void ClickTile(TileIndex tile); -void GetTileDesc(TileIndex tile, TileDesc *td); - void InitializeLandscape(); void GenerateLandscape(byte mode); diff --git a/src/misc.cpp b/src/misc.cpp index a74bc13940..3742f971d0 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -24,6 +24,7 @@ #include "cargotype.h" #include "group.h" #include "viewport.h" +#include "economy_func.h" char _name_array[512][32]; diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 8597fe5946..0d045d7529 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -19,6 +19,7 @@ #include "livery.h" #include "player_face.h" #include "strings_func.h" +#include "vehicle.h" /** Change the player's face. * @param tile unused diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index cab869c7c1..b3b9dcbcb3 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -40,6 +40,8 @@ #include "strings_func.h" #include "fileio.h" #include "fios.h" +#include "tile_cmd.h" + /* Variables to display file lists */ FiosItem *_fios_list; int _saveload_mode; diff --git a/src/network/network.cpp b/src/network/network.cpp index 00e5a4163d..d0558c4b79 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -30,6 +30,7 @@ extern const char _openttd_revision[]; #include /* va_list */ #include "../md5.h" #include "../fileio.h" +#include "../texteff.hpp" /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); diff --git a/src/newgrf_cargo.h b/src/newgrf_cargo.h index b28512ed04..2bad1213eb 100644 --- a/src/newgrf_cargo.h +++ b/src/newgrf_cargo.h @@ -6,6 +6,7 @@ #define NEWGRF_CARGO_H #include "newgrf_callbacks.h" +#include "cargo_type.h" enum { CC_NOAVAILABLE = 0, ///< No cargo class has been specified diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 876a28139f..790e5e8dc4 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -5,7 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "variables.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "debug.h" #include "sprite.h" diff --git a/src/news.h b/src/news.h index 1330f9aa17..b84da76007 100644 --- a/src/news.h +++ b/src/news.h @@ -6,6 +6,7 @@ #define NEWS_H #include "window_type.h" +#include "vehicle_type.h" struct NewsItem { StringID string_id; ///< Message text (sometimes also used for storing other info) diff --git a/src/npf.cpp b/src/npf.cpp index 3c7a0da055..76bebf27cf 100644 --- a/src/npf.cpp +++ b/src/npf.cpp @@ -6,6 +6,8 @@ #include "openttd.h" #include "bridge_map.h" #include "debug.h" +#include "tile_cmd.h" +#include "bridge.h" #include "functions.h" #include "landscape.h" #include "npf.h" diff --git a/src/openttd.h b/src/openttd.h index 216d74cf1b..664a0b72ce 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -28,7 +28,6 @@ struct Pair { #include "map.h" #include "slope_type.h" -#include "vehicle_type.h" // Forward declarations of structs. struct Depot; @@ -41,7 +40,6 @@ struct Industry; struct DrawPixelInfo; struct Group; typedef byte VehicleOrderID; ///< The index of an order within its current vehicle (not pool related) -typedef byte CargoID; typedef byte LandscapeID; typedef uint32 SpriteID; ///< The number of a sprite, without mapping bits and colortables struct PalSpriteID { @@ -233,55 +231,6 @@ struct GameDifficulty { GDType town_council_tolerance; // minimum required town ratings to be allowed to demolish stuff }; -enum { - // Temperate - CT_PASSENGERS = 0, - CT_COAL = 1, - CT_MAIL = 2, - CT_OIL = 3, - CT_LIVESTOCK = 4, - CT_GOODS = 5, - CT_GRAIN = 6, - CT_WOOD = 7, - CT_IRON_ORE = 8, - CT_STEEL = 9, - CT_VALUABLES = 10, - - // Arctic - CT_WHEAT = 6, - CT_HILLY_UNUSED = 8, - CT_PAPER = 9, - CT_GOLD = 10, - CT_FOOD = 11, - - // Tropic - CT_RUBBER = 1, - CT_FRUIT = 4, - CT_MAIZE = 6, - CT_COPPER_ORE = 8, - CT_WATER = 9, - CT_DIAMONDS = 10, - - // Toyland - CT_SUGAR = 1, - CT_TOYS = 3, - CT_BATTERIES = 4, - CT_CANDY = 5, - CT_TOFFEE = 6, - CT_COLA = 7, - CT_COTTON_CANDY = 8, - CT_BUBBLES = 9, - CT_PLASTIC = 10, - CT_FIZZY_DRINKS = 11, - - NUM_CARGO = 32, - - CT_NO_REFIT = 0xFE, - CT_INVALID = 0xFF -}; - -typedef uint AcceptedCargo[NUM_CARGO]; - struct TileDesc { StringID str; Owner owner; @@ -295,78 +244,6 @@ struct ViewportSign { byte width_1, width_2; }; - -#include "command_type.h" -typedef void DrawTileProc(TileInfo *ti); -typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y); -typedef CommandCost ClearTileProc(TileIndex tile, byte flags); -typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res); -typedef void GetTileDescProc(TileIndex tile, TileDesc *td); -/** - * GetTileTrackStatusProcs return a value that contains the possible tracks - * that can be taken on a given tile by a given transport. The return value is - * composed as follows: 0xaabbccdd. ccdd and aabb are bitmasks of trackdirs, - * where bit n corresponds to trackdir n. ccdd are the trackdirs that are - * present in the tile (1==present, 0==not present), aabb is the signal - * status, if applicable (0==green/no signal, 1==red, note that this is - * reversed from map3/2[tile] for railway signals). - * - * The result (let's call it ts) is often used as follows: - * tracks = (byte)(ts | ts >>8) - * This effectively converts the present part of the result (ccdd) to a - * track bitmask, which disregards directions. Normally, this is the same as just - * doing (byte)ts I think, although I am not really sure - * - * A trackdir is combination of a track and a dir, where the lower three bits - * are a track, the fourth bit is the direction. these give 12 (or 14) - * possible options: 0-5 and 8-13, so we need 14 bits for a trackdir bitmask - * above. - * @param tile the tile to get the track status from - * @param mode the mode of transportation - * @param sub_mode used to differentiate between different kinds within the mode - * @return the above mentions track status information - */ -typedef uint32 GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode); -typedef void GetProducedCargoProc(TileIndex tile, CargoID *b); -typedef void ClickTileProc(TileIndex tile); -typedef void AnimateTileProc(TileIndex tile); -typedef void TileLoopProc(TileIndex tile); -typedef void ChangeTileOwnerProc(TileIndex tile, PlayerID old_player, PlayerID new_player); -/** @see VehicleEnterTileStatus to see what the return values mean */ -typedef uint32 VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y); -typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh); -/** - * Called when a tile is affected by a terraforming operation. - * The function has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype. - * With DC_EXEC in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself). - * - * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation. - * - * @param tile The involved tile. - * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.). - * @param z_new TileZ after terraforming. - * @param tileh_new Slope after terraforming. - * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.) - */ -typedef CommandCost TerraformTileProc(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new); - -struct TileTypeProcs { - DrawTileProc *draw_tile_proc; - GetSlopeZProc *get_slope_z_proc; - ClearTileProc *clear_tile_proc; - GetAcceptedCargoProc *get_accepted_cargo_proc; - GetTileDescProc *get_tile_desc_proc; - GetTileTrackStatusProc *get_tile_track_status_proc; - ClickTileProc *click_tile_proc; - AnimateTileProc *animate_tile_proc; - TileLoopProc *tile_loop_proc; - ChangeTileOwnerProc *change_tile_owner_proc; - GetProducedCargoProc *get_produced_cargo_proc; - VehicleEnterTileProc *vehicle_enter_tile_proc; - GetFoundationProc *get_foundation_proc; - TerraformTileProc *terraform_tile_proc; -}; - typedef void PlaceProc(TileIndex tile); enum { diff --git a/src/order.h b/src/order.h index 17370db5eb..a6e091c779 100644 --- a/src/order.h +++ b/src/order.h @@ -7,6 +7,8 @@ #include "oldpool.h" #include "core/bitmath_func.hpp" +#include "cargo_type.h" +#include "vehicle_type.h" enum { INVALID_VEH_ORDER_ID = 0xFF, diff --git a/src/pathfind.cpp b/src/pathfind.cpp index ae7d258fa8..87a66ba504 100644 --- a/src/pathfind.cpp +++ b/src/pathfind.cpp @@ -7,7 +7,7 @@ #include "bridge_map.h" #include "station_map.h" #include "depot.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "map.h" #include "pathfind.h" @@ -17,6 +17,7 @@ #include "variables.h" #include "depot.h" #include "tunnelbridge_map.h" +#include "core/random_func.hpp" /* remember which tiles we have already visited so we don't visit them again. */ static bool TPFSetTileBit(TrackPathFinder *tpf, TileIndex tile, int dir) diff --git a/src/player.h b/src/player.h index decfc15f47..83fd5f7fa0 100644 --- a/src/player.h +++ b/src/player.h @@ -9,6 +9,8 @@ #include "aystar.h" #include "rail_type.h" #include "road_func.h" +#include "cargo_type.h" +#include "command_type.h" #include "engine.h" #include "livery.h" #include "genworld.h" diff --git a/src/rail.h b/src/rail.h index 3d8be6a25a..ccc6c78579 100644 --- a/src/rail.h +++ b/src/rail.h @@ -8,6 +8,7 @@ #include "gfx.h" #include "rail_type.h" #include "track_type.h" +#include "vehicle_type.h" #include "core/bitmath_func.hpp" #include "variables.h" #include "economy_func.h" diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index b30574ace6..ee2d1e6296 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -8,7 +8,7 @@ #include "bridge.h" #include "cmd_helper.h" #include "debug.h" -#include "functions.h" +#include "tile_cmd.h" #include "rail_map.h" #include "road_map.h" #include "table/sprites.h" @@ -2334,7 +2334,7 @@ static const signed char _deltacoord_leaveoffset[8] = { 0, 1, 0, -1 /* y */ }; -static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) +static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) { byte fract_coord; byte fract_coord_leave; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 38257a96c3..43519e0f69 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -7,6 +7,7 @@ #include "table/sprites.h" #include "table/strings.h" #include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "date.h" #include "map.h" diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index a4162a54d4..5e2546d080 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -13,7 +13,7 @@ #include "sprite.h" #include "table/sprites.h" #include "table/strings.h" -#include "functions.h" +#include "tile_cmd.h" #include "map.h" #include "landscape.h" #include "town_map.h" @@ -1353,7 +1353,7 @@ static const byte _roadveh_enter_depot_dir[4] = { TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_X_NE, TRACKDIR_Y_SE }; -static uint32 VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) +static VehicleEnterTileStatus VehicleEnter_Road(Vehicle *v, TileIndex tile, int x, int y) { switch (GetRoadTileType(tile)) { case ROAD_TILE_CROSSING: diff --git a/src/road_map.cpp b/src/road_map.cpp index 4d6a1d6f81..51723fa149 100644 --- a/src/road_map.cpp +++ b/src/road_map.cpp @@ -5,8 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "bridge_map.h" -#include "functions.h" -#include "landscape.h" +#include "tile_cmd.h" #include "road_map.h" #include "station.h" #include "tunnel_map.h" diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index d429f7dd3a..c78d073a7e 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -5,7 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "debug.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "road_map.h" #include "roadveh.h" diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 75dd4438fd..706049e0f6 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -7,6 +7,7 @@ #include "ship.h" #include "table/strings.h" #include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "map.h" #include "vehicle.h" diff --git a/src/sound.h b/src/sound.h index 2b3355a9ef..fa4c987bd7 100644 --- a/src/sound.h +++ b/src/sound.h @@ -5,7 +5,8 @@ #ifndef SOUND_H #define SOUND_H -#include "helpers.hpp" +#include "core/enum_type.hpp" +#include "vehicle_type.h" struct MusicFileSettings { byte playlist; diff --git a/src/station.h b/src/station.h index 67173f5591..62a7c69c40 100644 --- a/src/station.h +++ b/src/station.h @@ -12,6 +12,7 @@ #include "road_type.h" #include "newgrf_station.h" #include "cargopacket.h" +#include "cargo_type.h" #include #include diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index e876f4c10e..ba31f9243d 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -9,7 +9,7 @@ #include "bridge_map.h" #include "cmd_helper.h" #include "debug.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "station_map.h" #include "table/sprites.h" @@ -2345,7 +2345,7 @@ static const byte _enter_station_speedtable[12] = { 215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0 }; -static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) +static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) { if (v->type == VEH_TRAIN) { if (IsRailwayStation(tile) && IsFrontEngine(v) && @@ -2365,7 +2365,7 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); if (y == TILE_SIZE / 2) { if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; - if (x == 12) return VETSB_ENTERED_STATION | (station_id << VETS_STATION_ID_OFFSET); /* enter station */ + if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */ if (x < 12) { uint16 spd; diff --git a/src/texteff.cpp b/src/texteff.cpp index 3d1d0250db..447a6c2a55 100644 --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -5,6 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "functions.h" +#include "tile_cmd.h" #include "gfx.h" #include "landscape.h" #include "viewport.h" diff --git a/src/tile_cmd.h b/src/tile_cmd.h new file mode 100644 index 0000000000..60f8940cea --- /dev/null +++ b/src/tile_cmd.h @@ -0,0 +1,116 @@ +/* $Id$ */ + +/** @file tile_cmd.h Generic 'commands' that can be performed on all tiles. */ + +#ifndef TILE_CMD_H +#define TILE_CMD_H + +#include "slope_type.h" +#include "command_type.h" +#include "vehicle_type.h" +#include "cargo_type.h" + +/** The returned bits of VehicleEnterTile. */ +enum VehicleEnterTileStatus { + VETS_ENTERED_STATION = 1, ///< The vehicle entered a station + VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) + VETS_CANNOT_ENTER = 3, ///< The vehicle cannot enter the tile + + /** + * Shift the VehicleEnterTileStatus this many bits + * to the right to get the station ID when + * VETS_ENTERED_STATION is set + */ + VETS_STATION_ID_OFFSET = 8, + + /** Bit sets of the above specified bits */ + VETSB_CONTINUE = 0, ///< The vehicle can continue normally + VETSB_ENTERED_STATION = 1 << VETS_ENTERED_STATION, ///< The vehicle entered a station + VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) + VETSB_CANNOT_ENTER = 1 << VETS_CANNOT_ENTER, ///< The vehicle cannot enter the tile +}; +DECLARE_ENUM_AS_BIT_SET(VehicleEnterTileStatus); + +typedef void DrawTileProc(TileInfo *ti); +typedef uint GetSlopeZProc(TileIndex tile, uint x, uint y); +typedef CommandCost ClearTileProc(TileIndex tile, byte flags); +typedef void GetAcceptedCargoProc(TileIndex tile, AcceptedCargo res); +typedef void GetTileDescProc(TileIndex tile, TileDesc *td); + +/** + * GetTileTrackStatusProcs return a value that contains the possible tracks + * that can be taken on a given tile by a given transport. The return value is + * composed as follows: 0xaabbccdd. ccdd and aabb are bitmasks of trackdirs, + * where bit n corresponds to trackdir n. ccdd are the trackdirs that are + * present in the tile (1==present, 0==not present), aabb is the signal + * status, if applicable (0==green/no signal, 1==red, note that this is + * reversed from map3/2[tile] for railway signals). + * + * The result (let's call it ts) is often used as follows: + * tracks = (byte)(ts | ts >>8) + * This effectively converts the present part of the result (ccdd) to a + * track bitmask, which disregards directions. Normally, this is the same as just + * doing (byte)ts I think, although I am not really sure + * + * A trackdir is combination of a track and a dir, where the lower three bits + * are a track, the fourth bit is the direction. these give 12 (or 14) + * possible options: 0-5 and 8-13, so we need 14 bits for a trackdir bitmask + * above. + * @param tile the tile to get the track status from + * @param mode the mode of transportation + * @param sub_mode used to differentiate between different kinds within the mode + * @return the above mentions track status information + */ +typedef uint32 GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode); +typedef void GetProducedCargoProc(TileIndex tile, CargoID *b); +typedef void ClickTileProc(TileIndex tile); +typedef void AnimateTileProc(TileIndex tile); +typedef void TileLoopProc(TileIndex tile); +typedef void ChangeTileOwnerProc(TileIndex tile, PlayerID old_player, PlayerID new_player); + +/** @see VehicleEnterTileStatus to see what the return values mean */ +typedef VehicleEnterTileStatus VehicleEnterTileProc(Vehicle *v, TileIndex tile, int x, int y); +typedef Foundation GetFoundationProc(TileIndex tile, Slope tileh); + +/** + * Called when a tile is affected by a terraforming operation. + * The function has to check if terraforming of the tile is allowed and return extra terraform-cost that depend on the tiletype. + * With DC_EXEC in flags it has to perform tiletype-specific actions (like clearing land etc., but not the terraforming itself). + * + * @note The terraforming has not yet taken place. So GetTileZ() and GetTileSlope() refer to the landscape before the terraforming operation. + * + * @param tile The involved tile. + * @param flags Command flags passed to the terraform command (DC_EXEC, DC_QUERY_COST, etc.). + * @param z_new TileZ after terraforming. + * @param tileh_new Slope after terraforming. + * @return Error code or extra cost for terraforming (like clearing land, building foundations, etc., but not the terraforming itself.) + */ +typedef CommandCost TerraformTileProc(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new); + +struct TileTypeProcs { + DrawTileProc *draw_tile_proc; + GetSlopeZProc *get_slope_z_proc; + ClearTileProc *clear_tile_proc; + GetAcceptedCargoProc *get_accepted_cargo_proc; + GetTileDescProc *get_tile_desc_proc; + GetTileTrackStatusProc *get_tile_track_status_proc; + ClickTileProc *click_tile_proc; + AnimateTileProc *animate_tile_proc; + TileLoopProc *tile_loop_proc; + ChangeTileOwnerProc *change_tile_owner_proc; + GetProducedCargoProc *get_produced_cargo_proc; + VehicleEnterTileProc *vehicle_enter_tile_proc; + GetFoundationProc *get_foundation_proc; + TerraformTileProc *terraform_tile_proc; +}; + +extern const TileTypeProcs * const _tile_type_procs[16]; + +uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode); +void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac); +void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player); +void AnimateTile(TileIndex tile); +void ClickTile(TileIndex tile); +void GetTileDesc(TileIndex tile, TileDesc *td); + +#endif /* TILE_CMD_H */ diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 6620e86c69..fdf715f0f0 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -4,7 +4,7 @@ #include "stdafx.h" #include "openttd.h" -#include "functions.h" +#include "tile_cmd.h" #include "debug.h" #include "road_map.h" #include "road_internal.h" /* Cleaning up road bits */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index ee026d8eb9..67ef268be2 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -6,7 +6,7 @@ #include "openttd.h" #include "bridge_map.h" #include "debug.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "gui.h" #include "station_map.h" diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 4789864b02..2888091fe3 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -9,7 +9,7 @@ #include "table/strings.h" #include "table/sprites.h" #include "table/tree_land.h" -#include "functions.h" +#include "tile_cmd.h" #include "map.h" #include "landscape.h" #include "tree_map.h" diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 82695f693e..34f4d8b511 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -12,7 +12,7 @@ #include "road_map.h" #include "table/sprites.h" #include "table/strings.h" -#include "functions.h" +#include "tile_cmd.h" #include "map.h" #include "landscape.h" #include "tunnel_map.h" @@ -1257,7 +1257,7 @@ static const byte _tunnel_fractcoord_5[4] = {0x92, 0x89, 0x58, 0x25}; static const byte _tunnel_fractcoord_6[4] = {0x92, 0x89, 0x56, 0x45}; static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49}; -static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) +static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y) { int z = GetSlopeZ(x, y) - v->z_pos; diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index 5b373201f5..034341b7cc 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -6,7 +6,7 @@ #include "openttd.h" #include "table/strings.h" #include "table/sprites.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "map.h" #include "command_func.h" diff --git a/src/variables.h b/src/variables.h index 613cecc9e1..f21afc0249 100644 --- a/src/variables.h +++ b/src/variables.h @@ -11,9 +11,6 @@ #include "gfx.h" -VARDEF Money _cargo_payment_rates[NUM_CARGO]; -VARDEF uint16 _cargo_payment_rates_frac[NUM_CARGO]; - struct GameOptions { GameDifficulty diff; byte diff_level; @@ -39,9 +36,6 @@ VARDEF GameOptions *_opt_ptr; /* Amount of game ticks */ VARDEF uint16 _tick_counter; -/* This one is not used anymore. */ -VARDEF VehicleID _vehicle_id_ctr_day; - /* Skip aging of cargo? */ VARDEF byte _age_cargo_skip_counter; @@ -293,7 +287,6 @@ VARDEF uint32 _news_display_opt; VARDEF bool _news_ticker_sound; VARDEF StringID _error_message; -VARDEF Money _additional_cash_required; VARDEF bool _rightclick_emulate; @@ -317,10 +310,6 @@ VARDEF byte _switch_mode; VARDEF StringID _switch_mode_errorstr; VARDEF SmallFiosItem _file_to_saveload; - - -VARDEF Vehicle *_place_clicked_vehicle; - VARDEF char _ini_videodriver[32], _ini_musicdriver[32], _ini_sounddriver[32], _ini_blitter[32]; VARDEF int _num_resolutions; @@ -339,8 +328,6 @@ VARDEF char *_log_file; /* landscape.cpp */ extern const byte _tileh_to_sprite[32]; -extern const TileTypeProcs * const _tile_type_procs[16]; - extern bool _draw_bounding_boxes; /* misc */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 82fb34edd2..0c9dfabd37 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -10,7 +10,7 @@ #include "spritecache.h" #include "table/sprites.h" #include "table/strings.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "map.h" #include "vehicle.h" diff --git a/src/vehicle.h b/src/vehicle.h index 7ab327feea..0b7f35d67d 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -11,29 +11,11 @@ #include "track_type.h" #include "rail_type.h" #include "road_type.h" +#include "cargo_type.h" #include "window_type.h" #include "cargopacket.h" #include "texteff.hpp" - -/** The returned bits of VehicleEnterTile. */ -enum VehicleEnterTileStatus { - VETS_ENTERED_STATION = 1, ///< The vehicle entered a station - VETS_ENTERED_WORMHOLE = 2, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) - VETS_CANNOT_ENTER = 3, ///< The vehicle cannot enter the tile - - /** - * Shift the VehicleEnterTileStatus this many bits - * to the right to get the station ID when - * VETS_ENTERED_STATION is set - */ - VETS_STATION_ID_OFFSET = 8, - - /** Bit sets of the above specified bits */ - VETSB_CONTINUE = 0, ///< The vehicle can continue normally - VETSB_ENTERED_STATION = 1 << VETS_ENTERED_STATION, ///< The vehicle entered a station - VETSB_ENTERED_WORMHOLE = 1 << VETS_ENTERED_WORMHOLE, ///< The vehicle either entered a bridge, tunnel or depot tile (this includes the last tile of the bridge/tunnel) - VETSB_CANNOT_ENTER = 1 << VETS_CANNOT_ENTER, ///< The vehicle cannot enter the tile -}; +#include "command_type.h" /** Road vehicle states */ enum RoadVehicleStates { @@ -829,4 +811,9 @@ static inline uint32 GetCmdSendToDepot(const Vehicle *v) return GetCmdSendToDepot(v->type); } +/* This one is not used anymore. */ +VARDEF VehicleID _vehicle_id_ctr_day; +VARDEF Vehicle *_place_clicked_vehicle; + + #endif /* VEHICLE_H */ diff --git a/src/viewport.cpp b/src/viewport.cpp index 1ef7b9ccbf..f02ee112e0 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -5,7 +5,7 @@ #include "stdafx.h" #include "openttd.h" #include "debug.h" -#include "functions.h" +#include "tile_cmd.h" #include "gui.h" #include "spritecache.h" #include "table/sprites.h" diff --git a/src/viewport.h b/src/viewport.h index 9cff8861d4..08ef267445 100644 --- a/src/viewport.h +++ b/src/viewport.h @@ -7,6 +7,8 @@ #include "zoom.hpp" #include "window_type.h" +#include "vehicle_type.h" +#include "gfx.h" struct ViewPort { int left,top; // screen coordinates for the viewport diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 16f9a6b7e0..a401296587 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -10,7 +10,7 @@ #include "station_map.h" #include "table/sprites.h" #include "table/strings.h" -#include "functions.h" +#include "tile_cmd.h" #include "landscape.h" #include "map.h" #include "vehicle.h" @@ -891,7 +891,7 @@ static void ChangeTileOwner_Water(TileIndex tile, PlayerID old_player, PlayerID } } -static uint32 VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) +static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *v, TileIndex tile, int x, int y) { return VETSB_CONTINUE; } diff --git a/src/yapf/yapf.hpp b/src/yapf/yapf.hpp index 2bbbc0a7ac..dda6780c82 100644 --- a/src/yapf/yapf.hpp +++ b/src/yapf/yapf.hpp @@ -17,7 +17,7 @@ #include "../station.h" #include "../station_map.h" #include "../date.h" -#include "../functions.h" +#include "../tile_cmd.h" #include "../landscape.h" #include "yapf.h" #include "../pathfind.h"