Mercurial > hg > openttd
changeset 8119:b6ec923e9fa8 draft
(svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
line wrap: on
line diff
--- 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"
--- a/src/bridge.h +++ b/src/bridge.h @@ -37,4 +37,8 @@ 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 */
new file mode 100644 --- /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 */
--- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -5,6 +5,7 @@ #ifndef CARGOPACKET_H #define CARGOPACKET_H +#include "economy_type.h" #include <list> typedef uint32 CargoPacketID;
--- 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;
--- 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).
--- a/src/command_func.h +++ b/src/command_func.h @@ -76,6 +76,7 @@ * 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.
--- 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"
--- 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) {
--- 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 @@ 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) {
--- 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 @@ /* 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);
--- 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;
--- 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
--- 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 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();
--- 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);
--- 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;
--- 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 @@ 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);
--- a/src/industry_map.h +++ b/src/industry_map.h @@ -156,11 +156,12 @@ /** * 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 @@ _m[t].m3 = 0; _m[t].m4 = 0; SetIndustryGfx(t, gfx); - _me[t].m7 = Random(); + _me[t].m7 = random; } /**
--- 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,
--- 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 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);
--- 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];
--- 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
--- 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;
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -30,6 +30,7 @@ #include <stdarg.h> /* 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);
--- 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
--- 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"
--- 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)
--- 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"
--- a/src/openttd.h +++ b/src/openttd.h @@ -28,7 +28,6 @@ #include "map.h" #include "slope_type.h" -#include "vehicle_type.h" // Forward declarations of structs. struct Depot; @@ -41,7 +40,6 @@ 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 @@ 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 @@ 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 {
--- 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,
--- 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)
--- 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"
--- 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"
--- 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 @@ 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;
--- 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"
--- 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 @@ 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:
--- 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"
--- 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"
--- 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"
--- 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;
--- 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 <list> #include <set>
--- 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 @@ 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 @@ 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;
--- 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"
new file mode 100644 --- /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 */
--- 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 */
--- 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"
--- 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"
--- 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_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;
--- 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"
--- 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 @@ /* 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 bool _news_ticker_sound; VARDEF StringID _error_message; -VARDEF Money _additional_cash_required; VARDEF bool _rightclick_emulate; @@ -317,10 +310,6 @@ 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 @@ /* landscape.cpp */ extern const byte _tileh_to_sprite[32]; -extern const TileTypeProcs * const _tile_type_procs[16]; - extern bool _draw_bounding_boxes; /* misc */
--- 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"
--- 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 @@ return GetCmdSendToDepot(v->type); } +/* This one is not used anymore. */ +VARDEF VehicleID _vehicle_id_ctr_day; +VARDEF Vehicle *_place_clicked_vehicle; + + #endif /* VEHICLE_H */
--- 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"
--- 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
--- 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 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; }